Commits

Sebastian Sdorra committed 3cd1984

add maven metadata to scmp packages

  • Participants
  • Parent commits 888951e

Comments (0)

Files changed (4)

maven/scm-maven-plugin/pom.xml

     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
-      <version>2.2.1</version>
+      <version>${mavenVersion}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-artifact</artifactId>
-      <version>2.2.1</version>
+      <version>${mavenVersion}</version>
     </dependency>
     
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-project</artifactId>
-      <version>2.2.1</version>
+      <version>${mavenVersion}</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-model</artifactId>
+      <version>${mavenVersion}</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>1.5.6</version>
     </dependency>
     
     <dependency>
     </dependency>
     
   </dependencies>
+  
+  <properties>
+    <mavenVersion>2.0.6</mavenVersion>
+  </properties>
 
 </project>

maven/scm-maven-plugin/src/main/java/sonia/scm/maven/AbstractBaseScmMojo.java

     ArtifactRepository pluginRepository, Artifact artifact)
     throws MojoExecutionException
   {
-    String id =
-      artifact.getGroupId().concat(":").concat(artifact.getArtifactId());
+    String id = getId(artifact);
+      
 
     if (!excludeList.contains(id))
     {
       }
     }
   }
+  
+  protected String getId(Artifact artifact){
+    return artifact.getGroupId().concat(":").concat(artifact.getArtifactId());
+  }
 
   /**
    * Method description

maven/scm-maven-plugin/src/main/java/sonia/scm/maven/PackageMojo.java

 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.deployer.ArtifactDeployer;
+import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 
     File warFile = getWebApplicationArchive();
     List<String> excludeList = createExcludeList(warFile);
 
-    installArtifacts(excludeList, packageDirectory);
+    deployToDirectory(excludeList);
     copyDescriptor();
     createPackage();
   }
    *
    * @return
    */
+  public ArtifactDeployer getDeployer()
+  {
+    return deployer;
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   */
   public File getDescriptor()
   {
     return descriptor;
    * Method description
    *
    *
+   * @param deployer
+   */
+  public void setDeployer(ArtifactDeployer deployer)
+  {
+    this.deployer = deployer;
+  }
+
+  /**
+   * Method description
+   *
+   *
    * @param descriptor
    */
   public void setDescriptor(File descriptor)
 
   }
 
+  /**
+   * Method description
+   *
+   *
+   * @param excludeList
+   *
+   * @throws MojoExecutionException
+   */
+  private void deployToDirectory(List<String> excludeList)
+    throws MojoExecutionException
+  {
+
+    Artifact pluginArtifact = getPluginArtifact();
+
+    try
+    {
+      ArtifactRepository deploymentRepository = getDeploymentRepository();
+
+      deployToDirectory(excludeList, deploymentRepository, pluginArtifact);
+
+      for (Artifact artifact : artifacts)
+      {
+        deployToDirectory(excludeList, deploymentRepository, artifact);
+      }
+
+    }
+    catch (IOException ex)
+    {
+      throw new MojoExecutionException("could not create deloy repository", ex);
+    }
+    catch (ArtifactDeploymentException ex)
+    {
+      throw new MojoExecutionException("could not create deloy artifcat", ex);
+    }
+  }
+
+  /**
+   * Method description
+   *
+   *
+   *
+   * @param excludeList
+   * @param deploymentRepository
+   * @param artifact
+   *
+   * @throws ArtifactDeploymentException
+   */
+  private void deployToDirectory(List<String> excludeList,
+    ArtifactRepository deploymentRepository, Artifact artifact)
+    throws ArtifactDeploymentException
+  {
+    String id = getId(artifact);
+
+    if (!excludeList.contains(id))
+    {
+
+      artifact.isSnapshot();
+
+      File file = artifact.getFile();
+
+      deployer.deploy(file, artifact, deploymentRepository, localRepository);
+    }
+  }
+
+  //~--- get methods ----------------------------------------------------------
+
+  /**
+   * Method description
+   *
+   *
+   * @return
+   *
+   * @throws IOException
+   * @throws MojoExecutionException
+   */
+  private ArtifactRepository getDeploymentRepository()
+    throws IOException, MojoExecutionException
+  {
+
+    ArtifactRepositoryLayout artifactRepositoryLayout =
+      availableRepositoryLayouts.get(repositoryLayout);
+
+    if (artifactRepositoryLayout == null)
+    {
+      throw new MojoExecutionException(
+        "could not find repository layout ".concat(repositoryLayout));
+    }
+
+    return artifactRepositoryFactory.createDeploymentArtifactRepository(
+      "package.repository",
+      "file://".concat(packageDirectory.getAbsolutePath()),
+      artifactRepositoryLayout, true);
+  }
+
   //~--- fields ---------------------------------------------------------------
 
   /**
+   * @component
+   */
+  private ArtifactDeployer deployer;
+
+  /**
    * @parameter default-value="${project.build.directory}/classes/META-INF/scm/plugin.xml"
    */
   private File descriptor;

maven/scm-maven-plugin/src/main/java/sonia/scm/maven/RunMojo.java

    *
    * @throws MojoFailureException
    */
-  private void runServletContainer(File warFile) throws MojoFailureException
+  private void runServletContainer(File warFile) throws MojoExecutionException
   {
     getLog().info("start servletcontainer at port " + port);
 
     }
     catch (Exception ex)
     {
-      throw new MojoFailureException("could not start servletcontainer", ex);
+      throw new MojoExecutionException("could not start servletcontainer", ex);
     }
   }