You are viewing a plain text version of this content. The canonical link for it is here.
Posted to nmaven-commits@incubator.apache.org by si...@apache.org on 2007/05/22 18:06:46 UTC

svn commit: r540669 - in /incubator/nmaven/trunk: components/dotnet-artifact/src/main/java/org/apache/maven/dotnet/artifact/impl/ plugins/maven-fxcop-plugin/src/main/java/org/apache/maven/dotnet/plugin/fxcop/ site/src/site/apt/

Author: sisbell
Date: Tue May 22 11:06:44 2007
New Revision: 540669

URL: http://svn.apache.org/viewvc?view=rev&rev=540669
Log:
Added support for FxCop aggregator. It will generate an aggregate report of multiple assemblies.

Added:
    incubator/nmaven/trunk/plugins/maven-fxcop-plugin/src/main/java/org/apache/maven/dotnet/plugin/fxcop/FxCopAggregateMojo.java   (with props)
Modified:
    incubator/nmaven/trunk/components/dotnet-artifact/src/main/java/org/apache/maven/dotnet/artifact/impl/AssemblyResolverImpl.java
    incubator/nmaven/trunk/site/src/site/apt/features.apt
    incubator/nmaven/trunk/site/src/site/apt/getting-started.apt

Modified: incubator/nmaven/trunk/components/dotnet-artifact/src/main/java/org/apache/maven/dotnet/artifact/impl/AssemblyResolverImpl.java
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/dotnet-artifact/src/main/java/org/apache/maven/dotnet/artifact/impl/AssemblyResolverImpl.java?view=diff&rev=540669&r1=540668&r2=540669
==============================================================================
--- incubator/nmaven/trunk/components/dotnet-artifact/src/main/java/org/apache/maven/dotnet/artifact/impl/AssemblyResolverImpl.java (original)
+++ incubator/nmaven/trunk/components/dotnet-artifact/src/main/java/org/apache/maven/dotnet/artifact/impl/AssemblyResolverImpl.java Tue May 22 11:06:44 2007
@@ -133,17 +133,19 @@
                                                                         gacFilter );
         Set<Artifact> resolvedDependencies = result.getArtifacts();
         AssemblyRepositoryLayout layout = new AssemblyRepositoryLayout();
