diff options
author | Pascal Rapicault | 2014-11-11 01:48:22 +0000 |
---|---|---|
committer | Pascal Rapicault | 2014-11-11 01:48:22 +0000 |
commit | 2c821a9b217ad6736bc32d9423e893d50df76d51 (patch) | |
tree | 9e35e153320cd73acc94f804023f5d28d11a680a | |
parent | a1bc05103ee75a7f84ae047f92014248bad32bde (diff) | |
download | rt.equinox.p2-2c821a9b217ad6736bc32d9423e893d50df76d51.tar.gz rt.equinox.p2-2c821a9b217ad6736bc32d9423e893d50df76d51.tar.xz rt.equinox.p2-2c821a9b217ad6736bc32d9423e893d50df76d51.zip |
Make version optional and allow for a version comparator inI20141111-0830I20141111-0800
checkOrPromptForNative action
9 files changed, 82 insertions, 25 deletions
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/installCommands.txt b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/installCommands.txt index 8e52df8b8..5f0b89ae9 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/installCommands.txt +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/installCommands.txt @@ -1 +1,6 @@ -installPrefix=sudo apt-get install
\ No newline at end of file +installPrefix=sudo apt-get install +ge=>\= +gt=> +le=<\= +lt=< +eq=\=
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isInstalled.sh b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isInstalled.sh index 0d85cf317..3a1bbf7cd 100644..100755 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isInstalled.sh +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isInstalled.sh @@ -1,9 +1,22 @@ #!/bin/sh + +# Check if a package whose name and version are specified as input is installed. +# Return 0 if the package is installed, 1 if the version is not correct, 2 if the package is not installed +# +# Usage: +# $ ./isInstalled param1 [param2, param3] +# * param1: packageId +# * param2: version comparator +# * param3: version of the package + foundVersion=$(dpkg-query -f='${version}' --show $1) #The package is found, check the version if [ $? -eq 0 ]; then - dpkg --compare-versions $foundVersion ge $2 + if [ "$#" -eq 1 ]; then + return 0; + fi + dpkg --compare-versions $foundVersion $2 $3 if [ $? -eq 0 ]; then return 0; else diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Messages.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Messages.java index 3655d9856..fd251a3b6 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Messages.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Messages.java @@ -64,7 +64,6 @@ public class Messages extends NLS { public static String NativePackageExtractionApplication_MissingValue; public static String PromptForNative_InstallText; public static String PromptForNative_IntroText; - public static String PromptForNative_Version; public static String PromptForNative_DialogTitle; public static String rmdir_failed; public static String Util_Invalid_Zip_File_Format; diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativePackageEntry.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativePackageEntry.java index d6606ed66..6fa5bc0c9 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativePackageEntry.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativePackageEntry.java @@ -13,10 +13,20 @@ package org.eclipse.equinox.internal.p2.touchpoint.natives; public class NativePackageEntry { public String name; public String version; + public String comparator; - public NativePackageEntry(String name, String version) { + public String getComparator() { + return comparator; + } + + public void setComparator(String comparator) { + this.comparator = comparator; + } + + public NativePackageEntry(String name, String version, String comparator) { this.name = name; this.version = version; + this.comparator = comparator; } public String getName() { diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativePackageExtractionApplication.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativePackageExtractionApplication.java index 2262892e8..93451c83e 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativePackageExtractionApplication.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativePackageExtractionApplication.java @@ -34,7 +34,7 @@ public class NativePackageExtractionApplication implements IApplication { private static final String PROP_DEPENDS = "depends"; //$NON-NLS-1$ //Internal constants - private static final String DEFAULT_VERSION_CONSTRAINT = ">="; //$NON-NLS-1$ + private static final String DEFAULT_VERSION_CONSTRAINT = "ge"; //$NON-NLS-1$ private static final String _ACTION_ID = "_action_id_"; //$NON-NLS-1$ private static final String PROP_P2_PROFILE = "eclipse.p2.profile"; //$NON-NLS-1$ private static final Integer EXIT_ERROR = new Integer(13); @@ -54,12 +54,15 @@ public class NativePackageExtractionApplication implements IApplication { //Data collected by the application private Properties extractedData = new Properties(); + private Properties installCommandsProperties = new Properties(); + private boolean stackTrace = false; public Object start(IApplicationContext context) throws Exception { try { processArguments((String[]) context.getArguments().get("application.args")); //$NON-NLS-1$ initializeServices(); + NativeTouchpoint.loadInstallCommandsProperties(installCommandsProperties, "debian"); //$NON-NLS-1$ collectData(); persistInformation(); } catch (CoreException e) { @@ -168,7 +171,7 @@ public class NativePackageExtractionApplication implements IApplication { Map<String, String> parsedInstructions = parseInstruction(tokenizer.nextToken()); if (parsedInstructions != null && parsedInstructions.get(_ACTION_ID).endsWith(CheckAndPromptNativePackage.ID)) { if ("debian".equals(parsedInstructions.get(ActionConstants.PARM_LINUX_DISTRO))) { //$NON-NLS-1$ - depends += formatAsDependsEntry(parsedInstructions.get(ActionConstants.PARM_LINUX_PACKAGE_NAME), parsedInstructions.get(ActionConstants.PARM_LINUX_PACKAGE_VERSION), parsedInstructions.get(ActionConstants.PACKAGE_VERSION_CONSTRAINT)) + ','; + depends += formatAsDependsEntry(parsedInstructions.get(ActionConstants.PARM_LINUX_PACKAGE_NAME), parsedInstructions.get(ActionConstants.PARM_LINUX_PACKAGE_VERSION), parsedInstructions.get(ActionConstants.PARM_LINUX_VERSION_COMPARATOR)) + ','; } } } @@ -182,16 +185,20 @@ public class NativePackageExtractionApplication implements IApplication { extractedData.put(PROP_DEPENDS, depends); } - private String formatAsDependsEntry(String packageId, String version, String versionConstraint) { + private String formatAsDependsEntry(String packageId, String version, String versionComparator) { String result = packageId; - if (versionConstraint == null) - versionConstraint = DEFAULT_VERSION_CONSTRAINT; + if (versionComparator == null) + versionComparator = DEFAULT_VERSION_CONSTRAINT; if (version != null) { - result += '(' + versionConstraint + ' ' + version + ')'; + result += '(' + getUserFriendlyComparator(versionComparator) + ' ' + version + ')'; } return result; } + private String getUserFriendlyComparator(String comparator) { + return installCommandsProperties.getProperty(comparator, ""); //$NON-NLS-1$ + } + //Code copied from the InstructionParser class private Map<String, String> parseInstruction(String statement) { Map<String, String> instructions = new HashMap<String, String>(); diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java index c8d2e0a8b..206e3fba6 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativeTouchpoint.java @@ -36,6 +36,7 @@ public class NativeTouchpoint extends Touchpoint { private static Map<IProfile, IBackupStore> backups = new WeakHashMap<IProfile, IBackupStore>(); private List<NativePackageEntry> packagesToInstall = new ArrayList<NativePackageEntry>(); + private Properties installCommandsProperties = new Properties(); private IProvisioningAgent agent; private String distro; @@ -83,30 +84,46 @@ public class NativeTouchpoint extends Touchpoint { private void promptForNativePackage() { if (packagesToInstall.size() == 0) return; + loadInstallCommandsProperties(installCommandsProperties, distro); UIServices serviceUI = (UIServices) agent.getService(UIServices.SERVICE_NAME); String text = Messages.PromptForNative_IntroText; for (NativePackageEntry nativePackageEntry : packagesToInstall) { - text += "\t" + nativePackageEntry.name + Messages.PromptForNative_Version + nativePackageEntry.version + "\n"; //$NON-NLS-1$//$NON-NLS-2$ + text += "\t" + nativePackageEntry.name + ' ' + formatVersion(nativePackageEntry) + "\n"; //$NON-NLS-1$//$NON-NLS-2$ } text += Messages.PromptForNative_InstallText + createCommand(); serviceUI.showInformationMessage(Messages.PromptForNative_DialogTitle, text); } - private String getInstallCommad() { - File f = getFileFromBundle(distro, INSTALL_COMMANDS); + private String formatVersion(NativePackageEntry entry) { + if (entry.getVersion() == null) + return null; + return getUserFriendlyComparator(entry.comparator) + ' ' + entry.version + ' '; + } + private String getUserFriendlyComparator(String comparator) { + return installCommandsProperties.getProperty(comparator, ""); //$NON-NLS-1$ + } + + public static void loadInstallCommandsProperties(Properties properties, String distro) { + File f = getFileFromBundle(distro, INSTALL_COMMANDS); if (f == null) - return ""; //$NON-NLS-1$ + return; try { InputStream is = new BufferedInputStream(new FileInputStream(f)); - Properties properties = new Properties(); - properties.load(is); - return properties.getProperty(INSTALL_PREFIX, ""); //$NON-NLS-1$ + try { + properties.load(is); + } finally { + if (is != null) + is.close(); + } } catch (IOException e) { //fallthrough to return empty string } - return ""; //$NON-NLS-1$ + } + + private String getInstallCommad() { + return installCommandsProperties.getProperty(INSTALL_PREFIX, ""); //$NON-NLS-1$ } private String createCommand() { diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java index ba683dec6..d75317849 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java @@ -37,5 +37,5 @@ public class ActionConstants { public static final String PARM_LINUX_DISTRO = "distro"; //$NON-NLS-1$ public static final String PARM_LINUX_PACKAGE_NAME = "package"; //$NON-NLS-1$ public static final String PARM_LINUX_PACKAGE_VERSION = "version"; //$NON-NLS-1$ - public static final String PACKAGE_VERSION_CONSTRAINT = "constraint"; //$NON-NLS-1$ + public static final String PARM_LINUX_VERSION_COMPARATOR = "comparator"; //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CheckAndPromptNativePackage.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CheckAndPromptNativePackage.java index dbc8fba0a..9752de043 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CheckAndPromptNativePackage.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CheckAndPromptNativePackage.java @@ -31,10 +31,11 @@ public class CheckAndPromptNativePackage extends ProvisioningAction { String distro = (String) parameters.get(ActionConstants.PARM_LINUX_DISTRO); String packageName = (String) parameters.get(ActionConstants.PARM_LINUX_PACKAGE_NAME); String packageVersion = (String) parameters.get(ActionConstants.PARM_LINUX_PACKAGE_VERSION); + String versionComparator = (String) parameters.get(ActionConstants.PARM_LINUX_VERSION_COMPARATOR); - if (distro == null || packageName == null || packageVersion == null) + if (distro == null || packageName == null || (versionComparator != null && packageVersion == null)) return new Status(IStatus.ERROR, Activator.ID, Messages.Incorrect_Command); - + distro = distro.toLowerCase(); //If we are not running the distro we are provisioning, do nothing and return @@ -51,14 +52,20 @@ public class CheckAndPromptNativePackage extends ProvisioningAction { cmd.add(SHELL); cmd.add(scriptToExecute.getAbsolutePath()); cmd.add(packageName); - cmd.add(packageVersion); + if (packageVersion != null) { + if (versionComparator == null) + versionComparator = "ge"; //$NON-NLS-1$ + + cmd.add(versionComparator); + cmd.add(packageVersion); + } int exitValue = new ProcessBuilder(cmd).start().waitFor(); switch (exitValue) { case 0 : return Status.OK_STATUS; case 1 : case 2 : - ((NativeTouchpoint) getTouchpoint()).addPackageToInstall(new NativePackageEntry(packageName, packageVersion)); + ((NativeTouchpoint) getTouchpoint()).addPackageToInstall(new NativePackageEntry(packageName, packageVersion, versionComparator)); ((NativeTouchpoint) getTouchpoint()).setDistro(distro); return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties index 913f2a648..8b2b04d5e 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties @@ -53,8 +53,7 @@ NativePackageExtractionApplication_MissingParameters=Missing arguments, please s NativePackageExtractionApplication_MissingValue=The value is missing for argument {0}. NativePackageExtractionApplication_PersistencePb=error while persisting results in PromptForNative_InstallText=\n You can install those by executing the following command: \n\t -PromptForNative_IntroText=The software you installed requires the following OS packages to be installed : -PromptForNative_Version=\ version +PromptForNative_IntroText=The software you installed requires the following OS packages to be installed : \n PromptForNative_DialogTitle=Install native software packages rmdir_failed=Could not remove directory {0}. Util_Invalid_Zip_File_Format=Invalid zip file format |