Author: richard.opalka(a)jboss.com
Date: 2010-05-14 02:53:26 -0400 (Fri, 14 May 2010)
New Revision: 12231
Added:
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/AntTaskHelper.java
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSConsumeTask.java
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSProvideTask.java
Log:
[JBWS-3024] propagate JVM args to JVM system properties in forked ANT tools
Added: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/AntTaskHelper.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/AntTaskHelper.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/AntTaskHelper.java 2010-05-14
06:53:26 UTC (rev 12231)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.spi.tools.ant;
+
+import org.apache.tools.ant.types.CommandlineJava.SysProperties;
+import org.apache.tools.ant.types.Environment.Variable;
+
+/**
+ * Helper class for ANT tasks.
+ *
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ */
+final class AntTaskHelper
+{
+ /**
+ * Constructor.
+ */
+ private AntTaskHelper()
+ {
+ // forbidden constructor
+ }
+
+ /**
+ * Converts array of JVM arguments to ANT SysProperties object.
+ *
+ * @param arguments to be converted.
+ * @return ANT SysProperties object.
+ */
+ static SysProperties toSystemProperties(final String[] arguments)
+ {
+ final SysProperties retVal = new SysProperties();
+
+ if (arguments != null && arguments.length != 0)
+ {
+ for (final String argument : arguments)
+ {
+ if (argument.startsWith("-D"))
+ {
+ Variable var = AntTaskHelper.toVariable(argument);
+ retVal.addVariable(var);
+ }
+ }
+ }
+
+ return retVal;
+ }
+
+ /**
+ * Converts JVM property of format -Dkey=value to ANT Variable object.
+ *
+ * @param argument to be converted
+ * @return ANT Variable object
+ */
+ private static Variable toVariable(final String argument)
+ {
+ final Variable retVal = new Variable();
+ final int equalSignIndex = argument.indexOf('=');
+
+ if (equalSignIndex == -1)
+ {
+ final String key = argument.substring(2);
+ retVal.setKey(key);
+ }
+ else
+ {
+ final String key = argument.substring(2, equalSignIndex);
+ retVal.setKey(key);
+ final String value = argument.substring(equalSignIndex + 1);
+ retVal.setValue(value);
+ }
+
+ return retVal;
+ }
+}
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSConsumeTask.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSConsumeTask.java 2010-05-13
18:32:02 UTC (rev 12230)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSConsumeTask.java 2010-05-14
06:53:26 UTC (rev 12231)
@@ -37,6 +37,7 @@
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.CommandlineJava.SysProperties;
import org.jboss.wsf.spi.tools.WSContractConsumer;
/**
@@ -75,6 +76,7 @@
* </pre>
*
* @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public class WSConsumeTask extends Task
{
@@ -343,6 +345,12 @@
ExecuteJava execute = new ExecuteJava();
execute.setClasspath(path);
execute.setJavaCommand(command.getJavaCommand());
+
+ // propagate system properties (useful e.g. for endorsing)
+ String[] arguments = command.getVmCommand().getArguments();
+ SysProperties properties = AntTaskHelper.toSystemProperties(arguments);
+ execute.setSystemProperties(properties);
+
if (execute.fork(this) != 0)
throw new BuildException("Could not invoke WSConsumeTask",
getLocation());
}
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSProvideTask.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSProvideTask.java 2010-05-13
18:32:02 UTC (rev 12230)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSProvideTask.java 2010-05-14
06:53:26 UTC (rev 12231)
@@ -31,6 +31,8 @@
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.types.CommandlineJava.SysProperties;
+import org.apache.tools.ant.types.Environment.Variable;
import org.jboss.wsf.spi.tools.WSContractProvider;
import java.io.File;
@@ -317,7 +319,12 @@
ExecuteJava execute = new ExecuteJava();
execute.setClasspath(path);
execute.setJavaCommand(command.getJavaCommand());
-
+
+ // propagate system properties (useful e.g. for endorsing)
+ String[] arguments = command.getVmCommand().getArguments();
+ SysProperties properties = AntTaskHelper.toSystemProperties(arguments);
+ execute.setSystemProperties(properties);
+
if (execute.fork(this) != 0)
throw new BuildException("Could not invoke WSProvideTask",
getLocation());
}