Search in sources :

Example 1 with PublisherInfo

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

the class FeatureRootfileArtifactRepositoryTest method createPublisherInfo.

private PublisherInfo createPublisherInfo(boolean addMavenPropertyAdvice) {
    PublisherInfo publisherInfo = new PublisherInfo();
    publisherInfo.addAdvice(createFeatureRootAdvice());
    if (addMavenPropertyAdvice) {
        publisherInfo.addAdvice(createMavenPropertyAdvice());
    }
    return publisherInfo;
}
Also used : PublisherInfo(org.eclipse.equinox.p2.publisher.PublisherInfo)

Example 2 with PublisherInfo

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

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

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

the class P2GeneratorImpl method generateMetadata.

public DependencyMetadata generateMetadata(IArtifactFacade artifact, List<TargetEnvironment> environments) {
    PublisherInfo publisherInfo = new PublisherInfo();
    publisherInfo.setArtifactOptions(IPublisherInfo.A_INDEX | IPublisherInfo.A_PUBLISH);
    publisherInfo.setArtifactRepository(new TransientArtifactRepository());
    return super.generateMetadata(artifact, environments, publisherInfo, null);
}
Also used : IPublisherInfo(org.eclipse.equinox.p2.publisher.IPublisherInfo) PublisherInfo(org.eclipse.equinox.p2.publisher.PublisherInfo) TransientArtifactRepository(org.eclipse.tycho.p2.impl.publisher.repo.TransientArtifactRepository)

Example 5 with PublisherInfo

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

the class P2GeneratorImpl method generateMetadata.

@Override
public Map<String, IP2Artifact> generateMetadata(List<IArtifactFacade> artifacts, final File targetDir) throws IOException {
    Map<String, IP2Artifact> result = new LinkedHashMap<>();
    for (IArtifactFacade artifact : artifacts) {
        PublisherInfo publisherInfo = new PublisherInfo();
        DependencyMetadata metadata;
        // meta data handling for root files
        if (PackagingType.TYPE_ECLIPSE_FEATURE.equals(artifact.getPackagingType())) {
            publisherInfo.setArtifactOptions(IPublisherInfo.A_INDEX | IPublisherInfo.A_PUBLISH | IPublisherInfo.A_NO_MD5);
            FeatureRootfileArtifactRepository artifactsRepository = new FeatureRootfileArtifactRepository(publisherInfo, targetDir);
            publisherInfo.setArtifactRepository(artifactsRepository);
            metadata = super.generateMetadata(artifact, null, publisherInfo, null);
            result.putAll(artifactsRepository.getPublishedArtifacts());
        } else if (PackagingType.TYPE_P2_IU.equals(artifact.getPackagingType())) {
            TransientArtifactRepository artifactsRepository = new TransientArtifactRepository();
            publisherInfo.setArtifactRepository(artifactsRepository);
            final IArtifactFacade currentArtifact = artifact;
            IArtifactFacade targetDirAsArtifact = new IArtifactFacade() {

                @Override
                public String getVersion() {
                    return currentArtifact.getVersion();
                }

                @Override
                public String getPackagingType() {
                    return currentArtifact.getPackagingType();
                }

                @Override
                public File getLocation() {
                    return targetDir;
                }

                @Override
                public String getGroupId() {
                    return currentArtifact.getGroupId();
                }

                @Override
                public String getClassifier() {
                    return currentArtifact.getClassifier();
                }

                @Override
                public String getArtifactId() {
                    return currentArtifact.getArtifactId();
                }
            };
            metadata = super.generateMetadata(targetDirAsArtifact, null, publisherInfo, null);
        } else {
            publisherInfo.setArtifactOptions(IPublisherInfo.A_PUBLISH | IPublisherInfo.A_NO_MD5);
            TransientArtifactRepository artifactsRepository = new TransientArtifactRepository();
            publisherInfo.setArtifactRepository(artifactsRepository);
            metadata = super.generateMetadata(artifact, null, publisherInfo, null);
        }
        // secondary metadata is meant to represent installable units that are provided by this project
        // but do not affect dependencies of the project itself. generateMetadata is called at the end
        // of project build lifecycle, and primary/secondary metadata separation is irrelevant at this point
        P2Artifact p2artifact = new P2Artifact(artifact.getLocation(), metadata.getInstallableUnits(), getCanonicalArtifact(artifact.getClassifier(), metadata.getArtifactDescriptors()));
        result.put(artifact.getClassifier(), p2artifact);
        IArtifactDescriptor packed = getPackedArtifactDescriptor(metadata.getArtifactDescriptors());
        if (packed != null) {
            File packedLocation = new File(artifact.getLocation().getAbsolutePath() + ".pack.gz");
            if (!packedLocation.canRead()) {
                throw new IllegalArgumentException("Could not find packed artifact " + packed + " at " + packedLocation);
            }
            if (result.containsKey(RepositoryLayoutHelper.PACK200_CLASSIFIER)) {
                throw new IllegalArgumentException();
            }
            // workaround for bug 412497
            Map<String, String> additionalProperties = new HashMap<>(5);
            additionalProperties.put(RepositoryLayoutHelper.PROP_GROUP_ID, artifact.getGroupId());
            additionalProperties.put(RepositoryLayoutHelper.PROP_ARTIFACT_ID, artifact.getArtifactId());
            additionalProperties.put(RepositoryLayoutHelper.PROP_VERSION, artifact.getVersion());
            additionalProperties.put(RepositoryLayoutHelper.PROP_CLASSIFIER, RepositoryLayoutHelper.PACK200_CLASSIFIER);
            additionalProperties.put(RepositoryLayoutHelper.PROP_EXTENSION, RepositoryLayoutHelper.PACK200_EXTENSION);
            ((ArtifactDescriptor) packed).addProperties(additionalProperties);
            result.put(RepositoryLayoutHelper.PACK200_CLASSIFIER, new P2Artifact(packedLocation, Collections.<IInstallableUnit>emptySet(), packed));
        }
    }
    return result;
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) IArtifactFacade(org.eclipse.tycho.p2.metadata.IArtifactFacade) IPublisherInfo(org.eclipse.equinox.p2.publisher.IPublisherInfo) PublisherInfo(org.eclipse.equinox.p2.publisher.PublisherInfo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FeatureRootfileArtifactRepository(org.eclipse.tycho.p2.impl.publisher.repo.FeatureRootfileArtifactRepository) TransientArtifactRepository(org.eclipse.tycho.p2.impl.publisher.repo.TransientArtifactRepository) LinkedHashMap(java.util.LinkedHashMap) ArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File)

Aggregations

PublisherInfo (org.eclipse.equinox.p2.publisher.PublisherInfo)6 IPublisherInfo (org.eclipse.equinox.p2.publisher.IPublisherInfo)5 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)4 File (java.io.File)3 IStatus (org.eclipse.core.runtime.IStatus)3 Version (org.eclipse.equinox.p2.metadata.Version)3 IPublisherAction (org.eclipse.equinox.p2.publisher.IPublisherAction)3 PublisherResult (org.eclipse.equinox.p2.publisher.PublisherResult)3 TransientArtifactRepository (org.eclipse.tycho.p2.impl.publisher.repo.TransientArtifactRepository)3 LinkedHashMap (java.util.LinkedHashMap)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 IProvidedCapability (org.eclipse.equinox.p2.metadata.IProvidedCapability)2 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)2 AdviceFileAdvice (org.eclipse.equinox.p2.publisher.AdviceFileAdvice)2 Publisher (org.eclipse.equinox.p2.publisher.Publisher)2 JREAction (org.eclipse.equinox.p2.publisher.actions.JREAction)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1