Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2015-02-09 11:54:34 -0500
committerChristian W. Damus2015-02-09 12:02:18 -0500
commit60b36a12adba97cf474b5cd9c3cfa1b3f3067b1d (patch)
tree9f32960b9b4bfebe74bac4c777cab0f184244646 /plugins/developer/org.eclipse.papyrus.releng.tools
parent240b94e8eb546a35bf6769cb9283ff6b59eca784 (diff)
downloadorg.eclipse.papyrus-60b36a12adba97cf474b5cd9c3cfa1b3f3067b1d.tar.gz
org.eclipse.papyrus-60b36a12adba97cf474b5cd9c3cfa1b3f3067b1d.tar.xz
org.eclipse.papyrus-60b36a12adba97cf474b5cd9c3cfa1b3f3067b1d.zip
[Releng] Updating dependencies in multiple files
Enhance the dependency updater tool to support updating dependencies in multiple selected files. A single command handler now dispatches to concrete DependencyUpdaters discovered automatically from the classpath. Also added a check to prompt the user when updating a dependency with a URL that looks quite different, in case it might be rolling back an integration build to a previous stable build or something other suspicious change. The user is only prompted once per dependency (the same decision applied to all selected files).
Diffstat (limited to 'plugins/developer/org.eclipse.papyrus.releng.tools')
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/META-INF/MANIFEST.MF3
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml59
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/AbstractDependencyHandler.java111
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/AddSetupRepositoryUpdateAnnotationHandler.java5
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateDependenciesHandler.java241
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateMapHandler.java77
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateOomphSetupHandler.java168
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdatePOMHandler.java76
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/messages.properties5
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/DependencyUpdater.java89
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/MapUpdater.java26
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/OomphSetupUpdater.java129
-rw-r--r--plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/popup/actions/PomUpdater.java21
13 files changed, 482 insertions, 528 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 85a79784b47..ba96ddac965 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
@@ -7,7 +7,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.b3.aggregator.legacy;bundle-version="0.2.0",
org.eclipse.oomph.setup.targlets;bundle-version="1.0.0";resolution:=optional,
org.eclipse.oomph.p2;bundle-version="1.0.0",
- org.eclipse.emf.edit;bundle-version="2.10.0";resolution:=optional
+ org.eclipse.emf.edit;bundle-version="2.10.0";resolution:=optional,
+ com.google.guava;bundle-version="11.0.0"
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.1.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 76894f6ecb2..8e0d7186bf6 100644
--- a/plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml
+++ b/plugins/developer/org.eclipse.papyrus.releng.tools/plugin.xml
@@ -19,53 +19,24 @@
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
- commandId="org.eclipse.papyrus.releng.tools.updateRmap"
- style="push">
- <visibleWhen
- checkEnabled="false">
- <iterate
- operator="or">
- <adapt
- type="org.eclipse.core.resources.IFile">
- <or>
- <test
- property="org.eclipse.core.resources.extension"
- value="rmap">
- </test>
- </or>
- </adapt>
- </iterate>
- </visibleWhen>
- </command>
- <command
- commandId="org.eclipse.papyrus.releng.tools.updatePom"
+ commandId="org.eclipse.papyrus.releng.tools.updateDependencies"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
- operator="or">
+ ifEmpty="false"
+ operator="and">
<adapt
type="org.eclipse.core.resources.IFile">
<or>
<test
+ property="org.eclipse.core.resources.extension"
+ value="rmap">
+ </test>
+ <test
property="org.eclipse.core.resources.name"
value="*pom*.xml">
</test>
- </or>
- </adapt>
- </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">
@@ -92,19 +63,9 @@
<extension
point="org.eclipse.ui.commands">
<command
- defaultHandler="org.eclipse.papyrus.releng.tools.internal.handler.UpdateMapHandler"
- id="org.eclipse.papyrus.releng.tools.updateRmap"
- name="Update RMap from Aggregation Build Model">
- </command>
- <command
- defaultHandler="org.eclipse.papyrus.releng.tools.internal.handler.UpdatePOMHandler"
- 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">
+ defaultHandler="org.eclipse.papyrus.releng.tools.internal.handler.UpdateDependenciesHandler"
+ id="org.eclipse.papyrus.releng.tools.updateDependencies"
+ name="Update Dependencies from Aggregation Build Model">
</command>
<command
defaultHandler="org.eclipse.papyrus.releng.tools.internal.handler.AddSetupRepositoryUpdateAnnotationHandler"
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/AbstractDependencyHandler.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/AbstractDependencyHandler.java
deleted file mode 100644
index 8ad5ca7d72e..00000000000
--- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/AbstractDependencyHandler.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Bros (Mia-Software) - Bug 366567 - [Releng] Tool to update rmaps
- * Camille Letavernier (CEA LIST) - camille.letavernier@cea.fr - Generalize to handle POMs
- * Christian W. Damus (CEA) - Add support for updating Oomph setup models
- *
- *******************************************************************************/
-package org.eclipse.papyrus.releng.tools.internal.handler;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.papyrus.releng.tools.internal.Activator;
-import org.eclipse.papyrus.releng.tools.internal.Messages;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.dialogs.ElementListSelectionDialog;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-
-public abstract class AbstractDependencyHandler extends AbstractHandler {
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- Shell activeShell = HandlerUtil.getActiveShell(event);
- try {
- if(selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection)selection;
- Object selected = structuredSelection.getFirstElement();
- if(selected instanceof IFile) {
- IFile file = (IFile)selected;
- List<IFile> aggregationBuildFiles = findAggregationBuildFiles();
- IFile aggregationBuildFile = chooseAggregationBuildFile(aggregationBuildFiles, activeShell);
- if(aggregationBuildFile != null) {
- updateFile(file, aggregationBuildFile, activeShell);
- }
- }
- }
- } catch (Exception e) {
- Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error", e)); //$NON-NLS-1$
- MessageDialog.openError(activeShell, Messages.UpdateRMapAction_error, e.getLocalizedMessage());
- }
-
- return null;
- }
-
- protected static List<IFile> findAggregationBuildFiles() throws CoreException {
- List<IFile> aggregationBuildFiles = new ArrayList<IFile>();
- IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- for(IProject project : projects) {
- if(!project.isOpen()) {
- continue;
- }
- IResource[] members = project.members();
- for(IResource resource : members) {
- if(resource.getType() == IResource.FILE && resource.getName().endsWith(".b3aggr")) { //$NON-NLS-1$
- aggregationBuildFiles.add((IFile)resource);
- }
- }
- }
- return aggregationBuildFiles;
- }
-
- protected static IFile chooseAggregationBuildFile(final List<IFile> aggregationBuildFiles, Shell activeShell) {
- if(aggregationBuildFiles.size() == 0) {
- MessageDialog.openWarning(activeShell, Messages.UpdateRMapAction_noBuildModelFound, Messages.UpdateRMapAction_noBuildModelFoundLong);
- return null;
- }
- LabelProvider labelProvider = new LabelProvider() {
-
- @Override
- public String getText(final Object element) {
- if(element instanceof IFile) {
- IFile file = (IFile)element;
- return file.getProject().getName() + "/" + file.getName(); //$NON-NLS-1$
- }
- return super.getText(element);
- }
- };
-
- ElementListSelectionDialog dialog = new ElementListSelectionDialog(activeShell, labelProvider);
- dialog.setTitle(Messages.UpdateRMapAction_chooseBuildModel);
- dialog.setMessage(Messages.UpdateRMapAction_chooseBuildModelLong);
- dialog.setElements(aggregationBuildFiles.toArray());
- dialog.open();
- return (IFile)dialog.getFirstResult();
- }
-
- protected abstract void updateFile(IFile selectedFile, IFile aggregationBuildFile, Shell activeShell) throws CoreException;
-
-}
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/AddSetupRepositoryUpdateAnnotationHandler.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/AddSetupRepositoryUpdateAnnotationHandler.java
index 11c8fe2c32a..02b1024449e 100644
--- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/AddSetupRepositoryUpdateAnnotationHandler.java
+++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/AddSetupRepositoryUpdateAnnotationHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST and others.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Christian W. Damus - Support updating of multiple selected files
*
*****************************************************************************/
@@ -76,7 +77,7 @@ public class AddSetupRepositoryUpdateAnnotationHandler extends AbstractHandler {
Shell activeShell = HandlerUtil.getActiveShell(event);
try {
- IFile aggrFile = AbstractDependencyHandler.chooseAggregationBuildFile(AbstractDependencyHandler.findAggregationBuildFiles(), activeShell);
+ IFile aggrFile = UpdateDependenciesHandler.chooseAggregationBuildFile(UpdateDependenciesHandler.findAggregationBuildFiles(), activeShell);
if (aggrFile != null) {
ResourceSet rset = new ResourceSetImpl();
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
new file mode 100644
index 00000000000..d48ac99e1f4
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateDependenciesHandler.java
@@ -0,0 +1,241 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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:
+ * Nicolas Bros (Mia-Software) - Bug 366567 - [Releng] Tool to update rmaps
+ * Camille Letavernier (CEA LIST) - camille.letavernier@cea.fr - Generalize to handle POMs
+ * Christian W. Damus (CEA) - Add support for updating Oomph setup models
+ * Christian W. Damus - Support updating of multiple selected files
+ *
+ *******************************************************************************/
+package org.eclipse.papyrus.releng.tools.internal.handler;
+
+import java.lang.reflect.Modifier;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.b3.aggregator.Aggregation;
+import org.eclipse.b3.aggregator.AggregatorPackage;
+import org.eclipse.b3.aggregator.transformer.TransformationManager;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+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.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+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.DependencyUpdater;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.osgi.framework.Bundle;
+
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+
+public class UpdateDependenciesHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ Shell activeShell = HandlerUtil.getActiveShell(event);
+ List<IFile> updated = Lists.newArrayListWithExpectedSize(4);
+ IFile aggregationBuildFile = null;
+
+ try {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ List<IFile> files = ImmutableList.copyOf(Iterables.filter(structuredSelection.toList(), IFile.class));
+ if (!files.isEmpty()) {
+ List<IFile> aggregationBuildFiles = findAggregationBuildFiles();
+ aggregationBuildFile = chooseAggregationBuildFile(aggregationBuildFiles, activeShell);
+ if (aggregationBuildFile != null) {
+ Aggregation aggregation = loadAggregationModel(aggregationBuildFile);
+ if (aggregation != null) {
+ Map<Object, Object> context = Maps.newHashMap();
+ for (IFile file : files) {
+ if (updateFile(file, aggregation, activeShell, context)) {
+ updated.add(file);
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error", e)); //$NON-NLS-1$
+ MessageDialog.openError(activeShell, Messages.UpdateRMapAction_error, e.getLocalizedMessage());
+ }
+
+ if (updated.isEmpty()) {
+ MessageDialog.openInformation(activeShell, "No Files Updated", "No files were updated for new dependencies.");
+ } else {
+ String fileList = Joiner.on(", ").join(Iterables.transform(updated, new Function<IFile, IPath>() {
+ @Override
+ public IPath apply(IFile input) {
+ return input.getFullPath();
+ }
+ }));
+ MessageDialog.openInformation(activeShell, Messages.UpdateRMapAction_mapWasUpdatedTitle, NLS.bind(Messages.UpdateRMapAction_mapWasUpdated, fileList, aggregationBuildFile.getFullPath().toString()));
+ }
+
+ return null;
+ }
+
+ protected static List<IFile> findAggregationBuildFiles() throws CoreException {
+ List<IFile> aggregationBuildFiles = new ArrayList<IFile>();
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (IProject project : projects) {
+ if (!project.isOpen()) {
+ continue;
+ }
+ IResource[] members = project.members();
+ for (IResource resource : members) {
+ if (resource.getType() == IResource.FILE && resource.getName().endsWith(".b3aggr")) { //$NON-NLS-1$
+ aggregationBuildFiles.add((IFile) resource);
+ }
+ }
+ }
+ return aggregationBuildFiles;
+ }
+
+ protected static IFile chooseAggregationBuildFile(final List<IFile> aggregationBuildFiles, Shell activeShell) {
+ if (aggregationBuildFiles.size() == 0) {
+ MessageDialog.openWarning(activeShell, Messages.UpdateRMapAction_noBuildModelFound, Messages.UpdateRMapAction_noBuildModelFoundLong);
+ return null;
+ }
+ LabelProvider labelProvider = new LabelProvider() {
+
+ @Override
+ public String getText(final Object element) {
+ if (element instanceof IFile) {
+ IFile file = (IFile) element;
+ return file.getProject().getName() + "/" + file.getName(); //$NON-NLS-1$
+ }
+ return super.getText(element);
+ }
+ };
+
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(activeShell, labelProvider);
+ dialog.setTitle(Messages.UpdateRMapAction_chooseBuildModel);
+ dialog.setMessage(Messages.UpdateRMapAction_chooseBuildModelLong);
+ dialog.setElements(aggregationBuildFiles.toArray());
+ dialog.open();
+ return (IFile) dialog.getFirstResult();
+ }
+
+ protected static Aggregation loadAggregationModel(IFile aggregationBuildFile) throws CoreException {
+ Aggregation result = null;
+
+ // 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) {
+ result = (Aggregation) root;
+ } else {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "The b3aggr resource does not contain an aggregation model")); //$NON-NLS-1$
+ }
+
+ return result;
+ }
+
+ protected boolean updateFile(IFile selectedFile, Aggregation aggregationModel, Shell activeShell, Map<Object, Object> context) throws CoreException {
+ boolean result = false;
+
+ DependencyUpdater updater = findDependencyUpdater(selectedFile);
+ if (updater != null) {
+ updater.updateDocument(activeShell, selectedFile, aggregationModel.getAllContributions(true), context);
+ result = true;
+ }
+
+ return result;
+ }
+
+ protected DependencyUpdater findDependencyUpdater(IFile mapFile) throws CoreException {
+ final String path = "org/eclipse/papyrus/releng/tools/internal/popup/actions/"; //$NON-NLS-1$
+ DependencyUpdater result = null;
+ Bundle bundle = Activator.getDefault().getBundle();
+
+ // Try dev mode, first
+ Enumeration<URL> urls = bundle.findEntries("bin/" + path, "*.class", false);
+ if (urls == null) {
+ // Deployed mode
+ urls = bundle.findEntries(path, "*.class", false);
+ }
+
+ while (urls.hasMoreElements()) {
+ URL classURL = urls.nextElement();
+ URI classURI = URI.createURI(classURL.toExternalForm(), true);
+
+ try {
+ String className = classURI.trimFileExtension().lastSegment();
+ if (!"DependencyUpdater".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();
+ if (updater.canUpdate(mapFile)) {
+ result = updater;
+ break;
+ }
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ 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));
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateMapHandler.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateMapHandler.java
deleted file mode 100644
index 3b3f437f73e..00000000000
--- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateMapHandler.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*******************************************************************************
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Bros (Mia-Software) - Bug 366567 - [Releng] Tool to update rmaps
- * Camille Letavernier (CEA LIST) - camille.letavernier@cea.fr - Reimplement as a Handler
- *******************************************************************************/
-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.MapUpdater;
-import org.eclipse.swt.widgets.Shell;
-
-
-/* Reimplemented from org.eclipse.papyrus.releng.tools.internal.popup.actions.UpdateRMapAction */
-public class UpdateMapHandler extends AbstractDependencyHandler {
-
- @Override
- protected void updateFile(final IFile mapFile, final 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);
- MapUpdater mapUpdater = new MapUpdater(mapFile, allContributions);
- mapUpdater.updateDocument();
- }
-
- MessageDialog.openInformation(activeShell, Messages.UpdateRMapAction_mapWasUpdatedTitle, NLS.bind(Messages.UpdateRMapAction_mapWasUpdated, mapFile.getFullPath().toString(), aggregationBuildFile.getFullPath().toString()));
- }
-
-}
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
deleted file mode 100644
index 96681f953ee..00000000000
--- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdateOomphSetupHandler.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST, Christian W. Damus, 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
- * Christian W. Damus - Add support for updating multiple development streams in a setup model
- *
- *****************************************************************************/
-package org.eclipse.papyrus.releng.tools.internal.handler;
-
-import java.io.InputStream;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-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.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-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;
-import org.eclipse.ui.dialogs.ListDialog;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-
-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);
-
- String streamName = promptForStreamName(activeShell, setupFile);
- if (streamName == null) {
- // Cancel
- return;
- }
-
- OomphSetupUpdater setupUpdater = new OomphSetupUpdater(setupFile, allContributions, streamName);
- setupUpdater.updateDocument();
- }
-
- MessageDialog.openInformation(activeShell, Messages.UpdateRMapAction_mapWasUpdatedTitle, NLS.bind(Messages.UpdateRMapAction_mapWasUpdated, setupFile.getFullPath().toString(), aggregationBuildFile.getFullPath().toString()));
- }
-
- protected String promptForStreamName(Shell parentShell, IFile setupFile) throws CoreException {
- final Set<String> repositoryLists = new LinkedHashSet<String>();
-
- try (InputStream input = setupFile.getContents()) {
- SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
- parser.parse(input, new DefaultHandler() {
- int inTarglet;
- String repositoryListName;
- boolean foundAnnotation;
-
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- if ("targlet".equals(qName)) { //$NON-NLS-1$
- if ((inTarglet > 0) || "${eclipse.target.platform}".equals(attributes.getValue("activeRepositoryList"))) { //$NON-NLS-1$ //$NON-NLS-2$
- // This is a stream-switching targlet. Get its repository names
- inTarglet++;
- }
- } else if ((inTarglet > 0) && "repositoryList".equals(qName)) {
- String listName = attributes.getValue("name"); //$NON-NLS-1$
- if (listName != null && !listName.isEmpty()) {
- repositoryListName = listName;
- foundAnnotation = false;
- }
- } else if ("annotation".equals(qName) && OomphSetupUpdater.ANNOTATION_SOURCE.equals(attributes.getValue("source"))) { //$NON-NLS-1$ //$NON-NLS-2$
- foundAnnotation = true;
- }
- }
-
- @Override
- public void endElement(String uri, String localName, String qName) throws SAXException {
- if ("targlet".equals(qName)) { //$NON-NLS-1$
- inTarglet = Math.max(inTarglet - 1, 0);
- } else if ("repositoryList".equals(qName) && (repositoryListName != null)) { //$NON-NLS-1$
- if (foundAnnotation) {
- repositoryLists.add(repositoryListName);
- }
- repositoryListName = null;
- foundAnnotation = false;
- }
- }
- });
- } catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to scan setup model for available streams.", e));
- }
-
- if (repositoryLists.isEmpty()) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No streams are defined in the selected setup model."));
- }
-
- String first = repositoryLists.iterator().next();
- if (repositoryLists.size() == 1) {
- return first;
- }
-
- ILabelProvider labels = new LabelProvider();
- ListDialog dlg = new ListDialog(parentShell);
- dlg.setContentProvider(ArrayContentProvider.getInstance());
- dlg.setLabelProvider(labels);
- dlg.setInput(repositoryLists);
- dlg.setInitialSelections(new Object[] { repositoryLists.iterator().next() });
- dlg.setTitle("Select Stream");
- dlg.setMessage("Select the development stream to update.");
- labels.dispose();
-
- dlg.open();
- Object[] result = dlg.getResult();
- return ((result == null) || (result.length == 0)) ? null : (String) result[0];
- }
-}
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdatePOMHandler.java b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdatePOMHandler.java
deleted file mode 100644
index 1906482eb52..00000000000
--- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/handler/UpdatePOMHandler.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-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.PomUpdater;
-import org.eclipse.swt.widgets.Shell;
-
-
-public class UpdatePOMHandler extends AbstractDependencyHandler {
-
- @Override
- protected void updateFile(IFile pomFile, 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);
- PomUpdater pomUpdater = new PomUpdater(pomFile, allContributions);
- pomUpdater.updateDocument();
- }
-
- MessageDialog.openInformation(activeShell, Messages.UpdateRMapAction_mapWasUpdatedTitle, NLS.bind(Messages.UpdateRMapAction_mapWasUpdated, pomFile.getFullPath().toString(), aggregationBuildFile.getFullPath().toString()));
- }
-
-}
diff --git a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/messages.properties b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/messages.properties
index c6ddaf9a805..962818b2d05 100644
--- a/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/messages.properties
+++ b/plugins/developer/org.eclipse.papyrus.releng.tools/src/org/eclipse/papyrus/releng/tools/internal/messages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2011 Mia-Software.
+# Copyright (c) 2011, 2015 Mia-Software, Christian W. Damus, 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
@@ -7,10 +7,11 @@
#
# Contributors:
# Nicolas Bros (Mia-Software) - Bug 366567 - [Releng] Tool to update rmaps
+# Christian W. Damus - Support updating of multiple selected files
###############################################################################
UpdateRMapAction_mapWasUpdatedTitle=Papyrus Releng Tools
UpdateRMapAction_chooseBuildModel=Choose build model
-UpdateRMapAction_chooseBuildModelLong=Select the build model with which to update the map:
+UpdateRMapAction_chooseBuildModelLong=Select the build model with which to update dependencies:
UpdateRMapAction_error=Error
UpdateRMapAction_mapWasUpdated=The dependencies in {0}\nwere updated from {1}.
UpdateRMapAction_noBuildModelFound=No build model found
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 9b094c0f37d..084f33624e2 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, 2015 Mia-Software, CEA LIST, Christian W. Damus, 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,11 +9,13 @@
* 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
+ * Christian W. Damus - Support updating of multiple selected files
*
*******************************************************************************/
package org.eclipse.papyrus.releng.tools.internal.popup.actions;
import java.io.File;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -37,7 +39,10 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.releng.tools.internal.Activator;
+import org.eclipse.swt.widgets.Shell;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -49,24 +54,23 @@ public abstract class DependencyUpdater {
private final Pattern commentPattern = Pattern.compile("updateFrom\\s*\\(\\s*\"(.*?)\"\\s*,\\s*(\\d+)\\s*\\)"); //$NON-NLS-1$
- protected final IFile fMapFile;
+ private final Pattern typicalBuildTimestampPattern = Pattern.compile("[NISMR](?:-\\d+\\.\\d+(?:\\.\\d+)?(?:M|RC)\\d[abcd]-)?20\\d\\d[-0-9]+"); //$NON-NLS-1$
- protected final EList<Contribution> contributions;
-
- public DependencyUpdater(final IFile mapFile, final EList<Contribution> contributions) {
- this.fMapFile = mapFile;
- this.contributions = contributions;
+ public DependencyUpdater() {
+ super();
}
protected static final String PREFIX = "http://download.eclipse.org/"; //$NON-NLS-1$
- public void updateDocument() throws CoreException {
+ public abstract boolean canUpdate(IFile file);
+
+ public void updateDocument(final Shell parentShell, final IFile mapFile, final EList<Contribution> contributions, final Map<Object, Object> context) throws CoreException {
try {
- File mapFile = this.fMapFile.getLocation().toFile();
+ File rmapFile = mapFile.getLocation().toFile();
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
- Document doc = docBuilder.parse(mapFile);
+ Document doc = docBuilder.parse(rmapFile);
doc.normalize();
Element documentElement = doc.getDocumentElement();
@@ -82,16 +86,20 @@ public abstract class DependencyUpdater {
if (matcher.find()) {
String contributionName = matcher.group(1);
int repositoryIndex = Integer.parseInt(matcher.group(2));
- updateWithContribution(uri, contributionName, repositoryIndex);
+ Contribution contribution = findContribution(contributions, contributionName);
+ if (contribution == null) {
+ throw new RuntimeException("'updateFrom' failed: cannot find contribution with label \"" + contributionName + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ updateWithContribution(parentShell, uri, contribution, repositoryIndex, context);
} else if (comment.contains("updateFrom")) { //$NON-NLS-1$
throw new Exception("Wrong syntax for 'updateFrom' : should be " + getCommentSyntax()); //$NON-NLS-1$
}
}
}
- save(doc, mapFile);
+ save(doc, rmapFile);
- this.fMapFile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
+ mapFile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error updating map: " + e.getLocalizedMessage(), e)); //$NON-NLS-1$
@@ -107,26 +115,30 @@ public abstract class DependencyUpdater {
transformer.transform(source, result);
}
- protected void updateWithContribution(final Node uri, final String contributionName, final int repositoryIndex) {
- Contribution contribution = findContribution(contributionName);
- if (contribution == null) {
- throw new RuntimeException("'updateFrom' failed: cannot find contribution with label \"" + contributionName + "\""); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ protected void updateWithContribution(final Shell parentShell, final Node 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(\"" + contributionName + "\"" + repositoryIndex //$NON-NLS-1$ //$NON-NLS-2$
+ throw new RuntimeException("wrong index in updateFrom(\"" + contribution.getLabel() + "\"" + repositoryIndex //$NON-NLS-1$ //$NON-NLS-2$
+ ") : there are " + repositories.size() + " contributions"); //$NON-NLS-1$ //$NON-NLS-2$
}
String location = repositories.get(repositoryIndex).getLocation();
+ String current = getCurrentLocation(uri);
- updateUri(uri, location);
+ if ((current == null) || !current.equals(location)) {
+ if ((current == null) || current.isEmpty()
+ || isLocationSimilar(current, location) || promptToReplace(parentShell, contribution.getLabel(), current, location, context)) {
+ updateUri(uri, location);
+ }
+ }
}
+ protected abstract String getCurrentLocation(Node uri);
+
protected abstract void updateUri(Node uri, String location);
- protected Contribution findContribution(final String contributionName) {
+ protected Contribution findContribution(Iterable<? extends Contribution> contributions, final String contributionName) {
Contribution matchingContribution = null;
- for (Contribution contribution : this.contributions) {
+ for (Contribution contribution : contributions) {
if (contributionName.equalsIgnoreCase(contribution.getLabel())) {
matchingContribution = contribution;
}
@@ -163,4 +175,37 @@ public abstract class DependencyUpdater {
protected abstract String getXpath();
+ protected boolean isLocationSimilar(String oldLocation, String newLocation) {
+ boolean result = true; // Optimistically assume sameness if we can't find any build timestamps
+
+ Matcher oldMatcher = typicalBuildTimestampPattern.matcher(oldLocation);
+ Matcher newMatcher = typicalBuildTimestampPattern.matcher(newLocation);
+ boolean foundOld = oldMatcher.find();
+ boolean foundNew = newMatcher.find();
+
+ if (foundOld != foundNew) {
+ // definitely different
+ result = false;
+ } else if (foundNew) {
+ // Compare prefixes
+ String oldPrefix = oldLocation.substring(0, oldMatcher.start());
+ String newPrefix = newLocation.substring(0, newMatcher.start());
+ result = newPrefix.equals(oldPrefix);
+ }
+
+ return result;
+ }
+
+ protected boolean promptToReplace(Shell parentShell, String contributionName, String oldLocation, String newLocation, Map<Object, Object> context) {
+ String key = "$replace$::" + contributionName; //$NON-NLS-1$
+ Boolean result = (Boolean) context.get(key);
+
+ if (result == null) {
+ String message = NLS.bind("The new location \"{0}\" for project \"{1}\" is not like the current location \"{2}\". This could roll back to a previous (obsolete) version. Update anyways?", new Object[] { newLocation, contributionName, oldLocation });
+ result = MessageDialog.openQuestion(parentShell, "Confirm Location Update", message);
+ context.put(key, result);
+ }
+
+ return result;
+ }
}
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 f43b3f2bee2..a87968a4a6e 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 - 2014 Mia-Software, CEA LIST.
+ * Copyright (c) 2011, 2015 Mia-Software, CEA LIST, Christian W. Damus, 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
@@ -8,12 +8,11 @@
* Contributors:
* Nicolas Bros (Mia-Software) - Bug 366567 - [Releng] Tool to update rmaps
* Camille Letavernier (CEA LIST) - Generalize to support POMs
+ * Christian W. Damus - Support updating of multiple selected files
*******************************************************************************/
package org.eclipse.papyrus.releng.tools.internal.popup.actions;
-import org.eclipse.b3.aggregator.Contribution;
import org.eclipse.core.resources.IFile;
-import org.eclipse.emf.common.util.EList;
import org.w3c.dom.Node;
/**
@@ -33,23 +32,32 @@ import org.w3c.dom.Node;
* &lt;aggregator:Contribution ... label="xxx"&gt;
* </pre>
*
- * 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).
+ * 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 MapUpdater(final IFile mapFile, final EList<Contribution> contributions) {
- super(mapFile, contributions);
+ public MapUpdater() {
+ super();
+ }
+
+ @Override
+ public boolean canUpdate(IFile file) {
+ return "rmap".equals(file.getFileExtension()); //$NON-NLS-1$
}
@Override
protected String getXpath() {
- return "/rmap/searchPath/provider[@readerType='p2']/uri";
+ return "/rmap/searchPath/provider[@readerType='p2']/uri"; //$NON-NLS-1$
+ }
+
+ @Override
+ protected String getCurrentLocation(Node uri) {
+ return uri.getAttributes().getNamedItem("format").getTextContent(); //$NON-NLS-1$
}
@Override
protected void updateUri(Node uri, String location) {
- if(location.startsWith(PREFIX)) {
+ if (location.startsWith(PREFIX)) {
location = "{0}/" + location.substring(PREFIX.length()); //$NON-NLS-1$
}
uri.getAttributes().getNamedItem("format").setTextContent(location); //$NON-NLS-1$
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 1dc75406734..f23caae4575 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
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -10,27 +10,47 @@
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* 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;
import java.io.File;
+import java.io.InputStream;
import java.util.HashMap;
+import java.util.LinkedHashSet;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Pattern;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
import org.eclipse.b3.aggregator.Contribution;
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.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.releng.tools.internal.Activator;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ListDialog;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
public class OomphSetupUpdater extends DependencyUpdater {
@@ -43,12 +63,26 @@ public class OomphSetupUpdater extends DependencyUpdater {
private final Pattern indexPattern = Pattern.compile(":\\d+$"); //$NON-NLS-1$
- private final String streamName;
+ private String streamName;
+
+ public OomphSetupUpdater() {
+ super();
+ }
+
+ @Override
+ public boolean canUpdate(IFile file) {
+ return "setup".equals(file.getFileExtension()); //$NON-NLS-1$
+ }
- public OomphSetupUpdater(final IFile mapFile, final EList<Contribution> contributions, final String streamName) {
- super(mapFile, contributions);
+ @Override
+ public void updateDocument(final Shell parentShell, final IFile mapFile, final EList<Contribution> contributions, final Map<Object, Object> context) throws CoreException {
+ streamName = promptForStreamName(parentShell, mapFile, context);
+ if (streamName == null) {
+ // Cancel
+ return;
+ }
- this.streamName = streamName;
+ super.updateDocument(parentShell, mapFile, contributions, context);
}
@Override
@@ -118,6 +152,11 @@ public class OomphSetupUpdater extends DependencyUpdater {
}
@Override
+ protected String getCurrentLocation(Node uri) {
+ return uri.getAttributes().getNamedItem("url").getTextContent(); //$NON-NLS-1$
+ }
+
+ @Override
protected void updateUri(Node uri, String location) {
uri.getAttributes().getNamedItem("url").setTextContent(location); //$NON-NLS-1$
}
@@ -137,4 +176,84 @@ public class OomphSetupUpdater extends DependencyUpdater {
options.put(XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
resource.save(options);
}
+
+ protected String promptForStreamName(Shell parentShell, IFile setupFile, Map<Object, Object> context) throws CoreException {
+ final String key = "$setup.stream$"; //$NON-NLS-1$
+
+ String result = (String) context.get(key);
+ if (result != null) {
+ return result;
+ }
+
+ final Set<String> repositoryLists = new LinkedHashSet<String>();
+
+ try (InputStream input = setupFile.getContents()) {
+ SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
+ parser.parse(input, new DefaultHandler() {
+ int inTarglet;
+ String repositoryListName;
+ boolean foundAnnotation;
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ if ("targlet".equals(qName)) { //$NON-NLS-1$
+ if ((inTarglet > 0) || "${eclipse.target.platform}".equals(attributes.getValue("activeRepositoryList"))) { //$NON-NLS-1$ //$NON-NLS-2$
+ // This is a stream-switching targlet. Get its repository names
+ inTarglet++;
+ }
+ } else if ((inTarglet > 0) && "repositoryList".equals(qName)) {
+ String listName = attributes.getValue("name"); //$NON-NLS-1$
+ if (listName != null && !listName.isEmpty()) {
+ repositoryListName = listName;
+ foundAnnotation = false;
+ }
+ } else if ("annotation".equals(qName) && OomphSetupUpdater.ANNOTATION_SOURCE.equals(attributes.getValue("source"))) { //$NON-NLS-1$ //$NON-NLS-2$
+ foundAnnotation = true;
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ if ("targlet".equals(qName)) { //$NON-NLS-1$
+ inTarglet = Math.max(inTarglet - 1, 0);
+ } else if ("repositoryList".equals(qName) && (repositoryListName != null)) { //$NON-NLS-1$
+ if (foundAnnotation) {
+ repositoryLists.add(repositoryListName);
+ }
+ repositoryListName = null;
+ foundAnnotation = false;
+ }
+ }
+ });
+ } catch (Exception e) {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to scan setup model for available streams.", e));
+ }
+
+ if (repositoryLists.isEmpty()) {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No streams are defined in the selected setup model."));
+ }
+
+ String first = repositoryLists.iterator().next();
+ if (repositoryLists.size() == 1) {
+ return first;
+ }
+
+ ILabelProvider labels = new LabelProvider();
+ ListDialog dlg = new ListDialog(parentShell);
+ dlg.setContentProvider(ArrayContentProvider.getInstance());
+ dlg.setLabelProvider(labels);
+ dlg.setInput(repositoryLists);
+ dlg.setInitialSelections(new Object[] { repositoryLists.iterator().next() });
+ dlg.setTitle("Select Stream");
+ dlg.setMessage(NLS.bind("Select the development stream to update in \"{0}\".", setupFile.getFullPath()));
+ labels.dispose();
+
+ dlg.open();
+ Object[] dlgResult = dlg.getResult();
+ result = ((dlgResult == null) || (dlgResult.length == 0)) ? null : (String) dlgResult[0];
+ if (result != null) {
+ context.put(key, result);
+ }
+ return result;
+ }
}
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 0b3fc7d0105..1880d3406c8 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
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,24 +8,33 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus - Support updating of multiple selected files
*****************************************************************************/
package org.eclipse.papyrus.releng.tools.internal.popup.actions;
-import org.eclipse.b3.aggregator.Contribution;
import org.eclipse.core.resources.IFile;
-import org.eclipse.emf.common.util.EList;
import org.w3c.dom.Node;
public class PomUpdater extends DependencyUpdater {
- public PomUpdater(final IFile mapFile, final EList<Contribution> contributions) {
- super(mapFile, contributions);
+ public PomUpdater() {
+ super();
+ }
+
+ @Override
+ public boolean canUpdate(IFile file) {
+ return "xml".equals(file.getFileExtension()) && file.getName().contains("pom"); //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
protected String getXpath() {
- return "/project/repositories/repository/url";
+ return "/project/repositories/repository/url"; //$NON-NLS-1$
+ }
+
+ @Override
+ protected String getCurrentLocation(Node uri) {
+ return uri.getTextContent();
}
@Override

Back to the top