Hi Jeff, Thanks for the patch. Could you please open a JIRA on this?
Thanks, Jeff Jeff Smith wrote: > Thought I'd forward this to the dev list as well. > > Begin forwarded message: > >> *From: *Jeff Smith <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> >> *Date: *February 17, 2006 11:14:47 AM MST >> *To: [EMAIL PROTECTED] <mailto:user@mojo.codehaus.org> >> *Subject: **Re: [mojo-user] JBoss Plugin* >> >> Here is the patch. >> >> -jeff >> > > ------------------------------------------------------------------------ > > Index: src/main/java/org/codehaus/mojo/jboss/StartMojo.java > =================================================================== > --- src/main/java/org/codehaus/mojo/jboss/StartMojo.java (revision 1497) > +++ src/main/java/org/codehaus/mojo/jboss/StartMojo.java (working copy) > @@ -19,7 +19,7 @@ > import org.apache.maven.plugin.MojoExecutionException; > > /** > - * Starts JBoss in the background > + * Starts JBoss > * > * @author <a href="mailto:[EMAIL PROTECTED]">Jeff Genender</a> > * @goal start > Index: src/main/java/org/codehaus/mojo/jboss/ConfigureJBossMojo.java > =================================================================== > --- src/main/java/org/codehaus/mojo/jboss/ConfigureJBossMojo.java > (revision 0) > +++ src/main/java/org/codehaus/mojo/jboss/ConfigureJBossMojo.java > (revision 0) > @@ -0,0 +1,295 @@ > +/* > + * Licensed under the Apache License, Version 2.0 (the "License"); > + * you may not use this file except in compliance with the License. > + * You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > + * See the License for the specific language governing permissions and > + * limitations under the License. > + */ > +package org.codehaus.mojo.jboss; > + > +import org.apache.maven.plugin.MojoExecutionException; > +import org.apache.maven.plugin.MojoFailureException; > +import org.apache.velocity.app.VelocityEngine; > +import org.apache.velocity.Template; > +import org.apache.velocity.VelocityContext; > +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; > +import org.codehaus.plexus.util.FileUtils; > + > +import java.io.File; > +import java.io.IOException; > +import java.io.FileWriter; > +import java.util.Properties; > + > +/** > + * ConfigureJBossMojo > + > + * @goal configure > + */ > +public class ConfigureJBossMojo extends AbstractJBossMojo > +{ > + //CONSTANTS > + > + private static final String SERVER_DIR_NAME = "server"; > + > + //STATIC VARIABLES > + > + //INSTANCE VARIABLES > + > + private File jbossHomeDir; > + > + /** > + * The directory for overrides to the conf diretory > + * @parameter expression="${basedir}/jboss/conf" > + */ > + private File confDir; > + > + /** > + * The directory for overrides to the lib diretory > + * @parameter expression="${basedir}/jboss/lib" > + */ > + private File libDir; > + > + /** > + * The directory for overrides to the deploy diretory > + * @parameter expression="${basedir}/jboss/conf" > + */ > + private File deployDir; > + > + //CONSTRUCTING > + > + /** > + * Constructs a ConfigureJBossMojo. > + */ > + public ConfigureJBossMojo() { > + super(); > + } > + > + //STATIC METHODS > + > + //INITIALIZING > + > + //MOJO > + > + public void execute() throws MojoExecutionException, MojoFailureException > + { > + checkConfig(); > + jbossHomeDir = new File(jbossHome); > + checkJBossHome(); > + > + File serverDir = new File(outputDirectory.getAbsolutePath() + > File.separator + serverName); > + > + checkOutputDirectory(serverDir); > + copyBaseConfDir(serverDir); > + copyBaseDeployDir(serverDir); > + copyBaseLibDir(serverDir); > + overlayConfDir(serverDir); > + overlayDeployDir(serverDir); > + overlayLibDir(serverDir); > + buildBinDir(serverDir); > + } > + > + //ACCESSING > + > + //COMPARING > + > + //DISPLAYING > + > + //UTILITY > + > + private void checkJBossHome() throws MojoFailureException > + { > + if(!jbossHomeDir.exists()) > + { > + throw new MojoFailureException("The jbossHome specifed does not > exist."); > + } > + > + File serverParentDir = new File(jbossHomeDir.getAbsolutePath() + > File.separator + SERVER_DIR_NAME); > + > + if(!serverParentDir.exists()) > + { > + throw new MojoFailureException(jbossHomeDir.getAbsolutePath() + > " does not appear to be a valid jboss home"); > + } > + > + File serverDir = new File(serverParentDir.getAbsolutePath() + > File.separator + serverName); > + > + if(!serverDir.exists()) > + { > + throw new MojoFailureException(serverName + " is not a valid > server in " + serverParentDir.getAbsolutePath()); > + } > + } > + > + private void checkOutputDirectory(File serverDir) throws > MojoFailureException > + { > + if(outputDirectory == null) > + { > + throw new MojoFailureException("I don't know how you did it, but > the outputDirectory is null"); > + } > + > + if(!outputDirectory.exists()) > + { > + outputDirectory.mkdirs(); > + } > + > + if(!serverDir.exists()) > + { > + serverDir.mkdir(); > + } > + } > + > + private void copyBaseConfDir(File serverDir) throws > MojoExecutionException > + { > + copyBaseDir(serverDir, "conf"); > + } > + > + private void copyBaseLibDir(File serverDir) throws MojoExecutionException > + { > + copyBaseDir(serverDir, "lib"); > + } > + > + private void copyBaseDeployDir(File serverDir) throws > MojoExecutionException > + { > + copyBaseDir(serverDir, "deploy"); > + } > + > + private void copyBaseDir(File serverDir, String dirName) throws > MojoExecutionException > + { > + File baseDir = new File(jbossHome + File.separator + SERVER_DIR_NAME > + File.separator + serverName + File.separator + dirName); > + File dir = new File(serverDir.getAbsolutePath() + File.separator + > dirName); > + try > + { > + FileUtils.copyDirectoryStructure(baseDir, dir); > + } > + catch (IOException e) > + { > + throw new MojoExecutionException("Could Not Copy " + dirName + " > Dir", e); > + } > + } > + > + private void overlayConfDir(File serverDir) throws MojoExecutionException > + { > + overLayDir(serverDir, confDir, "conf"); > + } > + > + private void overlayDeployDir(File serverDir) throws > MojoExecutionException > + { > + overLayDir(serverDir, deployDir, "deploy"); > + } > + > + private void overlayLibDir(File serverDir) throws MojoExecutionException > + { > + overLayDir(serverDir, libDir, "lib"); > + } > + > + private void overLayDir(File serverDir, File overLayDir, String dirName) > throws MojoExecutionException > + { > + File baseDir = new File(serverDir + File.separator + dirName); > + if(overLayDir.exists()) > + { > + try > + { > + FileUtils.copyDirectoryStructure(overLayDir, baseDir); > + } > + catch(IOException e) > + { > + throw new MojoExecutionException("Could not overlay " + > dirName + "Dir", e); > + } > + } > + } > + > + private void buildBinDir(File serverDir) throws MojoExecutionException > + { > + File binDir = new File(outputDirectory.getAbsolutePath() + > File.separator + "bin"); > + > + if(!binDir.exists()) > + { > + binDir.mkdirs(); > + } > + > + VelocityEngine engine = new VelocityEngine(); > + Properties p = new Properties(); > + p.setProperty("resource.loader", "class"); > + p.setProperty("class.resource.loader.class", > ClasspathResourceLoader.class.getName() ); > + try { > + engine.init(p); > + } catch (Exception e) { > + throw new MojoExecutionException("Problem creating initting > velcoity engine", e); > + } > + > + VelocityContext context = new VelocityContext(); > + context.put("jbossServerHome", serverDir.getAbsolutePath()); > + context.put("jbossHome", jbossHomeDir.getAbsolutePath()); > + context.put("serverName", serverName); > + > + String osName = System.getProperty("os.name"); > + > + if (osName.startsWith("Windows")) > + { > + buildWindowsScripts(binDir, engine, context); > + } > + else > + { > + buildUnixScipts(binDir, engine, context); > + } > + } > + > + private void buildUnixScipts(File binDir, VelocityEngine engine, > VelocityContext context) throws MojoExecutionException > + { > + File runScript = new File(binDir + File.separator + "run.sh"); > + File shutdownScript = new File(binDir + File.separator + > "shutdown.sh"); > + > + try > + { > + Runtime runtime = Runtime.getRuntime(); > + > + Template runTemplate = engine.getTemplate("run.sh.vm"); > + FileWriter fileWriter = new FileWriter(runScript); > + runTemplate.merge(context, fileWriter); > + fileWriter.flush(); > + > + String command = "chmod 755 " + runScript.getAbsolutePath(); > + Process process = runtime.exec(command); > + > + Template shutdownTemplate = engine.getTemplate("shutdown.sh.vm"); > + fileWriter = new FileWriter(shutdownScript); > + shutdownTemplate.merge(context, fileWriter); > + fileWriter.flush(); > + > + command = "chmod 755 " + shutdownScript.getAbsolutePath(); > + process = runtime.exec(command); > + } > + catch(Exception e) > + { > + throw new MojoExecutionException("Problem generating scripts", > e); > + } > + } > + > + private void buildWindowsScripts(File binDir, VelocityEngine engine, > VelocityContext context) throws MojoExecutionException > + { > + File runScript = new File(binDir + File.separator + "run.sh"); > + File shutdownScript = new File(binDir + File.separator + > "shutdown.sh"); > + > + try > + { > + Template runTemplate = engine.getTemplate("run.bat.vm"); > + FileWriter fileWriter = new FileWriter(runScript); > + runTemplate.merge(context, fileWriter); > + fileWriter.flush(); > + > + Template shutdownTemplate = > engine.getTemplate("shutdown.bat.vm"); > + fileWriter = new FileWriter(shutdownScript); > + shutdownTemplate.merge(context, fileWriter); > + fileWriter.flush(); > + } > + catch(Exception e) > + { > + throw new MojoExecutionException("Problem generating scripts", > e); > + } > + } > +} > + > Index: src/main/java/org/codehaus/mojo/jboss/AbstractJBossMojo.java > =================================================================== > --- src/main/java/org/codehaus/mojo/jboss/AbstractJBossMojo.java > (revision 1497) > +++ src/main/java/org/codehaus/mojo/jboss/AbstractJBossMojo.java > (working copy) > @@ -21,6 +21,7 @@ > > import java.net.HttpURLConnection; > import java.net.URL; > +import java.io.File; > > /** > * Created by IntelliJ IDEA. > @@ -40,6 +41,11 @@ > protected String jbossHome; > > /** > + * @parameter expression="${project.build.directory}/jboss > + */ > + protected File outputDirectory; > + > + /** > * The server name > * > * @parameter expression="default" > @@ -62,10 +68,10 @@ > > Process p = null; > if (osName.startsWith("Windows")){ > - String command[] = {"cmd.exe", "/C", "cd " + jbossHome + > "\\bin & " + fName + ".bat " + " " + params }; > + String command[] = {"cmd.exe", "/C", "cd " + > outputDirectory.getAbsolutePath() + "\\bin & " + fName + ".bat " + " " + > params }; > p = runtime.exec(command); > } else { > - String command[] = {"sh", "-c", "cd " + jbossHome + "/bin; > ./" + fName + ".sh " + " " + params}; > + String command[] = {"sh", "-c", "cd " + > outputDirectory.getAbsolutePath() + "/bin; ./" + fName + ".sh " + " " + > params}; > p = runtime.exec(command); > } > > Index: pom.xml > =================================================================== > --- pom.xml (revision 1497) > +++ pom.xml (working copy) > @@ -23,10 +23,25 @@ > <version>2.0</version> > </dependency> > <dependency> > + <groupId>org.apache.maven</groupId> > + <artifactId>maven-plugin-api</artifactId> > + <version>2.0</version> > + </dependency> > + <dependency> > <groupId>commons-codec</groupId> > <artifactId>commons-codec</artifactId> > <version>1.3</version> > </dependency> > + <dependency> > + <groupId>velocity</groupId> > + <artifactId>velocity</artifactId> > + <version>1.4</version> > + </dependency> > + <dependency> > + <groupId>org.codehaus.plexus</groupId> > + <artifactId>plexus-utils</artifactId> > + <version>1.1</version> > + </dependency> > </dependencies> > <!-- > <dependencies> > > > ------------------------------------------------------------------------ > >> >> On Feb 17, 2006, at 9:37 AM, Manfred Geiler wrote: >> >>> yes, definitive! >>> >>> Thanks, >>> Manfred >>> >>> >>> On 2/17/06, Jeff Smith <[EMAIL PROTECTED] >>> <mailto:[EMAIL PROTECTED]>> wrote: >>>> All, >>>> >>>> I have modified the source for the maven 2 jboss plugin to work more >>>> like the maven 1.x plugin. I added a configure mojo that copies the >>>> contents of the specified server in your jboss home into the target >>>> directory. It can also overlay your own conf, lib an deploy stuff. >>>> Basically just like the maven 1.x plugin. Is there any interest in >>>> this? If so I can submit a patch. >>>> >>>> -jeff >>>> >> >