@@ -23,6 +23,7 @@ import org.aspectj.ajde.ui.StructureViewNodeFactory; | |||
import org.aspectj.asm.AsmManager; | |||
import org.aspectj.bridge.IMessageHandler; | |||
import org.aspectj.bridge.Version; | |||
import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions; | |||
import org.aspectj.util.LangUtil; | |||
import org.aspectj.util.Reflection; | |||
@@ -381,6 +382,15 @@ public class Ajde { | |||
} | |||
} | |||
/** | |||
* Returns true if the compiler is compatible with Java 6 | |||
* (which it will do when the compiler is upgraded to the | |||
* jdt 3.2 compiler) and false otherwise | |||
*/ | |||
public boolean compilerIsJava6Compatible() { | |||
// If it doesn't understand the jdklevel, versionToJdkLevel returns 0 | |||
return CompilerOptions.versionToJdkLevel(BuildOptionsAdapter.VERSION_16) != 0; | |||
} | |||
} |
@@ -27,6 +27,8 @@ public interface BuildOptionsAdapter { | |||
// Version constants | |||
public static final String VERSION_13 = "1.3"; | |||
public static final String VERSION_14 = "1.4"; | |||
public static final String VERSION_15 = "1.5"; | |||
public static final String VERSION_16 = "1.6"; | |||
// Warning constants | |||
public static final String WARN_CONSTRUCTOR_NAME = "constructorName"; |
@@ -235,11 +235,13 @@ public class CompilerAdapter { | |||
* Populate options in a build configuration, using the Ajde BuildOptionsAdapter. | |||
* Added by AMC 01.20.2003, bugzilla #29769 | |||
*/ | |||
private static boolean configureBuildOptions( AjBuildConfig config, BuildOptionsAdapter options, IMessageHandler handler) { | |||
private boolean configureBuildOptions( AjBuildConfig config, BuildOptionsAdapter options, IMessageHandler handler) { | |||
LangUtil.throwIaxIfNull(options, "options"); | |||
LangUtil.throwIaxIfNull(config, "config"); | |||
Map optionsToSet = new HashMap(); | |||
LangUtil.throwIaxIfNull(optionsToSet, "javaOptions"); | |||
checkNotAskedForJava6Compliance(options); | |||
if (options.getSourceCompatibilityLevel() != null && options.getSourceCompatibilityLevel().equals(CompilerOptions.VERSION_1_5)) { | |||
optionsToSet.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); | |||
@@ -356,6 +358,54 @@ public class CompilerAdapter { | |||
// ignored: lenient, porting, preprocess, strict, usejavac, workingdir | |||
} | |||
/** | |||
* Check that the user hasn't specified Java 6 for the compliance, source and | |||
* target levels. If they have then an error is thrown. | |||
*/ | |||
private void checkNotAskedForJava6Compliance(BuildOptionsAdapter options) { | |||
// bug 164384 - Throwing an IMessage.ERRROR rather than an IMessage.ABORT | |||
// means that we'll continue to try to compile the code. This means that | |||
// the user may see other errors (for example, if they're using annotations | |||
// then they'll get errors saying that they require 5.0 compliance). | |||
// Throwing IMessage.ABORT would prevent this, however, 'abort' is really | |||
// for compiler exceptions. | |||
String compliance = options.getComplianceLevel(); | |||
if (!LangUtil.isEmpty(compliance) | |||
&& compliance.equals(BuildOptionsAdapter.VERSION_16)){ | |||
String msg = "Java 6.0 compliance level is unsupported"; | |||
IMessage m = new Message(msg, IMessage.ERROR, null, null); | |||
messageHandler.handleMessage(m); | |||
return; | |||
} | |||
String source = options.getSourceCompatibilityLevel(); | |||
if (!LangUtil.isEmpty(source) | |||
&& source.equals(BuildOptionsAdapter.VERSION_16)){ | |||
String msg = "Java 6.0 source level is unsupported"; | |||
IMessage m = new Message(msg, IMessage.ERROR, null, null); | |||
messageHandler.handleMessage(m); | |||
return; | |||
} | |||
Map javaOptions = options.getJavaOptionsMap(); | |||
if (javaOptions != null){ | |||
String version = (String)javaOptions.get(CompilerOptions.OPTION_Compliance); | |||
String sourceVersion = (String)javaOptions.get(CompilerOptions.OPTION_Source); | |||
String targetVersion = (String)javaOptions.get(CompilerOptions.OPTION_TargetPlatform); | |||
if (version!=null && version.equals(BuildOptionsAdapter.VERSION_16)) { | |||
String msg = "Java 6.0 compliance level is unsupported"; | |||
IMessage m = new Message(msg, IMessage.ERROR, null, null); | |||
messageHandler.handleMessage(m); | |||
} else if (sourceVersion!=null && sourceVersion.equals(BuildOptionsAdapter.VERSION_16)) { | |||
String msg = "Java 6.0 source level is unsupported"; | |||
IMessage m = new Message(msg, IMessage.ERROR, null, null); | |||
messageHandler.handleMessage(m); | |||
} else if (targetVersion!=null && targetVersion.equals(BuildOptionsAdapter.VERSION_16)) { | |||
String msg = "Java 6.0 target level is unsupported"; | |||
IMessage m = new Message(msg, IMessage.ERROR, null, null); | |||
messageHandler.handleMessage(m); | |||
} | |||
} | |||
} | |||
/** | |||
* Helper method for configureBuildOptions | |||
*/ |
@@ -164,8 +164,8 @@ public class AjcBuildOptions implements BuildOptionsAdapter { | |||
/** | |||
* JDK Compliance level to be used by the compiler, either | |||
* VERSION_13 or VERSION_14. | |||
* From -1.3 / -1.4 | |||
* VERSION_13, VERSION_14 or VERSION_15. | |||
* From -1.3 / -1.4 / -1.5 | |||
*/ | |||
public String getComplianceLevel() { | |||
return preferencesAdapter.getProjectPreference(COMPLIANCE_LEVEL); | |||
@@ -176,7 +176,7 @@ public class AjcBuildOptions implements BuildOptionsAdapter { | |||
} | |||
/** | |||
* Source compatibility level, either VERSION_13 or VERSION_14. | |||
* Source compatibility level, either VERSION_13, VERSION_14 or VERSION_15. | |||
* From -source (eclipse option) | |||
*/ | |||
public String getSourceCompatibilityLevel() { |
@@ -18,15 +18,14 @@ import java.util.Set; | |||
import junit.framework.TestSuite; | |||
import org.aspectj.ajde.NullIdeTaskListManager.SourceLineTask; | |||
import org.aspectj.ajde.internal.CompilerAdapter; | |||
import org.aspectj.ajde.ui.UserPreferencesAdapter; | |||
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.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions; | |||
import org.aspectj.util.LangUtil; | |||
/** | |||
* Tests that a correctly populated AjBuildConfig object is created | |||
@@ -40,7 +39,7 @@ public class BuildConfigurationTests extends AjdeTestCase { | |||
private AjcBuildOptions buildOptions = null; | |||
private UserPreferencesAdapter preferencesAdapter = null; | |||
private NullIdeProperties projectProperties = null; | |||
private MessageHandler messageHandler; | |||
private NullIdeTaskListManager taskListManager; | |||
private static final String configFile = | |||
AjdeTests.testDataPath("examples/figures-coverage/all.lst"); | |||
@@ -80,6 +79,48 @@ public class BuildConfigurationTests extends AjdeTestCase { | |||
assertEquals( "compliance level", CompilerOptions.VERSION_1_4, compliance); | |||
assertEquals( "source level", CompilerOptions.VERSION_1_4, sourceLevel ); | |||
} | |||
public void testCompilanceLevelJava6() { | |||
buildOptions.setComplianceLevel( BuildOptionsAdapter.VERSION_16 ); | |||
buildConfig = compilerAdapter.genBuildConfig( configFile ); | |||
assertTrue(configFile + " failed", null != buildConfig); | |||
Map options = buildConfig.getOptions().getMap(); | |||
String compliance = (String) options.get(CompilerOptions.OPTION_Compliance); | |||
String sourceLevel = (String) options.get(CompilerOptions.OPTION_Source); | |||
if (Ajde.getDefault().compilerIsJava6Compatible()) { | |||
assertEquals("expected compliance level to be 1.6 but found " + compliance, "1.6", compliance); | |||
assertEquals("expected source level to be 1.6 but found " + sourceLevel, "1.6", sourceLevel ); | |||
assertTrue("expected to 'behaveInJava5Way' but aren't",buildConfig.getBehaveInJava5Way()); | |||
} else { | |||
List l = taskListManager.getSourceLineTasks(); | |||
String expectedError = "Java 6.0 compliance level is unsupported"; | |||
String found = ((SourceLineTask)l.get(0)).getContainedMessage().getMessage(); | |||
assertEquals("Expected 'Java 6.0 compliance level is unsupported'" + | |||
" error message but found " + found ,expectedError,found); | |||
} | |||
} | |||
public void testSourceCompatibilityLevelJava6() { | |||
buildOptions.setSourceCompatibilityLevel(BuildOptionsAdapter.VERSION_16 ); | |||
buildConfig = compilerAdapter.genBuildConfig( configFile ); | |||
assertTrue(configFile + " failed", null != buildConfig); | |||
Map options = buildConfig.getOptions().getMap(); | |||
String compliance = (String) options.get(CompilerOptions.OPTION_Compliance); | |||
String sourceLevel = (String) options.get(CompilerOptions.OPTION_Source); | |||
if (Ajde.getDefault().compilerIsJava6Compatible()) { | |||
assertEquals("expected compliance level to be 1.6 but found " + compliance, "1.6", compliance); | |||
assertEquals("expected source level to be 1.6 but found " + sourceLevel, "1.6", sourceLevel ); | |||
assertTrue("expected to 'behaveInJava5Way' but aren't",buildConfig.getBehaveInJava5Way()); | |||
} else { | |||
List l = taskListManager.getSourceLineTasks(); | |||
String expectedError = "Java 6.0 source level is unsupported"; | |||
String found = ((SourceLineTask)l.get(0)).getContainedMessage().getMessage(); | |||
assertEquals("Expected 'Java 6.0 compliance level is unsupported'" + | |||
" error message but found " + found ,expectedError,found); | |||
} | |||
} | |||
public void testSourceCompatibilityLevel() { | |||
buildOptions.setComplianceLevel( BuildOptionsAdapter.VERSION_13); | |||
@@ -500,25 +541,12 @@ public class BuildConfigurationTests extends AjdeTestCase { | |||
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); | |||
} | |||
}; | |||
taskListManager = new NullIdeTaskListManager(); | |||
ErrorHandler handler = new NullIdeErrorHandler(); | |||
try { | |||
// String s = null; | |||
Ajde.init( | |||
null, | |||
null, | |||
taskListManager, | |||
null, | |||
projectProperties, | |||
buildOptions, | |||
@@ -538,7 +566,7 @@ public class BuildConfigurationTests extends AjdeTestCase { | |||
buildOptions = null; | |||
compilerAdapter = null; | |||
projectProperties = null; | |||
messageHandler = null; | |||
taskListManager = null; | |||
} | |||
private void assertOptionEquals( String reason, Map options, String optionName, String value) { |