Search in sources :

Example 1 with MetadataIO

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

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

the class AbstractMavenMetadataRepository method load.

protected void load() {
    MetadataIO io = new MetadataIO();
    for (GAV gav : metadataIndex.getProjectGAVs()) {
        try {
            File localArtifactFileLocation = contentLocator.getLocalArtifactLocation(gav, RepositoryLayoutHelper.CLASSIFIER_P2_METADATA, RepositoryLayoutHelper.EXTENSION_P2_METADATA);
            if (!localArtifactFileLocation.exists()) {
                // if files have been manually removed from the repository, simply remove them from the index (bug 351080)
                metadataIndex.removeGav(gav);
            } else {
                InputStream is = new FileInputStream(localArtifactFileLocation);
                try {
                    Set<IInstallableUnit> gavUnits = io.readXML(is);
                    unitsMap.put(gav, gavUnits);
                    units.addAll(gavUnits);
                } finally {
                    is.close();
                }
            }
        } catch (IOException e) {
            // TODO throw properly typed exception if repository cannot be loaded
            e.printStackTrace();
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MetadataIO(org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IOException(java.io.IOException) GAV(org.eclipse.tycho.p2.repository.GAV) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with MetadataIO

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

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

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

the class ModuleMetadataRepository method storeWithoutExceptionHandling.

private void storeWithoutExceptionHandling() throws IOException {
    storage.getParentFile().mkdirs();
    MetadataIO io = new MetadataIO();
    io.writeXML(units, storage);
}
Also used : MetadataIO(org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO)

Aggregations

MetadataIO (org.eclipse.tycho.p2.maven.repository.xmlio.MetadataIO)7 IOException (java.io.IOException)5 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)5 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)2 GAV (org.eclipse.tycho.p2.repository.GAV)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 LinkedHashSet (java.util.LinkedHashSet)1 ArtifactKey (org.eclipse.equinox.internal.p2.metadata.ArtifactKey)1 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)1 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)1 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)1 IArtifactRepository (org.eclipse.equinox.p2.repository.artifact.IArtifactRepository)1 ArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor)1 ArtifactsIO (org.eclipse.tycho.p2.maven.repository.xmlio.ArtifactsIO)1 IP2Artifact (org.eclipse.tycho.p2.metadata.IP2Artifact)1