From a625ea2ed4810fb5aa1334c027418d25cfb37834 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 7 Nov 2005 10:53:18 +0000 Subject: fix for 95516 (-outxml / -outxmlfile) - from Matthew. --- ajde/testsrc/org/aspectj/ajde/AjdeTests.java | 1 + ajde/testsrc/org/aspectj/ajde/OutxmlTest.java | 93 ++++++++++++++++++++++ docs/devGuideDB/ajc.xml | 12 +++ .../src/org/aspectj/ajdt/ajc/BuildArgParser.java | 10 +++ .../ajdt/internal/core/builder/AjBuildConfig.java | 9 +++ .../ajdt/internal/core/builder/AjBuildManager.java | 54 ++++++++++++- .../aspectj/ajdt/ajc/BuildArgParserTestCase.java | 18 +++++ .../newsrc/org/aspectj/testing/CompileSpec.java | 20 +++++ testing/newsrc/org/aspectj/testing/RunSpec.java | 3 + tests/ltw/pakkage/Aspect3.aj | 23 ++++++ .../org/aspectj/systemtest/ajc150/Ajc150Tests.java | 2 +- .../aspectj/systemtest/ajc150/ltw/LTWTests.java | 13 ++- .../aspectj/systemtest/ajc150/ltw/ltw-tests.xml | 57 +++++++++++++ 13 files changed, 310 insertions(+), 5 deletions(-) create mode 100644 ajde/testsrc/org/aspectj/ajde/OutxmlTest.java create mode 100644 tests/ltw/pakkage/Aspect3.aj diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeTests.java b/ajde/testsrc/org/aspectj/ajde/AjdeTests.java index dfe880ddb..461dfc52f 100644 --- a/ajde/testsrc/org/aspectj/ajde/AjdeTests.java +++ b/ajde/testsrc/org/aspectj/ajde/AjdeTests.java @@ -59,6 +59,7 @@ public class AjdeTests extends TestCase { suite.addTestSuite(JarManifestTest.class); suite.addTestSuite(ExtensionTests.class); suite.addTestSuite(GenericsTest.class); + suite.addTestSuite(OutxmlTest.class); //$JUnit-END$ return suite; diff --git a/ajde/testsrc/org/aspectj/ajde/OutxmlTest.java b/ajde/testsrc/org/aspectj/ajde/OutxmlTest.java new file mode 100644 index 000000000..2ccb66b2d --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/OutxmlTest.java @@ -0,0 +1,93 @@ +/* ******************************************************************* + * Copyright (c) 2003 Contributors. + * 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 org.aspectj.ajde; + +import java.io.File; +import java.io.IOException; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.aspectj.util.FileUtil; + +public class OutxmlTest extends AjdeTestCase { + + public static final String PROJECT_DIR = "OutxmlTest"; + public static final String BIN_DIR = "bin"; + public static final String OUTJAR_NAME = "/bin/test.jar"; + public static final String DEFAULT_AOPXML_NAME = "META-INF/aop.xml"; + public static final String CUSTOM_AOPXML_NAME = "custom/aop.xml"; + + /* + * Ensure the output directory is clean + */ + protected void setUp() throws Exception { + super.setUp(PROJECT_DIR); + FileUtil.deleteContents(openFile(BIN_DIR)); + } + + + /** + * Aim: Test "-outxml" option produces the correct xml file + * + */ + public void testOutxmlToFile () { +// System.out.println("OutxmlTest.testOutxmlToFile() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'"); + assertTrue("Build failed",doSynchronousBuild("outxml-to-file.lst")); + assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty()); + + File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME); + assertTrue(DEFAULT_AOPXML_NAME + " missing",aopxml.exists()); + } + + /** + * Aim: Test "-outxmlfile filename" option produces the correct + * xml file + * + */ + public void testOutxmlfileToFile () { + assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-file.lst")); + assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty()); + + File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME); + assertTrue(CUSTOM_AOPXML_NAME + " missing",aopxml.exists()); + } + + /** + * Aim: Test "-outxmlfile filename" option produces the correct + * xml entry in outjar file + * + */ + public void testOutxmlfileToOutjar () { +// System.out.println("OutxmlTest.testOutxmlToOutjar() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'"); + File outjar = openFile(OUTJAR_NAME); + ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath()); + assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-outjar.lst")); + assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty()); + + File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME); + assertFalse(CUSTOM_AOPXML_NAME + " should not exisit",aopxml.exists()); + assertJarContainsEntry(outjar,CUSTOM_AOPXML_NAME); + } + + private void assertJarContainsEntry (File file, String entryName) { + + try { + JarFile jarFile = new JarFile(file); + JarEntry jarEntry = jarFile.getJarEntry(entryName); + assertNotNull(entryName + " missing",jarEntry); + } + catch (IOException ex) { + fail(ex.toString()); + } + } + +} diff --git a/docs/devGuideDB/ajc.xml b/docs/devGuideDB/ajc.xml index ea2cab2da..ef3438987 100644 --- a/docs/devGuideDB/ajc.xml +++ b/docs/devGuideDB/ajc.xml @@ -107,6 +107,18 @@ + + -outxml + Generate aop.xml file for load-time weaving with default name. + + + + + -outxmlfile custom/aop.xml + Generate aop.xml file for load-time weaving with custom name. + + + -incremental Run the compiler continuously. 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 84498d494..74135e9b6 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 @@ -492,6 +492,16 @@ public class BuildArgParser extends Main { } else { showError("-outjar requires jar path argument"); } + } else if (arg.equals("-outxml")) { + buildConfig.setOutxmlName("META-INF/aop.xml"); + } else if (arg.equals("-outxmlfile")) { + if (args.size() > nextArgIndex) { + String name = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue(); + buildConfig.setOutxmlName(name); + args.remove(args.get(nextArgIndex)); + } else { + showError("-outxmlfile requires file name argument"); + } } else if (arg.equals("-log")){ // remove it as it's already been handled in org.aspectj.tools.ajc.Main args.remove(args.get(nextArgIndex)); 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 d5f80f1a8..8b5cf2132 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 @@ -42,6 +42,7 @@ public class AjBuildConfig { private File outputDir; private File outputJar; + private String outxmlName; private List/*File*/ sourceRoots = new ArrayList(); private List/*File*/ files = new ArrayList(); private List /*File*/ binaryFiles = new ArrayList(); // .class files in indirs... @@ -165,6 +166,10 @@ public class AjBuildConfig { public File getOutputJar() { return outputJar; } + + public String getOutxmlName() { + return outxmlName; + } public List/*File*/ getInpath() { // Elements of the list are either archives (jars/zips) or directories @@ -183,6 +188,10 @@ public class AjBuildConfig { this.outputJar = outputJar; } + public void setOutxmlName(String name) { + this.outxmlName = name; + } + public void setInJars(List sourceJars) { this.inJars = sourceJars; } 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 bbcb8ea9b..9cb561ea2 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 @@ -14,15 +14,18 @@ package org.aspectj.ajdt.internal.core.builder; import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; +import java.io.PrintStream; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -125,6 +128,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc // FIXME asc should this really be in here? private IHierarchy structureModel; public AjBuildConfig buildConfig; + private List aspectNames = new LinkedList(); AjState state = new AjState(this); @@ -281,6 +285,11 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc state.successfulCompile(buildConfig,batch); copyResourcesToDestination(); + + if (buildConfig.getOutxmlName() != null) { + writeOutxmlFile(); + } + /*boolean weaved = *///weaveAndGenerateClassFiles(); // if not weaved, then no-op build, no model changes // but always returns true @@ -480,7 +489,38 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc } } + private void writeOutxmlFile () throws IOException { + String filename = buildConfig.getOutxmlName(); +// System.err.println("? AjBuildManager.writeOutxmlFile() outxml=" + filename); +// System.err.println("? AjBuildManager.writeOutxmlFile() outputDir=" + buildConfig.getOutputDir()); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + ps.println(""); + ps.println(""); + for (Iterator i = aspectNames.iterator(); i.hasNext();) { + String name = (String)i.next(); + ps.println(""); + } + ps.println(""); + ps.println(""); + ps.println(); + ps.close(); + if (zos != null) { + ZipEntry newEntry = new ZipEntry(filename); + + zos.putNextEntry(newEntry); + zos.write(baos.toByteArray()); + zos.closeEntry(); + } else { + OutputStream fos = + FileUtil.makeOutputStream(new File(buildConfig.getOutputDir(),filename)); + fos.write(baos.toByteArray()); + fos.close(); + } + } + // public static void dumprels() { // IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap(); // int ctr = 1; @@ -792,11 +832,13 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc public void acceptResult(CompilationResult unitResult) { // end of compile, must now write the results to the output destination // this is either a jar file or a file in a directory - if (!(unitResult.hasErrors() && !proceedOnError())) { + if (!(unitResult.hasErrors() && !proceedOnError())) { Collection classFiles = unitResult.compiledTypes.values(); + boolean shouldAddAspectName = (buildConfig.getOutxmlName() != null); for (Iterator iter = classFiles.iterator(); iter.hasNext();) { ClassFile classFile = (ClassFile) iter.next(); String filename = new String(classFile.fileName()); + String classname = filename.replace('/', '.'); filename = filename.replace('/', File.separatorChar) + ".class"; try { if (buildConfig.getOutputJar() == null) { @@ -804,6 +846,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc } else { writeZipEntry(classFile,filename); } + if (shouldAddAspectName) addAspectName(classname); } catch (IOException ex) { IMessage message = EclipseAdapterUtils.makeErrorMessage( new String(unitResult.fileName), @@ -854,6 +897,15 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc zos.write(classFile.getBytes()); zos.closeEntry(); } + + private void addAspectName (String name) { + BcelWorld world = getBcelWorld(); + ResolvedType type = world.resolve(name); +// System.err.println("? writeAspectName() type=" + type); + if (type.isAspect()) { + aspectNames.add(name); + } + } }; } diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java index a020afe9f..e207fe91c 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java @@ -21,6 +21,8 @@ import org.aspectj.ajdt.internal.core.builder.*; import org.aspectj.bridge.CountingMessageHandler; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.IMessageHandler; +import org.aspectj.bridge.IMessageHolder; +import org.aspectj.bridge.MessageHandler; import org.aspectj.bridge.MessageWriter; import org.aspectj.testing.util.TestUtil; import org.aspectj.org.eclipse.jdt.core.compiler.InvalidInputException; @@ -490,6 +492,22 @@ public class BuildArgParserTestCase extends TestCase { genBuildConfig(new String[] { TEST_DIR + "X.aj", TEST_DIR + "Y.aj"}, messageWriter); } + public void testOutxml () { + IMessageHolder messageHolder = new MessageHandler(); + AjBuildConfig config = genBuildConfig(new String[] { "-outxml", "-showWeaveInfo" }, messageHolder); + assertTrue("Warnings: " + messageHolder,!messageHolder.hasAnyMessage(IMessage.WARNING, true)); + assertEquals("Wrong outxml","META-INF/aop.xml",config.getOutxmlName()); + assertTrue("Following option currupted",config.getShowWeavingInformation()); + } + + public void testOutxmlfile () { + IMessageHolder messageHolder = new MessageHandler(); + AjBuildConfig config = genBuildConfig(new String[] { "-outxmlfile", "custom/aop.xml", "-showWeaveInfo" }, messageHolder); + assertTrue("Warnings: " + messageHolder,!messageHolder.hasAnyMessage(IMessage.WARNING, true)); + assertEquals("Wrong outxml","custom/aop.xml",config.getOutxmlName()); + assertTrue("Following option currupted",config.getShowWeavingInformation()); + } + protected void setUp() throws Exception { super.setUp(); } diff --git a/testing/newsrc/org/aspectj/testing/CompileSpec.java b/testing/newsrc/org/aspectj/testing/CompileSpec.java index 1b50387b0..6b98a6822 100644 --- a/testing/newsrc/org/aspectj/testing/CompileSpec.java +++ b/testing/newsrc/org/aspectj/testing/CompileSpec.java @@ -37,6 +37,7 @@ public class CompileSpec implements ITestStep { private String inpath; private String sourceroots; private String outjar; + private String outxml; private String xlintfile; private String options; private String baseDir; @@ -166,6 +167,20 @@ public class CompileSpec implements ITestStep { public void setOutjar(String outjar) { this.outjar = outjar; } + + /** + * @return Returns the outxml. + */ + public String getOutxmlfile() { + return outxml; + } + + /** + * @param outxml The the of the aop.xml file to generate + */ + public void setOutxmlfile(String outxml) { + this.outxml = outxml; + } /** * @return Returns the sourceroots. */ @@ -212,6 +227,11 @@ public class CompileSpec implements ITestStep { args.append(getOutjar()); args.append(" "); } + if (getOutxmlfile() != null) { + args.append("-outxmlfile "); + args.append(getOutxmlfile()); + args.append(" "); + } if (getOptions() != null) { StringTokenizer strTok = new StringTokenizer(getOptions(),","); while (strTok.hasMoreTokens()) { diff --git a/testing/newsrc/org/aspectj/testing/RunSpec.java b/testing/newsrc/org/aspectj/testing/RunSpec.java index 0716b8362..891600dbf 100644 --- a/testing/newsrc/org/aspectj/testing/RunSpec.java +++ b/testing/newsrc/org/aspectj/testing/RunSpec.java @@ -130,6 +130,9 @@ public class RunSpec implements ITestStep { boolean useLtw = false; if (ltwFile != null) { + // TODO maw use flag rather than empty file name + if (ltwFile.trim().length() == 0) return true; + File from = new File(baseDir,ltwFile); File to = new File(sandboxDirectory,"META-INF" + File.separator + "aop.xml"); // System.out.println("RunSpec.copyLtwFile() from=" + from.getAbsolutePath() + " to=" + to.getAbsolutePath()); diff --git a/tests/ltw/pakkage/Aspect3.aj b/tests/ltw/pakkage/Aspect3.aj new file mode 100644 index 000000000..08894259e --- /dev/null +++ b/tests/ltw/pakkage/Aspect3.aj @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Webster initial implementation + *******************************************************************************/ +package pakkage; + +import org.aspectj.lang.JoinPoint; + +public aspect Aspect3 { + + declare precedence : *, Aspect3; + + before () : execution(void Main.test2()){ + System.err.println("pakkage.Aspect3.before_" + thisJoinPoint.getSignature().getName()); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index 3a7560290..915c55794 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -51,7 +51,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void testITDCtor_pr112783() { runTest("Problem with constructor ITDs");} */ - //public void testPossibleStaticImports_pr113066() { runTest("possible static imports bug");} + public void testPossibleStaticImports_pr113066() { runTest("possible static imports bug");} public void testBrokenDecp_pr112476() { runTest("binary weaving decp broken");} public void testUnboundFormal_pr112027() { runTest("unexpected error unboundFormalInPC");} public void testNPEScopeSetup_pr115038() { runTest("NPE in ensureScopeSetup");} diff --git a/tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java b/tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java index 543d586e8..3b489cf07 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java @@ -28,8 +28,15 @@ public class LTWTests extends org.aspectj.testing.XMLBasedAjcTestCase { } - public void test001(){ - runTest("Ensure 1st aspect is rewoven when weaving 2nd aspect"); - } + public void test001(){ + runTest("Ensure 1st aspect is rewoven when weaving 2nd aspect"); + } + + public void testOutxmlFile (){ + runTest("Ensure valid aop.xml file is generated"); + } + public void testOutxmlJar (){ + runTest("Ensure valid aop.xml is generated for -outjar"); + } } diff --git a/tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml b/tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml index 0e818afbf..34f2f3dab 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml @@ -30,4 +30,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3