Search in sources :

Example 1 with RepositoryMetadata

use of org.apache.maven.artifact.repository.metadata.RepositoryMetadata in project archiva by apache.

the class LegacyToDefaultConverter method validateMetadata.

private boolean validateMetadata(Artifact artifact) throws ArtifactConversionException {
    ArtifactRepository repository = artifact.getRepository();
    boolean result = true;
    RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata(artifact);
    Path file = Paths.get(repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata(repositoryMetadata));
    if (Files.exists(file)) {
        Metadata metadata = readMetadata(file);
        result = validateMetadata(metadata, repositoryMetadata, artifact);
    }
    repositoryMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
    file = Paths.get(repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata(repositoryMetadata));
    if (Files.exists(file)) {
        Metadata metadata = readMetadata(file);
        result = result && validateMetadata(metadata, repositoryMetadata, artifact);
    }
    return result;
}
Also used : Path(java.nio.file.Path) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) RepositoryMetadata(org.apache.maven.artifact.repository.metadata.RepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) RepositoryMetadata(org.apache.maven.artifact.repository.metadata.RepositoryMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)

Example 2 with RepositoryMetadata

use of org.apache.maven.artifact.repository.metadata.RepositoryMetadata in project maven-plugins by apache.

the class DoapMojo method writeReleases.

/**
 * Write all DOAP releases.
 *
 * @param writer  not null
 * @param project the Maven project, not null
 * @throws MojoExecutionException if any
 * @see <a href="http://usefulinc.com/ns/doap#release">http://usefulinc.com/ns/doap#release</a>
 * @see <a href="http://usefulinc.com/ns/doap#Version">http://usefulinc.com/ns/doap#Version</a>
 */
private void writeReleases(XMLWriter writer, MavenProject project) throws MojoExecutionException {
    Artifact artifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging());
    RepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
    for (ArtifactRepository repo : remoteRepositories) {
        if (repo.isBlacklisted()) {
            continue;
        }
        if (repo.getSnapshots().isEnabled()) {
            continue;
        }
        if (repo.getReleases().isEnabled()) {
            try {
                repositoryMetadataManager.resolveAlways(metadata, localRepository, repo);
                break;
            } catch (RepositoryMetadataResolutionException e) {
                throw new MojoExecutionException(metadata.extendedToString() + " could not be retrieved from repositories due to an error: " + e.getMessage(), e);
            }
        }
    }
    if (metadata.getMetadata().getVersioning() == null) {
        messages.getWarnMessages().add("No versioning was found for " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ". Ignored DOAP <release/> tag.");
        return;
    }
    List<String> versions = metadata.getMetadata().getVersioning().getVersions();
    // Recent releases in first
    Collections.reverse(versions);
    boolean addComment = false;
    int i = 0;
    for (String version : versions) {
        if (!addComment) {
            DoapUtil.writeComment(writer, "Project releases.");
            addComment = true;
        }
        DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "release");
        DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "Version");
        DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "name");
        if (version.equals(metadata.getMetadata().getVersioning().getRelease())) {
            writer.writeText("Latest stable release");
        } else {
            writer.writeText(project.getName() + " - " + version);
        }
        // name
        writer.endElement();
        DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "revision", version);
        // list all file release from all remote repos
        for (ArtifactRepository repo : remoteRepositories) {
            Artifact artifactRelease = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), version, null, project.getPackaging());
            if (artifactRelease == null) {
                continue;
            }
            String fileRelease = repo.getUrl() + "/" + repo.pathOf(artifactRelease);
            try {
                DoapUtil.fetchURL(settings, new URL(fileRelease));
            } catch (IOException e) {
                getLog().debug("IOException :" + e.getMessage());
                continue;
            }
            DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "file-release", fileRelease);
            Date releaseDate = null;
            try {
                releaseDate = REPOSITORY_DATE_FORMAT.parse(metadata.getMetadata().getVersioning().getLastUpdated());
            } catch (ParseException e) {
                getLog().error("Unable to parse date '" + metadata.getMetadata().getVersioning().getLastUpdated() + "'");
                continue;
            }
            // See MDOAP-11
            if (i == 0) {
                DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(), "created", DOAP_DATE_FORMAT.format(releaseDate));
            }
        }
        // Version
        writer.endElement();
        // release
        writer.endElement();
        i++;
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) IOException(java.io.IOException) DoapArtifact(org.apache.maven.plugin.doap.options.DoapArtifact) Artifact(org.apache.maven.artifact.Artifact) URL(java.net.URL) Date(java.util.Date) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) RepositoryMetadata(org.apache.maven.artifact.repository.metadata.RepositoryMetadata) ParseException(java.text.ParseException) RepositoryMetadataResolutionException(org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata)

