You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by ma...@apache.org on 2014/08/01 16:21:11 UTC
svn commit: r1615110 - in /syncope/branches/1_2_X: ./ installer/
installer/src/main/java/org/apache/syncope/installer/containers/
installer/src/main/java/org/apache/syncope/installer/processes/
installer/src/main/java/org/apache/syncope/installer/utili...
Author: massi
Date: Fri Aug 1 14:21:10 2014
New Revision: 1615110
URL: http://svn.apache.org/r1615110
Log:
Use maven-invoker lib instead of maven command with runtime exec lib + refactoring #SYNCOPE-526
Added:
syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/FileSystemUtils.java
- copied, changed from r1615107, syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/AbstractProcess.java
syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
Removed:
syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/AbstractProcess.java
syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/Commands.java
Modified:
syncope/branches/1_2_X/installer/pom.xml
syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/containers/Tomcat.java
syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/ArchetypeProcess.java
syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/ContainerProcess.java
syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/PersistenceProcess.java
syncope/branches/1_2_X/installer/src/main/resources/izpack/install.xml
syncope/branches/1_2_X/pom.xml
Modified: syncope/branches/1_2_X/installer/pom.xml
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/installer/pom.xml?rev=1615110&r1=1615109&r2=1615110&view=diff
==============================================================================
--- syncope/branches/1_2_X/installer/pom.xml (original)
+++ syncope/branches/1_2_X/installer/pom.xml Fri Aug 1 14:21:10 2014
@@ -55,6 +55,10 @@ under the License.
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-panel</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-invoker</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Modified: syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/containers/Tomcat.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/containers/Tomcat.java?rev=1615110&r1=1615109&r2=1615110&view=diff
==============================================================================
--- syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/containers/Tomcat.java (original)
+++ syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/containers/Tomcat.java Fri Aug 1 14:21:10 2014
@@ -20,7 +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.FileSystemUtils;
import org.apache.syncope.installer.utilities.HttpUtils;
public class Tomcat extends AbstractContainer {
@@ -52,7 +52,7 @@ public class Tomcat extends AbstractCont
public boolean deployCore() {
int status;
- if (Commands.IS_WIN) {
+ if (FileSystemUtils.IS_WIN) {
status = httpUtils.getWithBasicAuth(pathEncoded(WIN_DEPLOY_SYNCOPE_CORE_QUERY));
} else {
status = httpUtils.getWithBasicAuth(path(UNIX_DEPLOY_SYNCOPE_CORE_QUERY));
@@ -63,7 +63,7 @@ public class Tomcat extends AbstractCont
public boolean deployConsole() {
int status;
- if (Commands.IS_WIN) {
+ if (FileSystemUtils.IS_WIN) {
status = httpUtils.getWithBasicAuth(pathEncoded(WIN_DEPLOY_SYNCOPE_CONSOLE_QUERY));
} else {
status = httpUtils.getWithBasicAuth(path(UNIX_DEPLOY_SYNCOPE_CONSOLE_QUERY));
Modified: syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/ArchetypeProcess.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/ArchetypeProcess.java?rev=1615110&r1=1615109&r2=1615110&view=diff
==============================================================================
--- syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/ArchetypeProcess.java (original)
+++ syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/ArchetypeProcess.java Fri Aug 1 14:21:10 2014
@@ -18,12 +18,13 @@
*/
package org.apache.syncope.installer.processes;
+import org.apache.syncope.installer.utilities.FileSystemUtils;
import com.izforge.izpack.panels.process.AbstractUIProcessHandler;
import java.io.File;
import org.apache.syncope.installer.files.Pom;
-import org.apache.syncope.installer.utilities.Commands;
+import org.apache.syncope.installer.utilities.MavenUtils;
-public class ArchetypeProcess extends AbstractProcess {
+public class ArchetypeProcess {
public void run(final AbstractUIProcessHandler handler, final String[] args) {
@@ -39,19 +40,22 @@ public class ArchetypeProcess extends Ab
final String syncopeAdminPassword = args[9];
if (!new File(installPath).exists()) {
- exec(Commands.createDirectory(installPath), handler, null);
+ FileSystemUtils.createDirectory(installPath, handler, null);
}
- exec(Commands.createArchetype(mavenDir, syncopeVersion, groupId, artifactId, secretKey, anonymousKey),
- handler, installPath);
- writeToFile(new File(installPath + "/" + artifactId + Pom.PATH),
+
+ final MavenUtils mavenUtils = new MavenUtils(mavenDir);
+
+ mavenUtils.archetypeGenerate(
+ syncopeVersion, groupId, artifactId, secretKey, anonymousKey, installPath);
+
+ FileSystemUtils.writeToFile(new File(installPath + "/" + artifactId + Pom.PATH),
String.format(Pom.FILE, syncopeVersion, syncopeVersion));
- exec(Commands.createDirectory(logsDirectory), handler, null);
+ FileSystemUtils.createDirectory(logsDirectory, handler, null);
- exec(Commands.createDirectory(bundlesDirectory), handler, null);
+ FileSystemUtils.createDirectory(bundlesDirectory, handler, null);
- exec(Commands.compileArchetype(mavenDir, logsDirectory, bundlesDirectory),
- handler, installPath + "/" + artifactId);
+ mavenUtils.createPackage(installPath + "/" + artifactId, logsDirectory, bundlesDirectory);
}
}
Modified: syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/ContainerProcess.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/ContainerProcess.java?rev=1615110&r1=1615109&r2=1615110&view=diff
==============================================================================
--- syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/ContainerProcess.java (original)
+++ syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/ContainerProcess.java Fri Aug 1 14:21:10 2014
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.installer.processes;
+import org.apache.syncope.installer.utilities.FileSystemUtils;
import com.izforge.izpack.panels.process.AbstractUIProcessHandler;
import java.io.File;
import org.apache.syncope.installer.containers.Glassfish;
@@ -28,9 +29,9 @@ import org.apache.syncope.installer.file
import org.apache.syncope.installer.files.JBossDeploymentStructureXml;
import org.apache.syncope.installer.files.PersistenceContextEMFactoryXml;
import org.apache.syncope.installer.files.WebXml;
-import org.apache.syncope.installer.utilities.Commands;
+import org.apache.syncope.installer.utilities.MavenUtils;
-public class ContainerProcess extends AbstractProcess {
+public class ContainerProcess {
private String installPath;
@@ -91,24 +92,26 @@ public class ContainerProcess extends Ab
jbossAdminPassword = args[18];
if (withDataSource) {
- writeToFile(new File(installPath + "/" + artifactId + WebXml.PATH), WebXml.withDataSource());
+ FileSystemUtils.writeToFile(new File(installPath + "/" + artifactId + WebXml.PATH), WebXml.withDataSource());
switch (selectedContainer) {
case JBOSS:
- writeToFile(new File(installPath + "/" + artifactId + WebXml.PATH), WebXml.withDataSourceForJBoss());
- writeToFile(new File(installPath + "/" + artifactId + PersistenceContextEMFactoryXml.PATH),
- PersistenceContextEMFactoryXml.FILE);
- writeToFile(new File(installPath + "/" + artifactId + JBossDeploymentStructureXml.PATH),
+ FileSystemUtils.writeToFile(new File(installPath + "/" + artifactId + WebXml.PATH),
+ WebXml.withDataSourceForJBoss());
+ FileSystemUtils.writeToFile(new File(installPath + "/" + artifactId
+ + PersistenceContextEMFactoryXml.PATH), PersistenceContextEMFactoryXml.FILE);
+ FileSystemUtils.writeToFile(new File(installPath + "/" + artifactId
+ + JBossDeploymentStructureXml.PATH),
String.format(JBossDeploymentStructureXml.FILE, jbossJdbcModuleName));
break;
case GLASSFISH:
- writeToFile(new File(installPath + "/" + artifactId + GlassfishWebXml.PATH),
+ FileSystemUtils.writeToFile(new File(installPath + "/" + artifactId + GlassfishWebXml.PATH),
GlassfishWebXml.withDataSource());
break;
}
}
- exec(Commands.compileArchetype(mavenDir, logsDirectory, bundlesDirectory),
- handler, installPath + "/" + artifactId);
+ final MavenUtils mavenUtils = new MavenUtils(mavenDir);
+ mavenUtils.createPackage(installPath + "/" + artifactId, logsDirectory, bundlesDirectory);
switch (selectedContainer) {
case TOMCAT:
@@ -148,12 +151,12 @@ public class ContainerProcess extends Ab
break;
case GLASSFISH:
final String createJavaOptCommand = "sh " + glassfishDir + Glassfish.CREATE_JAVA_OPT_COMMAND;
- exec(createJavaOptCommand, handler, null);
+ FileSystemUtils.exec(createJavaOptCommand, handler, null);
final Glassfish glassfish = new Glassfish(installPath, artifactId);
- exec("sh " + glassfishDir + Glassfish.DEPLOY_COMMAND + glassfish.deployCore(), handler, null);
- exec("sh " + glassfishDir + Glassfish.DEPLOY_COMMAND + glassfish.deployConsole(), handler, null);
+ FileSystemUtils.exec("sh " + glassfishDir + Glassfish.DEPLOY_COMMAND + glassfish.deployCore(), handler, null);
+ FileSystemUtils.exec("sh " + glassfishDir + Glassfish.DEPLOY_COMMAND + glassfish.deployConsole(), handler, null);
break;
}
}
Modified: syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/PersistenceProcess.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/PersistenceProcess.java?rev=1615110&r1=1615109&r2=1615110&view=diff
==============================================================================
--- syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/PersistenceProcess.java (original)
+++ syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/PersistenceProcess.java Fri Aug 1 14:21:10 2014
@@ -18,14 +18,14 @@
*/
package org.apache.syncope.installer.processes;
+import org.apache.syncope.installer.utilities.FileSystemUtils;
import com.izforge.izpack.panels.process.AbstractUIProcessHandler;
import java.io.File;
import org.apache.syncope.installer.enums.DBs;
import org.apache.syncope.installer.files.OrmXml;
import org.apache.syncope.installer.files.PersistenceProperties;
-import org.apache.syncope.installer.utilities.Commands;
-public class PersistenceProcess extends AbstractProcess {
+public class PersistenceProcess {
private String installPath;
@@ -83,14 +83,14 @@ public class PersistenceProcess extends
break;
}
- writeToFile(new File(
+ FileSystemUtils.writeToFile(new File(
installPath + "/" + artifactId + PersistenceProperties.PATH), persistenceProperties.toString());
}
private void writeOrmFile(final AbstractUIProcessHandler handler, final String content) {
- exec(Commands.createDirectory(installPath + "/" + artifactId + OrmXml.PATH_DIR), handler, null);
+ FileSystemUtils.createDirectory(installPath + "/" + artifactId + OrmXml.PATH_DIR, handler, null);
final File orm = new File(installPath + "/" + artifactId + OrmXml.PATH_COMPLETE);
- writeToFile(orm, content);
+ FileSystemUtils.writeToFile(orm, content);
}
}
Copied: syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/FileSystemUtils.java (from r1615107, syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/AbstractProcess.java)
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/FileSystemUtils.java?p2=syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/FileSystemUtils.java&p1=syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/AbstractProcess.java&r1=1615107&r2=1615110&rev=1615110&view=diff
==============================================================================
--- syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/processes/AbstractProcess.java (original)
+++ syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/FileSystemUtils.java Fri Aug 1 14:21:10 2014
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.syncope.installer.processes;
+package org.apache.syncope.installer.utilities;
import com.izforge.izpack.panels.process.AbstractUIProcessHandler;
import java.io.BufferedReader;
@@ -27,9 +27,18 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-public abstract class AbstractProcess {
+public class FileSystemUtils {
- protected void exec(final String cmd, final AbstractUIProcessHandler handler, final String path) {
+ public static final boolean IS_WIN = System.getProperty("os.name").toLowerCase().contains("win");
+
+ public static void createDirectory(final String directoryPath,
+ final AbstractUIProcessHandler handler, final String path) {
+ exec(String.format(CREATE_DIRECTORY, directoryPath), null, path);
+ }
+
+ private static final String CREATE_DIRECTORY = "mkdir -p %s";
+
+ public static void exec(final String cmd, final AbstractUIProcessHandler handler, final String path) {
try {
final ProcessBuilder builder = new ProcessBuilder(cmd.split(" "));
if (path != null && !path.isEmpty()) {
@@ -41,7 +50,7 @@ public abstract class AbstractProcess {
}
}
- protected void readResponse(final InputStream inputStream, final AbstractUIProcessHandler handler) throws
+ private static void readResponse(final InputStream inputStream, final AbstractUIProcessHandler handler) throws
IOException {
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line = reader.readLine();
@@ -52,7 +61,7 @@ public abstract class AbstractProcess {
inputStream.close();
}
- protected void writeToFile(final File orm, final String content) {
+ public static void writeToFile(final File orm, final String content) {
try {
final FileWriter fw = new FileWriter(orm.getAbsoluteFile());
final BufferedWriter bw = new BufferedWriter(fw);
Added: syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java?rev=1615110&view=auto
==============================================================================
--- syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java (added)
+++ syncope/branches/1_2_X/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java Fri Aug 1 14:21:10 2014
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.syncope.installer.utilities;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import org.apache.maven.shared.invoker.DefaultInvocationRequest;
+import org.apache.maven.shared.invoker.DefaultInvoker;
+import org.apache.maven.shared.invoker.InvocationRequest;
+import org.apache.maven.shared.invoker.InvocationResult;
+import org.apache.maven.shared.invoker.Invoker;
+import org.apache.maven.shared.invoker.MavenInvocationException;
+
+public class MavenUtils {
+
+ private static final String MAVEN_HOME_PROPERTY = "maven.home";
+
+ public MavenUtils(final String mavenHomeDirectory) {
+ if (System.getProperty(MAVEN_HOME_PROPERTY) == null || System.getProperty(MAVEN_HOME_PROPERTY).isEmpty()) {
+ System.setProperty(MAVEN_HOME_PROPERTY, mavenHomeDirectory);
+ }
+ }
+
+ public void archetypeGenerate(final String archetypeVersion, final String groupId,
+ final String artifactId, final String secretKey, final String anonymousKey, final String path) {
+
+ final InvocationRequest request = new DefaultInvocationRequest();
+ request.setGoals(Collections.singletonList("archetype:generate"));
+ request.setInteractive(false);
+ request.setProperties(archetypeProperties(archetypeVersion, groupId, artifactId, secretKey, anonymousKey));
+ invoke(request, "/tmp/syncope");
+ }
+
+ private Properties archetypeProperties(final String archetypeVersion, final String groupId,
+ final String artifactId, final String secretKey, final String anonymousKey) {
+ final Properties properties = new Properties();
+ properties.setProperty("archetypeGroupId", "org.apache.syncope");
+ properties.setProperty("archetypeArtifactId", "syncope-archetype");
+ properties.setProperty("archetypeRepository", "http://repository.apache.org/content/repositories/snapshots");
+ properties.setProperty("archetypeVersion", archetypeVersion);
+ properties.setProperty("groupId", groupId);
+ properties.setProperty("artifactId", artifactId);
+ properties.setProperty("secretKey", secretKey);
+ properties.setProperty("anonymousKey", anonymousKey);
+ return properties;
+ }
+
+ public void createPackage(final String path, final String logDirectory, final String bundlesDirectory) {
+
+ final InvocationRequest request = new DefaultInvocationRequest();
+ request.setProperties(packageProperties(logDirectory, bundlesDirectory));
+ final List<String> mavenGoals = new ArrayList<String>();
+ mavenGoals.add("clean");
+ mavenGoals.add("package");
+ request.setGoals(mavenGoals);
+ invoke(request, path);
+ }
+
+ private Properties packageProperties(final String logDirectory, final String bundlesDirectory) {
+ Properties properties = new Properties();
+ properties.setProperty("log.directory", logDirectory);
+ properties.setProperty("bundles.directory", bundlesDirectory);
+ return properties;
+ }
+
+ private InvocationResult invoke(final InvocationRequest request, final String path) {
+ InvocationResult result = null;
+ final Invoker invoker = new DefaultInvoker();
+ invoker.setWorkingDirectory(new File(path));
+ try {
+ result = invoker.execute(request);
+ } catch (MavenInvocationException ex) {
+
+ }
+ return result;
+ }
+
+}
Modified: syncope/branches/1_2_X/installer/src/main/resources/izpack/install.xml
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/installer/src/main/resources/izpack/install.xml?rev=1615110&r1=1615109&r2=1615110&view=diff
==============================================================================
--- syncope/branches/1_2_X/installer/src/main/resources/izpack/install.xml (original)
+++ syncope/branches/1_2_X/installer/src/main/resources/izpack/install.xml Fri Aug 1 14:21:10 2014
@@ -142,6 +142,9 @@ under the License.
<jar src="lib/jackson-core-@{jackson.version}.1.jar"/>
<jar src="lib/jackson-annotations-@{jackson.version}.jar"/>
+ <jar src="lib/maven-invoker-@{maven-invoker.version}.jar"/>
+ <jar src="lib/plexus-utils-3.0.8.jar"/>
+
<panels>
<panel classname="HTMLHelloPanel" id="welcome"/>
Modified: syncope/branches/1_2_X/pom.xml
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/pom.xml?rev=1615110&r1=1615109&r2=1615110&view=diff
==============================================================================
--- syncope/branches/1_2_X/pom.xml (original)
+++ syncope/branches/1_2_X/pom.xml Fri Aug 1 14:21:10 2014
@@ -367,6 +367,7 @@ under the License.
<codemirror.version>3.23</codemirror.version>
<izpack.version>5.0.0-rc2</izpack.version>
+ <maven-invoker.version>2.1.1</maven-invoker.version>
<jdeb.version>1.3</jdeb.version>
@@ -923,6 +924,11 @@ under the License.
<artifactId>izpack-panel</artifactId>
<version>${izpack.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-invoker</artifactId>
+ <version>${maven-invoker.version}</version>
+ </dependency>
<!-- TEST -->
<dependency>