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
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
==============================================================================
---
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
(isUpToDateWithPomAndSettingsAndDependencies(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;