Browse Source

fix for 95516 (-outxml / -outxmlfile) - from Matthew.

tags/V1_5_0RC1
aclement 18 years ago
parent
commit
a625ea2ed4

+ 1
- 0
ajde/testsrc/org/aspectj/ajde/AjdeTests.java View File

@@ -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;

+ 93
- 0
ajde/testsrc/org/aspectj/ajde/OutxmlTest.java View File

@@ -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());
}
}

}

+ 12
- 0
docs/devGuideDB/ajc.xml View File

@@ -107,6 +107,18 @@
</para></listitem>
</varlistentry>

<varlistentry>
<term>-outxml</term>
<listitem><para>Generate aop.xml file for load-time weaving with default name.
</para></listitem>
</varlistentry>

<varlistentry>
<term>-outxmlfile <replaceable>custom/aop.xml</replaceable></term>
<listitem><para>Generate aop.xml file for load-time weaving with custom name.
</para></listitem>
</varlistentry>

<varlistentry>
<term>-incremental</term>
<listitem><para>Run the compiler continuously.

+ 10
- 0
org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java View File

@@ -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));

+ 9
- 0
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java View File

@@ -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;
}

+ 53
- 1
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java View File

@@ -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);
}
}
};
}

+ 18
- 0
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java View File

@@ -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();
}

+ 20
- 0
testing/newsrc/org/aspectj/testing/CompileSpec.java View File

@@ -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()) {

+ 3
- 0
testing/newsrc/org/aspectj/testing/RunSpec.java View File

@@ -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());

+ 23
- 0
tests/ltw/pakkage/Aspect3.aj View File

@@ -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());
}
}

+ 1
- 1
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java View File

@@ -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");}

+ 10
- 3
tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java View File

@@ -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");
}
}


+ 57
- 0
tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml View File

@@ -30,4 +30,61 @@
</run>
</ajc-test>

<ajc-test dir="ltw"
title="Ensure valid aop.xml file is generated"
keywords="-outxml">
<compile
files="Main.java"
outjar="main.jar"
>
</compile>
<compile
classpath="main.jar"
files="Aspect1.aj, Aspect2.aj, pakkage/Aspect3.aj"
outxmlfile="META-INF/aop.xml"
>
</compile>
<run class="Main" ltw="">
<stdout>
<line text="Main.main"/>
<line text="Main.test1"/>
<line text="Main.test2"/>
</stdout>
<stderr>
<line text="Aspect1.before_test1"/>
<line text="Aspect2.before_test2"/>
<line text="pakkage.Aspect3.before_test2"/>
</stderr>
</run>
</ajc-test>

<ajc-test dir="ltw"
title="Ensure valid aop.xml is generated for -outjar"
keywords="-outxml">
<compile
files="Main.java"
outjar="main.jar"
>
</compile>
<compile
classpath="main.jar"
files="Aspect1.aj, Aspect2.aj, pakkage/Aspect3.aj"
outjar="aspects.jar"
options="-outxml"
>
</compile>
<run class="Main" ltw="">
<stdout>
<line text="Main.main"/>
<line text="Main.test1"/>
<line text="Main.test2"/>
</stdout>
<stderr>
<line text="Aspect1.before_test1"/>
<line text="Aspect2.before_test2"/>
<line text="pakkage.Aspect3.before_test2"/>
</stderr>
</run>
</ajc-test>


Loading…
Cancel
Save