Search in sources :

Example 1 with ArtifactsIO

use of org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO 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 2 with ArtifactsIO

use of org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO 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)

Example 3 with ArtifactsIO

use of org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO in project tycho by eclipse.

the class ModuleArtifactRepository method internalStoreWithException.

private void internalStoreWithException() throws IOException {
    ArtifactsIO io = new ArtifactsIO();
    io.writeXML(descriptors, p2DataFile);
}
Also used : ArtifactsIO(org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO)

Example 4 with ArtifactsIO

use of org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO in project tycho by eclipse.

the class P2GeneratorImpl method persistMetadata.

@Override
public void persistMetadata(Map<String, IP2Artifact> metadata, File unitsXml, File artifactsXml) throws IOException {
    Set<IInstallableUnit> units = new LinkedHashSet<>();
    Set<IArtifactDescriptor> artifactDescriptors = new LinkedHashSet<>();
    for (IP2Artifact artifact : metadata.values()) {
        for (Object unit : artifact.getInstallableUnits()) {
            units.add((IInstallableUnit) unit);
        }
        artifactDescriptors.add((IArtifactDescriptor) artifact.getArtifactDescriptor());
    }
    new MetadataIO().writeXML(units, unitsXml);
    new ArtifactsIO().writeXML(artifactDescriptors, artifactsXml);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) MetadataIO(org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) ArtifactsIO(org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 5 with ArtifactsIO

use of org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO in project tycho by eclipse.

the class ModuleArtifactRepository method load.

private void load() throws ProvisionException {
    try {
        FileInputStream p2DataFileStream = new FileInputStream(p2DataFile);
        try {
            Set<IArtifactDescriptor> descriptors = new ArtifactsIO().readXML(p2DataFileStream);
            for (IArtifactDescriptor descriptor : descriptors) {
                ModuleArtifactDescriptor internalDescriptor = getInternalDescriptorFromLoadedDescriptor(descriptor, p2DataFile);
                // TODO check that GAV properties match module GAV
                internalAddInternalDescriptor(internalDescriptor);
            }
        } finally {
            p2DataFileStream.close();
        }
    } catch (IOException e) {
        throw failedReadException(p2DataFile, null, e);
    }
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) ArtifactsIO(org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ModuleArtifactDescriptor(org.eclipse.tycho.repository.module.ModuleArtifactRepository.ModuleArtifactDescriptor)

Aggregations

ArtifactsIO (org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO)5 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)4 IOException (java.io.IOException)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 GAV (org.eclipse.tycho.p2.repository.GAV)2 TychoRepositoryIndex (org.eclipse.tycho.p2.repository.TychoRepositoryIndex)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)1 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)1 MetadataIO (org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO)1 IP2Artifact (org.eclipse.tycho.p2.metadata.IP2Artifact)1 ModuleArtifactDescriptor (org.eclipse.tycho.repository.module.ModuleArtifactRepository.ModuleArtifactDescriptor)1