Search in sources :

Example 1 with Snapshot

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

the class MavenUtil method generateMavenMetadata.

/**
     * Generate the maven-metadata-local.xml for the given Maven <code>Artifact</code>.
     *
     * @param artifact the Maven <code>Artifact</code>.
     * @param target   the target maven-metadata-local.xml file to generate.
     * @throws IOException if the maven-metadata-local.xml can't be generated.
     */
public static void generateMavenMetadata(Artifact artifact, File target) throws IOException {
    target.getParentFile().mkdirs();
    Metadata metadata = new Metadata();
    metadata.setGroupId(artifact.getGroupId());
    metadata.setArtifactId(artifact.getArtifactId());
    metadata.setVersion(artifact.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(artifact.getClassifier());
    snapshotVersion.setVersion(artifact.getVersion());
    snapshotVersion.setExtension(artifact.getType());
    snapshotVersion.setUpdated(versioning.getLastUpdated());
    versioning.addSnapshotVersion(snapshotVersion);
    metadata.setVersioning(versioning);
    MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer();
    Writer writer = new FileWriter(target);
    metadataWriter.write(writer, metadata);
}
Also used : 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) FileWriter(java.io.FileWriter) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) Date(java.util.Date) FileWriter(java.io.FileWriter) MetadataXpp3Writer(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer) Writer(java.io.Writer)

Example 2 with Snapshot

use of org.apache.maven.artifact.repository.metadata.Snapshot 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 3 with Snapshot

use of org.apache.maven.artifact.repository.metadata.Snapshot in project che by eclipse.

the class CheArtifactResolver method resolveOrig.

private void resolveOrig(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
    if (artifact == null) {
        return;
    }
    if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
        File systemFile = artifact.getFile();
        if (systemFile == null) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact);
        }
        if (!systemFile.exists()) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " not found in path: " + systemFile, artifact);
        }
        if (!systemFile.isFile()) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " is not a file: " + systemFile, artifact);
        }
        artifact.setResolved(true);
        return;
    }
    if (!artifact.isResolved()) {
        ArtifactResult result;
        try {
            ArtifactRequest artifactRequest = new ArtifactRequest();
            artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
            artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));
            // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
            LocalRepositoryManager lrm = session.getLocalRepositoryManager();
            String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
            artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
            result = repoSystem.resolveArtifact(session, artifactRequest);
        } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
            if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
                throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e);
            } else {
                throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
            }
        }
        artifact.selectVersion(result.getArtifact().getVersion());
        artifact.setFile(result.getArtifact().getFile());
        artifact.setResolved(true);
        if (artifact.isSnapshot()) {
            Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
            if (matcher.matches()) {
                Snapshot snapshot = new Snapshot();
                snapshot.setTimestamp(matcher.group(2));
                try {
                    snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
                    artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
                } catch (NumberFormatException e) {
                    logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
                }
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) LegacyLocalRepositoryManager(org.apache.maven.artifact.repository.LegacyLocalRepositoryManager) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) File(java.io.File) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException)

Example 4 with Snapshot

use of org.apache.maven.artifact.repository.metadata.Snapshot in project intellij-community by JetBrains.

the class CustomMaven3ArtifactResolver method resolveOld.

private void resolveOld(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
    if (artifact == null) {
        return;
    }
    if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
        File systemFile = artifact.getFile();
        if (systemFile == null) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact);
        }
        if (!systemFile.exists()) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " not found in path: " + systemFile, artifact);
        }
        if (!systemFile.isFile()) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " is not a file: " + systemFile, artifact);
        }
        artifact.setResolved(true);
        return;
    }
    if (!artifact.isResolved()) {
        ArtifactResult result;
        try {
            ArtifactRequest artifactRequest = new ArtifactRequest();
            artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
            artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));
            // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
            LocalRepositoryManager lrm = session.getLocalRepositoryManager();
            String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
            artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
            result = repoSystem.resolveArtifact(session, artifactRequest);
        } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
            if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
                throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e);
            } else {
                throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
            }
        }
        artifact.selectVersion(result.getArtifact().getVersion());
        artifact.setFile(result.getArtifact().getFile());
        artifact.setResolved(true);
        if (artifact.isSnapshot()) {
            Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
            if (matcher.matches()) {
                Snapshot snapshot = new Snapshot();
                snapshot.setTimestamp(matcher.group(2));
                try {
                    snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
                    artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
                } catch (NumberFormatException e) {
                    logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
                }
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) LegacyLocalRepositoryManager(org.apache.maven.artifact.repository.LegacyLocalRepositoryManager) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) File(java.io.File)

Example 5 with Snapshot

use of org.apache.maven.artifact.repository.metadata.Snapshot in project intellij-community by JetBrains.

the class CustomMaven30ArtifactResolver method resolveOld.

private void resolveOld(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
    if (artifact == null) {
        return;
    }
    if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
        File systemFile = artifact.getFile();
        if (systemFile == null) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact);
        }
        if (!systemFile.exists()) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " not found in path: " + systemFile, artifact);
        }
        if (!systemFile.isFile()) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " is not a file: " + systemFile, artifact);
        }
        artifact.setResolved(true);
        return;
    }
    if (!artifact.isResolved()) {
        ArtifactResult result;
        try {
            ArtifactRequest artifactRequest = new ArtifactRequest();
            artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
            artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));
            // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
            LocalRepositoryManager lrm = session.getLocalRepositoryManager();
            String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
            artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
            result = repoSystem.resolveArtifact(session, artifactRequest);
        } catch (org.sonatype.aether.resolution.ArtifactResolutionException e) {
            if (e.getCause() instanceof org.sonatype.aether.transfer.ArtifactNotFoundException) {
                throw new ArtifactNotFoundException(e.getMessage(), artifact, remoteRepositories, e) {
                };
            } else {
                throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
            }
        }
        artifact.selectVersion(result.getArtifact().getVersion());
        artifact.setFile(result.getArtifact().getFile());
        artifact.setResolved(true);
        if (artifact.isSnapshot()) {
            Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
            if (matcher.matches()) {
                Snapshot snapshot = new Snapshot();
                snapshot.setTimestamp(matcher.group(2));
                try {
                    snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
                    artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
                } catch (NumberFormatException e) {
                    logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
                }
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) LegacyLocalRepositoryManager(org.apache.maven.artifact.repository.LegacyLocalRepositoryManager) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) File(java.io.File)

Aggregations

Snapshot (org.apache.maven.artifact.repository.metadata.Snapshot)6 SnapshotArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)4 File (java.io.File)3 Matcher (java.util.regex.Matcher)3 LegacyLocalRepositoryManager (org.apache.maven.artifact.repository.LegacyLocalRepositoryManager)3 Date (java.util.Date)2 Artifact (org.apache.maven.artifact.Artifact)2 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)2 SnapshotVersion (org.apache.maven.artifact.repository.metadata.SnapshotVersion)2 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)2 MetadataXpp3Writer (org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)2 LocalRepositoryManager (org.eclipse.aether.repository.LocalRepositoryManager)2 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)2 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)2 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 MavenArchiveConfiguration (org.apache.maven.archiver.MavenArchiveConfiguration)1 MavenArchiver (org.apache.maven.archiver.MavenArchiver)1