Author: massi
Date: Fri Jul  4 13:01:31 2014
New Revision: 1607847

URL: http://svn.apache.org/r1607847
Log:
Some changes for windows env #SYNCOPE-526

Modified:
    
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/containers/Tomcat.java
    
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/AbstractProcess.java
    
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/ArchetypeProcess.java
    
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/ContainerProcess.java
    
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/PersistenceProcess.java
    
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/utilities/Commands.java
    
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/validators/ArchetypeValidator.java
    syncope/trunk/installer/src/main/resources/izpack/install.xml
    syncope/trunk/installer/src/main/resources/izpack/userInputSpec.xml

Modified: 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/containers/Tomcat.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/java/org/apache/syncope/installer/containers/Tomcat.java?rev=1607847&r1=1607846&r2=1607847&view=diff
==============================================================================
--- 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/containers/Tomcat.java
 (original)
+++ 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/containers/Tomcat.java
 Fri Jul  4 13:01:31 2014
@@ -20,6 +20,7 @@ package org.apache.syncope.installer.con
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
+import org.apache.syncope.installer.utilities.Commands;
 import org.apache.syncope.installer.utilities.HttpUtils;
 
 public class Tomcat {
@@ -42,19 +43,16 @@ public class Tomcat {
 
     private final HttpUtils httpUtils;
 
-    private final boolean isWin;
-
     public Tomcat(final boolean tomcatSsl, final String tomcatHost, final 
String tomcatPort,
             final String installPath, final String artifactId, final String 
tomcatUser, final String tomcatPassword) {
         this.installPath = installPath;
         this.artifactId = artifactId;
-        isWin = System.getProperty("os.name").toLowerCase().contains("win");
         httpUtils = new HttpUtils(tomcatSsl, tomcatHost, tomcatPort, 
tomcatUser, tomcatPassword);
     }
 
     public boolean deployCore() {
         int status;
-        if (isWin) {
+        if (Commands.IS_WIN) {
             status = 
httpUtils.getWithBasicAuth(pathEncoded(WIN_DEPLOY_SYNCOPE_CORE_QUERY));
         } else {
             status = 
httpUtils.getWithBasicAuth(path(UNIX_DEPLOY_SYNCOPE_CORE_QUERY));
@@ -65,7 +63,7 @@ public class Tomcat {
 
     public boolean deployConsole() {
         int status;
-        if (isWin) {
+        if (Commands.IS_WIN) {
             status = 
httpUtils.getWithBasicAuth(pathEncoded(WIN_DEPLOY_SYNCOPE_CONSOLE_QUERY));
         } else {
             status = 
httpUtils.getWithBasicAuth(path(UNIX_DEPLOY_SYNCOPE_CONSOLE_QUERY));

Modified: 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/AbstractProcess.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/AbstractProcess.java?rev=1607847&r1=1607846&r2=1607847&view=diff
==============================================================================
--- 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/AbstractProcess.java
 (original)
+++ 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/AbstractProcess.java
 Fri Jul  4 13:01:31 2014
@@ -31,12 +31,11 @@ public abstract class AbstractProcess {
 
     protected void exec(final String cmd, final AbstractUIProcessHandler 
handler, final String path) {
         try {
-            final Process process;
-            if (path == null || path.isEmpty()) {
-                process = Runtime.getRuntime().exec(cmd);
-            } else {
-                process = Runtime.getRuntime().exec(cmd, null, new File(path));
+            final ProcessBuilder builder = new ProcessBuilder(cmd.split(" "));
+            if (path != null && !path.isEmpty()) {
+                builder.directory(new File(path));
             }
+            final Process process = builder.start();
             readResponse(process.getInputStream(), handler);
         } catch (IOException ex) {
         }

Modified: 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/ArchetypeProcess.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/ArchetypeProcess.java?rev=1607847&r1=1607846&r2=1607847&view=diff
==============================================================================
--- 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/ArchetypeProcess.java
 (original)
+++ 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/ArchetypeProcess.java
 Fri Jul  4 13:01:31 2014
@@ -39,19 +39,17 @@ public class ArchetypeProcess extends Ab
         final String syncopeAdminPassword = args[9];
 
         if (!new File(installPath).exists()) {
-            exec(String.format(Commands.createDirectory, installPath), 
handler, null);
+            exec(Commands.createDirectory(installPath), handler, null);
         }
-
-        exec(String.format(Commands.createArchetypeCommand,
-                mavenDir, syncopeVersion, groupId, artifactId, secretKey, 
anonymousKey), handler, installPath);
+        exec(Commands.createArchetype(mavenDir, syncopeVersion, groupId, 
artifactId, secretKey, anonymousKey),
+                handler, installPath);
         writeToFile(new File(installPath + "/" + artifactId + Pom.PATH), 
Pom.FILE);
 
-        exec(String.format(Commands.createDirectory, logsDirectory), handler, 
null);
+        exec(Commands.createDirectory(logsDirectory), handler, null);
 
-        exec(String.format(Commands.createDirectory, bundlesDirectory), 
handler, null);
+        exec(Commands.createDirectory(bundlesDirectory), handler, null);
 
-        exec(String.format(
-                Commands.compileCommand, mavenDir, logsDirectory, 
bundlesDirectory),
+        exec(Commands.compileArchetype(mavenDir, logsDirectory, 
bundlesDirectory),
                 handler, installPath + "/" + artifactId);
     }
 

Modified: 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/ContainerProcess.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/ContainerProcess.java?rev=1607847&r1=1607846&r2=1607847&view=diff
==============================================================================
--- 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/ContainerProcess.java
 (original)
+++ 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/ContainerProcess.java
 Fri Jul  4 13:01:31 2014
@@ -107,8 +107,7 @@ public class ContainerProcess extends Ab
             }
         }
 
-        exec(String.format(
-                Commands.compileCommand, mavenDir, logsDirectory, 
bundlesDirectory),
+        exec(Commands.compileArchetype(mavenDir, logsDirectory, 
bundlesDirectory),
                 handler, installPath + "/" + artifactId);
 
         switch (selectedContainer) {

Modified: 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/PersistenceProcess.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/PersistenceProcess.java?rev=1607847&r1=1607846&r2=1607847&view=diff
==============================================================================
--- 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/PersistenceProcess.java
 (original)
+++ 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/processes/PersistenceProcess.java
 Fri Jul  4 13:01:31 2014
@@ -89,7 +89,7 @@ public class PersistenceProcess extends 
     }
 
     private void writeOrmFile(final AbstractUIProcessHandler handler, final 
String content) {
-        exec(String.format(Commands.createDirectory, installPath + "/" + 
artifactId + OrmXml.PATH_DIR), handler, null);
+        exec(Commands.createDirectory(installPath + "/" + artifactId + 
OrmXml.PATH_DIR), handler, null);
         final File orm = new File(installPath + "/" + artifactId + 
OrmXml.PATH_COMPLETE);
         writeToFile(orm, content);
     }

Modified: 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/utilities/Commands.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/java/org/apache/syncope/installer/utilities/Commands.java?rev=1607847&r1=1607846&r2=1607847&view=diff
==============================================================================
--- 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/utilities/Commands.java
 (original)
+++ 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/utilities/Commands.java
 Fri Jul  4 13:01:31 2014
@@ -19,17 +19,54 @@
 package org.apache.syncope.installer.utilities;
 
 public class Commands {
-    
-    public static final String createArchetypeCommand
-            = "%s/bin/mvn archetype:generate "
+
+    public static String createArchetype(final String mavenDir, final String 
syncopeVersion, final String groupId,
+            final String artifactId, final String secretKey, final String 
anonymousKey) {
+        final StringBuilder commandBuilder = new StringBuilder();
+        if (IS_WIN) {
+            commandBuilder.append("cmd /c ").append(String.format(WIN_MAVEN, 
mavenDir));
+        } else {
+            commandBuilder.append(String.format(UNIX_MAVEN, mavenDir));
+        }
+        return commandBuilder.append(String.format(
+                CREATE_ARCHETYPE_COMMAND, syncopeVersion, groupId, artifactId, 
secretKey, anonymousKey))
+                .toString();
+
+    }
+
+    private static final String UNIX_MAVEN = "%s/bin/mvn ";
+
+    private static final String WIN_MAVEN = "%s\\bin\\mvn ";
+
+    private static final String CREATE_ARCHETYPE_COMMAND = "archetype:generate 
"
             + "-DarchetypeGroupId=org.apache.syncope "
             + "-DarchetypeArtifactId=syncope-archetype "
-            + "-DarchetypeRepository=http://repo1.maven.org/maven2 "
+            + 
"-DarchetypeRepository=http://repository.apache.org/content/repositories/snapshots
 "
             + "-DarchetypeVersion=%s "
             + "-DgroupId=%s -DartifactId=%s -DsecretKey=%s -DanonymousKey=%s 
-DinteractiveMode=false";
 
-    public static final String compileCommand = "%s/bin/mvn clean package 
-Dlog.directory=%s -Dbundles.directory=%s ";
+    public static String compileArchetype(
+            final String mavenDir, final String logsDirectory, final String 
bundlesDirectory) {
+        final StringBuilder commandBuilder = new StringBuilder();
+        if (IS_WIN) {
+            commandBuilder.append("cmd /c ").append(String.format(WIN_MAVEN, 
mavenDir));;
+        } else {
+            commandBuilder.append(String.format(UNIX_MAVEN, mavenDir));;
+        }
+        return commandBuilder.append(String.format(
+                COMPILE_ARCHETYPE, logsDirectory, bundlesDirectory))
+                .toString();
+    }
+
+    private static final String COMPILE_ARCHETYPE
+            = "clean package -Dlog.directory=%s -Dbundles.directory=%s ";
+
+    public static String createDirectory(final String directory) {
+        return String.format(CREATE_DIRECTORY, directory);
+    }
+
+    private static final String CREATE_DIRECTORY = "mkdir -p %s";
 
-    public static final String createDirectory = "mkdir -p %s";
+    public static final boolean IS_WIN = 
System.getProperty("os.name").toLowerCase().contains("win");
 
 }

Modified: 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/validators/ArchetypeValidator.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/java/org/apache/syncope/installer/validators/ArchetypeValidator.java?rev=1607847&r1=1607846&r2=1607847&view=diff
==============================================================================
--- 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/validators/ArchetypeValidator.java
 (original)
+++ 
syncope/trunk/installer/src/main/java/org/apache/syncope/installer/validators/ArchetypeValidator.java
 Fri Jul  4 13:01:31 2014
@@ -19,6 +19,7 @@
 package org.apache.syncope.installer.validators;
 
 import com.izforge.izpack.api.data.InstallData;
+import java.io.File;
 
 public class ArchetypeValidator extends AbstractValidator {
 
@@ -27,6 +28,7 @@ public class ArchetypeValidator extends 
     @Override
     public Status validateData(final InstallData installData) {
 
+        final String mavenDir = installData.getVariable("mvn.directory");
         final String mavenGroupId = installData.getVariable("mvn.groupid");
         final String mavenArtifactId = 
installData.getVariable("mvn.artifactid");
         final String mavenSecretKey = installData.getVariable("mvn.secretkey");
@@ -36,6 +38,13 @@ public class ArchetypeValidator extends 
 
         boolean verified = true;
         error = new StringBuilder("Required fields:\n");
+        if (isEmpty(mavenDir)) {
+            error.append("Maven home directory\n");
+            verified = false;
+        } else if (!new File(mavenDir + "/bin/mvn").exists()){
+            error.append("Maven home directory not valid, check it 
please...\n");
+            verified = false;
+        }
         if (isEmpty(mavenGroupId)) {
             error.append("GroupID\n");
             verified = false;

Modified: syncope/trunk/installer/src/main/resources/izpack/install.xml
URL: 
http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/resources/izpack/install.xml?rev=1607847&r1=1607846&r2=1607847&view=diff
==============================================================================
--- syncope/trunk/installer/src/main/resources/izpack/install.xml (original)
+++ syncope/trunk/installer/src/main/resources/izpack/install.xml Fri Jul  4 
13:01:31 2014
@@ -69,7 +69,7 @@ under the License.
     <variable name="WELCOME_TEXT" value="Apache Syncope Installer"/>
     <variable name="WELCOME_VERSION" value="${appversion}"/>
     <variable name="TargetPanel.dir.unix" value="/tmp/syncope"/>
-    <variable name="TargetPanel.dir.windows" value="c:\\syncope"/>
+    <variable name="TargetPanel.dir.windows" value="C:\Program Files"/>
   </variables>
   
   <dynamicvariables>

Modified: syncope/trunk/installer/src/main/resources/izpack/userInputSpec.xml
URL: 
http://svn.apache.org/viewvc/syncope/trunk/installer/src/main/resources/izpack/userInputSpec.xml?rev=1607847&r1=1607846&r2=1607847&view=diff
==============================================================================
--- syncope/trunk/installer/src/main/resources/izpack/userInputSpec.xml 
(original)
+++ syncope/trunk/installer/src/main/resources/izpack/userInputSpec.xml Fri Jul 
 4 13:01:31 2014
@@ -44,12 +44,12 @@ under the License.
       <spec id="mvn.anonymous.key.id" size="20" set="123456789asdfghj"/>
     </field>
     <field type="space"/>
-    <field type="text" variable="mvn.log.directory">
-      <spec id="archetype.mvn.log.directory" size="20" 
set="${TargetPanel.dir.unix}/log"/>
+    <field type="dir" variable="mvn.log.directory">
+      <spec id="archetype.mvn.log.directory" size="20" set=""/>
     </field>
     <field type="space"/>
-    <field type="text" variable="mvn.bundle.directory">
-      <spec id="archetype.mvn.bundle.directory" size="20" 
set="${TargetPanel.dir.unix}/bundles"/>
+    <field type="dir" variable="mvn.bundle.directory">
+      <spec id="archetype.mvn.bundle.directory" size="20" set=""/>
     </field>
     <field type="space"/>
     <field type="text" variable="mvn.syncope.version">


Reply via email to