Search in sources :

Example 11 with SnapshotVersion

use of org.apache.maven.artifact.repository.metadata.SnapshotVersion in project indy by Commonjava.

the class VersioningMarshaller method readFrom.

@Override
public Versioning readFrom(ProtoStreamReader reader) throws IOException {
    Versioning versioning = new Versioning();
    versioning.setRelease(reader.readString("release"));
    versioning.setLatest(reader.readString("latest"));
    versioning.setLastUpdated(reader.readString("lastUpdated"));
    versioning.setSnapshotVersions(reader.readCollection("snapshotVersions", new ArrayList<SnapshotVersion>(), SnapshotVersion.class));
    versioning.setVersions(reader.readCollection("versions", new ArrayList<String>(), String.class));
    return versioning;
}
Also used : Versioning(org.apache.maven.artifact.repository.metadata.Versioning) SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) ArrayList(java.util.ArrayList)

Example 12 with SnapshotVersion

use of org.apache.maven.artifact.repository.metadata.SnapshotVersion in project indy by Commonjava.

the class SnapshotVersionMarshaller method readFrom.

@Override
public SnapshotVersion readFrom(ProtoStreamReader reader) throws IOException {
    SnapshotVersion version = new SnapshotVersion();
    version.setClassifier(reader.readString("classifier"));
    version.setExtension(reader.readString("extension"));
    version.setUpdated(reader.readString("updated"));
    version.setVersion(reader.readString("version"));
    return version;
}
Also used : SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion)

Example 13 with SnapshotVersion

use of org.apache.maven.artifact.repository.metadata.SnapshotVersion in project platformlayer by platformlayer.

the class MavenResolver method pickSnapshot.

private Path pickSnapshot(Path versionedPath, MavenReference reference, Metadata mavenMetadata) {
    // Snapshot snapshot = mavenMetadata.getVersioning().getSnapshot();
    // String timestamp = snapshot.getTimestamp();
    // String buildNumber = snapshot.getBuildNumber();
    SnapshotVersion found = null;
    for (SnapshotVersion snapshotVersion : mavenMetadata.getVersioning().getSnapshotVersions()) {
        String classifier = snapshotVersion.getClassifier();
        String extension = snapshotVersion.getExtension();
        if (classifier == null) {
            classifier = extension;
        }
        if (Objects.equal(classifier, reference.classifier)) {
            if (found != null) {
                throw new IllegalStateException("Multiple matches found");
            }
            found = snapshotVersion;
        }
    }
    if (found == null) {
        throw new IllegalStateException("Cannot find artifact: " + reference);
    }
    String name = reference.artifactId + "-" + found.getVersion();
    if (found.getClassifier() != null) {
        name += "-" + found.getClassifier();
    }
    name += "." + found.getExtension();
    Path resolvedPath = versionedPath.resolve(name);
    return resolvedPath;
}
Also used : Path(java.nio.file.Path) SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion)

Example 14 with SnapshotVersion

use of org.apache.maven.artifact.repository.metadata.SnapshotVersion in project karaf by apache.

the class KarMojo method createArchive.

/**
 * Generates the configuration archive.
 *
 * @param bundles
 */
