Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2009-02-12 01:01:34 +0000
committerPascal Rapicault2009-02-12 01:01:34 +0000
commitdc40844fedf1cee57f47f31460e7353024136d93 (patch)
tree8ac7b1b0163e134139f60d28114beda0a6a7be9c /bundles
parent149f9e0fbb539734e60e3bd591841dfd924036e3 (diff)
downloadrt.equinox.p2-dc40844fedf1cee57f47f31460e7353024136d93.tar.gz
rt.equinox.p2-dc40844fedf1cee57f47f31460e7353024136d93.tar.xz
rt.equinox.p2-dc40844fedf1cee57f47f31460e7353024136d93.zip
Support for smarter handling of the VM args
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddJVMArgumentActionTest.java46
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/JVMArgumentActionLogicTest.java280
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/ActionConstants.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/AddJVMArgumentAction.java265
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/Messages.java5
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RemoveJVMArgumentAction.java85
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/messages.properties43
8 files changed, 682 insertions, 48 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddJVMArgumentActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddJVMArgumentActionTest.java
index b0ffb94f3..4b620deaa 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddJVMArgumentActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AddJVMArgumentActionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2008-2009 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 http://www.eclipse.org/legal/epl-v10.html
@@ -8,10 +8,12 @@
******************************************************************************/
package org.eclipse.equinox.p2.tests.touchpoint.eclipse;
+import java.io.File;
import java.util.*;
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint;
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.ActionConstants;
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.AddJVMArgumentAction;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
import org.eclipse.equinox.internal.provisional.p2.engine.InstallableUnitOperand;
@@ -19,6 +21,10 @@ import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
public class AddJVMArgumentActionTest extends AbstractProvisioningTest {
+ private static File tempDir;
+ private LauncherData launcherData;
+ private Map parameters;
+
public AddJVMArgumentActionTest(String name) {
super(name);
}
@@ -27,8 +33,12 @@ public class AddJVMArgumentActionTest extends AbstractProvisioningTest {
super("");
}
- public void testExecuteUndo() {
- Map parameters = new HashMap();
+ public void setUp() throws Exception {
+ super.setUp();
+ tempDir = new File(System.getProperty("java.io.tmpdir"), "JVMArgs");
+ tempDir.mkdirs();
+
+ parameters = new HashMap();
EclipseTouchpoint touchpoint = new EclipseTouchpoint();
Properties profileProperties = new Properties();
profileProperties.setProperty(IProfile.PROP_INSTALL_FOLDER, getTempFolder().toString());
@@ -37,18 +47,36 @@ public class AddJVMArgumentActionTest extends AbstractProvisioningTest {
touchpoint.initializePhase(null, profile, "test", parameters);
parameters.put("iu", operand.second());
touchpoint.initializeOperand(profile, operand, parameters);
+ parameters.put(ActionConstants.PARM_PROFILE_DATA_DIRECTORY, tempDir);
+
Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
assertNotNull(manipulator);
+ launcherData = manipulator.getLauncherData();
+ }
+ public void tearDown() throws Exception {
+ delete(tempDir);
+ super.tearDown();
+ }
+
+ public void testExecuteUndo() {
String jvmArg = "-Dtest=true";
- assertFalse(Arrays.asList(manipulator.getLauncherData().getJvmArgs()).contains(jvmArg));
+
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(jvmArg));
parameters.put(ActionConstants.PARM_JVM_ARG, jvmArg);
- parameters = Collections.unmodifiableMap(parameters);
AddJVMArgumentAction action = new AddJVMArgumentAction();
- action.execute(parameters);
- assertTrue(Arrays.asList(manipulator.getLauncherData().getJvmArgs()).contains(jvmArg));
- action.undo(parameters);
- assertFalse(Arrays.asList(manipulator.getLauncherData().getJvmArgs()).contains(jvmArg));
+ action.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(jvmArg));
+ action.undo(Collections.unmodifiableMap(parameters));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(jvmArg));
+
+ // Test using byte argument
+ String byteArg = "-Xmx256M";
+ parameters.put(ActionConstants.PARM_JVM_ARG, byteArg);
+ action.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(byteArg));
+ action.undo(Collections.unmodifiableMap(parameters));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(byteArg));
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java
index 927be272d..abf8b1fb7 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/AllTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others.
+ * Copyright (c) 2008-2009 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
@@ -28,6 +28,7 @@ public class AllTests extends TestCase {
suite.addTestSuite(CollectActionTest.class);
suite.addTestSuite(InstallBundleActionTest.class);
suite.addTestSuite(InstallFeatureActionTest.class);
+ suite.addTestSuite(JVMArgumentActionLogicTest.class);
suite.addTestSuite(MarkStartedActionTest.class);
suite.addTestSuite(RemoveJVMArgumentActionTest.class);
suite.addTestSuite(RemoveProgramArgumentActionTest.class);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/JVMArgumentActionLogicTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/JVMArgumentActionLogicTest.java
new file mode 100644
index 000000000..0128758d4
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/eclipse/JVMArgumentActionLogicTest.java
@@ -0,0 +1,280 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.touchpoint.eclipse;
+
+import java.io.File;
+import java.util.*;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.*;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
+import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
+import org.eclipse.equinox.internal.provisional.p2.engine.InstallableUnitOperand;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+
+public class JVMArgumentActionLogicTest extends AbstractProvisioningTest {
+
+ private static File tempDir;
+ private Map parameters;
+ private LauncherData launcherData;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ tempDir = new File(System.getProperty("java.io.tmpdir"), "JVMArgs");
+ tempDir.mkdirs();
+
+ parameters = new HashMap();
+ EclipseTouchpoint touchpoint = new EclipseTouchpoint();
+ Properties profileProperties = new Properties();
+ profileProperties.setProperty(IProfile.PROP_INSTALL_FOLDER, getTempFolder().toString());
+ IProfile profile = createProfile("test", null, profileProperties);
+ InstallableUnitOperand operand = new InstallableUnitOperand(null, createIU("test"));
+ touchpoint.initializePhase(null, profile, "test", parameters);
+ parameters.put("iu", operand.second());
+ touchpoint.initializeOperand(profile, operand, parameters);
+ parameters.put(ActionConstants.PARM_PROFILE_DATA_DIRECTORY, tempDir);
+
+ Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
+ assertNotNull(manipulator);
+ launcherData = manipulator.getLauncherData();
+ }
+
+ public void tearDown() throws Exception {
+ AbstractProvisioningTest.delete(tempDir);
+ super.tearDown();
+ }
+
+ public void testStandardUse() {
+ AddJVMArgumentAction addAction = new AddJVMArgumentAction();
+ RemoveJVMArgumentAction rmAction = new RemoveJVMArgumentAction();
+
+ String maxJvmArg = "-Xmx512M";
+ String minJvmArg = "-Xmx256M";
+ String diffJvmArg = "-Xms50M";
+
+ // Add a value then undo
+ parameters.put(ActionConstants.PARM_JVM_ARG, maxJvmArg);
+ addAction.execute(parameters);
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(maxJvmArg));
+ addAction.undo(parameters);
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(maxJvmArg));
+
+ // Add value
+ parameters.put(ActionConstants.PARM_JVM_ARG, minJvmArg);
+ addAction = new AddJVMArgumentAction();
+ addAction.execute(parameters);
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(minJvmArg));
+
+ // Add a different type of argument
+ parameters.put(ActionConstants.PARM_JVM_ARG, diffJvmArg);
+ addAction.execute(parameters);
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(minJvmArg));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(diffJvmArg));
+ rmAction.execute(parameters);
+
+ // Add a larger value
+ parameters.put(ActionConstants.PARM_JVM_ARG, maxJvmArg);
+ addAction.execute(parameters);
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(maxJvmArg));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(minJvmArg));
+
+ // Remove large value
+ rmAction.execute(parameters);
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(minJvmArg));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(maxJvmArg));
+
+ // Remove first value
+ parameters.put(ActionConstants.PARM_JVM_ARG, minJvmArg);
+ rmAction.execute(parameters);
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(minJvmArg));
+ }
+
+ public void testPrefixEvaluation() {
+ String gigabyteArg = "-XX:MaxPermSize=1G";
+ String megabyteArg = "-XX:MaxPermSize=1M";
+ String kilobyteArg = "-XX:MaxPermSize=1K";
+ String byteArg = "-XX:MaxPermSize=1";
+ AddJVMArgumentAction addAction = new AddJVMArgumentAction();
+ RemoveJVMArgumentAction rmAction = new RemoveJVMArgumentAction();
+
+ // Standard prefix evaluation
+ parameters.put(ActionConstants.PARM_JVM_ARG, byteArg);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(byteArg));
+
+ parameters.put(ActionConstants.PARM_JVM_ARG, kilobyteArg);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(kilobyteArg));
+
+ parameters.put(ActionConstants.PARM_JVM_ARG, megabyteArg);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(megabyteArg));
+
+ parameters.put(ActionConstants.PARM_JVM_ARG, gigabyteArg);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(gigabyteArg));
+
+ // Remove values
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ parameters.put(ActionConstants.PARM_JVM_ARG, megabyteArg);
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ parameters.put(ActionConstants.PARM_JVM_ARG, kilobyteArg);
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ parameters.put(ActionConstants.PARM_JVM_ARG, byteArg);
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+
+ // Non-standard prefix evaluation
+ gigabyteArg = "-Xmx1G";
+ megabyteArg = "-Xmx2048M";
+
+ parameters.put(ActionConstants.PARM_JVM_ARG, gigabyteArg);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(gigabyteArg));
+
+ parameters.put(ActionConstants.PARM_JVM_ARG, megabyteArg);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(megabyteArg));
+
+ // Clear state
+ parameters.put(ActionConstants.PARM_JVM_ARG, megabyteArg);
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ parameters.put(ActionConstants.PARM_JVM_ARG, gigabyteArg);
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).size() == 0);
+ }
+
+ public void testInvalidValues() {
+ AddJVMArgumentAction action = new AddJVMArgumentAction();
+
+ String invalid = "-Xms25F";
+ String valid = "-Xms256M";
+
+ parameters.put(ActionConstants.PARM_JVM_ARG, invalid);
+
+ IStatus result = action.execute(Collections.unmodifiableMap(parameters));
+ if (!result.matches(IStatus.ERROR) && !(result.getException() instanceof IllegalArgumentException))
+ fail("Invalid Action value not caught!");
+
+ // User has injected an invalid value
+ launcherData.addJvmArg(invalid);
+ parameters.put(ActionConstants.PARM_JVM_ARG, valid);
+
+ result = action.execute(Collections.unmodifiableMap(parameters));
+ if (!result.matches(IStatus.ERROR) && !(result.getException() instanceof IllegalArgumentException))
+ fail("Invalid injected value not caught!");
+
+ launcherData.removeJvmArg(invalid);
+ }
+
+ public void testUserInjectsInitialValue() {
+ String userValue = "-Xmx400M";
+ String largeValue = "-Xmx512M";
+ AddJVMArgumentAction addAction = new AddJVMArgumentAction();
+ RemoveJVMArgumentAction rmAction = new RemoveJVMArgumentAction();
+
+ // Simulate a user injected value
+ launcherData.addJvmArg(userValue);
+
+ // Add a larger value
+ parameters.put(ActionConstants.PARM_JVM_ARG, largeValue);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(largeValue));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(userValue));
+
+ // Remove added value
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(largeValue));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(userValue));
+
+ // Clear state
+ launcherData.removeJvmArg(userValue);
+ parameters.put(ActionConstants.PARM_JVM_ARG, "-Xmx300M");
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).size() == 0);
+ }
+
+ public void testUserInjectsLargerValue() {
+ AddJVMArgumentAction addAction = new AddJVMArgumentAction();
+ RemoveJVMArgumentAction rmAction = new RemoveJVMArgumentAction();
+ String userValue = "-Xmx400M";
+ String initialValue = "-Xmx256M";
+ String smallValue = "-Xmx100M";
+
+ // Initial value
+ parameters.put(ActionConstants.PARM_JVM_ARG, initialValue);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(initialValue));
+
+ // Inject value
+ launcherData.removeJvmArg(initialValue);
+ launcherData.addJvmArg(userValue);
+
+ // Smaller value added
+ parameters.put(ActionConstants.PARM_JVM_ARG, smallValue);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(userValue));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(initialValue));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(smallValue));
+
+ // Value equal to User's added & removed
+ parameters.put(ActionConstants.PARM_JVM_ARG, userValue);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(userValue));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(initialValue));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(smallValue));
+
+ // Clear state
+ launcherData.removeJvmArg(userValue);
+ parameters.put(ActionConstants.PARM_JVM_ARG, initialValue);
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).size() == 0);
+ }
+
+ public void testUserInjectsSmallerValue() {
+ AddJVMArgumentAction addAction = new AddJVMArgumentAction();
+ RemoveJVMArgumentAction rmAction = new RemoveJVMArgumentAction();
+ String userValue = "-Xmx100M";
+ String initialValue = "-Xmx256M";
+ String largeValue = "-Xmx512M";
+
+ // Initial value
+ parameters.put(ActionConstants.PARM_JVM_ARG, initialValue);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(initialValue));
+
+ // Inject value
+ launcherData.removeJvmArg(initialValue);
+ launcherData.addJvmArg(userValue);
+
+ // Add new value
+ parameters.put(ActionConstants.PARM_JVM_ARG, largeValue);
+ addAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(largeValue));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(initialValue));
+ assertFalse(Arrays.asList(launcherData.getJvmArgs()).contains(userValue));
+
+ // Remove values
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ parameters.put(ActionConstants.PARM_JVM_ARG, initialValue);
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).contains(userValue));
+
+ // Clear state
+ launcherData.removeJvmArg(userValue);
+ parameters.put(ActionConstants.PARM_JVM_ARG, initialValue);
+ rmAction.execute(Collections.unmodifiableMap(parameters));
+ assertTrue(Arrays.asList(launcherData.getJvmArgs()).size() == 0);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/ActionConstants.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/ActionConstants.java
index abea53759..ad7ec6374 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/ActionConstants.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/ActionConstants.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2008-2009 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 http://www.eclipse.org/legal/epl-v10.html
@@ -36,6 +36,7 @@ public class ActionConstants {
public static final String PARM_LINK_TARGET = "linkTarget"; //$NON-NLS-1$
public static final String PARM_TARGET_FILE = "targetFile"; //$NON-NLS-1$
public static final String PARM_PERMISSIONS = "permissions"; //$NON-NLS-1$
+ public static final String PARM_PROFILE_DATA_DIRECTORY = "profileDataDirectory"; //$NON-NLS-1$
public static final String PARM_REPOSITORY_LOCATION = "location"; //$NON-NLS-1$
public static final String PARM_REPOSITORY_TYPE = "type"; //$NON-NLS-1$
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/AddJVMArgumentAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/AddJVMArgumentAction.java
index be5c221ef..1729291de 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/AddJVMArgumentAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/AddJVMArgumentAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2008-2009 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 http://www.eclipse.org/legal/epl-v10.html
@@ -8,33 +8,280 @@
******************************************************************************/
package org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions;
-import java.util.Map;
+import java.io.*;
+import java.util.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint;
-import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.*;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
import org.eclipse.osgi.util.NLS;
public class AddJVMArgumentAction extends ProvisioningAction {
public static final String ID = "addJvmArg"; //$NON-NLS-1$
+ protected static final String STORAGE = "org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions" + File.separator + "jvmargs"; //$NON-NLS-1$//$NON-NLS-2$
+
+ protected static final String XMX = "-Xmx"; //$NON-NLS-1$
+ protected static final String XMS = "-Xms"; //$NON-NLS-1$
+ protected static final String XX_MAX_PERM_SIZE = "-XX:MaxPermSize="; //$NON-NLS-1$
+ protected static final String PREFIX_USER_VALUE = "eclipse.userDefined:"; //$NON-NLS-1$
public IStatus execute(Map parameters) {
- Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
String jvmArg = (String) parameters.get(ActionConstants.PARM_JVM_ARG);
if (jvmArg == null)
return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_JVM_ARG, ID));
- manipulator.getLauncherData().addJvmArg(jvmArg);
- return Status.OK_STATUS;
+ return addArg(jvmArg, parameters);
}
public IStatus undo(Map parameters) {
- Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
String jvmArg = (String) parameters.get(ActionConstants.PARM_JVM_ARG);
if (jvmArg == null)
return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_JVM_ARG, ID));
- manipulator.getLauncherData().removeJvmArg(jvmArg);
+ return RemoveJVMArgumentAction.removeArg(jvmArg, parameters);
+ }
+
+ protected static String getUserArg(Properties storedValues, String flag) {
+ return storedValues.getProperty(PREFIX_USER_VALUE + flag);
+ }
+
+ protected static IStatus addArg(String arg, Map parameters) {
+ LauncherData launcherData = ((Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR)).getLauncherData();
+ File storageArea = (File) parameters.get(ActionConstants.PARM_PROFILE_DATA_DIRECTORY);
+ try {
+ if (arg.startsWith(XMS))
+ addByteArg(arg, XMS, launcherData, storageArea);
+ else if (arg.startsWith(XMX))
+ addByteArg(arg, XMX, launcherData, storageArea);
+ else if (arg.startsWith(XX_MAX_PERM_SIZE))
+ addByteArg(arg, XX_MAX_PERM_SIZE, launcherData, storageArea);
+ else
+ // Argument with a non-byte value, no special handling
+ launcherData.addJvmArg(arg);
+ } catch (IOException e) {
+ return new Status(IStatus.ERROR, Activator.ID, Messages.error_processing_vmargs, e);
+ } catch (IllegalArgumentException e) {
+ return new Status(IStatus.ERROR, Activator.ID, Messages.error_processing_vmargs, e);
+ }
return Status.OK_STATUS;
}
+
+ protected static void addByteArg(String arg, String flag, LauncherData launcherData, File storageArea) throws IOException {
+ Properties storedValues = load(storageArea);
+ String currentArg = getCurrentArg(flag, launcherData.getJvmArgs());
+
+ // Check for user changes
+ detectUserValue(currentArg, flag, storedValues);
+ validateValue(arg.substring(flag.length()));
+
+ rememberArg(storedValues, arg.substring(flag.length()), flag);
+ launcherData.removeJvmArg(currentArg);
+
+ // Set the argument to use & save stored values
+ setToMax(flag, storedValues, launcherData);
+ save(storedValues, storageArea);
+ }
+
+ // Throws exception if the argument is not a valid byte argument
+ protected static void validateValue(String arg) {
+ getByteValue(arg, getBytePower(arg));
+ }
+
+ // Determine if the user has changed config, if so save their value
+ protected static void detectUserValue(String currentValue, String flag, Properties storedValues) {
+ String maxValue = getMaxValue(getArgs(storedValues, flag));
+
+ if (currentValue == null)
+ // User has removed value from file
+ setUserArg(storedValues, flag, null);
+ else if ((maxValue == null) || (!maxValue.equals(currentValue.substring(flag.length()))))
+ // User has set an initial value, or modified the file
+ setUserArg(storedValues, flag, currentValue.substring(flag.length()));
+ }
+
+ protected static String getMaxValue(String[] values) {
+ if (values == null || values.length == 0)
+ return null;
+
+ int max = 0;
+ for (int i = 1; i < values.length; i++)
+ if (compareSize(values[max], values[i]) < 0)
+ max = i;
+ return values[max];
+ }
+
+ protected static void setToMax(String flag, Properties storedValues, LauncherData launcherData) {
+ String maxStored = getMaxValue(getArgs(storedValues, flag));
+ String userDefined = AddJVMArgumentAction.getUserArg(storedValues, flag);
+
+ if ((maxStored != null) || (userDefined != null)) {
+ // Replacement is available either stored, or user defined
+ if (maxStored == null)
+ launcherData.addJvmArg(flag + userDefined);
+ else if (userDefined == null)
+ launcherData.addJvmArg(flag + maxStored);
+ else if (AddJVMArgumentAction.compareSize(maxStored, userDefined) > 0)
+ launcherData.addJvmArg(flag + maxStored);
+ else
+ launcherData.addJvmArg(flag + userDefined);
+ }
+ }
+
+ // Returns: 1 when a>b, 0 when a=b, -1 when a<b
+ protected static int compareSize(String a, String b) {
+ double aVal, bVal;
+ int aPower = getBytePower(a);
+ int bPower = getBytePower(b);
+
+ aVal = getByteValue(a, aPower);
+ bVal = getByteValue(b, bPower);
+ // Ensure a value is expressed with the highest power (e.g. 2G not 2048M)
+ while (aVal > 1024) {
+ aVal /= 1024;
+ aPower += 10;
+ }
+ while (bVal > 1024) {
+ bVal /= 1024;
+ bPower += 10;
+ }
+
+ if ((aPower > bPower) && (aVal != 0))
+ return 1;
+ else if ((aPower < bPower) && (bVal != 0))
+ return -1;
+ // Both have same power, so direct comparison
+ else if (aVal > bVal)
+ return 1;
+ else if (aVal < bVal)
+ return -1;
+ else
+ return 0;
+ }
+
+ // Parse the numeric portion of an argument
+ private static double getByteValue(String arg, int power) {
+ try {
+ if (power == 0)
+ return Integer.parseInt(arg);
+ return Integer.parseInt(arg.substring(0, arg.length() - 1));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(NLS.bind(Messages.invalid_byte_format, arg));
+ }
+ }
+
+ private static int getBytePower(String arg) {
+ // If last digit determines if the value is in bytes,
+ // kilobytes, megabytes, or gigabytes
+ switch (arg.charAt(arg.length() - 1)) {
+ case 'k' :
+ case 'K' :
+ return 10;
+ case 'm' :
+ case 'M' :
+ return 20;
+ case 'g' :
+ case 'G' :
+ return 30;
+ default :
+ return 0;
+ }
+ }
+
+ // Get the current used argument if there is one
+ protected static String getCurrentArg(String flag, String[] jvmArgs) {
+ for (int i = 0; i < jvmArgs.length; i++)
+ if ((jvmArgs[i] != null) && (jvmArgs[i].startsWith(flag)))
+ return jvmArgs[i];
+ return null;
+ }
+
+ // Add one new value to those stored
+ protected static void rememberArg(Properties storedValues, String value, String flag) {
+ String argString = storedValues.getProperty(flag);
+
+ if (argString == null)
+ argString = ""; //$NON-NLS-1$
+ else if (argString.length() > 0)
+ argString += ',';
+
+ argString += value;
+
+ if (argString.length() != 0)
+ storedValues.put(flag, argString);
+ }
+
+ protected static String[] getArgs(Properties storage, String flag) {
+ String argString = storage.getProperty(flag);
+ if (argString == null || argString.length() == 0)
+ return new String[0];
+
+ List list = new ArrayList();
+ int i = 0;
+ String arg = ""; //$NON-NLS-1$
+
+ // Split comma-separated list into a List
+ while (i < argString.length()) {
+ char c = argString.charAt(i++);
+ if (c == ',') {
+ list.add(arg);
+ arg = ""; //$NON-NLS-1$
+ } else
+ arg += c;
+ }
+
+ list.add(arg);
+ String[] argList = new String[list.size()];
+ list.toArray(argList);
+
+ return argList;
+ }
+
+ // Store a single user argument, null removes stored values
+ private static void setUserArg(Properties storage, String flag, String value) {
+ if (value == null)
+ storage.remove(PREFIX_USER_VALUE + flag);
+ else
+ storage.setProperty(PREFIX_USER_VALUE + flag, value);
+ }
+
+ protected static Properties load(File storageArea) throws IOException {
+ Properties args = new Properties();
+ File file = new File(storageArea, STORAGE);
+ if (file.exists()) {
+ // Only load if file already exists
+ FileInputStream in = null;
+ try {
+ try {
+ in = new FileInputStream(file);
+ args.load(in);
+ } finally {
+ if (in != null)
+ in.close();
+ }
+ } catch (FileNotFoundException e) {
+ // Should not occur as we check to see if it exists
+ }
+ }
+ return args;
+ }
+
+ protected static void save(Properties args, File storageArea) throws IOException {
+ FileOutputStream out = null;
+ File file = new File(storageArea, STORAGE);
+ if (!file.exists())
+ // Ensure parent directory exists
+ file.getParentFile().mkdirs();
+
+ try {
+ try {
+ out = new FileOutputStream(file);
+ args.store(out, null);
+ } finally {
+ if (out != null)
+ out.close();
+ }
+ } catch (FileNotFoundException e) {
+ throw new IllegalStateException(NLS.bind(Messages.unable_to_open_file, file));
+ }
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/Messages.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/Messages.java
index 159dd9e4f..4f44c6a47 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/Messages.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/Messages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others.
+ * Copyright (c) 2008-2009 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
@@ -23,6 +23,9 @@ public class Messages extends NLS {
public static String cannot_configure_source_bundle;
public static String error_parsing_startlevel;
public static String no_bundle_pool;
+ public static String error_processing_vmargs;
+ public static String invalid_byte_format;
+ public static String unable_to_open_file;
static {
// load message values from bundle file and assign to fields below
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RemoveJVMArgumentAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RemoveJVMArgumentAction.java
index fd2815ed7..3560e8acd 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RemoveJVMArgumentAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RemoveJVMArgumentAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2008-2009 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 http://www.eclipse.org/legal/epl-v10.html
@@ -8,11 +8,14 @@
******************************************************************************/
package org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions;
+import java.io.File;
+import java.io.IOException;
import java.util.Map;
+import java.util.Properties;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint;
-import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util;
+import org.eclipse.equinox.internal.p2.touchpoint.eclipse.*;
+import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
import org.eclipse.osgi.util.NLS;
@@ -21,20 +24,88 @@ public class RemoveJVMArgumentAction extends ProvisioningAction {
public static final String ID = "removeJvmArg"; //$NON-NLS-1$
public IStatus execute(Map parameters) {
- Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
String jvmArg = (String) parameters.get(ActionConstants.PARM_JVM_ARG);
if (jvmArg == null)
return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_JVM_ARG, ID));
- manipulator.getLauncherData().removeJvmArg(jvmArg);
+ removeArg(jvmArg, parameters);
return Status.OK_STATUS;
}
public IStatus undo(Map parameters) {
- Manipulator manipulator = (Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR);
String jvmArg = (String) parameters.get(ActionConstants.PARM_JVM_ARG);
if (jvmArg == null)
return Util.createError(NLS.bind(Messages.parameter_not_set, ActionConstants.PARM_JVM_ARG, ID));
- manipulator.getLauncherData().addJvmArg(jvmArg);
+ AddJVMArgumentAction.addArg(jvmArg, parameters);
return Status.OK_STATUS;
}
+
+ public static IStatus removeArg(String arg, Map parameters) {
+ LauncherData launcherData = ((Manipulator) parameters.get(EclipseTouchpoint.PARM_MANIPULATOR)).getLauncherData();
+ File storageArea = (File) parameters.get(ActionConstants.PARM_PROFILE_DATA_DIRECTORY);
+
+ try {
+ if (arg.startsWith(AddJVMArgumentAction.XMS))
+ removeByteArg(arg, AddJVMArgumentAction.XMS, launcherData, storageArea);
+ else if (arg.startsWith(AddJVMArgumentAction.XMX))
+ removeByteArg(arg, AddJVMArgumentAction.XMX, launcherData, storageArea);
+ else if (arg.startsWith(AddJVMArgumentAction.XX_MAX_PERM_SIZE))
+ removeByteArg(arg, AddJVMArgumentAction.XX_MAX_PERM_SIZE, launcherData, storageArea);
+ else
+ // Argument with a non-byte value, no special handling
+ launcherData.removeJvmArg(arg);
+ } catch (IOException e) {
+ return new Status(IStatus.ERROR, Activator.ID, Messages.error_processing_vmargs, e);
+ } catch (IllegalArgumentException e) {
+ return new Status(IStatus.ERROR, Activator.ID, Messages.error_processing_vmargs, e);
+ }
+ return Status.OK_STATUS;
+ }
+
+ private static void removeByteArg(String arg, String flag, LauncherData launcherData, File storageArea) throws IOException {
+ Properties storedValues = AddJVMArgumentAction.load(storageArea);
+
+ String argValue = arg.substring(flag.length());
+ String currentArg = AddJVMArgumentAction.getCurrentArg(flag, launcherData.getJvmArgs());
+ // Check for user changes
+ AddJVMArgumentAction.detectUserValue(currentArg, flag, storedValues);
+ AddJVMArgumentAction.validateValue(arg.substring(flag.length()));
+
+ removeArg(storedValues, argValue, flag);
+ launcherData.removeJvmArg(currentArg);
+
+ // Set the argument to use & save stored values
+ AddJVMArgumentAction.setToMax(flag, storedValues, launcherData);
+ AddJVMArgumentAction.save(storedValues, storageArea);
+ }
+
+ private static void removeArg(Properties storage, String value, String flag) {
+ String[] args = AddJVMArgumentAction.getArgs(storage, flag);
+ for (int i = 0; i < args.length; i++)
+ if (args[i].equals(value)) {
+ args[i] = null;
+ // Stop now that we've removed a matching argument
+ break;
+ }
+ setArgs(storage, flag, args);
+ }
+
+ private static void setArgs(Properties storedValues, String flag, String[] args) {
+ if (args == null || args.length == 0)
+ // Null or empty list, unset flag
+ storedValues.remove(flag);
+ else {
+ // Build a comma separated list of values for this flag
+ String argString = ""; //$NON-NLS-1$
+ for (int i = 0; i < args.length; i++)
+ if (args[i] != null)
+ argString += args[i] + ',';
+
+ if (argString.length() > 0)
+ // Strip the trailing comma
+ storedValues.setProperty(flag, argString.substring(0, argString.length() - 1));
+ else
+ // Array was full of null values, unset flag
+ storedValues.remove(flag);
+ }
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/messages.properties b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/messages.properties
index db2a2e606..4392524be 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/messages.properties
@@ -1,20 +1,23 @@
-###############################################################################
-# Copyright (c) 2008 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
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-artifact_file_not_found=The artifact file for {0} was not found.
-parameter_not_set=The \"{0}\" parameter was not set in the \"{1}\" action.
-iu_contains_no_arifacts=Installable unit contains no artifacts: {0}.
-no_matching_artifact=No matching artifact found for: {0}.
-missing_manifest=The manifest is missing for: {0}.
-failed_bundleinfo=Failed to create bundleInfo for: {0}.
-cannot_configure_source_bundle=Cannot configure {0} as a source bundle.
-error_parsing_startlevel=Error parsing start level: {0} for bundle: {1}.
-no_bundle_pool=No bundle pool defined for profile: {0}. \ No newline at end of file
+###############################################################################
+# Copyright (c) 2008 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
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+
+artifact_file_not_found=The artifact file for {0} was not found.
+parameter_not_set=The \"{0}\" parameter was not set in the \"{1}\" action.
+iu_contains_no_arifacts=Installable unit contains no artifacts: {0}.
+no_matching_artifact=No matching artifact found for: {0}.
+missing_manifest=The manifest is missing for: {0}.
+failed_bundleinfo=Failed to create bundleInfo for: {0}.
+cannot_configure_source_bundle=Cannot configure {0} as a source bundle.
+error_parsing_startlevel=Error parsing start level: {0} for bundle: {1}.
+no_bundle_pool=No bundle pool defined for profile: {0}.
+error_processing_vmargs=An error occurred while processing the JVM argument.
+invalid_byte_format=Invalid format for byte argument: {0}.
+unable_to_open_file=Unable to open file: {0}.

Back to the top