-
         if ( addResolvedDependenciesToProject )
         {
             for ( Artifact artifact : resolvedDependencies )
             {
                 File originalFileWithVersion = artifact.getFile();
                 File targetFileWithoutVersion = new File( localArtifactRepository + "/" + layout.pathOf( artifact ) );
-              //  logger.info( "Original = " + originalFileWithVersion.getAbsolutePath() + ", Target = " +
-              //      targetFileWithoutVersion.getAbsolutePath() );
+                //  logger.info( "Original = " + originalFileWithVersion.getAbsolutePath() + ", Target = " +
+                //      targetFileWithoutVersion.getAbsolutePath() );
                 originalFileWithVersion.renameTo( targetFileWithoutVersion );
-               // artifact.setFile( targetFileWithoutVersion.getAbsoluteFile() );
+                if ( targetFileWithoutVersion.exists() )
+                {
+                    artifact.setFile( targetFileWithoutVersion.getAbsoluteFile() );
+                }
             }
 
             resolvedDependencies.addAll( gacDependencies );

Added: incubator/nmaven/trunk/plugins/maven-fxcop-plugin/src/main/java/org/apache/maven/dotnet/plugin/fxcop/FxCopAggregateMojo.java
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-fxcop-plugin/src/main/java/org/apache/maven/dotnet/plugin/fxcop/FxCopAggregateMojo.java?view=auto&rev=540669
==============================================================================
--- incubator/nmaven/trunk/plugins/maven-fxcop-plugin/src/main/java/org/apache/maven/dotnet/plugin/fxcop/FxCopAggregateMojo.java (added)
+++ incubator/nmaven/trunk/plugins/maven-fxcop-plugin/src/main/java/org/apache/maven/dotnet/plugin/fxcop/FxCopAggregateMojo.java Tue May 22 11:06:44 2007
@@ -0,0 +1,222 @@
+package org.apache.maven.dotnet.plugin.fxcop;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.dotnet.artifact.AssemblyResolver;
+import org.apache.maven.dotnet.artifact.AssemblyRepositoryLayout;
+import org.apache.maven.dotnet.artifact.ArtifactType;
+import org.apache.maven.dotnet.executable.ExecutionException;
+import org.apache.maven.dotnet.PlatformUnsupportedException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+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.model.Model;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.FileReader;
+import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.HashSet;
+
+/**
+ * @author Shane Isbell
+ * @goal aggregate
+ * @aggregator false
+ */
+public class FxCopAggregateMojo
+    extends AbstractMojo
+{
+    /**
+     * @component
+     */
+    private org.apache.maven.dotnet.executable.NetExecutableFactory netExecutableFactory;
+
+    /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     */
+    private MavenProject project;
+
+    /**
+     * The Vendor for the executable.
+     *
+     * @parameter expression="${vendor}"
+     */
+    private String vendor;
+
+    /**
+     * @parameter expression = "${frameworkVersion}"
+     */
+    private String frameworkVersion;
+
+    /**
+     * The profile that the executable should use.
+     *
+     * @parameter expression = "${profile}" default-value = "DEFAULT"
+     */
+    private String profile;
+
+    /**
+     * @component
+     */
+    private AssemblyResolver assemblyResolver;
+
+    /**
+     * @parameter expression="${settings.localRepository}"
+     * @readonly
+     */
+    private String localRepository;
+
+    /**
+     * @parameter expression = "${project.build.directory}"
+     */
+    private File targetDirectory;
+
+    /**
+     * The artifact factory component, which is used for creating artifacts.
+     *
+     * @component
+     */
+    private ArtifactFactory artifactFactory;
+
+
+    public void execute()
+        throws MojoExecutionException
+    {
+        Model model = project.getModel();
+        List<Dependency> aggregateDependencies = new ArrayList<Dependency>();
+        aggregateDependencies.addAll( model.getDependencies() );
+        try
+        {
+            aggregateDependencies.addAll( addDependenciesFrom( project.getFile() ) );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException("NMAVEN-000-000:");
+        }
+
+
+        ArtifactRepository localArtifactRepository =
+            new DefaultArtifactRepository( "local", "file://" + localRepository, new AssemblyRepositoryLayout() );
+
+        try
+        {
+            assemblyResolver.resolveTransitivelyFor( project, project.getArtifact(), aggregateDependencies,
+                                                     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() )
+        {
+            if ( artifact.getFile() != null && !artifact.getGroupId().startsWith( "NUnit"))
+            {
+                try
+                {
+                    FileUtils.copyFileToDirectory( artifact.getFile(), new File( targetDirectory, "fxcop" ) );
+                }
+                catch ( IOException e )
+                {
+                    throw new MojoExecutionException( "NMAVEN-1100-002: Artifact = " + artifact.toString(), e );
+                }
+            }
+        }
+
+        try
+        {
+            netExecutableFactory.getNetExecutableFor( vendor, frameworkVersion, profile, getCommands(),
+                                                      null ).execute();
+        }
+        catch ( ExecutionException e )
+        {
+            throw new MojoExecutionException( "NMAVEN-xxx-000: Unable to execute: Vendor " + vendor +
+                ", frameworkVersion = " + frameworkVersion + ", Profile = " + profile, e );
+        }
+        catch ( PlatformUnsupportedException e )
+        {
+            throw new MojoExecutionException( "NMAVEN-xxx-001: Platform Unsupported: Vendor " + vendor +
+                ", frameworkVersion = " + frameworkVersion + ", Profile = " + profile, e );
+        }
+    }
+
+    public List<String> getCommands()
+        throws MojoExecutionException
+    {
+        List<String> commands = new ArrayList<String>();
+
+        String targetPath = "target" + File.separator + "fxcop";
+        String outputPath = targetPath + File.separator + "Output.xml";
+
+        commands.add( "/f:" + targetPath );
+        commands.add( "/o:" + outputPath );
+        return commands;
+    }
+
+    private Model fileToPom( File pomFile )
+        throws IOException
+    {
+        FileReader fileReader = new FileReader( pomFile );
+        MavenXpp3Reader reader = new MavenXpp3Reader();
+        Model model;
+        try
+        {
+            model = reader.read( fileReader );
+        }
+        catch ( XmlPullParserException e )
+        {
+            e.printStackTrace();
+            throw new IOException( "NMAVEN-002-013: Unable to read pom file" );
+        }
+        return model;
+    }
+
+    private List<Dependency> addDependenciesFrom( File pomFile )
+        throws IOException
+    {
+        List<Dependency> dependencies = new ArrayList<Dependency>();
+
+        Model model = fileToPom( pomFile );
+        if ( !model.getPackaging().equals( "pom" ) )
+        {
+            Dependency rootDependency = new Dependency();
+            rootDependency.setArtifactId( model.getArtifactId() );
+            rootDependency.setGroupId( model.getGroupId() );
+            rootDependency.setVersion( model.getVersion() );
+            rootDependency.setType(
+                ArtifactType.getArtifactTypeForPackagingName( model.getPackaging() ).getPackagingType() );
+            rootDependency.setScope( Artifact.SCOPE_COMPILE );
+            dependencies.add( rootDependency );
+        }
+
+        List<String> modules = ( model != null ) ? model.getModules() : new ArrayList<String>();
+        for ( String module : modules )
+        {
+            File childPomFile = new File( pomFile.getParent() + "/" + module + "/pom.xml" );
+            if ( childPomFile.exists() )
+            {
+                dependencies.addAll( fileToPom( childPomFile ).getDependencies() );
+                dependencies.addAll( addDependenciesFrom( childPomFile ) );
+            }
+        }
+        return dependencies;
+    }
+}

Propchange: incubator/nmaven/trunk/plugins/maven-fxcop-plugin/src/main/java/org/apache/maven/dotnet/plugin/fxcop/FxCopAggregateMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/nmaven/trunk/site/src/site/apt/features.apt
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/site/src/site/apt/features.apt?view=diff&rev=540669&r1=540668&r2=540669
==============================================================================
--- incubator/nmaven/trunk/site/src/site/apt/features.apt (original)
+++ incubator/nmaven/trunk/site/src/site/apt/features.apt Tue May 22 11:06:44 2007
@@ -32,4 +32,6 @@
 
  * Experimental IDE Support (VS2005, #develop)
 
- * Deploying and Retrieving of .NET Artifacts from a Remote Repository
\ No newline at end of file
+ * Deploying and Retrieving of .NET Artifacts from a Remote Repository
+
+ * FxCop Maven Plugin
\ No newline at end of file

Modified: incubator/nmaven/trunk/site/src/site/apt/getting-started.apt
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/site/src/site/apt/getting-started.apt?view=diff&rev=540669&r1=540668&r2=540669
==============================================================================
--- incubator/nmaven/trunk/site/src/site/apt/getting-started.apt (original)
+++ incubator/nmaven/trunk/site/src/site/apt/getting-started.apt Tue May 22 11:06:44 2007
@@ -24,7 +24,7 @@
 
  * {{{getting-started.html#Using NMaven Settings File}Using NMaven Settings File}}
 
-
+ * {{{getting-started.html#FxCop Maven Plugin}FxCop Maven Plugin}}
 
 * {Building NMaven}
 
@@ -84,8 +84,9 @@
 
   [[2]] If compiling on Windows with either Microsoft or Mono:
 
-   [[a]] the csc (or gmcs) executable directory should be located on the system path. This is only needed for the initial bootstrap build
-   and may be removed afterwards.
+   [[a]] the csc (or gmcs) executable directory AND the .NET SDK install root (containing xsd, wsdl) should be located on the system path.
+    For Mono the executable directory and the SDK install root are the same. This configuration is only needed for the
+    initial bootstrap build and may be removed afterwards.
 
    [[b]] the directory path containing nunit-console should also be located on the system path. After the bootstrap build, you should leave
    the directory path containing the nunit-console executable within the system path. For other options, see:
@@ -557,3 +558,10 @@
 </nmavenSettings>
 +----+
 
+* {FxCop Maven Plugin}
+
+ Make sure that FxCopCmd is located within your path and then type:
+
++----+
+mvn org.apache.maven.dotnet.plugins:maven-fxcop-plugin:fxcop
++----+