Search in sources :

Example 1 with GAV

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

the class GAVArtifactDescriptor method getP2DerivedCoordinates.

/**
 * @return fake Maven coordinates derived from the given key; never <code>null</code>
 */
private static MavenRepositoryCoordinates getP2DerivedCoordinates(IArtifactKey key, Map<String, String> properties) {
    GAV gav = RepositoryLayoutHelper.getP2Gav(key.getClassifier(), key.getId(), key.getVersion().toString());
    String classifier = null;
    String extension = RepositoryLayoutHelper.DEFAULT_EXTERNSION;
    if (properties != null && IArtifactDescriptor.FORMAT_PACKED.equals(properties.get(IArtifactDescriptor.FORMAT))) {
        classifier = RepositoryLayoutHelper.PACK200_CLASSIFIER;
        extension = RepositoryLayoutHelper.PACK200_EXTENSION;
    }
    return new MavenRepositoryCoordinates(gav, classifier, extension);
}
Also used : MavenRepositoryCoordinates(org.eclipse.tycho.p2.repository.MavenRepositoryCoordinates) GAV(org.eclipse.tycho.p2.repository.GAV)

Example 2 with GAV

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

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

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

the class LocalMetadataRepository method save.

public void save() {
    File basedir = new File(getLocation());
    MetadataIO io = new MetadataIO();
    for (GAV gav : changedGAVs) {
        Set<IInstallableUnit> gavUnits = unitsMap.get(gav);
        if (gavUnits != null && !gavUnits.isEmpty()) {
            String relpath = RepositoryLayoutHelper.getRelativePath(gav, RepositoryLayoutHelper.CLASSIFIER_P2_METADATA, RepositoryLayoutHelper.EXTENSION_P2_METADATA);
            File file = new File(basedir, relpath);
            file.getParentFile().mkdirs();
            try {
                io.writeXML(gavUnits, file);
                metadataIndex.addGav(gav);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
    try {
        metadataIndex.save();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    changedGAVs.clear();
}
Also used : MetadataIO(org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IOException(java.io.IOException) File(java.io.File) GAV(org.eclipse.tycho.p2.repository.GAV)

Example 5 with GAV

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

the class LocalMetadataRepository method addInstallableUnits.

@Override
public void addInstallableUnits(Collection<IInstallableUnit> newUnits) {
    for (IInstallableUnit unit : newUnits) {
        GAV gav = RepositoryLayoutHelper.getGAV(unit.getProperties());
        addInstallableUnit(unit, gav);
    }
    save();
}
Also used : IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) GAV(org.eclipse.tycho.p2.repository.GAV)

Aggregations

GAV (org.eclipse.tycho.p2.repository.GAV)15 IOException (java.io.IOException)6 File (java.io.File)5 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)5 FileInputStream (java.io.FileInputStream)4 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)4 TychoRepositoryIndex (org.eclipse.tycho.p2.repository.TychoRepositoryIndex)4 Test (org.junit.Test)4 ArtifactsIO (org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO)3 BufferedOutputStream (java.io.BufferedOutputStream)2 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 MetadataIO (org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO)2 MavenRepositoryCoordinates (org.eclipse.tycho.p2.repository.MavenRepositoryCoordinates)2 BufferedReader (java.io.BufferedReader)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1