Lars,

It is necessary to execute the compiler in two separate configurations to
produce both Debug and Release libraries, so a classifier is necessary in
one of those cases to avoid overwriting the default project artifact.

We use this technique with a separate NPanday maven-compiler-plugin
execution to generate the Debug build with the "debug" classifier such that
both Debug and Release artifacts can be shipped with the final product.

tc,
-john.

On Sun, Aug 28, 2011 at 11:06 PM, Lars Corneliussen 
<[email protected]>wrote:

> Can you elaborate more on how this works? Would you then have to alter the
> pom for debug-compiles?
>
> Am 20.08.11 02:59, schrieb [email protected]:
>
>> Author: jfallows
>> Date: Sat Aug 20 00:59:56 2011
>> New Revision: 1159828
>>
>> URL: 
>> http://svn.apache.org/viewvc?**rev=1159828&view=rev<http://svn.apache.org/viewvc?rev=1159828&view=rev>
>> Log:
>> Fix for NPANDAY-461 adds a custom classifier making it easier to deliver
>> both debug and release builds from a single project
>>
>> Modified:
>>     incubator/npanday/trunk/**plugins/maven-compile-plugin/**
>> src/main/java/npanday/plugin/**compile/AbstractCompilerMojo.**java
>>
>> Modified: incubator/npanday/trunk/**plugins/maven-compile-plugin/**
>> src/main/java/npanday/plugin/**compile/AbstractCompilerMojo.**java
>> URL: http://svn.apache.org/viewvc/**incubator/npanday/trunk/**
>> plugins/maven-compile-plugin/**src/main/java/npanday/plugin/**
>> compile/AbstractCompilerMojo.**java?rev=1159828&r1=1159827&**
>> r2=1159828&view=diff<http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/maven-compile-plugin/src/main/java/npanday/plugin/compile/AbstractCompilerMojo.java?rev=1159828&r1=1159827&r2=1159828&view=diff>
>> ==============================**==============================**
>> ==================
>> --- incubator/npanday/trunk/**plugins/maven-compile-plugin/**
>> src/main/java/npanday/plugin/**compile/AbstractCompilerMojo.**java
>> (original)
>> +++ incubator/npanday/trunk/**plugins/maven-compile-plugin/**
>> src/main/java/npanday/plugin/**compile/AbstractCompilerMojo.**java Sat
>> Aug 20 00:59:56 2011
>> @@ -19,6 +19,7 @@
>>
>>  package npanday.plugin.compile;
>>
>> +import npanday.ArtifactType;
>>  import npanday.ArtifactTypeHelper;
>>  import npanday.PathUtil;
>>  import npanday.vendor.**SettingsException;
>> @@ -38,6 +39,7 @@ import npanday.registry.**RepositoryRegist
>>  import org.apache.maven.plugin.**AbstractMojo;
>>  import org.apache.maven.plugin.**MojoExecutionException;
>>  import org.apache.maven.project.**MavenProject;
>> +import org.apache.maven.project.**MavenProjectHelper;
>>  import org.codehaus.plexus.util.**FileUtils;
>>
>>  import java.io.BufferedReader;
>> @@ -100,6 +102,14 @@ public abstract class AbstractCompilerMo
>>      protected MavenProject project;
>>
>>      /**
>> +     * The maven project helper.
>> +     *
>> +     * @component
>> +     * @required
>> +     */
>> +    protected MavenProjectHelper projectHelper;
>> +
>> +    /**
>>       * The location of the local Maven repository.
>>       *
>>       * @parameter expression="${settings.**localRepository}"
>> @@ -312,6 +322,11 @@ public abstract class AbstractCompilerMo
>>      protected boolean isDebug;
>>
>>      /**
>> +     * @parameter classifier;
>> +     */
>> +    protected String classifier;
>> +
>> +    /**
>>       * @component
>>       */
>>      protected npanday.executable.**NetExecutableFactory
>> netExecutableFactory;
>> @@ -1119,6 +1134,17 @@ public abstract class AbstractCompilerMo
>>                      getCompilerConfig(),
>>                      project,
>>                      profileAssemblyPath);
>> +
>> +            File compiledArtifact = compilerExecutable.**
>> getCompiledArtifact();
>> +
>> +            // TODO: see issue with CompilerContextImpl.**getArtifact(),
>> which does not incorporate outputDirectory
>> +            if ( outputDirectory != null )
>> +            {
>> +                ArtifactType artifactType = getCompilerConfig().**
>> getArtifactType();
>> +                compiledArtifact = new 
>> File(outputDirectory.**getAbsolutePath()
>> + File.separator +
>> +                                            project.getArtifactId() + "."
>> + artifactType.getExtension());
>> +            }
>> +
>>              if (!test)
>>              {
>>                  // System.Runtime.Versioning.**TargetFrameworkAttribute
>> support
>> @@ -1132,7 +1158,7 @@ public abstract class AbstractCompilerMo
>>                      if (**isUpToDateWithPomAndSettingsAn**dDependencies(
>> **compilerExecutable.**getCompiledArtifact()))
>>                      {
>>                          getLog().info("NPANDAY-900-**003: Nothing to
>> compile - all classes are up-to-date");
>> -                        project.getArtifact().setFile(**
>> compilerExecutable.**getCompiledArtifact());
>> +                        attachArtifact(**compiledArtifact, classifier);
>>                          return;
>>                      }
>>                  }
>> @@ -1152,7 +1178,7 @@ public abstract class AbstractCompilerMo
>>
>>              if (!test)
>>              {
>> -                project.getArtifact().setFile(**compilerExecutable.**
>> getCompiledArtifact());
>> +                attachArtifact(**compiledArtifact, classifier);
>>              }
>>
>>          }
>> @@ -1171,6 +1197,19 @@ public abstract class AbstractCompilerMo
>>          getLog().info("Mojo Execution Time = " + (endTime - startTime));
>>      }
>>
>> +    private void attachArtifact(File artifact, String classifier) {
>> +        if ( classifier != null )
>> +        {
>> +            getLog().debug("Attaching artifact " + artifact.getPath() + "
>> with classifier: " + classifier);
>> +            projectHelper.attachArtifact(**project, artifact,
>> classifier);
>> +        }
>> +        else
>> +        {
>> +            getLog().debug("Attaching default project artifact " +
>> artifact.getPath());
>> +            project.getArtifact().setFile(**artifact);
>> +        }
>> +    }
>> +
>>
>>      protected abstract void initializeDefaults() throws
>> MojoExecutionException;
>>
>>
>>
>>
>


-- 
>|< Kaazing Corporation >|<
John Fallows | CTO | +1.650.960.8148
444 Castro St, Suite 1100 | Mountain View, CA 94041, USA

Reply via email to