Author: sisbell Date: Fri Jun 1 20:04:34 2007 New Revision: 543698 URL: http://svn.apache.org/viewvc?view=rev&rev=543698 Log: Initial import of repository plugin. This is similar to the maven-assembly-plugin but handles both .NET and Java artifacts.
Added: incubator/nmaven/trunk/plugins/maven-repository-plugin/ incubator/nmaven/trunk/plugins/maven-repository-plugin/pom.xml (with props) incubator/nmaven/trunk/plugins/maven-repository-plugin/src/ incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/ incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/ incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/ incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/ incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/maven/ incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/maven/dotnet/ incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/maven/dotnet/plugin/ incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/maven/dotnet/plugin/repository/ incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/maven/dotnet/plugin/repository/RepositoryAssemblerMojo.java (with props) Added: incubator/nmaven/trunk/plugins/maven-repository-plugin/pom.xml URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-repository-plugin/pom.xml?view=auto&rev=543698 ============================================================================== --- incubator/nmaven/trunk/plugins/maven-repository-plugin/pom.xml (added) +++ incubator/nmaven/trunk/plugins/maven-repository-plugin/pom.xml Fri Jun 1 20:04:34 2007 @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?><!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +--> +<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"> + <parent> + <groupId>org.apache.maven.dotnet.plugins</groupId> + <version>0.14-SNAPSHOT</version> + <artifactId>maven-dotnet-plugins</artifactId> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.dotnet.plugins</groupId> + <artifactId>maven-repository-plugin</artifactId> + <packaging>maven-plugin</packaging> + <name>maven-repository-plugin</name> + <description> + Maven Plugin for .NET + </description> +</project> \ No newline at end of file Propchange: incubator/nmaven/trunk/plugins/maven-repository-plugin/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/maven/dotnet/plugin/repository/RepositoryAssemblerMojo.java URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/maven/dotnet/plugin/repository/RepositoryAssemblerMojo.java?view=auto&rev=543698 ============================================================================== --- incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/maven/dotnet/plugin/repository/RepositoryAssemblerMojo.java (added) +++ incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/maven/dotnet/plugin/repository/RepositoryAssemblerMojo.java Fri Jun 1 20:04:34 2007 @@ -0,0 +1,248 @@ +package org.apache.maven.dotnet.plugin.repository; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.deployer.ArtifactDeploymentException; +import org.apache.maven.artifact.deployer.ArtifactDeployer; +import org.apache.maven.dotnet.artifact.AssemblyResolver; +import org.apache.maven.dotnet.artifact.ArtifactType; +import org.apache.maven.dotnet.artifact.AssemblyRepositoryLayout; +import org.apache.maven.dotnet.artifact.ArtifactContext; +import org.apache.maven.dotnet.registry.RepositoryRegistry; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.artifact.ProjectArtifactMetadata; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.Parent; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.util.Set; +import java.util.List; +import java.util.ArrayList; +import java.util.HashSet; +import java.io.File; +import java.io.IOException; +import java.io.FileReader; +import java.io.FileNotFoundException; + +/** + * @author Shane Isbell + * @goal package + */ +public class RepositoryAssemblerMojo + extends AbstractMojo +{ + /** + * The maven project. + * + * @parameter expression="${project}" + * @required + */ + private MavenProject project; + + /** + * @parameter expression="${settings.localRepository}" + * @readonly + */ + private String localRepository; + + /** + * @component + */ + private AssemblyResolver assemblyResolver; + + /** + * @component + */ + private ArtifactDeployer artifactDeployer; + + /** + * Component used to create a repository + * + * @component + */ + private ArtifactRepositoryFactory repositoryFactory; + + /** + * @component + */ + private ArtifactFactory artifactFactory; + + /** + * @component + */ + private org.apache.maven.dotnet.NMavenRepositoryRegistry nmavenRegistry; + + /** + * @component + */ + private ArtifactContext artifactContext; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + RepositoryRegistry repositoryRegistry; + try + { + repositoryRegistry = nmavenRegistry.createRepositoryRegistry(); + } + catch ( IOException e ) + { + throw new MojoExecutionException( + "NMAVEN-1600-000: Failed to create the repository registry for this plugin", e ); + } + + artifactContext.init( project, project.getRemoteArtifactRepositories(), new File( localRepository ) ); + + List<Dependency> javaDependencies = new ArrayList<Dependency>(); + List<Dependency> netDependencies = new ArrayList<Dependency>(); + + for ( Dependency dependency : (List<Dependency>) project.getDependencies() ) + { + if ( !dependency.getType().equals( ArtifactType.LIBRARY.getTargetCompileType() ) ) + { + javaDependencies.add( dependency ); + } + else + { + netDependencies.add( dependency ); + } + } + + assemblyRepository( javaDependencies, new DefaultRepositoryLayout() ); + assemblyRepository( netDependencies, new AssemblyRepositoryLayout() ); + } + + public void assemblyRepository( List<Dependency> dependencies, ArtifactRepositoryLayout layout ) + throws MojoExecutionException, MojoFailureException + { + if ( dependencies.size() == 0 ) + { + return; + } + + ArtifactRepository localArtifactRepository = + new DefaultArtifactRepository( "local", "file://" + localRepository, layout ); + ArtifactRepository deploymentRepository = repositoryFactory.createDeploymentArtifactRepository( null, + "file://" + project.getBuild().getDirectory() + + "/archive-temp/releases", + new DefaultRepositoryLayout(), + true ); + + try + { + assemblyResolver.resolveTransitivelyFor( project, project.getArtifact(), dependencies, + project.getRemoteArtifactRepositories(), localArtifactRepository, + true ); + } + catch ( ArtifactResolutionException e ) + { + throw new MojoExecutionException( "NMAVEN-901-000: Unable to resolve assemblies", e ); + } + catch ( ArtifactNotFoundException e ) + { + throw new MojoExecutionException( "NMAVEN-901-001: Unable to resolve assemblies", e ); + } + + for ( Artifact artifact : (Set<Artifact>) project.getDependencyArtifacts() ) + { + Set<Artifact> pomParentArtifacts = getPomArtifactsFor( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion(), layout, true ); + Set<Artifact> pomArtifacts = getPomArtifactsFor( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion(), layout, false ); + if ( pomArtifacts.size() == 1 ) + { + ArtifactMetadata metadata = + new ProjectArtifactMetadata( artifact, pomArtifacts.toArray( new Artifact[1] )[0].getFile() ); + artifact.addMetadata( metadata ); + } + + try + { + artifactDeployer.deploy( artifact.getFile(), artifact, deploymentRepository, localArtifactRepository ); + //Deploy parent poms + for ( Artifact pomArtifact : pomParentArtifacts ) + { + artifactDeployer.deploy( pomArtifact.getFile(), pomArtifact, deploymentRepository, + localArtifactRepository ); + } + } + catch ( ArtifactDeploymentException e ) + { + throw new MojoExecutionException( "NMAVEN-DEPLOY: Deploy Failed", e ); + } + } + } + + private Set<Artifact> getPomArtifactsFor( String groupId, String artifactId, String version, + ArtifactRepositoryLayout layout, boolean addParents ) + throws MojoExecutionException + { + Set<Artifact> pomArtifacts = new HashSet<Artifact>(); + Artifact pomArtifact = artifactFactory.createArtifact( groupId, artifactId, version, "pom", "pom" ); + File pomFile = new File( localRepository, layout.pathOf( pomArtifact ) ); + + if ( pomFile.exists() ) + { + File tmpFile = null; + try + { + tmpFile = File.createTempFile( "pom" + artifactId, "pom" ); + FileUtils.copyFile( pomFile, tmpFile ); + } + catch ( IOException e ) + { + e.printStackTrace(); + } + pomArtifact.setFile( tmpFile ); + pomArtifacts.add( pomArtifact ); + FileReader fileReader; + try + { + fileReader = new FileReader( tmpFile ); + } + catch ( FileNotFoundException e ) + { + throw new MojoExecutionException( "NMAVEN-000-000: Unable to read pom" ); + } + MavenXpp3Reader reader = new MavenXpp3Reader(); + Model model; + try + { + model = reader.read( fileReader ); + } + catch ( XmlPullParserException e ) + { + throw new MojoExecutionException( "NMAVEN-000-000: Unable to read model" ); + + } + catch ( IOException e ) + { + throw new MojoExecutionException( "NMAVEN-000-000: Unable to read model" ); + } + + Parent parent = model.getParent(); + + if ( parent != null && addParents ) + { + pomArtifacts.addAll( getPomArtifactsFor( parent.getGroupId(), parent.getArtifactId(), + parent.getVersion(), layout, true ) ); + } + } + + return pomArtifacts; + } +} Propchange: incubator/nmaven/trunk/plugins/maven-repository-plugin/src/main/java/org/apache/maven/dotnet/plugin/repository/RepositoryAssemblerMojo.java ------------------------------------------------------------------------------ svn:eol-style = native