Author: jdcasey Date: Thu Aug 10 12:53:38 2006 New Revision: 430505 URL: http://svn.apache.org/viewvc?rev=430505&view=rev Log: Adding plugin to allow the staging of a freshly built plugin into the local repository for integration testing, then pull it back out for actual installation/deployment/whatever.
Added: maven/sandbox/plugins/maven-plugin-test-plugin/ maven/sandbox/plugins/maven-plugin-test-plugin/pom.xml (with props) maven/sandbox/plugins/maven-plugin-test-plugin/src/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedInstallMojo.java (with props) maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedUninstallMojo.java (with props) maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/backup/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/backup/PluginBackupManager.java (with props) maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/DefaultPluginManagerAccess.java (with props) maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/PluginManagerAccess.java (with props) maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingException.java (with props) maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingManager.java (with props) Added: maven/sandbox/plugins/maven-plugin-test-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-plugin-test-plugin/pom.xml?rev=430505&view=auto ============================================================================== --- maven/sandbox/plugins/maven-plugin-test-plugin/pom.xml (added) +++ maven/sandbox/plugins/maven-plugin-test-plugin/pom.xml Thu Aug 10 12:53:38 2006 @@ -0,0 +1,72 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-test-plugin</artifactId> + <packaging>maven-plugin</packaging> + <version>1.0-SNAPSHOT</version> + <name>Maven Mojo Archetype</name> + <url>http://maven.apache.org</url> + <dependencies> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>file-management</artifactId> + <version>1.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0.4</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>2.0.4</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.0.4</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact-manager</artifactId> + <version>2.0.4</version> + </dependency> + <dependency> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>2.1</version> + <type>maven-plugin</type> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-plugin-plugin</artifactId> + <configuration> + <goalPrefix>plugin-test</goalPrefix> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-maven-plugin</artifactId> + <executions> + <execution> + <id>create-component-descriptor</id> + <phase>generate-resources</phase> + <goals> + <goal>descriptor</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/pom.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedInstallMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedInstallMojo.java?rev=430505&view=auto ============================================================================== --- maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedInstallMojo.java (added) +++ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedInstallMojo.java Thu Aug 10 12:53:38 2006 @@ -0,0 +1,152 @@ +package org.apache.maven.plugin.plugintest; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.installer.ArtifactInstaller; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.plugintest.backup.PluginBackupManager; +import org.apache.maven.plugin.plugintest.manager.PluginManagerAccess; +import org.apache.maven.plugin.plugintest.stage.PluginStagingException; +import org.apache.maven.plugin.plugintest.stage.PluginStagingManager; + +import java.io.File; +import java.io.IOException; + +/** + * Stages a plugin for integration testing. + * + * @goal stage + * + * @phase pre-integration-test + */ +public class StagedInstallMojo + extends AbstractMojo +{ + + /** + * @parameter default-value="${project.artifact}" + * @required + * @readonly + */ + private Artifact projectArtifact; + + /** + * @parameter default-value="${project.file}" + * @required + * @readonly + */ + private File pomFile; + + /** + * @component + */ + private ArtifactFactory artifactFactory; + + /** + * @parameter default-value="${localRepository}" + * @required + * @readonly + */ + private ArtifactRepository localRepository; + + /** + * @component + */ + private ArtifactInstaller artifactInstaller; + + /** + * @parameter + */ + private String goalPrefix; + + /** + * @parameter default-value="${project.name}" + * @required + * @readonly + */ + private String projectName; + + /** + * @parameter default-value="${project.packaging}" + * @required + * @readonly + */ + private String projectPackaging; + + /** + * @parameter default-value="${project.build.directory}/plugin-staging-backup" + * @required + */ + private File backupDirectory; + + /** + * @component + */ + private PluginManagerAccess pluginManagerAccess; + + public void execute() + throws MojoExecutionException + { + // 1. backup the local-repository section for the plugin...put it in a place that's easy to restore from. + PluginBackupManager backupManager = new PluginBackupManager( localRepository, getLog() ); + + try + { + backupManager.backupInstalledPluginData( projectArtifact, backupDirectory ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error backing up plugin for testing.", e ); + } + + // 2. create a new artifact, to attach metadata to it. + PluginStagingManager stagingManager = + new PluginStagingManager( localRepository, artifactFactory, artifactInstaller, getLog() ); + + Artifact artifact = stagingManager.duplicateProjectArtifact( projectArtifact, projectPackaging ); + + // 3. add the plugin metadata for 'installing' into the local repo + stagingManager.addPluginMetadata( artifact, projectName, goalPrefix ); + + // 4. install the current plugin into the local repository + try + { + stagingManager.installPlugin( artifact, pomFile ); + } + catch ( PluginStagingException e ) + { + try + { + backupManager.restorePluginData( backupDirectory ); + } + catch ( IOException ioe ) + { + getLog().error( "Error restoring plugin data backed up to: \'" + backupDirectory + "\' on plugin staging failure.", ioe ); + } + + throw new MojoExecutionException( "Error staging plugin: " + e.getMessage(), e ); + } + + // 5. clean up any plugin containers associated with this plugin's info...so it will reload + pluginManagerAccess.clearPluginData( projectArtifact ); + } + +} Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedInstallMojo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedInstallMojo.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedUninstallMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedUninstallMojo.java?rev=430505&view=auto ============================================================================== --- maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedUninstallMojo.java (added) +++ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedUninstallMojo.java Thu Aug 10 12:53:38 2006 @@ -0,0 +1,81 @@ +package org.apache.maven.plugin.plugintest; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.plugintest.backup.PluginBackupManager; +import org.apache.maven.plugin.plugintest.manager.PluginManagerAccess; + +import java.io.File; +import java.io.IOException; + +/** + * Remove staged plugin information from the local repository. + * + * @goal unstage + * + * @phase post-integration-test + */ +public class StagedUninstallMojo + extends AbstractMojo +{ + + /** + * @parameter default-value="${project.artifact}" + * @required + * @readonly + */ + private Artifact projectArtifact; + + /** + * @parameter default-value="${localRepository}" + * @required + * @readonly + */ + private ArtifactRepository localRepository; + + /** + * @parameter default-value="${project.build.directory}/plugin-staging-backup" + * @required + */ + private File backupDirectory; + + /** + * @component + */ + private PluginManagerAccess pluginManagerAccess; + + public void execute() + throws MojoExecutionException + { + PluginBackupManager backupManager = new PluginBackupManager( localRepository, getLog() ); + + try + { + backupManager.restorePluginData( backupDirectory ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error un-staging plugin: " + e.getMessage(), e ); + } + + pluginManagerAccess.clearPluginData( projectArtifact ); + } +} Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedUninstallMojo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/StagedUninstallMojo.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/backup/PluginBackupManager.java URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/backup/PluginBackupManager.java?rev=430505&view=auto ============================================================================== --- maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/backup/PluginBackupManager.java (added) +++ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/backup/PluginBackupManager.java Thu Aug 10 12:53:38 2006 @@ -0,0 +1,119 @@ +package org.apache.maven.plugin.plugintest.backup; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Versioning; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.artifact.ProjectArtifactMetadata; +import org.apache.maven.shared.model.fileset.FileSet; +import org.apache.maven.shared.model.fileset.util.FileSetManager; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +public class PluginBackupManager +{ + + private final Log log; + + private final ArtifactRepository localRepository; + + public PluginBackupManager( ArtifactRepository localRepository, Log log ) + { + this.localRepository = localRepository; + this.log = log; + } + + public void backupInstalledPluginData( Artifact projectArtifact, File backupDirectory ) + throws IOException + { + ArtifactRepositoryLayout layout = localRepository.getLayout(); + + File basedir = new File( localRepository.getBasedir() ); + + // find the directory where plugin-group metadata is stored...for prefix mappings. + GroupRepositoryMetadata groupMetadata = new GroupRepositoryMetadata( projectArtifact.getGroupId() ); + + String relativePath = layout.pathOfLocalRepositoryMetadata( groupMetadata, localRepository ); + + File localPath = new File( basedir, relativePath ); + + File groupMetadataDir = localPath.getParentFile(); + + backup( groupMetadataDir, "**/maven-metadata*.xml", relativePath, backupDirectory ); + + // find the directory where plugin-artifact metadata is stored...for snapshot versioning. + Versioning versioning = new Versioning(); + versioning.setLatest( projectArtifact.getVersion() ); + versioning.updateTimestamp(); + + ArtifactRepositoryMetadata artifactMetadata = new ArtifactRepositoryMetadata( projectArtifact, versioning ); + + relativePath = layout.pathOfLocalRepositoryMetadata( artifactMetadata, localRepository ); + + localPath = new File( basedir, relativePath ); + + File artifactMetadataDir = localPath.getParentFile(); + + backup( artifactMetadataDir, "**/maven-metadata*", relativePath, backupDirectory ); + + // find the directory where the plugin artifact itself is stored...in case a file gets overwritten. + relativePath = layout.pathOf( projectArtifact ); + + localPath = new File( basedir, relativePath ); + + File artifactDir = localPath.getParentFile(); + + backup( artifactDir, "**/*", relativePath, backupDirectory ); + + // find the directory where the plugin POM is stored...in case the POM version is the same. + ProjectArtifactMetadata pomMetadata = new ProjectArtifactMetadata( projectArtifact ); + + relativePath = layout.pathOfLocalRepositoryMetadata( pomMetadata, localRepository ); + + localPath = new File( basedir, relativePath ); + + File pomDir = localPath.getParentFile(); + + backup( pomDir, "**/*", relativePath, backupDirectory ); + } + + private void backup( File groupMetadataDir, String pattern, String relativePath, File backupDirectory ) + throws IOException + { + FileSet fs = new FileSet(); + + fs.setDirectory( groupMetadataDir.getAbsolutePath() ); + fs.addInclude( pattern ); + + FileSetManager fsm = new FileSetManager( log ); + + String[] includedFiles = fsm.getIncludedFiles( fs ); + + File destDir = new File( backupDirectory, relativePath ); + destDir.mkdirs(); + + for ( int i = 0; i < includedFiles.length; i++ ) + { + File src = new File( groupMetadataDir, includedFiles[i] ); + File dest = new File( destDir, includedFiles[i] ); + + dest.getParentFile().mkdirs(); + + FileUtils.copyFile( src, dest ); + } + } + + public void restorePluginData( File backupDirectory ) + throws IOException + { + File localRepoDir = new File( localRepository.getBasedir() ); + + FileUtils.copyDirectory( backupDirectory, localRepoDir ); + } + +} Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/backup/PluginBackupManager.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/backup/PluginBackupManager.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/DefaultPluginManagerAccess.java URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/DefaultPluginManagerAccess.java?rev=430505&view=auto ============================================================================== --- maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/DefaultPluginManagerAccess.java (added) +++ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/DefaultPluginManagerAccess.java Thu Aug 10 12:53:38 2006 @@ -0,0 +1,48 @@ +package org.apache.maven.plugin.plugintest.manager; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.MavenPluginCollector; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; + +/** + * @plexus.component role="org.apache.maven.plugin.plugintest.manager.PluginManagerAccess" role-hint="default" + * @author jdcasey + * + */ +public class DefaultPluginManagerAccess + implements PluginManagerAccess, Contextualizable +{ + + /** + * @plexus.requirement + */ + MavenPluginCollector pluginCollector; + + private PlexusContainer container; + + public void clearPluginData( Artifact pluginArtifact ) + { + Plugin plugin = new Plugin(); + + plugin.setArtifactId( pluginArtifact.getArtifactId() ); + plugin.setGroupId( pluginArtifact.getGroupId() ); + + pluginCollector.flushPluginDescriptor( plugin ); + + String key = plugin.getKey(); + + container.removeChildContainer( key ); + } + + public void contextualize( Context context ) + throws ContextException + { + this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } + +} Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/DefaultPluginManagerAccess.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/DefaultPluginManagerAccess.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/PluginManagerAccess.java URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/PluginManagerAccess.java?rev=430505&view=auto ============================================================================== --- maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/PluginManagerAccess.java (added) +++ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/PluginManagerAccess.java Thu Aug 10 12:53:38 2006 @@ -0,0 +1,10 @@ +package org.apache.maven.plugin.plugintest.manager; + +import org.apache.maven.artifact.Artifact; + +public interface PluginManagerAccess +{ + + void clearPluginData( Artifact pluginArtifact ); + +} Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/PluginManagerAccess.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/manager/PluginManagerAccess.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingException.java URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingException.java?rev=430505&view=auto ============================================================================== --- maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingException.java (added) +++ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingException.java Thu Aug 10 12:53:38 2006 @@ -0,0 +1,17 @@ +package org.apache.maven.plugin.plugintest.stage; + +public class PluginStagingException + extends Exception +{ + + public PluginStagingException( String message, Throwable cause ) + { + super( message, cause ); + } + + public PluginStagingException( String message ) + { + super( message ); + } + +} Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingException.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingManager.java URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingManager.java?rev=430505&view=auto ============================================================================== --- maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingManager.java (added) +++ maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingManager.java Thu Aug 10 12:53:38 2006 @@ -0,0 +1,115 @@ +package org.apache.maven.plugin.plugintest.stage; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.installer.ArtifactInstallationException; +import org.apache.maven.artifact.installer.ArtifactInstaller; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Versioning; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.artifact.ProjectArtifactMetadata; + +import java.io.File; +import java.util.Collection; +import java.util.Iterator; + +public class PluginStagingManager +{ + + private ArtifactFactory artifactFactory; + + private final Log log; + + private ArtifactRepository localRepository; + + private ArtifactInstaller installer; + + public PluginStagingManager( ArtifactRepository localRepository, ArtifactFactory artifactFactory, + ArtifactInstaller installer, Log log ) + { + this.localRepository = localRepository; + this.artifactFactory = artifactFactory; + this.installer = installer; + this.log = log; + } + + public Artifact duplicateProjectArtifact( Artifact projectArtifact, String projectPackaging ) + { + Artifact artifact = + artifactFactory.createBuildArtifact( projectArtifact.getGroupId(), projectArtifact.getArtifactId(), + projectArtifact.getVersion(), projectPackaging ); + + artifact.setFile( projectArtifact.getFile() ); + + Collection metadataList = projectArtifact.getMetadataList(); + + if ( metadataList != null ) + { + for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) + { + ArtifactMetadata metadata = ( ArtifactMetadata ) iter.next(); + + artifact.addMetadata( metadata ); + } + } + + return artifact; + } + + public void addPluginMetadata( Artifact artifact, String projectName, String goalPrefixOverride ) + { + Versioning versioning = new Versioning(); + versioning.setLatest( artifact.getVersion() ); + versioning.updateTimestamp(); + ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); + artifact.addMetadata( metadata ); + + GroupRepositoryMetadata groupMetadata = new GroupRepositoryMetadata( artifact.getGroupId() ); + groupMetadata.addPluginMapping( getGoalPrefix( goalPrefixOverride, artifact ), artifact.getArtifactId(), + projectName ); + + artifact.addMetadata( groupMetadata ); + } + + private String getGoalPrefix( String goalPrefixOverride, Artifact artifact ) + { + if ( goalPrefixOverride == null ) + { + goalPrefixOverride = PluginDescriptor.getGoalPrefixFromArtifactId( artifact.getArtifactId() ); + } + + return goalPrefixOverride; + } + + public void installPlugin( Artifact artifact, File pomFile ) + throws PluginStagingException + { + try + { + ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pomFile ); + artifact.addMetadata( metadata ); + + File file = artifact.getFile(); + + // Here, we have a temporary solution to MINSTALL-3 (isDirectory() is true if it went through compile + // but not package). We are designing in a proper solution for Maven 2.1 + if ( file != null && !file.isDirectory() ) + { + installer.install( file, artifact, localRepository ); + } + else + { + throw new PluginStagingException( + "The packaging for this project did not assign a file to the build artifact" ); + } + } + catch ( ArtifactInstallationException e ) + { + throw new PluginStagingException( e.getMessage(), e ); + } + } +} Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingManager.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/plugins/maven-plugin-test-plugin/src/main/java/org/apache/maven/plugin/plugintest/stage/PluginStagingManager.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision"