Skip to content

Commit

Permalink
Move IDependencyMetadata to a shared place (#44)
Browse files Browse the repository at this point in the history
Refactoring: Move IDependencyMetadata to a shared place

Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi authored Apr 11, 2021
1 parent 9e73883 commit af7f47c
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@
* Contributors:
* Sonatype Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.tycho.p2.metadata;
package org.eclipse.tycho;

import java.util.Collection;
import java.util.Set;

public interface IDependencyMetadata {

Set<Object /* IInstallableUnit */> getMetadata(boolean primary);
enum DependencyMetadataType {
SEED, RESOLVE;
}

Set<Object /* IInstallableUnit */> getMetadata();
Set<? /* IInstallableUnit */> getDependencyMetadata(DependencyMetadataType type);

Set<? /* IInstallableUnit */> getDependencyMetadata();

void setDependencyMetadata(DependencyMetadataType type, Collection<? /* IInstallableUnit */> units);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,11 @@
package org.eclipse.tycho;

import java.io.File;
import java.util.Set;

/**
* A Tycho project in the reactor.
*/
public interface ReactorProject {
/**
* Conventional key used to store ReactorProject in MavenProject.context
*/
public static final String CTX_REACTOR_PROJECT = "tycho.reactor-project";

/**
* Conventional key used to store dependency metadata in MavenProject.context
*/
public static final String CTX_DEPENDENCY_METADATA = "tycho.dependency-metadata";

/**
* Conventional key used to store secondary dependency metadata in MavenProject.context
*/
public static final String CTX_SECONDARY_DEPENDENCY_METADATA = "tycho.secondary-dependency-metadata";
public interface ReactorProject extends IDependencyMetadata {

/**
* Conventional sources jar Maven artifact classifier.
Expand Down Expand Up @@ -76,22 +61,6 @@ public interface ReactorProject {

public void setContextValue(String key, Object value);

//

public void setDependencyMetadata(boolean primary, Set<? /* IInstallableUnit */> installableUnits);

/**
* Returns set of p2 <tt>IInstallableUnit</tt>s that describe requirements and provided
* capabilities of this project.
*/
public Set<?> getDependencyMetadata(boolean primary);

/**
* Returns project dependency metadata with both primary and secondary project installable
* units.
*/
public Set<?> getDependencyMetadata();

public String getBuildQualifier();

public String getExpandedVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import java.util.LinkedHashSet;
import java.util.Set;

import org.eclipse.tycho.IDependencyMetadata;
import org.eclipse.tycho.IDependencyMetadata.DependencyMetadataType;
import org.eclipse.tycho.p2.metadata.IArtifactFacade;
import org.eclipse.tycho.p2.metadata.IDependencyMetadata;

public class ArtifactMock implements IArtifactFacade {
private File location;
Expand Down Expand Up @@ -51,8 +52,8 @@ public ArtifactMock(File location, String groupId, String artifactId, String ver
}

public ArtifactMock(ReactorProjectStub project, String classifier) {
this(project.getBasedir(), project.getGroupId(), project.getArtifactId(), project.getVersion(), project
.getPackaging(), classifier);
this(project.getBasedir(), project.getGroupId(), project.getArtifactId(), project.getVersion(),
project.getPackaging(), classifier);
}

@Override
Expand Down Expand Up @@ -94,7 +95,9 @@ public Set<Object> getDependencyMetadata(boolean primary) {
}

public void setDependencyMetadata(IDependencyMetadata dependencyMetadata) {
this.dependencyMetadata = new LinkedHashSet<>(dependencyMetadata.getMetadata(true));
this.secondaryDependencyMetadata = new LinkedHashSet<>(dependencyMetadata.getMetadata(false));
this.dependencyMetadata = new LinkedHashSet<>(
dependencyMetadata.getDependencyMetadata(DependencyMetadataType.SEED));
this.secondaryDependencyMetadata = new LinkedHashSet<>(
dependencyMetadata.getDependencyMetadata(DependencyMetadataType.RESOLVE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
package org.eclipse.tycho.p2.impl.test;

import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.tycho.BuildDirectory;
import org.eclipse.tycho.BuildOutputDirectory;
import org.eclipse.tycho.IDependencyMetadata;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.ReactorProjectIdentities;
import org.eclipse.tycho.p2.metadata.IDependencyMetadata;

// TODO use interface with a subset of methods to ease stubbing?
public class ReactorProjectStub extends ReactorProjectIdentities implements ReactorProject {
Expand Down Expand Up @@ -93,28 +95,37 @@ public String getPackaging() {
}

@Override
public Set<?> getDependencyMetadata(boolean primary) {
return primary ? dependencyMetadata : secondaryDependencyMetadata;
public Set<?> getDependencyMetadata(DependencyMetadataType type) {
switch (type) {
case SEED:
return dependencyMetadata;
case RESOLVE:
return secondaryDependencyMetadata;
default:
return Collections.emptySet();
}
}

public void setDependencyMetadata(IDependencyMetadata dependencyMetadata) {
this.dependencyMetadata = new LinkedHashSet<>(dependencyMetadata.getMetadata(true));
this.secondaryDependencyMetadata = new LinkedHashSet<>(dependencyMetadata.getMetadata(false));
this.dependencyMetadata = new LinkedHashSet<>(
dependencyMetadata.getDependencyMetadata(DependencyMetadataType.SEED));
this.secondaryDependencyMetadata = new LinkedHashSet<>(
dependencyMetadata.getDependencyMetadata(DependencyMetadataType.RESOLVE));
}

@Override
public void setDependencyMetadata(boolean primary, Set<?> installableUnits) {
if (primary)
this.dependencyMetadata = installableUnits;
else
this.secondaryDependencyMetadata = installableUnits;
public void setDependencyMetadata(DependencyMetadataType type, Collection<?> units) {
if (type == DependencyMetadataType.SEED)
this.dependencyMetadata = new LinkedHashSet<>(units);
else if (type == DependencyMetadataType.RESOLVE)
this.secondaryDependencyMetadata = new LinkedHashSet<>(units);
}

// TODO share with real implementation?
@Override
public Set<?> getDependencyMetadata() {
Set<?> primary = getDependencyMetadata(true);
Set<?> secondary = getDependencyMetadata(false);
Set<?> primary = getDependencyMetadata(DependencyMetadataType.SEED);
Set<?> secondary = getDependencyMetadata(DependencyMetadataType.RESOLVE);

if (primary == null) {
return secondary;
Expand Down Expand Up @@ -185,4 +196,5 @@ public String getName() {
// TODO implement
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public void testGenerateSourceBundleMetadata() throws Exception {
DependencyMetadataGenerator p2GeneratorImpl = new SourcesBundleDependencyMetadataGenerator();
File location = new File("resources/generator/bundle").getCanonicalFile();
ArtifactMock artifactMock = new ArtifactMock(location, "org.acme", "foo", "0.0.1", "eclipse-plugin");
Set<Object> units = p2GeneratorImpl
.generateMetadata(artifactMock, getEnvironments(), null, new PublisherOptions(false)).getMetadata();
Set<?> units = p2GeneratorImpl
.generateMetadata(artifactMock, getEnvironments(), null, new PublisherOptions(false))
.getDependencyMetadata();
assertEquals(1, units.size());
IInstallableUnit sourceBundleUnit = getUnit("foo.source", units);
assertNotNull(sourceBundleUnit);
Expand All @@ -76,16 +77,17 @@ public void generateSourceBundleMetadataForProjectWithP2Inf() throws Exception {
DependencyMetadataGenerator p2GeneratorImpl = new SourcesBundleDependencyMetadataGenerator();
File location = new File("resources/generator/bundle-p2-inf").getCanonicalFile();
ArtifactMock artifactMock = new ArtifactMock(location, "org.acme", "foo", "0.0.1", "eclipse-plugin");
Set<Object> units = p2GeneratorImpl
.generateMetadata(artifactMock, getEnvironments(), null, new PublisherOptions(false)).getMetadata();
Set<?> units = p2GeneratorImpl
.generateMetadata(artifactMock, getEnvironments(), null, new PublisherOptions(false))
.getDependencyMetadata();

assertEquals(1, units.size());

IInstallableUnit unit = getUnit("foo.source", units);
assertEquals(0, unit.getRequirements().size());
}

private IInstallableUnit getUnit(String id, Set<Object> units) {
private IInstallableUnit getUnit(String id, Set<?> units) {
for (Object obj : units) {
IInstallableUnit unit = (IInstallableUnit) obj;
if (id.equals(unit.getId())) {
Expand All @@ -106,7 +108,7 @@ public void testOptionalImportPackage_REQUIRE() throws Exception {
ArtifactMock artifactMock = new ArtifactMock(location, "optional-import-package", "optional-import-package",
"0.0.1", "eclipse-plugin");
Set<Object> units = generator.generateMetadata(artifactMock, getEnvironments(),
OptionalResolutionAction.REQUIRE, new PublisherOptions()).getMetadata();
OptionalResolutionAction.REQUIRE, new PublisherOptions()).getDependencyMetadata();
assertEquals(1, units.size());
IInstallableUnit iu = getUnit("optional-import-package", units);
assertNotNull(iu);
Expand All @@ -132,8 +134,8 @@ public void testOptionalImportPackage_IGNORE() throws Exception {
File location = new File("resources/generator/optional-import-package").getCanonicalFile();
ArtifactMock artifactMock = new ArtifactMock(location, "optional-import-package", "optional-import-package",
"0.0.1", "eclipse-plugin");
Set<Object> units = generator.generateMetadata(artifactMock, getEnvironments(), OptionalResolutionAction.IGNORE,
new PublisherOptions()).getMetadata();
Set<?> units = generator.generateMetadata(artifactMock, getEnvironments(), OptionalResolutionAction.IGNORE,
new PublisherOptions()).getDependencyMetadata();
assertEquals(1, units.size());
IInstallableUnit iu = getUnit("optional-import-package", units);
assertNotNull(iu);
Expand All @@ -147,8 +149,8 @@ public void testOptionalRequireBundle_REQUIRE() throws Exception {
File location = new File("resources/generator/optional-require-bundle").getCanonicalFile();
ArtifactMock artifactMock = new ArtifactMock(location, "optional-require-bundle", "optional-require-bundle",
"0.0.1", "eclipse-plugin");
Set<Object> units = generator.generateMetadata(artifactMock, getEnvironments(),
OptionalResolutionAction.REQUIRE, new PublisherOptions()).getMetadata();
Set<?> units = generator.generateMetadata(artifactMock, getEnvironments(), OptionalResolutionAction.REQUIRE,
new PublisherOptions()).getDependencyMetadata();
assertEquals(1, units.size());
IInstallableUnit iu = getUnit("optional-require-bundle", units);
assertNotNull(iu);
Expand All @@ -168,8 +170,8 @@ public void testOptionalRequireBundle_OPTIONAL() throws Exception {
File location = new File("resources/generator/optional-require-bundle").getCanonicalFile();
ArtifactMock artifactMock = new ArtifactMock(location, "optional-require-bundle", "optional-require-bundle",
"0.0.1", "eclipse-plugin");
Set<Object> units = generator.generateMetadata(artifactMock, getEnvironments(),
OptionalResolutionAction.OPTIONAL, new PublisherOptions()).getMetadata();
Set<?> units = generator.generateMetadata(artifactMock, getEnvironments(), OptionalResolutionAction.OPTIONAL,
new PublisherOptions()).getDependencyMetadata();
assertEquals(1, units.size());
IInstallableUnit iu = getUnit("optional-require-bundle", units);
assertNotNull(iu);
Expand All @@ -189,8 +191,8 @@ public void testOptionalRequireBundle_IGNORE() throws Exception {
File location = new File("resources/generator/optional-require-bundle").getCanonicalFile();
ArtifactMock artifactMock = new ArtifactMock(location, "optional-require-bundle", "optional-require-bundle",
"0.0.1", "eclipse-plugin");
Set<Object> units = generator.generateMetadata(artifactMock, getEnvironments(), OptionalResolutionAction.IGNORE,
new PublisherOptions()).getMetadata();
Set<?> units = generator.generateMetadata(artifactMock, getEnvironments(), OptionalResolutionAction.IGNORE,
new PublisherOptions()).getDependencyMetadata();
assertEquals(1, units.size());
IInstallableUnit iu = getUnit("optional-require-bundle", units);
assertNotNull(iu);
Expand All @@ -204,8 +206,8 @@ public void testOptionalRequireBundleP2inf_REQUIRE() throws Exception {
File location = new File("resources/generator/optional-reqiure-bundle-p2inf").getCanonicalFile();
ArtifactMock artifactMock = new ArtifactMock(location, "optional-reqiure-bundle-p2inf",
"optional-reqiure-bundle-p2inf", "0.0.1", "eclipse-plugin");
Set<Object> units = generator.generateMetadata(artifactMock, getEnvironments(),
OptionalResolutionAction.REQUIRE, new PublisherOptions()).getMetadata();
Set<?> units = generator.generateMetadata(artifactMock, getEnvironments(), OptionalResolutionAction.REQUIRE,
new PublisherOptions()).getDependencyMetadata();
assertEquals(1, units.size());
IInstallableUnit iu = getUnit("optional-reqiure-bundle-p2inf", units);
assertNotNull(iu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.tycho.IDependencyMetadata;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.core.resolver.shared.OptionalResolutionAction;
import org.eclipse.tycho.core.shared.TargetEnvironment;
Expand All @@ -25,7 +26,6 @@
import org.eclipse.tycho.p2.impl.publisher.P2GeneratorImpl;
import org.eclipse.tycho.p2.impl.test.ArtifactMock;
import org.eclipse.tycho.p2.impl.test.ReactorProjectStub;
import org.eclipse.tycho.p2.metadata.IDependencyMetadata;
import org.eclipse.tycho.p2.metadata.PublisherOptions;
import org.eclipse.tycho.p2.resolver.facade.P2Resolver;
import org.eclipse.tycho.p2.target.PomDependencyCollectorImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IVersionedId;
import org.eclipse.tycho.IDependencyMetadata.DependencyMetadataType;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.ReactorProjectIdentities;
import org.eclipse.tycho.artifacts.TargetPlatformFilter;
Expand Down Expand Up @@ -308,8 +309,8 @@ private ReactorProject createReactorProject(String artifactId, String[] primaryU
ReactorProjectStub result = new ReactorProjectStub(basedir, artifactId);

DependencyMetadata dependencyMetadata = new DependencyMetadata();
dependencyMetadata.setMetadata(true, createUnits(primaryUnitIds));
dependencyMetadata.setMetadata(false, createUnits(secondaryUnitIds));
dependencyMetadata.setDependencyMetadata(DependencyMetadataType.SEED, createUnits(primaryUnitIds));
dependencyMetadata.setDependencyMetadata(DependencyMetadataType.RESOLVE, createUnits(secondaryUnitIds));
result.setDependencyMetadata(dependencyMetadata);

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.equinox.p2.publisher.PublisherResult;
import org.eclipse.equinox.p2.publisher.actions.ICapabilityAdvice;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.tycho.IDependencyMetadata.DependencyMetadataType;
import org.eclipse.tycho.core.resolver.shared.OptionalResolutionAction;
import org.eclipse.tycho.core.shared.BuildProperties;
import org.eclipse.tycho.core.shared.BuildPropertiesParser;
Expand Down Expand Up @@ -130,8 +131,8 @@ private DependencyMetadata publish(PublisherInfo publisherInfo, List<IPublisherA

DependencyMetadata metadata = new DependencyMetadata();

metadata.setMetadata(true, result.getIUs(null, PublisherResult.ROOT));
metadata.setMetadata(false, result.getIUs(null, PublisherResult.NON_ROOT));
metadata.setDependencyMetadata(DependencyMetadataType.SEED, result.getIUs(null, PublisherResult.ROOT));
metadata.setDependencyMetadata(DependencyMetadataType.RESOLVE, result.getIUs(null, PublisherResult.NON_ROOT));

IArtifactRepository artifactRepository = publisherInfo.getArtifactRepository();
if (artifactRepository instanceof TransientArtifactRepository) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ public DependencyMetadata generateMetadata(IArtifactFacade artifact, List<Target
OptionalResolutionAction optionalAction, PublisherOptions options) {
return super.generateMetadata(artifact, environments, new PublisherInfo(), optionalAction, options);
}

}
Loading

0 comments on commit af7f47c

Please sign in to comment.