Permalink
Browse files

387796 Make J2SE-1.5 the global execution environment default

- If no execution environment is configured, use J2SE-1.5. This implies
  the following behaviour changes if there is no execution environment
  configuration at all (i.e. neither in POM, build.properties, nor
  manifest):
-- The p2 target platform and dependency resolvers would resolve against
   1.5 instead of 1.6.
-- The compile class path would be restricted to the J2SE-1.5 packages
   instead of allowing the use of everything in the JDK.
- This also leads to a minor performance improvement, because ee=null no
  longer occurs and therefore there are more hits in the target file
  resolver cache (bug 380271).
- Deleted the logic that tried to guess the execution environment
  corresponding to the running JRE.

Bug: 387796
Bug: 380271
Change-Id: Ic29cd079ac178246f609d770c60aaa87865db1df
  • Loading branch information...
1 parent bd6e75e commit e751feb410f20b2d7ffc3cee89fe5d71484c94c6 @oberlies oberlies committed Nov 7, 2012
@@ -1,5 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: bundle.nobree
-Bundle-Version: 1.0.0
-Import-Package: org.w3c.dom
@@ -361,29 +361,6 @@ public void resolutionEE() throws Exception {
}
@Test
- public void resolutionNoEE() throws Exception {
- // TODO 387796 is this the null meaning no explicit configuration? if yes, this may be dropped with bug 387796
- context = createTargetPlatformBuilderWithEE((String) null);
-
- context.addP2Repository(resourceFile("repositories/javax.xml").toURI());
-
- File bundle = resourceFile("resolver/bundle.nobree");
- String artifactId = "bundle.nobree";
- addReactorProject(bundle, TYPE_ECLIPSE_PLUGIN, artifactId);
-
- List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), bundle);
-
- Assert.assertEquals(1, results.size());
- P2ResolutionResult result = results.get(0);
-
- Assert.assertEquals(1, result.getArtifacts().size());
-
- Assert.assertEquals(2, result.getNonReactorUnits().size());
- assertContainsUnit("a.jre.javase", result.getNonReactorUnits());
- assertContainsUnit("config.a.jre.javase", result.getNonReactorUnits());
- }
-
- @Test
public void resolutionCustomEE() throws Exception {
context = createTargetPlatformBuilderWithCustomEE("Custom_Profile-2");
@@ -41,6 +41,11 @@
private final Map<VersionedId, IInstallableUnit> temporaryUnits;
public StandardEEResolutionHints(String executionEnvironment) {
+ if (executionEnvironment == null) {
+ // don't specify a default here; ExecutionEnvironmentConfiguration does the defaulting
+ throw new NullPointerException();
+ }
+
this.executionEnvironment = executionEnvironment;
this.additionalUnits = computeAdditionalUnits(executionEnvironment);
this.temporaryUnits = computeTemporaryAdditions(additionalUnits);
@@ -65,7 +65,6 @@
import org.eclipse.tycho.core.utils.MavenArtifactRef;
import org.eclipse.tycho.core.utils.TychoProjectUtils;
import org.eclipse.tycho.runtime.Adaptable;
-import org.osgi.framework.Constants;
import copied.org.apache.maven.plugin.AbstractCompilerMojo;
import copied.org.apache.maven.plugin.CompilationFailureException;
@@ -223,9 +222,8 @@
public void execute() throws MojoExecutionException, CompilationFailureException {
ExecutionEnvironment minimalBREE = getBundleProject().getManifestMinimalEE(project);
- ExecutionEnvironment bree = getTargetExecutionEnvironment();
getLog().debug("Manifest minimal BREE: " + (minimalBREE != null ? minimalBREE.toString() : "<null>"));
- getLog().debug("Effective BREE: " + (bree != null ? bree.toString() : "<null>"));
+ getLog().debug("Effective EE: " + getTargetExecutionEnvironment());
String effectiveTargetLevel = getTargetLevel();
getLog().debug("Effective source/target: " + getSourceLevel() + "/" + effectiveTargetLevel);
@@ -429,15 +427,12 @@ private void configureBootclasspathAccessRules(CompilerConfiguration compilerCon
accessRules.add(new DefaultAccessRule("java/**", false));
accessRules.addAll(getStrictSystemBundleAccessRules());
} else {
- ExecutionEnvironment environment = getTargetExecutionEnvironment();
- if (environment != null) {
- accessRules.add(new DefaultAccessRule("java/**", false));
- for (String pkg : environment.getSystemPackages()) {
- accessRules.add(new DefaultAccessRule(pkg.trim().replace('.', '/') + "/*", false));
- }
- // now add packages exported by framework extension bundles
- accessRules.addAll(((BundleProject) getBundleProject()).getBootClasspathExtraAccessRules(project));
+ accessRules.add(new DefaultAccessRule("java/**", false));
+ for (String pkg : getTargetExecutionEnvironment().getSystemPackages()) {
+ accessRules.add(new DefaultAccessRule(pkg.trim().replace('.', '/') + "/*", false));
}
+ // now add packages exported by framework extension bundles
+ accessRules.addAll(((BundleProject) getBundleProject()).getBootClasspathExtraAccessRules(project));
}
if (accessRules.size() > 0) {
compilerConfiguration
@@ -459,16 +454,9 @@ private void configureJavaHome(CompilerConfiguration compilerConfiguration) thro
if (useJDK != JDKUsage.BREE) {
return;
}
- ExecutionEnvironment environment = getTargetExecutionEnvironment();
- if (environment == null) {
- getLog().warn(
- "useJDK = BREE configured, but bundle has no " + Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT
- + " header. Compiling with current JDK.");
- } else {
- DefaultJavaToolChain toolChain = findMatchingJavaToolChain(environment);
- compilerConfiguration.addCompilerCustomArgument("use.java.home", toolChain.getJavaHome());
- configureBootClassPath(compilerConfiguration, toolChain);
- }
+ DefaultJavaToolChain toolChain = findMatchingJavaToolChain(getTargetExecutionEnvironment());
+ compilerConfiguration.addCompilerCustomArgument("use.java.home", toolChain.getJavaHome());
+ configureBootClassPath(compilerConfiguration, toolChain);
}
private void configureBootClassPath(CompilerConfiguration compilerConfiguration, DefaultJavaToolChain javaToolChain) {
@@ -547,6 +535,7 @@ private void configureSourceAndTargetLevel(CompilerConfiguration compilerConfigu
}
private ExecutionEnvironment getTargetExecutionEnvironment() throws MojoExecutionException {
+ // never null
return TychoProjectUtils.getExecutionEnvironmentConfiguration(project).getFullSpecification();
}
@@ -591,16 +580,15 @@ private ExecutionEnvironment getTargetExecutionEnvironment() throws MojoExecutio
}
public String getExecutionEnvironment() throws MojoExecutionException {
- ExecutionEnvironment env = getTargetExecutionEnvironment();
- return env != null ? env.getProfileName() : null;
+ return getTargetExecutionEnvironment().getProfileName();
}
public String getSourceLevel() throws MojoExecutionException {
return getSourceLevel(getTargetExecutionEnvironment());
}
- private String getSourceLevel(ExecutionEnvironment env) throws MojoExecutionException {
- // first, explicit pom configuration
+ private String getSourceLevel(ExecutionEnvironment ee) throws MojoExecutionException {
+ // first, explicit POM configuration
if (source != null) {
return source;
}
@@ -609,23 +597,21 @@ private String getSourceLevel(ExecutionEnvironment env) throws MojoExecutionExce
if (javacSource != null) {
return javacSource;
}
- // then, BREE
- if (env != null) {
- String compilerSourceLevel = env.getCompilerSourceLevelDefault();
- // TODO 387796 never null?
- if (compilerSourceLevel != null) {
- return compilerSourceLevel;
- }
+ // then, execution environment
+ String eeSource = ee.getCompilerSourceLevelDefault();
+ if (eeSource != null) {
+ return eeSource;
}
+
return DEFAULT_SOURCE_VERSION;
}
public String getTargetLevel() throws MojoExecutionException {
return getTargetLevel(getTargetExecutionEnvironment());
}
- public String getTargetLevel(ExecutionEnvironment env) throws MojoExecutionException {
- // first, explicit pom configuration
+ public String getTargetLevel(ExecutionEnvironment ee) throws MojoExecutionException {
+ // first, explicit POM configuration
if (target != null) {
return target;
}
@@ -634,14 +620,12 @@ public String getTargetLevel(ExecutionEnvironment env) throws MojoExecutionExcep
if (javacTarget != null) {
return javacTarget;
}
- // then, BREE
- // TODO 387796 never null?
- if (env != null) {
- String eeTarget = env.getCompilerTargetLevelDefault();
- if (eeTarget != null) {
- return eeTarget;
- }
+ // then, execution environment
+ String eeTarget = ee.getCompilerTargetLevelDefault();
+ if (eeTarget != null) {
+ return eeTarget;
}
+
return DEFAULT_TARGET_VERSION;
}
@@ -18,15 +18,17 @@
import org.eclipse.tycho.core.ee.shared.SystemCapability;
public class ExecutionEnvironmentConfigurationImpl implements ExecutionEnvironmentConfiguration {
+ private static final String DEFAULT_EXECUTION_ENVIRONMENT = "J2SE-1.5";
+
private static final int PRIMARY = 0;
private static final int SECONDARY = 1;
private Logger logger;
/** Configurations, ordered by precedence */
private final ProfileConfiguration[] configurations = new ProfileConfiguration[2];
- private boolean configurationFreeze = false;
+ private String effectiveProfileName = null;
private CustomExecutionEnvironment customExecutionEnvironment;
public ExecutionEnvironmentConfigurationImpl(Logger logger) {
@@ -53,44 +55,33 @@ public void setProfileConfiguration(String profileName, String configurationOrig
}
private void checkConfigurationMutable() throws IllegalStateException {
- if (configurationFreeze) {
+ if (effectiveProfileName != null) {
throw new IllegalStateException("Cannot change execution environment configuration after it has been used");
}
}
- private ProfileConfiguration getEffectiveConfiguration() {
- // disallow further configuration changes
- boolean freezeTriggered = !configurationFreeze;
- configurationFreeze = true;
+ public String getProfileName() {
+ if (effectiveProfileName == null) {
+ // this also disallows further configuration changes
+ effectiveProfileName = computeEffectiveProfileName();
+ }
+ return effectiveProfileName;
+ }
+ private String computeEffectiveProfileName() {
for (ProfileConfiguration entry : configurations) {
if (entry != null) {
-
- if (freezeTriggered) {
- logger.debug("Using execution environment '" + entry.profileName + "' configured in "
- + entry.origin);
- }
-
- return entry;
+ logger.debug("Using execution environment '" + entry.profileName + "' configured in " + entry.origin);
+ return entry.profileName;
}
}
- return null;
- }
- public String getProfileName() {
- ProfileConfiguration configuration = getEffectiveConfiguration();
- if (configuration == null) {
- // TODO 387796 return explicit global default instead of null
- return null;
- }
- return configuration.profileName;
+ logger.debug("Using default execution environment '" + DEFAULT_EXECUTION_ENVIRONMENT + "'");
+ return DEFAULT_EXECUTION_ENVIRONMENT;
}
public boolean isCustomProfile() {
String profileName = getProfileName();
- if (profileName == null) {
- return false;
- }
// TODO 385930 add explicit method for this in ExecutionEnvironmentUtils
try {
@@ -123,17 +114,7 @@ public ExecutionEnvironment getFullSpecification() throws IllegalStateException
return customExecutionEnvironment;
}
- ProfileConfiguration configuration = getEffectiveConfiguration();
- if (configuration == null) {
- // TODO 387796 return explicit global default instead of null
- return null;
- }
- try {
- return ExecutionEnvironmentUtils.getExecutionEnvironment(configuration.profileName);
- } catch (UnknownEnvironmentException e) {
- throw new IllegalArgumentException("Invalid execution environment '" + configuration.profileName
- + "' configured in " + configuration.origin, e);
- }
+ return ExecutionEnvironmentUtils.getExecutionEnvironment(getProfileName());
}
private static class ProfileConfiguration {
Oops, something went wrong.

0 comments on commit e751feb

Please sign in to comment.