You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2011/01/17 18:56:34 UTC
svn commit: r1060026 - in /cocoon/trunk/tools/cocoon-maven-plugin: pom.xml
src/main/java/org/apache/cocoon/maven/rcl/PrepareWebappMojo.java
Author: reinhard
Date: Mon Jan 17 17:56:33 2011
New Revision: 1060026
URL: http://svn.apache.org/viewvc?rev=1060026&view=rev
Log:
set release versions
Modified:
cocoon/trunk/tools/cocoon-maven-plugin/pom.xml
cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/rcl/PrepareWebappMojo.java
Modified: cocoon/trunk/tools/cocoon-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-plugin/pom.xml?rev=1060026&r1=1060025&r2=1060026&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-plugin/pom.xml (original)
+++ cocoon/trunk/tools/cocoon-maven-plugin/pom.xml Mon Jan 17 17:56:33 2011
@@ -21,14 +21,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
+ <packaging>maven-plugin</packaging>
+
<parent>
<artifactId>cocoon-tools-modules</artifactId>
<groupId>org.apache.cocoon</groupId>
- <version>5-SNAPSHOT</version>
+ <version>8</version>
</parent>
<artifactId>cocoon-maven-plugin</artifactId>
<version>1.0.0-RC1-SNAPSHOT</version>
- <packaging>maven-plugin</packaging>
<name>Cocoon Maven 2 Plugin</name>
<dependencies>
Modified: cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/rcl/PrepareWebappMojo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/rcl/PrepareWebappMojo.java?rev=1060026&r1=1060025&r2=1060026&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/rcl/PrepareWebappMojo.java (original)
+++ cocoon/trunk/tools/cocoon-maven-plugin/src/main/java/org/apache/cocoon/maven/rcl/PrepareWebappMojo.java Mon Jan 17 17:56:33 2011
@@ -65,9 +65,8 @@ import org.w3c.dom.Document;
import org.xml.sax.SAXException;
/**
- * Create a web application environment for a Cocoon block, including support
- * for the reloading classloader.
- *
+ * Create a web application environment for a Cocoon block, including support for the reloading classloader.
+ *
* @goal prepare
* @requiresProject true
* @requiresDependencyResolution runtime
@@ -76,9 +75,9 @@ import org.xml.sax.SAXException;
*/
public class PrepareWebappMojo extends AbstractMojo {
- private static final String LIB_VERSION_WRAPPER = "1.0.0-RC1-SNAPSHOT";
+ private static final String LIB_VERSION_WRAPPER = "1.0.0";
- private static final String LIB_VERSION_SPRING_RELOADER = "1.0.0-RC1-SNAPSHOT";
+ private static final String LIB_VERSION_SPRING_RELOADER = "1.0.0";
private static final String WEB_INF_WEB_XML = "WEB-INF/web.xml";
@@ -223,71 +222,152 @@ public class PrepareWebappMojo extends A
private MavenProject project;
+ protected static File createPath(File file) {
+ if (file.getParentFile() != null && !file.getParentFile().exists()) {
+ file.getParentFile().mkdirs();
+ }
+ return file;
+ }
+
public void execute() throws MojoExecutionException {
// check if this plugin is useful at all
- if (!project.getPackaging().equals("jar") || !rclPropertiesFile.exists()) {
- getLog().info("Don't execute the Cocoon RCL plugin becaues either its packaging "
- + "type is not 'jar' or "
- + "there is no rcl.properties file in the block's base directory.");
+ if (!this.project.getPackaging().equals("jar") || !this.rclPropertiesFile.exists()) {
+ this.getLog().info("Don't execute the Cocoon RCL plugin becaues either its packaging "
+ + "type is not 'jar' or "
+ + "there is no rcl.properties file in the block's base directory.");
return;
}
// check profile
if ("cocoon-22".equals(this.webappProfile)) {
- getLog().info("Preparing a Cocoon web application.");
+ this.getLog().info("Preparing a Cocoon web application.");
} else if ("ssf".equals(this.webappProfile)) {
- getLog().info("Preparing a Servlet-Service web application.");
+ this.getLog().info("Preparing a Servlet-Service web application.");
} else {
throw new MojoExecutionException("Only the profiles 'cocoon-22' and 'ssf' are supported.");
}
// create web application containing all necessary files (web.xml, applicationContext.xml, log4j.xconf)
- File webAppBaseDir = new File(target, "webapp");
- writeInputStreamToFile(readResourceFromClassloader(WEB_INF_WEB_XML),
+ File webAppBaseDir = new File(this.target, "webapp");
+ this.writeInputStreamToFile(this.readResourceFromClassloader(WEB_INF_WEB_XML),
createPath(new File(webAppBaseDir, WEB_INF_WEB_XML)));
- writeInputStreamToFile(readResourceFromClassloader(WEB_INF_APP_CONTEXT),
+ this.writeInputStreamToFile(this.readResourceFromClassloader(WEB_INF_APP_CONTEXT),
createPath(new File(webAppBaseDir, WEB_INF_APP_CONTEXT)));
- writeLog4jXml(webAppBaseDir);
+ this.writeLog4jXml(webAppBaseDir);
// copy the content of a custom webapp context directory to the prepared web application.
- copyCustomWebappDirectory(webAppBaseDir);
+ this.copyCustomWebappDirectory(webAppBaseDir);
// copy rcl webapp wrapper and all its dependencies to WEB-INF/lib
- copyRclWrapperLibs(webAppBaseDir);
+ this.copyRclWrapperLibs(webAppBaseDir);
// read the properties
- RwmProperties props = readProperties();
+ RwmProperties props = this.readProperties();
// create a file that contains the URLs of all libraries (config for the UrlClassLoader)
- createUrlClassLoaderConf(webAppBaseDir, props);
+ this.createUrlClassLoaderConf(webAppBaseDir, props);
// create a file that contains the URLs of all classes directories (config for the ReloadingClassLoader)
- createReloadingClassLoaderConf(webAppBaseDir, props);
+ this.createReloadingClassLoaderConf(webAppBaseDir, props);
// based on the RCL configuration file, create a Spring properties file
- createSpringProperties(webAppBaseDir, props);
+ this.createSpringProperties(webAppBaseDir, props);
// based on the RCL configuration file, create a Cocoon properties file
- createCocoonProperties(webAppBaseDir, props);
+ this.createCocoonProperties(webAppBaseDir, props);
// create RCL properties
- createProperties(webAppBaseDir);
+ this.createProperties(webAppBaseDir);
// apply xpatch files
- applyXpatchFiles(webAppBaseDir, props);
+ this.applyXpatchFiles(webAppBaseDir, props);
// rewrite WebXml
- rewriteWebXml(webAppBaseDir);
+ this.rewriteWebXml(webAppBaseDir);
}
- protected RwmProperties readProperties() throws MojoExecutionException {
- RwmProperties props = null;
+ protected void applyXpatchFiles(File webAppBaseDir, RwmProperties props) throws MojoExecutionException {
+ // find all xpatch files in all configured blocks
+ Set classesDirs = props.getClassesDirs();
+ File[] allXPatchFiles = new File[0];
+ for(Iterator it = classesDirs.iterator(); it.hasNext();) {
+ String f = RwmProperties.calcRootDir((String) it.next());
+ try {
+ File f1 = new File(new File(new URI(f)), "src/main/resources/META-INF/cocoon/xpatch");
+ File[] xmlFiles = f1.listFiles(new FilenameFilter() {
+ public boolean accept(File d, String name) {
+ return name.toLowerCase().endsWith(".xweb");
+ }
+ });
+ if(xmlFiles != null) {
+ File[] mergedArray = new File[allXPatchFiles.length + xmlFiles.length];
+ System.arraycopy(allXPatchFiles, 0, mergedArray, 0, allXPatchFiles.length);
+ System.arraycopy(xmlFiles, 0, mergedArray, allXPatchFiles.length, xmlFiles.length);
+ allXPatchFiles = mergedArray;
+ }
+ } catch (URISyntaxException e) {
+ }
+ }
+
+ Map libs = AbstractDeployMojo.getBlockArtifactsAsMap(this.project, this.getLog());
+ AbstractDeployMojo.xpatch(libs, allXPatchFiles, webAppBaseDir, this.getLog());
+ }
+
+ protected void copyCustomWebappDirectory(File webAppBaseDir) throws MojoExecutionException {
+ if (this.customWebappDirectory == null) {
+ return;
+ }
+ if (!this.customWebappDirectory.exists()) {
+ throw new MojoExecutionException("The custom web application directory does not exist.");
+ }
+ if (!this.customWebappDirectory.isDirectory()) {
+ throw new MojoExecutionException(
+ "The value of the parameter 'customWebappDirectory' doesn't point to a directory.");
+ }
+
try {
- props = new RwmProperties(this.rclPropertiesFile, this.project.getBasedir());
- } catch (ConfigurationException e) {
- throw new MojoExecutionException("Can't read " + this.rclPropertiesFile.getAbsolutePath(), e);
+ FileUtils.copyDirectory(this.customWebappDirectory, webAppBaseDir);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Can't copy custom webapp files (directory: '" + this.customWebappDirectory
+ + ") to the web application in preparation.", e);
+ }
+ }
+
+ protected void copyRclWrapperLibs(File webAppBaseDir) throws MojoExecutionException {
+ Set rclWebappDependencies = this.getDependencies("org.apache.cocoon", "cocoon-rcl-webapp-wrapper", LIB_VERSION_WRAPPER, "jar");
+ for (Iterator rclIt = rclWebappDependencies.iterator(); rclIt.hasNext();) {
+ Artifact artifact = (Artifact) rclIt.next();
+ try {
+ FileUtils.copyFileToDirectory(artifact.getFile(), createPath(new File(webAppBaseDir, WEB_INF_LIB)));
+ } catch (IOException e) {
+ throw new MojoExecutionException("Can't copy artifact " + artifact);
+ }
+ this.getLog().info("Adding lib to " + WEB_INF_LIB + ": " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
+ + artifact.getVersion() + ":" + artifact.getType());
+ }
+ }
+
+ protected void createCocoonProperties(File webAppBaseDir, RwmProperties props) throws MojoExecutionException {
+ File springPropFile = createPath(new File(webAppBaseDir, WEB_INF_COCOON_PROPS));
+ try {
+ FileOutputStream springPropsOs = new FileOutputStream(springPropFile);
+ props.getCocoonProperties().store(springPropsOs, "Cocoon properties as read from " + this.rclPropertiesFile.toURI().toURL());
+ springPropsOs.close();
+ } catch (IOException e) {
+ throw new MojoExecutionException("Can't write to " + springPropFile.getAbsolutePath(), e);
+ }
+ }
+
+ protected void createProperties(File webAppBaseDir) throws MojoExecutionException {
+ File rclProps = createPath(new File(webAppBaseDir, WEB_INF_RCLWRAPPER_PROPERTIES));
+ try {
+ Properties props = new Properties();
+ props.setProperty("reloading.spring.enabled", Boolean.toString(this.reloadingSpringEnabled));
+ props.setProperty("reloading.classloader.enabled", Boolean.toString(this.reloadingClassLoaderEnabled));
+ props.store(new FileOutputStream(rclProps), "Reloading Classloader Properties");
+ } catch (IOException e) {
+ throw new MojoExecutionException("Can't write to " + rclProps.getAbsolutePath(), e);
}
- return props;
}
@SuppressWarnings("unchecked")
@@ -321,17 +401,28 @@ public class PrepareWebappMojo extends A
if (excludeLibProps.contains(artifact.getGroupId() + ":" + artifact.getArtifactId())) {
continue;
}
-
+
fw.write(artifact.getFile().toURI().toURL().toExternalForm() + "\n");
this.getLog().debug("Adding library (URLClassLoader configuration): " + artifact.getArtifactId());
}
-
+
fw.close();
} catch(IOException e) {
throw new MojoExecutionException("Error while writing to " + urlClConfFile, e);
}
}
+ protected void createSpringProperties(File webAppBaseDir, RwmProperties props) throws MojoExecutionException {
+ File springPropFile = createPath(new File(webAppBaseDir, WEB_INF_COCOON_SPRING_PROPS));
+ try {
+ FileOutputStream springPropsOs = new FileOutputStream(springPropFile);
+ props.getSpringProperties().store(springPropsOs, "Spring properties as read from " + this.rclPropertiesFile.toURI().toURL());
+ springPropsOs.close();
+ } catch (IOException e) {
+ throw new MojoExecutionException("Can't write to " + springPropFile.getAbsolutePath(), e);
+ }
+ }
+
protected void createUrlClassLoaderConf(File webAppBaseDir, RwmProperties props) throws MojoExecutionException {
File urlClConfFile = createPath(new File(webAppBaseDir, WEB_INF_RCL_URLCL_CONF));
try {
@@ -345,7 +436,7 @@ public class PrepareWebappMojo extends A
}
// add all project artifacts
- Set<Artifact> artifacts = project.getArtifacts();
+ Set<Artifact> artifacts = this.project.getArtifacts();
ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
Set<Artifact> filteredArtifacts = new HashSet<Artifact>();
@@ -355,133 +446,89 @@ public class PrepareWebappMojo extends A
continue;
}
// remove artifacts that are not in runtime scope
- if(!filter.include(eachArtifact)) {
+ if(!filter.include(eachArtifact)) {
continue;
}
// skip explicit excludes
if(excludeLibProps.contains(eachArtifact.getGroupId() + ":" + eachArtifact.getArtifactId())) {
continue;
}
-
+
filteredArtifacts.add(eachArtifact);
}
-
+
// add the Spring reloader libraries
- Set<Artifact> springReloaderArtifacts = getDependencies("org.apache.cocoon", "cocoon-rcl-spring-reloader",
- LIB_VERSION_SPRING_RELOADER, "jar");
+ Set<Artifact> springReloaderArtifacts = this.getDependencies("org.apache.cocoon", "cocoon-rcl-spring-reloader",
+ LIB_VERSION_SPRING_RELOADER, "jar");
filteredArtifacts.addAll(springReloaderArtifacts);
for (Artifact eachArtifact : filteredArtifacts) {
fw.write(eachArtifact.getFile().toURI().toURL().toExternalForm() + "\n");
this.getLog().debug("Adding library (URLClassLoader configuration): " + eachArtifact.getArtifactId());
}
-
+
fw.close();
} catch(IOException e) {
throw new MojoExecutionException("Error while writing to " + urlClConfFile, e);
}
}
- protected void createSpringProperties(File webAppBaseDir, RwmProperties props) throws MojoExecutionException {
- File springPropFile = createPath(new File(webAppBaseDir, WEB_INF_COCOON_SPRING_PROPS));
+ protected Set<Artifact> getDependencies(final String groupId, final String artifactId, final String version,
+ final String packaging) throws MojoExecutionException {
+ Set returnSet = new HashSet();
try {
- FileOutputStream springPropsOs = new FileOutputStream(springPropFile);
- props.getSpringProperties().store(springPropsOs, "Spring properties as read from " + this.rclPropertiesFile.toURI().toURL());
- springPropsOs.close();
- } catch (IOException e) {
- throw new MojoExecutionException("Can't write to " + springPropFile.getAbsolutePath(), e);
- }
- }
+ Set artifacts = null;
+ ArtifactResolutionResult result = null;
- protected void createCocoonProperties(File webAppBaseDir, RwmProperties props) throws MojoExecutionException {
- File springPropFile = createPath(new File(webAppBaseDir, WEB_INF_COCOON_PROPS));
- try {
- FileOutputStream springPropsOs = new FileOutputStream(springPropFile);
- props.getCocoonProperties().store(springPropsOs, "Cocoon properties as read from " + this.rclPropertiesFile.toURI().toURL());
- springPropsOs.close();
- } catch (IOException e) {
- throw new MojoExecutionException("Can't write to " + springPropFile.getAbsolutePath(), e);
- }
- }
+ Dependency dependency = new Dependency();
+ dependency.setGroupId(groupId);
+ dependency.setArtifactId(artifactId);
+ dependency.setVersion(version);
- protected void copyRclWrapperLibs(File webAppBaseDir) throws MojoExecutionException {
- Set rclWebappDependencies = getDependencies("org.apache.cocoon", "cocoon-rcl-webapp-wrapper", LIB_VERSION_WRAPPER, "jar");
- for (Iterator rclIt = rclWebappDependencies.iterator(); rclIt.hasNext();) {
- Artifact artifact = (Artifact) rclIt.next();
- try {
- FileUtils.copyFileToDirectory(artifact.getFile(), createPath(new File(webAppBaseDir, WEB_INF_LIB)));
- } catch (IOException e) {
- throw new MojoExecutionException("Can't copy artifact " + artifact);
+ List dependencies = new ArrayList();
+ dependencies.add(dependency);
+ Artifact pomArtifact = this.artifactFactory.createBuildArtifact("unspecified", "unspecified", "0.0", "jar");
+ Map managedDependencies = Collections.EMPTY_MAP;
+ artifacts = MavenMetadataSource.createArtifacts(this.artifactFactory, dependencies, "compile", null, null);
+ result = this.artifactResolver.resolveTransitively(artifacts, pomArtifact, managedDependencies, this.localRepository,
+ this.remoteArtifactRepositories, this.metadataSource);
+
+ for (Iterator i = artifacts.iterator(); i.hasNext();) {
+ Artifact artifact = (Artifact) i.next();
+ returnSet.add(artifact);
}
- getLog().info("Adding lib to " + WEB_INF_LIB + ": " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
- + artifact.getVersion() + ":" + artifact.getType());
+ for (Iterator i = result.getArtifacts().iterator(); i.hasNext();) {
+ Artifact artifact = (Artifact) i.next();
+ returnSet.add(artifact);
+ }
+ } catch (ArtifactResolutionException e) {
+ throw new MojoExecutionException("Can't resolve artifact " + groupId + ":" + artifactId + ":" + version, e);
+ } catch (ArtifactNotFoundException e) {
+ throw new MojoExecutionException("Can't find artifact " + groupId + ":" + artifactId + ":" + version, e);
+ } catch (InvalidDependencyVersionException e) {
+ throw new MojoExecutionException("Invalid version of artifact " + groupId + ":" + artifactId + ":"
+ + version, e);
}
+ return returnSet;
}
- protected void createProperties(File webAppBaseDir) throws MojoExecutionException {
- File rclProps = createPath(new File(webAppBaseDir, WEB_INF_RCLWRAPPER_PROPERTIES));
+ protected RwmProperties readProperties() throws MojoExecutionException {
+ RwmProperties props = null;
try {
- Properties props = new Properties();
- props.setProperty("reloading.spring.enabled", Boolean.toString(this.reloadingSpringEnabled));
- props.setProperty("reloading.classloader.enabled", Boolean.toString(this.reloadingClassLoaderEnabled));
- props.store(new FileOutputStream(rclProps), "Reloading Classloader Properties");
- } catch (IOException e) {
- throw new MojoExecutionException("Can't write to " + rclProps.getAbsolutePath(), e);
+ props = new RwmProperties(this.rclPropertiesFile, this.project.getBasedir());
+ } catch (ConfigurationException e) {
+ throw new MojoExecutionException("Can't read " + this.rclPropertiesFile.getAbsolutePath(), e);
}
+ return props;
}
- protected void writeLog4jXml(File webAppBaseDir) throws MojoExecutionException {
- Map log4jTemplateMap = new HashMap();
- log4jTemplateMap.put("useConsoleAppender", new Boolean(this.useConsoleAppender));
- log4jTemplateMap.put("useSocketAppender", new Boolean(this.useSocketAppender));
- writeStringTemplateToFile(webAppBaseDir, WEB_INF_LOG4J, customLog4jXconf, log4jTemplateMap);
- }
-
- protected void copyCustomWebappDirectory(File webAppBaseDir) throws MojoExecutionException {
- if (this.customWebappDirectory == null) {
- return;
- }
- if (!this.customWebappDirectory.exists()) {
- throw new MojoExecutionException("The custom web application directory does not exist.");
- }
- if (!this.customWebappDirectory.isDirectory()) {
- throw new MojoExecutionException(
- "The value of the parameter 'customWebappDirectory' doesn't point to a directory.");
- }
-
- try {
- FileUtils.copyDirectory(this.customWebappDirectory, webAppBaseDir);
- } catch (IOException e) {
- throw new MojoExecutionException("Can't copy custom webapp files (directory: '" + this.customWebappDirectory
- + ") to the web application in preparation.", e);
- }
- }
- protected void applyXpatchFiles(File webAppBaseDir, RwmProperties props) throws MojoExecutionException {
- // find all xpatch files in all configured blocks
- Set classesDirs = props.getClassesDirs();
- File[] allXPatchFiles = new File[0];
- for(Iterator it = classesDirs.iterator(); it.hasNext();) {
- String f = RwmProperties.calcRootDir((String) it.next());
- try {
- File f1 = new File(new File(new URI(f)), "src/main/resources/META-INF/cocoon/xpatch");
- File[] xmlFiles = f1.listFiles(new FilenameFilter() {
- public boolean accept(File d, String name) {
- return name.toLowerCase().endsWith(".xweb");
- }
- });
- if(xmlFiles != null) {
- File[] mergedArray = new File[allXPatchFiles.length + xmlFiles.length];
- System.arraycopy(allXPatchFiles, 0, mergedArray, 0, allXPatchFiles.length);
- System.arraycopy(xmlFiles, 0, mergedArray, allXPatchFiles.length, xmlFiles.length);
- allXPatchFiles = mergedArray;
- }
- } catch (URISyntaxException e) {
- }
- }
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ utility methods ~~~~~~~~~~
- Map libs = AbstractDeployMojo.getBlockArtifactsAsMap(this.project, this.getLog());
- AbstractDeployMojo.xpatch(libs, allXPatchFiles, webAppBaseDir, this.getLog());
+ protected InputStream readResourceFromClassloader(String fileName) {
+ String resource = PrepareWebappMojo.class.getPackage().getName().replace('.', '/') + "/profiles/"
+ + this.webappProfile + "/" + fileName;
+ return PrepareWebappMojo.class.getClassLoader().getResourceAsStream(resource);
}
protected void rewriteWebXml(File webAppBaseDir) throws MojoExecutionException {
@@ -495,9 +542,9 @@ public class PrepareWebappMojo extends A
throw new MojoExecutionException("Problem while parsing " + webXml);
}
WebXmlRewriter webXmlRewriter = new WebXmlRewriter(
- "org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServlet",
- "org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingListener",
- "org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServletFilter", false);
+ "org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServlet",
+ "org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingListener",
+ "org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingServletFilter", false);
if (webXmlRewriter.rewrite(webXmlDocument)) {
// save web.xml
try {
@@ -511,46 +558,24 @@ public class PrepareWebappMojo extends A
}
}
+ protected void writeInputStreamToFile(final InputStream is, final File f) throws MojoExecutionException {
+ Validate.notNull(is);
+ Validate.notNull(f);
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ utility methods ~~~~~~~~~~
-
- protected Set<Artifact> getDependencies(final String groupId, final String artifactId, final String version,
- final String packaging) throws MojoExecutionException {
- Set returnSet = new HashSet();
try {
- Set artifacts = null;
- ArtifactResolutionResult result = null;
-
- Dependency dependency = new Dependency();
- dependency.setGroupId(groupId);
- dependency.setArtifactId(artifactId);
- dependency.setVersion(version);
-
- List dependencies = new ArrayList();
- dependencies.add(dependency);
- Artifact pomArtifact = artifactFactory.createBuildArtifact("unspecified", "unspecified", "0.0", "jar");
- Map managedDependencies = Collections.EMPTY_MAP;
- artifacts = MavenMetadataSource.createArtifacts(artifactFactory, dependencies, "compile", null, null);
- result = artifactResolver.resolveTransitively(artifacts, pomArtifact, managedDependencies, localRepository,
- remoteArtifactRepositories, metadataSource);
-
- for (Iterator i = artifacts.iterator(); i.hasNext();) {
- Artifact artifact = (Artifact) i.next();
- returnSet.add(artifact);
- }
- for (Iterator i = result.getArtifacts().iterator(); i.hasNext();) {
- Artifact artifact = (Artifact) i.next();
- returnSet.add(artifact);
- }
- } catch (ArtifactResolutionException e) {
- throw new MojoExecutionException("Can't resolve artifact " + groupId + ":" + artifactId + ":" + version, e);
- } catch (ArtifactNotFoundException e) {
- throw new MojoExecutionException("Can't find artifact " + groupId + ":" + artifactId + ":" + version, e);
- } catch (InvalidDependencyVersionException e) {
- throw new MojoExecutionException("Invalid version of artifact " + groupId + ":" + artifactId + ":"
- + version, e);
+ FileWriter fw = new FileWriter(f);
+ IOUtils.copy(is, fw);
+ fw.close();
+ } catch (IOException e) {
+ throw new MojoExecutionException("Can't write to file " + f);
}
- return returnSet;
+ }
+
+ protected void writeLog4jXml(File webAppBaseDir) throws MojoExecutionException {
+ Map log4jTemplateMap = new HashMap();
+ log4jTemplateMap.put("useConsoleAppender", new Boolean(this.useConsoleAppender));
+ log4jTemplateMap.put("useSocketAppender", new Boolean(this.useSocketAppender));
+ this.writeStringTemplateToFile(webAppBaseDir, WEB_INF_LOG4J, this.customLog4jXconf, log4jTemplateMap);
}
protected void writeStringTemplateToFile(final File basedir, final String fileName, final String customFile,
@@ -566,10 +591,10 @@ public class PrepareWebappMojo extends A
} else {
this.getLog().info(
"supplied custom file " + customFile + " doesn't exist. Fallback to default: " + fileName);
- fileIs = readResourceFromClassloader(fileName);
+ fileIs = this.readResourceFromClassloader(fileName);
}
} else {
- fileIs = readResourceFromClassloader(fileName);
+ fileIs = this.readResourceFromClassloader(fileName);
}
StringTemplate stringTemplate = new StringTemplate(IOUtils.toString(fileIs));
for (Iterator templateObjectsIt = templateObjects.keySet().iterator(); templateObjectsIt.hasNext();) {
@@ -590,30 +615,4 @@ public class PrepareWebappMojo extends A
}
}
}
-
- protected InputStream readResourceFromClassloader(String fileName) {
- String resource = PrepareWebappMojo.class.getPackage().getName().replace('.', '/') + "/profiles/"
- + this.webappProfile + "/" + fileName;
- return PrepareWebappMojo.class.getClassLoader().getResourceAsStream(resource);
- }
-
- protected static File createPath(File file) {
- if (file.getParentFile() != null && !file.getParentFile().exists()) {
- file.getParentFile().mkdirs();
- }
- return file;
- }
-
- protected void writeInputStreamToFile(final InputStream is, final File f) throws MojoExecutionException {
- Validate.notNull(is);
- Validate.notNull(f);
-
- try {
- FileWriter fw = new FileWriter(f);
- IOUtils.copy(is, fw);
- fw.close();
- } catch (IOException e) {
- throw new MojoExecutionException("Can't write to file " + f);
- }
- }
}