Skip to content

Commit

Permalink
395281 allow to resolve without reactor project nor local repo
Browse files Browse the repository at this point in the history
- used for resolving the runtime of eclipserun-plugin
  independent of the project and its target platform

- add setter to TargetPlatformBuilder to control whether IUs installed
  in local maven repo should be part of the target platform

Bug: 395281
Change-Id: Idba050a286c0f657093d8c28196ddd2d9358a83f
  • Loading branch information
jsievers committed Jan 18, 2013
1 parent 2e3faf9 commit 08631a0
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 105 deletions.
Expand Up @@ -29,7 +29,6 @@
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.tycho.p2.impl.repo.FileBasedTychoRepositoryIndex;
import org.eclipse.tycho.p2.repository.GAV;
import org.eclipse.tycho.p2.repository.LocalRepositoryReader;
import org.eclipse.tycho.p2.repository.RepositoryLayoutHelper;
import org.eclipse.tycho.p2.repository.TychoRepositoryIndex;
Expand Down Expand Up @@ -61,21 +60,6 @@ private LocalMetadataRepository createRepository(File location) throws Provision
return new LocalMetadataRepository(location.toURI(), metadataIndex);
}

@Test
public void testIncludeInTargetPlatformFalse() throws Exception {
LocalMetadataRepository repository = createRepository(tempFolder.newFolder());
repository.setIncludeInTargetPlatform(false);
InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
iud.setId("test");
iud.setVersion(Version.parseVersion("1.0.0"));
IInstallableUnit iu = MetadataFactory.createInstallableUnit(iud);
repository.addInstallableUnit(iu, new GAV("groupId", "artifactId", "version"));

IQueryResult<IInstallableUnit> result = repository.query(QueryUtil.ALL_UNITS, monitor);
ArrayList<IInstallableUnit> allius = new ArrayList<IInstallableUnit>(result.toSet());
Assert.assertEquals(0, allius.size());
}

