Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2014-09-11 14:47:46 -0400
committerChristian W. Damus2014-09-11 20:47:19 -0400
commit0462488d67ad8ba3acdfab5f43bb752ee6d58654 (patch)
treeb0fe7281b4e47a9c2413e81cc8d4e4108eca04d8 /plugins/developer/org.eclipse.papyrus.releng.tools
parent63efad3385885383b86892e0a379d10d8a8f1f68 (diff)
downloadorg.eclipse.papyrus-0462488d67ad8ba3acdfab5f43bb752ee6d58654.tar.gz
org.eclipse.papyrus-0462488d67ad8ba3acdfab5f43bb752ee6d58654.tar.xz
org.eclipse.papyrus-0462488d67ad8ba3acdfab5f43bb752ee6d58654.zip
[Releng] Add support for Oomph setup models to the B3Aggr-based dependency updater tool
Support annotations on targlet repository elements with source like updateFrom:<component-name>:<repo-index> to update dependency repository URLs automatically.
Diffstat (limited to 'plugins/developer/org.eclipse.papyrus.releng.tools')
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml27
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateOomphSetupHandler.java77
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/DependencyUpdater.java57
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/OomphSetupUpdater.java74
4 files changed, 213 insertions, 22 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml b/plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml
index e33d623e45e..5e027451da1 100644
--- a/plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml
+++ b/plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?> <!--
- Copyright (c) 2011-2014 Mia-Software, CEA LIST.
+ Copyright (c) 2011, 2014 Mia-Software, 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
@@ -9,6 +9,7 @@
Contributors:
Nicolas Bros (Mia-Software) - initial API and implementation
Camille Letavernier (CEA LIST) - Reimplement with Eclipse Menu/Handlers
+ Christian W. Damus (CEA) - Add support for updating Oomph setup models
-->
<plugin>
@@ -55,6 +56,25 @@
</iterate>
</visibleWhen>
</command>
+ <command
+ commandId="org.eclipse.papyrus.releng.tools.updateOomphSetup"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <iterate
+ operator="or">
+ <adapt
+ type="org.eclipse.core.resources.IFile">
+ <or>
+ <test
+ property="org.eclipse.core.resources.extension"
+ value="setup">
+ </test>
+ </or>
+ </adapt>
+ </iterate>
+ </visibleWhen>
+ </command>
</menuContribution>
</extension>
<extension
@@ -69,6 +89,11 @@
id="org.eclipse.papyrus.releng.tools.updatePom"
name="Update POM from Aggregation Build Model">
</command>
+ <command
+ defaultHandler="org.eclipse.papyrus.releng.tools.internal.handler.UpdateOomphSetupHandler"
+ id="org.eclipse.papyrus.releng.tools.updateOomphSetup"
+ name="Update Setup from Aggregation Build Model">
+ </command>
</extension>
</plugin>
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateOomphSetupHandler.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateOomphSetupHandler.java
new file mode 100644
index 00000000000..865c844c43f
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateOomphSetupHandler.java
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - Add support for updating Oomph setup models
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.releng.tools.internal.handler;
+
+import org.eclipse.b3.aggregator.Aggregation;
+import org.eclipse.b3.aggregator.AggregatorPackage;
+import org.eclipse.b3.aggregator.Contribution;
+import org.eclipse.b3.aggregator.transformer.TransformationManager;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.EList;
+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.jface.dialogs.MessageDialog;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.releng.tools.internal.Activator;
+import org.eclipse.papyrus.releng.tools.internal.Messages;
+import org.eclipse.papyrus.releng.tools.internal.popup.actions.OomphSetupUpdater;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class UpdateOomphSetupHandler extends AbstractDependencyHandler {
+
+ @Override
+ protected void updateFile(IFile setupFile, IFile aggregationBuildFile, Shell activeShell) throws CoreException {
+
+ // make sure the EPackage is initialized
+ AggregatorPackage.eINSTANCE.getEFactoryInstance();
+ URI uri = URI.createPlatformResourceURI(aggregationBuildFile.getFullPath().toString(), true);
+
+ final ResourceSet resourceSet = new ResourceSetImpl();
+ Resource resource = null;
+ try {
+ // with the latest version of the metamodel
+ resource = resourceSet.getResource(uri, true);
+ resource.load(null);
+ } catch (Exception e) {
+ // with an older version of the metamodel
+ try {
+ TransformationManager transformationManager = new TransformationManager(uri);
+ resource = transformationManager.transformResource(true);
+ } catch (Exception e1) {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error loading b3aggr. Make sure you have the latest version of B3 installed. : " + e.getLocalizedMessage(), e1)); //$NON-NLS-1$
+ }
+ }
+
+ if (resource.getContents().size() == 0) {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "The b3aggr resource is empty")); //$NON-NLS-1$
+ }
+
+ EObject root = resource.getContents().get(0);
+ if (root instanceof Aggregation) {
+ Aggregation aggregation = (Aggregation) root;
+ EList<Contribution> allContributions = aggregation.getAllContributions(true);
+ OomphSetupUpdater setupUpdater = new OomphSetupUpdater(setupFile, allContributions);
+ setupUpdater.updateDocument();
+ }
+
+ MessageDialog.openInformation(activeShell, Messages.UpdateRMapAction_mapWasUpdatedTitle, NLS.bind(Messages.UpdateRMapAction_mapWasUpdated, setupFile.getFullPath().toString(), aggregationBuildFile.getFullPath().toString()));
+ }
+}
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 8eb83b6da09..9020eb3c20e 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 - 2014 Mia-Software, CEA LIST.
+ * Copyright (c) 2011, 2014 Mia-Software, CEA LIST.
* 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
@@ -8,6 +8,8 @@
* Contributors:
* Nicolas Bros (Mia-Software) - Bug 366567 - [Releng] Tool to update rmaps
* Camille Letavernier (CEA LIST) - Generalize to support POMs
+ * Christian W. Damus (CEA) - Add support for updating Oomph setup models
+ *
*******************************************************************************/
package org.eclipse.papyrus.releng.tools.internal.popup.actions;
@@ -45,6 +47,8 @@ import org.w3c.dom.NodeList;
public abstract class DependencyUpdater {
+ private final Pattern commentPattern = Pattern.compile("updateFrom\\s*\\(\\s*\"(.*?)\"\\s*,\\s*(\\d+)\\s*\\)"); //$NON-NLS-1$
+
protected final IFile fMapFile;
protected final EList<Contribution> contributions;
@@ -67,21 +71,20 @@ public abstract class DependencyUpdater {
Element documentElement = doc.getDocumentElement();
XPath xpath = XPathFactory.newInstance().newXPath();
- NodeList uris = (NodeList)xpath.evaluate(getXpath(), documentElement, XPathConstants.NODESET);
+ NodeList uris = (NodeList) xpath.evaluate(getXpath(), documentElement, XPathConstants.NODESET);
- for(int i = 0; i < uris.getLength(); i++) {
+ for (int i = 0; i < uris.getLength(); i++) {
Node uri = uris.item(i);
- Comment precedingComment = getPrecedingComment(uri);
- if(precedingComment != null) {
- String comment = precedingComment.getTextContent();
- Pattern pattern = Pattern.compile("updateFrom\\s*\\(\\s*\"(.*?)\"\\s*,\\s*(\\d+)\\s*\\)"); //$NON-NLS-1$
- Matcher matcher = pattern.matcher(comment);
- if(matcher.find()) {
+ Node precedingComment = getPrecedingComment(uri);
+ if (precedingComment != null) {
+ String comment = getCommentContent(precedingComment);
+ Matcher matcher = getCommentPattern().matcher(comment);
+ if (matcher.find()) {
String contributionName = matcher.group(1);
int repositoryIndex = Integer.parseInt(matcher.group(2));
updateWithContribution(uri, contributionName, repositoryIndex);
- } else if(comment.contains("updateFrom")) { //$NON-NLS-1$
- throw new Exception("Wrong syntax for 'updateFrom' : should be updateFrom(\"<contributionName>\",<index>)"); //$NON-NLS-1$
+ } else if (comment.contains("updateFrom")) { //$NON-NLS-1$
+ throw new Exception("Wrong syntax for 'updateFrom' : should be " + getCommentSyntax()); //$NON-NLS-1$
}
}
}
@@ -102,13 +105,13 @@ public abstract class DependencyUpdater {
protected void updateWithContribution(final Node uri, final String contributionName, final int repositoryIndex) {
Contribution contribution = findContribution(contributionName);
- if(contribution == null) {
+ if (contribution == null) {
throw new RuntimeException("'updateFrom' failed: cannot find contribution with label \"" + contributionName + "\""); //$NON-NLS-1$ //$NON-NLS-2$
}
EList<MappedRepository> repositories = contribution.getRepositories();
- if(repositoryIndex >= repositories.size()) {
+ if (repositoryIndex >= repositories.size()) {
throw new RuntimeException("wrong index in updateFrom(\"" + contributionName + "\"" + repositoryIndex //$NON-NLS-1$ //$NON-NLS-2$
- + ") : there are " + repositories.size() + " contributions"); //$NON-NLS-1$ //$NON-NLS-2$
+ + ") : there are " + repositories.size() + " contributions"); //$NON-NLS-1$ //$NON-NLS-2$
}
String location = repositories.get(repositoryIndex).getLocation();
@@ -119,22 +122,22 @@ public abstract class DependencyUpdater {
protected Contribution findContribution(final String contributionName) {
Contribution matchingContribution = null;
- for(Contribution contribution : this.contributions) {
- if(contributionName.equalsIgnoreCase(contribution.getLabel())) {
+ for (Contribution contribution : this.contributions) {
+ if (contributionName.equalsIgnoreCase(contribution.getLabel())) {
matchingContribution = contribution;
}
}
return matchingContribution;
}
- protected Comment getPrecedingComment(final Node node) {
+ 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;
+ while (previous != null) {
+ if (previous.getNodeType() == Node.COMMENT_NODE) {
+ comment = (Comment) previous;
break;
- } else if(previous.getNodeType() != Node.TEXT_NODE) {
+ } else if (previous.getNodeType() != Node.TEXT_NODE) {
break;
}
previous = previous.getPreviousSibling();
@@ -142,6 +145,18 @@ public abstract class DependencyUpdater {
return comment;
}
+ 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();
}
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
new file mode 100644
index 00000000000..4fb438e9db1
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/OomphSetupUpdater.java
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - Add support for updating Oomph setup models
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.releng.tools.internal.popup.actions;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.b3.aggregator.Contribution;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.EList;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+
+public class OomphSetupUpdater extends DependencyUpdater {
+
+ private final Pattern annotationPattern = Pattern.compile("updateFrom:([^:]+):(\\d+)"); //$NON-NLS-1$
+
+ public OomphSetupUpdater(final IFile mapFile, final EList<Contribution> contributions) {
+ super(mapFile, contributions);
+ }
+
+ @Override
+ protected Pattern getCommentPattern() {
+ return annotationPattern;
+ }
+
+ @Override
+ protected String getCommentContent(Node comment) {
+ return ((Element) comment).getAttribute("source"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected String getCommentSyntax() {
+ return "updateFrom:<contributionName>:<index>"; //$NON-NLS-1$
+ }
+
+ @Override
+ protected Node getPrecedingComment(Node node) {
+ Element result = null;
+
+ for (Node next = node.getFirstChild(); next != null; next = next.getNextSibling()) {
+ if (next.getNodeType() == Node.ELEMENT_NODE) {
+ if ("annotation".equals(next.getNodeName())) { //$NON-NLS-1$
+ result = (Element) next;
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ protected String getXpath() {
+ return "//setupTask[@type='setup.targlets:TargletTask']/targlet/repositoryList/repository";
+ }
+
+ @Override
+ protected void updateUri(Node uri, String location) {
+ uri.getAttributes().getNamedItem("url").setTextContent(location); //$NON-NLS-1$
+ }
+
+}

Back to the top