diff options
author | Pascal Rapicault | 2014-11-05 20:17:46 +0000 |
---|---|---|
committer | Pascal Rapicault | 2014-11-05 20:17:46 +0000 |
commit | 86288d6619d82beca2fc889782f460eb6ac874f1 (patch) | |
tree | a57311bd96b23ef918ea398fd0e8650cebc9d907 /bundles/org.eclipse.equinox.p2.touchpoint.natives | |
parent | 5eaa208019d3f5399d371f53e7662edc89e5b0e3 (diff) | |
download | rt.equinox.p2-86288d6619d82beca2fc889782f460eb6ac874f1.tar.gz rt.equinox.p2-86288d6619d82beca2fc889782f460eb6ac874f1.tar.xz rt.equinox.p2-86288d6619d82beca2fc889782f460eb6ac874f1.zip |
Initial addition of the support to check for debian packages
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.touchpoint.natives')
13 files changed, 284 insertions, 15 deletions
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.touchpoint.natives/META-INF/MANIFEST.MF index 3aa1e0eec..c7b9b0e70 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.p2.touchpoint.natives;singleton:=true -Bundle-Version: 1.1.100.qualifier +Bundle-Version: 1.2.0.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.touchpoint.natives.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/build.properties b/bundles/org.eclipse.equinox.p2.touchpoint.natives/build.properties index a6e5526cb..edcda0b8d 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/build.properties +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/build.properties @@ -14,5 +14,6 @@ bin.includes = META-INF/,\ .,\ plugin.xml,\ about.html,\ - plugin.properties + plugin.properties,\ + nativePackageScripts/ src.includes = about.html 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 new file mode 100644 index 000000000..8e52df8b8 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/installCommands.txt @@ -0,0 +1 @@ +installPrefix=sudo apt-get install
\ 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 new file mode 100644 index 000000000..0d85cf317 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isInstalled.sh @@ -0,0 +1,15 @@ +#!/bin/sh +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 0 ]; then + return 0; + else + return 1; + fi +fi + +#We are here because the package is not found +return 2; diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isRunning.sh b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isRunning.sh new file mode 100644 index 000000000..0dd60287b --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isRunning.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +ls /etc/debian_version +if [ $? -eq 0 ]; then + return 0; +fi + +return 2; + diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isRunning.sh~ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isRunning.sh~ new file mode 100644 index 000000000..7573a4b2b --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/debian/isRunning.sh~ @@ -0,0 +1,8 @@ +#!/bin/sh + +ls /etc/debian_version +if [ $? -eq 0 ]; then + return 0; +fi + +return 2; diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml b/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml index 2565253a1..3c7a78146 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml @@ -110,4 +110,15 @@ version="1.0.0"> </action> </extension> + <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CheckAndPromptNativePackage" + description="checkAndPromptNativePackage(ditro, package,version)" + name="checkAndPromptNativePackage" + touchpointType="org.eclipse.equinox.p2.native" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> </plugin> 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 c8aade19e..d2bf16ae3 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. + * Copyright (c) 2007, 2014 IBM Corporation 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,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Rapicorp, Inc - prompt to install debian package *******************************************************************************/ package org.eclipse.equinox.internal.p2.touchpoint.natives; @@ -51,9 +52,16 @@ public class Messages extends NLS { public static String copy_failed; public static String failed_backup_restore; public static String backup_file_failed; + public static String Cannot_Check_Package; + public static String Cannot_Find_status; public static String Error_list_children_0; + public static String Incorrect_Command; public static String link_failed; public static String mkdir_failed; + 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; public static String Util_Error_Unzipping; 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 new file mode 100644 index 000000000..d6606ed66 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/NativePackageEntry.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2014 Rapicorp, Inc 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: + * Rapicorp, Inc - prompt to install debian package + *******************************************************************************/ +package org.eclipse.equinox.internal.p2.touchpoint.natives; + +public class NativePackageEntry { + public String name; + public String version; + + public NativePackageEntry(String name, String version) { + this.name = name; + this.version = version; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } +} 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 75a0241df..c8d2e0a8b 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 IBM Corporation and others. + * Copyright (c) 2007, 2014 IBM Corporation 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,17 +7,17 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Rapicorp, Inc - prompt to install debian package *******************************************************************************/ package org.eclipse.equinox.internal.p2.touchpoint.natives; -import java.io.File; -import java.io.IOException; -import java.util.Map; -import java.util.WeakHashMap; +import java.io.*; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.ActionConstants; -import org.eclipse.equinox.p2.core.IProvisioningAgent; -import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.core.*; import org.eclipse.equinox.p2.engine.IProfile; import org.eclipse.equinox.p2.engine.spi.Touchpoint; import org.eclipse.equinox.p2.metadata.IArtifactKey; @@ -25,17 +25,23 @@ import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository; import org.eclipse.osgi.util.NLS; public class NativeTouchpoint extends Touchpoint { - public static final String PARM_BACKUP = "backup"; //$NON-NLS-1$ - public static final String PARM_ARTIFACT = "artifact"; //$NON-NLS-1$ - public static final String PARM_ARTIFACT_LOCATION = "artifact.location"; //$NON-NLS-1$ + private static final String FOLDER = "nativePackageScripts"; //$NON-NLS-1$ + private static final String INSTALL_COMMANDS = "installCommands.txt"; //$NON-NLS-1$ + private static final String INSTALL_PREFIX = "installPrefix"; //$NON-NLS-1$ + private static Map<IProfile, IBackupStore> backups = new WeakHashMap<IProfile, IBackupStore>(); + private List<NativePackageEntry> packagesToInstall = new ArrayList<NativePackageEntry>(); + + private IProvisioningAgent agent; + private String distro; + public IStatus initializeOperand(IProfile profile, Map<String, Object> parameters) { - IProvisioningAgent agent = (IProvisioningAgent) parameters.get(ActionConstants.PARM_AGENT); + agent = (IProvisioningAgent) parameters.get(ActionConstants.PARM_AGENT); IArtifactKey artifactKey = (IArtifactKey) parameters.get(PARM_ARTIFACT); if (!parameters.containsKey(PARM_ARTIFACT_LOCATION) && artifactKey != null) { try { @@ -67,12 +73,58 @@ public class NativeTouchpoint extends Touchpoint { } public IStatus commit(IProfile profile) { + promptForNativePackage(); IBackupStore store = getBackupStore(profile); store.discard(); clearProfileState(profile); return Status.OK_STATUS; } + private void promptForNativePackage() { + if (packagesToInstall.size() == 0) + return; + 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 += Messages.PromptForNative_InstallText + createCommand(); + serviceUI.showInformationMessage(Messages.PromptForNative_DialogTitle, text); + } + + private String getInstallCommad() { + File f = getFileFromBundle(distro, INSTALL_COMMANDS); + + if (f == null) + return ""; //$NON-NLS-1$ + + try { + InputStream is = new BufferedInputStream(new FileInputStream(f)); + Properties properties = new Properties(); + properties.load(is); + return properties.getProperty(INSTALL_PREFIX, ""); //$NON-NLS-1$ + } catch (IOException e) { + //fallthrough to return empty string + } + return ""; //$NON-NLS-1$ + } + + private String createCommand() { + String text = getInstallCommad() + ' '; + for (NativePackageEntry nativePackageEntry : packagesToInstall) { + text += nativePackageEntry.name + " "; //$NON-NLS-1$ + } + return text; + } + + public void addPackageToInstall(NativePackageEntry entry) { + packagesToInstall.add(entry); + } + + public void setDistro(String distro) { + this.distro = distro; + } + /** * Converts a profile id into a string that can be used as a file name in any file system. */ @@ -115,6 +167,21 @@ public class NativeTouchpoint extends Touchpoint { return returnStatus; } + public static File getFileFromBundle(String distro, String file) { + URL[] installScripts = FileLocator.findEntries(Activator.getContext().getBundle(), new Path(NativeTouchpoint.FOLDER + '/' + distro + '/' + file)); + if (installScripts.length == 0) + return null; + + try { + return URIUtil.toFile(URIUtil.toURI(FileLocator.toFileURL(installScripts[0]))); + } catch (URISyntaxException e) { + //Can't happen, the URI is returned by OSGi + } catch (IOException e) { + //continue to return null + } + return null; + } + /** * Cleans up the transactional state associated with a profile. */ 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 bb22ee514..722a1d37b 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 @@ -34,4 +34,7 @@ public class ActionConstants { public static final String PARM_COPY_OVERWRITE = "overwrite"; //$NON-NLS-1$ public static final String PARM_OPTIONS = "options"; //$NON-NLS-1$ public static final String PARM_ABSOLUTE_FILES = "absoluteFiles"; //$NON-NLS-1$ + public static final Object PARM_LINUX_DISTRO = "distro"; //$NON-NLS-1$ + public static final Object PARM_LINUX_PACKAGE_NAME = "package"; //$NON-NLS-1$ + public static final Object PARM_LINUX_PACKAGE_VERSION = "version"; //$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 new file mode 100644 index 000000000..dbc8fba0a --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CheckAndPromptNativePackage.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2014 Rapicorp, Inc. 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: + * Rapicorp, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.internal.p2.touchpoint.natives.actions; + +import java.io.File; +import java.io.IOException; +import java.util.*; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.internal.p2.touchpoint.natives.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.osgi.util.NLS; + +public class CheckAndPromptNativePackage extends ProvisioningAction { + public static final String ID = "checkAndPromptNativePackage"; //$NON-NLS-1$ + private static final String IS_INSTALLED = "isInstalled.sh"; //$NON-NLS-1$ + private static final String IS_RUNNING = "isRunning.sh"; //$NON-NLS-1$ + private static final String SHELL = "/bin/sh"; //$NON-NLS-1$ + + @Override + public IStatus execute(Map<String, Object> parameters) { + //Get and check the paremeters + 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); + + if (distro == null || packageName == 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 + if (!runningDistro(distro)) + return Status.OK_STATUS; + + //Check if the desired package is installed and collect information in the touchpoint + File scriptToExecute = NativeTouchpoint.getFileFromBundle(distro, IS_INSTALLED); + if (scriptToExecute == null) + return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Cannot_Find_status, distro)); + + try { + List<String> cmd = new ArrayList<String>(4); + cmd.add(SHELL); + cmd.add(scriptToExecute.getAbsolutePath()); + cmd.add(packageName); + 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()).setDistro(distro); + return Status.OK_STATUS; + } + } catch (IOException e) { + return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Cannot_Check_Package, new String[] {packageName, packageVersion, distro})); + } catch (InterruptedException e) { + return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Cannot_Check_Package, new String[] {packageName, packageVersion, distro})); + } + return Status.OK_STATUS; + } + + //Check if the given distro is currently being run + protected boolean runningDistro(String distro) { + try { + File scriptToExecute = NativeTouchpoint.getFileFromBundle(distro, IS_RUNNING); + if (scriptToExecute == null) + return false; + + List<String> cmd = new ArrayList<String>(4); + cmd.add(SHELL); + cmd.add(scriptToExecute.getAbsolutePath()); + int exitValue = new ProcessBuilder(cmd).start().waitFor(); + if (exitValue == 0) + return true; + return false; + } catch (IOException e) { + return false; + } catch (InterruptedException e) { + return false; + } + } + + @Override + public IStatus undo(Map<String, Object> parameters) { + //Nothing to do since we are not modifying any state. + return null; + } + +}
\ No newline at end of file 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 1bbd40111..ca7227fc3 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 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2007, 2009 IBM Corporation and others. +# Copyright (c) 2007, 2014 IBM Corporation 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,6 +7,7 @@ # # Contributors: # IBM Corporation - initial API and implementation +# Rapicorp, Inc - prompt to install debian package ############################################################################### BackupStore_backupCopy_closed_store=Can not perform backup on closed backup store. @@ -40,9 +41,17 @@ download_cache_not_writeable=Agent download cache not writeable: {0}. copy_failed=I/O Error while copying {0} - see details. failed_backup_restore=Restore of backup failed - see log for details. Backup directory name: {0}. backup_file_failed=Backup of file {0} failed. + +Cannot_Check_Package=Failed to check the status of native package: {0} version {1} on {2}. +Cannot_Find_status=Could not find script to check the status of the package on Error_list_children_0=Error while retrieving children of directory: {0} +Incorrect_Command=Incorrect use of the command. One of the parameter is missing. link_failed=Could not create link {0}. mkdir_failed=Could not create directory {0}. +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_DialogTitle=Install native software packages rmdir_failed=Could not remove directory {0}. Util_Invalid_Zip_File_Format=Invalid zip file format Util_Error_Unzipping=Error unzipping {0}: {1} |