Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Le Menez2015-08-19 14:06:14 +0000
committerQuentin Le Menez2015-08-21 08:36:47 +0000
commit6f51c1e47c75f2f33207c7da4686eb0ef3043279 (patch)
treedff807479e7c6bc727e8c21bcbe3d6e90d307a21
parent30daef8ca05f7c79cdf1d36cd5f9f1266dbb944c (diff)
downloadorg.eclipse.papyrus-6f51c1e47c75f2f33207c7da4686eb0ef3043279.tar.gz
org.eclipse.papyrus-6f51c1e47c75f2f33207c7da4686eb0ef3043279.tar.xz
org.eclipse.papyrus-6f51c1e47c75f2f33207c7da4686eb0ef3043279.zip
Bug 475382: [Releng] Change the behavior of the version updater tool
https://bugs.eclipse.org/bugs/show_bug.cgi?id=475382 - added new conditions when updating the different versions - Master version Signed-off-by: Quentin Le Menez <quentin.lemenez@cea.fr>
-rw-r--r--plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/features/ChangeFeatureVersionHandler.java11
-rw-r--r--plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/plugins/ChangeDependencyVersionNumberHandler.java114
-rw-r--r--plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/plugins/ChangePluginVersionHandler.java11
3 files changed, 114 insertions, 22 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/features/ChangeFeatureVersionHandler.java b/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/features/ChangeFeatureVersionHandler.java
index 2ff35d0a709..f87c81754da 100644
--- a/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/features/ChangeFeatureVersionHandler.java
+++ b/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/features/ChangeFeatureVersionHandler.java
@@ -20,14 +20,17 @@ public class ChangeFeatureVersionHandler extends AbstractChangeProjectVersionHan
@Override
protected void setVersionNumber(final IProject project, final String newVersion, String notManagedProjectNames) {
- if(project.isOpen()) {
+ if (project.isOpen()) {
try {
- if(project.hasNature(Utils.FEATURE_NATURE)) {//for features
+ if (project.hasNature(Utils.FEATURE_NATURE)) {// for features
try {
final IFeatureProjectEditor editor = new FeatureProjectEditor(project);
editor.init();
- editor.setVersion(newVersion);
- editor.save();
+ // This test is necessary to bypass the plugins tagged 0.*.*
+ if (editor.getVersion().matches("[1-9]+\\.[0-9]+\\.[0-9]+\\.qualifier")) {
+ editor.setVersion(newVersion);
+ editor.save();
+ }
} catch (final ParserConfigurationException e) {
Activator.log.error(e);
notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
diff --git a/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/plugins/ChangeDependencyVersionNumberHandler.java b/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/plugins/ChangeDependencyVersionNumberHandler.java
index db0f336f7db..6b95d1b135c 100644
--- a/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/plugins/ChangeDependencyVersionNumberHandler.java
+++ b/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/plugins/ChangeDependencyVersionNumberHandler.java
@@ -1,12 +1,18 @@
package org.eclipse.papyrus.dev.project.management.handlers.plugins;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.jar.Manifest;
+import java.util.jar.Attributes.Name;
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.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -23,8 +29,14 @@ import org.eclipse.papyrus.dev.project.management.dialog.TwoInputDialog;
import org.eclipse.papyrus.dev.project.management.utils.Utils;
import org.eclipse.papyrus.eclipse.project.editors.file.ManifestEditor;
import org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor;
+import org.eclipse.pde.core.project.IBundleProjectDescription;
+import org.eclipse.pde.core.project.IBundleProjectService;
+import org.eclipse.pde.core.project.IRequiredBundleDescription;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
//TODO should be covered with JUnit test
public class ChangeDependencyVersionNumberHandler extends AbstractHandler {
@@ -48,7 +60,7 @@ public class ChangeDependencyVersionNumberHandler extends AbstractHandler {
public String isValid(final String newText) {
final boolean match = newText.matches("[0-9]+\\.[0-9]+\\.[0-9]");
- if(!match) {
+ if (!match) {
return NLS.bind("The version number should be : something like this : {0}.", INITIAL_VALUE);
}
return null;
@@ -56,7 +68,7 @@ public class ChangeDependencyVersionNumberHandler extends AbstractHandler {
};
final TwoInputDialog dialog = new TwoInputDialog(Display.getCurrent().getActiveShell(), TITLE, "Enter the new version for the Papyrus dependencies", "pattern plugin name", INITIAL_VALUE, PAPYRUS_NAME, validator);
- if(dialog.open() == Window.OK) {
+ if (dialog.open() == Window.OK) {
final String newVersion = dialog.getValue();
final String pattern = dialog.getValue_2();
@@ -101,10 +113,10 @@ public class ChangeDependencyVersionNumberHandler extends AbstractHandler {
monitor.beginTask("Update dependency versions", projects.length);
- for(final IProject current : projects) {
+ for (final IProject current : projects) {
final String name = current.getName();
- if(name.startsWith(PAPYRUS_NAME)) {//TODO : add the possibility to manage other plugins
+ if (name.startsWith(PAPYRUS_NAME)) {// TODO : add the possibility to manage other plugins
setVersionNumber(current, pattern, newVersion, notManagedProjectNames);
} else {
notManagedProjectNames += NLS.bind("- {0} \n", current.getName());
@@ -118,11 +130,11 @@ public class ChangeDependencyVersionNumberHandler extends AbstractHandler {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
- if(textResult.equals("")) {
- final MessageDialog informationDialog = new MessageDialog(Display.getCurrent().getActiveShell(), WARNING_DIALOG_TITLE, null, WARNING_DIALOG_MESSAGE2, MessageDialog.INFORMATION, new String[]{ "OK" }, 0);
+ if (textResult.equals("")) {
+ final MessageDialog informationDialog = new MessageDialog(Display.getCurrent().getActiveShell(), WARNING_DIALOG_TITLE, null, WARNING_DIALOG_MESSAGE2, MessageDialog.INFORMATION, new String[] { "OK" }, 0);
informationDialog.open();
} else {
- final MessageDialog informationDialog = new MessageDialog(Display.getCurrent().getActiveShell(), WARNING_DIALOG_TITLE, null, WARNING_DIALOG_MESSAGE + "\n" + textResult, MessageDialog.INFORMATION, new String[]{ "OK" }, 0);
+ final MessageDialog informationDialog = new MessageDialog(Display.getCurrent().getActiveShell(), WARNING_DIALOG_TITLE, null, WARNING_DIALOG_MESSAGE + "\n" + textResult, MessageDialog.INFORMATION, new String[] { "OK" }, 0);
informationDialog.open();
}
}
@@ -134,21 +146,21 @@ public class ChangeDependencyVersionNumberHandler extends AbstractHandler {
/**
*
* @param project
- * the project to manage
+ * the project to manage
* @param dependencyPattern
- * the pattern used to find the dependency to update
+ * the pattern used to find the dependency to update
* @param newVersion
- * the new version for the project
+ * the new version for the project
* @param notManagedProjectNames
- * a String used to build the message with the not managed projects
+ * a String used to build the message with the not managed projects
*/
private void setVersionNumber(final IProject project, final String dependencyPattern, final String newValue, String notManagedProjectNames) {
- if(project.isOpen()) {
+ if (project.isOpen()) {
try {
final boolean pluginnature = project.hasNature(Utils.PLUGIN_NATURE);
- if(pluginnature) {
+ if (pluginnature) {
try {
- final IManifestEditor editor = new ManifestEditor(project);
+ MyManifestEditor editor = new MyManifestEditor(project);
editor.init();
editor.setDependenciesVersion(dependencyPattern, newValue);
editor.save();
@@ -168,4 +180,78 @@ public class ChangeDependencyVersionNumberHandler extends AbstractHandler {
notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
}
}
+
+
+ private class MyManifestEditor extends ManifestEditor {
+
+ private static final String SEMICOLON = ";"; //$NON-NLS-1$
+
+ private static final String COMMA = ","; //$NON-NLS-1$
+
+ private static final String ASSIGN = "="; //$NON-NLS-1$
+
+ private static final String BUNDLE_VERSION = "bundle-version"; //$NON-NLS-1$
+
+ private static final String REQUIRED_BUNDLE = "Require-Bundle"; //$NON-NLS-1$
+
+ private Manifest manifest;
+
+ private IFile manifestFile;
+
+ /**
+ * Constructor.
+ *
+ * @param project
+ * @throws IOException
+ * @throws CoreException
+ */
+ public MyManifestEditor(IProject project) throws IOException, CoreException {
+ super(project);
+ manifestFile = project.getFile("META-INF/MANIFEST.MF");
+ manifest = new Manifest(manifestFile.getContents());
+ }
+
+ /**
+ * @see org.eclipse.papyrus.eclipse.project.editors.file.ManifestEditor#setDependenciesVersion(java.lang.String, java.lang.String)
+ *
+ * @param dependencyPattern
+ * @param newVersion
+ */
+ @Override
+ public void setDependenciesVersion(String dependencyPattern, String newVersion) {
+ final Name rqBundle = new Name(REQUIRED_BUNDLE);
+ final String requireBundles = manifest.getMainAttributes().getValue(rqBundle);
+ final String[] bundles = requireBundles.split(COMMA);
+ String newRequiredBundles = ""; //$NON-NLS-1$
+ for (int ii = 0; ii < bundles.length; ii++) {// we iterate on the declared dependencies
+ final String currentDependency = bundles[ii];
+ final String[] dependencyValue = currentDependency.split(SEMICOLON);
+ if (dependencyValue[0].contains(dependencyPattern)) {
+ String[] test = dependencyValue[1].split("[0-9]+\\.[0-9]+\\.[0-9]");
+ String oldVersion = dependencyValue[1].substring(test[0].length(), test[0].length() + 5);
+ // This test is necessary to take into account the versions tagged 0.*.*
+ String newBundleVersion = BUNDLE_VERSION + ASSIGN + '"' + newVersion + '"';
+ if (!oldVersion.matches("[1-9]+\\.[0-9]+\\.[0-9]")) {
+ newBundleVersion = BUNDLE_VERSION + ASSIGN + '"' + oldVersion + '"';
+ }
+ newRequiredBundles += dependencyValue[0] + SEMICOLON + newBundleVersion;
+ for (int i = 1; i < dependencyValue.length; i++) {
+ final String declaration = dependencyValue[i];
+ if (declaration.contains(BUNDLE_VERSION + ASSIGN)) {
+ // we ignore it
+ } else {
+ newRequiredBundles += SEMICOLON + dependencyValue[i];// we add the others declaration
+ }
+ }
+ } else {
+ newRequiredBundles += currentDependency;// we copy the existing declaration
+ }
+ if (ii < (bundles.length - 1)) {
+ newRequiredBundles += COMMA;
+ }
+ }
+ setValue(REQUIRED_BUNDLE, newRequiredBundles);
+ }
+ }
+
}
diff --git a/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/plugins/ChangePluginVersionHandler.java b/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/plugins/ChangePluginVersionHandler.java
index 68ff928fedd..223fa7a30f1 100644
--- a/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/plugins/ChangePluginVersionHandler.java
+++ b/plugins/developer/org.eclipse.papyrus.dev.project.management/src/org/eclipse/papyrus/dev/project/management/handlers/plugins/ChangePluginVersionHandler.java
@@ -17,14 +17,17 @@ public class ChangePluginVersionHandler extends AbstractChangeProjectVersionHand
@Override
protected void setVersionNumber(final IProject project, final String newVersion, String notManagedProjectNames) {
- if(project.isOpen()) {
+ if (project.isOpen()) {
try {
- if(project.hasNature(Utils.PLUGIN_NATURE)) {
+ if (project.hasNature(Utils.PLUGIN_NATURE)) {
try {
final IManifestEditor editor = new ManifestEditor(project);
editor.init();
- editor.setBundleVersion(newVersion);
- editor.save();
+ // This test is necessary to bypass the plugins tagged 0.*.*
+ if (editor.getBundleVersion().matches("[1-9]+\\.[0-9]+\\.[0-9]+\\.qualifier")) {
+ editor.setBundleVersion(newVersion);
+ editor.save();
+ }
} catch (final IOException e) {
Activator.log.error(e);
notManagedProjectNames += NLS.bind("- {0} \n", project.getName());

Back to the top