From 0a77939b3286d5ac033797234741436c57ad202f Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 14 Oct 2004 12:51:18 +0000 Subject: [PATCH] Fix for: Bugzilla Bug 75568 : ajc changes classfile timestamps even if compilation fails (regression) and maybe: Bugzilla Bug 74245: -proceedOnError does not weave aspects on compile error --- .../org/aspectj/ajdt/ajc/BuildArgParser.java | 5 +- .../internal/compiler/AjCompilerAdapter.java | 7 +- .../internal/core/builder/AjBuildConfig.java | 8 +++ .../internal/core/builder/AjBuildManager.java | 5 +- .../core/builder/AjCompilerOptions.java | 1 + .../internal/core/builder/AspectJBuilder.java | 2 +- org.aspectj.ajdt.core/testdata/src1/C1.java | 3 + org.aspectj.ajdt.core/testdata/src1/C2.java | 4 ++ .../compiler/batch/AjdtBatchTests.java | 1 + .../batch/ProceedOnErrorTestCase.java | 66 +++++++++++++++++++ 10 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 org.aspectj.ajdt.core/testdata/src1/C1.java create mode 100644 org.aspectj.ajdt.core/testdata/src1/C2.java create mode 100644 org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/ProceedOnErrorTestCase.java diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java index 837bbf52d..f3aad9214 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java @@ -608,6 +608,8 @@ public class BuildArgParser extends Main { // dirLookahead(arg, args, nextArgIndex); // } else if (arg.equals("-extdirs")) { // dirLookahead(arg, args, nextArgIndex); + } else if (arg.equals("-proceedOnError")) { + buildConfig.setProceedOnError(true); } else if (new File(arg).isDirectory()) { showError("dir arg not permitted: " + arg); } else { @@ -616,9 +618,10 @@ public class BuildArgParser extends Main { // -d args, -help (handled), // -classpath, -target, -1.3, -1.4, -source [1.3|1.4] // -nowarn, -warn:[...], -deprecation, -noImportError, - // -proceedOnError, -g:[...], -preserveAllLocals, + // -g:[...], -preserveAllLocals, // -referenceInfo, -encoding, -verbose, -log, -time // -noExit, -repeat + // (Actually, -noExit grabbed by Main) unparsedArgs.add(arg); } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/AjCompilerAdapter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/AjCompilerAdapter.java index ccb9821b9..5f1e66525 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/AjCompilerAdapter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/AjCompilerAdapter.java @@ -46,6 +46,7 @@ public class AjCompilerAdapter implements ICompilerAdapter { private boolean isBatchCompile; private boolean reportedErrors; private boolean isXNoWeave; + private boolean proceedOnError; private IIntermediateResultsRequestor intermediateResultsRequestor; private IProgressListener progressListener; private IOutputClassFileNameProvider outputFileNameProvider; @@ -83,7 +84,8 @@ public class AjCompilerAdapter implements ICompilerAdapter { IBinarySourceProvider binarySourceProvider, Map fullBinarySourceEntries, /* fileName |-> List */ Collection /* InterimCompilationResult */ resultSetForFullWeave, - boolean isXNoWeave) { + boolean isXNoWeave, + boolean proceedOnError) { this.compiler = compiler; this.isBatchCompile = isBatchCompile; this.weaver = weaver; @@ -92,6 +94,7 @@ public class AjCompilerAdapter implements ICompilerAdapter { this.outputFileNameProvider = outputFileNameProvider; this.binarySourceProvider = binarySourceProvider; this.isXNoWeave = isXNoWeave; + this.proceedOnError = proceedOnError; this.binarySourceSetForFullWeave = fullBinarySourceEntries; this.resultSetForFullWeave = resultSetForFullWeave; this.eWorld = eFactory; @@ -108,7 +111,7 @@ public class AjCompilerAdapter implements ICompilerAdapter { public void afterCompiling() { try { - if (isXNoWeave || reportedErrors) { + if (isXNoWeave || (reportedErrors && !proceedOnError)) { // no point weaving... just tell the requestor we're done notifyRequestor(); } else { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java index c798a7dcc..562a5951b 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java @@ -516,4 +516,12 @@ public class AjBuildConfig { public boolean getShowWeavingInformation() { return options.showWeavingInformation; } + + public void setProceedOnError(boolean b) { + options.proceedOnError = b; + } + + public boolean getProceedOnError() { + return options.proceedOnError; + } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java index 0c0d9aadd..f8e6050d1 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java @@ -780,7 +780,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc } protected boolean proceedOnError() { - return true; //??? + return buildConfig.getProceedOnError(); } // public void noteClassFiles(AjCompiler.InterimResult result) { @@ -970,7 +970,8 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc this, // IBinarySourceProvider state.binarySourceFiles, state.resultsFromFile.values(), - buildConfig.isNoWeave()); + buildConfig.isNoWeave(), + buildConfig.getProceedOnError()); } /* (non-Javadoc) diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java index c2022484c..904954721 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java @@ -70,6 +70,7 @@ public class AjCompilerOptions extends CompilerOptions { public boolean generateModel = false; public boolean generateJavaDocsInModel = false; public boolean generateEmacsSymFiles = false; + public boolean proceedOnError = false; /** diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java index 03a8132d3..a1e066b79 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java @@ -139,7 +139,7 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto return new AjCompilerAdapter(forCompiler,isBatchBuild,myBcelWorld, myWeaver,eFactory,unwovenResultCollector,ajNotifier,fileNameProvider,bsProvider, fullBinarySourceEntries,resultSetForFullWeave, - ajOptions.noWeave); + ajOptions.noWeave,ajOptions.proceedOnError); } /* (non-Javadoc) diff --git a/org.aspectj.ajdt.core/testdata/src1/C1.java b/org.aspectj.ajdt.core/testdata/src1/C1.java new file mode 100644 index 000000000..3fd8170c3 --- /dev/null +++ b/org.aspectj.ajdt.core/testdata/src1/C1.java @@ -0,0 +1,3 @@ +class C { + +} \ No newline at end of file diff --git a/org.aspectj.ajdt.core/testdata/src1/C2.java b/org.aspectj.ajdt.core/testdata/src1/C2.java new file mode 100644 index 000000000..39a6c3af6 --- /dev/null +++ b/org.aspectj.ajdt.core/testdata/src1/C2.java @@ -0,0 +1,4 @@ +BROKEN +class C { + +} \ No newline at end of file diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/AjdtBatchTests.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/AjdtBatchTests.java index d89573909..23b1425e8 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/AjdtBatchTests.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/AjdtBatchTests.java @@ -32,6 +32,7 @@ public class AjdtBatchTests extends TestCase { suite.addTestSuite(JavadocTest.class); suite.addTestSuite(PartiallyExposedHierarchyTestCase.class); suite.addTestSuite(CompilerDumpTestCase.class); + suite.addTestSuite(ProceedOnErrorTestCase.class); // XXX suite.addTestSuite(VerifyWeaveTestCase.class); //suite.addTestSuite(WorkingCommandTestCase.class); //$JUnit-END$ diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/ProceedOnErrorTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/ProceedOnErrorTestCase.java new file mode 100644 index 000000000..3b856570d --- /dev/null +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/ProceedOnErrorTestCase.java @@ -0,0 +1,66 @@ +/* ******************************************************************* + * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * 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: + * PARC initial implementation + * ******************************************************************/ + +package org.aspectj.ajdt.internal.compiler.batch; + +import java.io.File; +import java.io.IOException; +import java.util.Date; + + +public class ProceedOnErrorTestCase extends CommandTestCase { + + public ProceedOnErrorTestCase(String name) { + super(name); + } + + /** + * Compile C1.java that defines C.class then compile C2.java which contains another version of C.class but also + * contains errors. Because -proceedOnError is not supplied, the .class file should not be touched when compiling + * C2.java. + */ + public void testNoProceedOnError() throws IOException { + checkCompile("src1/C1.java", NO_ERRORS); + File f =new File("out"+File.separator+"C.class"); + long oldmodtime = f.lastModified(); + pause(2); + checkCompile("src1/C2.java", new int[]{1}); + f =new File("out"+File.separator+"C.class"); + long newmodtime = f.lastModified(); + // Without -proceedOnError supplied, we should *not* change the time stamp on the .class file + assertTrue("The .class file should not have been modified as '-proceedOnError' was not supplied (old="+ + new Date(oldmodtime).toString()+")(new="+new Date(newmodtime).toString()+")", + oldmodtime==newmodtime); + } + + public void testProceedOnError() throws IOException { + checkCompile("src1/C1.java", NO_ERRORS); + File f =new File("out"+File.separator+"C.class"); + long oldmodtime = f.lastModified(); + pause(2); + checkCompile("src1/C2.java",new String[]{"-proceedOnError"}, new int[]{1}); + f =new File("out"+File.separator+"C.class"); + long newmodtime = f.lastModified(); + // Without -proceedOnError supplied, we should *not* change the time stamp on the .class file + assertTrue("The .class file should have been modified as '-proceedOnError' *was* supplied (old="+ + new Date(oldmodtime).toString()+")(new="+new Date(newmodtime).toString()+")", + newmodtime>oldmodtime); + } + + + private void pause(int secs) { + try { + Thread.sleep(secs*1000); + } catch (InterruptedException ie) {} + } + +} -- 2.39.5