Search in sources :

Example 16 with Location

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());
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) ArrayList(java.util.ArrayList) IRequiredCapability(org.eclipse.equinox.internal.p2.metadata.IRequiredCapability) ArtifactMock(org.eclipse.tycho.p2.impl.test.ArtifactMock) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File) SourcesBundleDependencyMetadataGenerator(org.eclipse.tycho.p2.impl.publisher.SourcesBundleDependencyMetadataGenerator) DefaultDependencyMetadataGenerator(org.eclipse.tycho.p2.impl.publisher.DefaultDependencyMetadataGenerator) DependencyMetadataGenerator(org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator) Test(org.junit.Test)

Example 17 with Location

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());
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) ArrayList(java.util.ArrayList) IRequiredCapability(org.eclipse.equinox.internal.p2.metadata.IRequiredCapability) ArtifactMock(org.eclipse.tycho.p2.impl.test.ArtifactMock) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File) SourcesBundleDependencyMetadataGenerator(org.eclipse.tycho.p2.impl.publisher.SourcesBundleDependencyMetadataGenerator) DefaultDependencyMetadataGenerator(org.eclipse.tycho.p2.impl.publisher.DefaultDependencyMetadataGenerator) DependencyMetadataGenerator(org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator) Test(org.junit.Test)

Example 18 with Location

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;
}
Also used : BundlesAction(org.eclipse.equinox.p2.publisher.eclipse.BundlesAction) ArrayList(java.util.ArrayList) ProductAction(org.eclipse.equinox.p2.publisher.eclipse.ProductAction) Feature(org.eclipse.equinox.p2.publisher.eclipse.Feature) CategoryParser(org.eclipse.equinox.internal.p2.updatesite.CategoryParser) FeaturesAction(org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction) FeatureParser(org.eclipse.equinox.internal.p2.publisher.eclipse.FeatureParser) IPublisherAction(org.eclipse.equinox.p2.publisher.IPublisherAction) IProductDescriptor(org.eclipse.equinox.internal.p2.publisher.eclipse.IProductDescriptor) SiteXMLAction(org.eclipse.equinox.internal.p2.updatesite.SiteXMLAction) SiteModel(org.eclipse.equinox.internal.p2.updatesite.SiteModel) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ProductFile2(org.eclipse.tycho.p2.impl.publisher.model.ProductFile2) File(java.io.File)

Example 19 with Location

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));
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) ArrayList(java.util.ArrayList) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) P2GeneratorImpl(org.eclipse.tycho.p2.impl.publisher.P2GeneratorImpl) BuildPropertiesParserForTesting(org.eclipse.tycho.test.util.BuildPropertiesParserForTesting) DependencyMetadata(org.eclipse.tycho.p2.impl.publisher.DependencyMetadata) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File) Test(org.junit.Test)

Example 20 with Location

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());
}
Also used : InstallableUnitLocation(org.eclipse.tycho.p2.target.facade.TargetDefinition.InstallableUnitLocation) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 File (java.io.File)14 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)11 ArrayList (java.util.ArrayList)10 DefaultDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.DefaultDependencyMetadataGenerator)8 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)8 SourcesBundleDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.SourcesBundleDependencyMetadataGenerator)7 DependencyMetadataGenerator (org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator)7 InstallableUnitLocation (org.eclipse.tycho.p2.target.facade.TargetDefinition.InstallableUnitLocation)7 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)6 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)4 TargetDefinition (org.eclipse.tycho.p2.target.facade.TargetDefinition)4 IOException (java.io.IOException)3 URI (java.net.URI)3 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)3 TychoRepositoryIndex (org.eclipse.tycho.p2.repository.TychoRepositoryIndex)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)2