diff options
author | aclement <aclement> | 2005-11-07 10:53:18 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-11-07 10:53:18 +0000 |
commit | a625ea2ed4810fb5aa1334c027418d25cfb37834 (patch) | |
tree | 6b02edf6c31afafd77ecb4bdc28ca802b4c49596 /org.aspectj.ajdt.core | |
parent | e9e0a7be5be07919d74f7da12fa59232a8b81a1e (diff) | |
download | aspectj-a625ea2ed4810fb5aa1334c027418d25cfb37834.tar.gz aspectj-a625ea2ed4810fb5aa1334c027418d25cfb37834.zip |
fix for 95516 (-outxml / -outxmlfile) - from Matthew.
Diffstat (limited to 'org.aspectj.ajdt.core')
4 files changed, 90 insertions, 1 deletions
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("<aspectj>"); + ps.println("<aspects>"); + for (Iterator i = aspectNames.iterator(); i.hasNext();) { + String name = (String)i.next(); + ps.println("<aspect name=\"" + name + "\"/>"); + } + ps.println("</aspects>"); + ps.println("</aspectj>"); + 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(); } |