Browse Source

Added nested elements and attributes to reference CLASSPATH structures

defined at another place in the same project.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267896 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
c32873b519
5 changed files with 248 additions and 22 deletions
  1. +47
    -3
      src/main/org/apache/tools/ant/taskdefs/Java.java
  2. +60
    -3
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  3. +105
    -8
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  4. +36
    -7
      src/main/org/apache/tools/ant/taskdefs/Rmic.java
  5. +0
    -1
      src/main/org/apache/tools/ant/types/Commandline.java

+ 47
- 3
src/main/org/apache/tools/ant/taskdefs/Java.java View File

@@ -61,6 +61,7 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;


import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -79,6 +80,7 @@ public class Java extends Task {
private boolean fork = false; private boolean fork = false;
private File dir = null; private File dir = null;
private boolean failOnError = false; private boolean failOnError = false;
private Vector classpathReferences = new Vector();
/** /**
* Do the execution. * Do the execution.
@@ -137,6 +139,22 @@ public class Java extends Task {
return cmdl.createClasspath(project); return cmdl.createClasspath(project);
} }


/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void addClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void setClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

/** /**
* Set the class name. * Set the class name.
*/ */
@@ -218,7 +236,10 @@ public class Java extends Task {
private void run(CommandlineJava command) throws BuildException { private void run(CommandlineJava command) throws BuildException {
ExecuteJava exe = new ExecuteJava(); ExecuteJava exe = new ExecuteJava();
exe.setJavaCommand(command.getJavaCommand()); exe.setJavaCommand(command.getJavaCommand());
exe.setClasspath(command.getClasspath());
Path p = new Path(project);
p.append(command.getClasspath());
addReferencesToPath(classpathReferences, p);
exe.setClasspath(p);
exe.execute(project); exe.execute(project);
} }


@@ -252,10 +273,33 @@ public class Java extends Task {
for (int i=0; i<args.size(); i++) { for (int i=0; i<args.size(); i++) {
cmdj.createArgument().setValue((String) args.elementAt(i)); cmdj.createArgument().setValue((String) args.elementAt(i));
} }
if (cmdl.getClasspath() != null) {
cmdj.createClasspath(project).append(cmdl.getClasspath());
if (cmdl.getClasspath() != null || classpathReferences.size() > 0) {
Path p = cmdj.createClasspath(project);
if (cmdl.getClasspath() != null) {
p.append(cmdl.getClasspath());
}
addReferencesToPath(classpathReferences, p);
} }
run(cmdj); run(cmdj);
} }


/**
* Appends the referenced Path instances to the other path.
*
* @param v Vector of Reference objects referring to Path objects.
* @param p Path to append to.
*/
private void addReferencesToPath(Vector v, Path p) {
for (int i=0; i<v.size(); i++) {
Reference r = (Reference) v.elementAt(i);
Object o = r.getReferencedObject(project);
if (o instanceof Path) {
p.append((Path) o);
} else {
String msg = r.getRefId()+" doesn\'t denote a classpath";
throw new BuildException(msg, location);
}
}
}
} }

+ 60
- 3
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -100,11 +100,13 @@ public class Javac extends MatchingTask {
private Path src; private Path src;
private File destDir; private File destDir;
private Path compileClasspath; private Path compileClasspath;
private Vector classpathReferences = new Vector();
private boolean debug = false; private boolean debug = false;
private boolean optimize = false; private boolean optimize = false;
private boolean deprecation = false; private boolean deprecation = false;
private String target; private String target;
private Path bootclasspath; private Path bootclasspath;
private Vector bootClasspathReferences = new Vector();
private Path extdirs; private Path extdirs;
private static String lSep = System.getProperty("line.separator"); private static String lSep = System.getProperty("line.separator");


@@ -163,6 +165,22 @@ public class Javac extends MatchingTask {
return compileClasspath; return compileClasspath;
} }


/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void addClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void setClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