@SuppressWarnings("deprecation")
private File createArchive(List<Artifact> bundles, File featuresFile, String groupId, String artifactId, String version) throws MojoExecutionException {
    ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
    File archiveFile = getArchiveFile(outputDirectory, finalName, classifier);
    MavenArchiver archiver = new MavenArchiver();
    MavenArchiveConfiguration configuration = new MavenArchiveConfiguration();
    configuration.addManifestEntries(archive.getManifestEntries());
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(archiveFile);
    try {
        // TODO should .kar be a bundle?
        // archive.addManifestEntry(Constants.BUNDLE_NAME, project.getName());
        // archive.addManifestEntry(Constants.BUNDLE_VENDOR, project.getOrganization().getName());
        // ArtifactVersion version = project.getArtifact().getSelectedVersion();
        // String versionString = "" + version.getMajorVersion() + "." + version.getMinorVersion() + "." + version.getIncrementalVersion();
        // if (version.getQualifier() != null) {
        // versionString += "." + version.getQualifier();
        // }
        // archive.addManifestEntry(Constants.BUNDLE_VERSION, versionString);
        // archive.addManifestEntry(Constants.BUNDLE_MANIFESTVERSION, "2");
        // archive.addManifestEntry(Constants.BUNDLE_DESCRIPTION, project.getDescription());
        // // NB, no constant for this one
        // archive.addManifestEntry("Bundle-License", ((License) project.getLicenses().get(0)).getUrl());
        // archive.addManifestEntry(Constants.BUNDLE_DOCURL, project.getUrl());
        // //TODO this might need some help
        // archive.addManifestEntry(Constants.BUNDLE_SYMBOLICNAME, project.getArtifactId());
        // include the feature.xml
        Artifact featureArtifact = factory.createArtifactWithClassifier(groupId, artifactId, version, "xml", KarArtifactInstaller.FEATURE_CLASSIFIER);
        jarArchiver.addFile(featuresFile, repositoryPath + layout.pathOf(featureArtifact));
        if (featureArtifact.isSnapshot()) {
            // the artifact is a snapshot, create the maven-metadata-local.xml
            getLog().debug("Feature artifact is a SNAPSHOT, handling the maven-metadata-local.xml");
            File metadataTarget = new File(featuresFile.getParentFile(), "maven-metadata-local.xml");
            getLog().debug("Looking for " + metadataTarget.getAbsolutePath());
            if (!metadataTarget.exists()) {
                // the maven-metadata-local.xml doesn't exist, create it
                getLog().debug(metadataTarget.getAbsolutePath() + " doesn't exist, create it");
                Metadata metadata = new Metadata();
                metadata.setGroupId(featureArtifact.getGroupId());
                metadata.setArtifactId(featureArtifact.getArtifactId());
                metadata.setVersion(featureArtifact.getVersion());
                metadata.setModelVersion("1.1.0");
                Versioning versioning = new Versioning();
                versioning.setLastUpdatedTimestamp(new Date(System.currentTimeMillis()));
                Snapshot snapshot = new Snapshot();
                snapshot.setLocalCopy(true);
                versioning.setSnapshot(snapshot);
                SnapshotVersion snapshotVersion = new SnapshotVersion();
                snapshotVersion.setClassifier(featureArtifact.getClassifier());
                snapshotVersion.setVersion(featureArtifact.getVersion());
                snapshotVersion.setExtension(featureArtifact.getType());
                snapshotVersion.setUpdated(versioning.getLastUpdated());
                versioning.addSnapshotVersion(snapshotVersion);
                metadata.setVersioning(versioning);
                MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer();
                try (Writer writer = new FileWriter(metadataTarget)) {
                    metadataWriter.write(writer, metadata);
                } catch (Exception e) {
                    getLog().warn("Could not create maven-metadata-local.xml", e);
                    getLog().warn("It means that this SNAPSHOT could be overwritten by an older one present on remote repositories");
                }
            }
            getLog().debug("Adding file " + metadataTarget.getAbsolutePath() + " in the jar path " + repositoryPath + layout.pathOf(featureArtifact).substring(0, layout.pathOf(featureArtifact).lastIndexOf('/')) + "/maven-metadata-local.xml");
            jarArchiver.addFile(metadataTarget, repositoryPath + layout.pathOf(featureArtifact).substring(0, layout.pathOf(featureArtifact).lastIndexOf('/')) + "/maven-metadata-local.xml");
        }
        for (Artifact artifact : bundles) {
            artifactResolver.resolve(artifact, remoteRepos, localRepo);
            // TODO this may not be reasonable, but... resolved snapshot artifacts have timestamped versions
            // which do not work in startup.properties.
            artifact.setVersion(artifact.getBaseVersion());
            if (artifact.isSnapshot()) {
                // the artifact is a snapshot, create the maven-metadata-local.xml
                final File metadataTmp = Files.createTempFile("maven-metadata-local.xml", ".tmp").toFile();
                try {
                    MavenUtil.generateMavenMetadata(artifact, metadataTmp);
                } catch (Exception e) {
                    getLog().warn("Could not create maven-metadata-local.xml", e);
                    getLog().warn("It means that this SNAPSHOT could be overwritten by an older one present on remote repositories");
                }
                jarArchiver.addFile(metadataTmp, repositoryPath + layout.pathOf(artifact).substring(0, layout.pathOf(artifact).lastIndexOf('/')) + "/maven-metadata-local.xml");
                try {
                    metadataTmp.delete();
                } catch (final Exception ex) {
                    getLog().warn("Cannot delete temporary created file.", ex);
                }
            }
            String targetFileName = repositoryPath + layout.pathOf(artifact);
            jarArchiver.addFile(artifact.getFile(), targetFileName);
        }
        if (resourcesDir.isDirectory()) {
            archiver.getArchiver().addDirectory(resourcesDir);
        }
        archiver.createArchive(project, archive);
        return archiveFile;
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to create archive", e);
    }
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) MavenArchiver(org.apache.maven.archiver.MavenArchiver) Artifact(org.apache.maven.artifact.Artifact) Date(java.util.Date) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) MetadataXpp3Writer(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer) SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) MavenArchiveConfiguration(org.apache.maven.archiver.MavenArchiveConfiguration) MetadataXpp3Writer(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer)

Aggregations

SnapshotVersion (org.apache.maven.artifact.repository.metadata.SnapshotVersion)14 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)10 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)8 Snapshot (org.apache.maven.artifact.repository.metadata.Snapshot)6 MetadataXpp3Writer (org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer)5 File (java.io.File)4 FileWriter (java.io.FileWriter)3 MavenResolver (io.fabric8.maven.MavenResolver)2 Date (java.util.Date)2 MavenArtifact (org.gradle.api.publish.maven.MavenArtifact)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1