Example usage for org.apache.maven.artifact.installer ArtifactInstallationException ArtifactInstallationException

List of usage examples for org.apache.maven.artifact.installer ArtifactInstallationException ArtifactInstallationException

Introduction

In this page you can find the example usage for org.apache.maven.artifact.installer ArtifactInstallationException ArtifactInstallationException.

Prototype

public ArtifactInstallationException(String message, Throwable cause) 

Source Link

Usage

From source file:org.hardisonbrewing.maven.core.DependencyService.java

License:Open Source License

public static final void install(File src, Artifact artifact) throws ArtifactInstallationException {

    try {/*from  w w  w  .j a  va2 s .  c  om*/
        artifact.addMetadata(createArtifactMetadata(artifact));
    } catch (IOException e) {
        throw new ArtifactInstallationException(e.getMessage(), e);
    }

    ArtifactInstaller artifactInstaller = getArtifactInstaller();
    artifactInstaller.install(src, artifact, DependencyService.getLocalRepository());
}

From source file:org.sonatype.nexus.maven.staging.deploy.strategy.AbstractDeployStrategy.java

License:Open Source License

/**
 * Performs an "install" (not to be confused with "install into local repository!) into the staging repository. It
 * will retain snapshot versions, and no metadata is created at all. In short: performs a simple file copy.
 * <p/>//from w  w w .  j  a v  a  2 s . c  om
 * This one single method is not thread safe, as it performs IO and appends to the "index" file. Hence, this
 * one method is execute in a synchronized block of a static object's monitor, to prevent multiple parallel
 * install actions to happen. As install is local FS operation, this method should quickly finish it's job
 * as costly operations (like asking for Staging profile of REST API of remote Nexus) already happened, we
 * do only local FS ops here.
 */
protected void install(final File source, final Artifact artifact, final ArtifactRepository stagingRepository,
        final File stagingDirectory, final ArtifactRepository remoteRepository)
        throws ArtifactInstallationException, MojoExecutionException {
    synchronized (parallelLock) {
        final String path = stagingRepository.pathOf(artifact);
        try {
            artifactInstaller.install(source, artifact, stagingRepository);

            String pluginPrefix = null;
            // String pluginName = null;
            for (ArtifactMetadata artifactMetadata : artifact.getMetadataList()) {
                if (artifactMetadata instanceof GroupRepositoryMetadata) {
                    final Plugin plugin = ((GroupRepositoryMetadata) artifactMetadata).getMetadata()
                            .getPlugins().get(0);
                    pluginPrefix = plugin.getPrefix();
                    // pluginName = plugin.getName();
                }
            }

            // append the index file
            final FileOutputStream fos = new FileOutputStream(new File(stagingDirectory, ".index"), true);
            final OutputStreamWriter osw = new OutputStreamWriter(fos, "ISO-8859-1");
            final PrintWriter pw = new PrintWriter(osw);
            String pomFileName = null;
            for (ArtifactMetadata artifactMetadata : artifact.getMetadataList()) {
                if (artifactMetadata instanceof ProjectArtifactMetadata) {
                    pomFileName = (artifactMetadata).getLocalFilename(stagingRepository);
                }
            }
            pw.println(String.format("%s=%s:%s:%s:%s:%s:%s:%s:%s:%s:%s", path, artifact.getGroupId(),
                    artifact.getArtifactId(), artifact.getVersion(),
                    Strings.isNullOrEmpty(artifact.getClassifier()) ? "n/a" : artifact.getClassifier(),
                    artifact.getType(), artifact.getArtifactHandler().getExtension(),
                    Strings.isNullOrEmpty(pomFileName) ? "n/a" : pomFileName,
                    Strings.isNullOrEmpty(pluginPrefix) ? "n/a" : pluginPrefix,
                    remoteRepository != null ? remoteRepository.getId() : "n/a",
                    remoteRepository != null ? remoteRepository.getUrl() : "n/a"));
            pw.flush();
            pw.close();
        } catch (IOException e) {
            throw new ArtifactInstallationException("Cannot locally stage and maintain the index file!", e);
        }
    }
}