Example 3 with RepositoryMetadata

use of org.apache.maven.artifact.repository.metadata.RepositoryMetadata in project maven-plugins by apache.

the class TestCopyDependenciesMojo2 method createExpandedVersionArtifact.

private Artifact createExpandedVersionArtifact(String baseVersion, String groupId, String artifactId, String scope, String type, String classifier) throws IOException {
    Artifact expandedSnapshot = this.stubFactory.createArtifact(groupId, artifactId, VersionRange.createFromVersion(baseVersion), scope, type, classifier, false);
    Snapshot snapshot = new Snapshot();
    snapshot.setTimestamp("20130710.122148");
    snapshot.setBuildNumber(1);
    RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata(expandedSnapshot, snapshot);
    String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
    expandedSnapshot.setResolvedVersion(StringUtils.replace(baseVersion, Artifact.SNAPSHOT_VERSION, newVersion));
    expandedSnapshot.addMetadata(metadata);
    return expandedSnapshot;
}
Also used : Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) RepositoryMetadata(org.apache.maven.artifact.repository.metadata.RepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with RepositoryMetadata

use of org.apache.maven.artifact.repository.metadata.RepositoryMetadata in project maven-dependency-plugin by apache.

the class TestCopyDependenciesMojo2 method createExpandedVersionArtifact.

private Artifact createExpandedVersionArtifact(String baseVersion, String groupId, String artifactId, String scope, String type, String classifier) throws IOException {
    Artifact expandedSnapshot = this.stubFactory.createArtifact(groupId, artifactId, VersionRange.createFromVersion(baseVersion), scope, type, classifier, false);
    Snapshot snapshot = new Snapshot();
    snapshot.setTimestamp("20130710.122148");
    snapshot.setBuildNumber(1);
    RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata(expandedSnapshot, snapshot);
    String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
    expandedSnapshot.setResolvedVersion(StringUtils.replace(baseVersion, Artifact.SNAPSHOT_VERSION, newVersion));
    expandedSnapshot.addMetadata(metadata);
    return expandedSnapshot;
}
Also used : Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) RepositoryMetadata(org.apache.maven.artifact.repository.metadata.RepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with RepositoryMetadata

use of org.apache.maven.artifact.repository.metadata.RepositoryMetadata in project archiva by apache.

the class LegacyToDefaultConverter method updateMetadata.

private void updateMetadata(RepositoryMetadata artifactMetadata, ArtifactRepository targetRepository, Metadata newMetadata, FileTransaction transaction) throws ArtifactConversionException {
    Path file = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
    Metadata metadata;
    boolean changed;
    if (Files.exists(file)) {
        metadata = readMetadata(file);
        changed = metadata.merge(newMetadata);
    } else {
        changed = true;
        metadata = newMetadata;
    }
    if (changed) {
        try (StringWriter writer = new StringWriter()) {
            MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
            mappingWriter.write(writer, metadata);
            transaction.createFile(writer.toString(), file, digesters);
        } catch (IOException e) {
            throw new ArtifactConversionException(Messages.getString("error.writing.target.metadata"), // $NON-NLS-1$
            e);
        }
    }
}
Also used : Path(java.nio.file.Path) MetadataXpp3Writer(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer) StringWriter(java.io.StringWriter) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) RepositoryMetadata(org.apache.maven.artifact.repository.metadata.RepositoryMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) IOException(java.io.IOException)

Aggregations

RepositoryMetadata (org.apache.maven.artifact.repository.metadata.RepositoryMetadata)5 SnapshotArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)4 Artifact (org.apache.maven.artifact.Artifact)3 ArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)2 Snapshot (org.apache.maven.artifact.repository.metadata.Snapshot)2 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 RepositoryMetadataResolutionException (org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException)1 MetadataXpp3Writer (org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 DoapArtifact (org.apache.maven.plugin.doap.options.DoapArtifact)1