Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Mojo #5

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
<repository>
<id>luteceSnapshot</id>
<name>luteceSnapshot</name>
<url>http://dev.lutece.paris.fr/snapshot_repository</url>
<url>https://dev.lutece.paris.fr/snapshot_repository</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>lutece</id>
<name>luteceRepository</name>
<url>http://dev.lutece.paris.fr/maven_repository</url>
<url>https://dev.lutece.paris.fr/maven_repository</url>
<layout>default</layout>
</repository>
</repositories>
Expand Down Expand Up @@ -102,6 +102,16 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>${tomcat.version}</version>
</dependency>
</dependencies>


Expand Down Expand Up @@ -230,6 +240,7 @@
<jiraProjectName>MAVENPLUGIN</jiraProjectName>
<jiraComponentId>10157</jiraComponentId>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tomcat.version>9.0.64</tomcat.version>
</properties>

<profiles>
Expand Down
163 changes: 163 additions & 0 deletions src/main/java/fr/paris/lutece/maven/AbstractAssemblySiteMojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Copyright (c) 2002-2015, Mairie de Paris
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright notice
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice
* and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* License 1.0
*/
package fr.paris.lutece.maven;

import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.util.StringUtils;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
* Abstract mojo to create a site.
*
* Builds a site's final WAR from a Lutece core artifact and a set of Lutece
* plugin artifacts.<br/> Note that the Lutece dependencies (core and plugins)
* will only be updated the first time the WAR is created. Subsequent calls to
* this goal will only update the site's specific files.<br/> If you wish to
* force webapp re-creation (for instance, if you changed the version of a
* dependency), call the <code>clean</code> phase before this goal.
*/

