Search in sources :

Example 6 with InstallableUnitDescription

use of org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription in project tycho by eclipse.

the class AuthoredIUAction method perform.

@Override
@SuppressWarnings("deprecation")
public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) {
    File iuFile = new File(iuProject, "p2iu.xml");
    if (!iuFile.exists())
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not find the p2iu.xml file in folder " + iuProject);
    try {
        FileInputStream is = new FileInputStream(iuFile);
        InstallableUnitDescription iuDescriptions = new MetadataIO().readOneIU(is);
        tweakIU(iuDescriptions);
        Set<IInstallableUnit> ius = toIUs(iuDescriptions);
        results.addIUs(ius, IPublisherResult.ROOT);
        IArtifactRepository repo = info.getArtifactRepository();
        boolean artifactReferenced = false;
        if (repo != null) {
            for (IInstallableUnit iu : ius) {
                Collection<IArtifactKey> associatedKeys = iu.getArtifacts();
                for (IArtifactKey key : associatedKeys) {
                    ArtifactDescriptor ad = (ArtifactDescriptor) PublisherHelper.createArtifactDescriptor(info, key, null);
                    processArtifactPropertiesAdvice(iu, ad, info);
                    ad.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, IArtifactDescriptor.TYPE_ZIP);
                    ad.setProperty(RepositoryLayoutHelper.PROP_EXTENSION, "zip");
                    repo.addDescriptor(ad);
                    artifactReferenced = true;
                }
            }
        }
        // and fails in many places. I tried to change the code where the failures were occurring but did not succeed.
        if (!artifactReferenced && repo != null) {
            IInstallableUnit iu = ((IInstallableUnit) ius.iterator().next());
            ArtifactDescriptor ad = (ArtifactDescriptor) PublisherHelper.createArtifactDescriptor(info, new ArtifactKey("binary", "generated_" + iu.getId(), iu.getVersion()), null);
            processArtifactPropertiesAdvice(iu, ad, info);
            ad.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, IArtifactDescriptor.TYPE_ZIP);
            repo.addDescriptor(ad);
            artifactReferenced = true;
        }
        return Status.OK_STATUS;
    } catch (IOException e) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error while reading " + iuFile, e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) ArtifactKey(org.eclipse.equinox.internal.p2.metadata.ArtifactKey) IArtifactRepository(org.eclipse.equinox.p2.repository.artifact.IArtifactRepository) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) ArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) MetadataIO(org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File)

Example 7 with InstallableUnitDescription

use of org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription in project tycho by eclipse.

the class AuthoredIUAction method ensureSelfCapability.

private void ensureSelfCapability(InstallableUnitDescription iu) {
    Collection<IProvidedCapability> capabilities = iu.getProvidedCapabilities();
    for (IProvidedCapability capability : capabilities) {
        if (IInstallableUnit.NAMESPACE_IU_ID.equals(capability.getNamespace()) && iu.getId().equals(capability.getName()) && iu.getVersion().equals(capability.getVersion())) {
            return;
        }
    }
    IProvidedCapability[] newCapabilities = new IProvidedCapability[capabilities.size() + 1];
    capabilities.toArray(newCapabilities);
    newCapabilities[newCapabilities.length - 1] = createSelfCapability(iu.getId(), iu.getVersion());
    iu.setCapabilities(newCapabilities);
}
Also used : IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability)

Example 8 with InstallableUnitDescription

use of org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription in project tycho by eclipse.

the class BundleDependenciesAction method createAdviceFileAdvice.

@Override
protected void createAdviceFileAdvice(BundleDescription bundleDescription, IPublisherInfo publisherInfo) {
    String location = bundleDescription.getLocation();
    if (location == null)
        return;
    File adviceFile = new File(location, AdviceFileAdvice.BUNDLE_ADVICE_FILE.toString());
    if (!adviceFile.canRead()) {
        return;
    }
    Map<String, String> advice = new LinkedHashMap<>();
    try {
        InputStream is = new BufferedInputStream(new FileInputStream(adviceFile));
        try {
            Properties props = new Properties();
            props.load(is);
            for (Map.Entry<Object, Object> p : props.entrySet()) {
                advice.put((String) p.getKey(), (String) p.getValue());
            }
        } finally {
            try {
                is.close();
            } catch (IOException secondary) {
            // secondary exception
            }
        }
    } catch (IOException e) {
        // TODO log
        return;
    }
    final String symbolicName = bundleDescription.getSymbolicName();
    final Version bundleVersion = PublisherHelper.fromOSGiVersion(bundleDescription.getVersion());
    AdviceFileParser parser = new AdviceFileParser(symbolicName, bundleVersion, advice) {

        @Override
        protected IRequirement createRequirement(String namespace, String name, VersionRange range, String filter, boolean optional, boolean multiple, boolean greedy) {
            if (optionalAction == OptionalResolutionAction.OPTIONAL) {
                return super.createRequirement(namespace, name, range, filter, optional, multiple, greedy);
            }
            return BundleDependenciesAction.this.createRequirement(namespace, name, range, filter, optional, multiple, greedy);
        }
    };
    try {
        parser.parse();
    } catch (Exception e) {
        // TODO log
        return;
    }
    final IProvidedCapability[] provided = parser.getProvidedCapabilities();
    final IRequirement[] required = parser.getRequiredCapabilities();
    if (provided == null && required == null) {
        return;
    }
    publisherInfo.addAdvice(new ICapabilityAdvice() {

        @Override
        public boolean isApplicable(String configSpec, boolean includeDefault, String id, Version version) {
            return symbolicName.equals(id) && bundleVersion.equals(version);
        }

        @Override
        public IRequirement[] getRequiredCapabilities(InstallableUnitDescription iu) {
            return required;
        }

        @Override
        public IProvidedCapability[] getProvidedCapabilities(InstallableUnitDescription iu) {
            return provided;
        }

        @Override
        public IRequirement[] getMetaRequiredCapabilities(InstallableUnitDescription iu) {
            return null;
        }
    });
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VersionRange(org.eclipse.equinox.p2.metadata.VersionRange) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) BufferedInputStream(java.io.BufferedInputStream) Version(org.eclipse.equinox.p2.metadata.Version) AdviceFileParser(org.eclipse.equinox.p2.publisher.AdviceFileParser) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ICapabilityAdvice(org.eclipse.equinox.p2.publisher.actions.ICapabilityAdvice)

