git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271991 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,46 +0,0 @@ | |||||
| /* Copyright (c) 2000 The Apache Software Foundation */ | |||||
| package org.apache.tools.ant.tasks; | |||||
| import java.io.*; | |||||
| import org.apache.tools.ant.*; | |||||
| public class Copy extends Task { | |||||
| private String src; | |||||
| private String dest; | |||||
| public void execute() throws BuildException { | |||||
| try { | |||||
| FileInputStream in = new FileInputStream(src); | |||||
| FileOutputStream out = new FileOutputStream(dest); | |||||
| byte[] buf = new byte[4096]; | |||||
| int len = 0; | |||||
| while ((len = in.read(buf)) != -1) { | |||||
| out.write(buf, 0, len); | |||||
| } | |||||
| } | |||||
| catch(FileNotFoundException exc) { | |||||
| throw new BuildException("File not found"); | |||||
| } | |||||
| catch(IOException exc) { | |||||
| throw new AntException("Error copying files", exc); | |||||
| } | |||||
| } | |||||
| public String getSrc() { | |||||
| return src; | |||||
| } | |||||
| public void setSrc(String src) { | |||||
| this.src = src; | |||||
| } | |||||
| public String getDest() { | |||||
| return dest; | |||||
| } | |||||
| public void setDest(String dest) { | |||||
| this.dest = dest; | |||||
| } | |||||
| } | |||||
| @@ -1,21 +0,0 @@ | |||||
| /* Copyright (c) 2000 The Apache Software Foundation */ | |||||
| package org.apache.tools.ant.tasks; | |||||
| import org.apache.tools.ant.*; | |||||
| public class Echo extends Task { | |||||
| private String message; | |||||
| public void execute() throws BuildException { | |||||
| System.out.println(message); | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| public void setMessage(String message) { | |||||
| this.message = message; | |||||
| } | |||||
| } | |||||
| @@ -1,43 +0,0 @@ | |||||
| /* Copyright (c) 2000 The Apache Software Foundation */ | |||||
| package org.apache.tools.ant.tasks; | |||||
| import java.io.*; | |||||
| import java.util.*; | |||||
| import org.apache.tools.ant.*; | |||||
| public class Fileset { | |||||
| private String src; | |||||
| public String getSrc() { | |||||
| return src; | |||||
| } | |||||
| public void setSrc(String src) { | |||||
| this.src = src; | |||||
| } | |||||
| public void getFiles(List results) throws BuildException { | |||||
| if (src == null) { | |||||
| throw new BuildException("Missing property \"src\"", null); //LOCATION | |||||
| } | |||||
| File dir = new File(src); | |||||
| if (!dir.exists()) { | |||||
| throw new BuildException(src + " does not exist", null); // LOCATION!!! | |||||
| } | |||||
| getFiles(dir, results); | |||||
| } | |||||
| private void getFiles(File file, List results) { | |||||
| if (file.isDirectory()) { | |||||
| File[] files = file.listFiles(); | |||||
| for (int i = 0; i < files.length; i++) { | |||||
| getFiles(files[i], results); | |||||
| } | |||||
| } | |||||
| else if (file.getPath().endsWith(".java")) { | |||||
| results.add(file.getPath()); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,85 +0,0 @@ | |||||
| /* Copyright (c) 2000 The Apache Software Foundation */ | |||||
| package org.apache.tools.ant.tasks; | |||||
| import java.io.*; | |||||
| import java.lang.reflect.*; | |||||
| import java.util.*; | |||||
| import org.apache.tools.ant.*; | |||||
| public class Jar extends Task { | |||||
| private String jarfile; | |||||
| private String basedir; | |||||
| private String manifest; | |||||
| public String getJarfile() { | |||||
| return jarfile; | |||||
| } | |||||
| public void setJarfile(String jarfile) { | |||||
| this.jarfile = jarfile; | |||||
| } | |||||
| public String getBasedir() { | |||||
| return basedir; | |||||
| } | |||||
| public void setBasedir(String basedir) { | |||||
| this.basedir = basedir; | |||||
| } | |||||
| public String getManifest() { | |||||
| return manifest; | |||||
| } | |||||
| public void setManifest(String manifest) { | |||||
| this.manifest = manifest; | |||||
| } | |||||
| public void execute() throws BuildException { | |||||
| File dir = new File(jarfile).getParentFile(); | |||||
| if (dir != null) { | |||||
| dir.mkdirs(); | |||||
| } | |||||
| List argList = new ArrayList(); | |||||
| if (manifest == null) { | |||||
| argList.add("-cf"); | |||||
| } | |||||
| else { | |||||
| argList.add("-cmf"); | |||||
| argList.add(manifest); | |||||
| } | |||||
| argList.add(jarfile); | |||||
| argList.add("-C"); | |||||
| argList.add(basedir); | |||||
| argList.add("."); | |||||
| String[] args = (String[]) argList.toArray(new String[argList.size()]); | |||||
| try { | |||||
| Class type = getClass().getClassLoader().loadClass("sun.tools.jar.Main"); | |||||
| Method method = type.getMethod("main", new Class[] { args.getClass() }); | |||||
| getWorkspace().info("Running jar..."); | |||||
| method.invoke(null, new Object[] { args }); | |||||
| } | |||||
| catch(InvocationTargetException exc) { | |||||
| Throwable cause = exc.getTargetException(); | |||||
| if (cause instanceof ExitException) { | |||||
| if (((ExitException)cause).getStatus() != 0) { | |||||
| throw new BuildException("Build failed"); | |||||
| } | |||||
| } | |||||
| else { | |||||
| throw new AntException("Error running jar", exc); | |||||
| } | |||||
| } | |||||
| catch(ClassNotFoundException exc) { | |||||
| throw new AntException("Jar class not found. Makes sure tools.jar is in your classpath"); | |||||
| } | |||||
| catch(Exception exc) { | |||||
| throw new AntException("Error running jar", exc); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,93 +0,0 @@ | |||||
| /* Copyright (c) 2000 The Apache Software Foundation */ | |||||
| package org.apache.tools.ant.tasks; | |||||
| import java.lang.reflect.*; | |||||
| import java.io.*; | |||||
| import java.util.*; | |||||
| import org.apache.tools.ant.*; | |||||
| public class Javac extends Task { | |||||
| private Fileset[] fileset; | |||||
| private String dest; | |||||
| private String classpath; | |||||
| private String compilerclass = null; | |||||
| public void execute() throws BuildException { | |||||
| if (compilerclass == null) { | |||||
| compilerclass = "com.sun.tools.javac.Main"; | |||||
| } | |||||
| List argList = new ArrayList(); | |||||
| argList.add("-d"); | |||||
| argList.add(dest); | |||||
| if (classpath != null) { | |||||
| argList.add("-classpath"); | |||||
| // Replace the project's path separator with the system's path separator | |||||
| argList.add(classpath.replace(getProject().getPathSeparator(), File.pathSeparatorChar)); | |||||
| } | |||||
| for (int i = 0; i < fileset.length; i++) { | |||||
| fileset[i].getFiles(argList); | |||||
| } | |||||
| String[] args = (String[]) argList.toArray(new String[argList.size()]); | |||||
| try { | |||||
| new File(dest).mkdirs(); | |||||
| Class type = getClass().getClassLoader().loadClass(compilerclass); | |||||
| Method method = type.getMethod("main", new Class[] { args.getClass() }); | |||||
| getWorkspace().info("Running javac..."); | |||||
| method.invoke(null, new Object[] { args }); | |||||
| } | |||||
| catch(InvocationTargetException exc) { | |||||
| Throwable cause = exc.getTargetException(); | |||||
| if (cause instanceof ExitException) { | |||||
| if (((ExitException)cause).getStatus() != 0) { | |||||
| throw new BuildException("Compile failed"); | |||||
| } | |||||
| } | |||||
| else { | |||||
| throw new AntException("Error running compiler", exc); | |||||
| } | |||||
| } | |||||
| catch(ClassNotFoundException exc) { | |||||
| throw new BuildException("Compiler class not found. Makes sure tools.jar is in your classpath"); | |||||
| } | |||||
| catch(IllegalAccessException exc) { | |||||
| throw new AntException("Unable to access compiler class", exc); | |||||
| } | |||||
| catch(NoSuchMethodException exc) { | |||||
| throw new AntException("Unable to find main method on compiler class", exc); | |||||
| } | |||||
| } | |||||
| public String getDest() { | |||||
| return dest; | |||||
| } | |||||
| public void setDest(String dest) { | |||||
| this.dest = dest; | |||||
| } | |||||
| public String getClasspath() { | |||||
| return classpath; | |||||
| } | |||||
| public void setClasspath(String classpath) { | |||||
| this.classpath = classpath; | |||||
| } | |||||
| public Fileset[] getFileset() { | |||||
| return fileset; | |||||
| } | |||||
| public void setFileset(Fileset[] fileset) { | |||||
| this.fileset = fileset; | |||||
| } | |||||
| } | |||||
| @@ -1,31 +0,0 @@ | |||||
| /* Copyright (c) 2000 The Apache Software Foundation */ | |||||
| package org.apache.tools.ant.tasks; | |||||
| import java.io.*; | |||||
| import java.net.*; | |||||
| import org.apache.tools.ant.*; | |||||
| public class JavacLoader extends Task { | |||||
| public void execute() throws BuildException { | |||||
| try { | |||||
| URL toolsJar = findToolsJar(); | |||||
| ClassLoader loader = new URLClassLoader( | |||||
| new URL[] { getProject().getBase(), toolsJar }, | |||||
| getWorkspace().getClass().getClassLoader()); | |||||
| getWorkspace().registerTask("javac", loader.loadClass("org.apache.tools.ant.tasks.Javac")); | |||||
| } | |||||
| catch(MalformedURLException exc) { | |||||
| throw new AntException("Bad URL", exc); | |||||
| } | |||||
| catch(ClassNotFoundException exc) { | |||||
| throw new BuildException("Class not found"); | |||||
| } | |||||
| } | |||||
| private URL findToolsJar() throws MalformedURLException { | |||||
| // I assume this won't work everywhere... | |||||
| return new File(new File(System.getProperty("java.home")), "../lib/tools.jar").toURL(); | |||||
| } | |||||
| } | |||||
| @@ -1,30 +0,0 @@ | |||||
| /* Copyright (c) 2000 The Apache Software Foundation */ | |||||
| package org.apache.tools.ant.tasks; | |||||
| import org.apache.tools.ant.*; | |||||
| public class SetVariable extends Task { | |||||
| private String name; | |||||
| private String value; | |||||
| public void execute() throws BuildException { | |||||
| getProject().setVariable(name, value); | |||||
| } | |||||
| public void setName(String name) { | |||||
| this.name = name; | |||||
| } | |||||
| public String getName() { | |||||
| return name; | |||||
| } | |||||
| public void setValue(String value) { | |||||
| this.value = value; | |||||
| } | |||||
| public String getValue() { | |||||
| return value; | |||||
| } | |||||
| } | |||||