Example usage for org.apache.maven.artifact.resolver ArtifactResolutionResult hasMissingArtifacts

List of usage examples for org.apache.maven.artifact.resolver ArtifactResolutionResult hasMissingArtifacts

Introduction

In this page you can find the example usage for org.apache.maven.artifact.resolver ArtifactResolutionResult hasMissingArtifacts.

Prototype

public boolean hasMissingArtifacts() 

Source Link

Usage

From source file:org.seasar.uruma.eclipath.ArtifactHelper.java

License:Apache License

public void resolve(EclipathArtifact artifact, boolean throwOnError, boolean forceResolve) {
    // TODO Maven3 ????
    // Check if jar is not available
    File notAvailableFile = null;
    if (workspaceConfigurator.isConfigured()) {
        String notAvailablePath = workspaceConfigurator.getClasspathVariableM2REPO() + "/"
                + artifact.getRepositoryPath() + NOT_AVAILABLE_SUFFIX;
        notAvailableFile = new File(notAvailablePath);
        if (!forceResolve) {
            if (!throwOnError && notAvailableFile.exists()) {
                return;
            }//from w w  w  .j  av  a2 s  . com
        } else {
            notAvailableFile.delete();
        }
    }

    // prepare artifact resolution request
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact.getArtifact());
    request.setLocalRepository(localRepository);
    request.setRemoteRepositories(remoteRepositories);
    // TODO ?
    request.setForceUpdate(forceResolve);

    // do resolve
    ArtifactResolutionResult result = repositorySystem.resolve(request);
    if (result.isSuccess()) {
        for (Artifact resolvedSrcArtifact : result.getArtifacts()) {
            Logger.info("  resolved: " + resolvedSrcArtifact.toString());
        }
    } else {
        try {
            if (result.hasMissingArtifacts() && notAvailableFile != null) {
                FileUtils.touch(notAvailableFile);
            }
        } catch (IOException ignore) {
        }

        if (throwOnError) {
            throw new ArtifactResolutionRuntimeException("artifact resolution failed.", result);
        } else {
            Logger.warn("artifact resolution failed. : " + artifact.toString());
        }
    }
}