/** /**
* Sets the bootclasspath that will be used to compile the classes * Sets the bootclasspath that will be used to compile the classes
* against. * against.
@@ -185,6 +203,22 @@ public class Javac extends MatchingTask {
return bootclasspath; return bootclasspath;
} }


/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void addBootClasspathRef(Reference r) {
bootClasspathReferences.addElement(r);
}

/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void setBootClasspathRef(Reference r) {
bootClasspathReferences.addElement(r);
}

/** /**
* Sets the extension directories that will be used during the * Sets the extension directories that will be used during the
* compilation. * compilation.
@@ -355,6 +389,7 @@ public class Javac extends MatchingTask {
if (compileClasspath != null) { if (compileClasspath != null) {
addExistingToClasspath(classpath,compileClasspath); addExistingToClasspath(classpath,compileClasspath);
} }
addReferencesToPath(classpathReferences, classpath);


// add the system classpath // add the system classpath


@@ -505,7 +540,8 @@ public class Javac extends MatchingTask {
if (optimize) { if (optimize) {
cmd.createArgument().setValue("-O"); cmd.createArgument().setValue("-O");
} }
if (bootclasspath != null) {
if (bootclasspath != null || bootClasspathReferences.size() > 0) {
addReferencesToPath(bootClasspathReferences, createBootclasspath());
cmd.createArgument().setValue("-bootclasspath"); cmd.createArgument().setValue("-bootclasspath");
cmd.createArgument().setPath(bootclasspath); cmd.createArgument().setPath(bootclasspath);
} }
@@ -559,7 +595,8 @@ public class Javac extends MatchingTask {


// Jikes doesn't support bootclasspath dir (-bootclasspath) // Jikes doesn't support bootclasspath dir (-bootclasspath)
// so we'll emulate it for compatibility and convenience. // so we'll emulate it for compatibility and convenience.
if (bootclasspath != null) {
if (bootclasspath != null || bootClasspathReferences.size() > 0) {
addReferencesToPath(bootClasspathReferences, createBootclasspath());
classpath.append(bootclasspath); classpath.append(bootclasspath);
} }


@@ -713,7 +750,7 @@ public class Javac extends MatchingTask {


/** /**
* Emulation of extdirs feature in java >= 1.2. * Emulation of extdirs feature in java >= 1.2.
* This method adds all file in the given
* This method adds all files in the given
* directories (but not in sub-directories!) to the classpath, * directories (but not in sub-directories!) to the classpath,
* so that you don't have to specify them all one by one. * so that you don't have to specify them all one by one.
* @param classpath - Path to append files to * @param classpath - Path to append files to
@@ -740,5 +777,25 @@ public class Javac extends MatchingTask {
classpath.addFileset(fs); classpath.addFileset(fs);
} }
} }

/**
* Appends the referenced Path instances to the other path.
*
* @param v Vector of Reference objects referring to Path objects.
* @param p Path to append to.
*/
private void addReferencesToPath(Vector v, Path p) {
for (int i=0; i<v.size(); i++) {
Reference r = (Reference) v.elementAt(i);
Object o = r.getReferencedObject(project);
if (o instanceof Path) {
p.append((Path) o);
} else {
String msg = r.getRefId()+" doesn\'t denote a classpath";
throw new BuildException(msg, location);
}
}
}
} }



+ 105
- 8
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -60,6 +60,7 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;


import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
@@ -119,7 +120,8 @@ public class Javadoc extends Task {
private Path path; private Path path;
private Vector params = new Vector(); private Vector params = new Vector();
private Vector pathRefs = new Vector();

public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
@@ -137,6 +139,7 @@ public class Javadoc extends Task {
} }


public Path getPath() { public Path getPath() {
addReferencesToPath(pathRefs, path);
return path; return path;
} }
@@ -147,6 +150,22 @@ public class Javadoc extends Task {
return path; return path;
} }


/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <pathref> element.
*/
public void addPathRef(Reference r) {
pathRefs.addElement(r);
}

/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <pathref> element.
*/
public void setPathRef(Reference r) {
pathRefs.addElement(r);
}

