AJC produces partial output jar file, when there are warnings during weaving (new dependencies)tags/V1_2_1
@@ -4,12 +4,13 @@ | |||
<comment></comment> | |||
<projects> | |||
<project>asm</project> | |||
<project>weaver</project> | |||
<project>bridge</project> | |||
<project>org.eclipse.jdt.core</project> | |||
<project>runtime</project> | |||
<project>testing-client</project> | |||
<project>testing-util</project> | |||
<project>util</project> | |||
<project>weaver</project> | |||
</projects> | |||
<buildSpec> | |||
<buildCommand> |
@@ -20,6 +20,7 @@ import java.util.*; | |||
import org.aspectj.ajdt.internal.core.builder.*; | |||
import org.aspectj.bridge.*; | |||
import org.aspectj.util.*; | |||
import org.aspectj.weaver.WeaverMessages; | |||
import org.eclipse.jdt.core.compiler.InvalidInputException; | |||
import org.eclipse.jdt.internal.compiler.batch.Main; | |||
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; | |||
@@ -180,6 +181,42 @@ public class BuildArgParser extends Main { | |||
&& (0 == buildConfig.getSourceRoots().size())) { | |||
MessageUtil.error(handler, "specify a source root when in incremental mode"); | |||
} | |||
/* | |||
* Ensure we don't overwrite injars, inpath or aspectpath with outjar | |||
* bug-71339 | |||
*/ | |||
File outjar = buildConfig.getOutputJar(); | |||
if (outjar != null) { | |||
/* Search injars */ | |||
for (Iterator i = buildConfig.getInJars().iterator(); i.hasNext(); ) { | |||
File injar = (File)i.next(); | |||
if (injar.equals(outjar)) { | |||
String message = WeaverMessages.format(WeaverMessages.OUTJAR_IN_INPUT_PATH); | |||
MessageUtil.error(handler,message); | |||
} | |||
} | |||
/* Search inpath */ | |||
for (Iterator i = buildConfig.getInpath().iterator(); i.hasNext(); ) { | |||
File inPathElement = (File)i.next(); | |||
if (!inPathElement.isDirectory() && inPathElement.equals(outjar)) { | |||
String message = WeaverMessages.format(WeaverMessages.OUTJAR_IN_INPUT_PATH); | |||
MessageUtil.error(handler,message); | |||
} | |||
} | |||
/* Search aspectpath */ | |||
for (Iterator i = buildConfig.getAspectpath().iterator(); i.hasNext(); ) { | |||
File pathElement = (File)i.next(); | |||
if (!pathElement.isDirectory() && pathElement.equals(outjar)) { | |||
String message = WeaverMessages.format(WeaverMessages.OUTJAR_IN_INPUT_PATH); | |||
MessageUtil.error(handler,message); | |||
} | |||
} | |||
} | |||
setDebugOptions(); | |||
buildConfig.getOptions().set(options); |
@@ -229,7 +229,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc | |||
} | |||
} finally { | |||
if (zos != null) { | |||
closeOutputStream(); | |||
closeOutputStream(buildConfig.getOutputJar()); | |||
} | |||
ret = !handler.hasErrors(); | |||
// bug 59895, don't release reference to handler as may be needed by a nested call | |||
@@ -257,17 +257,22 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc | |||
return true; | |||
} | |||
private void closeOutputStream() { | |||
private void closeOutputStream(File outJar) { | |||
try { | |||
if (zos != null) zos.close(); | |||
zos = null; | |||
/* Ensure we don't write an incomplete JAR bug-71339 */ | |||
if (handler.hasErrors()) { | |||
outJar.delete(); | |||
} | |||
} catch (IOException ex) { | |||
IMessage message = | |||
new Message("Unable to write outjar " | |||
+ buildConfig.getOutputJar().getPath() | |||
+ outJar.getPath() | |||
+ "(" + ex.getMessage() | |||
+ ")", | |||
new SourceLocation(buildConfig.getOutputJar(),0), | |||
new SourceLocation(outJar,0), | |||
true); | |||
handler.handleMessage(message); | |||
} |
@@ -0,0 +1,17 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2004 IBM Corporation and others. | |||
* All rights reserved. This program and the accompanying materials | |||
* are made available under the terms of the Common Public License v1.0 | |||
* which accompanies this distribution, and is available at | |||
* http://www.eclipse.org/legal/cpl-v10.html | |||
* | |||
* Contributors: | |||
* Matthew Webster - initial implementation | |||
*******************************************************************************/ | |||
package jar1; | |||
public class Parent { | |||
public static void main(String[] args) { | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2004 IBM Corporation and others. | |||
* All rights reserved. This program and the accompanying materials | |||
* are made available under the terms of the Common Public License v1.0 | |||
* which accompanies this distribution, and is available at | |||
* http://www.eclipse.org/legal/cpl-v10.html | |||
* | |||
* Contributors: | |||
* Matthew Webster - initial implementation | |||
*******************************************************************************/ | |||
package jar2; | |||
import jar1.Parent; | |||
public class Child extends Parent { | |||
public static void main(String[] args) { | |||
System.out.println("? Child.main()"); | |||
} | |||
} |
@@ -0,0 +1,22 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2004 IBM Corporation and others. | |||
* All rights reserved. This program and the accompanying materials | |||
* are made available under the terms of the Common Public License v1.0 | |||
* which accompanies this distribution, and is available at | |||
* http://www.eclipse.org/legal/cpl-v10.html | |||
* | |||
* Contributors: | |||
* Matthew Webster - initial implementation | |||
*******************************************************************************/ | |||
package jar3; | |||
public aspect Aspect { | |||
pointcut main () : | |||
execution(* *.main(..)); | |||
after () : main () { | |||
System.out.println("? Aspect.main()"); | |||
} | |||
} |
@@ -40,6 +40,8 @@ public class BcweaverJarMaker { | |||
makeURLWeavingClassLoaderJars(); | |||
makeDuplicateManifestTestJars(); | |||
makeOutjarTestJars(); | |||
} | |||
public static void makeJar0() throws IOException { | |||
@@ -357,4 +359,58 @@ public class BcweaverJarMaker { | |||
args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/TraceHello.java"); | |||
CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS); | |||
} | |||
public static void makeOutjarTestJars() throws IOException { | |||
List args = new ArrayList(); | |||
/* | |||
* parent | |||
*/ | |||
args.clear(); | |||
args.add("-classpath"); | |||
args.add("../lib/test/aspectjrt.jar;../lib/test/testing-client.jar" + | |||
File.pathSeparator + System.getProperty("aspectjrt.path")); | |||
args.add("-outjar"); | |||
args.add("./testdata/OutjarTest/parent.jar"); | |||
args.add(AjdtAjcTests.TESTDATA_PATH + "/OutjarTest/src/jar1/Parent.java"); | |||
CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS); | |||
/* | |||
* child | |||
*/ | |||
args.clear(); | |||
args.add("-classpath"); | |||
args.add("../lib/test/aspectjrt.jar;../lib/test/testing-client.jar" | |||
+ File.pathSeparator + System.getProperty("aspectjrt.path") | |||
+ File.pathSeparator + "./testdata/OutjarTest/parent.jar"); | |||
args.add("-outjar"); | |||
args.add("./testdata/OutjarTest/child.jar"); | |||
args.add(AjdtAjcTests.TESTDATA_PATH + "/OutjarTest/src/jar2/Child.java"); | |||
CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS); | |||
/* | |||
* aspects | |||
*/ | |||
args.clear(); | |||
args.add("-classpath"); | |||
args.add("../lib/test/aspectjrt.jar;../lib/test/testing-client.jar" | |||
+ File.pathSeparator + System.getProperty("aspectjrt.path")); | |||
args.add("-outjar"); | |||
args.add("./testdata/OutjarTest/aspects.jar"); | |||
args.add(AjdtAjcTests.TESTDATA_PATH + "/OutjarTest/src/jar3/Aspect.aj"); | |||
CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS); | |||
/* | |||
* aspectjar | |||
*/ | |||
// args = new ArrayList(); | |||
// args.add("-classpath"); | |||
// args.add("../lib/test/aspectjrt.jar;../lib/test/testing-client.jar" + | |||
// File.pathSeparator + System.getProperty("aspectjrt.path")); | |||
// args.add("-outjar"); | |||
// args.add("../ajde/testdata/DuplicateManifestTest/aspectjar.jar"); | |||
// args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/Trace.java"); | |||
// args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/TraceHello.java"); | |||
// CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS); | |||
} | |||
} |
@@ -25,6 +25,7 @@ public class AjdtBuilderTests extends TestCase { | |||
suite.addTestSuite(AsmBuilderTest.class); | |||
suite.addTestSuite(AjCompilerOptionsTest.class); | |||
suite.addTestSuite(AjStateTest.class); | |||
suite.addTestSuite(OutjarTest.class); | |||
//$JUnit-END$ | |||
return suite; | |||
} |
@@ -53,6 +53,8 @@ public class Ajc { | |||
private int incrementalStage = 10; | |||
private boolean shouldEmptySandbox = true; | |||
private AjcCommandController controller; | |||
private static boolean verbose = (!System.getProperty("org.aspectj.tools.ajc.Ajc.verbose","false").equals("false")); | |||
/** | |||
* Constructs a new Ajc instance, with a new AspectJ compiler | |||
@@ -175,6 +177,11 @@ public class Ajc { | |||
System.setOut(systemOut); | |||
System.setErr(systemErr); | |||
} | |||
if (verbose) { | |||
System.err.println(result.getStandardError()); | |||
System.out.println(result.getStandardOutput()); | |||
System.out.println(result); | |||
} | |||
return result; | |||
} | |||
@@ -279,6 +286,7 @@ public class Ajc { | |||
if ((args[i].equals("-aspectpath") || | |||
args[i].equals("-inpath") || | |||
args[i].equals("-injars") || | |||
args[i].equals("-outjar") || | |||
args[i].equals("-classpath") || | |||
args[i].equals("-sourceroots") || | |||
args[i].equals("-Xlintfile") || |