We set the BREE to JavaSE-1.6 for 'eclipse-plugin', 'eclipse-test-plugin', and 'eclipse-feature' packaging types but we should do this for all packaging types. (eg. 'eclipse-repository', 'eclipse-application', 'eclipse-update-site')
337 lines
18 KiB
Diff
337 lines
18 KiB
Diff
From 3f23b14c4853e12d023b1e5a1a330997d034274d Mon Sep 17 00:00:00 2001
|
|
From: Roland Grunberg <rgrunber@redhat.com>
|
|
Date: Tue, 12 Jun 2012 10:38:51 -0400
|
|
Subject: [PATCH] Implement a custom resolver for Tycho in local mode.
|
|
|
|
When running in local mode, dependencies should be resolved by looking
|
|
on the local system. Remote repositories should be ignored unless
|
|
offline mode is disabled.
|
|
|
|
Automatically create a local p2 repository of all bundles on the system
|
|
so that they may be used for local dependency resolution. This is done
|
|
using a modified version of Eclipse's copy-platform script.
|
|
|
|
Since Fedora 17, we need an Execution Environment of at least JavaSE-1.6
|
|
for Eclipse bundles. Eclipse Juno platform bundles depend on
|
|
javax.annotation. In Fedora this is provided by geronimo-annotation, but
|
|
has a dependency on javax.lang.model (since 1.6).
|
|
|
|
Use the defined target environments in local mode when the property
|
|
tycho.local.keepTarget is set.
|
|
|
|
Change-Id: Ia1ece07ece2412bc4a88901631f3f651ad2b634b
|
|
---
|
|
.../tycho/p2/target/TargetDefinitionResolver.java | 10 ++--
|
|
.../tycho/p2/target/TargetPlatformBuilderImpl.java | 55 ++++++++++++++++++++--
|
|
.../core/maven/TychoMavenLifecycleParticipant.java | 16 +++++++
|
|
.../tycho/core/osgitools/AbstractTychoProject.java | 12 ++++-
|
|
.../tycho/core/osgitools/OsgiBundleProject.java | 42 ++++++++++++++++-
|
|
.../DefaultTargetPlatformConfigurationReader.java | 5 +-
|
|
.../tycho/osgi/runtime/TychoP2RuntimeLocator.java | 15 ++++++
|
|
.../p2/resolver/P2TargetPlatformResolver.java | 10 ++++
|
|
8 files changed, 153 insertions(+), 12 deletions(-)
|
|
|
|
diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetDefinitionResolver.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetDefinitionResolver.java
|
|
index 5fdc6a1..838e267 100644
|
|
--- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetDefinitionResolver.java
|
|
+++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetDefinitionResolver.java
|
|
@@ -24,6 +24,7 @@ import org.eclipse.core.runtime.CoreException;
|
|
import org.eclipse.core.runtime.IProgressMonitor;
|
|
import org.eclipse.core.runtime.IStatus;
|
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
+import org.eclipse.core.runtime.URIUtil;
|
|
import org.eclipse.equinox.p2.core.IProvisioningAgent;
|
|
import org.eclipse.equinox.p2.core.ProvisionException;
|
|
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
|
|
@@ -103,9 +104,12 @@ public class TargetDefinitionResolver {
|
|
|
|
List<IMetadataRepository> metadataRepositories = new ArrayList<IMetadataRepository>();
|
|
for (Repository repository : iuLocationDefinition.getRepositories()) {
|
|
- repositoryIdManager.addMapping(repository.getId(), repository.getLocation());
|
|
- artifactRepositories.add(repository.getLocation());
|
|
- metadataRepositories.add(loadRepository(repository));
|
|
+ // We cannot resolve a non-file URI in local mode
|
|
+ if (System.getProperty("maven.local.mode") == null || URIUtil.isFileURI(repository.getLocation())) {
|
|
+ repositoryIdManager.addMapping(repository.getId(), repository.getLocation());
|
|
+ artifactRepositories.add(repository.getLocation());
|
|
+ metadataRepositories.add(loadRepository(repository));
|
|
+ }
|
|
}
|
|
|
|
IQueryable<IInstallableUnit> locationUnits = new CompoundQueryable<IInstallableUnit>(
|
|
diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetPlatformBuilderImpl.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetPlatformBuilderImpl.java
|
|
index fa1cfab..489903e 100644
|
|
--- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetPlatformBuilderImpl.java
|
|
+++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetPlatformBuilderImpl.java
|
|
@@ -38,6 +38,9 @@ import org.eclipse.equinox.p2.core.IProvisioningAgent;
|
|
import org.eclipse.equinox.p2.core.ProvisionException;
|
|
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
|
|
import org.eclipse.equinox.p2.metadata.VersionedId;
|
|
+import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
|
|
+import org.eclipse.equinox.p2.metadata.expression.IExpression;
|
|
+import org.eclipse.equinox.p2.query.IQuery;
|
|
import org.eclipse.equinox.p2.query.IQueryResult;
|
|
import org.eclipse.equinox.p2.query.QueryUtil;
|
|
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
|
|
@@ -223,6 +226,12 @@ public class TargetPlatformBuilderImpl implements TargetPlatformBuilder {
|
|
IMetadataRepository metadataRepository = null;
|
|
IArtifactRepository artifactRepository = null;
|
|
|
|
+ // We cannot resolve a non-file URI in local mode while offline
|
|
+ if (System.getProperty("maven.local.mode") != null && offline && !URIUtil.isFileURI(location.getURL())) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+
|
|
try {
|
|
remoteRepositoryIdManager.addMapping(location.getId(), location.getURL());
|
|
|
|
@@ -359,12 +368,48 @@ public class TargetPlatformBuilderImpl implements TargetPlatformBuilder {
|
|
result.addAll(contentPart.getUnits());
|
|
}
|
|
|
|
- SubMonitor sub = SubMonitor.convert(monitor, metadataRepositories.size() * 200);
|
|
- for (IMetadataRepository repository : metadataRepositories) {
|
|
- IQueryResult<IInstallableUnit> matches = repository.query(QueryUtil.ALL_UNITS, sub.newChild(100));
|
|
- result.addAll(matches.toUnmodifiableSet());
|
|
+ if (System.getProperty("maven.local.mode") != null && !offline) {
|
|
+ final String uri = "file:" + System.getProperty("user.dir") + "/.m2/p2/repo";
|
|
+ final IExpression notmatchIU_ID = ExpressionUtil.parse("id != $0");
|
|
+ IMetadataRepository systemLocalP2Repo = null;
|
|
+
|
|
+ // Sanity check even though the repo we want should be at index 1
|
|
+ for (IMetadataRepository repository : metadataRepositories) {
|
|
+ if (repository.getLocation().toString().equals(uri)) {
|
|
+ systemLocalP2Repo = repository;
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ IQuery<IInstallableUnit> noLocalIUs = QueryUtil.createIUAnyQuery();
|
|
+
|
|
+ // Create a conjunction query that negates all IUs on the local system
|
|
+ for (IInstallableUnit unit : systemLocalP2Repo.query(QueryUtil.ALL_UNITS, null).toUnmodifiableSet()) {
|
|
+ noLocalIUs = QueryUtil.createCompoundQuery(noLocalIUs, QueryUtil.createMatchQuery(notmatchIU_ID, unit.getId()), true);
|
|
+ }
|
|
+
|
|
+ SubMonitor sub = SubMonitor.convert(monitor, metadataRepositories.size() * 200);
|
|
+ for (IMetadataRepository repository : metadataRepositories) {
|
|
+ IQueryResult<IInstallableUnit> matches;
|
|
+ if (repository.getLocation().toString().equals(uri)) {
|
|
+ matches = repository.query(QueryUtil.ALL_UNITS, sub.newChild(100));
|
|
+ } else {
|
|
+ // Don't collect any remote IUs that can be found on the system
|
|
+ // This will favour IUs in the system local p2 repository
|
|
+ matches = repository.query(noLocalIUs, sub.newChild(100));
|
|
+ }
|
|
+ result.addAll(matches.toUnmodifiableSet());
|
|
+ }
|
|
+ sub.done();
|
|
+ } else {
|
|
+ SubMonitor sub = SubMonitor.convert(monitor, metadataRepositories.size() * 200);
|
|
+ for (IMetadataRepository repository : metadataRepositories) {
|
|
+ IQueryResult<IInstallableUnit> matches = repository.query(QueryUtil.ALL_UNITS, sub.newChild(100));
|
|
+ matches = repository.query(QueryUtil.ALL_UNITS, sub.newChild(100));
|
|
+ result.addAll(matches.toUnmodifiableSet());
|
|
+ }
|
|
+ sub.done();
|
|
}
|
|
- sub.done();
|
|
|
|
if (logger.isDebugEnabled()) {
|
|
IQueryResult<IInstallableUnit> locallyInstalledIUs = localMetadataRepository.query(QueryUtil.ALL_UNITS,
|
|
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java b/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java
|
|
index 0dd2fd4..15669a6 100644
|
|
--- a/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java
|
|
+++ b/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoMavenLifecycleParticipant.java
|
|
@@ -11,6 +11,7 @@
|
|
package org.eclipse.tycho.core.maven;
|
|
|
|
import java.io.File;
|
|
+import java.io.IOException;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
@@ -55,6 +56,21 @@ public class TychoMavenLifecycleParticipant extends AbstractMavenLifecyclePartic
|
|
registerExecutionListener(session);
|
|
configureComponents(session);
|
|
|
|
+ // Create a system p2 repository for local dependency resolution
|
|
+ if (System.getProperty("maven.local.mode") != null) {
|
|
+ try {
|
|
+ String[] cmd = new String[] { "/usr/share/java/tycho/copy-platform-all",
|
|
+ System.getProperty("user.dir") + "/.m2/p2/repo" };
|
|
+ System.out.println("Building system local p2 repository...");
|
|
+ Process p = Runtime.getRuntime().exec(cmd);
|
|
+ p.waitFor();
|
|
+ } catch (IOException e) {
|
|
+ // Continue
|
|
+ } catch (InterruptedException e) {
|
|
+ // Continue
|
|
+ }
|
|
+ }
|
|
+
|
|
for (MavenProject project : projects) {
|
|
resolver.setupProject(session, project, DefaultReactorProject.adapt(project));
|
|
}
|
|
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractTychoProject.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractTychoProject.java
|
|
index 283770a..c642392 100644
|
|
--- a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractTychoProject.java
|
|
+++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractTychoProject.java
|
|
@@ -98,7 +98,17 @@ public abstract class AbstractTychoProject extends AbstractLogEnabled implements
|
|
}
|
|
|
|
try {
|
|
- return ExecutionEnvironmentUtils.getExecutionEnvironment(profile);
|
|
+ ExecutionEnvironment ee = ExecutionEnvironmentUtils.getExecutionEnvironment(profile);
|
|
+
|
|
+ if (System.getProperty("maven.local.mode") != null) {
|
|
+ // EE must be at least JavaSE-1.6
|
|
+ final ExecutionEnvironment javaSE16 = ExecutionEnvironmentUtils.getExecutionEnvironment("JavaSE-1.6");
|
|
+ if (ee.compareTo(javaSE16) < 0) {
|
|
+ ee = javaSE16;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return ee;
|
|
} catch (UnknownEnvironmentException e) {
|
|
// can't happen, ee is validated during configuration parsing
|
|
}
|
|
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/OsgiBundleProject.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/OsgiBundleProject.java
|
|
index c4b783e..e83dd72 100644
|
|
--- a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/OsgiBundleProject.java
|
|
+++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/OsgiBundleProject.java
|
|
@@ -525,12 +525,50 @@ public class OsgiBundleProject extends AbstractTychoProject implements BundlePro
|
|
if (envs.isEmpty()) {
|
|
return null;
|
|
}
|
|
- return Collections.min(envs);
|
|
+
|
|
+ ExecutionEnvironment manifestMinimalEE = Collections.min(envs);
|
|
+ ExecutionEnvironment tmp;
|
|
+
|
|
+ if (System.getProperty("maven.local.mode") != null) {
|
|
+ try {
|
|
+ // EE must be at least JavaSE-1.6
|
|
+ final ExecutionEnvironment javaSE16 = ExecutionEnvironmentUtils.getExecutionEnvironment("JavaSE-1.6");
|
|
+ while (!envs.isEmpty()) {
|
|
+ tmp = Collections.min(envs);
|
|
+ if (tmp.compareTo(javaSE16) >= 0) {
|
|
+ manifestMinimalEE = tmp;
|
|
+ break;
|
|
+ }
|
|
+ envs.remove(tmp);
|
|
+ }
|
|
+
|
|
+ if (envs.isEmpty()) {
|
|
+ return javaSE16;
|
|
+ }
|
|
+ } catch (UnknownEnvironmentException e) {
|
|
+ // Continue
|
|
+ }
|
|
+ }
|
|
+ return manifestMinimalEE;
|
|
}
|
|
|
|
protected ExecutionEnvironment getExecutionEnvironment(MavenProject project, String profile) {
|
|
try {
|
|
- return ExecutionEnvironmentUtils.getExecutionEnvironment(profile);
|
|
+ ExecutionEnvironment ee = ExecutionEnvironmentUtils.getExecutionEnvironment(profile);
|
|
+
|
|
+ if (System.getProperty("maven.local.mode") != null && ee != null) {
|
|
+ try {
|
|
+ // EE must be at least JavaSE-1.6
|
|
+ final ExecutionEnvironment javaSE16 = ExecutionEnvironmentUtils.getExecutionEnvironment("JavaSE-1.6");
|
|
+ if (ee.compareTo(javaSE16) < 0) {
|
|
+ ee = javaSE16;
|
|
+ }
|
|
+ } catch (UnknownEnvironmentException e) {
|
|
+ // Continue
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return ee;
|
|
} catch (UnknownEnvironmentException e) {
|
|
throw new RuntimeException("Unknown execution environment specified in build.properties of project "
|
|
+ project, e);
|
|
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/DefaultTargetPlatformConfigurationReader.java b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/DefaultTargetPlatformConfigurationReader.java
|
|
index c2997bc..fafb77e 100644
|
|
--- a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/DefaultTargetPlatformConfigurationReader.java
|
|
+++ b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/DefaultTargetPlatformConfigurationReader.java
|
|
@@ -66,7 +66,10 @@ public class DefaultTargetPlatformConfigurationReader {
|
|
+ configuration.toString());
|
|
}
|
|
|
|
- addTargetEnvironments(result, project, configuration);
|
|
+ // Use the defined environments only in local mode with tycho.local.keepTarget
|
|
+ if (System.getProperty("maven.local.mode") == null || System.getProperty("tycho.local.keepTarget") != null) {
|
|
+ addTargetEnvironments(result, project, configuration);
|
|
+ }
|
|
|
|
setTargetPlatformResolver(result, configuration);
|
|
|
|
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/osgi/runtime/TychoP2RuntimeLocator.java b/tycho-core/src/main/java/org/eclipse/tycho/osgi/runtime/TychoP2RuntimeLocator.java
|
|
index ff4c14a..de02644 100644
|
|
--- a/tycho-core/src/main/java/org/eclipse/tycho/osgi/runtime/TychoP2RuntimeLocator.java
|
|
+++ b/tycho-core/src/main/java/org/eclipse/tycho/osgi/runtime/TychoP2RuntimeLocator.java
|
|
@@ -22,6 +22,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
|
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
|
+import org.apache.maven.artifact.resolver.JavadirWorkspaceReader;
|
|
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
|
|
import org.apache.maven.execution.MavenSession;
|
|
import org.apache.maven.model.Dependency;
|
|
@@ -38,6 +39,7 @@ import org.eclipse.sisu.equinox.embedder.EquinoxRuntimeLocator;
|
|
import org.eclipse.tycho.dev.DevWorkspaceResolver;
|
|
import org.eclipse.tycho.locking.facade.FileLockService;
|
|
import org.eclipse.tycho.locking.facade.FileLocker;
|
|
+import org.sonatype.aether.util.artifact.DefaultArtifact;
|
|
|
|
@Component(role = EquinoxRuntimeLocator.class)
|
|
public class TychoP2RuntimeLocator implements EquinoxRuntimeLocator {
|
|
@@ -189,6 +191,19 @@ public class TychoP2RuntimeLocator implements EquinoxRuntimeLocator {
|
|
Artifact artifact = repositorySystem.createArtifact(dependency.getGroupId(), dependency.getArtifactId(),
|
|
dependency.getVersion(), dependency.getType());
|
|
|
|
+ // If we are in local mode, find the artifact on the system
|
|
+ if (System.getProperty("maven.local.mode") != null) {
|
|
+ JavadirWorkspaceReader wReader = new JavadirWorkspaceReader();
|
|
+ DefaultArtifact newArtifact = new DefaultArtifact(artifact.getGroupId()
|
|
+ + ":" + artifact.getArtifactId()
|
|
+ + ":" + artifact.getType()
|
|
+ + ":" + artifact.getVersion());
|
|
+ File file = wReader.findArtifact(newArtifact);
|
|
+ if (file != null) {
|
|
+ artifact.setFile(file);
|
|
+ }
|
|
+ }
|
|
+
|
|
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
|
|
request.setArtifact(artifact);
|
|
request.setResolveRoot(true).setResolveTransitively(false);
|
|
diff --git a/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/resolver/P2TargetPlatformResolver.java b/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/resolver/P2TargetPlatformResolver.java
|
|
index 4db1bd4..b45a4ea 100644
|
|
--- a/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/resolver/P2TargetPlatformResolver.java
|
|
+++ b/tycho-p2/tycho-p2-facade/src/main/java/org/eclipse/tycho/p2/resolver/P2TargetPlatformResolver.java
|
|
@@ -193,6 +193,16 @@ public class P2TargetPlatformResolver extends AbstractTargetPlatformResolver imp
|
|
tpBuilder.setProjectLocation(project.getBasedir());
|
|
tpBuilder.setIncludePackedArtifacts(configuration.isIncludePackedArtifacts());
|
|
|
|
+ // Add Fedora Local P2 Repository when running in local mode
|
|
+ if (System.getProperty("maven.local.mode") != null) {
|
|
+ String uri = "file:" + System.getProperty("user.dir") + "/.m2/p2/repo";
|
|
+ try {
|
|
+ tpBuilder.addP2Repository(new MavenRepositoryLocation(uri, new URI(uri)));
|
|
+ } catch (URISyntaxException e) {
|
|
+ getLogger().warn("Unable to resolve repository URI : " + uri, e);
|
|
+ }
|
|
+ }
|
|
+
|
|
addThisReactorProjectToTargetPlatform(session, project, configuration, tpBuilder);
|
|
|
|
addOtherReactorProjectsToTargetPlatform(project, reactorProjects, tpBuilder);
|
|
--
|
|
1.7.11.4
|
|
|