diff options
author | Christian Georgi | 2014-12-31 14:35:55 +0000 |
---|---|---|
committer | Pascal Rapicault | 2015-03-31 17:00:04 +0000 |
commit | f0966580855884e5394a8eefe84668adf30ca20a (patch) | |
tree | dca0c1e0da80298da61e3e65d237fa91307b1c19 | |
parent | 78b280357284b0385ce46a57ab4afdcd6ae8e78d (diff) | |
download | rt.equinox.p2-f0966580855884e5394a8eefe84668adf30ca20a.tar.gz rt.equinox.p2-f0966580855884e5394a8eefe84668adf30ca20a.tar.xz rt.equinox.p2-f0966580855884e5394a8eefe84668adf30ca20a.zip |
Check for Windows packages using Windows registry
Bug: 456811
Change-Id: I4bce66b7a8ffe1f2844d5a3f3f19c6a8e1c96bee
Signed-off-by: Christian Georgi <christian.georgi@sap.com>
13 files changed, 460 insertions, 15 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/UIServices.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/UIServices.java index 0571b5c9c..4b378bcaf 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/UIServices.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/UIServices.java @@ -148,9 +148,10 @@ public abstract class UIServices { * Opens an information dialog * @param title - the title of the dialog * @param text - the text shown in the dialog + * @param linkText - an optional text to be rendered as hyperlink * @since 2.4 */ - public void showInformationMessage(String title, String text) { + public void showInformationMessage(String title, String text, String linkText) { System.out.println(text); } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java index 7f5c07251..a268a8667 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java @@ -47,6 +47,9 @@ import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.equinox.spi.p2.publisher.PublisherHelper; import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.service.resolver.BundleDescription; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; @@ -112,7 +115,7 @@ public abstract class AbstractProvisioningTest extends TestCase { assertTrue(message, !result.isOK()); } - protected static void assertOK(IStatus status) { + public static void assertOK(IStatus status) { assertOK("The status should have been OK.", status); } @@ -816,7 +819,7 @@ public abstract class AbstractProvisioningTest extends TestCase { * already exists. The returned profile will be removed automatically * in the tearDown method. */ - protected IProfile createProfile(String name, Map properties) { + public IProfile createProfile(String name, Map properties) { //remove any existing profile with the same name IProfileRegistry profileRegistry = getProfileRegistry(); profileRegistry.removeProfile(name); @@ -1747,4 +1750,26 @@ public abstract class AbstractProvisioningTest extends TestCase { IProvisioningPlan plan = planner.getProvisioningPlan(request, null, null); assertOK(plan.getStatus()); } + + /** + * Exposes {@link AbstractProvisioningTest}'s helper methods as JUnit {@link TestRule}. + * To be used by JUnit4 tests which must not extend {@link TestCase}. + */ + public static final class ProvisioningTestRuleAdapter extends AbstractProvisioningTest implements TestRule { + + public Statement apply(final Statement base, Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + setUp(); + try { + base.evaluate(); + } finally { + tearDown(); + } + } + }; + } + } + } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/natives/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/natives/AllTests.java index 077451ac1..7a131b84d 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/natives/AllTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/natives/AllTests.java @@ -30,6 +30,7 @@ public class AllTests extends TestCase { suite.addTestSuite(CopyActionTest.class); suite.addTestSuite(RemoveActionTest.class); suite.addTestSuite(BackupStoreTest.class); + suite.addTest(new JUnit4TestAdapter(CheckAndPromptNativePackageWindowsRegistryTest.class)); return suite; } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/natives/CheckAndPromptNativePackageWindowsRegistryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/natives/CheckAndPromptNativePackageWindowsRegistryTest.java new file mode 100644 index 000000000..0e24a1045 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/natives/CheckAndPromptNativePackageWindowsRegistryTest.java @@ -0,0 +1,198 @@ +/******************************************************************************* + * Copyright (c) 2015 SAP SE 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: + * SAP SE - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.tests.touchpoint.natives; + +import static org.eclipse.equinox.p2.tests.AbstractProvisioningTest.assertOK; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assume.assumeThat; + +import java.io.File; +import java.util.*; +import java.util.prefs.Preferences; +import org.eclipse.core.runtime.Platform; +import org.eclipse.equinox.internal.p2.touchpoint.natives.NativeTouchpoint; +import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.ActionConstants; +import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CheckAndPromptNativePackageWindowsRegistry; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.tests.AbstractProvisioningTest.ProvisioningTestRuleAdapter; +import org.junit.*; + +public class CheckAndPromptNativePackageWindowsRegistryTest { + + @BeforeClass + public static void classSetUp() throws Exception { + assumeThat("Windows only: uses Windows registry", Platform.getOS(), equalTo(Platform.OS_WIN32)); + } + + @Rule + public final ProvisioningTestRuleAdapter testHelper = new ProvisioningTestRuleAdapter(); + + private Preferences prefsNode; + + @Before + public void setUp() throws Exception { + prefsNode = Preferences.userNodeForPackage(getClass()); + prefsNode.clear(); + prefsNode.flush(); + } + + @Test + public void execute_StringAttribute() throws Exception { + String attributeName = "attribute"; + String attributeValue = "value"; + prefsNode.put(attributeName, attributeValue); + prefsNode.flush(); + + Map<String, Object> parameters = new HashMap<String, Object>(); + NativeTouchpoint touchpoint = createTouchpoint(parameters); + parameters.put(ActionConstants.PARM_LINUX_DISTRO, CheckAndPromptNativePackageWindowsRegistry.WINDOWS_DISTRO); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_NAME, "windows package"); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_VERSION, "1.0"); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_KEY, registryPath(prefsNode)); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_ATTRIBUTE_NAME, attributeName); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_ATTRIBUTE_VALUE, attributeValue); + parameters = Collections.unmodifiableMap(parameters); + + ProvisioningAction action = new CheckAndPromptNativePackageWindowsRegistry(); + action.setTouchpoint(touchpoint); + + assertOK(action.execute(parameters)); + assertEquals(Collections.emptyList(), touchpoint.getPackagesToInstall()); + } + + @Test + public void execute_StringAttribute_DifferentValues() throws Exception { + String attributeName = "attribute"; + String attributeValue = "value"; + prefsNode.put(attributeName, attributeValue); + prefsNode.flush(); + + Map<String, Object> parameters = new HashMap<String, Object>(); + NativeTouchpoint touchpoint = createTouchpoint(parameters); + parameters.put(ActionConstants.PARM_LINUX_DISTRO, CheckAndPromptNativePackageWindowsRegistry.WINDOWS_DISTRO); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_NAME, "windows package"); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_VERSION, "1.0"); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_KEY, registryPath(prefsNode)); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_ATTRIBUTE_NAME, attributeName); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_ATTRIBUTE_VALUE, attributeValue + "_DIFF"); + parameters = Collections.unmodifiableMap(parameters); + + ProvisioningAction action = new CheckAndPromptNativePackageWindowsRegistry(); + action.setTouchpoint(touchpoint); + + assertOK(action.execute(parameters)); + assertEquals(touchpoint.getPackagesToInstall().toString(), 1, touchpoint.getPackagesToInstall().size()); + } + + @Test + public void execute_IntAttribute() throws Exception { + String attributeName = "attribute"; + int attributeValue = 1; + prefsNode.putInt(attributeName, attributeValue); + prefsNode.flush(); + + Map<String, Object> parameters = new HashMap<String, Object>(); + NativeTouchpoint touchpoint = createTouchpoint(parameters); + parameters.put(ActionConstants.PARM_LINUX_DISTRO, CheckAndPromptNativePackageWindowsRegistry.WINDOWS_DISTRO); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_NAME, "windows package"); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_VERSION, "1.0"); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_KEY, registryPath(prefsNode)); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_ATTRIBUTE_NAME, attributeName); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_ATTRIBUTE_VALUE, String.valueOf(attributeValue)); + parameters = Collections.unmodifiableMap(parameters); + + ProvisioningAction action = new CheckAndPromptNativePackageWindowsRegistry(); + action.setTouchpoint(touchpoint); + + assertOK(action.execute(parameters)); + assertEquals(Collections.emptyList(), touchpoint.getPackagesToInstall()); + } + + @Test + public void execute_IntAttribute_DifferentLiteralValue() throws Exception { + String attributeName = "attribute"; + int attributeValue = 1; + prefsNode.putInt(attributeName, attributeValue); + prefsNode.flush(); + + Map<String, Object> parameters = new HashMap<String, Object>(); + NativeTouchpoint touchpoint = createTouchpoint(parameters); + parameters.put(ActionConstants.PARM_LINUX_DISTRO, CheckAndPromptNativePackageWindowsRegistry.WINDOWS_DISTRO); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_NAME, "windows package"); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_VERSION, "1.0"); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_KEY, registryPath(prefsNode)); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_ATTRIBUTE_NAME, attributeName); + // we simulate a different literal value + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_ATTRIBUTE_VALUE, "0" + String.valueOf(attributeValue)); + parameters = Collections.unmodifiableMap(parameters); + + ProvisioningAction action = new CheckAndPromptNativePackageWindowsRegistry(); + action.setTouchpoint(touchpoint); + + assertOK(action.execute(parameters)); + assertEquals(Collections.emptyList(), touchpoint.getPackagesToInstall()); + } + + @Test + public void execute_KeyExistence() throws Exception { + Map<String, Object> parameters = new HashMap<String, Object>(); + NativeTouchpoint touchpoint = createTouchpoint(parameters); + parameters.put(ActionConstants.PARM_LINUX_DISTRO, CheckAndPromptNativePackageWindowsRegistry.WINDOWS_DISTRO); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_NAME, "windows package"); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_VERSION, "1.0"); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_KEY, registryPath(prefsNode)); + parameters = Collections.unmodifiableMap(parameters); + + ProvisioningAction action = new CheckAndPromptNativePackageWindowsRegistry(); + action.setTouchpoint(touchpoint); + + assertOK(action.execute(parameters)); + assertEquals(Collections.emptyList(), touchpoint.getPackagesToInstall()); + } + + @Test + public void execute_KeyExistence_DifferentKeys() throws Exception { + Map<String, Object> parameters = new HashMap<String, Object>(); + NativeTouchpoint touchpoint = createTouchpoint(parameters); + parameters.put(ActionConstants.PARM_LINUX_DISTRO, CheckAndPromptNativePackageWindowsRegistry.WINDOWS_DISTRO); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_NAME, "windows package"); + parameters.put(ActionConstants.PARM_LINUX_PACKAGE_VERSION, "1.0"); + parameters.put(ActionConstants.PARM_WINDOWS_REGISTRY_KEY, registryPath(prefsNode) + "\\node"); + parameters = Collections.unmodifiableMap(parameters); + + ProvisioningAction action = new CheckAndPromptNativePackageWindowsRegistry(); + action.setTouchpoint(touchpoint); + + assertOK(action.execute(parameters)); + assertEquals(touchpoint.getPackagesToInstall().toString(), 1, touchpoint.getPackagesToInstall().size()); + } + + private NativeTouchpoint createTouchpoint(Map<String, Object> parameters) { + Properties profileProperties = new Properties(); + File installFolder = testHelper.getTempFolder(); + profileProperties.setProperty(IProfile.PROP_INSTALL_FOLDER, installFolder.toString()); + IProfile profile = testHelper.createProfile("test", profileProperties); + + parameters.put(ActionConstants.PARM_PROFILE, profile); + NativeTouchpoint touchpoint = new NativeTouchpoint(); + touchpoint.initializePhase(null, profile, "test", parameters); + return touchpoint; + } + + private static String registryPath(Preferences prefs) { + String path = prefs.absolutePath().replace('/', '\\'); + String root = prefs.isUserNode() ? "HKCU" : "HKLM"; + return root + "\\Software\\JavaSoft\\Prefs" + path; + } + +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/windows/isInstalled.bat b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/windows/isInstalled.bat new file mode 100644 index 000000000..feaf81541 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/nativePackageScripts/windows/isInstalled.bat @@ -0,0 +1,40 @@ +:: Check if a registry key and, optionally, an attribute is available in the registry. +:: Return 0 if the key/attribute is installed, 2 otherwise. +:: Usage +:: isInstalled.bat key [attributeName attributeValue] + +@echo off +SetLocal EnableExtensions + +Set key=%1 + +:: if no attribute name is supplied, only check the key +If "%2"=="" Goto check_key + + + +:check_attribute +Set attribute=%2 +Set value=%3 + +:: query registry and get the second and third token, which is the type and the value +For /F "usebackq tokens=2,3" %%A In (`reg query "%key%" /v "%attribute%" 2^>nul ^| find "%attribute%"`) Do ( + Set type=%%A + Set value_actual=%%B +) + +If "REG_DWORD"=="%type%" ( + :: convert hex to int value + Set /A value_actual=%value_actual% +) + +If Not %value_actual% Equ %value% exit /B 2 +exit /B 0 + + + +:check_key +reg query "%key%" >nul 2>nul +If Errorlevel 1 exit /B 2 + +exit /B 0 diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml b/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml index 527fe1f4c..067b2d715 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml @@ -122,6 +122,17 @@ </action> </extension> <extension + point="org.eclipse.equinox.p2.engine.actions"> + <action + class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CheckAndPromptNativePackageWindowsRegistry" + description="checkAndPromptNativePackageWindowsRegistry(package,version,key,attributeName,attributeValue)" + name="checkAndPromptNativePackageWindowsRegistry" + touchpointType="org.eclipse.equinox.p2.native" + touchpointVersion="1.0.0" + version="1.0.0"> + </action> + </extension> + <extension id="nativePackageExtractor" point="org.eclipse.core.runtime.applications"> <application 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 6fa5bc0c9..98dd0ba66 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 @@ -14,6 +14,7 @@ public class NativePackageEntry { public String name; public String version; public String comparator; + public String downloadLink; public String getComparator() { return comparator; @@ -44,4 +45,18 @@ public class NativePackageEntry { public void setVersion(String version) { this.version = version; } + + public String getDownloadLink() { + return downloadLink; + } + + public void setDownloadLink(String downloadLink) { + this.downloadLink = downloadLink; + } + + @Override + public String toString() { + return name + ' ' + version; + } + } 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 93451c83e..6dc1f65c6 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 @@ -63,6 +63,7 @@ public class NativePackageExtractionApplication implements IApplication { processArguments((String[]) context.getArguments().get("application.args")); //$NON-NLS-1$ initializeServices(); NativeTouchpoint.loadInstallCommandsProperties(installCommandsProperties, "debian"); //$NON-NLS-1$ + NativeTouchpoint.loadInstallCommandsProperties(installCommandsProperties, "windows"); //$NON-NLS-1$ collectData(); persistInformation(); } catch (CoreException e) { 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 206e3fba6..2c8544962 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 @@ -87,11 +87,28 @@ public class NativeTouchpoint extends Touchpoint { loadInstallCommandsProperties(installCommandsProperties, distro); UIServices serviceUI = (UIServices) agent.getService(UIServices.SERVICE_NAME); String text = Messages.PromptForNative_IntroText; + String downloadLinks = ""; //$NON-NLS-1$ + List<NativePackageEntry> entriesWithoutDownloadLink = new ArrayList<NativePackageEntry>(packagesToInstall.size()); for (NativePackageEntry nativePackageEntry : packagesToInstall) { - text += "\t" + nativePackageEntry.name + ' ' + formatVersion(nativePackageEntry) + "\n"; //$NON-NLS-1$//$NON-NLS-2$ + text += '\t' + nativePackageEntry.name + ' ' + formatVersion(nativePackageEntry) + '\n'; + if (nativePackageEntry.getDownloadLink() != null) { + downloadLinks += " <a>" + nativePackageEntry.getDownloadLink() + "</a>\n"; //$NON-NLS-1$ //$NON-NLS-2$ + } else { + entriesWithoutDownloadLink.add(nativePackageEntry); + } + } + + String installCommands = createCommand(entriesWithoutDownloadLink); + if (installCommands != null) { + text += Messages.PromptForNative_InstallText + installCommands; + } + + String downloadText = null; + if (downloadLinks.length() > 0) { + downloadText = "You can download those from the following locations:\n" + downloadLinks; } - text += Messages.PromptForNative_InstallText + createCommand(); - serviceUI.showInformationMessage(Messages.PromptForNative_DialogTitle, text); + + serviceUI.showInformationMessage(Messages.PromptForNative_DialogTitle, text, downloadText); } private String formatVersion(NativePackageEntry entry) { @@ -101,6 +118,8 @@ public class NativeTouchpoint extends Touchpoint { } private String getUserFriendlyComparator(String comparator) { + if (comparator == null) + return ""; //$NON-NLS-1$ return installCommandsProperties.getProperty(comparator, ""); //$NON-NLS-1$ } @@ -126,9 +145,11 @@ public class NativeTouchpoint extends Touchpoint { return installCommandsProperties.getProperty(INSTALL_PREFIX, ""); //$NON-NLS-1$ } - private String createCommand() { + private String createCommand(List<NativePackageEntry> packageEntries) { + if (packageEntries.isEmpty()) + return null; String text = getInstallCommad() + ' '; - for (NativePackageEntry nativePackageEntry : packagesToInstall) { + for (NativePackageEntry nativePackageEntry : packageEntries) { text += nativePackageEntry.name + " "; //$NON-NLS-1$ } return text; @@ -138,6 +159,10 @@ public class NativeTouchpoint extends Touchpoint { packagesToInstall.add(entry); } + public List<NativePackageEntry> getPackagesToInstall() { + return Collections.unmodifiableList(packagesToInstall); + } + public void setDistro(String distro) { this.distro = distro; } 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 d75317849..ee5e2ff1b 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,8 +34,12 @@ 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 String PARM_DOWNLOAD_LINK = "downloadLink"; //$NON-NLS-1$ 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 PARM_LINUX_VERSION_COMPARATOR = "comparator"; //$NON-NLS-1$ + public static final String PARM_WINDOWS_REGISTRY_KEY = "key"; //$NON-NLS-1$ + public static final String PARM_WINDOWS_REGISTRY_ATTRIBUTE_NAME = "attributeName"; //$NON-NLS-1$ + public static final String PARM_WINDOWS_REGISTRY_ATTRIBUTE_VALUE = "attributeValue"; //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CheckAndPromptNativePackageWindowsRegistry.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CheckAndPromptNativePackageWindowsRegistry.java new file mode 100644 index 000000000..d2768e030 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CheckAndPromptNativePackageWindowsRegistry.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2015 SAP SE 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: + * SAP SE - 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 CheckAndPromptNativePackageWindowsRegistry extends ProvisioningAction { + public static final String ID = "checkAndPromptNativePackageWindowsRegistry"; //$NON-NLS-1$ + public static final String WINDOWS_DISTRO = "windows"; //$NON-NLS-1$ + private static final boolean IS_WINDOWS = java.io.File.separatorChar == '\\'; + private static final String IS_INSTALLED = "isInstalled.bat"; //$NON-NLS-1$ + private static final String SHELL = "cmd.exe"; //$NON-NLS-1$ + + @Override + public IStatus execute(Map<String, Object> parameters) { + //If we are not running on Windows, do nothing and return + if (!IS_WINDOWS) + return Status.OK_STATUS; + + //Get and check the paremeters + String packageName = (String) parameters.get(ActionConstants.PARM_LINUX_PACKAGE_NAME); + String packageVersion = (String) parameters.get(ActionConstants.PARM_LINUX_PACKAGE_VERSION); + String key = (String) parameters.get(ActionConstants.PARM_WINDOWS_REGISTRY_KEY); + String attName = (String) parameters.get(ActionConstants.PARM_WINDOWS_REGISTRY_ATTRIBUTE_NAME); + String attValue = (String) parameters.get(ActionConstants.PARM_WINDOWS_REGISTRY_ATTRIBUTE_VALUE); + + if (key == null || (attName != null && attValue == null)) + return new Status(IStatus.ERROR, Activator.ID, Messages.Incorrect_Command); + + //Check if the desired package is installed and collect information in the touchpoint + File scriptToExecute = NativeTouchpoint.getFileFromBundle(WINDOWS_DISTRO, IS_INSTALLED); + if (scriptToExecute == null) + return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Cannot_Find_status, WINDOWS_DISTRO)); + + try { + List<String> cmd = new ArrayList<String>(6); + cmd.add(SHELL); + cmd.add("/c"); //$NON-NLS-1$ + cmd.add(scriptToExecute.getAbsolutePath()); + cmd.add(key); + if (attName != null) { + cmd.add(attName); + cmd.add(attValue); + } + int exitValue = new ProcessBuilder(cmd).start().waitFor(); + switch (exitValue) { + case 0 : + return Status.OK_STATUS; + case 1 : + case 2 : + default : + NativePackageEntry packageEntry = new NativePackageEntry(packageName, packageVersion, null); + String downloadLink = (String) parameters.get(ActionConstants.PARM_DOWNLOAD_LINK); + packageEntry.setDownloadLink(downloadLink); + ((NativeTouchpoint) getTouchpoint()).addPackageToInstall(packageEntry); + ((NativeTouchpoint) getTouchpoint()).setDistro(WINDOWS_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, WINDOWS_DISTRO})); + } catch (InterruptedException e) { + return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Cannot_Check_Package, new String[] {packageName, packageVersion, WINDOWS_DISTRO})); + } + } + + @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 8b2b04d5e..2df1df727 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,8 @@ 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 : \n -PromptForNative_DialogTitle=Install native software packages +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 Util_Error_Unzipping=Error unzipping {0}: {1} diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ValidationDialogServiceUI.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ValidationDialogServiceUI.java index 2994b7f0e..19506544a 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ValidationDialogServiceUI.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ValidationDialogServiceUI.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui; +import java.net.URL; import java.security.cert.Certificate; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.Job; @@ -23,8 +24,11 @@ import org.eclipse.jface.dialogs.*; import org.eclipse.jface.viewers.*; import org.eclipse.jface.window.Window; import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.*; import org.eclipse.ui.PlatformUI; /** @@ -33,6 +37,37 @@ import org.eclipse.ui.PlatformUI; */ public class ValidationDialogServiceUI extends UIServices { + + static final class MessageDialogWithLink extends MessageDialog { + private final String linkText; + + MessageDialogWithLink(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex, String linkText) { + super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex); + this.linkText = linkText; + } + + protected Control createCustomArea(Composite parent) { + if (linkText == null) + return super.createCustomArea(parent); + + Link link = new Link(parent, SWT.NONE); + link.setText(linkText); + link.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + try { + URL url = new URL(e.text); + PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(url); + } catch (Exception x) { + ProvUIActivator.getDefault().getLog().log(// + new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, x.getMessage(), x)); + } + } + }); + return link; + } + } + /** * Subclassed to add a cancel button to the error dialog. */ @@ -185,14 +220,15 @@ public class ValidationDialogServiceUI extends UIServices { return result[0]; } - public void showInformationMessage(final String title, final String text) { + public void showInformationMessage(final String title, final String text, final String linkText) { if (isHeadless()) { - super.showInformationMessage(title, text); + super.showInformationMessage(title, text, linkText); return; } PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { - MessageDialog.openInformation(ProvUI.getDefaultParentShell(), title, text); + MessageDialog dialog = new MessageDialogWithLink(ProvUI.getDefaultParentShell(), title, null, text, MessageDialog.INFORMATION, new String[] {IDialogConstants.OK_LABEL}, 0, linkText); + dialog.open(); } }); } @@ -203,4 +239,5 @@ public class ValidationDialogServiceUI extends UIServices { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291049 return !PlatformUI.isWorkbenchRunning(); } + } |