Author: mfortun Date: 2011-08-17 16:59:50 +0200 (Wed, 17 Aug 2011) New Revision: 1167 Url: http://nuiton.org/repositories/revision/wikitty/1167 Log: *working on run goal Added: trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/JettyUtil.java Modified: trunk/pom.xml trunk/wikitty-publication/pom.xml trunk/wp-maven-plugin/pom.xml trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPJarMojo.java trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPRunMojo.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2011-08-17 12:39:27 UTC (rev 1166) +++ trunk/pom.xml 2011-08-17 14:59:50 UTC (rev 1167) @@ -383,7 +383,21 @@ <version>${jspapiversion}</version> </dependency> + <!-- Maven plugin for wikitty publication specific dependency --> <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <version>${jettyPluginVersion}</version> + </dependency> + + <dependency> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>${dependencyPluginVersion}</version> + </dependency> + + + <dependency> <groupId>org.nuiton</groupId> <artifactId>maven-helper-plugin</artifactId> <version>${helperPluginVersion}</version> @@ -505,6 +519,19 @@ <artifactId>plexus-utils</artifactId> <version>1.5.15</version> </dependency> + + <!-- Maven plugin for wikitty publication specific dependency --> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <version>${jettyPluginVersion}</version> + </dependency> + + <dependency> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>${dependencyPluginVersion}</version> + </dependency> </dependencies> Modified: trunk/wikitty-publication/pom.xml =================================================================== --- trunk/wikitty-publication/pom.xml 2011-08-17 12:39:27 UTC (rev 1166) +++ trunk/wikitty-publication/pom.xml 2011-08-17 14:59:50 UTC (rev 1167) @@ -136,7 +136,7 @@ <artifactId>log4j</artifactId> <scope>runtime</scope> </dependency> - + </dependencies> <!-- ************************************************************* --> Modified: trunk/wp-maven-plugin/pom.xml =================================================================== --- trunk/wp-maven-plugin/pom.xml 2011-08-17 12:39:27 UTC (rev 1166) +++ trunk/wp-maven-plugin/pom.xml 2011-08-17 14:59:50 UTC (rev 1167) @@ -77,6 +77,17 @@ <scope>runtime</scope> </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + </dependency> + + </dependencies> <!-- ************************************************************* --> Added: trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/JettyUtil.java =================================================================== --- trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/JettyUtil.java (rev 0) +++ trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/JettyUtil.java 2011-08-17 14:59:50 UTC (rev 1167) @@ -0,0 +1,161 @@ +package org.nuiton.wikitty.plugin; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.eclipse.jetty.util.Scanner; +import org.eclipse.jetty.xml.XmlConfiguration; +import org.mortbay.jetty.plugin.AbstractJettyMojo; + +/** + * New definition of the JettyRunWarMojo + * to set the protected visibility and getter and setter for the webApp file + * + * @author mfortun + * + */ +public class JettyUtil extends AbstractJettyMojo +{ + + /** + * The location of the war file. + * @parameter expression="${project.build.directory}/${project.build.finalName}.war" + * @required + */ + protected File webApp; + + + + public File getWebApp() { + return webApp; + } + + + + public void setWebApp(File webApp) { + this.webApp = webApp; + } + + + + /** + * @see org.apache.maven.plugin.Mojo#execute() + */ + public void execute() throws MojoExecutionException, MojoFailureException + { + super.execute(); + } + + + + public void configureWebApplication () throws Exception + { + super.configureWebApplication(); + + webAppConfig.setWar(webApp.getCanonicalPath()); + } + + + + /** + * @see org.mortbay.jetty.plugin.AbstractJettyMojo#checkPomConfiguration() + */ + public void checkPomConfiguration() throws MojoExecutionException + { + return; + } + + + + /* (non-Javadoc) + * @see org.eclipse.jetty.server.plugin.AbstractJettyMojo#configureScanner() + */ + public void configureScanner() throws MojoExecutionException + { + final ArrayList scanList = new ArrayList(); + scanList.add(getProject().getFile()); + scanList.add(webApp); + setScanList(scanList); + + ArrayList listeners = new ArrayList(); + listeners.add(new Scanner.BulkListener() + { + public void filesChanged(List changes) + { + try + { + boolean reconfigure = changes.contains(getProject().getFile().getCanonicalPath()); + restartWebApp(reconfigure); + } + catch (Exception e) + { + getLog().error("Error reconfiguring/restarting webapp after change in watched files",e); + } + } + }); + setScannerListeners(listeners); + + } + + + + + public void restartWebApp(boolean reconfigureScanner) throws Exception + { + getLog().info("Restarting webapp ..."); + getLog().debug("Stopping webapp ..."); + webAppConfig.stop(); + getLog().debug("Reconfiguring webapp ..."); + + checkPomConfiguration(); + + // check if we need to reconfigure the scanner, + // which is if the pom changes + if (reconfigureScanner) + { + getLog().info("Reconfiguring scanner after change to pom.xml ..."); + ArrayList scanList = getScanList(); + scanList.clear(); + scanList.add(getProject().getFile()); + scanList.add(webApp); + setScanList(scanList); + getScanner().setScanDirs(scanList); + } + + getLog().debug("Restarting webapp ..."); + webAppConfig.start(); + getLog().info("Restart completed."); + } + + + /** + * @see org.mortbay.jetty.plugin.AbstractJettyMojo#finishConfigurationBeforeStart() + */ + public void finishConfigurationBeforeStart() + { + return; + } + + + + + public void applyJettyXml() throws Exception + { + if (getJettyXmlFiles() == null) + return; + + for ( File xmlFile : getJettyXmlFiles() ) + { + getLog().info( "Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath() ); + XmlConfiguration xmlConfiguration = new XmlConfiguration(xmlFile.toURI().toURL()); + xmlConfiguration.configure(this.server); + } + } + + + + +} Modified: trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPJarMojo.java =================================================================== --- trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPJarMojo.java 2011-08-17 12:39:27 UTC (rev 1166) +++ trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPJarMojo.java 2011-08-17 14:59:50 UTC (rev 1167) @@ -24,6 +24,8 @@ */ package org.nuiton.wikitty.plugin; +import java.io.File; + import org.nuiton.util.ApplicationConfig; import org.nuiton.wikitty.WikittyConfigOption; import org.nuiton.wikitty.publication.WikittyFileUtil; @@ -65,8 +67,10 @@ origin += WikittyPublicationConstant.LABEL_DELIM + SRC_DIR_NAME + WikittyFileUtil.WIKITTY_LABEL_SEPARATOR + MAIN_DIR_NAME; - target += getProject().getBuild().getDirectory() - + WikittyPublicationConstant.LABEL_DELIM + applicationName; + target += getProject().getBuild().getDirectory(); + createDirectoryIfNecessary(new File(target)); + + target += WikittyPublicationConstant.LABEL_DELIM + applicationName; WikittyPublicationSynchronize.synchronisationServices(origin, target, true, false, false); Modified: trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPRunMojo.java =================================================================== --- trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPRunMojo.java 2011-08-17 12:39:27 UTC (rev 1166) +++ trunk/wp-maven-plugin/src/main/java/org/nuiton/wikitty/plugin/WPRunMojo.java 2011-08-17 14:59:50 UTC (rev 1167) @@ -24,9 +24,19 @@ */ package org.nuiton.wikitty.plugin; +import java.io.File; + +import org.apache.maven.plugin.dependency.CopyDependenciesMojo; +import org.nuiton.wikitty.WikittyConfigOption; +import org.nuiton.wikitty.publication.PropertiesExtended; +import org.nuiton.wikitty.publication.WikittyFileUtil; +import org.nuiton.wikitty.publication.WikittyPublicationConstant; +import org.nuiton.wikitty.publication.WikittyPublicationFallbackService; +import org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem; + /** * To run a wikitty publication project. - * + * * @author tchemit <chemit@codelutin.com> * @version $Id$ * @goal run @@ -37,16 +47,58 @@ */ public class WPRunMojo extends AbstractWPMojo { + static public String FALLBACK_PROPERTIE_FILE_NAME = "fallback.properties"; + @Override protected void init() throws Exception { - //TODO + // TODO } @Override protected void doAction() throws Exception { - //TODO + // TODO mfortun-2011-08-17 need to use copyDepencies Mojo to find + // the wikittyPublication war + File webApp = null; + + //CopyDependenciesMojo + String build = project.getBuild().getDirectory(); + createDirectoryIfNecessary(new File(build)); + + File propsFile = new File(build + File.separator + + FALLBACK_PROPERTIE_FILE_NAME); + if (propsFile.exists()) { + deleteFile(propsFile); + } + createNewFile(propsFile); + // construct propertie for fallback service + String fileSystemUrlService = getProject().getBasedir().toURI().toURL() + .toExternalForm(); + fileSystemUrlService += WikittyPublicationConstant.LABEL_DELIM + + SRC_DIR_NAME + WikittyFileUtil.WIKITTY_LABEL_SEPARATOR + + MAIN_DIR_NAME; + + + PropertiesExtended propsFSServiceFall = new PropertiesExtended( + propsFile); + + propsFSServiceFall.put( + WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS.getKey(), + WikittyPublicationFileSystem.class.getName()); + propsFSServiceFall.put(WikittyConfigOption.WIKITTY_SERVER_URL.getKey(), + fileSystemUrlService); + propsFSServiceFall.store(); + + // set the propertie to find our propertieFile + //TODO mfortun-2011-08-17 need to put the complete path to the file ? + System.setProperty( + WikittyPublicationFallbackService.WIKITTY_FALLBACK_FILE_KEY, + FALLBACK_PROPERTIE_FILE_NAME); + + JettyUtil jettyRunMojo = new JettyUtil(); + jettyRunMojo.setWebApp(webApp); + jettyRunMojo.execute(); } }