Author: alessio.soldano(a)jboss.com
Date: 2008-02-18 20:24:06 -0500 (Mon, 18 Feb 2008)
New Revision: 5720
Added:
common/trunk/src/main/java/org/jboss/ws/
common/trunk/src/main/java/org/jboss/ws/tools/
common/trunk/src/main/java/org/jboss/ws/tools/ant/
common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseClasspathTask.java
common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseJUnitTestsTask.java
common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseProjectTask.java
Modified:
common/trunk/.classpath
common/trunk/ant-import/build-thirdparty.xml
common/trunk/build.xml
common/trunk/version.properties
Log:
[JBWS-1891] Adding Ant tasks
Modified: common/trunk/.classpath
===================================================================
--- common/trunk/.classpath 2008-02-18 12:28:29 UTC (rev 5719)
+++ common/trunk/.classpath 2008-02-19 01:24:06 UTC (rev 5720)
@@ -14,5 +14,6 @@
<classpathentry combineaccessrules="false" kind="src"
path="/spi"/>
<classpathentry kind="lib"
path="thirdparty/jboss-javaee.jar"/>
<classpathentry kind="lib" path="thirdparty/saaj-api.jar"/>
+ <classpathentry kind="lib" path="thirdparty/ant.jar"/>
<classpathentry kind="output" path="output/eclipse"/>
</classpath>
Modified: common/trunk/ant-import/build-thirdparty.xml
===================================================================
--- common/trunk/ant-import/build-thirdparty.xml 2008-02-18 12:28:29 UTC (rev 5719)
+++ common/trunk/ant-import/build-thirdparty.xml 2008-02-19 01:24:06 UTC (rev 5720)
@@ -48,6 +48,7 @@
<get
src="${jboss.repository}/jboss/microcontainer/${jboss-microcontainer}/lib/jboss-dependency-src.zip"
dest="${thirdparty.dir}/jboss-dependency-src.zip" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/jboss/microcontainer/${jboss-microcontainer}/lib/jboss-microcontainer.jar"
dest="${thirdparty.dir}/jboss-microcontainer.jar" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/jboss/microcontainer/${jboss-microcontainer}/lib/jboss-microcontainer-src.zip"
dest="${thirdparty.dir}/jboss-microcontainer-src.zip"
usetimestamp="true" verbose="true"/>
+ <get src="${jboss.repository}/apache-ant/${apache-ant}/lib/ant.jar"
dest="${thirdparty.dir}/ant.jar" usetimestamp="true"
verbose="true"/>
<get src="${jboss.repository}/junit/${junit}/lib/junit.jar"
dest="${thirdparty.dir}/junit.jar" usetimestamp="true"
verbose="true"/>
<get src="${jboss.repository}/sun-jaf/${sun-jaf}/lib/activation.jar"
dest="${thirdparty.dir}/activation.jar" usetimestamp="true"
verbose="true"/>
<get src="${jboss.repository}/sun-jaxb/${sun-jaxb}/lib/jaxb-api.jar"
dest="${thirdparty.dir}/jaxb-api.jar" usetimestamp="true"
verbose="true"/>
Modified: common/trunk/build.xml
===================================================================
--- common/trunk/build.xml 2008-02-18 12:28:29 UTC (rev 5719)
+++ common/trunk/build.xml 2008-02-19 01:24:06 UTC (rev 5720)
@@ -61,6 +61,7 @@
<javac srcdir="${common.java.dir}" sourcepath=""
destdir="${common.output.classes.dir}" encoding="utf-8"
debug="${javac.debug}" verbose="${javac.verbose}"
deprecation="${javac.deprecation}"
failonerror="${javac.fail.onerror}" source="1.5"
target="1.5">
<include name="org/jboss/wsf/**"/>
+ <include name="org/jboss/ws/**"/>
<classpath refid="common.thirdparty.classpath"/>
</javac>
</target>
@@ -102,6 +103,7 @@
<jar jarfile="${common.output.lib.dir}/jbossws-common.jar"
manifest="${common.output.etc.dir}/default.mf">
<fileset dir="${common.output.classes.dir}">
<include name="org/jboss/wsf/**"/>
+ <include name="org/jboss/ws/**"/>
</fileset>
</jar>
Added: common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseClasspathTask.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseClasspathTask.java
(rev 0)
+++ common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseClasspathTask.java 2008-02-19
01:24:06 UTC (rev 5720)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ws.tools.ant;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Path;
+
+/**
+ * An Ant task creating a simple Eclipse .classpath file using the provided
+ * Ant's path id.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 15-Feb-2008
+ */
+public class EclipseClasspathTask extends Task
+{
+ private String pathId;
+ private String excludesFile;
+
+ @Override
+ public void execute() throws BuildException
+ {
+ Project project = getProject();
+ Path path = (Path)project.getReference(pathId);
+ String[] pathElements = path.list();
+ try
+ {
+ List<String> excludes = getExcludes();
+ StringBuffer sb = new StringBuffer();
+ generateContent(sb, excludes, pathElements);
+ BufferedWriter out = new BufferedWriter(new FileWriter(new
File(getProject().getBaseDir(), ".classpath")));
+ out.write(sb.toString());
+ out.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new BuildException(e);
+ }
+ }
+
+ private void generateContent(StringBuffer sb, List<String> excludes, String[]
libs)
+ {
+ sb.append("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n");
+ sb.append("<classpath>\n");
+ if (excludes != null && !excludes.isEmpty())
+ {
+ sb.append("<classpathentry excluding=\"");
+ for (Iterator<String> it = excludes.iterator(); it.hasNext();)
+ {
+ sb.append(it.next());
+ if (it.hasNext())
+ sb.append("|");
+ }
+ sb.append("\" kind=\"src\"
path=\"tests/java\"/>\n");
+ }
+ sb.append("<classpathentry kind=\"con\"
path=\"org.eclipse.jdt.launching.JRE_CONTAINER\"/>\n");
+ for (int i = 0; i < libs.length; i++)
+ {
+ if (new File(libs[i]).exists())
+ {
+ sb.append("<classpathentry kind=\"lib\"
path=\"");
+ sb.append(absoluteToRelativePath(libs[i]));
+ sb.append("\"/>\n");
+ }
+ }
+ sb.append("<classpathentry kind=\"output\"
path=\"bin\"/>\n");
+ sb.append("</classpath>");
+ }
+
+ private List<String> getExcludes() throws IOException
+ {
+ List<String> excludes = new LinkedList<String>();
+ BufferedReader in = null;
+ try
+ {
+ in = new BufferedReader(new FileReader(excludesFile));
+ String str;
+ while ((str = in.readLine()) != null)
+ {
+ if (str.length() > 0 & !str.startsWith("#"))
+ excludes.add(str);
+ }
+ }
+ finally
+ {
+ if (in != null)
+ in.close();
+ }
+ return excludes;
+ }
+
+ private String absoluteToRelativePath(String absolutePath)
+ {
+ String baseDir = getProject().getBaseDir().toString();
+ String result = absolutePath;
+ if (absolutePath.startsWith(baseDir))
+ {
+ result = absolutePath.substring(baseDir.length());
+ if (result.startsWith("\\") || result.startsWith("/"))
+ result = result.substring(1);
+ }
+ return result;
+ }
+
+ public void setPathId(String pathId)
+ {
+ this.pathId = pathId;
+ }
+
+ public void setExcludesFile(String excludesFile)
+ {
+ this.excludesFile = excludesFile;
+ }
+
+}
Property changes on:
common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseClasspathTask.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseJUnitTestsTask.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseJUnitTestsTask.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseJUnitTestsTask.java 2008-02-19
01:24:06 UTC (rev 5720)
@@ -0,0 +1,249 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ws.tools.ant;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.FileSet;
+
+/**
+ * An Ant task creating Eclipse's launch configuration files for the JUnit tests
+ * of the test-suite.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 18-Feb-2008
+ */
+public class EclipseJUnitTestsTask extends Task
+{
+ private String projectName;
+ private String projectWorkingDir; // the Eclipse project working dir, i.e. the output
dir
+ private String srcDir; // the tests src dir
+ private String integrationTarget;
+ private String jbossHome;
+ private String endorsedDir;
+ private String namingProviderUrl;
+ private String securityPolicy;
+ private FileSet fileset;
+
+ @Override
+ public void execute() throws BuildException
+ {
+ try
+ {
+ DirectoryScanner dsc = fileset.getDirectoryScanner(getProject());
+ String[] classes = dsc.getIncludedFiles();
+ for (int i = 0; i < classes.length; i++)
+ {
+ String clazz = classes[i];
+ File file = new File(getProject().getBaseDir(), pathToClassName(clazz) +
".launch");
+ BufferedWriter out = new BufferedWriter(new FileWriter(file));
+ out.write(getSingleTestConf(clazz).toString());
+ out.close();
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new BuildException(e);
+ }
+ }
+
+ public FileSet createFileset()
+ {
+ this.fileset = new FileSet();
+ return fileset;
+ }
+
+ private static String pathToFullClassName(String path)
+ {
+ // remove ".class" and replace slashes and backslashes with a dot
+ return path.substring(0, path.length() - 6).replaceAll("\\\\",
".").replaceAll("/", ".");
+ }
+
+ private static String pathToClassName(String path)
+ {
+ String fullClassName = pathToFullClassName(path);
+ return fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
+ }
+
+ private LaunchConfiguration getSingleTestConf(String clazz)
+ {
+ LaunchConfiguration conf = new LaunchConfiguration();
+
conf.addEntryToListAttribute("org.eclipse.debug.core.MAPPED_RESOURCE_PATHS",
"/" + projectName + "/" + absoluteToRelativePath(srcDir) +
"/"
+ + clazz.substring(0, clazz.length() - 6) + ".java");
+
conf.addEntryToListAttribute("org.eclipse.debug.core.MAPPED_RESOURCE_TYPES",
"1");
+
conf.putBooleanAttribute("org.eclipse.debug.core.appendEnvironmentVariables",
true);
+ conf.putBooleanAttribute("org.eclipse.jdt.junit.KEEPRUNNING_ATTR",
false);
+ conf.putStringAttribute("org.eclipse.jdt.junit.CONTAINER",
"");
+ conf.putStringAttribute("org.eclipse.jdt.junit.TESTNAME", "");
+ conf.putStringAttribute("org.eclipse.jdt.junit.TEST_KIND",
"org.eclipse.jdt.junit.loader.junit3");
+ conf.putStringAttribute("org.eclipse.jdt.launching.MAIN_TYPE",
pathToFullClassName(clazz));
+ conf.putStringAttribute("org.eclipse.jdt.launching.PROJECT_ATTR",
projectName);
+ // computing the userDir; please note we get the relative path since we use the
Eclipse $workspace_loc variable
+ String userDir = "${workspace_loc:" + projectName + "}/" +
absoluteToRelativePath(projectWorkingDir);
+ conf.putStringAttribute("org.eclipse.jdt.launching.VM_ARGUMENTS",
getVMArguments(userDir));
+ conf.putStringAttribute("org.eclipse.jdt.launching.WORKING_DIRECTORY",
userDir);
+ return conf;
+ }
+
+ private String getVMArguments(String userDir)
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("-Djbossws.integration.target=").append(integrationTarget);
+ sb.append(" -ea ");
+ sb.append("-Dtest.execution.dir=").append(userDir);
+ sb.append(" -Djava.endorsed.dirs=").append(endorsedDir);
+ sb.append(" ");
+ sb.append("-Djava.naming.provider.url=").append(namingProviderUrl);
+
sb.append(" -Djava.protocol.handler.pkgs=org.jboss.virtual.protocol ");
+
sb.append("-Djava.security.policy=").append(absoluteToRelativePath(securityPolicy));
+
sb.append(" -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory ");
+ sb.append("-Duser.dir=").append(userDir);
+ sb.append(" -Djboss.home=").append(jbossHome);
+ sb.append(" -Djdk.home=${env_var:JAVA_HOME}");
+ return sb.toString();
+ }
+
+ private String absoluteToRelativePath(String absolutePath)
+ {
+ String baseDir = getProject().getBaseDir().toString();
+ if (!absolutePath.startsWith(baseDir))
+ throw new IllegalArgumentException("The provided absolute path is outside
the current basedir: " + baseDir);
+ return absolutePath.substring(baseDir.length() + 1);
+ }
+
+ public void setSrcDir(String srcDir)
+ {
+ this.srcDir = srcDir;
+ }
+
+ public void setProjectName(String projectName)
+ {
+ this.projectName = projectName;
+ }
+
+ public void setProjectWorkingDir(String projectWorkingDir)
+ {
+ this.projectWorkingDir = projectWorkingDir;
+ }
+
+ public void setIntegrationTarget(String integrationTarget)
+ {
+ this.integrationTarget = integrationTarget;
+ }
+
+ public void setJbossHome(String jbossHome)
+ {
+ this.jbossHome = jbossHome;
+ }
+
+ public void setNamingProviderUrl(String namingProviderUrl)
+ {
+ this.namingProviderUrl = namingProviderUrl;
+ }
+
+ public void setSecurityPolicy(String securityPolicy)
+ {
+ this.securityPolicy = securityPolicy;
+ }
+
+ public void setEndorsedDir(String endorsedDir)
+ {
+ this.endorsedDir = endorsedDir;
+ }
+
+ private class LaunchConfiguration
+ {
+ private Map<String, String> booleanAttributes = new LinkedHashMap<String,
String>();
+ private Map<String, String> stringAttributes = new LinkedHashMap<String,
String>();
+ private Map<String, List<String>> listAttributes = new
LinkedHashMap<String, List<String>>();
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n");
+ sb.append("<launchConfiguration
type=\"org.eclipse.jdt.junit.launchconfig\">\n");
+ for (String key : listAttributes.keySet())
+ {
+ sb.append("<listAttribute
key=\"").append(key).append("\">\n");
+ for (String value : listAttributes.get(key))
+ {
+ sb.append("<listEntry
value=\"").append(value).append("\"/>\n");
+ }
+ sb.append("</listAttribute>\n");
+ }
+ for (String key : booleanAttributes.keySet())
+ {
+ sb.append("<booleanAttribute key=\"").append(key);
+ sb.append("\"
value=\"").append(booleanAttributes.get(key)).append("\"/>\n");
+ }
+ for (String key : stringAttributes.keySet())
+ {
+ sb.append("<stringAttribute key=\"").append(key);
+ sb.append("\"
value=\"").append(stringAttributes.get(key)).append("\"/>\n");
+ }
+ sb.append("</launchConfiguration>");
+ return sb.toString();
+ }
+
+ public Map<String, String> getBooleanAttributes()
+ {
+ return booleanAttributes;
+ }
+
+ public void putBooleanAttribute(String name, boolean value)
+ {
+ this.booleanAttributes.put(name, String.valueOf(value));
+ }
+
+ public Map<String, String> getStringAttributes()
+ {
+ return stringAttributes;
+ }
+
+ public void putStringAttribute(String name, String value)
+ {
+ this.stringAttributes.put(name, value);
+ }
+
+ public Map<String, List<String>> getListAttributes()
+ {
+ return listAttributes;
+ }
+
+ public void addEntryToListAttribute(String attribute, String entryValue)
+ {
+ if (!listAttributes.containsKey(attribute))
+ listAttributes.put(attribute, new LinkedList<String>());
+ listAttributes.get(attribute).add(entryValue);
+ }
+ }
+}
Property changes on:
common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseJUnitTestsTask.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseProjectTask.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseProjectTask.java
(rev 0)
+++ common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseProjectTask.java 2008-02-19
01:24:06 UTC (rev 5720)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ws.tools.ant;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+/**
+ * An Ant task creating a simple Eclipse .project file using the provided project name.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 18-Feb-2008
+ */
+public class EclipseProjectTask extends Task
+{
+ private String projectName;
+
+ @Override
+ public void execute() throws BuildException
+ {
+ try
+ {
+ StringBuffer sb = new StringBuffer();
+ generateContent(sb);
+ BufferedWriter out = new BufferedWriter(new FileWriter(new
File(getProject().getBaseDir(), ".project")));
+ out.write(sb.toString());
+ out.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new BuildException(e);
+ }
+ }
+
+ private void generateContent(StringBuffer sb)
+ {
+ sb.append("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n");
+ sb.append("<projectDescription>\n <name>");
+ sb.append(projectName);
+ sb.append("</name>\n" +
+ " <comment></comment>\n" +
+ " <projects>\n" +
+ " </projects>\n" +
+ " <buildSpec>\n" +
+ " <buildCommand>\n" +
+ "
<name>org.eclipse.jdt.core.javabuilder</name>\n" +
+ " <arguments>\n" +
+ " </arguments>\n" +
+ " </buildCommand>\n" +
+ " </buildSpec>\n" +
+ " <natures>\n" +
+ "
<nature>org.eclipse.jdt.core.javanature</nature>\n" +
+ " </natures>\n" +
+ "</projectDescription>");
+ }
+
+ public void setProjectName(String projectName)
+ {
+ this.projectName = projectName;
+ }
+}
Property changes on:
common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseProjectTask.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: common/trunk/version.properties
===================================================================
--- common/trunk/version.properties 2008-02-18 12:28:29 UTC (rev 5719)
+++ common/trunk/version.properties 2008-02-19 01:24:06 UTC (rev 5720)
@@ -19,6 +19,7 @@
jboss-common-logging-spi=2.0.2.GA
jboss-javaee=5.0.0.Beta3Update1
jboss-microcontainer=2.0.0.Beta3
+apache-ant=1.6.5
junit=3.8.1
sun-jaf=1.1
sun-jaxb=2.1.4