summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrzysztof Daniel2013-01-24 07:23:15 (EST)
committerPascal Rapicault2013-01-27 22:09:53 (EST)
commit54c8d356527d1321e25bd837e674b758aa61e248 (patch)
tree80e4f61cb25caab90fa7f0679d51c3794a21ae9d
parent6177c466083fb7676ebfe5790bc0951043b3b727 (diff)
downloadrt.equinox.p2-54c8d356527d1321e25bd837e674b758aa61e248.zip
rt.equinox.p2-54c8d356527d1321e25bd837e674b758aa61e248.tar.gz
rt.equinox.p2-54c8d356527d1321e25bd837e674b758aa61e248.tar.bz2
SimpleConfiguratorImpl refactoring and tests.
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTest.java106
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/testData/simpleconfigurator/master/bundles.info0
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/testData/simpleconfigurator/user/bundles.info0
-rw-r--r--bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java62
5 files changed, 145 insertions, 24 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTest.java
new file mode 100644
index 0000000..0d964ac
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTest.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, 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: Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.equinox.p2.tests.simpleconfigurator;
+
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+import org.eclipse.equinox.internal.simpleconfigurator.SimpleConfiguratorImpl;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+
+public class SimpleConfiguratorTest extends AbstractProvisioningTest {
+
+ private URL relativeURL;
+ private File userConfiguration;
+ private File masterConfguration;
+ private URL[] sharedConfiguration = new URL[2];
+ private URL[] localConfiguration = new URL[1];
+ private SimpleConfiguratorImpl configurator;
+
+ public void setUp() throws Exception {
+ relativeURL = new URL("file://bundles.info");
+ userConfiguration = getTestData("userConfiguration", "testData/simpleconfigurator/user");
+ sharedConfiguration[0] = userConfiguration.toURL();
+ masterConfguration = getTestData("userConfiguration", "testData/simpleconfigurator/master");
+ sharedConfiguration[1] = masterConfguration.toURL();
+ localConfiguration[0] = sharedConfiguration[1];
+ configurator = getSimpleConfigurator();
+ }
+
+ private SimpleConfiguratorImpl getSimpleConfigurator() {
+ return new SimpleConfiguratorImpl(null, null);
+ }
+
+ private void storeTimestamp(long timestamp) throws IOException {
+ File f = new File(userConfiguration.getParent(), SimpleConfiguratorImpl.BASE_TIMESTAMP_FILE_BUNDLESINFO);
+ Properties p = new Properties();
+ p.put(SimpleConfiguratorImpl.KEY_BUNDLESINFO_TIMESTAMP, "" + timestamp);
+ p.store(new FileWriter(f), "");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ System.setProperty(SimpleConfiguratorImpl.PROP_IGNORE_USER_CONFIGURATION, "false");
+ File f = new File(userConfiguration.getParent(), SimpleConfiguratorImpl.BASE_TIMESTAMP_FILE_BUNDLESINFO);
+ if (f.exists()) {
+ f.delete();
+ }
+ super.tearDown();
+ }
+
+ private void assertIsPropertySet(boolean set) {
+ assertEquals(set, Boolean.TRUE.toString().equalsIgnoreCase(System.getProperty(SimpleConfiguratorImpl.PROP_IGNORE_USER_CONFIGURATION)));
+ }
+
+ public void testSimpleConfiguration() throws MalformedURLException {
+ assertEquals(localConfiguration[0], configurator.chooseConfigurationURL(relativeURL, localConfiguration));
+ assertIsPropertySet(false);
+ }
+
+ public void testNotExistingConfigiration() throws MalformedURLException {
+ assertNull(configurator.chooseConfigurationURL(relativeURL, new URL[] {new File(".", "notexisting").toURL()}));
+ assertIsPropertySet(false);
+ }
+
+ public void testSharedConfigurationUserNotExisting() throws MalformedURLException {
+ sharedConfiguration[0] = new File(".", "notexisting").toURL();
+ assertEquals(sharedConfiguration[1], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration));
+ assertIsPropertySet(false);
+ }
+
+ // no timestamp -> pick user
+ public void testSharedConfigurationNoTimestamp() throws MalformedURLException {
+ assertEquals(sharedConfiguration[0], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration));
+ assertIsPropertySet(false);
+ }
+
+ //master modified -> pick master
+ public void testSharedConfigurationMasterModified() throws IOException {
+ storeTimestamp(1000);
+ assertEquals(sharedConfiguration[1], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration));
+ assertIsPropertySet(true);
+ }
+
+ //master not modified -> pick user
+ public void testSharedConfigurationMasterUnmodified() throws IOException {
+ storeTimestamp(new File(masterConfguration, relativeURL.getFile()).lastModified());
+ assertEquals(sharedConfiguration[0], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration));
+ assertIsPropertySet(false);
+ }
+
+ //master not modified, but property present -> pick master
+ public void testSharedConfigurationMasterUnmodifiedPropertySet() throws IOException {
+ System.setProperty(SimpleConfiguratorImpl.PROP_IGNORE_USER_CONFIGURATION, "true");
+ storeTimestamp(new File(masterConfguration, relativeURL.getFile()).lastModified());
+ assertEquals(sharedConfiguration[1], configurator.chooseConfigurationURL(relativeURL, sharedConfiguration));
+ assertIsPropertySet(true);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java
index a3b448f..454f30d 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java
@@ -16,6 +16,7 @@ public class SimpleConfiguratorTests {
public static Test suite() {
TestSuite suite = new TestSuite("Tests for org.eclipse.equinox.simpleconfigurator");
//$JUnit-BEGIN$
+ suite.addTestSuite(SimpleConfiguratorTest.class);
suite.addTestSuite(SimpleConfiguratorUtilsTest.class);
suite.addTestSuite(BundlesTxtTest.class);
suite.addTestSuite(NonExclusiveMode.class);
diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/simpleconfigurator/master/bundles.info b/bundles/org.eclipse.equinox.p2.tests/testData/simpleconfigurator/master/bundles.info
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/testData/simpleconfigurator/master/bundles.info
diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/simpleconfigurator/user/bundles.info b/bundles/org.eclipse.equinox.p2.tests/testData/simpleconfigurator/user/bundles.info
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/testData/simpleconfigurator/user/bundles.info
diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java
index d7b2c4b..70d3b4c 100644
--- a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java
+++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java
@@ -47,7 +47,7 @@ public class SimpleConfiguratorImpl implements Configurator {
private static final long NO_TIMESTAMP = -1;
public static final String BASE_TIMESTAMP_FILE_BUNDLESINFO = ".baseBundlesInfoTimestamp"; //$NON-NLS-1$
public static final String KEY_BUNDLESINFO_TIMESTAMP = "bundlesInfoTimestamp";
- private static final String PROP_IGNORE_USER_CONFIGURATION = "eclipse.ignoreUserConfiguration"; //$NON-NLS-1$
+ public static final String PROP_IGNORE_USER_CONFIGURATION = "eclipse.ignoreUserConfiguration"; //$NON-NLS-1$
public SimpleConfiguratorImpl(BundleContext context, Bundle bundle) {
this.context = context;
@@ -87,30 +87,10 @@ public class SimpleConfiguratorImpl implements Configurator {
//if it is an relative file URL, then resolve it against the configuration area
// TODO Support relative file URLs when not on Equinox
URL[] configURL = EquinoxUtils.getConfigAreaURL(context);
- if (configURL != null) {
- File userConfig = new File(configURL[0].getFile(), url.getFile());
- if (configURL.length == 1)
- return userConfig.exists() ? userConfig.toURL() : null;
- File sharedConfig = new File(configURL[1].getFile(), url.getFile());
- if (!userConfig.exists())
- return sharedConfig.exists() ? sharedConfig.toURL() : null;
-
- if (!sharedConfig.exists())
- return userConfig.toURL();
-
- if (Boolean.TRUE.toString().equals(System.getProperty(PROP_IGNORE_USER_CONFIGURATION)))
- return sharedConfig.toURL();
-
- long sharedBundlesInfoTimestamp = getCurrentBundlesInfoBaseTimestamp(sharedConfig);
- long lastKnownBaseTimestamp = getLastKnownBundlesInfoBaseTimestamp(userConfig.getParentFile());
-
- if (lastKnownBaseTimestamp == sharedBundlesInfoTimestamp || lastKnownBaseTimestamp == NO_TIMESTAMP) {
- return userConfig.toURL();
- } else {
- System.setProperty(PROP_IGNORE_USER_CONFIGURATION, Boolean.TRUE.toString());
- return sharedConfig.toURL();
- }
+ URL result = chooseConfigurationURL(url, configURL);
+ if (result != null) {
+ return result;
}
} catch (MalformedURLException e) {
return null;
@@ -126,6 +106,40 @@ public class SimpleConfiguratorImpl implements Configurator {
return null;
}
+ /**
+ * This method is public for testing purposes only.
+ * @param relativeURL - a relative URL of the configuration
+ * @param configURL - an array of parent config URLs to which relativeURL can be appended.
+ */
+ public URL chooseConfigurationURL(URL relativeURL, URL[] configURL) throws MalformedURLException {
+ if (configURL != null) {
+ File userConfig = new File(configURL[0].getFile(), relativeURL.getFile());
+ if (configURL.length == 1)
+ return userConfig.exists() ? userConfig.toURL() : null;
+
+ File sharedConfig = new File(configURL[1].getFile(), relativeURL.getFile());
+ if (!userConfig.exists())
+ return sharedConfig.exists() ? sharedConfig.toURL() : null;
+
+ if (!sharedConfig.exists())
+ return userConfig.toURL();
+
+ if (Boolean.TRUE.toString().equals(System.getProperty(PROP_IGNORE_USER_CONFIGURATION)))
+ return sharedConfig.toURL();
+
+ long sharedBundlesInfoTimestamp = getCurrentBundlesInfoBaseTimestamp(sharedConfig);
+ long lastKnownBaseTimestamp = getLastKnownBundlesInfoBaseTimestamp(userConfig.getParentFile());
+
+ if (lastKnownBaseTimestamp == sharedBundlesInfoTimestamp || lastKnownBaseTimestamp == NO_TIMESTAMP) {
+ return userConfig.toURL();
+ } else {
+ System.setProperty(PROP_IGNORE_USER_CONFIGURATION, Boolean.TRUE.toString());
+ return sharedConfig.toURL();
+ }
+ }
+ return null;
+ }
+
private long getLastKnownBundlesInfoBaseTimestamp(File configFolder) {
File storedSharedTimestamp = new File(configFolder, BASE_TIMESTAMP_FILE_BUNDLESINFO);
if (!storedSharedTimestamp.exists())