import org.aspectj.ajde.ui.internal.AjcBuildOptions;
import org.aspectj.ajde.ui.internal.UserPreferencesStore;
import org.aspectj.ajdt.internal.core.builder.AjBuildConfig;
+import org.aspectj.bridge.*;
+import org.aspectj.bridge.MessageHandler;
import org.aspectj.util.LangUtil;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
private AjcBuildOptions buildOptions = null;
private UserPreferencesAdapter preferencesAdapter = null;
private NullIdeProperties projectProperties = null;
+ private MessageHandler messageHandler;
private static final String configFile =
- "testdata/examples/figures-coverage/all.lst";
+ AjdeTests.TESTDATA_PATH + "/examples/figures-coverage/all.lst";
public BuildConfigurationTests( String name ) {
// The tests...
public void testCharacterEncoding() {
buildOptions.setCharacterEncoding( "12345" );
- buildConfig = compilerAdapter.genBuildConfig( configFile );
+ buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
String encoding = (String) options.get( CompilerOptions.OPTION_Encoding );
assertEquals( "character encoding", "12345", encoding );
public void testComplianceLevel() {
buildOptions.setComplianceLevel( BuildOptionsAdapter.VERSION_14 );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
String compliance = (String) options.get(CompilerOptions.OPTION_Compliance);
String sourceLevel = (String) options.get(CompilerOptions.OPTION_Source);
buildOptions.setComplianceLevel( BuildOptionsAdapter.VERSION_13);
buildOptions.setSourceCompatibilityLevel( BuildOptionsAdapter.VERSION_14);
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
String compliance = (String) options.get(CompilerOptions.OPTION_Compliance);
String sourceLevel = (String) options.get(CompilerOptions.OPTION_Source);
buildOptions.setComplianceLevel( BuildOptionsAdapter.VERSION_14);
buildOptions.setSourceCompatibilityLevel( BuildOptionsAdapter.VERSION_13);
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
String compliance = (String) options.get(CompilerOptions.OPTION_Compliance);
String sourceLevel = (String) options.get(CompilerOptions.OPTION_Source);
public void testNullWarnings() {
buildOptions.setWarnings( null );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
// this should leave us with the default warnings
buildOptions.setWarnings( warnings );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
// this should leave us with all the user specifiable warnings
public void testNoDebugOptions() {
buildOptions.setDebugLevel( null );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
// this should leave us with the default debug settings
public void testEmptyDebugOptions() {
buildOptions.setDebugLevel( new HashSet() );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
// this should leave us with the debug on
debugOpts.add( BuildOptionsAdapter.DEBUG_ALL );
buildOptions.setDebugLevel( debugOpts );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
// this should leave us with all debug on
debugOpts.add( BuildOptionsAdapter.DEBUG_VARS );
buildOptions.setDebugLevel( debugOpts );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
// this should leave us with all debug on
public void testNoImport() {
buildOptions.setNoImportError( true );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
String noImport = (String) options.get( CompilerOptions.OPTION_ReportInvalidImport );
assertEquals( "no import", CompilerOptions.WARNING, noImport );
public void testPreserveAllLocals() {
buildOptions.setPreserveAllLocals( true );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
Map options = buildConfig.getJavaOptions();
String preserve = (String) options.get( CompilerOptions.OPTION_PreserveUnusedLocal );
assertEquals( "preserve unused", CompilerOptions.PRESERVE, preserve );
public void testNonStandardOptions() {
buildOptions.setNonStandardOptions( "-XnoWeave" );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
assertTrue( "XnoWeave", buildConfig.isNoWeave() );
buildOptions.setNonStandardOptions( "-XserializableAspects" );
buildConfig = compilerAdapter.genBuildConfig( configFile );
// and a few options thrown in at once
buildOptions.setNonStandardOptions( "-Xlint -XnoInline -XserializableAspects" );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
assertEquals( "Xlint", AjBuildConfig.AJLINT_DEFAULT,
buildConfig.getLintMode());
assertTrue( "XnoInline", buildConfig.isXnoInline());
Set roots = new HashSet();
projectProperties.setSourceRoots( roots );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
List configRoots = buildConfig.getSourceRoots();
assertTrue( "no source dirs", configRoots.isEmpty() );
- File f = new File( "testdata/examples/figures/figures-coverage" );
+ File f = new File( AjdeTests.TESTDATA_PATH + "/examples/figures/figures-coverage" );
roots.add( f );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
List configRoots2 = buildConfig.getSourceRoots();
assertTrue( "one source dir", configRoots2.size() == 1 );
assertTrue( "source dir", configRoots2.contains(f) );
- File f2 = new File( "testdata/examples/figures/figures-demo" );
+ File f2 = new File( AjdeTests.TESTDATA_PATH + "/examples/figures/figures-demo" );
roots.add( f2 );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
List configRoots3 = buildConfig.getSourceRoots();
assertTrue( "two source dirs", configRoots3.size() == 2 );
assertTrue( "source dir 1", configRoots3.contains(f) );
Set jars = new HashSet();
projectProperties.setInJars( jars );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
List inJars = buildConfig.getInJars();
assertTrue( "no in jars", inJars.isEmpty() );
File f = new File( "jarone.jar" );
jars.add( f );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
List inJars2 = buildConfig.getInJars();
assertTrue( "one in jar", inJars2.size() == 1 );
assertTrue( "in jar", inJars2.contains(f) );
Set aspects = new HashSet();
projectProperties.setAspectPath( aspects );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
List aPath = buildConfig.getAspectpath();
assertTrue( "no aspect path", aPath.isEmpty() );
File f = new File( "jarone.jar" );
aspects.add( f );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
List aPath2 = buildConfig.getAspectpath();
assertEquals("aspectpath", 1, aPath2.size());
assertTrue( "1 aspectpath", aPath2.contains(f) );
File f2 = new File( "jartwo.jar" );
aspects.add( f2 );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
List aPath3 = buildConfig.getAspectpath();
assertTrue( "two jars in path", aPath3.size() == 2 );
assertTrue( "1 aspectpath", aPath3.contains(f) );
String outJar = "mybuild.jar";
projectProperties.setOutJar( outJar );
buildConfig = compilerAdapter.genBuildConfig( configFile );
+ assertTrue(configFile + " failed", null != buildConfig);
assertNotNull("output jar", buildConfig.getOutputJar());
assertEquals( "out jar", outJar, buildConfig.getOutputJar().toString() );
}
buildOptions = new AjcBuildOptions(preferencesAdapter);
compilerAdapter = new CompilerAdapter();
projectProperties = new NullIdeProperties( "" );
+ messageHandler = new MessageHandler(true);
+ ErrorHandler handler = new ErrorHandler() {
+ public void handleWarning(String message) {
+ MessageUtil.warn(messageHandler, message);
+ }
+ public void handleError(String message) {
+ MessageUtil.error(messageHandler, message);
+ }
+ public void handleError(String message, Throwable t) {
+ IMessage m = new Message(message, IMessage.ERROR, t, null);
+ messageHandler.handleMessage(m);
+ }
+ };
try {
String s = null;
- Ajde.init(
+ Ajde.init(
null,
null,
null,
buildOptions,
null,
null,
- null);
+ handler);
} catch (Throwable t) {
String s = "Unable to initialize AJDE "
+ LangUtil.renderException(t);
buildOptions = null;
compilerAdapter = null;
projectProperties = null;
+ messageHandler = null;
}
private void assertOptionEquals( String reason, Map options, String optionName, String value) {