Search in sources :

Example 11 with Feature

use of org.eclipse.equinox.p2.publisher.eclipse.Feature in project tycho by eclipse.

the class FeatureDependenciesAction method addPublisherAdvice.

@Override
protected void addPublisherAdvice(IPublisherInfo publisherInfo) {
    // see org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction.createAdviceFileAdvice(Feature, IPublisherInfo)
    IPath location = new Path(feature.getLocation());
    Version version = Version.parseVersion(feature.getVersion());
    String groupId = getId();
    AdviceFileAdvice advice = new AdviceFileAdvice(groupId, version, location, new Path("p2.inf"));
    if (advice.containsAdvice()) {
        publisherInfo.addAdvice(advice);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) Version(org.eclipse.equinox.p2.metadata.Version) AdviceFileAdvice(org.eclipse.equinox.p2.publisher.AdviceFileAdvice)

Example 12 with Feature

use of org.eclipse.equinox.p2.publisher.eclipse.Feature 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 13 with Feature

use of org.eclipse.equinox.p2.publisher.eclipse.Feature in project tycho by eclipse.

the class P2DependencyGeneratorImplTest method feature_with_p2_inf.

@Test
public void feature_with_p2_inf() throws Exception {
    generateDependencies("feature-p2-inf", PackagingType.TYPE_ECLIPSE_FEATURE);
    List<IInstallableUnit> units = new ArrayList<>(this.units);
    // no feature.jar IU because dependencyOnly=true
    assertEquals(2, units.size());
    // TODO
    IInstallableUnit unit = units.get(0);
    assertEquals("org.eclipse.tycho.p2.impl.test.feature-p2-inf.feature.group", unit.getId());
    assertEquals("1.0.0.qualifier", unit.getVersion().toString());
    List<IRequirement> requirements = new ArrayList<>(unit.getRequirements());
    assertEquals(1, requirements.size());
    IRequiredCapability requirement = (IRequiredCapability) requirements.get(0);
    assertEquals(IInstallableUnit.NAMESPACE_IU_ID, requirement.getNamespace());
    assertEquals("required.p2.inf", requirement.getName());
    assertEquals(0, artifacts.size());
    assertEquals("iu.p2.inf", units.get(1).getId());
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) ArrayList(java.util.ArrayList) IRequiredCapability(org.eclipse.equinox.internal.p2.metadata.IRequiredCapability) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) Test(org.junit.Test)

Example 14 with Feature

use of org.eclipse.equinox.p2.publisher.eclipse.Feature in project tycho by eclipse.

the class P2DependencyGeneratorImplTest method feature.

@Test
public void feature() throws Exception {
    generateDependencies("feature", PackagingType.TYPE_ECLIPSE_FEATURE);
    // no feature.jar IU because dependencyOnly=true
    assertEquals(1, units.size());
    IInstallableUnit unit = units.iterator().next();
    assertEquals("org.eclipse.tycho.p2.impl.test.feature.feature.group", unit.getId());
    assertEquals("1.0.0.qualifier", unit.getVersion().toString());
    assertEquals(DEFAULT_CLASSIFIER, unit.getProperty(RepositoryLayoutHelper.PROP_CLASSIFIER));
    List<IRequirement> requirements = new ArrayList<>(unit.getRequirements());
    assertEquals(6, requirements.size());
    IRequiredCapability capability = getRequiredCapability("another.required.feature.feature.group", requirements);
    IMatchExpression<IInstallableUnit> matches = capability.getMatches();
    assertEquals("providedCapabilities.exists(x | x.name == $0 && x.namespace == $1 && x.version >= $2 && x.version < $3)", matches.toString());
    assertEquals(Version.parseVersion("1.0.0"), matches.getParameters()[2]);
    assertEquals(Version.parseVersion("2.0.0"), matches.getParameters()[3]);
    assertEquals(0, artifacts.size());
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) ArrayList(java.util.ArrayList) IRequiredCapability(org.eclipse.equinox.internal.p2.metadata.IRequiredCapability) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) Test(org.junit.Test)

Example 15 with Feature

use of org.eclipse.equinox.p2.publisher.eclipse.Feature in project gemoc-studio by eclipse.

the class PrepareInstallProfileJob method queryInstallableUnits.

/**
 * Perform a query to get the installable units. This causes p2 to determine
 * what features are available in each repository. We select installable
 * units by matching both the feature id and the repository; it is possible
 * though unlikely that the same feature id is available from more than one
 * of the selected repositories, and we must ensure that the user gets the
 * one that they asked for.
 */
private List<IInstallableUnit> queryInstallableUnits(SubMonitor monitor, List<IMetadataRepository> repositories) throws URISyntaxException {
    final List<IInstallableUnit> installableUnits = new ArrayList<IInstallableUnit>();
    monitor.setWorkRemaining(repositories.size());
    for (final IMetadataRepository repository : repositories) {
        checkCancelled(monitor);
        final Set<String> installableUnitIdsThisRepository = getDescriptorIds(repository);
        IQuery<IInstallableUnit> query = // 
        QueryUtil.createMatchQuery(// $NON-NLS-1$
        "id ~= /*.feature.group/ && " + // $NON-NLS-1$
        "properties['org.eclipse.equinox.p2.type.group'] == true ");
        IQueryResult<IInstallableUnit> result = repository.query(query, monitor.newChild(1));
        for (Iterator<IInstallableUnit> iter = result.iterator(); iter.hasNext(); ) {
            IInstallableUnit iu = iter.next();
            String id = iu.getId();
            if (installableUnitIdsThisRepository.contains(id.substring(0, id.indexOf(P2_FEATURE_GROUP_SUFFIX)))) {
                installableUnits.add(iu);
            }
        }
    }
    return installableUnits;
}
Also used : ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)8 ArrayList (java.util.ArrayList)6 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)4 Version (org.eclipse.equinox.p2.metadata.Version)4 Test (org.junit.Test)4 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)2 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Path (org.eclipse.core.runtime.Path)1