summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-08-14 10:55:59 +0000
committerclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-08-14 10:55:59 +0000
commita8e021a5b4450e117b76d9f6cc69bd24cd1dd5d3 (patch)
treec3913b3a4c59b027dc0fe2f7712ad2a6c0533eac
parenta59e78782149933c37e21486c292f2c1a7fc9c2c (diff)
downloadmocca-a8e021a5b4450e117b76d9f6cc69bd24cd1dd5d3.tar.gz
mocca-a8e021a5b4450e117b76d9f6cc69bd24cd1dd5d3.tar.bz2
mocca-a8e021a5b4450e117b76d9f6cc69bd24cd1dd5d3.zip
fixed updateRequired function
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@434 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
-rw-r--r--BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Configurator.java159
-rw-r--r--BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java4
-rw-r--r--BKUWebStart/src/main/resources/at/gv/egiz/bku/webstart/conf/conf.zipbin2944 -> 3005 bytes
-rw-r--r--BKUWebStart/src/main/resources/log4j.properties2
-rw-r--r--BKUWebStart/src/test/java/at/gv/egiz/bku/webstart/ConfiguratorTest.java175
-rw-r--r--BKUWebStart/src/test/resources/commons-logging.properties1
-rw-r--r--BKUWebStart/src/test/resources/log4j.properties35
7 files changed, 320 insertions, 56 deletions
diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Configurator.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Configurator.java
index ab1746ed..f1349637 100644
--- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Configurator.java
+++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Configurator.java
@@ -79,7 +79,7 @@ public class Configurator {
public static final String PASSWD_FILE = ".secret";
private static final Log log = LogFactory.getLog(Configurator.class);
-
+
/** currently installed configuration version */
private String version;
private String certsVersion;
@@ -104,7 +104,7 @@ public class Configurator {
if (log.isDebugEnabled()) {
log.debug("config directory " + configDir + ", version " + version);
}
- if (updateRequired(version)) {
+ if (updateRequired(version, MIN_CONFIG_VERSION)) {
File moccaDir = configDir.getParentFile();
File zipFile = new File(moccaDir, "conf-" + version + ".zip");
ZipOutputStream zipOS = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
@@ -135,7 +135,7 @@ public class Configurator {
log.debug("certificate-store directory " + certsDir + ", version " + certsVersion);
}
String newCertsVersion = getCertificatesVersion();
- if (updateRequiredStrict(certsVersion, newCertsVersion)) {
+ if (updateRequired(certsVersion, newCertsVersion)) {
File moccaDir = certsDir.getParentFile();
File zipFile = new File(moccaDir, "certs-" + certsVersion + ".zip");
ZipOutputStream zipOS = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
@@ -174,7 +174,7 @@ public class Configurator {
String version;
while ((version = versionReader.readLine().trim()) != null) {
if (version.length() > 0 && !version.startsWith("#")) {
- log.debug("configuration version from " + versionFile + ": " + version);
+ log.trace("configuration version from " + versionFile + ": " + version);
return version;
}
}
@@ -221,70 +221,119 @@ public class Configurator {
return certsResourceVersion;
}
- protected static boolean updateRequired(String oldVersion) {
- log.debug("comparing " + oldVersion + " to " + MIN_CONFIG_VERSION);
- if (oldVersion != null && !UNKOWN_VERSION.equals(oldVersion)) {
-
- int majorEnd = oldVersion.indexOf('-');
- String oldMajor = (majorEnd < 0) ? oldVersion : oldVersion.substring(0, majorEnd);
-
- String minMajor = MIN_CONFIG_VERSION;
- boolean releaseRequired = true;
- if (MIN_CONFIG_VERSION.endsWith("-SNAPSHOT")) {
- releaseRequired = false;
- minMajor = minMajor.substring(0, minMajor.length() - 9);
- }
-
- int compare = oldMajor.compareTo(minMajor);
- if (compare < 0 ||
- // SNAPSHOT versions are pre-releases (update if release required)
- (compare == 0 && releaseRequired && oldVersion.startsWith("-SNAPSHOT", majorEnd))) {
- log.debug("configuration update required");
- return true;
- } else {
- log.debug("configuration up to date");
- return false;
- }
- }
- log.debug("no old version, configuration update required");
- return true;
- }
-
/**
* if unknown old, update in any case
- * if known old and unknown new, don't update
+ * if known old and unknown min, don't update
* @param oldVersion
- * @param newVersion
+ * @param minVersion
* @return
*/
- private boolean updateRequiredStrict(String oldVersion, String newVersion) {
- log.debug("comparing " + oldVersion + " to " + newVersion);
+ protected static boolean updateRequired(String oldVersion, String minVersion) {
+ log.debug("comparing " + oldVersion + " to " + minVersion);
if (oldVersion != null && !UNKOWN_VERSION.equals(oldVersion)) {
- if (newVersion != null && !UNKOWN_VERSION.equals(newVersion)) {
- String[] oldV = oldVersion.split("-");
- String[] newV = newVersion.split("-");
- log.trace("comparing " + oldV[0] + " to " + newV[0]);
- if (oldV[0].compareTo(newV[0]) < 0) {
- log.debug("update required");
- return true;
- } else {
- log.trace("comparing " + oldV[oldV.length - 1] + " to " + newV[newV.length - 1]);
- if (oldV[oldV.length - 1].compareTo(newV[newV.length - 1]) < 0) {
+ if (minVersion != null && !UNKOWN_VERSION.equals(minVersion)) {
+ int fromInd = 0;
+ int nextIndOld, nextIndMin;
+ int xOld, xMin;
+
+ // assume dots '.' appear in major version only (not after "-SNAPSHOT")
+ while ((nextIndOld = oldVersion.indexOf('.', fromInd)) > 0) {
+ nextIndMin = minVersion.indexOf('.', fromInd);
+ if (nextIndMin < 0) {
+ log.debug("installed version newer than minimum required (newer minor version)");
+ }
+ xOld = Integer.valueOf(oldVersion.substring(fromInd, nextIndOld));
+ xMin = Integer.valueOf(minVersion.substring(fromInd, nextIndMin));
+ if (xMin > xOld) {
log.debug("update required");
return true;
- } else {
- log.debug("no update required");
+ } else if (xMin < xOld) {
+ log.debug("installed version newer than minimum required");
return false;
}
+ fromInd = nextIndOld + 1;
+ }
+
+ // compare last digit of major
+ boolean preRelease = true;
+ int majorEndOld = oldVersion.indexOf("-SNAPSHOT");
+ if (majorEndOld < 0) {
+ preRelease = false;
+ majorEndOld = oldVersion.length();
+ }
+
+ boolean releaseRequired = false;
+ int majorEndMin = minVersion.indexOf("-SNAPSHOT");
+ if (majorEndMin < 0) {
+ releaseRequired = true;
+ majorEndMin = minVersion.length();
+ }
+
+ xOld = Integer.valueOf(oldVersion.substring(fromInd, majorEndOld));
+ boolean hasMoreDigitsMin = true;
+ nextIndMin = minVersion.indexOf('.', fromInd);
+ if (nextIndMin < 0) {
+ hasMoreDigitsMin = false;
+ nextIndMin = majorEndMin;
+ }
+ xMin = Integer.valueOf(minVersion.substring(fromInd, nextIndMin));
+ if (xMin > xOld) {
+ log.debug("update required");
+ return true;
+ } else if (xMin < xOld) {
+ log.debug("installed version newer than minimum required");
+ return false;
+ } else if (hasMoreDigitsMin) { // xMin == xOld
+ log.debug("update required (newer minor version required)");
+ return true;
+ } else if (preRelease && releaseRequired) {
+ log.debug("pre-release installed but release required");
+ return true;
+ } else {
+ log.debug("exact match, no updated required");
+ return false;
}
}
- log.debug("unknown new version, do not update");
- return true;
+ log.debug("unknown minimum version, do not update");
+ return false;
}
- log.debug("unknown old version, update required");
+ log.debug("no old version, update required");
return true;
}
-
+
+ /**
+
+ * @param oldVersion
+ * @param newVersion
+ * @return
+ */
+// private boolean updateRequiredStrict(String oldVersion, String newVersion) {
+// log.debug("comparing " + oldVersion + " to " + newVersion);
+// if (oldVersion != null && !UNKOWN_VERSION.equals(oldVersion)) {
+// if (newVersion != null && !UNKOWN_VERSION.equals(newVersion)) {
+// String[] oldV = oldVersion.split("-");
+// String[] newV = newVersion.split("-");
+// log.trace("comparing " + oldV[0] + " to " + newV[0]);
+// if (oldV[0].compareTo(newV[0]) < 0) {
+// log.debug("update required");
+// return true;
+// } else {
+// log.trace("comparing " + oldV[oldV.length - 1] + " to " + newV[newV.length - 1]);
+// if (oldV[oldV.length - 1].compareTo(newV[newV.length - 1]) < 0) {
+// log.debug("update required");
+// return true;
+// } else {
+// log.debug("no update required");
+// return false;
+// }
+// }
+// }
+// log.debug("unknown new version, do not update");
+// return true;
+// }
+// log.debug("unknown old version, update required");
+// return true;
+// }
protected static void backupAndDelete(File dir, URI relativeTo, ZipOutputStream zip) throws IOException {
if (dir.isDirectory()) {
File[] subDirs = dir.listFiles();
@@ -320,7 +369,7 @@ public class Configurator {
private static void createConfig(File configDir, String version) throws IOException {
if (log.isDebugEnabled()) {
- log.debug("creating configuration version " + Launcher.version + " in " + configDir );
+ log.debug("creating configuration version " + Launcher.version + " in " + configDir);
}
configDir.mkdirs();
File confTemplateFile = new File(configDir, CONF_TEMPLATE_FILE);
@@ -347,7 +396,7 @@ public class Configurator {
if (certsURL != null) {
StringBuilder url = new StringBuilder(certsURL.toExternalForm());
url = url.replace(url.length() - CERTIFICATES_PKG.length(), url.length(), "META-INF/MANIFEST.MF");
- log.debug("retrieve certificate resource names from " + url);
+ log.trace("retrieve certificate resource names from " + url);
certsURL = new URL(url.toString());
Manifest certsManifest = new Manifest(certsURL.openStream());
certsDir.mkdirs();
diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java
index 4df90ab2..a2947833 100644
--- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java
+++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java
@@ -177,7 +177,11 @@ public class Container {
perms.add(new FilePermission(new File(System.getProperty("user.home")).getAbsolutePath(), "read, write"));
perms.add(new FilePermission(new File(System.getProperty("user.home") + "/-").getAbsolutePath(), "read, write"));
perms.add(new FilePermission(new File(System.getProperty("user.home") + "/.mocca/logs/*").getAbsolutePath(), "read, write,delete"));
+ perms.add(new FilePermission(new File(System.getProperty("user.home") + "/.mocca/certs/-").getAbsolutePath(), "read, write,delete"));
+ //TODO
+ log.trace("granting file read/write permission to MOCCA local");
+ perms.add(new FilePermission("<<ALL_FILES>>", "read, write"));
return perms;
}
diff --git a/BKUWebStart/src/main/resources/at/gv/egiz/bku/webstart/conf/conf.zip b/BKUWebStart/src/main/resources/at/gv/egiz/bku/webstart/conf/conf.zip
index 1df56e5c..7ed90b7b 100644
--- a/BKUWebStart/src/main/resources/at/gv/egiz/bku/webstart/conf/conf.zip
+++ b/BKUWebStart/src/main/resources/at/gv/egiz/bku/webstart/conf/conf.zip
Binary files differ
diff --git a/BKUWebStart/src/main/resources/log4j.properties b/BKUWebStart/src/main/resources/log4j.properties
index 76de3576..76562ccf 100644
--- a/BKUWebStart/src/main/resources/log4j.properties
+++ b/BKUWebStart/src/main/resources/log4j.properties
@@ -18,7 +18,7 @@ log4j.rootLogger=DEBUG, file
log4j.logger.org.mortbay.log=INFO
log4j.logger.pki=INFO
-log4j.additivity.pki=false
+#log4j.additivity.pki=false
# STDOUT appender
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
diff --git a/BKUWebStart/src/test/java/at/gv/egiz/bku/webstart/ConfiguratorTest.java b/BKUWebStart/src/test/java/at/gv/egiz/bku/webstart/ConfiguratorTest.java
new file mode 100644
index 00000000..0c08a276
--- /dev/null
+++ b/BKUWebStart/src/test/java/at/gv/egiz/bku/webstart/ConfiguratorTest.java
@@ -0,0 +1,175 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package at.gv.egiz.bku.webstart;
+
+import java.io.File;
+import java.net.URI;
+import java.util.zip.ZipOutputStream;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author clemens
+ */
+public class ConfiguratorTest {
+
+
+ public ConfiguratorTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of ensureConfiguration method, of class Configurator.
+ */
+ @Ignore
+ @Test
+ public void testEnsureConfiguration() throws Exception {
+ System.out.println("ensureConfiguration");
+ Configurator instance = new Configurator();
+ instance.ensureConfiguration();
+ // TODO review the generated test code and remove the default call to fail.
+ fail("The test case is a prototype.");
+ }
+
+ /**
+ * Test of ensureCertificates method, of class Configurator.
+ */
+ @Ignore
+ @Test
+ public void testEnsureCertificates() throws Exception {
+ System.out.println("ensureCertificates");
+ Configurator instance = new Configurator();
+ instance.ensureCertificates();
+ // TODO review the generated test code and remove the default call to fail.
+ fail("The test case is a prototype.");
+ }
+
+ /**
+ * Test of isCertRenewed method, of class Configurator.
+ */
+ @Ignore
+ @Test
+ public void testIsCertRenewed() {
+ System.out.println("isCertRenewed");
+ Configurator instance = new Configurator();
+ boolean expResult = false;
+ boolean result = instance.isCertRenewed();
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ fail("The test case is a prototype.");
+ }
+
+ /**
+ * Test of readVersion method, of class Configurator.
+ */
+ @Ignore
+ @Test
+ public void testReadVersion() {
+ System.out.println("readVersion");
+ File versionFile = null;
+ String expResult = "";
+ String result = Configurator.readVersion(versionFile);
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ fail("The test case is a prototype.");
+ }
+
+ /**
+ * Test of updateRequired method, of class Configurator.
+ */
+ @Test
+ public void testUpdateRequired() {
+ System.out.println("updateRequired");
+ String oldVersion = "1.0.9-SNAPSHOT-r123";
+ String minVersion = "1.0.9-SNAPSHOT";
+ boolean expResult = false;
+ boolean result = Configurator.updateRequired(oldVersion, minVersion);
+ assertEquals(expResult, result);
+
+ oldVersion = "1.0.9-SNAPSHOT-r123";
+ minVersion = "1.0.9";
+ expResult = true;
+ result = Configurator.updateRequired(oldVersion, minVersion);
+ assertEquals(expResult, result);
+
+ oldVersion = "1.0.9-SNAPSHOT-r123";
+ minVersion = "1.0.10-SNAPSHOT";
+ expResult = true;
+ result = Configurator.updateRequired(oldVersion, minVersion);
+ assertEquals(expResult, result);
+
+ oldVersion = "1.0.9";
+ minVersion = "1.0.9.1-SNAPSHOT";
+ expResult = true;
+ result = Configurator.updateRequired(oldVersion, minVersion);
+ assertEquals(expResult, result);
+
+ oldVersion = "1.0.9";
+ minVersion = "1.0.8.99-SNAPSHOT";
+ expResult = false;
+ result = Configurator.updateRequired(oldVersion, minVersion);
+ assertEquals(expResult, result);
+
+ oldVersion = "1";
+ minVersion = "2";
+ expResult = true;
+ result = Configurator.updateRequired(oldVersion, minVersion);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of backupAndDelete method, of class Configurator.
+ */
+ @Ignore
+ @Test
+ public void testBackupAndDelete() throws Exception {
+ System.out.println("backupAndDelete");
+ File dir = null;
+ URI relativeTo = null;
+ ZipOutputStream zip = null;
+ Configurator.backupAndDelete(dir, relativeTo, zip);
+ // TODO review the generated test code and remove the default call to fail.
+ fail("The test case is a prototype.");
+ }
+
+ /**
+ * Test of initConfig method, of class Configurator.
+ */
+ @Ignore
+ @Test
+ public void testInitConfig() throws Exception {
+ System.out.println("initConfig");
+ File configDir = null;
+ Configurator instance = new Configurator();
+ instance.initConfig(configDir);
+ // TODO review the generated test code and remove the default call to fail.
+ fail("The test case is a prototype.");
+ }
+
+} \ No newline at end of file
diff --git a/BKUWebStart/src/test/resources/commons-logging.properties b/BKUWebStart/src/test/resources/commons-logging.properties
new file mode 100644
index 00000000..29292562
--- /dev/null
+++ b/BKUWebStart/src/test/resources/commons-logging.properties
@@ -0,0 +1 @@
+org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
diff --git a/BKUWebStart/src/test/resources/log4j.properties b/BKUWebStart/src/test/resources/log4j.properties
new file mode 100644
index 00000000..ea08c51d
--- /dev/null
+++ b/BKUWebStart/src/test/resources/log4j.properties
@@ -0,0 +1,35 @@
+# Copyright 2008 Federal Chancellery Austria and
+# Graz University of Technology
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# loglever DEBUG, appender STDOUT
+log4j.rootLogger=TRACE, STDOUT
+log4j.logger.org.mortbay.log=INFO
+log4j.logger.pki=INFO
+
+#log4j.additivity.pki=false
+
+# STDOUT appender
+log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
+log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
+#log4j.appender.STDOUT.layout.ConversionPattern=%5p | %d{dd HH:mm:ss,SSS} | %20c | %10t | %m%n
+#log4j.appender.STDOUT.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
+log4j.appender.STDOUT.layout.ConversionPattern=%-5p |%d | %t | %c %x- %m%n
+
+### FILE appender
+log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.file.datePattern='.'yyyy-MM-dd
+log4j.appender.file.File=${user.home}/.mocca/logs/webstart.log
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %-5p %c{1}:%L - %m%n \ No newline at end of file