Example 9 with InstallableUnitDescription

use of org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription in project tycho by eclipse.

the class DependencyCollectorTest method missingDependencies.

@Test
public void missingDependencies() {
    InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
    String time = Long.toString(System.currentTimeMillis());
    iud.setId(time);
    iud.setVersion(Version.createOSGi(0, 0, 0, time));
    ArrayList<IRequirement> requirements = new ArrayList<>();
    VersionRange range = new VersionRange("[1.2.3,1.2.4)");
    requirements.add(MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "this.is.a.missing.iu", range, null, 1, /* min */
    1, /* max */
    true));
    iud.setRequirements(requirements.toArray(new IRequirement[requirements.size()]));
    HashSet<IInstallableUnit> rootUIs = new HashSet<>();
    rootUIs.add(MetadataFactory.createInstallableUnit(iud));
    ResolutionDataImpl data = new ResolutionDataImpl(ExecutionEnvironmentTestUtils.NOOP_EE_RESOLUTION_HINTS);
    data.setRootIUs(rootUIs);
    data.setAdditionalRequirements(new ArrayList<IRequirement>());
    data.setAvailableIUs(Collections.<IInstallableUnit>emptyList());
    DependencyCollector dc = new DependencyCollector(logVerifier.getLogger());
    dc.setData(data);
    try {
        dc.resolve(Collections.<String, String>emptyMap(), new NullProgressMonitor());
        Assert.fail();
    } catch (RuntimeException e) {
        Throwable cause = e.getCause();
        Assert.assertTrue(cause instanceof ProvisionException);
        ProvisionException pe = (ProvisionException) cause;
        Assert.assertTrue(pe.getStatus().isMultiStatus());
        MultiStatus status = (MultiStatus) pe.getStatus();
        Assert.assertEquals(1, status.getChildren().length);
        Assert.assertTrue(e.toString().contains("this.is.a.missing.iu"));
    }
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) VersionRange(org.eclipse.equinox.p2.metadata.VersionRange) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with InstallableUnitDescription

use of org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription in project tycho by eclipse.

the class AbstractDependenciesAction method perform.

@Override
public IStatus perform(IPublisherInfo publisherInfo, IPublisherResult results, IProgressMonitor monitor) {
    InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
    iud.setId(getId());
    iud.setVersion(getVersion());
    Set<IProvidedCapability> provided = new LinkedHashSet<>();
    addProvidedCapabilities(provided);
    provided.add(MetadataFactory.createProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, iud.getId(), iud.getVersion()));
    iud.addProvidedCapabilities(provided);
    iud.addRequirements(getRequiredCapabilities());
    addProperties(iud);
    addPublisherAdvice(publisherInfo);
    processCapabilityAdvice(iud, publisherInfo);
    processInstallableUnitPropertiesAdvice(iud, publisherInfo);
    IInstallableUnit iu = MetadataFactory.createInstallableUnit(iud);
    results.addIU(iu, PublisherResult.ROOT);
    InstallableUnitDescription[] others = processAdditionalInstallableUnitsAdvice(iu, publisherInfo);
    if (others != null) {
        for (InstallableUnitDescription other : others) {
            // using PublisherResult.NON_ROOT results in these IUs appear after the primary
            // see org.eclipse.equinox.p2.publisher.PublisherResult.getIUs(String, String)
            // see org.eclipse.tycho.p2.metadata.IReactorArtifactFacade.getDependencyMetadata()
            results.addIU(MetadataFactory.createInstallableUnit(other), PublisherResult.NON_ROOT);
        }
    }
    return Status.OK_STATUS;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Aggregations

InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)19 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)9 ArrayList (java.util.ArrayList)6 File (java.io.File)4 IProvidedCapability (org.eclipse.equinox.p2.metadata.IProvidedCapability)4 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)4 Test (org.junit.Test)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ArtifactKey (org.eclipse.equinox.internal.p2.metadata.ArtifactKey)2 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)2 Version (org.eclipse.equinox.p2.metadata.Version)2 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)2 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1