[seam-commits] Seam SVN: r10142 - in maven-plugins/trunk: seam-instrument-wicket and 7 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Mar 10 11:47:08 EDT 2009


Author: cpopetz
Date: 2009-03-10 11:47:08 -0400 (Tue, 10 Mar 2009)
New Revision: 10142

Added:
   maven-plugins/trunk/seam-instrument-wicket/
   maven-plugins/trunk/seam-instrument-wicket/pom.xml
   maven-plugins/trunk/seam-instrument-wicket/src/
   maven-plugins/trunk/seam-instrument-wicket/src/main/
   maven-plugins/trunk/seam-instrument-wicket/src/main/java/
   maven-plugins/trunk/seam-instrument-wicket/src/main/java/org/
   maven-plugins/trunk/seam-instrument-wicket/src/main/java/org/jboss/
   maven-plugins/trunk/seam-instrument-wicket/src/main/java/org/jboss/seam/
   maven-plugins/trunk/seam-instrument-wicket/src/main/java/org/jboss/seam/wicket/
   maven-plugins/trunk/seam-instrument-wicket/src/main/java/org/jboss/seam/wicket/InstrumentationMojo.java
Log:
Initial commit of seam-instrument-wicket maven plugin



Property changes on: maven-plugins/trunk/seam-instrument-wicket
___________________________________________________________________
Name: svn:ignore
   + .classpath
.settings
.project


Added: maven-plugins/trunk/seam-instrument-wicket/pom.xml
===================================================================
--- maven-plugins/trunk/seam-instrument-wicket/pom.xml	                        (rev 0)
+++ maven-plugins/trunk/seam-instrument-wicket/pom.xml	2009-03-10 15:47:08 UTC (rev 10142)
@@ -0,0 +1,123 @@
+<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>
+  <groupId>org.jboss.seam</groupId>
+  <artifactId>seam-instrument-wicket</artifactId>
+  <packaging>maven-plugin</packaging>
+  <version>2.1.2-SNAPSHOT</version>
+  <name>Seam Wicket Instrumentation</name>
+  <url>http://www.seamframework.org</url>
+  <description>
+      A maven mojo to instrument wicket components to work with Seam's wicket integration.
+  </description>
+   
+   <contributors>
+      <contributor>
+         <name>Clint Popetz</name>
+      </contributor>
+   </contributors>
+   
+   <scm>
+      <developerConnection>scm:svn:https://svn.jboss.org/repos/seam/maven-plugins/trunk</developerConnection>
+      <connection>scm:svn:http://anonsvn.jboss.org/repos/seam/maven-plugins</connection>
+      <url>http://fisheye.jboss.org/browse/Seam/maven-plugins</url>
+   </scm>
+
+   <pluginRepositories>
+      <pluginRepository>
+         <id>repository.jboss.org</id>
+         <name>JBoss Repository</name>
+         <url>http://repository.jboss.org/maven2</url>
+      </pluginRepository>
+   </pluginRepositories>
+   <repositories>
+      <repository>
+         <id>repository.jboss.org</id>
+         <name>JBoss Repository</name>
+         <url>http://repository.jboss.org/maven2</url>
+      </repository>
+   </repositories>
+
+   <distributionManagement>
+      <repository>
+         <!-- Copy the dist to the local checkout of the JBoss maven2 repo ${maven.repository.root} -->
+         <!-- It is anticipated that ${maven.repository.root} be set in user's settings.xml -->
+         <!-- todo : replace this with direct svn access once the svnkit providers are available -->
+         <id>repository.jboss.org</id>
+         <url>file://${maven.repository.root}</url>
+      </repository>
+      <snapshotRepository>
+         <id>snapshots.jboss.org</id>
+         <name>JBoss Snapshot Repository</name>
+         <url>dav:https://snapshots.jboss.org/maven2</url>
+      </snapshotRepository>
+   </distributionManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+    	<groupId>javassist</groupId>
+    	<artifactId>javassist</artifactId>
+    	<version>3.8.0.GA</version>
+    </dependency>
+    <dependency>
+    	<groupId>org.jboss.seam</groupId>
+    	<artifactId>jboss-seam-wicket</artifactId>
+    	<version>2.1.2-SNAPSHOT</version>
+    </dependency>
+      <dependency>
+        <groupId>log4j</groupId>
+        <artifactId>log4j</artifactId>
+        <version>1.2.14</version>
+      </dependency>
+    <dependency>
+    	<groupId>org.jboss.seam</groupId>
+    	<artifactId>jboss-seam</artifactId>
+    	<version>2.1.2-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+  
+    <build>
+
+    <pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+		<plugin>
+			<groupId>org.apache.maven.plugins</groupId>
+			<artifactId>maven-source-plugin</artifactId>
+			<executions>
+				<execution>
+					<goals>
+						<goal>jar</goal>
+					</goals>
+				</execution>
+			</executions>
+		</plugin>
+
+  	</plugins>
+  	</pluginManagement>
+		</build>
+	</project>

