Hi guys,
my name is Petar Tahchiev and I am a former Maven developer. Recently I've
been playing with the APPASSEMBLY plugin,
and I think I've done some improvements to it (see attached patch).
All I wanted was to creat a daemon for my project, zip it and deploy it to
a remote server. I figured out I need to create
a daemon with the following folder structure:
+ROOT
- bin/
- conf/
- lib/
- logs/
- webapps/ROOT/
So my first step was to use the maven-war plugin to create the exploded
folder ROOT in the webapps directory. This worked well.
After that the maven appassembly plugin should create the rest of my folder
structure. And it really did, but with
these minor defects:
1) I have a config folder in src/main/config/tomcat/ which contains the
server.xml and web.xml and a bunch of other
catalina conf files. When I used the
<copyConfigurationDirectory>true</copyConfigurationDirectory>
it didn't copy my configuration files. So digging in the code I saw that
this attribute was set on the AssemblyMojo (AM),
which extends AbstractScriptGeneratorMojo (ASGM), and for daemons I was
using the GenerateDaemonsMojo (GM) which extended
the same ASGM, so the structure is pretty much:
(AAM)
^
|
(ASGM)
^
|
/ \
(GDM) (AM)
So what I did was to move the copyConfiguration property from (AM) to
(ASGM) so that both (GDM) and (AM) could use it. I had to also
copy the <configurationSourceDirectory> and <configurationDirectory>
attributes, the copyConfigurationDirectory and installDependencies
methods. After this it worked great - my config files were copied.
2) I didn't want to generate a repository in my lib folder, because I was
generating exploded war file in webapps/ROOT and inside it's
WEB-INF/lib folder were all the jar files that I needed so I didn't want to
have any duplication. Unfortunately the same situation as before -
the generateRepository was specified on (AM) and I needed it both on (AM)
and (GDM), so I simply moved it to (ASGM). Now that this problem
was solved, my lib/ repository folder contained only the tanukisoftware
libraries. Perfect!!!
3) Another problem I faced was, that some of my libraries were with scope
provided (like mysql connectors, and servlet-api and tomcat-embedded
jars, etc.). But they weren't copied to the repository lib/ folder. So I
made a small change, after installing the dependencies in the
lib repository I added another method to copy all the dependencies with
scope "provided" in the lib repository. And if you really think about
it it's where they belong - if they should be provided and we are creating
a server daemon, they must be provided in the lib folder.
4) My last change was to add two new attributes <tempDirectory> and
<logsDirectory>. If those are provided, the maven plugin will create the
provided folders just before the end. I had a problem that when starting
the tomcat daemon it was trying to write it's PID file inside the logs
directory, which weren't there so I had to every time call antrun plugin to
create that folder, which seemed a huge overkill. Anyways if the
folders are not provided, no folders are created.
With all those changes I am happily creating my zips, with either jetty or
tomcat (depending on the profile you run maven in), and I really
believe that these changes will help someone else too.
Please let me know what you think and if the source looks good enough,
apply it in the trunk.
Thanks
P.S. I have also modified one of the tests to test if a null-or-empty
<commandLineArgument> was passed. Before I was getting a Null-pointer
exception so I added a null check in there.
--
Regards, Petar!
Karlovo, Bulgaria.
---
Public PGP Key at:
https://keyserver1.pgp.com/vkd/DownloadKey.event?keyid=0x19658550C3110611
Key Fingerprint: A369 A7EE 61BC 93A3 CDFF 55A5 1965 8550 C311 0611
Index: appassembler-maven-plugin/src/test/resources/project-1/descriptor.xml
===================================================================
--- appassembler-maven-plugin/src/test/resources/project-1/descriptor.xml (revision 18830)
+++ appassembler-maven-plugin/src/test/resources/project-1/descriptor.xml (working copy)
@@ -40,6 +40,7 @@
<environmentSetupFileName>app-env</environmentSetupFileName>
<commandLineArguments>
<commandLineArgument>arg1=arg1-value</commandLineArgument>
+ <commandLineArgument></commandLineArgument>
</commandLineArguments>
<generatorConfigurations>
<generatorConfiguration>
Index: appassembler-maven-plugin/src/test/java/org/codehaus/mojo/appassembler/daemon/generic/GenericDaemonGeneratorTest.java
===================================================================
--- appassembler-maven-plugin/src/test/java/org/codehaus/mojo/appassembler/daemon/generic/GenericDaemonGeneratorTest.java (revision 18830)
+++ appassembler-maven-plugin/src/test/java/org/codehaus/mojo/appassembler/daemon/generic/GenericDaemonGeneratorTest.java (working copy)
@@ -61,6 +61,7 @@
assertNodeEquals( "321", "maxStackSize", actual );
assertNodeEquals( "foo=bar", "systemProperty", actual );
assertNodeEquals( "arg1=arg1-value", "commandLineArgument", actual );
+ assertNodeNull("commandLineArgument", actual );
}
@@ -72,4 +73,7 @@
document.getElementsByTagName( tagName ).item( 0 ).getFirstChild().getNodeValue() );
}
+ private void assertNodeNull(String tagName, Document document) {
+ assertNull(document.getElementsByTagName( tagName ).item( 1 ).getFirstChild());
+ }
}
Index: appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AssembleMojo.java
===================================================================
--- appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AssembleMojo.java (revision 18830)
+++ appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AssembleMojo.java (working copy)
@@ -104,29 +104,6 @@
private String binFolder;
/**
- * The name of the target directory for configuration files.
- *
- * @parameter default-value="etc"
- */
- private String configurationDirectory;
-
- /**
- * The name of the source directory for configuration files.
- *
- * @parameter default-value="src/main/config"
- * @since 1.1
- */
- private File configurationSourceDirectory;
-
- /**
- * If the source configuration directory should be copied to the configured <code>configurationDirectory</code>.
- *
- * @parameter default-value="false"
- * @since 1.1
- */
- private boolean copyConfigurationDirectory;
-
- /**
* Extra arguments that will be given to the JVM verbatim. If you define JvmSettings on the
* {@link Program#setJvmSettings(JvmSettings)} level this part will be overwritten by the given parameters on
* program level. Otherwise if {@link Program#setJvmSettings(JvmSettings)} is not given these settings will be used
@@ -141,13 +118,6 @@
private String extraJvmArguments;
/**
- * Set to <code>false</code> to skip repository generation.
- *
- * @parameter default-value="true"
- */
- private boolean generateRepository;
-
- /**
* If the <code>configurationDirectory</code> (<code>etc</code> by default) should be included in the beginning of
* the classpath in the generated bin files.
*
@@ -344,28 +314,11 @@
artifacts.add( artifact );
}
}
-
// ----------------------------------------------------------------------
// Install dependencies in the new repository
// ----------------------------------------------------------------------
- if ( generateRepository )
- {
- // The repo where the jar files will be installed
- ArtifactRepository artifactRepository =
- artifactRepositoryFactory.createDeploymentArtifactRepository( "appassembler", "file://"
- + assembleDirectory.getAbsolutePath() + "/" + repositoryName, artifactRepositoryLayout, false );
+ super.installDependencies(assembleDirectory.getAbsolutePath(), repositoryName);
- for ( Iterator it = artifacts.iterator(); it.hasNext(); )
- {
- Artifact artifact = (Artifact) it.next();
-
- installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName );
- }
-
- // install the project's artifact in the new repository
- installArtifact( projectArtifact, artifactRepository );
- }
-
// ----------------------------------------------------------------------
// Setup
// ----------------------------------------------------------------------
@@ -416,9 +369,9 @@
// Copy configuration directory
// ----------------------------------------------------------------------
- if ( copyConfigurationDirectory )
+ if ( isCopyConfigurationDirectory() )
{
- copyConfigurationDirectory();
+ copyConfigurationDirectory(assembleDirectory.getAbsolutePath());
}
}
@@ -575,45 +528,6 @@
}
}
- private void copyConfigurationDirectory()
- throws MojoFailureException
- {
- if ( !configurationSourceDirectory.exists() )
- {
- throw new MojoFailureException( "The source directory for configuration files does not exist: "
- + configurationSourceDirectory.getAbsolutePath() );
- }
-
- getLog().debug( "copying configuration directory." );
-
- File configurationTargetDirectory = new File( assembleDirectory.getAbsolutePath(), configurationDirectory );
- if ( !configurationTargetDirectory.exists() )
- {
- // Create (if necessary) target directory for configuration files
- boolean success = configurationTargetDirectory.mkdirs();
-
- if ( !success )
- {
- throw new MojoFailureException( "Failed to create the target directory for configuration files: "
- + configurationTargetDirectory.getAbsolutePath() );
- }
-
- try
- {
- getLog().debug( "Will try to copy configuration files from "
- + configurationSourceDirectory.getAbsolutePath() + " to "
- + configurationTargetDirectory.getAbsolutePath() );
-
- FileUtils.copyDirectory( configurationSourceDirectory, configurationTargetDirectory,
- FileFilterHelper.createDefaultFilter() );
- }
- catch ( IOException e )
- {
- throw new MojoFailureException( "Failed to copy the configuration files." );
- }
- }
- }
-
private Set validatePlatforms( Set platformsToValidate, Set defaultPlatforms )
throws MojoFailureException
{
Index: appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/daemon/jsw/JavaServiceWrapperDaemonGenerator.java
===================================================================
--- appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/daemon/jsw/JavaServiceWrapperDaemonGenerator.java (revision 18830)
+++ appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/daemon/jsw/JavaServiceWrapperDaemonGenerator.java (working copy)
@@ -439,8 +439,9 @@
for ( Iterator i = daemon.getCommandLineArguments().iterator(); i.hasNext(); count++ )
{
String argument = (String) i.next();
-
- confFile.setProperty( "wrapper.app.parameter." + count, argument );
+ if (StringUtils.isNotEmpty(argument)) {
+ confFile.setProperty( "wrapper.app.parameter." + count, argument );
+ }
}
}
Index: appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AbstractScriptGeneratorMojo.java
===================================================================
--- appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AbstractScriptGeneratorMojo.java (revision 18830)
+++ appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AbstractScriptGeneratorMojo.java (working copy)
@@ -24,12 +24,20 @@
* SOFTWARE.
*/
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.appassembler.daemon.DaemonGeneratorService;
+import org.codehaus.mojo.appassembler.util.FileFilterHelper;
-import java.io.File;
-import java.util.List;
-
/**
* This is intended to collect all generic parts of the script generating Mojos assemble and generate-daemons into a
* single class. A first step of hopefully merging the two into one some day.
@@ -95,6 +103,36 @@
* @since 1.3
*/
protected String windowsScriptTemplate;
+
+ /**
+ * Set to <code>false</code> to skip repository generation.
+ *
+ * @parameter default-value="true"
+ */
+ protected boolean generateRepository;
+
+ /**
+ * If the source configuration directory should be copied to the configured <code>configurationDirectory</code>.
+ *
+ * @parameter default-value="false"
+ * @since 1.1
+ */
+ protected boolean copyConfigurationDirectory;
+
+ /**
+ * The name of the target directory for configuration files.
+ *
+ * @parameter default-value="conf"
+ */
+ protected String configurationDirectory;
+
+ /**
+ * The name of the source directory for configuration files.
+ *
+ * @parameter default-value="src/main/config"
+ * @since 1.1
+ */
+ private File configurationSourceDirectory;
// -----------------------------------------------------------------------
// Read-only Parameters
@@ -121,7 +159,54 @@
* @component
*/
protected DaemonGeneratorService daemonGeneratorService;
+
+ protected void copyConfigurationDirectory(final String targetDirectory) throws MojoFailureException {
+ if (!configurationSourceDirectory.exists()) {
+ throw new MojoFailureException("The source directory for configuration files does not exist: " + configurationSourceDirectory.getAbsolutePath());
+ }
+ getLog().debug("copying configuration directory.");
+
+ File configurationTargetDirectory = new File(targetDirectory, configurationDirectory);
+
+ if (!configurationTargetDirectory.exists()) {
+ // Create (if necessary) target directory for configuration files
+ boolean success = configurationTargetDirectory.mkdirs();
+
+ if (!success) {
+ throw new MojoFailureException("Failed to create the target directory for configuration files: "
+ + configurationTargetDirectory.getAbsolutePath());
+ }
+ }
+ try {
+ getLog().debug("Will try to copy configuration files from " + configurationSourceDirectory.getAbsolutePath() + " to "
+ + configurationTargetDirectory.getAbsolutePath());
+
+ FileUtils.copyDirectory(configurationSourceDirectory, configurationTargetDirectory, FileFilterHelper.createDefaultFilter());
+ } catch (IOException e) {
+ throw new MojoFailureException("Failed to copy the configuration files.");
+ }
+ }
+
+ protected void installDependencies(final String outputDirectory, final String repositoryName) throws MojoExecutionException, MojoFailureException {
+ if ( isGenerateRepository() )
+ {
+ // The repo where the jar files will be installed
+ ArtifactRepository artifactRepository =
+ artifactRepositoryFactory.createDeploymentArtifactRepository( "appassembler", "file://"
+ + outputDirectory + "/" + repositoryName, getArtifactRepositoryLayout(), false );
+
+ for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+ {
+ Artifact artifact = (Artifact) it.next();
+ installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName );
+ }
+
+ // install the project's artifact in the new repository
+ installArtifact( projectArtifact, artifactRepository );
+ }
+ }
+
// -----------------------------------------------------------------------
// Getters and setters
// -----------------------------------------------------------------------
@@ -145,4 +230,44 @@
{
this.useWildcardClassPath = useWildcardClassPath;
}
+
+ public boolean isGenerateRepository() {
+ return generateRepository;
+ }
+
+ public void setGenerateRepository(boolean generateRepository) {
+ this.generateRepository = generateRepository;
+ }
+
+ public File getConfigurationSourceDirectory() {
+ return configurationSourceDirectory;
+ }
+
+ public void setConfigurationSourceDirectory(File configurationSourceDirectory) {
+ this.configurationSourceDirectory = configurationSourceDirectory;
+ }
+
+ public boolean isCopyConfigurationDirectory() {
+ return copyConfigurationDirectory;
+ }
+
+ public void setCopyConfigurationDirectory(boolean copyConfigurationDirectory) {
+ this.copyConfigurationDirectory = copyConfigurationDirectory;
+ }
+
+ public String getConfigurationDirectory() {
+ return configurationDirectory;
+ }
+
+ public void setConfigurationDirectory(String configurationDirectory) {
+ this.configurationDirectory = configurationDirectory;
+ }
+
+ public MavenProject getMavenProject() {
+ return mavenProject;
+ }
+
+ public void setMavenProject(MavenProject mavenProject) {
+ this.mavenProject = mavenProject;
+ }
}
Index: appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/GenerateDaemonsMojo.java
===================================================================
--- appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/GenerateDaemonsMojo.java (revision 18830)
+++ appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/GenerateDaemonsMojo.java (working copy)
@@ -64,15 +64,20 @@
* @required
*/
private File basedir;
-
+
/**
- * The name of the target directory for configuration files.
+ * The logs directory of the project.
*
- * @parameter default-value="conf"
- * @since 1.5
- * @todo Synchronize the default value with the other mojos in 2.0
+ * @parameter expression="${logsDirectory}"
*/
- private String configurationDirectory;
+ private String logsDirectory;
+
+ /**
+ * The temp directory of the project.
+ *
+ * @parameter expression="${tempDirectory}"
+ */
+ private String tempDirectory;
/**
* Set of {@linkplain Daemon}s to generate.
@@ -243,24 +248,56 @@
File outputDirectory = new File( request.getOutputDirectory(), daemon.getId() );
- // @todo Refactor: This code is near identical to what is in AssembleMojo
- // The repo where the jar files will be installed
- ArtifactRepository artifactRepository =
- artifactRepositoryFactory.createDeploymentArtifactRepository( "appassembler", "file://"
- + outputDirectory.getAbsolutePath() + "/" + repositoryName, artifactRepositoryLayout, false );
+ // ----------------------------------------------------------------------
+ // Install dependencies in the new repository
+ // ----------------------------------------------------------------------
+ super.installDependencies(outputDirectory.getAbsolutePath(), repositoryName);
- for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+ // ----------------------------------------------------------------------
+ // Install provided dependencies
+ // ----------------------------------------------------------------------
+ installPluginArtifacts(outputDirectory.getAbsolutePath(), repositoryName);
+
+ // ----------------------------------------------------------------------
+ // Copy configuration directory
+ // ----------------------------------------------------------------------
+
+ if ( isCopyConfigurationDirectory() )
{
- Artifact artifact = (Artifact) it.next();
+ copyConfigurationDirectory(outputDirectory.getAbsolutePath());
+ }
- installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName );
+ // ----------------------------------------------------------------------
+ // Create logs and temp dirs if specified
+ // ----------------------------------------------------------------------
+
+ if (this.logsDirectory != null) {
+ File logsDirectory = new File( outputDirectory, this.logsDirectory );
+ logsDirectory.mkdirs();
}
+
+ if (this.tempDirectory != null) {
+ File tempDirectory = new File( outputDirectory, this.tempDirectory );
+ tempDirectory.mkdirs();
+ }
+
+ }
- // install the project's artifact in the new repository
- installArtifact( projectArtifact, artifactRepository );
+ }
+ }
+ private void installPluginArtifacts(final String outputDirectory, final String repositoryName) throws MojoExecutionException, MojoFailureException {
+ // The repo where the jar files will be installed
+ ArtifactRepository artifactRepository =
+ artifactRepositoryFactory.createDeploymentArtifactRepository("appassembler", "file://" + outputDirectory + "/" + repositoryName,
+ getArtifactRepositoryLayout(), false);
+ Set<Artifact> artifacts = mavenProject.getDependencyArtifacts();
+ if (artifacts != null) {
+ for (Artifact artifact : artifacts) {
+ if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
+ installArtifact(artifact, artifactRepository, this.useTimestampInSnapshotFileName);
+ }
}
-
}
}
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email