Search in sources :

Example 16 with ArtifactDescriptor

use of org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor in project tycho by eclipse.

the class ModuleArtifactRepositoryTest method testReadingWithOtherDescriptorType.

@Test
public void testReadingWithOtherDescriptorType() throws Exception {
    subject = ModuleArtifactRepository.restoreInstance(null, existingModuleDir);
    IArtifactDescriptor originalDescriptor = subject.getArtifactDescriptors(BUNDLE_ARTIFACT_KEY)[0];
    IArtifactDescriptor equivalentDescriptor = new ArtifactDescriptor(originalDescriptor);
    assertThat(subject.contains(BUNDLE_ARTIFACT_KEY), is(true));
    assertThat(subject.contains(originalDescriptor), is(true));
    assertThat(subject.contains(equivalentDescriptor), is(true));
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) ArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) Test(org.junit.Test)

Example 17 with ArtifactDescriptor

use of org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor in project tycho by eclipse.

the class ModuleArtifactRepositoryTest method testRemovingWithOtherDescriptorType.

@Test
public void testRemovingWithOtherDescriptorType() throws Exception {
    // existingModuleDir points to the original source files -> use temporary repository instead so that we don't edit source files
    subject = ModuleArtifactRepository.createInstance(null, tempManager.newFolder("targetDir"));
    // TODO write via sink
    OutputStream outputStream = subject.getOutputStream(newDescriptor(BINARY_ARTIFACT_KEY));
    writeAndClose(outputStream, BINARY_ARTIFACT_SIZE);
    IArtifactDescriptor originalDescriptor = subject.getArtifactDescriptors(BINARY_ARTIFACT_KEY)[0];
    IArtifactDescriptor equivalentDescriptor = new ArtifactDescriptor(originalDescriptor);
    // self-test: now the key/descriptor should be contained
    assertThat(subject.contains(BINARY_ARTIFACT_KEY), is(true));
    assertThat(subject.contains(originalDescriptor), is(true));
    assertThat(subject.contains(equivalentDescriptor), is(true));
    subject.removeDescriptor(equivalentDescriptor);
    assertThat(subject.contains(equivalentDescriptor), is(false));
    assertThat(subject.contains(originalDescriptor), is(false));
    assertThat(subject.contains(BUNDLE_ARTIFACT_KEY), is(false));
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) ArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test)

Example 18 with ArtifactDescriptor

use of org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor 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 19 with ArtifactDescriptor

use of org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor 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)

Example 20 with ArtifactDescriptor

use of org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor in project tycho by eclipse.

the class TargetPlatformBundlePublisherTest method artifactMD5Of.

private static String artifactMD5Of(IArtifactKey key, IRawArtifactProvider artifactProvider) throws Exception {
    ProbeRawArtifactSink probeSink = ProbeRawArtifactSink.newRawArtifactSinkFor(new ArtifactDescriptor(key));
    artifactProvider.getArtifact(probeSink, null);
    return probeSink.md5AsHex();
}
Also used : ProbeRawArtifactSink(org.eclipse.tycho.repository.streaming.testutil.ProbeRawArtifactSink) ArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)

Aggregations

IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)29 ArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor)25 Test (org.junit.Test)22 File (java.io.File)8 MavenRepositoryCoordinates (org.eclipse.tycho.p2.repository.MavenRepositoryCoordinates)8 FeatureRootAdviceTest (org.eclipse.tycho.p2.impl.publisher.rootfiles.FeatureRootAdviceTest)4 ArtifactKey (org.eclipse.equinox.internal.p2.metadata.ArtifactKey)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)2 ProcessingStepDescriptor (org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor)2 IP2Artifact (org.eclipse.tycho.p2.metadata.IP2Artifact)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 IStatus (org.eclipse.core.runtime.IStatus)1