diff options
author | wisberg <wisberg> | 2003-10-01 05:24:04 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2003-10-01 05:24:04 +0000 |
commit | 83b5e4a3a53ef41d14c2e565bdcc742a363ab2f5 (patch) | |
tree | 97cf41c6dd6d37ab11b2383d1868d37624c241b3 /taskdefs | |
parent | e0c8a4875c23cc2443bd309658d8dab3e1f7d070 (diff) | |
download | aspectj-83b5e4a3a53ef41d14c2e565bdcc742a363ab2f5.tar.gz aspectj-83b5e4a3a53ef41d14c2e565bdcc742a363ab2f5.zip |
- fix for bugs disclosed by fixes for bug 40807
- added xweavedir attribute for weaving from and to
a directory of classes
Diffstat (limited to 'taskdefs')
-rw-r--r-- | taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapter.java | 129 | ||||
-rw-r--r-- | taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java | 87 |
2 files changed, 130 insertions, 86 deletions
diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapter.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapter.java index 77f0afced..bd594c369 100644 --- a/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapter.java +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapter.java @@ -10,7 +10,6 @@ * Wes Isberg initial implementation * ******************************************************************/ - package org.aspectj.tools.ant.taskdefs; import org.apache.tools.ant.BuildException; @@ -34,15 +33,12 @@ import java.io.IOException; * requires all the files every time. To work around this, * set the global property CLEAN ("build.compiler.clean") to delete * all .class files in the destination directory before compiling. - * This clean process only permits one compile process at a time - * for each destination directory because it tracks recursion by - * writing a tag file to the destination directory. * * <p><u>Warnings</u>: * <ol> * <li>cleaning will not work if no destination directory - * is specified in the javac task - * (because we don't know where to put the tag file).</li> + * is specified in the javac task. + * (RFE: find and kill .class files in source dirs?)</li> * <li>cleaning will makes stepwise build processes fail * if they depend on the results of the prior compilation being * in the same directory, since this deletes <strong>all</strong> @@ -56,108 +52,81 @@ import java.io.IOException; * @since AspectJ 1.1, Ant 1.5.1 */ public class Ajc11CompilerAdapter implements CompilerAdapter { + /** * Define this system/project property to signal that the * destination directory should be cleaned * and javac reinvoked * to get the complete list of files every time. - */ + */ public static final String CLEAN = "build.compiler.clean"; - + + /** track whether we re-called <code>javac.execute()</code> */ + private static final ThreadLocal inSelfCall = new ThreadLocal() { + public Object initialValue() { + return Boolean.FALSE; + } + }; + Javac javac; - + public void setJavac(Javac javac) { this.javac = javac; + javac.setTaskName(javac.getTaskName() + " - ajc"); } - + public boolean execute() throws BuildException { - checkJavac(); - if (recurse()) { - javac.execute(); // re-invokes us after recalculating file list - } else { + if (null == javac) { + throw new IllegalStateException("null javac"); + } + if (!((Boolean) inSelfCall.get()).booleanValue() + && afterCleaningDirs()) { + // if we are not re-calling ourself and we cleaned dirs, + // then re-call javac to get the list of all source files. + inSelfCall.set(Boolean.TRUE); + javac.execute(); + // javac re-invokes us after recalculating file list + } else { try { AjcTask ajc = new AjcTask(); String err = ajc.setupAjc(javac); if (null != err) { throw new BuildException(err, javac.getLocation()); } - ajc.execute(); // handles BuildException for failonerror, etc. + ajc.execute(); + // handles BuildException for failonerror, etc. } finally { - doneRecursing(); + inSelfCall.set(Boolean.FALSE); } } return true; } - /** @throws IllegalStateException if javac is not defined */ - protected void checkJavac() { - if (null == javac) { - throw new IllegalStateException("null javac"); - } - } - /** - * Get javac dest dir. - * @param client the String label for the client seeking the directory - * (only used in throwing BuildException) - * @return File dest dir - * @throws BuildException if not specified and required + * If destDir exists and property CLEAN is set, + * this cleans out the dest dir of any .class files, + * and returns true to signal a recursive call. + * @return true if destDir was cleaned. */ - protected File getDestDir(String client) { - checkJavac(); - File destDir = javac.getDestdir(); - if (null == destDir) { - throw new BuildException("require destDir for " + client); - } - return destDir; - } - - protected File getTagFile() { - return new File(getDestDir("getting tag file directory"), - "Ajc11CompilerAdapter.tag"); - } - - /** - * If property CLEAN is set, then this - * cleans out the dest dir of any .class files, - * installs a tag file, and returns true to signal a recursive call. - * That means this returns false if CLEAN is not set - * or if the tag file already exists (i.e., already recursing). - * The result is that javac is re-invoked after the dest dir - * is cleaned, so it picks up all the correct source files. - * (This is a costly hack to work around Javac's forcing the - * pruning of the file list.) - * @return true if javac should be re-invoked. - */ - protected boolean recurse() { - checkJavac(); - String cleanDirs = javac.getProject().getProperty(CLEAN); - if (null == cleanDirs) { - return false; - } - File destDir = getDestDir("recursing to clean"); - File tagFile = getTagFile(); - if (tagFile.exists()) { + private boolean afterCleaningDirs() { + String clean = javac.getProject().getProperty(CLEAN); + if (null == clean) { return false; } - try { - javac.log(CLEAN + " cleaning .class files from " + destDir, - Project.MSG_VERBOSE); - FileUtil.deleteContents(destDir, FileUtil.DIRS_AND_WRITABLE_CLASSES, true); - FileWriter fw = new FileWriter(tagFile); - fw.write("Ajc11CompilerAdapter.recursing"); - fw.close(); - return true; - } catch (IOException e) { + File destDir = javac.getDestdir(); + if (null == destDir) { + javac.log( + CLEAN + " specified, but no dest dir to clean", + Project.MSG_WARN); return false; } - } - - protected void doneRecursing() { - File tagFile = getTagFile(); - if (tagFile.exists()) { - tagFile.delete(); - } + javac.log( + CLEAN + " cleaning .class files from " + destDir, + Project.MSG_VERBOSE); + FileUtil.deleteContents( + destDir, + FileUtil.DIRS_AND_WRITABLE_CLASSES, + true); + return true; } } - diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java index 7237a8a85..c8eb47cbe 100644 --- a/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java @@ -130,6 +130,9 @@ public class AjcTask extends MatchingTask { File javacDestDir = javac.getDestdir(); if (null != javacDestDir) { ajc.setDestdir(javacDestDir); + // filter requires dest dir + // mimic Javac task's behavior in copying resources, + ajc.setSourceRootCopyFilter("**/CVS/*,**/*.java,**/*.aj"); } ajc.setBootclasspath(javac.getBootclasspath()); ajc.setExtdirs(javac.getExtdirs()); @@ -137,8 +140,6 @@ public class AjcTask extends MatchingTask { // ignore srcDir -- all files picked up in recalculated file list // ajc.setSrcDir(javac.getSrcdir()); ajc.addFiles(javac.getFileList()); - // mimic Javac task's behavior in copying resources, - ajc.setSourceRootCopyFilter("**/CVS/*,**/*.java,**/*.aj"); // arguments can override the filter, add to paths, override options ajc.readArguments(javac.getCurrentCompilerArgs()); @@ -299,6 +300,7 @@ public class AjcTask extends MatchingTask { private Path argfiles; private List ignored; private Path sourceRoots; + private File xweaveDir; // ----- added by adapter - integrate better? private List /* File */ adapterFiles; private String[] adapterArguments; @@ -381,6 +383,7 @@ public class AjcTask extends MatchingTask { srcdir = null; tmpOutjar = null; verbose = false; + xweaveDir = null; } protected void ignore(String ignored) { @@ -542,6 +545,13 @@ public class AjcTask extends MatchingTask { this.failonerror = failonerror; } + /** + * @return true if fork was set + */ + public boolean isForked() { + return fork; + } + public void setFork(boolean fork) { this.fork = fork; } @@ -749,7 +759,14 @@ public class AjcTask extends MatchingTask { } return sourceRoots.createPath(); } - + + public void setXWeaveDir(File file) { + if ((null != file) && file.isDirectory() + && file.canRead()) { + xweaveDir = file; + } + } + public void setInjarsref(Reference ref) { createInjars().setRefid(ref); } @@ -894,6 +911,7 @@ public class AjcTask extends MatchingTask { } else { executing = true; } + setupOptions(); verifyOptions(); try { String[] args = makeCommand(); @@ -980,6 +998,63 @@ public class AjcTask extends MatchingTask { } /** + * Create any pseudo-options required to implement + * some of the macro options + * @throws BuildException if options conflict + */ + protected void setupOptions() { + if (null != xweaveDir) { + if (DEFAULT_DESTDIR != destDir) { + throw new BuildException("weaveDir forces destdir"); + } + if (null != outjar) { + throw new BuildException("weaveDir forces outjar"); + } + if (null != injars) { + throw new BuildException("weaveDir incompatible with injars now"); + } + File injar = zipDirectory(xweaveDir); + setInjars(new Path(getProject(), injar.getAbsolutePath())); + setDestdir(xweaveDir); + } + } + + protected File zipDirectory(File dir) { + File tempDir = new File("."); + try { + tempDir = File.createTempFile("AjcTest", ".tmp"); + tempDir.mkdirs(); + tempDir.deleteOnExit(); // XXX remove zip explicitly.. + } catch (IOException e) { + // ignore + } +// File result = new File(tempDir, + String filename = "AjcTask-" + + System.currentTimeMillis() + + ".zip"; + File result = new File(filename); + Zip zip = new Zip(); + zip.setProject(getProject()); + zip.setDestFile(result); + zip.setTaskName(getTaskName() + " - zip"); + FileSet fileset = new FileSet(); + fileset.setDir(dir); + zip.addFileset(fileset); + zip.execute(); + Delete delete = new Delete(); + delete.setProject(getProject()); + delete.setTaskName(getTaskName() + " - delete"); + delete.setDir(dir); + delete.execute(); + Mkdir mkdir = new Mkdir(); + mkdir.setProject(getProject()); + mkdir.setTaskName(getTaskName() + " - mkdir"); + mkdir.setDir(dir); + mkdir.execute(); + return result; + } + + /** * @throw BuildException if options conflict */ protected void verifyOptions() { @@ -987,7 +1062,6 @@ public class AjcTask extends MatchingTask { if (fork && isInIncrementalMode() && !isInIncrementalFileMode()) { sb.append("can fork incremental only using tag file.\n"); } - if ((null != sourceRootCopyFilter) && (null == outjar) && (DEFAULT_DESTDIR == destDir)) { final String REQ = " requires dest dir or output jar.\n";
sb.append("sourceRootCopyFilter"); @@ -1051,8 +1125,9 @@ public class AjcTask extends MatchingTask { int errs = holder.numMessages(IMessage.ERROR, false); errs -= numPreviousErrors; if (0 < errs) { - // errors should already be printed by interceptor - throw new BuildException(errs + " errors"); + String m = errs + " errors"; + MessageUtil.print(System.err, holder, "", MessageUtil.MESSAGE_ALL, MessageUtil.PICK_ERROR, true); + throw new BuildException(m); } } // Throw BuildException if there are any fail or abort |