public DocletParam createParam() { public DocletParam createParam() {
DocletParam param = new DocletParam(); DocletParam param = new DocletParam();
params.addElement(param); params.addElement(param);
@@ -196,7 +215,9 @@ public class Javadoc extends Task {
private String packageList = null; private String packageList = null;
private Vector links = new Vector(2); private Vector links = new Vector(2);
private Vector groups = new Vector(2); private Vector groups = new Vector(2);

private Vector classpathReferences = new Vector();
private Vector bootClasspathReferences = new Vector();
private Vector sourcepathReferences = new Vector();


public void setMaxmemory(String max){ public void setMaxmemory(String max){
if(javadoc1){ if(javadoc1){
@@ -223,6 +244,22 @@ public class Javadoc extends Task {
} }
return sourcePath; return sourcePath;
} }
/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <sourcepathref> element.
*/
public void addSourcepathRef(Reference r) {
sourcepathReferences.addElement(r);
}

/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <sourcepathref> element.
*/
public void setSourcepathRef(Reference r) {
sourcepathReferences.addElement(r);
}

public void setDestdir(File dir) { public void setDestdir(File dir) {
cmd.createArgument().setValue("-d"); cmd.createArgument().setValue("-d");
cmd.createArgument().setFile(dir); cmd.createArgument().setFile(dir);
@@ -266,6 +303,13 @@ public class Javadoc extends Task {
doclet.setPath(src); doclet.setPath(src);
} }


public void setDocletPathRef(Reference r) {
if (doclet == null) {
doclet = new DocletInfo();
}
doclet.setPathRef(r);
}

public DocletInfo createDoclet() { public DocletInfo createDoclet() {
doclet = new DocletInfo(); doclet = new DocletInfo();
return doclet; return doclet;
@@ -287,6 +331,22 @@ public class Javadoc extends Task {
} }
return classpath; return classpath;
} }
/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void addClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void setClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

public void setBootclasspath(Path src) { public void setBootclasspath(Path src) {
if (bootclasspath == null) { if (bootclasspath == null) {
bootclasspath = src; bootclasspath = src;
@@ -300,6 +360,22 @@ public class Javadoc extends Task {
} }
return bootclasspath; return bootclasspath;
} }
/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <bootclasspathref> element.
*/
public void addBootClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <bootclasspathref> element.
*/
public void setBootClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

public void setExtdirs(String src) { public void setExtdirs(String src) {
if (!javadoc1) { if (!javadoc1) {
cmd.createArgument().setValue("-extdirs"); cmd.createArgument().setValue("-extdirs");
@@ -522,14 +598,14 @@ public class Javadoc extends Task {
if (classpath == null) if (classpath == null)
classpath = Path.systemClasspath; classpath = Path.systemClasspath;


addReferencesToPath(classpathReferences, classpath);
addReferencesToPath(sourcepathReferences, sourcePath);


if ( (!javadoc1) || (sourcePath == null) ) {
if (!javadoc1) {
cmd.createArgument().setValue("-classpath"); cmd.createArgument().setValue("-classpath");
cmd.createArgument().setPath(classpath); cmd.createArgument().setPath(classpath);
if (sourcePath != null) {
cmd.createArgument().setValue("-sourcepath");
cmd.createArgument().setPath(sourcePath);
}
cmd.createArgument().setValue("-sourcepath");
cmd.createArgument().setPath(sourcePath);
} else { } else {
cmd.createArgument().setValue("-classpath"); cmd.createArgument().setValue("-classpath");
cmd.createArgument().setValue(sourcePath.toString() + cmd.createArgument().setValue(sourcePath.toString() +
@@ -570,7 +646,9 @@ public class Javadoc extends Task {
} }
} }
} }
if (bootclasspath != null) {
if (bootclasspath != null || bootClasspathReferences.size() > 0) {
addReferencesToPath(bootClasspathReferences,
createBootclasspath());
cmd.createArgument().setValue("-bootclasspath"); cmd.createArgument().setValue("-bootclasspath");
cmd.createArgument().setPath(bootclasspath); cmd.createArgument().setPath(bootclasspath);
} }
@@ -694,6 +772,25 @@ public class Javadoc extends Task {
} }
} }


/**
* Appends the referenced Path instances to the other path.
*
* @param v Vector of Reference objects referring to Path objects.
* @param p Path to append to.
*/
private void addReferencesToPath(Vector v, Path p) {
for (int i=0; i<v.size(); i++) {
Reference r = (Reference) v.elementAt(i);
Object o = r.getReferencedObject(project);
if (o instanceof Path) {
p.append((Path) o);
} else {
String msg = r.getRefId()+" doesn\'t denote a classpath";
throw new BuildException(msg, location);
}
}
}
/** /**
* Given a source path, a list of package patterns, fill the given list * Given a source path, a list of package patterns, fill the given list
* with the packages found in that path subdirs matching one of the given * with the packages found in that path subdirs matching one of the given


+ 36
- 7
src/main/org/apache/tools/ant/taskdefs/Rmic.java View File

@@ -58,6 +58,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;


import java.io.*; import java.io.*;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@@ -96,6 +97,7 @@ public class Rmic extends MatchingTask {
private boolean filtering = false; private boolean filtering = false;


private Vector compileList = new Vector(); private Vector compileList = new Vector();
private Vector classpathReferences = new Vector();


public void setBase(String base) { public void setBase(String base) {
this.base = base; this.base = base;
@@ -136,7 +138,7 @@ public class Rmic extends MatchingTask {
} }


/** /**
* Maybe creates a nesetd classpath element.
* Maybe creates a nested classpath element.
*/ */
public Path createClasspath() { public Path createClasspath() {
if (compileClasspath == null) { if (compileClasspath == null) {
@@ -145,11 +147,26 @@ public class Rmic extends MatchingTask {
return compileClasspath; return compileClasspath;
} }


/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void addClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void setClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

/** /**
* Indicates that the classes found by the directory match should be * Indicates that the classes found by the directory match should be
* checked to see if they implement java.rmi.Remote. * checked to see if they implement java.rmi.Remote.
* This defaults to false if not set.
*/
* This defaults to false if not set. */
public void setVerify(String verify) { public void setVerify(String verify) {
this.verify = Project.toBoolean(verify); this.verify = Project.toBoolean(verify);
} }
@@ -170,7 +187,19 @@ public class Rmic extends MatchingTask {
if (null != sourceBase) { if (null != sourceBase) {
sourceBaseFile = project.resolveFile(sourceBase); sourceBaseFile = project.resolveFile(sourceBase);
} }
String classpath = getCompileClasspath(baseDir);
Path classpath = getCompileClasspath(baseDir);

for (int i=0; i<classpathReferences.size(); i++) {
Reference r = (Reference) classpathReferences.elementAt(i);
Object o = r.getReferencedObject(project);
if (o instanceof Path) {
classpath.append((Path) o);
} else {
String msg = r.getRefId()+" doesn\'t denote a classpath";
throw new BuildException(msg, location);
}
}


// scan base dirs to build up compile lists only if a // scan base dirs to build up compile lists only if a
// specific classname is not given // specific classname is not given
@@ -193,7 +222,7 @@ public class Rmic extends MatchingTask {
args[i++] = "-d"; args[i++] = "-d";
args[i++] = baseDir.getAbsolutePath(); args[i++] = baseDir.getAbsolutePath();
args[i++] = "-classpath"; args[i++] = "-classpath";
args[i++] = classpath;
args[i++] = classpath.toString();
if (null != stubVersion) { if (null != stubVersion) {
if ("1.1".equals(stubVersion)) if ("1.1".equals(stubVersion))
args[i++] = "-v1.1"; args[i++] = "-v1.1";
@@ -369,7 +398,7 @@ public class Rmic extends MatchingTask {
// XXX // XXX
// we need a way to not use the current classpath. // we need a way to not use the current classpath.


private String getCompileClasspath(File baseFile) {
private Path getCompileClasspath(File baseFile) {
// add dest dir to classpath so that previously compiled and // add dest dir to classpath so that previously compiled and
// untouched classes are on classpath // untouched classes are on classpath
Path classpath = new Path(project, baseFile.getAbsolutePath()); Path classpath = new Path(project, baseFile.getAbsolutePath());
@@ -390,7 +419,7 @@ public class Rmic extends MatchingTask {
addExistingToClasspath(classpath, new Path(project, bootcp)); addExistingToClasspath(classpath, new Path(project, bootcp));
} }
} }
return classpath.toString();
return classpath;
} }


/** /**


+ 0
- 1
src/main/org/apache/tools/ant/types/Commandline.java View File

@@ -108,7 +108,6 @@ public class Commandline {
public class Argument { public class Argument {


private String[] parts; private String[] parts;
private Reference pathRef;


/** /**
* Sets a single commandline argument. * Sets a single commandline argument.


Loading…
Cancel
Save