public void install()

in maven-artifact-manager/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java [55:137]


    public void install( File source, Artifact artifact, ArtifactRepository localRepository )
        throws ArtifactInstallationException
    {
        
        // If we're installing the POM, we need to transform it first. The source file supplied for 
        // installation here may be the POM, but that POM may not be set as the file of the supplied
        // artifact. Since the transformation only has access to the artifact and not the supplied
        // source file, we have to use the Artifact.setFile(..) and Artifact.getFile(..) methods
        // to shunt the POM file into the transformation process.
        // Here, we also set a flag indicating that the POM has been shunted through the Artifact,
        // and to expect the transformed version to be available in the Artifact afterwards...
        boolean useArtifactFile = false;
        File oldArtifactFile = artifact.getFile();
        if ( "pom".equals( artifact.getType() ) )
        {
            artifact.setFile( source );
            useArtifactFile = true;
        }
        
        try
        {
            transformationManager.transformForInstall( artifact, localRepository );
            
            // If we used the Artifact shunt to transform a POM source file, we need to install
            // the transformed version, not the supplied version. Therefore, we need to replace
            // the supplied source POM with the one from Artifact.getFile(..).
            if ( useArtifactFile )
            {
                source = artifact.getFile();
                artifact.setFile( oldArtifactFile );
            }

            String localPath = localRepository.pathOf( artifact );

            // TODO: use a file: wagon and the wagon manager?
            File destination = new File( localRepository.getBasedir(), localPath );
            if ( !destination.getParentFile().exists() )
            {
                destination.getParentFile().mkdirs();
            }

            boolean copy =
                !destination.exists() || "pom".equals( artifact.getType() )
                    || source.lastModified() != destination.lastModified() || source.length() != destination.length();

            if ( copy )
            {
                getLogger().info( "Installing " + source + " to " + destination );

                FileUtils.copyFile( source, destination );
                destination.setLastModified( source.lastModified() );
            }
            else
            {
                getLogger().info( "Skipped re-installing " + source + " to " + destination + ", seems unchanged" );
            }

            // Now, we'll set the artifact's file to the one installed in the local repository,
            // to help avoid duplicate copy operations in the deployment step.
            if ( useArtifactFile )
            {
                artifact.setFile( destination );
            }

            // must be after the artifact is installed
            for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
            {
                ArtifactMetadata metadata = (ArtifactMetadata) i.next();
                repositoryMetadataManager.install( metadata, localRepository );
            }
            // TODO: would like to flush this, but the plugin metadata is added in advance, not as an install/deploy transformation
            // This would avoid the need to merge and clear out the state during deployment
//            artifact.getMetadataList().clear();
        }
        catch ( IOException e )
        {
            throw new ArtifactInstallationException( "Error installing artifact: " + e.getMessage(), e );
        }
        catch ( RepositoryMetadataInstallationException e )
        {
            throw new ArtifactInstallationException( "Error installing artifact's metadata: " + e.getMessage(), e );
        }
    }