@Test
public void addInstallableUnit() throws CoreException {
File location = new File("target/metadataRepo");
Expand Down
Expand Up @@ -14,15 +14,10 @@
import java.io.IOException;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.CollectionResult;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.tycho.p2.maven.repository.AbstractMavenMetadataRepository;
import org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO;
import org.eclipse.tycho.p2.repository.GAV;
Expand All @@ -33,8 +28,6 @@
public class LocalMetadataRepository extends AbstractMavenMetadataRepository {

private Set<GAV> changedGAVs = new LinkedHashSet<GAV>();
// TODO this shouldn't be handled here
private boolean includeInTargetPlatform = true;

/**
* Create new repository
Expand All @@ -56,15 +49,6 @@ public LocalMetadataRepository(URI location, TychoRepositoryIndex projectIndex,
super(location, projectIndex, contentLocator);
}

@Override
public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) {
if (includeInTargetPlatform) {
return super.query(query, monitor);
} else {
return new CollectionResult<IInstallableUnit>(Collections.<IInstallableUnit> emptyList());
}
}

@Override
public void addInstallableUnits(Collection<IInstallableUnit> newUnits) {
for (IInstallableUnit unit : newUnits) {
Expand Down Expand Up @@ -128,12 +112,4 @@ public boolean isModifiable() {
return true;
}

public void setIncludeInTargetPlatform(boolean value) {
this.includeInTargetPlatform = value;
}

public boolean getIncludeInTargetPlatform() {
return includeInTargetPlatform;
}

}
Expand Up @@ -60,7 +60,7 @@ public void basic() throws Exception {
String artifactId = "org.eclipse.tycho.p2.impl.resolver.test.bundle01";
addReactorProject(bundle, TYPE_ECLIPSE_PLUGIN, artifactId);

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), bundle);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), bundle);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand Down Expand Up @@ -116,7 +116,7 @@ public void duplicateInstallableUnit() throws Exception {
addReactorProject(resourceFile("duplicate-iu/featureA2"), TYPE_ECLIPSE_FEATURE, "featureA2");

try {
impl.resolveProject(context.buildTargetPlatform(), projectLocation);
impl.resolveDependencies(context.buildTargetPlatform(), projectLocation);
fail();
} catch (DuplicateReactorIUsException e) {
// TODO proper assertion
Expand All @@ -129,7 +129,7 @@ public void featureInstallableUnits() throws Exception {
String artifactId = "org.eclipse.tycho.p2.impl.resolver.test.feature01";
addReactorProject(feature, TYPE_ECLIPSE_FEATURE, artifactId);

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), feature);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), feature);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand All @@ -156,7 +156,7 @@ public void sourceBundle() throws Exception {
sb.setDependencyMetadata(metadata);
context.addReactorArtifact(sb);

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), feature);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), feature);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand Down Expand Up @@ -188,7 +188,7 @@ public void eclipseRepository() throws Exception {

addContextProject(resourceFile("resolver/bundle01"), TYPE_ECLIPSE_PLUGIN);

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), projectDir);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), projectDir);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand All @@ -208,7 +208,7 @@ public void bundleUsesSWT() throws Exception {
String artifactId = "org.eclipse.tycho.p2.impl.resolver.test.bundleUsesSWT";
addReactorProject(bundle, TYPE_ECLIPSE_PLUGIN, artifactId);

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), bundle);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), bundle);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand All @@ -227,7 +227,7 @@ public void swt() throws Exception {
File swtFragment = resourceFile("resolver/swt/swtFragment");
addReactorProject(swtFragment, TYPE_ECLIPSE_PLUGIN, "org.eclipse.tycho.p2.impl.resolver.test.swtFragment");

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), swt);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), swt);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand All @@ -243,7 +243,7 @@ public void swtFragment() throws Exception {
File swtFragment = resourceFile("resolver/swt/swtFragment");
addReactorProject(swtFragment, TYPE_ECLIPSE_PLUGIN, "org.eclipse.tycho.p2.impl.resolver.test.swtFragment");

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), swtFragment);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), swtFragment);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand All @@ -262,7 +262,7 @@ public void swtFragmentWithRemoteSWT() throws Exception {
File swtFragment = resourceFile("resolver/swt/swtFragment");
addReactorProject(swtFragment, TYPE_ECLIPSE_PLUGIN, "org.eclipse.tycho.p2.impl.resolver.test.swtFragment");

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), swtFragment);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), swtFragment);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand Down Expand Up @@ -299,7 +299,7 @@ public void reactorVsExternal() throws Exception {
File featureProject = resourceFile("reactor-vs-external/feature01");
addReactorProject(featureProject, TYPE_ECLIPSE_FEATURE, "org.sonatype.tycho.p2.impl.resolver.test.feature01");

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), featureProject);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), featureProject);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand All @@ -322,7 +322,7 @@ public void resolutionRestrictedEE() throws Exception {
String artifactId = "bundle.bree";
addReactorProject(bundle, TYPE_ECLIPSE_PLUGIN, artifactId);

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), bundle);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), bundle);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand All @@ -345,7 +345,7 @@ public void resolutionEE() throws Exception {
String artifactId = "bundle.bree";
addReactorProject(bundle, TYPE_ECLIPSE_PLUGIN, artifactId);

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), bundle);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), bundle);

Assert.assertEquals(1, results.size());
P2ResolutionResult result = results.get(0);
Expand All @@ -368,7 +368,7 @@ public void resolutionCustomEE() throws Exception {
File bundle = resourceFile("resolver/bundleRequiringVersionedJDKPackage");
addReactorProject(bundle, TYPE_ECLIPSE_PLUGIN, "bundleRequiringVersionedJDKPackage");

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), bundle);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), bundle);

assertThat(results.size(), is(1));
P2ResolutionResult result = results.get(0); // huh?
Expand All @@ -389,7 +389,7 @@ public void featureMultienvP2Inf() throws Exception {
String artifactId = "feature.multienv.p2-inf";
addReactorProject(bundle, TYPE_ECLIPSE_FEATURE, artifactId);

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), bundle);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), bundle);

Assert.assertEquals(2, results.size());

Expand Down Expand Up @@ -417,7 +417,7 @@ public void productMultienvP2Inf() throws Exception {
String artifactId = "product.multienv.p2-inf";
addReactorProject(bundle, TYPE_ECLIPSE_REPOSITORY, artifactId);

List<P2ResolutionResult> results = impl.resolveProject(context.buildTargetPlatform(), bundle);
List<P2ResolutionResult> results = impl.resolveDependencies(context.buildTargetPlatform(), bundle);

Assert.assertEquals(2, results.size());

Expand Down
Expand Up @@ -111,15 +111,15 @@ protected final TargetPlatformBuilderImpl createTargetPlatformBuilderWithEE(Stri

protected final TargetPlatformBuilderImpl createTargetPlatformBuilderWithEE(
ExecutionEnvironmentResolutionHandler eeResolutionHandler) throws Exception {
return new TestTargetPlatformBuilderFactory().createTargetPlatformBuider(eeResolutionHandler);
return new TestTargetPlatformBuilderFactory().createTargetPlatformBuilder(eeResolutionHandler);
}

protected final TargetPlatformBuilderImpl createTargetPlatformBuilderWithCustomEE(String customEE) throws Exception {
return new TestTargetPlatformBuilderFactory()
.createTargetPlatformBuilder(new CustomEEResolutionHints(customEE));
}

private static class TestTargetPlatformBuilderFactory {
static class TestTargetPlatformBuilderFactory {

private MavenContext mavenContext;
private TargetDefinitionResolverService targetDefinitionResolverService;
Expand All @@ -140,6 +140,14 @@ private static class TestTargetPlatformBuilderFactory {
localArtifactRepo = new LocalArtifactRepository(localRepoIndices, localRepositoryReader);
}

public LocalMetadataRepository getLocalMetadataRepository() {
return localMetadataRepo;
}

public TargetPlatformBuilderImpl createTargetPlatformBuilder() throws Exception {
return createTargetPlatformBuilder(new NoopEEResolverHints());
}

public TargetPlatformBuilderImpl createTargetPlatformBuilder(
ExecutionEnvironmentResolutionHints executionEnvironment) throws Exception {
ExecutionEnvironmentResolutionHandler eeHandler = new ExecutionEnvironmentResolutionHandler(
Expand All @@ -151,10 +159,10 @@ public void readFullSpecification(Collection<IInstallableUnit> targetPlatformCon
}
};

return createTargetPlatformBuider(eeHandler);
return createTargetPlatformBuilder(eeHandler);
}

public TargetPlatformBuilderImpl createTargetPlatformBuider(ExecutionEnvironmentResolutionHandler eeHandler)
public TargetPlatformBuilderImpl createTargetPlatformBuilder(ExecutionEnvironmentResolutionHandler eeHandler)
throws ProvisionException {
return new TargetPlatformBuilderImpl(new RemoteAgent(mavenContext), mavenContext,
targetDefinitionResolverService, eeHandler, localArtifactRepo, localMetadataRepo);
Expand Down
Expand Up @@ -10,12 +10,16 @@
*******************************************************************************/
package org.eclipse.tycho.p2.impl.resolver;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.tycho.ArtifactKey;
Expand All @@ -30,7 +34,11 @@
import org.eclipse.tycho.p2.impl.test.ArtifactMock;
import org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator;
import org.eclipse.tycho.p2.metadata.IDependencyMetadata;
import org.eclipse.tycho.p2.repository.GAV;
import org.eclipse.tycho.p2.target.TargetPlatformBuilderImpl;
import org.eclipse.tycho.repository.local.LocalMetadataRepository;
import org.eclipse.tycho.test.util.BuildPropertiesParserForTesting;
import org.eclipse.tycho.test.util.InstallableUnitUtil;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -193,6 +201,23 @@ public void testReactorProjectFiltering() throws Exception {
assertContainsIU(units, "org.eclipse.tycho.p2.impl.test.feature-p2-inf.feature.group");
}

@Test
public void testIncludeLocalMavenRepo() throws Exception {
TestTargetPlatformBuilderFactory factory = new TestTargetPlatformBuilderFactory();
LocalMetadataRepository localMetadataRepo = factory.getLocalMetadataRepository();
// add one IU to local repo
localMetadataRepo.addInstallableUnit(InstallableUnitUtil.createIU("locallyInstalledIU", "1.0.0"), new GAV(
"test", "foo", "1.0.0"));
TargetPlatformBuilderImpl tpBuilder = factory.createTargetPlatformBuilder();
Collection<IInstallableUnit> iusIncludingLocalRepo = tpBuilder.buildTargetPlatform().getInstallableUnits();
tpBuilder.setIncludeLocalMavenRepo(false);
Collection<IInstallableUnit> iusWithoutLocalRepo = tpBuilder.buildTargetPlatform().getInstallableUnits();
Set<IInstallableUnit> retainedIUs = new HashSet<IInstallableUnit>(iusIncludingLocalRepo);
retainedIUs.removeAll(iusWithoutLocalRepo);
assertEquals(1, retainedIUs.size());
assertEquals("locallyInstalledIU", retainedIUs.iterator().next().getId());
}

private void assertContainsIU(Collection<IInstallableUnit> units, String id) {
Assert.assertNotNull("Missing installable unit with id " + id, getIU(units, id));
}
Expand Down
Expand Up @@ -32,11 +32,7 @@ public interface P2TargetPlatform extends TargetPlatform {
*/
ExecutionEnvironmentResolutionHints getEEResolutionHints();

/**
* Notify the target platform implementation about which IUs are actually used. This for example
* allows debug output.
*/
void reportUsedIUs(Collection<IInstallableUnit> usedUnits);
void reportUsedLocalIUs(Collection<IInstallableUnit> usedUnits);

void downloadArtifacts(Collection<IInstallableUnit> usedUnits);

Expand Down
Expand Up @@ -62,13 +62,6 @@ private static synchronized LocalMetadataRepository getLocalMetadataRepository(M
localMetadataRepository = new LocalMetadataRepository(localMavenRepoRoot.toURI(),
localRepoIndices.getMetadataIndex(), contentLocator);

// TODO this logic shouldn't be here
String localArtifactHandling = context.getSessionProperties().getProperty("tycho.localArtifacts");
if ("ignore".equalsIgnoreCase(localArtifactHandling)) {
context.getLogger().debug(
"tycho.localArtifacts=" + localArtifactHandling + " -> ignoring locally built artifacts");
localMetadataRepository.setIncludeInTargetPlatform(false);
}
}
return localMetadataRepository;
}
Expand Down

0 comments on commit 08631a0

Please sign in to comment.