public abstract class AbstractAssemblySiteMojo
extends AbstractLuteceWebappMojo
{
private static final String SNAPSHOT_PATTERN = "SNAPSHOT";

/**
* The output date format.
*
* @parameter default-value="yyyyMMdd.HHmmss"
* @required
*/
private String utcTimestampPattern;

/**
* The name of the generated WAR file.
*
* @parameter expression="${project.build.finalName}"
* @required
*/
private String finalName;

/**
* A temporary directory used to hold the exploded version of the webapp.
*
* @parameter expression="${project.build.directory}/${project.build.finalName}"
* @required
*/
private File explodedDirectory;

/**
* Whether creating the archive should be forced.
*
* @parameter expression="${jar.forceCreation}" default-value="false"
*/
private boolean forceCreation;

/**
* The maven archive configuration to use.
*
* See <a
* href="http://maven.apache.org/ref/current/maven-archiver/apidocs/org/apache/maven/archiver/MavenArchiveConfiguration.html">the
* Javadocs for MavenArchiveConfiguration</a>.
*
* @parameter
*/
private MavenArchiveConfiguration archive = new MavenArchiveConfiguration( );

/**
* The Jar archiver.
*
* @component role="org.codehaus.plexus.archiver.Archiver" roleHint="jar"
* @required
*/
private JarArchiver jarArchiver;

protected File assemblySite( )
throws MojoExecutionException
{
prepare();
return createWAR();
}

protected File prepare( )
throws MojoExecutionException {
// Explode the webapp in the temporary directory
explodeWebapp( explodedDirectory );
explodeConfigurationFiles( explodedDirectory );
return explodedDirectory;
}

protected File createWAR( )
throws MojoExecutionException {
// put the timestamp in the assembly name
if ( ArtifactUtils.isSnapshot( project.getVersion( ) ) )
{
DateFormat utcDateFormatter = new SimpleDateFormat( utcTimestampPattern );
String newVersion = utcDateFormatter.format( new Date( ) );
finalName = StringUtils.replace( finalName, SNAPSHOT_PATTERN, newVersion );
}

// Make a war from the exploded directory
File warFile = new File( outputDirectory, finalName + ".war" );

MavenArchiver archiver = new MavenArchiver( );
archiver.setArchiver( jarArchiver );
archiver.setOutputFile( warFile );
archive.setForced( forceCreation );

try
{
if ( explodedDirectory.exists( ) )
{
archiver.getArchiver( )
.addDirectory( explodedDirectory, PACKAGE_WEBAPP_INCLUDES, PACKAGE_WEBAPP_RESOURCES_EXCLUDES );
}

archiver.createArchive( project, archive );
} catch ( Exception e )
{
throw new MojoExecutionException( "Error assembling WAR", e );
}

return warFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public abstract class AbstractLuteceWebappMojo
*
* @component
*/
private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory;
protected org.apache.maven.artifact.factory.ArtifactFactory artifactFactory;

/**
* The artifact resolver.
Expand Down
104 changes: 1 addition & 103 deletions src/main/java/fr/paris/lutece/maven/AssemblySiteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,9 @@
*/
package fr.paris.lutece.maven;

import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.util.StringUtils;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.apache.maven.plugins.annotations.Mojo;

/**
Expand All @@ -65,61 +54,8 @@
@Mojo( name = "site-assembly" )

public class AssemblySiteMojo
extends AbstractLuteceWebappMojo
extends AbstractAssemblySiteMojo
{
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
private static final String SNAPSHOT_PATTERN = "SNAPSHOT";

/**
* The output date format.
*
* @parameter default-value="yyyyMMdd.HHmmss"
* @required
*/
private String utcTimestampPattern;

/**
* The name of the generated WAR file.
*
* @parameter expression="${project.build.finalName}"
* @required
*/
private String finalName;

/**
* A temporary directory used to hold the exploded version of the webapp.
*
* @parameter expression="${project.build.directory}/${project.build.finalName}"
* @required
*/
private File explodedDirectory;

/**
* Whether creating the archive should be forced.
*
* @parameter expression="${jar.forceCreation}" default-value="false"
*/
private boolean forceCreation;

/**
* The maven archive configuration to use.
*
* See <a
* href="http://maven.apache.org/ref/current/maven-archiver/apidocs/org/apache/maven/archiver/MavenArchiveConfiguration.html">the
* Javadocs for MavenArchiveConfiguration</a>.
*
* @parameter
*/
private MavenArchiveConfiguration archive = new MavenArchiveConfiguration( );

/**
* The Jar archiver.
*
* @component role="org.codehaus.plexus.archiver.Archiver" roleHint="jar"
* @required
*/
private JarArchiver jarArchiver;

/**
* Executes the mojo on the current project.
*
Expand All @@ -139,42 +75,4 @@ public void execute( )
assemblySite( );
}
}

private void assemblySite( )
throws MojoExecutionException
{
// Explode the webapp in the temporary directory
explodeWebapp( explodedDirectory );
explodeConfigurationFiles( explodedDirectory );

// put the timestamp in the assembly name
if ( ArtifactUtils.isSnapshot( project.getVersion( ) ) )
{
DateFormat utcDateFormatter = new SimpleDateFormat( utcTimestampPattern );
String newVersion = utcDateFormatter.format( new Date( ) );
finalName = StringUtils.replace( finalName, SNAPSHOT_PATTERN, newVersion );
}

// Make a war from the exploded directory
File warFile = new File( outputDirectory, finalName + ".war" );

MavenArchiver archiver = new MavenArchiver( );
archiver.setArchiver( jarArchiver );
archiver.setOutputFile( warFile );
archive.setForced( forceCreation );

try
{
if ( explodedDirectory.exists( ) )
{
archiver.getArchiver( )
.addDirectory( explodedDirectory, PACKAGE_WEBAPP_INCLUDES, PACKAGE_WEBAPP_RESOURCES_EXCLUDES );
}

archiver.createArchive( project, archive );
} catch ( Exception e )
{
throw new MojoExecutionException( "Error assembling WAR", e );
}
}
}
Loading