Author: alessio.soldano(a)jboss.com
Date: 2008-03-13 20:36:19 -0400 (Thu, 13 Mar 2008)
New Revision: 5971
Added:
common/trunk/src/main/java/org/jboss/ws/tools/ant/PathWriterTask.java
Modified:
common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseClasspathTask.java
Log:
[JBWS-1888] new ant task and some changes to the eclipse classpath task
Modified: common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseClasspathTask.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseClasspathTask.java 2008-03-13
18:39:12 UTC (rev 5970)
+++ common/trunk/src/main/java/org/jboss/ws/tools/ant/EclipseClasspathTask.java 2008-03-14
00:36:19 UTC (rev 5971)
@@ -47,6 +47,9 @@
{
private String pathId;
private String excludesFile;
+ private String outputFile;
+ private String srcPath;
+ private String srcOutput;
@Override
public void execute() throws BuildException
@@ -59,7 +62,8 @@
List<String> excludes = getExcludes();
StringBuffer sb = new StringBuffer();
generateContent(sb, excludes, pathElements);
- BufferedWriter out = new BufferedWriter(new FileWriter(new
File(getProject().getBaseDir(), ".classpath")));
+ File file = outputFile != null ? new File(outputFile) : new
File(getProject().getBaseDir(), ".classpath");
+ BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.write(sb.toString());
out.close();
}
@@ -74,17 +78,32 @@
{
sb.append("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n");
sb.append("<classpath>\n");
+ sb.append("<classpathentry ");
if (excludes != null && !excludes.isEmpty())
{
- sb.append("<classpathentry excluding=\"");
+ sb.append("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("\" ");
}
+ sb.append("kind=\"src\" ");
+ if (srcOutput != null)
+ {
+ sb.append("output=\"");
+ sb.append(srcOutput);
+ sb.append("\" ");
+ }
+ if (srcPath != null)
+ {
+ sb.append("path=\"");
+ sb.append(srcPath);
+ sb.append("\" ");
+ }
+ sb.append("/>\n");
sb.append("<classpathentry kind=\"con\"
path=\"org.eclipse.jdt.launching.JRE_CONTAINER\"/>\n");
for (int i = 0; i < libs.length; i++)
{
@@ -102,22 +121,25 @@
private List<String> getExcludes() throws IOException
{
List<String> excludes = new LinkedList<String>();
- BufferedReader in = null;
- try
+ if (excludesFile != null)
{
- in = new BufferedReader(new FileReader(excludesFile));
- String str;
- while ((str = in.readLine()) != null)
+ BufferedReader in = null;
+ try
{
- if (str.length() > 0 & !str.startsWith("#"))
- excludes.add(str);
+ 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();
+ }
}
- finally
- {
- if (in != null)
- in.close();
- }
return excludes;
}
@@ -144,4 +166,19 @@
this.excludesFile = excludesFile;
}
+ public void setOutputFile(String outputFile)
+ {
+ this.outputFile = outputFile;
+ }
+
+ public void setSrcPath(String srcPath)
+ {
+ this.srcPath = srcPath;
+ }
+
+ public void setSrcOutput(String srcOutput)
+ {
+ this.srcOutput = srcOutput;
+ }
+
}
Added: common/trunk/src/main/java/org/jboss/ws/tools/ant/PathWriterTask.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/tools/ant/PathWriterTask.java
(rev 0)
+++ common/trunk/src/main/java/org/jboss/ws/tools/ant/PathWriterTask.java 2008-03-14
00:36:19 UTC (rev 5971)
@@ -0,0 +1,117 @@
+/*
+ * 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.StringTokenizer;
+
+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 that writes a given path element to a file, so that
+ * it can be easily imported by other build files.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 13-Mar-2008
+ */
+public class PathWriterTask extends Task
+{
+ private String pathId;
+ private String outputFile;
+ private String variables; //to perform path substitution, i.e. jboss.home <-->
/dati/jboss-4.2.3.GA
+
+ @Override
+ public void execute() throws BuildException
+ {
+ Project project = getProject();
+ Path path = (Path)project.getReference(pathId);
+ String[] pathElements = path.list();
+ try
+ {
+ StringBuffer sb = new StringBuffer();
+ generateContent(sb, pathElements);
+ BufferedWriter out = new BufferedWriter(new FileWriter(new File(outputFile)));
+ out.write(sb.toString());
+ out.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new BuildException(e);
+ }
+ }
+
+ private void generateContent(StringBuffer sb, String[] libs)
+ {
+ sb.append("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n");
+ sb.append("<project>\n");
+ sb.append("<path id=\"");
+ sb.append(pathId);
+ sb.append("\">");
+ for (int i = 0; i < libs.length; i++)
+ {
+ sb.append("<pathelement location=\"");
+ sb.append(getPath(libs[i]));
+ sb.append("\"/>\n");
+ }
+ sb.append("</path>");
+ sb.append("</project>\n");
+ }
+
+ private String getPath(String absolutePath)
+ {
+ StringTokenizer st = new StringTokenizer(variables, ";:, ", false);
+ while (st.hasMoreTokens())
+ {
+ String v = st.nextToken();
+ String value = getProject().getProperty(v);
+ if (absolutePath.contains(value))
+ {
+ int begin = absolutePath.indexOf(value);
+ int end = begin + value.length();
+ absolutePath = absolutePath.substring(0, begin) + "${" + v +
"}" + absolutePath.substring(end);
+ }
+ }
+ return absolutePath;
+ }
+
+ public void setPathId(String pathId)
+ {
+ this.pathId = pathId;
+ }
+
+ public void setOutputFile(String outputFile)
+ {
+ this.outputFile = outputFile;
+ }
+
+ public void setVariables(String variables)
+ {
+ this.variables = variables;
+ }
+
+}
Property changes on:
common/trunk/src/main/java/org/jboss/ws/tools/ant/PathWriterTask.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF