Skip to content

The Unified and Autonomous Development Platform

Fix some minor upgrade issues

Robin Shen0d97831f0471
diff --git a/commons.bootstrap/src/main/java/com/pmease/commons/bootstrap/Bootstrap.java b/commons.bootstrap/src/main/java/com/pmease/commons/bootstrap/Bootstrap.java
index b855e76cdd..6b0ea2bf1b 100644
--- a/commons.bootstrap/src/main/java/com/pmease/commons/bootstrap/Bootstrap.java
+++ b/commons.bootstrap/src/main/java/com/pmease/commons/bootstrap/Bootstrap.java
@@ -126,11 +126,6 @@ public class Bootstrap {
try {
if (command == null) {
- getStatusDir().mkdirs();
- if (!getStatusDir().exists()) {
- throw new RuntimeException("Unable to create directory: " + getStatusDir().getAbsolutePath());
- }
-
if (!sandboxMode) {
File serverRunningFile = getServerRunningFile();
if (serverRunningFile.exists())
diff --git a/commons.hibernate/src/main/java/com/pmease/commons/hibernate/command/DefaultUpgradeCommand.java b/commons.hibernate/src/main/java/com/pmease/commons/hibernate/command/DefaultUpgradeCommand.java
index b34d260e52..5f928b4379 100644
--- a/commons.hibernate/src/main/java/com/pmease/commons/hibernate/command/DefaultUpgradeCommand.java
+++ b/commons.hibernate/src/main/java/com/pmease/commons/hibernate/command/DefaultUpgradeCommand.java
@@ -165,6 +165,7 @@ public class DefaultUpgradeCommand extends DefaultPersistManager {
} catch (IOException e) {
throw new RuntimeException(e);
}
+ restoreExecutables(upgradeBackup);
if (!MigrationHelper.getVersion(migrator.getClass()).equals(oldDataVersion.get())) {
dbBackup = new File(upgradeDir, getBackupName("dbbackup") + ".zip");
@@ -186,6 +187,7 @@ public class DefaultUpgradeCommand extends DefaultPersistManager {
} catch (IOException e) {
throw new RuntimeException(e);
}
+ restoreExecutables(upgradeBackup);
}
boolean failed;
@@ -267,6 +269,7 @@ public class DefaultUpgradeCommand extends DefaultPersistManager {
FileUtils.deleteFile(child);
}
FileUtils.copyDirectory(upgradeBackup, upgradeDir);
+ restoreExecutables(upgradeDir);
logger.info("Old installation directory is now restored.");
} catch (Exception e2) {
logger.error("Error restoring old installation directory", e2);
@@ -317,8 +320,18 @@ public class DefaultUpgradeCommand extends DefaultPersistManager {
}
protected void copyProgramFilesTo(File upgradeDir) {
+ String result;
+ try {
+ String from = FileUtils.readFileToString(new File(upgradeDir, "bin/server.sh"));
+ String to = FileUtils.readFileToString(new File(Bootstrap.getBinDir(), "server.sh"));
+ result = UpgradeUtils.copyRunAs(from, to);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
cleanAndCopy(new File(Bootstrap.installDir, "3rdparty-licenses"), new File(upgradeDir, "3rdparty-licenses"));
cleanAndCopy(Bootstrap.getBinDir(), new File(upgradeDir, "bin"));
+ FileUtils.writeFile(new File(upgradeDir, "bin/server.sh"), result);
cleanAndCopy(Bootstrap.getBootDir(), new File(upgradeDir, "boot"));
cleanAndCopy(Bootstrap.getLibDir(), new File(upgradeDir, "lib"));
for (File file: Bootstrap.getSiteLibDir().listFiles()) {
@@ -337,19 +350,23 @@ public class DefaultUpgradeCommand extends DefaultPersistManager {
} catch (IOException e) {
throw new RuntimeException(e);
}
+ restoreExecutables(upgradeDir);
}
protected void cleanAndCopy(File srcDir, File destDir) {
try {
FileUtils.cleanDir(destDir);
FileUtils.copyDirectory(srcDir, destDir);
- for (File file: destDir.listFiles()) {
- if (file.getName().endsWith(".sh"))
- file.setExecutable(true);
- }
} catch (IOException e) {
throw new RuntimeException(e);
}
}
+ private void restoreExecutables(File installDir) {
+ for (File file: new File(installDir, "bin").listFiles()) {
+ if (file.getName().endsWith(".sh"))
+ file.setExecutable(true);
+ }
+ }
+
}
diff --git a/commons.hibernate/src/main/java/com/pmease/commons/hibernate/command/UpgradeUtils.java b/commons.hibernate/src/main/java/com/pmease/commons/hibernate/command/UpgradeUtils.java
new file mode 100644
index 0000000000..63d67b0fc5
--- /dev/null
+++ b/commons.hibernate/src/main/java/com/pmease/commons/hibernate/command/UpgradeUtils.java
@@ -0,0 +1,19 @@
+package com.pmease.commons.hibernate.command;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class UpgradeUtils {
+
+ public static String copyRunAs(String from, String to) {
+ Matcher matcher = Pattern.compile("(?m)^(#|\\s)*RUN_AS_USER\\s*=.*$").matcher(from);
+ if (matcher.find()) {
+ String runAs = matcher.group();
+ to = StringUtils.replace(to, "#RUN_AS_USER=", runAs);
+ }
+ return to;
+ }
+
+}
diff --git a/commons.hibernate/src/test/java/com/pmease/commons/hibernate/command/UpgradeUtilsTest.java b/commons.hibernate/src/test/java/com/pmease/commons/hibernate/command/UpgradeUtilsTest.java
new file mode 100644
index 0000000000..c97add4c65
--- /dev/null
+++ b/commons.hibernate/src/test/java/com/pmease/commons/hibernate/command/UpgradeUtilsTest.java
@@ -0,0 +1,68 @@
+package com.pmease.commons.hibernate.command;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class UpgradeUtilsTest {
+
+ @Test
+ public void test() {
+ String from = ""
+ + "# specify RUN_AS_USER here\n"
+ + "RUN_AS_USER = robin \n"
+ + "some String here RUN_AS_USER=\"\"\n";
+ String to = ""
+ + "# specify RUN_AS_USER here\n"
+ + "#RUN_AS_USER=\n"
+ + "some String here RUN_AS_USER=\"\"\n";
+ String expected = ""
+ + "# specify RUN_AS_USER here\n"
+ + "RUN_AS_USER = robin \n"
+ + "some String here RUN_AS_USER=\"\"\n";
+ assertEquals(expected, UpgradeUtils.copyRunAs(from, to));
+
+ from = ""
+ + "# specify RUN_AS_USER here\r\n"
+ + "#RUN_AS_USER = robin \r\n"
+ + "some String here RUN_AS_USER=\"\"\r\n";
+ to = ""
+ + "# specify RUN_AS_USER here\r\n"
+ + "#RUN_AS_USER=\r\n"
+ + "some String here RUN_AS_USER=\"\"\r\n";
+ expected = ""
+ + "# specify RUN_AS_USER here\r\n"
+ + "#RUN_AS_USER = robin \r\n"
+ + "some String here RUN_AS_USER=\"\"\r\n";
+ assertEquals(expected, UpgradeUtils.copyRunAs(from, to));
+
+ from = ""
+ + "# specify RUN_AS_USER here\n"
+ + "#RUN_AS_USER=\n"
+ + "some String here RUN_AS_USER=\"\"\n";
+ to = ""
+ + "# specify RUN_AS_USER here\n"
+ + "#RUN_AS_USER=\n"
+ + "some String here RUN_AS_USER=\"\"\n";
+ expected = ""
+ + "# specify RUN_AS_USER here\n"
+ + "#RUN_AS_USER=\n"
+ + "some String here RUN_AS_USER=\"\"\n";
+ assertEquals(expected, UpgradeUtils.copyRunAs(from, to));
+
+ from = ""
+ + "# specify RUN_AS_USER here\n"
+ + "## RUN_AS_USER = robinshen \n"
+ + "some String here RUN_AS_USER=\"\"\n";
+ to = ""
+ + "# specify RUN_AS_USER here\n"
+ + "#RUN_AS_USER=\n"
+ + "some String here RUN_AS_USER=\"\"\n";
+ expected = ""
+ + "# specify RUN_AS_USER here\n"
+ + "## RUN_AS_USER = robinshen \n"
+ + "some String here RUN_AS_USER=\"\"\n";
+ assertEquals(expected, UpgradeUtils.copyRunAs(from, to));
+ }
+
+}
diff --git a/commons.jsw/wrapper/customization/sh.script.in b/commons.jsw/wrapper/customization/sh.script.in
index e46f5f2bce..90e565a125 100644
--- a/commons.jsw/wrapper/customization/sh.script.in
+++ b/commons.jsw/wrapper/customization/sh.script.in
@@ -267,9 +267,6 @@ if [ "$FIRST_CHAR" != "/" ]
then
PIDDIR=$REALDIR/$PIDDIR
fi
-if [ ! -d "$PIDDIR" ]; then
- mkdir $PIDDIR
-fi
# Same test for WRAPPER_CMD
FIRST_CHAR=`echo $WRAPPER_CMD | cut -c1,1`
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/migration/DatabaseMigrator.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/migration/DatabaseMigrator.java
index 160a068444..89e1987f10 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/migration/DatabaseMigrator.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/migration/DatabaseMigrator.java
@@ -28,4 +28,18 @@ public class DatabaseMigrator implements Migrator {
}
}
+ private void migrate2(File dataDir, Stack<Integer> versions) {
+ for (File file: dataDir.listFiles()) {
+ if (file.getName().startsWith("Depots.xml")) {
+ VersionedDocument dom = VersionedDocument.fromFile(file);
+ for (Element element: dom.getRootElement().elements()) {
+ Element gateKeeperElement = element.element("gateKeeper");
+ gateKeeperElement.detach();
+ element.addElement("gateKeepers");
+ }
+ dom.writeToFile(file, false);
+ }
+ }
+ }
+
}
diff --git a/gitplex.product/pom.xml b/gitplex.product/pom.xml
index 491a2143c4..327c1c6766 100644
--- a/gitplex.product/pom.xml
+++ b/gitplex.product/pom.xml
@@ -161,5 +161,5 @@
<moduleClass>com.pmease.gitplex.product.ProductModule</moduleClass>
<aggregation>true</aggregation>
</properties>
- <version>1.0-beta1-build2</version>
+ <version>1.0-EAP-build1</version>
</project>
diff --git a/gitplex.product/system/status/do_not_remove.txt b/gitplex.product/system/status/do_not_remove.txt
new file mode 100644
index 0000000000..e69de29bb2