diff options
author | Camille Letavernier | 2016-04-26 12:59:13 +0000 |
---|---|---|
committer | Camille Letavernier | 2016-04-29 11:32:13 +0000 |
commit | f29492436da5affb390b2700cf7b89c9a9927a35 (patch) | |
tree | e87c1c638799d352b6fc85aba12b9a8e59be62a9 /plugins/developer/org.eclipse.papyrus.releng.tools | |
parent | eb9ade65dbe96eb1eb47385d848d8f951728344e (diff) | |
download | org.eclipse.papyrus-f29492436da5affb390b2700cf7b89c9a9927a35.tar.gz org.eclipse.papyrus-f29492436da5affb390b2700cf7b89c9a9927a35.tar.xz org.eclipse.papyrus-f29492436da5affb390b2700cf7b89c9a9927a35.zip |
Bug 492375: [Releng] Define a Target Platform to improve build
performances
https://bugs.eclipse.org/bugs/show_bug.cgi?id=492375
Change-Id: I5d454d4a1920bd407f6ca20d3a112c662610914d
Signed-off-by: Camille Letavernier <camille.letavernier@cea.fr>
Diffstat (limited to 'plugins/developer/org.eclipse.papyrus.releng.tools')
10 files changed, 360 insertions, 115 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/META-INF/MANIFEST.MF b/plugins/developer/org.eclipse.papyrus.releng.tools/META-INF/MANIFEST.MF index 3780cc3872b..6f2588136fb 100644 --- a/plugins/developer/org.eclipse.papyrus.releng.tools/META-INF/MANIFEST.MF +++ b/plugins/developer/org.eclipse.papyrus.releng.tools/META-INF/MANIFEST.MF @@ -6,7 +6,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.12.0,4.0.0)", org.eclipse.oomph.setup.targlets;bundle-version="[1.3.0,2.0.0)", org.eclipse.emf.edit;bundle-version="[2.12.0,3.0.0)", com.google.guava;bundle-version="11.0.0", - org.eclipse.oomph.setup.workingsets;bundle-version="[1.3.0,2.0.0)" + org.eclipse.oomph.setup.workingsets;bundle-version="[1.3.0,2.0.0)", + fr.obeo.releng.targetplatform;bundle-version="2.1.1";resolution:=optional Bundle-Vendor: %Bundle-Vendor Bundle-ActivationPolicy: lazy Bundle-Version: 1.2.0.qualifier diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml b/plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml index 8e0d7186bf6..772f111bf31 100644 --- a/plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml +++ b/plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml @@ -41,6 +41,10 @@ property="org.eclipse.core.resources.extension"
value="setup">
</test>
+ <test
+ property="org.eclipse.core.resources.extension"
+ value="tpd">
+ </test>
</or>
</adapt>
</iterate>
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateDependenciesHandler.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateDependenciesHandler.java index 5acb4b02d11..8431c835db8 100644 --- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateDependenciesHandler.java +++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateDependenciesHandler.java @@ -121,7 +121,7 @@ public class UpdateDependenciesHandler extends AbstractHandler { }
protected static List<IFile> findAggregationBuildFiles() throws CoreException {
- List<IFile> aggregationBuildFiles = new ArrayList<IFile>();
+ List<IFile> aggregationBuildFiles = new ArrayList<>();
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : projects) {
if (!project.isOpen()) {
@@ -202,8 +202,8 @@ public class UpdateDependenciesHandler extends AbstractHandler { protected boolean updateFile(IFile selectedFile, Aggregation aggregationModel, Shell activeShell, Map<Object, Object> context) throws CoreException {
boolean result = false;
- List<DependencyUpdater> updaters = findDependencyUpdater(selectedFile);
- for (DependencyUpdater updater : updaters) {
+ List<DependencyUpdater<?>> updaters = findDependencyUpdater(selectedFile);
+ for (DependencyUpdater<?> updater : updaters) {
updater.updateDocument(activeShell, selectedFile, aggregationModel.getAllContributions(true), context);
result = true;
}
@@ -211,7 +211,7 @@ public class UpdateDependenciesHandler extends AbstractHandler { return result;
}
- protected List<DependencyUpdater> findDependencyUpdater(IFile mapFile) throws CoreException {
+ protected List<DependencyUpdater<?>> findDependencyUpdater(IFile mapFile) throws CoreException {
final String path = "org/eclipse/papyrus/releng/tools/internal/popup/actions/"; //$NON-NLS-1$
Bundle bundle = Activator.getDefault().getBundle();
@@ -223,7 +223,7 @@ public class UpdateDependenciesHandler extends AbstractHandler { urls = bundle.findEntries(path, "*.class", false);
}
- List<DependencyUpdater> updaters = new LinkedList<>();
+ List<DependencyUpdater<?>> updaters = new LinkedList<>();
while (urls.hasMoreElements()) {
URL classURL = urls.nextElement();
@@ -231,10 +231,11 @@ public class UpdateDependenciesHandler extends AbstractHandler { try {
String className = classURI.trimFileExtension().lastSegment();
- if (!"DependencyUpdater".equals(className) && className.endsWith("Updater")) {
+
+ if (!"DependencyUpdater".equals(className) && !"XMLDependencyUpdater".equals(className) && className.endsWith("Updater")) {
Class<? extends DependencyUpdater> updaterClass = bundle.loadClass(path.replace('/', '.') + className).asSubclass(DependencyUpdater.class);
if (!Modifier.isAbstract(updaterClass.getModifiers())) {
- DependencyUpdater updater = updaterClass.newInstance();
+ DependencyUpdater<?> updater = updaterClass.newInstance();
if (updater.canUpdate(mapFile)) {
updaters.add(updater);
}
@@ -244,6 +245,8 @@ public class UpdateDependenciesHandler extends AbstractHandler { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No such class: " + classURI.lastSegment(), e));
} catch (IllegalAccessException | InstantiationException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to instantiated " + classURI.lastSegment(), e));
+ } catch (Throwable t) { // Classes with missing optional dependencies. Simple Warning
+ Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Failed to instantiate " + classURI.lastSegment(), t));
}
}
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/DependencyUpdater.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/DependencyUpdater.java index 97a0a521f34..3979ba1bb75 100644 --- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/DependencyUpdater.java +++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/DependencyUpdater.java @@ -11,11 +11,10 @@ * Christian W. Damus (CEA) - Add support for updating Oomph setup models
* Christian W. Damus - Support updating of multiple selected files
* Christian W. Damus - Ignore equivalent URL prefixes in detecting suspicious updates
- *
+ *
*******************************************************************************/
package org.eclipse.papyrus.releng.tools.internal.popup.actions;
-import java.io.File;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -24,17 +23,6 @@ import java.util.Set; import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathFactory;
-
import org.eclipse.b3.aggregator.Contribution;
import org.eclipse.b3.aggregator.MappedRepository;
import org.eclipse.core.resources.IFile;
@@ -63,11 +51,6 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ListSelectionDialog;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -75,8 +58,20 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-
-public abstract class DependencyUpdater {
+/**
+ * Generic DependencyUpdater
+ *
+ * This class will read a B3 Aggregator model (e.g. from Simrel) to find up-to-date P2 repositories.
+ *
+ * Subclasses will then be able to update the relevant <T> element (e.g. XML Dom Node, EMF EObject...)
+ * with the new repository location
+ *
+ * The matching is typically done via comments using the following format: updateFrom(repositoryLabel, index)
+ * It is up to subclasses to retrieve these comments in their model (XML Document, EMF Model)
+ *
+ * @param <T>
+ */
+public abstract class DependencyUpdater<T> {
private final Pattern commentPattern = Pattern.compile("updateFrom\\s*\\(\\s*\"(.*?)\"\\s*,\\s*(\\d+)\\s*\\)"); //$NON-NLS-1$
@@ -92,24 +87,15 @@ public abstract class DependencyUpdater { public abstract boolean canUpdate(IFile file);
+ protected abstract List<T> getNodesToUpdate(IFile file) throws CoreException;
+
public void updateDocument(final Shell parentShell, final IFile mapFile, final EList<Contribution> contributions, final Map<Object, Object> context) throws CoreException {
try {
- File rmapFile = mapFile.getLocation().toFile();
-
- DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
- Document doc = docBuilder.parse(rmapFile);
- doc.normalize();
- Element documentElement = doc.getDocumentElement();
-
- XPath xpath = XPathFactory.newInstance().newXPath();
- NodeList uris = (NodeList) xpath.evaluate(getXpath(), documentElement, XPathConstants.NODESET);
- List<UpdateItem> updates = Lists.newArrayList();
- for (int i = 0; i < uris.getLength(); i++) {
- Node uri = uris.item(i);
- Node precedingComment = getPrecedingComment(uri);
- if (precedingComment != null) {
- String comment = getCommentContent(precedingComment);
+ List<T> nodesToUpdate = getNodesToUpdate(mapFile);
+ List<UpdateItem<T>> updates = Lists.newArrayList();
+ for (T uri : nodesToUpdate) {
+ String comment = getComment(uri);
+ if (comment != null) {
Matcher matcher = getCommentPattern().matcher(comment);
if (matcher.find()) {
String contributionName = matcher.group(1);
@@ -118,7 +104,7 @@ public abstract class DependencyUpdater { if (contribution == null) {
throw new RuntimeException("'updateFrom' failed: cannot find contribution with label \"" + contributionName + "\""); //$NON-NLS-1$ //$NON-NLS-2$
}
- updates.add(new UpdateItem(uri, contribution, repositoryIndex));
+ updates.add(new UpdateItem<>(uri, contribution, repositoryIndex));
} else if (comment.contains("updateFrom")) { //$NON-NLS-1$
throw new Exception("Wrong syntax for 'updateFrom' : should be " + getCommentSyntax()); //$NON-NLS-1$
}
@@ -126,11 +112,11 @@ public abstract class DependencyUpdater { }
if (confirmUpdates(parentShell, updates, context)) {
- for (UpdateItem next : updates) {
+ for (UpdateItem<T> next : updates) {
updateWithContribution(parentShell, next.uriNode, next.contribution, next.repositoryIndex, context);
}
- save(doc, rmapFile);
+ save(mapFile);
mapFile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
}
@@ -141,16 +127,9 @@ public abstract class DependencyUpdater { }
}
- protected void save(Document document, File destination) throws Exception {
- Transformer transformer = TransformerFactory.newInstance().newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
-
- StreamResult result = new StreamResult(destination);
- DOMSource source = new DOMSource(document);
- transformer.transform(source, result);
- }
+ abstract protected void save(IFile file) throws Exception;
- protected void updateWithContribution(final Shell parentShell, final Node uri, final Contribution contribution, final int repositoryIndex, final Map<Object, Object> context) {
+ protected void updateWithContribution(final Shell parentShell, final T uri, final Contribution contribution, final int repositoryIndex, final Map<Object, Object> context) {
EList<MappedRepository> repositories = contribution.getRepositories();
if (repositoryIndex >= repositories.size()) {
throw new RuntimeException("wrong index in updateFrom(\"" + contribution.getLabel() + "\"" + repositoryIndex //$NON-NLS-1$ //$NON-NLS-2$
@@ -161,9 +140,9 @@ public abstract class DependencyUpdater { updateUri(uri, location);
}
- protected abstract String getCurrentLocation(Node uri);
+ protected abstract String getCurrentLocation(T uri);
- protected abstract void updateUri(Node uri, String location);
+ protected abstract void updateUri(T uri, String location);
protected Contribution findContribution(Iterable<? extends Contribution> contributions, final String contributionName) {
Contribution matchingContribution = null;
@@ -175,36 +154,19 @@ public abstract class DependencyUpdater { return matchingContribution;
}
- protected Node getPrecedingComment(final Node node) {
- Comment comment = null;
- Node previous = node.getPreviousSibling();
- while (previous != null) {
- if (previous.getNodeType() == Node.COMMENT_NODE) {
- comment = (Comment) previous;
- break;
- } else if (previous.getNodeType() != Node.TEXT_NODE) {
- break;
- }
- previous = previous.getPreviousSibling();
- }
- return comment;
- }
+ protected abstract String getComment(T node);
protected Pattern getCommentPattern() {
return commentPattern;
}
- protected String getCommentContent(Node comment) {
- return comment.getTextContent();
- }
-
protected String getCommentSyntax() {
return "updateFrom(\"<contributionName>\",<index>)"; //$NON-NLS-1$
}
- protected abstract String getXpath();
- private boolean promptToReplaceSingle(Shell parentShell, LocationUpdate locationUpdate, Map<Object, Object> context) {
+
+ private boolean promptToReplaceSingle(Shell parentShell, LocationUpdate<T> locationUpdate, Map<Object, Object> context) {
String message = NLS.bind("{0}\n\nUpdate anyways?", locationUpdate.strategy.getUpdateConfirmationMessage(locationUpdate.update, locationUpdate.oldLocation, locationUpdate.newLocation)); //$NON-NLS-1$
boolean result = MessageDialog.openQuestion(parentShell, "Confirm Location Update", message);
setReplace(locationUpdate.update, result, context);
@@ -212,11 +174,11 @@ public abstract class DependencyUpdater { return result;
}
- private Boolean getReplace(UpdateItem update, Map<Object, Object> context) {
+ private Boolean getReplace(UpdateItem<T> update, Map<Object, Object> context) {
return (Boolean) context.get("$replace$::" + update.contribution.getLabel()); //$NON-NLS-1$
}
- private void setReplace(UpdateItem update, Boolean replace, Map<Object, Object> context) {
+ private void setReplace(UpdateItem<T> update, Boolean replace, Map<Object, Object> context) {
context.put("$replace$::" + update.contribution.getLabel(), replace); //$NON-NLS-1$
}
@@ -224,13 +186,13 @@ public abstract class DependencyUpdater { * Prompt to confirm multiple suspicious dependency replacements, returning those updates that the
* user confirms to perform.
*/
- private Collection<LocationUpdate> promptToReplaceMultiple(Shell parentShell, Collection<? extends LocationUpdate> locationUpdates, Map<Object, Object> context) {
- final List<LocationUpdate> result = Lists.newArrayList(locationUpdates);
+ private Collection<LocationUpdate<T>> promptToReplaceMultiple(Shell parentShell, Collection<? extends LocationUpdate<T>> locationUpdates, Map<Object, Object> context) {
+ final List<LocationUpdate<T>> result = Lists.newArrayList(locationUpdates);
ILabelProvider labels = new LabelProvider() {
@Override
public String getText(Object element) {
- return ((LocationUpdate) element).update.contribution.getLabel();
+ return ((LocationUpdate<?>) element).update.contribution.getLabel();
}
};
@@ -261,7 +223,7 @@ public abstract class DependencyUpdater { if (sel.isEmpty()) {
details.setText(""); //$NON-NLS-1$
} else {
- LocationUpdate update = (LocationUpdate) sel.getFirstElement();
+ LocationUpdate<?> update = (LocationUpdate<?>) sel.getFirstElement();
details.setText(update.strategy.getUpdateConfirmationMessage(update.update, update.oldLocation, update.newLocation));
}
}
@@ -273,8 +235,8 @@ public abstract class DependencyUpdater { dialog.setTitle("Confirm Location Update");
if (dialog.open() == Window.OK) {
Set<?> toUpdate = ImmutableSet.copyOf(dialog.getResult());
- for (Iterator<LocationUpdate> iter = result.iterator(); iter.hasNext();) {
- LocationUpdate next = iter.next();
+ for (Iterator<LocationUpdate<T>> iter = result.iterator(); iter.hasNext();) {
+ LocationUpdate<T> next = iter.next();
boolean update = toUpdate.contains(next);
setReplace(next.update, update, context);
@@ -290,11 +252,11 @@ public abstract class DependencyUpdater { return result;
}
- private boolean confirmUpdates(final Shell parentShell, List<UpdateItem> updates, Map<Object, Object> context) {
- Map<UpdateItem, LocationUpdate> toPrompt = Maps.newHashMap();
+ private boolean confirmUpdates(final Shell parentShell, List<UpdateItem<T>> updates, Map<Object, Object> context) {
+ Map<UpdateItem<T>, LocationUpdate<T>> toPrompt = Maps.newHashMap();
- for (Iterator<UpdateItem> iter = updates.iterator(); iter.hasNext();) {
- UpdateItem next = iter.next();
+ for (Iterator<UpdateItem<T>> iter = updates.iterator(); iter.hasNext();) {
+ UpdateItem<T> next = iter.next();
// Check for previous prompt answer
Boolean previousAnswer = getReplace(next, context);
@@ -317,7 +279,7 @@ public abstract class DependencyUpdater { if ((current != null) && !current.isEmpty()) {
LocationUpdateStrategy strategy = findLocationUpdateStrategy(next, current, location);
if (strategy != null) {
- toPrompt.put(next, new LocationUpdate(next, strategy, current, location));
+ toPrompt.put(next, new LocationUpdate<>(next, strategy, current, location));
}
}
}
@@ -327,8 +289,8 @@ public abstract class DependencyUpdater { if (!toPrompt.isEmpty()) {
if (toPrompt.size() == 1) {
// Simple dialog
- UpdateItem update = Iterables.getOnlyElement(toPrompt.keySet());
- LocationUpdate location = toPrompt.get(update);
+ UpdateItem<T> update = Iterables.getOnlyElement(toPrompt.keySet());
+ LocationUpdate<T> location = toPrompt.get(update);
if (!promptToReplaceSingle(parentShell, location, context)) {
updates.remove(update);
}
@@ -342,7 +304,7 @@ public abstract class DependencyUpdater { return !updates.isEmpty();
}
- private LocationUpdateStrategy findLocationUpdateStrategy(UpdateItem update, String oldLocation, String newLocation) {
+ private LocationUpdateStrategy findLocationUpdateStrategy(UpdateItem<T> update, String oldLocation, String newLocation) {
LocationUpdateStrategy result = null;
for (LocationUpdateStrategy next : locationUpdateStrategies) {
@@ -359,12 +321,12 @@ public abstract class DependencyUpdater { // Nested types
//
- private static class UpdateItem {
- final Node uriNode;
+ private static class UpdateItem<T> {
+ final T uriNode;
final Contribution contribution;
final int repositoryIndex;
- UpdateItem(Node uriNode, Contribution contribution, int repositoryIndex) {
+ UpdateItem(T uriNode, Contribution contribution, int repositoryIndex) {
super();
this.uriNode = uriNode;
@@ -373,13 +335,13 @@ public abstract class DependencyUpdater { }
}
- private static class LocationUpdate {
- final UpdateItem update;
+ private static class LocationUpdate<T> {
+ final UpdateItem<T> update;
final LocationUpdateStrategy strategy;
final String oldLocation;
final String newLocation;
- LocationUpdate(UpdateItem update, LocationUpdateStrategy strategy, String oldLocation, String newLocation) {
+ LocationUpdate(UpdateItem<T> update, LocationUpdateStrategy strategy, String oldLocation, String newLocation) {
super();
this.update = update;
@@ -392,9 +354,9 @@ public abstract class DependencyUpdater { private interface LocationUpdateStrategy {
Pattern URL_PREFIX_PATTERN = Pattern.compile("^(?:\\$\\{[^}]+\\}/|\\Qhttp://download.eclipse.org/\\E)"); //$NON-NLS-1$
- boolean shouldAutoUpdate(UpdateItem update, String oldLocation, String newLocation);
+ boolean shouldAutoUpdate(UpdateItem<?> update, String oldLocation, String newLocation);
- String getUpdateConfirmationMessage(UpdateItem update, String oldLocation, String newLocation);
+ String getUpdateConfirmationMessage(UpdateItem<?> update, String oldLocation, String newLocation);
default boolean hasRecognizedURLPrefix(String location) {
return URL_PREFIX_PATTERN.matcher(location).find();
@@ -437,12 +399,12 @@ public abstract class DependencyUpdater { private final Pattern typicalBuildTimestampPattern = Pattern.compile("[NISMR](?:-\\d+\\.\\d+(?:\\.\\d+)?(?:M|RC)\\d[abcd]-)?20\\d\\d[-0-9]+"); //$NON-NLS-1$
@Override
- public boolean shouldAutoUpdate(UpdateItem update, String oldLocation, String newLocation) {
+ public boolean shouldAutoUpdate(UpdateItem<?> update, String oldLocation, String newLocation) {
return matchURLPattern(typicalBuildTimestampPattern, oldLocation, newLocation);
}
@Override
- public String getUpdateConfirmationMessage(UpdateItem update, String oldLocation, String newLocation) {
+ public String getUpdateConfirmationMessage(UpdateItem<?> update, String oldLocation, String newLocation) {
return NLS.bind("The new location \"{0}\" for project \"{1}\" is not like the current location \"{2}\". This could roll back to an older (obsolete) build.", new Object[] { newLocation, update.contribution.getLabel(), oldLocation });
}
}
@@ -451,7 +413,7 @@ public abstract class DependencyUpdater { private final Pattern typicalMilestonesPattern = Pattern.compile("\\d+\\.\\d+(milestones|interim)$"); //$NON-NLS-1$
@Override
- public boolean shouldAutoUpdate(UpdateItem update, String oldLocation, String newLocation) {
+ public boolean shouldAutoUpdate(UpdateItem<?> update, String oldLocation, String newLocation) {
boolean result = true; // Optimistically assume sameness if we can't find any milestones/interim segment
Matcher oldMatcher = typicalMilestonesPattern.matcher(oldLocation);
@@ -470,7 +432,7 @@ public abstract class DependencyUpdater { }
@Override
- public String getUpdateConfirmationMessage(UpdateItem update, String oldLocation, String newLocation) {
+ public String getUpdateConfirmationMessage(UpdateItem<?> update, String oldLocation, String newLocation) {
return NLS.bind("The current location \"{2}\" for project \"{1}\" provides interim builds. Updating from \"{0}\" could roll back to a previous milestone build.", new Object[] { newLocation, update.contribution.getLabel(), oldLocation });
}
}
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/MapUpdater.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/MapUpdater.java index a87968a4a6e..9542a606fd9 100644 --- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/MapUpdater.java +++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/MapUpdater.java @@ -22,7 +22,7 @@ import org.w3c.dom.Node; * These comments must appear before each "rm:uri" element which must be updated automatically, like this:
*
* <pre>
- * <!-- updateFrom("Eclipse", 0) --> + * <!-- updateFrom("Eclipse", 0) -->
* <rm:uri format="http://download.eclipse.org/eclipse/updates/4.2milestones/S-4.2M3-201110281100"/>
* </pre>
*
@@ -34,7 +34,7 @@ import org.w3c.dom.Node; *
* The second parameter is the index of the "repositories" element that must be used (in case there are several update sites defined on one contribution).
*/
-public class MapUpdater extends DependencyUpdater {
+public class MapUpdater extends XMLDependencyUpdater {
public MapUpdater() {
super();
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/OomphSetupUpdater.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/OomphSetupUpdater.java index f23caae4575..c0852df4589 100644 --- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/OomphSetupUpdater.java +++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/OomphSetupUpdater.java @@ -11,7 +11,7 @@ * Christian W. Damus (CEA) - Add support for updating Oomph setup models * Christian W. Damus - Add support for updating multiple development streams in a setup model * Christian W. Damus - Support updating of multiple selected files - * + * *****************************************************************************/ package org.eclipse.papyrus.releng.tools.internal.popup.actions; @@ -53,7 +53,7 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; -public class OomphSetupUpdater extends DependencyUpdater { +public class OomphSetupUpdater extends XMLDependencyUpdater { public static final String ANNOTATION_SOURCE = "http://www.eclipse.org/Papyrus/2014/releng/dependencytools";//$NON-NLS-1$ @@ -98,7 +98,7 @@ public class OomphSetupUpdater extends DependencyUpdater { NodeList details = annotation.getElementsByTagName("detail"); //$NON-NLS-1$ for (int i = 0; i < details.getLength(); i++) { Element next = (Element) details.item(i); - if (UPDATE_KEY.equals(next.getAttribute("key"))) { //$NON-NLS-1$ //$NON-NLS-2$ + if (UPDATE_KEY.equals(next.getAttribute("key"))) { //$NON-NLS-1$ String repoSpec = null; if (next.hasAttribute("value")) { //$NON-NLS-1$ repoSpec = next.getAttribute("value"); //$NON-NLS-1$ @@ -166,7 +166,7 @@ public class OomphSetupUpdater extends DependencyUpdater { // Use EMF resource serialization to format the file in the EMF style ResourceSet rset = new ResourceSetImpl(); Resource resource = rset.createResource(URI.createFileURI(destination.getAbsolutePath())); - Map<Object, Object> options = new HashMap<Object, Object>(); + Map<Object, Object> options = new HashMap<>(); options.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, true); options.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true); ((XMLResource) resource).load(document, options); @@ -185,7 +185,7 @@ public class OomphSetupUpdater extends DependencyUpdater { return result; } - final Set<String> repositoryLists = new LinkedHashSet<String>(); + final Set<String> repositoryLists = new LinkedHashSet<>(); try (InputStream input = setupFile.getContents()) { SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/PomPropertiesUpdater.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/PomPropertiesUpdater.java index ba3efab8074..250d38128a6 100644 --- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/PomPropertiesUpdater.java +++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/PomPropertiesUpdater.java @@ -16,7 +16,7 @@ import org.eclipse.core.resources.IFile; import org.w3c.dom.Node;
-public class PomPropertiesUpdater extends DependencyUpdater {
+public class PomPropertiesUpdater extends XMLDependencyUpdater {
public PomPropertiesUpdater() {
super();
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/PomUpdater.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/PomUpdater.java index 9dc7940558f..08594b886e9 100644 --- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/PomUpdater.java +++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/PomUpdater.java @@ -16,7 +16,7 @@ import org.eclipse.core.resources.IFile; import org.w3c.dom.Node;
-public class PomUpdater extends DependencyUpdater {
+public class PomUpdater extends XMLDependencyUpdater {
public PomUpdater() {
super();
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/TPDUpdater.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/TPDUpdater.java new file mode 100644 index 00000000000..496c62ebd5f --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/TPDUpdater.java @@ -0,0 +1,142 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.releng.tools.internal.popup.actions; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.xtext.TerminalRule; +import org.eclipse.xtext.nodemodel.ICompositeNode; +import org.eclipse.xtext.nodemodel.ILeafNode; +import org.eclipse.xtext.nodemodel.INode; +import org.eclipse.xtext.nodemodel.util.NodeModelUtils; + +import fr.obeo.releng.targetplatform.Location; +import fr.obeo.releng.targetplatform.TargetPlatform; + +/** + * @author Camille Letavernier + * + */ +public class TPDUpdater extends DependencyUpdater<Location> { + + private Resource currentTarget; + + /** + * @see org.eclipse.papyrus.releng.tools.internal.popup.actions.DependencyUpdater#canUpdate(org.eclipse.core.resources.IFile) + * + * @param file + * @return + */ + @Override + public boolean canUpdate(IFile file) { + return "tpd".equals(file.getFileExtension()); + } + + @Override + protected List<Location> getNodesToUpdate(IFile file) throws CoreException { + ResourceSet resourceSet = new ResourceSetImpl(); + + URI workspaceURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true); + + currentTarget = resourceSet.getResource(workspaceURI, true); + + for (EObject rootElement : currentTarget.getContents()) { + if (rootElement instanceof TargetPlatform) { + TargetPlatform tp = (TargetPlatform) rootElement; + return tp.getLocations(); + } + } + + return Collections.emptyList(); + } + + @Override + protected void save(IFile file) throws Exception { + currentTarget.save(null); + } + + @Override + protected String getCurrentLocation(Location uri) { + return uri.getUri(); + } + + @Override + protected void updateUri(Location uri, String location) { + uri.setUri(location); + } + + @Override + protected String getComment(Location location) { + List<String> comments = findCommentsAsString(location); + + for (String comment : comments) { + if (comment.contains("updateFrom")) { + return comment; + } + } + + return null; + } + + /** + * Expected structure: the Location contains a Multiline or Single line comment before the location keyword + * + * <pre> + * // A Comment + * /* Another Comment / + * location locID "http://locURL/repo" { + * installable.unit1.id + * installable.unit2.id + * } + * </pre> + * + * @param location + * @return + */ + protected List<String> findCommentsAsString(Location location) { + List<String> comments = new ArrayList<>(); + + INode grammarNode = NodeModelUtils.getNode(location); + if (grammarNode instanceof ICompositeNode) { + ICompositeNode compositeNode = (ICompositeNode) grammarNode; + for (INode child : compositeNode.getChildren()) { + if (child instanceof ILeafNode) { + ILeafNode leafNode = (ILeafNode) child; + if (leafNode.isHidden()) { + if (child.getGrammarElement() instanceof TerminalRule) { + TerminalRule rule = (TerminalRule) child.getGrammarElement(); + String name = rule.getName(); + if ("SL_COMMENT".equals(name) || "ML_COMMENT".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$ + String text = leafNode.getText(); + text = text.replaceAll("[\\*/]", "").trim(); // Remove all / and */, as the leafNode is the raw element + comments.add(text); + } + } + } + } + } + } + + return comments; + } + +} diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/XMLDependencyUpdater.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/XMLDependencyUpdater.java new file mode 100644 index 00000000000..873299151d2 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/XMLDependencyUpdater.java @@ -0,0 +1,133 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.releng.tools.internal.popup.actions; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; +import org.eclipse.papyrus.releng.tools.internal.Activator; +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Specialization of the DependencyAdapter for XML Documents + * + * @author Camille Letavernier + * + */ +public abstract class XMLDependencyUpdater extends DependencyUpdater<Node> { + + private Document currentDocument; + + protected abstract String getXpath(); + + @Override + protected List<Node> getNodesToUpdate(IFile file) throws CoreException { + File rmapFile = file.getLocation().toFile(); + + try { + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); + currentDocument = docBuilder.parse(rmapFile); + currentDocument.normalize(); + Element documentElement = currentDocument.getDocumentElement(); + + XPath xpath = XPathFactory.newInstance().newXPath(); + NodeList uris = (NodeList) xpath.evaluate(getXpath(), documentElement, XPathConstants.NODESET); + + List<Node> result = new ArrayList<>(uris.getLength()); + for (int i = 0; i < uris.getLength(); i++) { + result.add(uris.item(i)); + } + + return result; + } catch (OperationCanceledException ex) { + throw ex; + } catch (Exception ex) { + throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error updating map: " + ex.getLocalizedMessage(), ex)); //$NON-NLS-1$ + } + + + } + + @Override + protected String getComment(final Node node) { + Node comment = getPrecedingComment(node); + + return comment == null ? null : getCommentContent(comment); + } + + protected Node getPrecedingComment(Node node) { + Comment comment = null; + + Node previous = node.getPreviousSibling(); + while (previous != null) { + if (previous.getNodeType() == Node.COMMENT_NODE) { + comment = (Comment) previous; + break; + } else if (previous.getNodeType() != Node.TEXT_NODE) { + break; + } + previous = previous.getPreviousSibling(); + } + + return comment; + } + + protected String getCommentContent(Node comment) { + return comment.getTextContent(); + } + + /** + * @see org.eclipse.papyrus.releng.tools.internal.popup.actions.DependencyUpdater#save(org.eclipse.core.resources.IFile) + * + * @param file + */ + @Override + protected void save(IFile file) throws Exception { + File destination = file.getLocation().toFile(); + + save(currentDocument, destination); + } + + protected void save(Document document, File destination) throws Exception { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ + + StreamResult result = new StreamResult(destination); + DOMSource source = new DOMSource(currentDocument); + transformer.transform(source, result); + } + +} |