Added: maven-plugins/trunk/seam-instrument-wicket/src/main/java/org/jboss/seam/wicket/InstrumentationMojo.java
===================================================================
--- maven-plugins/trunk/seam-instrument-wicket/src/main/java/org/jboss/seam/wicket/InstrumentationMojo.java	                        (rev 0)
+++ maven-plugins/trunk/seam-instrument-wicket/src/main/java/org/jboss/seam/wicket/InstrumentationMojo.java	2009-03-10 15:47:08 UTC (rev 10142)
@@ -0,0 +1,172 @@
+package org.jboss.seam.wicket;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.LoaderClassPath;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.jboss.seam.wicket.ioc.JavassistInstrumentor;
+
+/**
+ * This mojo takes classes specified with the "includes" parameter in the plugin configuration
+ * and instruments them with Seam's Wicket JavassistInstrumentor.
+ * @goal instrument
+ * @requiresDependencyResolution
+ * @phase process-classes
+ */
+public class InstrumentationMojo extends AbstractMojo
+{
+   /**
+    * Location of the file.
+    * 
+    * @parameter expression="${project.build.directory}/classes"
+    * @required
+    */
+   private File classesDirectory;
+
+   public File getClassesDirectory()
+   {
+      return classesDirectory;
+   }
+
+   public void setClassesDirectory(File classesDirectory)
+   {
+      this.classesDirectory = classesDirectory;
+   }
+
+   /**
+    * Maven project we are building
+    * 
+    * @parameter expression="${project}"
+    * @required
+    */
+   private MavenProject project;
+
+   /**
+    * A set of file patterns representing classes to instrument
+    * 
+    * @parameter alias="includes"
+    */
+   private String[] includes = new String[0];
+
+   public String[] getIncludes()
+   {
+      return includes;
+   }
+
+   public void setIncludes(String[] includes)
+   {
+      this.includes = includes;
+   }
+
+   /**
+    * @parameter default-value="${project.runtimeClasspathElements}"
+    * @readonly
+    */
+   private List<String> runtimeClassPath;
+
+   /**
+    * Same as above, but compiled regexps
+    */
+   private List<Pattern> mIncludePatterns;
+
+   public void execute() throws MojoExecutionException
+   {
+
+      try
+      {
+         // make sure target/classes has been created
+         if (!classesDirectory.exists())
+         {
+            throw new IllegalStateException("target/classes directory does not exist");
+         }
+
+         ClassPool classPool = new ClassPool();
+         classPool.insertClassPath(classesDirectory.getPath());
+         // append system classpath
+         ClassLoader system = Object.class.getClassLoader();
+         if (system == null)
+         {
+            system = Thread.currentThread().getContextClassLoader();
+         }
+         classPool.insertClassPath(new LoaderClassPath(system));
+
+         for (Object path : project.getCompileClasspathElements())
+         {
+            File dir = new File((String) path);
+            if (dir.exists())
+            {
+               classPool.insertClassPath((String) path);
+            }
+         }
+         for (String path : runtimeClassPath)
+         {
+            classPool.insertClassPath((String) path);
+         }
+
+         mIncludePatterns = new ArrayList<Pattern>();
+         for (String pat : includes)
+         {
+            mIncludePatterns.add(Pattern.compile(pat));
+         }
+
+         Map<String, CtClass> instrumentedClasses = new HashMap<String, CtClass>();
+
+         JavassistInstrumentor instrumentor = new JavassistInstrumentor(classPool);
+
+         List<String> classes = new ArrayList<String>();
+         visitDir(classesDirectory, classes);
+
+         for (String path : classes)
+         {
+            instrumentedClasses.put(path, instrumentor.instrumentClass(filenameToClassname(path)));
+         }
+         for (Map.Entry<String, CtClass> entry : instrumentedClasses.entrySet())
+         {
+            if (entry.getValue().isModified())
+               entry.getValue().writeFile(classesDirectory.getPath());
+         }
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+         throw new MojoExecutionException("Error instrumenting wicket code", e);
+      }
+   }
+
+   private void visitDir(File classesDir, List<String> classes)
+   {
+      for (File file : classesDir.listFiles())
+      {
+         if (file.getPath().endsWith(".class"))
+         {
+            for (Pattern pat : mIncludePatterns)
+            {
+               if (pat.matcher(file.getPath()).find())
+               {
+                  classes.add(file.getPath());
+                  break;
+               }
+            }
+         }
+         else if (file.isDirectory())
+            visitDir(file, classes);
+      }
+   }
+
+   protected String filenameToClassname(String filename)
+   {
+      filename = filename.substring(classesDirectory.getPath().length() + 1);
+      return filename.substring(0, filename.lastIndexOf(".class")).replace('/', '.').replace('\\', '.');
+   }
+
+}




More information about the seam-commits mailing list