use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Location in project tycho by eclipse.
the class P2GeneratorImplTest method testOptionalRequireBundle_OPTIONAL.
@Test
public void testOptionalRequireBundle_OPTIONAL() throws Exception {
DependencyMetadataGenerator generator = createDependencyMetadataGenerator();
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).getMetadata();
assertEquals(1, units.size());
IInstallableUnit iu = getUnit("optional-require-bundle", units);
assertNotNull(iu);
List<IRequirement> requirements = new ArrayList<>(iu.getRequirements());
assertEquals(1, requirements.size());
IRequiredCapability requirement = (IRequiredCapability) requirements.get(0);
assertFalse(requirement.isGreedy());
assertEquals(0, requirement.getMin());
assertEquals(1, requirement.getMax());
assertEquals(BundlesAction.CAPABILITY_NS_OSGI_BUNDLE, requirement.getNamespace());
assertEquals("org.eclipse.osgi", requirement.getName());
}
use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Location in project tycho by eclipse.
the class P2GeneratorImplTest method testOptionalRequireBundleP2inf_REQUIRE.
@Test
public void testOptionalRequireBundleP2inf_REQUIRE() throws Exception {
DependencyMetadataGenerator generator = createDependencyMetadataGenerator();
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).getMetadata();
assertEquals(1, units.size());
IInstallableUnit iu = getUnit("optional-reqiure-bundle-p2inf", units);
assertNotNull(iu);
List<IRequirement> requirements = new ArrayList<>(iu.getRequirements());
assertEquals(1, requirements.size());
IRequiredCapability requirement = (IRequiredCapability) requirements.get(0);
assertTrue(requirement.isGreedy());
assertEquals(1, requirement.getMin());
assertEquals(1, requirement.getMax());
assertEquals(BundlesAction.CAPABILITY_NS_OSGI_BUNDLE, requirement.getNamespace());
assertEquals("org.eclipse.osgi", requirement.getName());
}
use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Location in project tycho by eclipse.
the class P2GeneratorImpl method getPublisherActions.
@Override
protected List<IPublisherAction> getPublisherActions(IArtifactFacade artifact, List<TargetEnvironment> environments, OptionalResolutionAction optionalAction) {
if (!dependenciesOnly && optionalAction != null) {
throw new IllegalArgumentException();
}
List<IPublisherAction> actions = new ArrayList<>();
String packaging = artifact.getPackagingType();
File location = artifact.getLocation();
if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(packaging) || PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(packaging)) {
if (dependenciesOnly && optionalAction != null) {
actions.add(new BundleDependenciesAction(location, optionalAction));
} else {
actions.add(new BundlesAction(new File[] { location }));
}
} else if (PackagingType.TYPE_ECLIPSE_FEATURE.equals(packaging)) {
Feature feature = new FeatureParser().parse(location);
feature.setLocation(location.getAbsolutePath());
if (dependenciesOnly) {
actions.add(new FeatureDependenciesAction(feature));
} else {
actions.add(new FeaturesAction(new Feature[] { feature }));
}
} else if (PackagingType.TYPE_ECLIPSE_APPLICATION.equals(packaging)) {
String product = new File(location, artifact.getArtifactId() + ".product").getAbsolutePath();
try {
IProductDescriptor productDescriptor = new ProductFile2(product);
if (dependenciesOnly) {
actions.add(new ProductDependenciesAction(productDescriptor));
} else {
actions.add(new ProductAction(product, productDescriptor, null, null));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} else if (PackagingType.TYPE_ECLIPSE_UPDATE_SITE.equals(packaging)) {
if (dependenciesOnly) {
actions.add(new SiteDependenciesAction(location, artifact.getArtifactId(), artifact.getVersion()));
} else {
actions.add(new SiteXMLAction(location.toURI(), null));
}
} else if (PackagingType.TYPE_ECLIPSE_REPOSITORY.equals(packaging)) {
for (File productFile : getProductFiles(location)) {
String product = productFile.getAbsolutePath();
IProductDescriptor productDescriptor;
try {
productDescriptor = new ProductFile2(product);
} catch (Exception e) {
throw new RuntimeException("Unable to parse the product file " + product, e);
}
if (dependenciesOnly) {
actions.add(new ProductDependenciesAction(productDescriptor));
}
}
for (File categoryFile : getCategoryFiles(location)) {
CategoryParser cp = new CategoryParser(null);
FileInputStream ins = null;
try {
try {
ins = new FileInputStream(categoryFile);
SiteModel siteModel = cp.parse(ins);
actions.add(new CategoryDependenciesAction(siteModel, artifact.getArtifactId(), artifact.getVersion()));
} finally {
if (ins != null) {
ins.close();
}
}
} catch (Exception e) {
throw new RuntimeException("Unable to read category File", e);
}
}
} else if (PackagingType.TYPE_P2_IU.equals(packaging)) {
actions.add(new AuthoredIUAction(location));
} else if (location.isFile() && location.getName().endsWith(".jar")) {
actions.add(new BundlesAction(new File[] { location }));
} else {
throw new IllegalArgumentException("Unknown type of packaging " + packaging);
}
return actions;
}
use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Location in project tycho by eclipse.
the class P2MetadataGeneratorImplTest method gav.
@Test
public void gav() throws Exception {
P2GeneratorImpl impl = new P2GeneratorImpl(false);
impl.setBuildPropertiesParser(new BuildPropertiesParserForTesting());
File location = new File("resources/generator/bundle").getCanonicalFile();
String groupId = "org.eclipse.tycho.p2.impl.test";
String artifactId = "bundle";
String version = "1.0.0-SNAPSHOT";
List<TargetEnvironment> environments = new ArrayList<>();
DependencyMetadata metadata = impl.generateMetadata(new ArtifactMock(location, groupId, artifactId, version, PackagingType.TYPE_ECLIPSE_PLUGIN), environments);
List<IInstallableUnit> units = new ArrayList<>(metadata.getInstallableUnits());
List<IArtifactDescriptor> artifacts = new ArrayList<>(metadata.getArtifactDescriptors());
Assert.assertEquals(1, units.size());
IInstallableUnit unit = units.iterator().next();
Assert.assertEquals("org.eclipse.tycho.p2.impl.test.bundle", unit.getId());
Assert.assertEquals("1.0.0.qualifier", unit.getVersion().toString());
Assert.assertEquals(2, unit.getRequirements().size());
Assert.assertEquals(1, artifacts.size());
IArtifactDescriptor ad = artifacts.iterator().next();
Assert.assertEquals("org.eclipse.tycho.p2.impl.test.bundle", ad.getArtifactKey().getId());
Assert.assertEquals("1.0.0.qualifier", ad.getArtifactKey().getVersion().toString());
Assert.assertEquals(groupId, ad.getProperties().get(RepositoryLayoutHelper.PROP_GROUP_ID));
Assert.assertEquals(artifactId, ad.getProperties().get(RepositoryLayoutHelper.PROP_ARTIFACT_ID));
Assert.assertEquals(version, ad.getProperties().get(RepositoryLayoutHelper.PROP_VERSION));
}
use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Location in project tycho by eclipse.
the class TargetDefinitionFileTest method testExplictIncludeModeValues.
@Test
public void testExplictIncludeModeValues() throws Exception {
List<? extends Location> locations = readTarget("includeModes.target").getLocations();
InstallableUnitLocation locationWithPlanner = (InstallableUnitLocation) locations.get(1);
InstallableUnitLocation locationWithSlicer = (InstallableUnitLocation) locations.get(2);
InstallableUnitLocation locationWithSlicerAndAllEnvironments = (InstallableUnitLocation) locations.get(3);
assertEquals(IncludeMode.PLANNER, locationWithPlanner.getIncludeMode());
assertEquals(IncludeMode.SLICER, locationWithSlicer.getIncludeMode());
assertEquals(false, locationWithSlicer.includeAllEnvironments());
assertEquals(IncludeMode.SLICER, locationWithSlicerAndAllEnvironments.getIncludeMode());
assertEquals(true, locationWithSlicerAndAllEnvironments.includeAllEnvironments());
}
Aggregations