jvanzyl 02/04/11 04:55:32
Added: src/java/org/apache/maven/ant AntUtils.java
CreateClasspath.java CreatePatternSet.java
GetList.java ListTask.java
Log:
Repackaging the simple ant tasks used in the bootstrap.
Revision Changes Path
1.1
jakarta-turbine-maven/src/java/org/apache/maven/ant/AntUtils.java
Index: AntUtils.java
===================================================================
package org.apache.maven.ant;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.PatternSet;
/**
* Ant utilities for creating paths and pattern sets from
* sets of values.
*
* @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
* @version $Id: AntUtils.java,v 1.1 2002/04/11 11:55:32 jvanzyl Exp $
*/
public class AntUtils
{
/**
* Create the classpath reference.
*/
public static void createClasspathReference(Project project,
String reference,
List list,
File baseDir)
{
Path classpath = new Path(project);
for (Iterator i = list.iterator(); i.hasNext();)
{
String jar = (String) i.next();
Path p = new Path(project);
p.setPath(new File(baseDir, jar).getAbsolutePath());
classpath.append(p);
}
project.addReference(reference, classpath);
}
/**
* Create the source directories reference.
*/
public static void createPatternSetReference(Project project,
String reference,
List list)
{
StringBuffer includesSb = new StringBuffer();
StringBuffer excludesSb = new StringBuffer();
PatternSet patternSet = new PatternSet();
for (Iterator i = list.iterator(); i.hasNext();)
{
String line = (String) i.next();
line = line.trim();
if (line.startsWith("include"))
{
// We have something like the following pattern:
// include = conf/foo.xml
includesSb.append(line.substring(line.indexOf("=")+1)).append(',');
}
else if (line.startsWith("exclude"))
{
// We have something like the following pattern:
// exclude = conf/foo.xml
excludesSb.append(line.substring(line.indexOf("=")+1)).append(',');
}
else
{
// We have a jar descriptor file
includesSb.append(line).append(',');
}
}
String includes = includesSb.toString();
String excludes = excludesSb.toString();
if (includes.length() > 0)
{
// Remove trailing comma
includes = includes.substring(0,includes.length()-1);
patternSet.setIncludes(includes);
}
if (excludes.length() > 0)
{
// Remove trailing comma
excludes = excludes.substring(0,excludes.length()-1);
patternSet.setExcludes(excludes);
}
project.addReference(reference, patternSet);
}
}
1.1
jakarta-turbine-maven/src/java/org/apache/maven/ant/CreateClasspath.java
Index: CreateClasspath.java
===================================================================
package org.apache.maven.ant;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.net.URL;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
/**
* Get a list of resources from a website.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
*/
public class CreateClasspath
extends ListTask
{
/**
* Ant project reference for the patternset.
*/
private String reference;
/**
* Base directory from which to build the classpath.
*/
private File baseDir;
/**
* Set the name of the reference.
*/
public void setReference(String reference)
{
this.reference = reference;
}
/**
* Set the name of the reference.
*/
public void setBaseDir(File baseDir)
{
this.baseDir = baseDir;
}
/**
* Does the work.
*
* @exception Exception Thrown in unrecoverable error.
*/
public void execute()
throws BuildException
{
AntUtils.createClasspathReference(project, reference,
getList(getListFile()), baseDir);
}
}
1.1
jakarta-turbine-maven/src/java/org/apache/maven/ant/CreatePatternSet.java
Index: CreatePatternSet.java
===================================================================
package org.apache.maven.ant;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.net.URL;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
/**
* Get a list of resources from a website.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
*/
public class CreatePatternSet
extends ListTask
{
/**
* Ant project reference for the patternset.
*/
private String reference;
/**
* Set the name of the reference.
*/
public void setReference(String reference)
{
this.reference = reference;
}
/**
* Does the work.
*
* @exception Exception Thrown in unrecoverable error.
*/
public void execute()
throws BuildException
{
AntUtils.createPatternSetReference(project, reference,
getList(getListFile()));
}
}
1.1 jakarta-turbine-maven/src/java/org/apache/maven/ant/GetList.java
Index: GetList.java
===================================================================
package org.apache.maven.ant;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.net.URL;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.maven.util.HttpUtils;
/**
* Get a list of resources from a website.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
*/
public class GetList
extends ListTask
{
private File dest;
private boolean verbose = false;
private boolean useTimestamp = true;
private boolean ignoreErrors = true;
private String uname = null;
private String pword = null;
private String baseUrl;
/**
* This is the directory where all the requested
* files go.
*
* @param dest Destination directory for requested files.
*/
public void setDest(File dest)
{
this.dest = dest;
}
/**
* Sets the baseUrl attribute of the Get object
*/
public void setBaseUrl(String baseUrl)
{
this.baseUrl = baseUrl;
}
/**
* Sets the proxyHost attribute of the Get object
*/
public void setProxyHost(String proxyHost)
{
System.getProperties().put("proxySet", "true");
System.getProperties().put("proxyHost", proxyHost);
}
/**
* Sets the proxyPort attribute of the Get object
*/
public void setProxyPort(String proxyPort)
{
System.getProperties().put("proxyPort", proxyPort);
}
/**
* Does the work.
*
* @exception Exception Thrown in unrecoverable error.
*/
public void execute()
throws BuildException
{
if (baseUrl == null)
{
throw new BuildException("baseUrl attribute is required");
}
if (dest == null)
{
throw new BuildException("dest attribute is required");
}
if (dest.exists() && !dest.canWrite())
{
throw new BuildException("Can't write to " + dest.getAbsolutePath());
}
for (Iterator j = getList(getListFile()).iterator(); j.hasNext(); )
{
try
{
String file = (String) j.next();
File destinationFile = new File(dest, file);
URL source = new URL(baseUrl + file);
HttpUtils.getFile(source, destinationFile, file, verbose,
ignoreErrors,useTimestamp,uname,pword);
}
catch (Exception e)
{
throw new BuildException(e);
}
}
}
/**
* Be verbose, if set to "<CODE>true</CODE>".
*
* @param v if "true" then be verbose
*/
public void setVerbose(boolean v)
{
verbose = v;
}
/**
* Don't stop if get fails if set to "<CODE>true</CODE>".
*
* @param v if "true" then don't report download errors up to ant
*/
public void setIgnoreErrors(boolean v)
{
ignoreErrors = v;
}
/**
* Use timestamps, if set to "<CODE>true</CODE>". <p>
*
* In this situation, the if-modified-since header is set so that the file
* is only fetched if it is newer than the local file (or there is no local
* file) This flag is only valid on HTTP connections, it is ignored in other
* cases. When the flag is set, the local copy of the downloaded file will
* also have its timestamp set to the remote file time. <br>
* Note that remote files of date 1/1/1970 (GMT) are treated as 'no
* timestamp', and web servers often serve files with a timestamp in the
* future by replacing their timestamp with that of the current time. Also,
* inter-computer clock differences can cause no end of grief.
*
* @param v "true" to enable file time fetching
*/
public void setUseTimestamp(boolean v)
{
useTimestamp = v;
}
/**
* Username for basic auth.
*
* @param u username for authentication
*/
public void setUsername(String u)
{
this.uname = u;
}
/**
* password for the basic auth.
*
* @param p password for authentication
*/
public void setPassword(String p)
{
this.pword = p;
}
}
1.1
jakarta-turbine-maven/src/java/org/apache/maven/ant/ListTask.java
Index: ListTask.java
===================================================================
package org.apache.maven.ant;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
/**
* Get a list of resources from a website.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
*/
public abstract class ListTask
extends Task
{
/**
* The file containing the list of values to process.
*/
private File listFile;
/**
* Set the list of values to process.
*/
public void setListFile(File listFile)
{
this.listFile = listFile;
}
/**
* Get the list of values to process.
*/
public File getListFile()
{
return listFile;
}
/**
* Does the work.
*
* @exception Exception Thrown in unrecoverable error.
*/
public abstract void execute() throws BuildException;
/**
* Read the file that contains the list of values into
* a List.
*/
public static List getList(File f)
{
List list = new ArrayList();
String line;
try
{
BufferedReader in = new BufferedReader(new FileReader(f));
while ((line=in.readLine()) != null)
{
line = line.trim();
// Allow comments to be placed in the payload
// descriptor.
if (line.startsWith("#") || line.startsWith("--") || line.length() <
1)
{
continue;
}
list.add(line);
}
}
catch (Exception e)
{
}
return list;
}
// We need to move to the commons-logging goodies here.
protected static void logx(String message)
{
System.out.println(message);
}
}