Search in sources :

Example 1 with IArtifactDescriptor

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

the class GAVArtifactDescriptorTest method testDeserialization.

@Test
public void testDeserialization() {
    // parsing to p2's implementation of IArtifactDescriptor is done elsewhere, so assume this is the input
    ArtifactDescriptor input = createP2Descriptor();
    input.setProperty("maven-groupId", TEST_GAV.getGroupId());
    input.setProperty("maven-artifactId", TEST_GAV.getArtifactId());
    input.setProperty("maven-version", TEST_GAV.getVersion());
    subject = new GAVArtifactDescriptor(input);
    assertThat(subject.getArtifactKey(), is(TEST_KEY));
    assertThat(subject.getMavenCoordinates(), is(new MavenRepositoryCoordinates(TEST_GAV, DEFAULT_CLASSIFIER, DEFAULT_EXTENSION)));
}
Also used : MavenRepositoryCoordinates(org.eclipse.tycho.p2.repository.MavenRepositoryCoordinates) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) ArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor) Test(org.junit.Test)

Example 2 with IArtifactDescriptor

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

the class LocalArtifactRepositoryP2APITest method testRemoveForeignEquivalentDescriptor.

@Test
public void testRemoveForeignEquivalentDescriptor() {
    IArtifactDescriptor foreignDescriptor = foreignEquivalentOf(ARTIFACT_B_DESCRIPTOR);
    // self-test
    assertTrue(subject.contains(foreignDescriptor));
    subject.removeDescriptor(foreignDescriptor);
    // foreign descriptor must have been replaced by internal descriptor for the calls to the internal HashMap
    assertFalse(subject.contains(foreignDescriptor));
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) Test(org.junit.Test)

Example 3 with IArtifactDescriptor

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

the class LocalArtifactRepositoryP2APITest method localPackedDescriptorFor.

/**
 * Returns a descriptor of the internally used {@link IArtifactDescriptor} type for the pack200
 * format of the given key.
 */
private static IArtifactDescriptor localPackedDescriptorFor(IArtifactKey key) {
    GAVArtifactDescriptor result = new GAVArtifactDescriptor(key);
    result.setProcessingSteps(new IProcessingStepDescriptor[] { new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true) });
    result.setProperty(IArtifactDescriptor.FORMAT, IArtifactDescriptor.FORMAT_PACKED);
    return result;
}
Also used : IProcessingStepDescriptor(org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor) ProcessingStepDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor)

Example 4 with IArtifactDescriptor

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

the class LocalArtifactRepository method saveMaven.

private void saveMaven() {
    File location = getBasedir();
    TychoRepositoryIndex index = localRepoIndices.getArtifactsIndex();
    ArtifactsIO io = new ArtifactsIO();
    Set<IArtifactDescriptor> changedDescriptors = new HashSet<IArtifactDescriptor>(descriptors);
    changedDescriptors.removeAll(descriptorsOnLastSave);
    Set<IArtifactKey> changedKeys = new HashSet<>();
    for (IArtifactDescriptor changedDescriptor : changedDescriptors) {
        changedKeys.add(changedDescriptor.getArtifactKey());
    }
    for (IArtifactKey key : changedKeys) {
        Set<GAVArtifactDescriptor> keyDescriptors = descriptorsMap.get(key);
        if (keyDescriptors != null && !keyDescriptors.isEmpty()) {
            // all descriptors should have the same GAV
            GAVArtifactDescriptor anyDescriptorOfKey = keyDescriptors.iterator().next();
            GAV gav = anyDescriptorOfKey.getMavenCoordinates().getGav();
            index.addGav(gav);
            String relpath = getMetadataRelpath(gav);
            File file = new File(location, relpath);
            file.getParentFile().mkdirs();
            try {
                OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
                try {
                    io.writeXML(keyDescriptors, os);
                } finally {
                    os.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
    try {
        index.save();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    descriptorsOnLastSave = new HashSet<IArtifactDescriptor>(descriptors);
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) ArtifactsIO(org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO) TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) IOException(java.io.IOException) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) FileOutputStream(java.io.FileOutputStream) File(java.io.File) GAV(org.eclipse.tycho.p2.repository.GAV) BufferedOutputStream(java.io.BufferedOutputStream) HashSet(java.util.HashSet)

Example 5 with IArtifactDescriptor

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

the class LocalArtifactRepository method loadMaven.

private void loadMaven() {
    final ArtifactsIO io = new ArtifactsIO();
    TychoRepositoryIndex index = localRepoIndices.getArtifactsIndex();
    for (final GAV gav : index.getProjectGAVs()) {
        try {
            File localArtifactFileLocation = contentLocator.getLocalArtifactLocation(gav, RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS, RepositoryLayoutHelper.EXTENSION_P2_ARTIFACTS);
            if (!localArtifactFileLocation.exists()) {
                // if files have been manually removed from the repository, simply remove them from the index (bug 351080)
                index.removeGav(gav);
            } else {
                final InputStream is = new FileInputStream(contentLocator.getLocalArtifactLocation(gav, RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS, RepositoryLayoutHelper.EXTENSION_P2_ARTIFACTS));
                try {
                    final Set<IArtifactDescriptor> gavDescriptors = io.readXML(is);
                    for (IArtifactDescriptor descriptor : gavDescriptors) {
                        internalAddDescriptor(descriptor);
                    }
                } finally {
                    is.close();
                }
            }
        } catch (IOException e) {
            // TODO throw properly typed exception if repository cannot be loaded
            e.printStackTrace();
        }
    }
    descriptorsOnLastSave = new HashSet<IArtifactDescriptor>(descriptors);
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArtifactsIO(org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO) TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) IOException(java.io.IOException) GAV(org.eclipse.tycho.p2.repository.GAV) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)32 Test (org.junit.Test)16 File (java.io.File)9 IStatus (org.eclipse.core.runtime.IStatus)8 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)7 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)6 OutputStream (java.io.OutputStream)5 ArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor)5 IOException (java.io.IOException)4 IArtifactRepository (org.eclipse.equinox.p2.repository.artifact.IArtifactRepository)4 FeatureRootAdviceTest (org.eclipse.tycho.p2.impl.publisher.rootfiles.FeatureRootAdviceTest)4 ArtifactsIO (org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO)4 IP2Artifact (org.eclipse.tycho.p2.metadata.IP2Artifact)4 BufferedOutputStream (java.io.BufferedOutputStream)3 FileOutputStream (java.io.FileOutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2