1 19 20 package org.apache.geronimo.mavenplugins.car; 21 22 import org.apache.geronimo.kernel.repository.WriteableRepository; 23 import org.apache.geronimo.system.repository.Maven2Repository; 24 25 import org.apache.geronimo.genesis.util.ArtifactItem; 26 27 import org.apache.maven.plugin.MojoExecutionException; 28 import org.apache.maven.artifact.Artifact; 29 30 import java.io.File ; 31 32 39 public class InstallArtifactsMojo 40 extends AbstractCarMojo 41 { 42 48 private File repositoryDirectory = null; 49 50 56 private ArtifactItem[] artifacts = null; 57 58 63 private boolean force = true; 64 65 protected void doExecute() throws Exception { 66 if (!repositoryDirectory.exists()) { 67 repositoryDirectory.mkdirs(); 68 log.info("Created directory: " + repositoryDirectory); 69 } 70 else if (!repositoryDirectory.isDirectory()) { 71 throw new MojoExecutionException("Invalid reposiory directory: " + repositoryDirectory); 72 } 73 74 WriteableRepository repository = new Maven2Repository(repositoryDirectory); 75 76 for (int i=0; i<artifacts.length; i++) { 78 Artifact artifact = getArtifact(artifacts[i]); 79 log.info("Installing: " + artifact); 80 81 org.apache.geronimo.kernel.repository.Artifact gartifact = mavenArtifactToGeronimo(artifact); 82 if (repository.contains(gartifact)) { 83 if (force) { 84 File file = repository.getLocation(gartifact); 85 log.debug("Force deletion of: " + file); 86 87 if (!file.delete()) { 88 throw new MojoExecutionException("Failed to delete artifact from repository: " + artifacts[i]); 89 } 90 } 91 else { 92 throw new MojoExecutionException("Artifact already exists in repository: " + artifacts[i]); 93 } 94 } 95 96 repository.copyToRepository(artifact.getFile(), gartifact, null); 97 } 98 } 99 100 103 private org.apache.geronimo.kernel.repository.Artifact mavenArtifactToGeronimo(final Artifact artifact) { 104 assert artifact != null; 105 106 return new org.apache.geronimo.kernel.repository.Artifact( 107 artifact.getGroupId(), 108 artifact.getArtifactId(), 109 artifact.getVersion(), 110 artifact.getType() 111 ); 112 } 113 } 114 | Popular Tags |