directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r718200 - in /directory/sandbox/kayyagari/apacheds-olm: pom.xml src/main/java/org/apache/directory/server/ src/main/java/org/apache/directory/server/OlmCodeEnhancerMojo.java src/main/java/org/apache/directory/server/OlmSourceGenMojo.java
Date Mon, 17 Nov 2008 09:00:32 GMT
Author: kayyagari
Date: Mon Nov 17 01:00:30 2008
New Revision: 718200

URL: http://svn.apache.org/viewvc?rev=718200&view=rev
Log:
a maven plugin implementation for generating and enhancing the byte code

Added:
    directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/
    directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/OlmCodeEnhancerMojo.java
    directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/OlmSourceGenMojo.java
Modified:
    directory/sandbox/kayyagari/apacheds-olm/pom.xml

Modified: directory/sandbox/kayyagari/apacheds-olm/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/pom.xml?rev=718200&r1=718199&r2=718200&view=diff
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/pom.xml (original)
+++ directory/sandbox/kayyagari/apacheds-olm/pom.xml Mon Nov 17 01:00:30 2008
@@ -8,13 +8,14 @@
   </parent>
   <artifactId>apacheds-olm</artifactId>
   <name>apacheds-olm</name>
+  <packaging>maven-plugin</packaging>
   <version>0.0.1-SNAPSHOT</version>
   <description>Object LDAP Mapping</description>
   <dependencies>
     <dependency>
       <groupId>org.apache.directory.shared</groupId>
       <artifactId>shared-ldap</artifactId>
-      <version>0.9.13-SNAPSHOT</version>
+      <version>0.9.14-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>antlr</groupId>
@@ -36,6 +37,16 @@
       <artifactId>apacheds-server-unit</artifactId>
       <version>1.5.5-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0</version>
+    </dependency>    
+    <dependency>
+      <groupId>cglib</groupId>
+      <artifactId>cglib</artifactId>
+      <version>2.2</version>
+    </dependency>
   </dependencies>
   <build>
    <plugins>

Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/OlmCodeEnhancerMojo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/OlmCodeEnhancerMojo.java?rev=718200&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/OlmCodeEnhancerMojo.java
(added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/OlmCodeEnhancerMojo.java
Mon Nov 17 01:00:30 2008
@@ -0,0 +1,52 @@
+
+package org.apache.directory.server;
+
+import java.io.File;
+
+import org.apache.directory.olm.util.CodeEnhancer;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * 
+ * Enhances the implementation classes of Attribute and Entry interfaces using <i>CodeEnhancer</i>.
+ *
+ * @goal enhance
+ * @phase process-classes
+ * @requiresDependencyResolution compile
+ * 
+ * @see CodeEnhancer
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class OlmCodeEnhancerMojo extends AbstractMojo
+{
+
+    /**
+     * the directory in which the class files are present
+     * 
+     * @parameter expression="target/classes"
+     * @required
+     */
+    File classDir;
+
+    public void execute() throws MojoExecutionException, MojoFailureException
+    {
+        try
+        {
+            getLog().info( "Starting the CodeEnhancer Mojo" );
+
+            CodeEnhancer ce = new CodeEnhancer();
+            ce.enhanceAll( classDir.listFiles() );
+        }
+        catch( Exception e )
+        {
+            e.printStackTrace();
+            throw new MojoExecutionException( "Failed to enhance the class files", e );
+        }
+
+    }
+
+}

Added: directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/OlmSourceGenMojo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/OlmSourceGenMojo.java?rev=718200&view=auto
==============================================================================
--- directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/OlmSourceGenMojo.java
(added)
+++ directory/sandbox/kayyagari/apacheds-olm/src/main/java/org/apache/directory/server/OlmSourceGenMojo.java
Mon Nov 17 01:00:30 2008
@@ -0,0 +1,119 @@
+package org.apache.directory.server;
+
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.directory.olm.SourceGenerator;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+
+/**
+ * Goal which generates java source for representing the attributes and objectclasses present
in
+ * the LDAP schema files.
+ *
+ * @goal generate
+ * @description Generates java sources from schema files (present in OpenLDAP format)
+ * @phase generate-sources
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class OlmSourceGenMojo extends AbstractMojo
+{
+    /**
+     * The directory containing the OpenLDAP schema files.
+     * @parameter
+     * @required
+     */
+    private File[] schemaFiles;
+
+    /**
+     * The target directory into which the plugin generates schema java sources.
+     * @parameter expression="target/generated-sources"
+     */
+    private File outputDirectory;
+
+    /**
+     * The default package to use for generated sources.
+     * @parameter expression="org.apache.directory.olm"
+     */
+    private String defaultPackage;
+
+    /**
+     * suffix of the schema filename
+     * @parameter expression=".schema"
+     */
+    private String fileSuffix;
+
+    
+    private FileFilter schemaFileFilter = new FileFilter()
+    {
+
+        public boolean accept( File pathname )
+        {
+            if( pathname.isDirectory() )
+            {
+                return true;
+            }
+            
+            return pathname.getName().endsWith( fileSuffix );
+        }
+        
+    };
+    
+    
+    public void execute() throws MojoExecutionException
+    {
+        
+        try
+        {
+            getLog().info( "Starting execution of OlmPlugin" );
+
+            Properties syntaxes = new Properties();
+            String syntaxFileName = "syntax.properties";
+            getLog().info( "Loading syntax mappings from " + SourceGenerator.class.getClassLoader().getResource(
syntaxFileName ).getPath() );
+            syntaxes.load( SourceGenerator.class.getClassLoader().getResourceAsStream( syntaxFileName
) );
+            
+            SourceGenerator sg = new SourceGenerator( syntaxes, outputDirectory );
+            
+            getLog().info( "Setting the default package to - " + defaultPackage );
+ 
+            sg.setDefaultPackage( defaultPackage );
+            
+            Set<File> schemas = new HashSet<File>();
+            addSchemas( schemaFiles, schemas );
+            
+            sg.loadSchema( schemas );
+            sg.generateSource();
+            
+            getLog().info( "Excecution of OlmPlugin complete" );
+        }
+        catch( Exception e )
+        {
+            getLog().error( e );
+            throw new MojoExecutionException( "Failed to generate java source(s) from schema
file(s)", e );
+        }
+    }
+    
+    
+    private void addSchemas( File[] files, Set<File> schemas )
+    {
+        for( File f : files )
+        {
+            if( f.isDirectory() )
+            {
+                addSchemas( f.listFiles( schemaFileFilter ), schemas );
+            }
+            else if ( f.getName().endsWith( fileSuffix ) )
+            {
+                schemas.add( f );
+            }
+        }
+            
+    }
+}



Mime
View raw message