Example usage for org.apache.maven.artifact.repository.metadata SnapshotArtifactRepositoryMetadata SnapshotArtifactRepositoryMetadata

List of usage examples for org.apache.maven.artifact.repository.metadata SnapshotArtifactRepositoryMetadata SnapshotArtifactRepositoryMetadata

Introduction

In this page you can find the example usage for org.apache.maven.artifact.repository.metadata SnapshotArtifactRepositoryMetadata SnapshotArtifactRepositoryMetadata.

Prototype

public SnapshotArtifactRepositoryMetadata(Artifact artifact, Snapshot snapshot) 

Source Link

Usage

From source file:hudson.maven.artifact.transform.SnapshotTransformation.java

License:Apache License

public void transformForInstall(Artifact artifact, ArtifactRepository localRepository) {
    if (artifact.isSnapshot()) {
        Snapshot snapshot = new Snapshot();
        snapshot.setLocalCopy(true);//from   w w w . j ava  2 s  . com
        RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata(artifact, snapshot);

        artifact.addMetadata(metadata);
    }
}

From source file:hudson.maven.artifact.transform.SnapshotTransformation.java

License:Apache License

public void transformForDeployment(Artifact artifact, ArtifactRepository remoteRepository,
        ArtifactRepository localRepository) throws ArtifactDeploymentException {
    if (artifact.isSnapshot()) {
        Snapshot snapshot = new Snapshot();
        if (remoteRepository.isUniqueVersion()) {
            snapshot.setTimestamp(getDeploymentTimestamp());
        }//from   w w w. jav  a  2s . c  o  m

        // we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect
        try {
            int buildNumber = resolveLatestSnapshotBuildNumber(artifact, localRepository, remoteRepository);

            snapshot.setBuildNumber(buildNumber + 1);
        } catch (RepositoryMetadataResolutionException e) {
            throw new ArtifactDeploymentException("Error retrieving previous build number for artifact '"
                    + artifact.getDependencyConflictId() + "': " + e.getMessage(), e);
        }

        RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata(artifact, snapshot);

        artifact.setResolvedVersion(
                constructVersion(metadata.getMetadata().getVersioning(), artifact.getBaseVersion()));

        artifact.addMetadata(metadata);
    }
}

From source file:org.eclipse.che.maven.CheArtifactResolver.java

License:Apache License

private void resolveOrig(Artifact artifact, List<ArtifactRepository> remoteRepositories,
        RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
    if (artifact == null) {
        return;/* www.ja  v  a  2s  .c  om*/
    }

    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());
                }
            }
        }
    }
}

From source file:org.jetbrains.idea.maven.server.embedder.CustomMaven32ArtifactResolver.java

License:Apache License

private void resolveOld(Artifact artifact, List<ArtifactRepository> remoteRepositories,
        RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
    if (artifact == null) {
        return;//ww  w.  ja  v  a2s  .c o m
    }

    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());
                }
            }
        }
    }
}