tycho/tycho-use-custom-resolver.patch

365 lines
20 KiB
Diff
Raw Normal View History

From 4df42326a0bc35ec82cda69c5d74e9b5d55d30d7 Mon Sep 17 00:00:00 2001
From: Roland Grunberg <rgrunber@redhat.com>
2012-06-12 15:06:31 +00:00
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.
2012-06-12 15:06:31 +00:00
Change-Id: Ia1ece07ece2412bc4a88901631f3f651ad2b634b
---
.../tycho/p2/target/TargetDefinitionResolver.java | 10 ++--
.../tycho/p2/target/TargetPlatformBuilderImpl.java | 55 ++++++++++++++++++++--
.../core/maven/TychoMavenLifecycleParticipant.java | 16 +++++++
2012-09-24 21:06:48 +00:00
.../tycho/core/osgitools/AbstractTychoProject.java | 24 ++++++++++
.../tycho/core/osgitools/OsgiBundleProject.java | 29 +++++++++++-
.../DefaultTargetPlatformConfigurationReader.java | 5 +-
2012-09-24 21:06:48 +00:00
.../osgi/runtime/TychoOsgiRuntimeLocator.java | 15 ++++++
.../p2/resolver/P2TargetPlatformResolver.java | 10 ++++
2012-09-24 21:06:48 +00:00
8 files changed, 154 insertions(+), 10 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
2012-09-24 21:06:48 +00:00
index 5cc8718..5513dda 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;
2012-09-24 21:06:48 +00:00
@@ -104,9 +105,12 @@ public class TargetDefinitionResolver {
List<IMetadataRepository> metadataRepositories = new ArrayList<IMetadataRepository>();
for (Repository repository : iuLocationDefinition.getRepositories()) {
2012-08-07 14:44:21 +00:00
- 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())) {
2012-08-07 14:44:21 +00:00
+ 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 d1cd5da..1cc4050 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;
2012-09-24 21:06:48 +00:00
@@ -231,6 +234,12 @@ public class TargetPlatformBuilderImpl implements TargetPlatformBuilder {
2012-06-12 15:06:31 +00:00
IMetadataRepository metadataRepository = null;
IArtifactRepository artifactRepository = null;
+ // We cannot resolve a non-file URI in local mode while offline
2012-08-07 14:44:21 +00:00
+ if (System.getProperty("maven.local.mode") != null && offline && !URIUtil.isFileURI(location.getURL())) {
+ return;
+ }
2012-06-12 15:06:31 +00:00
+
+
try {
2012-08-07 14:44:21 +00:00
remoteRepositoryIdManager.addMapping(location.getId(), location.getURL());
2012-09-24 21:06:48 +00:00
@@ -367,12 +376,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 cccb6ff..9e8268d 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;
2012-09-24 21:06:48 +00:00
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -73,6 +74,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));
2012-06-12 15:06:31 +00:00
}
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 695133d..5a698a2 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
2012-09-24 21:06:48 +00:00
@@ -20,6 +20,9 @@ import org.eclipse.tycho.artifacts.TargetPlatform;
import org.eclipse.tycho.core.TargetPlatformConfiguration;
import org.eclipse.tycho.core.TychoConstants;
import org.eclipse.tycho.core.TychoProject;
+import org.eclipse.tycho.core.ee.ExecutionEnvironmentUtils;
+import org.eclipse.tycho.core.ee.UnknownEnvironmentException;
+import org.eclipse.tycho.core.ee.shared.ExecutionEnvironment;
import org.eclipse.tycho.core.ee.shared.ExecutionEnvironmentConfiguration;
import org.eclipse.tycho.core.facade.TargetEnvironment;
import org.eclipse.tycho.core.osgitools.targetplatform.LocalTargetPlatformResolver;
@@ -92,17 +95,38 @@ public abstract class AbstractTychoProject extends AbstractLogEnabled implements
2012-06-12 15:06:31 +00:00
2012-09-24 21:06:48 +00:00
String configuredForcedProfile = tpConfiguration.getExecutionEnvironment();
if (configuredForcedProfile != null) {
+ configuredForcedProfile = overrideToAtLeastJavaSE16(configuredForcedProfile);
2012-09-24 21:06:48 +00:00
sink.overrideProfileConfiguration(configuredForcedProfile,
"target-platform-configuration <executionEnvironment>");
}
String configuredDefaultProfile = tpConfiguration.getExecutionEnvironmentDefault();
if (configuredDefaultProfile != null) {
+ configuredDefaultProfile = overrideToAtLeastJavaSE16(configuredDefaultProfile);
2012-09-24 21:06:48 +00:00
sink.setProfileConfiguration(configuredDefaultProfile,
"target-platform-configuration <executionEnvironmentDefault>");
}
}
+ public String overrideToAtLeastJavaSE16 (String profile) {
+ try {
+ ExecutionEnvironment ee = ExecutionEnvironmentUtils.getExecutionEnvironment(profile);
2012-06-12 15:06:31 +00:00
+
2012-09-24 21:06:48 +00:00
+ 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.isCompatibleCompilerTargetLevel(javaSE16.getCompilerTargetLevel())) {
+ ee = javaSE16;
2012-06-12 15:06:31 +00:00
+ }
2012-09-24 21:06:48 +00:00
+ }
2012-06-12 15:06:31 +00:00
+
2012-09-24 21:06:48 +00:00
+ return ee.getProfileName();
+ } catch (UnknownEnvironmentException e) {
+ // can't happen, ee is validated during configuration parsing
+ return null;
+ }
+ }
+
public TargetPlatform getTargetPlatform(MavenProject project) {
return (TargetPlatform) project.getContextValue(TychoConstants.CTX_TARGET_PLATFORM);
}
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
2012-09-24 21:06:48 +00:00
index fb73469..efe97ae 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
2012-09-24 21:06:48 +00:00
@@ -45,7 +45,9 @@ import org.eclipse.tycho.core.BundleProject;
import org.eclipse.tycho.core.PluginDescription;
import org.eclipse.tycho.core.TychoConstants;
import org.eclipse.tycho.core.TychoProject;
+import org.eclipse.tycho.core.ee.ExecutionEnvironmentUtils;
import org.eclipse.tycho.core.ee.StandardExecutionEnvironment;
+import org.eclipse.tycho.core.ee.UnknownEnvironmentException;
import org.eclipse.tycho.core.ee.shared.ExecutionEnvironment;
import org.eclipse.tycho.core.ee.shared.ExecutionEnvironmentConfiguration;
import org.eclipse.tycho.core.facade.BuildPropertiesParser;
@@ -492,6 +494,7 @@ public class OsgiBundleProject extends AbstractTychoProject implements BundlePro
String pdeProfile = getEclipsePluginProject(DefaultReactorProject.adapt(project)).getBuildProperties()
.getJreCompilationProfile();
if (pdeProfile != null) {
+ pdeProfile = overrideToAtLeastJavaSE16(pdeProfile);
sink.setProfileConfiguration(pdeProfile.trim(), "build.properties");
} else {
@@ -509,7 +512,31 @@ public class OsgiBundleProject extends AbstractTychoProject implements BundlePro
2012-08-07 14:44:21 +00:00
if (envs.isEmpty()) {
return null;
}
2012-08-07 14:44:21 +00:00
- 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);
2012-09-24 21:06:48 +00:00
+ if (tmp.isCompatibleCompilerTargetLevel(javaSE16.getCompilerTargetLevel())) {
+ manifestMinimalEE = tmp;
+ break;
+ }
+ envs.remove(tmp);
+ }
+
+ if (envs.isEmpty()) {
+ return javaSE16;
+ }
+ } catch (UnknownEnvironmentException e) {
+ // Continue
+ }
+ }
2012-08-07 14:44:21 +00:00
+ return manifestMinimalEE;
}
2012-09-24 21:06:48 +00:00
}
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
2012-09-24 21:06:48 +00:00
index e5efab5..8628d7a 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
2012-09-24 21:06:48 +00:00
@@ -64,7 +64,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);
2012-09-24 21:06:48 +00:00
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/osgi/runtime/TychoOsgiRuntimeLocator.java b/tycho-core/src/main/java/org/eclipse/tycho/osgi/runtime/TychoOsgiRuntimeLocator.java
index 9935c5f..0885aea 100644
--- a/tycho-core/src/main/java/org/eclipse/tycho/osgi/runtime/TychoOsgiRuntimeLocator.java
+++ b/tycho-core/src/main/java/org/eclipse/tycho/osgi/runtime/TychoOsgiRuntimeLocator.java
2012-08-07 14:44:21 +00:00
@@ -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;
2012-08-07 14:44:21 +00:00
@@ -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;
2012-09-24 21:06:48 +00:00
/**
* Implementation of {@link org.eclipse.sisu.equinox.embedder.EquinoxRuntimeLocator} for Tycho's
@@ -201,6 +203,19 @@ public class TychoOsgiRuntimeLocator implements EquinoxRuntimeLocator {
2012-08-07 14:44:21 +00:00
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);
+ }
+ }
+
2012-08-07 14:44:21 +00:00
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
2012-09-24 21:06:48 +00:00
index 0d4d61e..ef3264d 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
2012-09-24 21:06:48 +00:00
@@ -191,6 +191,16 @@ public class P2TargetPlatformResolver extends AbstractTargetPlatformResolver imp
tpBuilder.setProjectLocation(project.getBasedir());
2012-06-12 15:06:31 +00:00
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 {
2012-08-07 14:44:21 +00:00
+ 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