Search in sources :

Example 1 with IPublisherInfo

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

the class PublisherActionRunner method newPublisherInfo.

private IPublisherInfo newPublisherInfo(IMetadataRepository metadataOutput, IArtifactRepository artifactsOutput) {
    final PublisherInfo publisherInfo = new PublisherInfo();
    publisherInfo.setMetadataRepository(metadataOutput);
    publisherInfo.setArtifactRepository(artifactsOutput);
    publisherInfo.setArtifactOptions(IPublisherInfo.A_INDEX | IPublisherInfo.A_PUBLISH);
    // TODO publishers only need an IQueryable<IInstallableUnit> -> changing this in p2 would simplify things for us
    publisherInfo.setContextMetadataRepository(contextIUs);
    // no (known) publisher action needs context artifact repositories
    setTargetEnvironments(publisherInfo);
    return publisherInfo;
}
Also used : PublisherInfo(org.eclipse.equinox.p2.publisher.PublisherInfo) IPublisherInfo(org.eclipse.equinox.p2.publisher.IPublisherInfo)

Example 2 with IPublisherInfo

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

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

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

the class SiteDependenciesAction method perform.

@Override
public IStatus perform(IPublisherInfo publisherInfo, IPublisherResult results, IProgressMonitor monitor) {
    try {
        // don't need transport to read local site.xml
        Transport transport = null;
        updateSite = UpdateSite.load(location.toURI(), transport, monitor);
    } catch (ProvisionException e) {
        return new Status(IStatus.ERROR, Activator.ID, "Error generating site xml action.", e);
    }
    return super.perform(publisherInfo, results, monitor);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) Transport(org.eclipse.equinox.internal.p2.repository.Transport)

Example 5 with IPublisherInfo

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

the class SourcesBundleDependencyMetadataGenerator method getPublisherActions.

@Override
protected List<IPublisherAction> getPublisherActions(IArtifactFacade artifact, List<TargetEnvironment> environments, OptionalResolutionAction optionalAction) {
    ArrayList<IPublisherAction> actions = new ArrayList<>();
    String id = artifact.getArtifactId();
    String version = toCanonicalVersion(artifact.getVersion());
    try {
        // generated source bundle is not available at this point in filesystem yet, need to create
        // in-memory BundleDescription instead
        Dictionary<String, String> manifest = new Hashtable<>();
        manifest.put("Manifest-Version", "1.0");
        manifest.put("Bundle-ManifestVersion", "2");
        String sourceBundleSymbolicName = id + ".source";
        manifest.put("Bundle-SymbolicName", sourceBundleSymbolicName);
        manifest.put("Bundle-Version", version);
        manifest.put("Eclipse-SourceBundle", id + ";version=" + version + ";roots:=\".\"");
        StateObjectFactory factory = StateObjectFactory.defaultFactory;
        BundleDescription bundleDescription = factory.createBundleDescription(factory.createState(false), manifest, artifact.getLocation().getAbsolutePath(), createId(sourceBundleSymbolicName, version));
        bundleDescription.setUserObject(manifest);
        actions.add(new BundlesAction(new BundleDescription[] { bundleDescription }) {

            @Override
            protected void createAdviceFileAdvice(BundleDescription bundleDescription, IPublisherInfo publisherInfo) {
            // 367255 p2.inf is not applicable to sources bundles
            }
        });
    } catch (BundleException e) {
        throw new RuntimeException(e);
    }
    return actions;
}
Also used : IPublisherAction(org.eclipse.equinox.p2.publisher.IPublisherAction) BundlesAction(org.eclipse.equinox.p2.publisher.eclipse.BundlesAction) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) ArrayList(java.util.ArrayList) IPublisherInfo(org.eclipse.equinox.p2.publisher.IPublisherInfo) StateObjectFactory(org.eclipse.osgi.service.resolver.StateObjectFactory) BundleException(org.osgi.framework.BundleException)

Aggregations

File (java.io.File)3 IStatus (org.eclipse.core.runtime.IStatus)3 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)3 Version (org.eclipse.equinox.p2.metadata.Version)3 IPublisherInfo (org.eclipse.equinox.p2.publisher.IPublisherInfo)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 Status (org.eclipse.core.runtime.Status)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)2 IProvidedCapability (org.eclipse.equinox.p2.metadata.IProvidedCapability)2 AdviceFileAdvice (org.eclipse.equinox.p2.publisher.AdviceFileAdvice)2 IPublisherAction (org.eclipse.equinox.p2.publisher.IPublisherAction)2 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1