Java Code Examples for org.eclipse.aether.resolution.ArtifactResult#isMissing()

The following examples show how to use org.eclipse.aether.resolution.ArtifactResult#isMissing() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractMavenArtifactRepositoryManager.java    From galleon with Apache License 2.0 6 votes vote down vote up
@Override
public void resolve(MavenArtifact artifact) throws MavenUniverseException {
    if (artifact.isResolved()) {
        throw new MavenUniverseException("Artifact is already resolved");
    }
    final ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(),
            artifact.getExtension(), artifact.getVersion()));

    request.setRepositories(getRepositories());

    final ArtifactResult result;
    try {
        result = repoSystem.resolveArtifact(getSession(), request);
    } catch (Exception e) {
        throw new MavenUniverseException(FpMavenErrors.artifactResolution(request.getArtifact().toString()), e);
    }
    if (!result.isResolved()) {
        throw new MavenUniverseException(FpMavenErrors.artifactResolution(request.getArtifact().toString()));
    }
    if (result.isMissing()) {
        throw new MavenUniverseException(FpMavenErrors.artifactMissing(request.getArtifact().toString()));
    }
    artifact.setPath(Paths.get(result.getArtifact().getFile().toURI()));
}
 
Example 2
Source File: SingerMojo.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
private Path findMain() {
    final LocalRepositoryManager lrm = repositorySystemSession.getLocalRepositoryManager();
    final Artifact artifact = new DefaultArtifact(GAV.GROUP, "component-kitap", "fatjar", "jar", GAV.VERSION);
    final File location = new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact));
    if (!location.exists()) {
        final ArtifactRequest artifactRequest =
                new ArtifactRequest().setArtifact(artifact).setRepositories(remoteRepositories);
        try {
            final ArtifactResult result =
                    repositorySystem.resolveArtifact(repositorySystemSession, artifactRequest);
            if (result.isMissing()) {
                throw new IllegalStateException("Can't find " + artifact);
            }
            return result.getArtifact().getFile().toPath();
        } catch (final ArtifactResolutionException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
    return location.toPath();
}
 
Example 3
Source File: MeecrowaveBundleMojo.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
private File resolve(final String group, final String artifact, final String version, final String classifier) {
    final DefaultArtifact art = new DefaultArtifact(group, artifact, classifier, "jar", version);
    final ArtifactRequest artifactRequest = new ArtifactRequest().setArtifact(art).setRepositories(remoteRepositories);

    final LocalRepositoryManager lrm = session.getLocalRepositoryManager();
    art.setFile(new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifactRequest.getArtifact())));

    try {
        final ArtifactResult result = repositorySystem.resolveArtifact(session, artifactRequest);
        if (result.isMissing()) {
            throw new IllegalStateException("Can't find commons-cli, please add it to the pom.");
        }
        return result.getArtifact().getFile();
    } catch (final ArtifactResolutionException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 4
Source File: ComponentDependenciesBase.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
protected Artifact resolve(final Artifact art) {
    final ArtifactRequest artifactRequest =
            new ArtifactRequest().setArtifact(art).setRepositories(remoteRepositories);
    try {
        final ArtifactResult result = repositorySystem.resolveArtifact(repositorySystemSession, artifactRequest);
        if (result.isMissing()) {
            throw new IllegalStateException("Can't find " + art);
        }
        return result.getArtifact();
    } catch (final ArtifactResolutionException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 5
Source File: ArtifactResolver.java    From revapi with Apache License 2.0 5 votes vote down vote up
private Artifact resolveArtifact(Artifact artifact, RepositorySystemSession session) throws ArtifactResolutionException {
    ArtifactRequest request = new ArtifactRequest().setArtifact(artifact)
            .setRepositories(repositories);

    ArtifactResult result = repositorySystem.resolveArtifact(session, request);

    if (!result.isResolved() || result.isMissing()) {
        throw new ArtifactResolutionException(Collections.singletonList(result), "The artifact was not" +
                " resolved or is missing: '" + artifact.toString() + "'.");
    }

    return result.getArtifact();
}