You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by rw...@apache.org on 2009/05/12 21:22:05 UTC
svn commit: r774039 - in /portals/jetspeed-2/portal/trunk:
applications/jetspeed-demo/jetspeed-mvn-demo-pom.xml
maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java
Author: rwatler
Date: Tue May 12 19:22:04 2009
New Revision: 774039
URL: http://svn.apache.org/viewvc?rev=774039&view=rev
Log:
APA-9 - Log4j logging refactor using apa-logging
-----------------------------------------------------
- Add "edits" capability to jetspeed-deploy-maven-plugin that allows arbitrary files to
be edited in place during deployment.
- Add "edit" entry to demo deployment configurations to edit tomcat server.xml configuration
to hook apa-logging listeners used to setup the org.apache.portals.logdir system property.
Modified:
portals/jetspeed-2/portal/trunk/applications/jetspeed-demo/jetspeed-mvn-demo-pom.xml
portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java
Modified: portals/jetspeed-2/portal/trunk/applications/jetspeed-demo/jetspeed-mvn-demo-pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed-demo/jetspeed-mvn-demo-pom.xml?rev=774039&r1=774038&r2=774039&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/applications/jetspeed-demo/jetspeed-mvn-demo-pom.xml (original)
+++ portals/jetspeed-2/portal/trunk/applications/jetspeed-demo/jetspeed-mvn-demo-pom.xml Tue May 12 19:22:04 2009
@@ -347,7 +347,20 @@
<artifact>org.apache.portals.jetspeed-2:j2-admin:war</artifact>
<delete>./j2-admin</delete>
</deployment>
+ <!-- logging -->
+ <deployment>
+ <artifact>org.apache.portals.applications:apa-logging:jar</artifact>
+ <destination>server-lib</destination>
+ </deployment>
</deployments>
+ <edits>
+ <!-- logging -->
+ <edit>
+ <targetName>server.xml</targetName>
+ <destination>server-conf</destination>
+ <editorClassName>org.apache.portals.applications.logging.tomcat.ServerXMLConfigurer</editorClassName>
+ </edit>
+ </edits>
</configuration>
</execution>
</executions>
@@ -409,6 +422,12 @@
<version>${org.apache.portals.jetspeed.version}</version>
<type>war</type>
</dependency>
+ <!-- logging -->
+ <dependency>
+ <groupId>org.apache.portals.applications</groupId>
+ <artifactId>apa-logging</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
<!-- plugin own dependencies -->
<dependency>
@@ -596,7 +615,20 @@
<infuse>true</infuse>
<delete>./webcontent</delete>
</deployment>
+ <!-- logging -->
+ <deployment>
+ <artifact>org.apache.portals.applications:apa-logging:jar</artifact>
+ <destination>server-lib</destination>
+ </deployment>
</deployments>
+ <edits>
+ <!-- logging -->
+ <edit>
+ <targetName>server.xml</targetName>
+ <destination>server-conf</destination>
+ <editorClassName>org.apache.portals.applications.logging.tomcat.ServerXMLConfigurer</editorClassName>
+ </edit>
+ </edits>
</configuration>
</execution>
</executions>
@@ -677,6 +709,12 @@
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
+ <!-- logging -->
+ <dependency>
+ <groupId>org.apache.portals.applications</groupId>
+ <artifactId>apa-logging</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
<!-- plugin own dependencies -->
<dependency>
Modified: portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java?rev=774039&r1=774038&r2=774039&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java (original)
+++ portals/jetspeed-2/portal/trunk/maven/jetspeed-deploy-maven-plugin/src/main/java/org/apache/jetspeed/maven/plugins/DeployMojo.java Tue May 12 19:22:04 2009
@@ -24,6 +24,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -104,6 +108,13 @@
private String contextName;
}
+ public static class Edit
+ {
+ private String destination;
+ private String targetName;
+ private String editorClassName;
+ }
+
/**
* The target base directory.
* @parameter
@@ -153,6 +164,11 @@
*/
private String profile;
+ /**
+ * @parameter
+ */
+ private Edit[] edits;
+
private Artifacts artifacts;
/* (non-Javadoc)
@@ -486,6 +502,90 @@
}
}
}
+
+ if (edits != null)
+ {
+ for (int i = 0; i < edits.length; i++)
+ {
+ Edit edit = edits[i];
+
+ // validate edit
+ if (edit.destination == null)
+ {
+ throw new MojoExecutionException("Required edit destination not specified");
+ }
+ if (edit.targetName == null)
+ {
+ throw new MojoExecutionException("Required edit targetName not specified");
+ }
+ if (edit.editorClassName == null)
+ {
+ throw new MojoExecutionException("Required edit editorClassName not specified");
+ }
+
+ // instantiate editor class and find method that takes a single
+ // file attribute to edit
+ Class<?> editorClass = null;
+ try
+ {
+ editorClass = Class.forName(edit.editorClassName);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new MojoExecutionException("Cannot load editor class: "+cnfe, cnfe);
+ }
+ try
+ {
+ editorClass.getConstructor(new Class<?>[0]);
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ throw new MojoExecutionException("Cannot find default constructor for "+editorClass);
+ }
+ Method editorMethod = null;
+ Method [] editorMethods = editorClass.getDeclaredMethods();
+ for (int j = 0; ((editorMethod == null) && (j < editorMethods.length)); j++)
+ {
+ Method method = editorMethods[j];
+ Type [] parameterTypes = method.getGenericParameterTypes();
+ Type returnType = method.getGenericReturnType();
+ int modifiers = method.getModifiers();
+ if ((parameterTypes.length == 1) && (parameterTypes[0] == File.class) && (returnType == Void.TYPE) && Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers))
+ {
+ editorMethod = method;
+ }
+ }
+ if (editorMethod == null)
+ {
+ throw new MojoExecutionException("Cannot find editor method in "+editorClass+" with signature: public void method(java.io.File file)");
+ }
+
+ // validate file destination and targetName
+ File targetDir = new File(targetBaseDir, (String)destMap.get(edit.destination));
+ File editTargetFile = new File(targetDir, edit.targetName);
+ if (!editTargetFile.isFile() || !editTargetFile.canRead() || !editTargetFile.canWrite())
+ {
+ throw new MojoExecutionException("Cannot find, read, or write target file to edit: "+editTargetFile);
+ }
+
+ // instantiate editor and invoke editor to edit target file
+ try
+ {
+ Object editorInstance = editorClass.newInstance();
+ editorMethod.invoke(editorInstance, editTargetFile);
+
+ getLog().info(" editing in "+edit.destination+": "+edit.targetName+" using "+editorClass.getSimpleName()+"."+editorMethod.getName()+"()");
+ }
+ catch (InvocationTargetException ite)
+ {
+ throw new MojoExecutionException("Exception thrown by editor method: "+editorClass.getName()+"."+editorMethod.getName()+"("+editTargetFile+"): "+ite.getTargetException(), ite.getTargetException());
+ }
+ catch (Exception e)
+ {
+ throw new MojoExecutionException("Failed to instantiate or invoke editor method: "+editorClass.getName()+"."+editorMethod.getName()+"("+editTargetFile+"): "+e, e);
+ }
+ }
+ }
}
private static String getValue(String value, String defaultValue)
@@ -707,6 +807,14 @@
{
destMap.put("local", ((String)destMap.get("deploy"))+"/local");
}
+ if (!destMap.containsKey("server-conf"))
+ {
+ destMap.put("server-conf", "conf");
+ }
+ if (!destMap.containsKey("server-lib"))
+ {
+ destMap.put("server-lib","server/lib");
+ }
}
else if (profile.equals(PROFILE_TOMCAT6))
{
@@ -730,6 +838,14 @@
{
destMap.put("local", ((String)destMap.get("deploy"))+"/local");
}
+ if (!destMap.containsKey("server-conf"))
+ {
+ destMap.put("server-conf", "conf");
+ }
+ if (!destMap.containsKey("server-lib"))
+ {
+ destMap.put("server-lib", "lib");
+ }
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org