When in local mode, but not offline, Tycho should favour local system dependencies over remote ones in all cases.
352 lines
19 KiB
Diff
352 lines
19 KiB
Diff
From 595646a547fca48d8211b29f9951190ba737f42a 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 +++++++
|
|
.../core/osgitools/EclipseFeatureProject.java | 22 +++++++++
|
|
.../tycho/core/osgitools/OsgiBundleProject.java | 42 ++++++++++++++++-
|
|
.../DefaultTargetPlatformConfigurationReader.java | 5 +-
|
|
.../tycho/osgi/runtime/TychoP2RuntimeLocator.java | 15 ++++++
|
|
.../p2/resolver/P2TargetPlatformResolver.java | 10 ++++
|
|
8 files changed, 164 insertions(+), 11 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/EclipseFeatureProject.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/EclipseFeatureProject.java
|
|
index 0fe42a6..1bc3a6e 100644
|
|
--- a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/EclipseFeatureProject.java
|
|
+++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/EclipseFeatureProject.java
|
|
@@ -21,6 +21,9 @@ import org.eclipse.tycho.core.ArtifactDependencyVisitor;
|
|
import org.eclipse.tycho.core.ArtifactDependencyWalker;
|
|
import org.eclipse.tycho.core.TychoProject;
|
|
import org.eclipse.tycho.core.facade.TargetEnvironment;
|
|
+import org.eclipse.tycho.core.UnknownEnvironmentException;
|
|
+import org.eclipse.tycho.core.utils.ExecutionEnvironment;
|
|
+import org.eclipse.tycho.core.utils.ExecutionEnvironmentUtils;
|
|
import org.eclipse.tycho.model.Feature;
|
|
|
|
@Component(role = TychoProject.class, hint = org.eclipse.tycho.ArtifactKey.TYPE_ECLIPSE_FEATURE)
|
|
@@ -49,4 +52,23 @@ public class EclipseFeatureProject extends AbstractArtifactBasedProject {
|
|
Feature.loadFeature(project.getBasedir());
|
|
}
|
|
|
|
+ @Override
|
|
+ public ExecutionEnvironment getExecutionEnvironment(MavenProject project) {
|
|
+ ExecutionEnvironment ee = super.getExecutionEnvironment(project);
|
|
+
|
|
+ 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;
|
|
+ }
|
|
+
|
|
}
|
|
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.2
|
|
|