Skip to content

Commit

Permalink
manage multiple call to builder due to duplicated melange files
Browse files Browse the repository at this point in the history
- ignore melange files in target folder, we should consider only those
outside bin folder (in model or src folders for exmaple)
 contributes to
#25 and
diverse-project/melange#105



Signed-off-by: dvojtise <[email protected]>
  • Loading branch information
dvojtise committed Feb 14, 2018
1 parent c6a194e commit a8d5ddc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecoretools.design.ui,
org.eclipse.gemoc.commons.eclipse.pde,
org.jdom2;bundle-version="2.0.6",
org.eclipse.gemoc.xdsmlframework.ide.ui;bundle-version="2.4.0"
org.eclipse.gemoc.xdsmlframework.ide.ui;bundle-version="2.4.0",
org.eclipse.core.jobs,
org.eclipse.jdt.core
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
Expand All @@ -31,6 +34,8 @@
import org.eclipse.gemoc.execution.sequential.javaxdsml.ide.ui.Activator;
import org.eclipse.gemoc.xdsmlframework.api.extensions.languages.LanguageDefinitionExtensionPoint;
import org.eclipse.gemoc.xdsmlframework.ide.ui.builder.pde.PluginXMLHelper;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.jdom2.Element;
import org.osgi.framework.BundleException;

Expand Down Expand Up @@ -68,10 +73,13 @@ public boolean visit(IResourceDelta delta) throws CoreException {

class GemocSequentialLanguageResourceVisitor implements IResourceVisitor {
public boolean visit(IResource resource) {

updateProjectPluginConfiguration(resource);
checkConsistency(resource);
//return true to continue visiting children.
return true;
if (resource instanceof IFolder || resource instanceof IProject)
return true;
else return false;
}
}

Expand Down Expand Up @@ -108,38 +116,53 @@ public void checkConsistency(IResource resource){
* @param resource
*/
private void updateProjectPluginConfiguration(IResource resource) {

if (resource instanceof IFile
&& resource.getFileExtension().equals("melange")) {

IFile file = (IFile) resource;
IProject project = file.getProject();
// try {
try {
IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
if(javaProject.getOutputLocation().isPrefixOf(file.getFullPath())){
// ignore melange files in target folder, we should consider only those outside it (in model or src folders for exmaple)
return;
};
} catch (CoreException e) {
Activator.error(e.getMessage(), e);
}
if (file.exists()) {

//Load .melange file
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
ResourceSet rs = new ResourceSetImpl();
Resource res = rs.getResource(uri, true);
ModelTypingSpace root = (ModelTypingSpace)res.getContents().get(0);
String packageName = root.getName();

//Browse declared Languages
for (fr.inria.diverse.melange.metamodel.melange.Element element : root.getElements()) {
if(element instanceof Language){
Language language = (Language) element;
// update entry in plugin.xml
setPluginLanguageNameAndFilePath(project, file, packageName+"."+language.getName());
Job job = Job.create("Update GEMOC Project Plugin Configuration of "+project.getName(), (ICoreRunnable) monitor -> {
//Load .melange file
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
ResourceSet rs = new ResourceSetImpl();
Resource res = rs.getResource(uri, true);
ModelTypingSpace root = (ModelTypingSpace)res.getContents().get(0);
String packageName = root.getName();

//Browse declared Languages
for (fr.inria.diverse.melange.metamodel.melange.Element element : root.getElements()) {
if(element instanceof Language){
Language language = (Language) element;
// update entry in plugin.xml
setPluginLanguageNameAndFilePath(project, file, packageName+"."+language.getName());
}
}
}

//Use default model loader
updateModelLoaderClass(project, null);
ManifestChanger manifestChanger = new ManifestChanger(project);
try {
manifestChanger.addPluginDependency(org.eclipse.gemoc.executionframework.extensions.sirius.Activator.PLUGIN_ID);
manifestChanger.commit();
} catch (BundleException | IOException | CoreException e) {
Activator.error(e.getMessage(), e);
}

//Use default model loader
updateModelLoaderClass(project, null);
ManifestChanger manifestChanger = new ManifestChanger(project);
try {
manifestChanger.addPluginDependency(org.eclipse.gemoc.executionframework.extensions.sirius.Activator.PLUGIN_ID);
manifestChanger.commit();
} catch (BundleException | IOException | CoreException e) {
Activator.error(e.getMessage(), e);
}
});
// lock the whole project
job.setRule(project);
// Start the Job
job.schedule(500);
}
}
}
Expand Down

0 comments on commit a8d5ddc

Please sign in to comment.