Search in sources :

Example 1 with TychoRepositoryIndex

use of org.eclipse.tycho.p2.repository.TychoRepositoryIndex in project tycho by eclipse.

the class LocalArtifactRepositoryTest method testOutdatedIndex.

@Test
public void testOutdatedIndex() {
    // create Repo with single artifact
    LocalArtifactRepository repo = new LocalArtifactRepository(localRepoIndices);
    ArtifactDescriptor desc = newBundleArtifactDescriptor(false);
    repo.addDescriptor(desc);
    repo.save();
    // check: the artifact is in the index
    TychoRepositoryIndex artifactIndex = createArtifactsIndex(baseDir);
    Assert.assertFalse(artifactIndex.getProjectGAVs().isEmpty());
    // delete artifact content from file system
    deleteDir(new File(baseDir, "p2"));
    // create a new repo and check that the reference was gracefully removed from the index
    repo = new LocalArtifactRepository(localRepoIndices);
    repo.save();
    artifactIndex = createArtifactsIndex(baseDir);
    Assert.assertTrue(artifactIndex.getProjectGAVs().isEmpty());
}
Also used : ArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) File(java.io.File) Test(org.junit.Test)

Example 2 with TychoRepositoryIndex

use of org.eclipse.tycho.p2.repository.TychoRepositoryIndex in project tycho by eclipse.

the class LocalMetadataRepositoryTest method createRepository.

private LocalMetadataRepository createRepository(File location) throws ProvisionException {
    location.mkdirs();
    File metadataFile = new File(location, FileBasedTychoRepositoryIndex.METADATA_INDEX_RELPATH);
    metadataFile.delete();
    metadataFile.getParentFile().mkdirs();
    TychoRepositoryIndex metadataIndex = createMetadataIndex(location);
    return new LocalMetadataRepository(location.toURI(), metadataIndex);
}
Also used : TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) FileBasedTychoRepositoryIndex(org.eclipse.tycho.repository.local.index.FileBasedTychoRepositoryIndex) File(java.io.File)

Example 3 with TychoRepositoryIndex

use of org.eclipse.tycho.p2.repository.TychoRepositoryIndex in project tycho by eclipse.

the class LocalMetadataRepositoryTest method testOutdatedIndex.

@Test
public void testOutdatedIndex() throws CoreException {
    // create and fill repo
    File location = new File("target/indexmetadataRepo");
    LocalMetadataRepository repository = createRepository(location);
    InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
    iud.setId("test");
    iud.setVersion(Version.parseVersion("1.0.0"));
    iud.setProperty(RepositoryLayoutHelper.PROP_GROUP_ID, "group");
    iud.setProperty(RepositoryLayoutHelper.PROP_ARTIFACT_ID, "artifact");
    iud.setProperty(RepositoryLayoutHelper.PROP_VERSION, "version");
    IInstallableUnit iu = MetadataFactory.createInstallableUnit(iud);
    repository.addInstallableUnits(Arrays.asList(iu));
    repository = (LocalMetadataRepository) loadRepository(location);
    // check: the artifact is in the index
    TychoRepositoryIndex metaIndex = createMetadataIndex(location);
    Assert.assertFalse(metaIndex.getProjectGAVs().isEmpty());
    // delete artifact from file system
    deleteDir(new File(location, "group"));
    // create a new repo and check that the reference was gracefully removed from the index
    repository = (LocalMetadataRepository) loadRepository(location);
    repository.save();
    metaIndex = createMetadataIndex(location);
    Assert.assertTrue(metaIndex.getProjectGAVs().isEmpty());
}
Also used : InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) FileBasedTychoRepositoryIndex(org.eclipse.tycho.repository.local.index.FileBasedTychoRepositoryIndex) File(java.io.File) Test(org.junit.Test)

Example 4 with TychoRepositoryIndex

use of org.eclipse.tycho.p2.repository.TychoRepositoryIndex 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 TychoRepositoryIndex

use of org.eclipse.tycho.p2.repository.TychoRepositoryIndex 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

TychoRepositoryIndex (org.eclipse.tycho.p2.repository.TychoRepositoryIndex)7 File (java.io.File)5 GAV (org.eclipse.tycho.p2.repository.GAV)4 IOException (java.io.IOException)3 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)3 ArtifactsIO (org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO)2 FileBasedTychoRepositoryIndex (org.eclipse.tycho.repository.local.index.FileBasedTychoRepositoryIndex)2 Test (org.junit.Test)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 Artifact (org.apache.maven.artifact.Artifact)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)1 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)1 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)1 ArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor)1