|
@@ -55,8 +55,7 @@ public class SCTBuilder extends IncrementalProjectBuilder {
|
|
|
private static final String SGEN_FILE_EXTENSION = "sgen";
|
|
|
public static final String BUILDER_ID = "org.yakindu.sct.builder.SCTBuilder";
|
|
|
|
|
|
- private final class ElementRefGenerator implements
|
|
|
- Predicate<GeneratorEntry> {
|
|
|
+ private final class ElementRefGenerator implements Predicate<GeneratorEntry> {
|
|
|
|
|
|
private final URI uri;
|
|
|
|
|
@@ -69,8 +68,7 @@ public class SCTBuilder extends IncrementalProjectBuilder {
|
|
|
}
|
|
|
|
|
|
public boolean apply(GeneratorEntry input) {
|
|
|
- return uri != null && input.getElementRef() != null
|
|
|
- && !input.getElementRef().eIsProxy()
|
|
|
+ return uri != null && input.getElementRef() != null && !input.getElementRef().eIsProxy()
|
|
|
&& uri.equals(EcoreUtil.getURI(input.getElementRef()));
|
|
|
}
|
|
|
}
|
|
@@ -109,8 +107,7 @@ public class SCTBuilder extends IncrementalProjectBuilder {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected IProject[] build(int kind,
|
|
|
- @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor)
|
|
|
+ protected IProject[] build(int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor)
|
|
|
throws CoreException {
|
|
|
if (kind == FULL_BUILD) {
|
|
|
fullBuild(monitor);
|
|
@@ -125,16 +122,14 @@ public class SCTBuilder extends IncrementalProjectBuilder {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- protected void fullBuild(final IProgressMonitor monitor)
|
|
|
- throws CoreException {
|
|
|
+ protected void fullBuild(final IProgressMonitor monitor) throws CoreException {
|
|
|
try {
|
|
|
getProject().accept(new SimpleResourceVisitor());
|
|
|
} catch (CoreException e) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- protected void incrementalBuild(IResourceDelta delta,
|
|
|
- IProgressMonitor monitor) throws CoreException {
|
|
|
+ protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
|
|
|
delta.accept(new DeltaVisitor());
|
|
|
}
|
|
|
|
|
@@ -148,43 +143,37 @@ public class SCTBuilder extends IncrementalProjectBuilder {
|
|
|
* Contains a set of already build sgen files. Accepted
|
|
|
* sgen-files are added inside this method.
|
|
|
*/
|
|
|
- public void doIt(final IResource changedResource,
|
|
|
- final Set<IResource> buildSgens) {
|
|
|
+ public void doIt(final IResource changedResource, final Set<IResource> buildSgens) {
|
|
|
if (changedResource.getType() != IResource.FILE) {
|
|
|
return;
|
|
|
}
|
|
|
- if (SGEN_FILE_EXTENSION.equals(changedResource.getFileExtension())
|
|
|
- && !buildSgens.contains(changedResource)) {
|
|
|
+ if (SGEN_FILE_EXTENSION.equals(changedResource.getFileExtension()) && !buildSgens.contains(changedResource)) {
|
|
|
if (hasError(changedResource)) {
|
|
|
logGenmodelError(changedResource.getFullPath().toString());
|
|
|
} else {
|
|
|
buildSgens.add(changedResource);
|
|
|
executeGenmodelGenerator(changedResource);
|
|
|
}
|
|
|
- } else if (SCT_FILE_EXTENSION
|
|
|
- .equals(changedResource.getFileExtension())) {
|
|
|
+ } else if (SCT_FILE_EXTENSION.equals(changedResource.getFileExtension())) {
|
|
|
// TODO rely on indexed genmodel and referenced objects uri
|
|
|
final Statechart statechart = loadFromResource(changedResource);
|
|
|
+ if (statechart == null)
|
|
|
+ return;
|
|
|
try {
|
|
|
changedResource.getProject().accept(new IResourceVisitor() {
|
|
|
|
|
|
- public boolean visit(IResource resource)
|
|
|
- throws CoreException {
|
|
|
+ public boolean visit(IResource resource) throws CoreException {
|
|
|
if (IResource.FILE == resource.getType()
|
|
|
- && SGEN_FILE_EXTENSION.equals(resource
|
|
|
- .getFileExtension())
|
|
|
- && !buildSgens.contains(resource)
|
|
|
- && isGenmodelForStatechart(resource, statechart)) {
|
|
|
+ && SGEN_FILE_EXTENSION.equals(resource.getFileExtension())
|
|
|
+ && !buildSgens.contains(resource) && isGenmodelForStatechart(resource, statechart)) {
|
|
|
// TODO: would be good to filter the config for the
|
|
|
// statechart so only the sct that changed is
|
|
|
// build
|
|
|
if (hasError(changedResource)) {
|
|
|
- logStatechartError(changedResource
|
|
|
- .getFullPath().toString());
|
|
|
+ logStatechartError(changedResource.getFullPath().toString());
|
|
|
} else {
|
|
|
if (hasError(resource)) {
|
|
|
- logGenmodelError(resource.getFullPath()
|
|
|
- .toString());
|
|
|
+ logGenmodelError(resource.getFullPath().toString());
|
|
|
} else {
|
|
|
buildSgens.add(resource);
|
|
|
executeGenmodelGenerator(resource);
|
|
@@ -204,11 +193,9 @@ public class SCTBuilder extends IncrementalProjectBuilder {
|
|
|
private boolean hasError(IResource resource) {
|
|
|
IMarker[] findMarkers = null;
|
|
|
try {
|
|
|
- findMarkers = resource.findMarkers(IMarker.PROBLEM, true,
|
|
|
- IResource.DEPTH_INFINITE);
|
|
|
+ findMarkers = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
|
|
|
for (IMarker iMarker : findMarkers) {
|
|
|
- Integer attribute = (Integer) iMarker
|
|
|
- .getAttribute(IMarker.SEVERITY);
|
|
|
+ Integer attribute = (Integer) iMarker.getAttribute(IMarker.SEVERITY);
|
|
|
if (attribute.intValue() == IMarker.SEVERITY_ERROR) {
|
|
|
return true;
|
|
|
}
|
|
@@ -220,54 +207,41 @@ public class SCTBuilder extends IncrementalProjectBuilder {
|
|
|
}
|
|
|
|
|
|
protected void executeGenmodelGenerator(IResource resource) {
|
|
|
- new GeneratorExecutor().executeGenerator(resource.getProject().getFile(
|
|
|
- resource.getProjectRelativePath()));
|
|
|
+ new GeneratorExecutor().executeGenerator(resource.getProject().getFile(resource.getProjectRelativePath()));
|
|
|
}
|
|
|
|
|
|
protected void logGenmodelError(String resource) {
|
|
|
Status status = new Status(Status.ERROR, BUILDER_ID, String.format(
|
|
|
- "Cannot execute Genmodel %s. The file contains errors.",
|
|
|
- resource));
|
|
|
- Platform.getLog(GeneratorActivator.getDefault().getBundle())
|
|
|
- .log(status);
|
|
|
+ "Cannot execute Genmodel %s. The file contains errors.", resource));
|
|
|
+ Platform.getLog(GeneratorActivator.getDefault().getBundle()).log(status);
|
|
|
}
|
|
|
|
|
|
protected void logStatechartError(final String resource) {
|
|
|
- Status status = new Status(
|
|
|
- Status.ERROR,
|
|
|
- BUILDER_ID,
|
|
|
- String.format(
|
|
|
- "Cannot generate Code for Statechart %s. The file contains errors.",
|
|
|
- resource));
|
|
|
- Platform.getLog(GeneratorActivator.getDefault().getBundle())
|
|
|
- .log(status);
|
|
|
+ Status status = new Status(Status.ERROR, BUILDER_ID, String.format(
|
|
|
+ "Cannot generate Code for Statechart %s. The file contains errors.", resource));
|
|
|
+ Platform.getLog(GeneratorActivator.getDefault().getBundle()).log(status);
|
|
|
}
|
|
|
|
|
|
- private boolean isGenmodelForStatechart(IResource genmodelResource,
|
|
|
- final Statechart statechart) {
|
|
|
+ private boolean isGenmodelForStatechart(IResource genmodelResource, final Statechart statechart) {
|
|
|
GeneratorModel genModel = loadFromResource(genmodelResource);
|
|
|
- return genModel != null
|
|
|
- && !genModel.getEntries().isEmpty()
|
|
|
- && Iterables.any(genModel.getEntries(),
|
|
|
- new ElementRefGenerator(statechart));
|
|
|
+ return genModel != null && !genModel.getEntries().isEmpty()
|
|
|
+ && Iterables.any(genModel.getEntries(), new ElementRefGenerator(statechart));
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private <TYPE extends EObject> TYPE loadFromResource(IResource res) {
|
|
|
- URI uri = URI.createPlatformResourceURI(res.getFullPath().toString(),
|
|
|
- true);
|
|
|
+ URI uri = URI.createPlatformResourceURI(res.getFullPath().toString(), true);
|
|
|
ResourceSet set = new ResourceSetImpl();
|
|
|
Resource emfResource = null;
|
|
|
try {
|
|
|
emfResource = set.getResource(uri, true);
|
|
|
} catch (WrappedException e) {
|
|
|
- Platform.getLog(GeneratorActivator.getDefault().getBundle())
|
|
|
- .log(new Status(IStatus.WARNING, GeneratorActivator.PLUGIN_ID,
|
|
|
- "Resource "+uri+" can not be loaded by builder",e));
|
|
|
+ Platform.getLog(GeneratorActivator.getDefault().getBundle()).log(
|
|
|
+ new Status(IStatus.WARNING, GeneratorActivator.PLUGIN_ID, "Resource " + uri
|
|
|
+ + " can not be loaded by builder", e));
|
|
|
return null;
|
|
|
}
|
|
|
- if (emfResource.getErrors().size() > 0
|
|
|
- || emfResource.getContents().size() == 0)
|
|
|
+ if (emfResource.getErrors().size() > 0 || emfResource.getContents().size() == 0)
|
|
|
return null;
|
|
|
return (TYPE) emfResource.getContents().get(0);
|
|
|
}
|