Skip to content

Commit

Permalink
485916: a builder for merging generated plugin.xml files
Browse files Browse the repository at this point in the history
Change-Id: I8f436b5d70878e0345c0b25a2547bafbf1865a1c
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=485916
  • Loading branch information
LorenzoBettini committed Feb 17, 2016
1 parent 047c564 commit b5bb805
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
Expand All @@ -16,7 +21,7 @@ org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
Expand Down
4 changes: 2 additions & 2 deletions dsl/org.eclipse.emf.parsley.dsl.additional.builder/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
locationURI="popup:org.eclipse.ui.projectConfigure?after=additions">
<command
commandId="org.eclipse.emf.parsley.dsl.additional.builder.addRemoveEmfParsleyDslPluginXmlNature"
label="Disable Sample builder"
label="Disable EMF Parsley builder"
style="push">
<visibleWhen
checkEnabled="false">
Expand All @@ -68,7 +68,7 @@
</command>
<command
commandId="org.eclipse.emf.parsley.dsl.additional.builder.addRemoveEmfParsleyDslPluginXmlNature"
label="Enable Sample builder"
label="Enable EMF Parsley builder"
style="push">
<visibleWhen
checkEnabled="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public Activator() {
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
Expand All @@ -34,6 +35,7 @@ public void start(BundleContext context) throws Exception {
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

public class AddRemoveEmfParsleyDslPluginXmlNatureHandler extends AbstractHandler {

private ISelection selection;

@SuppressWarnings("cast")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// TODO Auto-generated method stub
ISelection selection = HandlerUtil.getCurrentSelection(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
import java.io.InputStreamReader;
import java.util.Map;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
Expand All @@ -25,123 +20,47 @@
import org.eclipse.emf.parsley.dsl.generator.EmfParsleyDslOutputConfigurationProvider;
import org.eclipse.emf.parsley.dsl.pluginxml.PluginXmlLoader;
import org.eclipse.xtext.util.StringInputStream;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

import com.google.common.io.CharStreams;

public class EmfParsleyDslPluginXmlBuilder extends IncrementalProjectBuilder {

class SampleDeltaVisitor implements IResourceDeltaVisitor {
/*
* (non-Javadoc)
*
* @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
*/
class EmfParsleyDslPluginXmlBuilderDeltaVisitor implements IResourceDeltaVisitor {
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
IResource resource = delta.getResource();
switch (delta.getKind()) {
case IResourceDelta.ADDED:
// handle added resource
checkXML(resource);
break;
case IResourceDelta.REMOVED:
// handle removed resource
break;
case IResourceDelta.CHANGED:
if (delta.getKind() != IResourceDelta.REMOVED) {
// handle changed resource
checkXML(resource);
break;
copyFromGeneratedPluginXml(resource);
}
//return true to continue visiting children.
return true;
}
}

class SampleResourceVisitor implements IResourceVisitor {
class EmfParsleyDslPluginXmlBuilderResourceVisitor implements IResourceVisitor {
@Override
public boolean visit(IResource resource) throws CoreException {
checkXML(resource);
copyFromGeneratedPluginXml(resource);
//return true to continue visiting children.
return true;
}
}

class XMLErrorHandler extends DefaultHandler {

private IFile file;

public XMLErrorHandler(IFile file) {
this.file = file;
}

private void addMarker(SAXParseException e, int severity) {
EmfParsleyDslPluginXmlBuilder.this.addMarker(file, e.getMessage(), e
.getLineNumber(), severity);
}

public void error(SAXParseException exception) throws SAXException {
addMarker(exception, IMarker.SEVERITY_ERROR);
}

public void fatalError(SAXParseException exception) throws SAXException {
addMarker(exception, IMarker.SEVERITY_ERROR);
}

public void warning(SAXParseException exception) throws SAXException {
addMarker(exception, IMarker.SEVERITY_WARNING);
}
}

public static final String BUILDER_ID = "org.eclipse.emf.parsley.dsl.additional.builder.emfParsleyDslPluginXmlBuilder";

private static final String MARKER_TYPE = "org.eclipse.emf.parsley.dsl.additional.builder.xmlProblem";

private SAXParserFactory parserFactory;

private void addMarker(IFile file, String message, int lineNumber,
int severity) {
try {
IMarker marker = file.createMarker(MARKER_TYPE);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, severity);
if (lineNumber == -1) {
lineNumber = 1;
}
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
} catch (CoreException e) {
}
}

/*
* (non-Javadoc)
*
* @see org.eclipse.core.internal.events.InternalBuilder#build(int,
* java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
*/
protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
throws CoreException {
if (kind == FULL_BUILD) {
@Override
protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
IResourceDelta delta = getDelta(getProject());
if (delta == null) {
fullBuild(monitor);
} else {
IResourceDelta delta = getDelta(getProject());
if (delta == null) {
fullBuild(monitor);
} else {
incrementalBuild(delta, monitor);
}
incrementalBuild(delta, monitor);
}
return null;
}

protected void clean(IProgressMonitor monitor) throws CoreException {
// delete markers set and files created
getProject().deleteMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE);
}

void checkXML(IResource resource) throws CoreException {
void copyFromGeneratedPluginXml(IResource resource) throws CoreException {
if (resource instanceof IFile && resource.getName()
.endsWith(EmfParsleyDslOutputConfigurationProvider.PLUGIN_XML_EMFPARSLEY_GEN_EXTENSION)) {
IFile file = (IFile) resource;
Expand All @@ -162,39 +81,24 @@ void checkXML(IResource resource) throws CoreException {
}

protected String loadFromResource(IFile file) throws CoreException {
try {
return CharStreams.toString(new InputStreamReader(file.getContents()));
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "while reading " + file.getFullPath(), e));
}
}

private void deleteMarkers(IFile file) {
try {
file.deleteMarkers(MARKER_TYPE, false, IResource.DEPTH_ZERO);
} catch (CoreException ce) {
}
return loadFromResource(new InputStreamReader(file.getContents()), file.getFullPath().toString());
}

protected void fullBuild(final IProgressMonitor monitor)
throws CoreException {
protected String loadFromResource(InputStreamReader reader, String information) throws CoreException {
try {
getProject().accept(new SampleResourceVisitor());
} catch (CoreException e) {
return CharStreams.toString(reader);
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "while reading " + information, e));
}
}

private SAXParser getParser() throws ParserConfigurationException,
SAXException {
if (parserFactory == null) {
parserFactory = SAXParserFactory.newInstance();
}
return parserFactory.newSAXParser();
protected void fullBuild(final IProgressMonitor monitor) throws CoreException {
getProject().accept(new EmfParsleyDslPluginXmlBuilderResourceVisitor());
}

protected void incrementalBuild(IResourceDelta delta,
IProgressMonitor monitor) throws CoreException {
// the visitor does the work.
delta.accept(new SampleDeltaVisitor());
delta.accept(new EmfParsleyDslPluginXmlBuilderDeltaVisitor());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class EmfParsleyDslPluginXmlNature implements IProjectNature {
*
* @see org.eclipse.core.resources.IProjectNature#configure()
*/
@Override
public void configure() throws CoreException {
IProjectDescription desc = project.getDescription();
ICommand[] commands = desc.getBuildSpec();
Expand All @@ -44,6 +45,7 @@ public void configure() throws CoreException {
*
* @see org.eclipse.core.resources.IProjectNature#deconfigure()
*/
@Override
public void deconfigure() throws CoreException {
IProjectDescription description = getProject().getDescription();
ICommand[] commands = description.getBuildSpec();
Expand All @@ -65,6 +67,7 @@ public void deconfigure() throws CoreException {
*
* @see org.eclipse.core.resources.IProjectNature#getProject()
*/
@Override
public IProject getProject() {
return project;
}
Expand All @@ -74,6 +77,7 @@ public IProject getProject() {
*
* @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
*/
@Override
public void setProject(IProject project) {
this.project = project;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Boolean apply(final Map.Entry<String, IDocumentAttributeNode> it) {
});
}

@SuppressWarnings("cast")
public static IDocumentAttributeNode getId(final DocumentElementNode node) {
return ((IDocumentAttributeNode) node.getNodeAttributesMap().get("id"));
}
Expand Down
5 changes: 4 additions & 1 deletion dsl/org.eclipse.emf.parsley.dsl.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ Require-Bundle: org.eclipse.emf.parsley.dsl,
org.objectweb.asm;bundle-version="[5.0.1,6.0.0)";resolution:=optional,
org.eclipse.emf.parsley.tests.pde.utils,
org.eclipse.emf.parsley.generator.common,
org.eclipse.emf.parsley.dsl.additional.builder
org.eclipse.emf.parsley.dsl.additional.builder,
org.mockito;bundle-version="1.9.5",
org.objenesis;bundle-version="1.0.0",
org.hamcrest;bundle-version="[1.0.0,2.0.0)"
Import-Package: org.apache.log4j,
org.apache.log4j.spi,
org.hamcrest.core,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig">
<booleanAttribute key="append.args" value="true"/>
<booleanAttribute key="askclear" value="false"/>
<booleanAttribute key="automaticAdd" value="true"/>
<booleanAttribute key="automaticValidate" value="false"/>
<stringAttribute key="bootstrap" value=""/>
<stringAttribute key="checked" value="[NONE]"/>
<booleanAttribute key="clearConfig" value="true"/>
<booleanAttribute key="clearws" value="true"/>
<booleanAttribute key="clearwslog" value="false"/>
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
<booleanAttribute key="default" value="true"/>
<booleanAttribute key="includeOptional" value="true"/>
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.eclipse.emf.parsley.dsl.tests/xtend-gen/org/eclipse/emf/parsley/dsl/ui/tests/EmfParsleyDslPluginXmlBuilderTest.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.parsley.dsl.ui.tests.EmfParsleyDslPluginXmlBuilderTest"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.emf.parsley.dsl.tests"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XX:ReservedCodeCacheSize=64m -Xms40m -Xmx1024m -XX:MaxPermSize=256m -Dorg.eclipse.swt.browser.DefaultType=mozilla"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.platform.ide"/>
<booleanAttribute key="run_in_ui_thread" value="true"/>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfig" value="true"/>
<booleanAttribute key="useDefaultConfigArea" value="false"/>
<booleanAttribute key="useProduct" value="true"/>
</launchConfiguration>
Loading

0 comments on commit b5bb805

Please sign in to comment.