Search in sources :

Example 1 with InstallationException

use of org.sonatype.aether.installation.InstallationException in project sonatype-aether by sonatype.

the class DefaultInstaller method install.

private void install(RepositorySystemSession session, RequestTrace trace, Artifact artifact) throws InstallationException {
    LocalRepositoryManager lrm = session.getLocalRepositoryManager();
    File srcFile = artifact.getFile();
    File dstFile = new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact));
    artifactInstalling(session, trace, artifact, dstFile);
    Exception exception = null;
    try {
        boolean copy = "pom".equals(artifact.getExtension()) || srcFile.lastModified() != dstFile.lastModified() || srcFile.length() != dstFile.length();
        if (copy) {
            fileProcessor.copy(srcFile, dstFile, null);
            dstFile.setLastModified(srcFile.lastModified());
        } else {
            logger.debug("Skipped re-installing " + srcFile + " to " + dstFile + ", seems unchanged");
        }
        lrm.add(session, new LocalArtifactRegistration(artifact));
    } catch (Exception e) {
        exception = e;
        throw new InstallationException("Failed to install artifact " + artifact + ": " + e.getMessage(), e);
    } finally {
        artifactInstalled(session, trace, artifact, dstFile, exception);
    }
}
Also used : LocalArtifactRegistration(org.sonatype.aether.repository.LocalArtifactRegistration) InstallationException(org.sonatype.aether.installation.InstallationException) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) File(java.io.File) InstallationException(org.sonatype.aether.installation.InstallationException)

Example 2 with InstallationException

use of org.sonatype.aether.installation.InstallationException in project sonatype-aether by sonatype.

the class DefaultInstaller method install.

private void install(RepositorySystemSession session, RequestTrace trace, Metadata metadata) throws InstallationException {
    LocalRepositoryManager lrm = session.getLocalRepositoryManager();
    File dstFile = new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalMetadata(metadata));
    metadataInstalling(session, trace, metadata, dstFile);
    Exception exception = null;
    try {
        if (metadata instanceof MergeableMetadata) {
            ((MergeableMetadata) metadata).merge(dstFile, dstFile);
        } else {
            fileProcessor.copy(metadata.getFile(), dstFile, null);
        }
        lrm.add(session, new LocalMetadataRegistration(metadata));
    } catch (Exception e) {
        exception = e;
        throw new InstallationException("Failed to install metadata " + metadata + ": " + e.getMessage(), e);
    } finally {
        metadataInstalled(session, trace, metadata, dstFile, exception);
    }
}
Also used : InstallationException(org.sonatype.aether.installation.InstallationException) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) MergeableMetadata(org.sonatype.aether.metadata.MergeableMetadata) LocalMetadataRegistration(org.sonatype.aether.repository.LocalMetadataRegistration) File(java.io.File) InstallationException(org.sonatype.aether.installation.InstallationException)

Example 3 with InstallationException

use of org.sonatype.aether.installation.InstallationException in project sonatype-aether by sonatype.

the class DefaultInstallerTest method checkFailedEvents.

private void checkFailedEvents(String msg, Artifact artifact) {
    InstallRequest request = new InstallRequest().addArtifact(artifact);
    msg = "Repository events problem (case: " + msg + ")";
    try {
        installer.install(session, request);
        fail("expected exception");
    } catch (InstallationException e) {
        checkEvents(msg, artifact, true);
    }
}
Also used : InstallRequest(org.sonatype.aether.installation.InstallRequest) InstallationException(org.sonatype.aether.installation.InstallationException)

Example 4 with InstallationException

use of org.sonatype.aether.installation.InstallationException in project sonatype-aether by sonatype.

the class DefaultInstallerTest method checkFailedEvents.

private void checkFailedEvents(String msg, Metadata metadata) {
    InstallRequest request = new InstallRequest().addMetadata(metadata);
    msg = "Repository events problem (case: " + msg + ")";
    try {
        installer.install(session, request);
        fail("expected exception");
    } catch (InstallationException e) {
        checkEvents(msg, metadata, true);
    }
}
Also used : InstallRequest(org.sonatype.aether.installation.InstallRequest) InstallationException(org.sonatype.aether.installation.InstallationException)

Aggregations

InstallationException (org.sonatype.aether.installation.InstallationException)4 File (java.io.File)2 InstallRequest (org.sonatype.aether.installation.InstallRequest)2 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)2 MergeableMetadata (org.sonatype.aether.metadata.MergeableMetadata)1 LocalArtifactRegistration (org.sonatype.aether.repository.LocalArtifactRegistration)1 LocalMetadataRegistration (org.sonatype.aether.repository.LocalMetadataRegistration)1