directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r359991 - /directory/trunk/apacheds-plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaToolMojo.java
Date Fri, 30 Dec 2005 05:23:50 GMT
Author: akarasulu
Date: Thu Dec 29 21:23:44 2005
New Revision: 359991

URL: http://svn.apache.org/viewcvs?rev=359991&view=rev
Log:
Added stale schema file check which compares the timestamp of the schema file
with the timestamp of the generated XXXSchema.java file in the target output
directory/package. 

Modified:
    directory/trunk/apacheds-plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaToolMojo.java

Modified: directory/trunk/apacheds-plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaToolMojo.java
URL: http://svn.apache.org/viewcvs/directory/trunk/apacheds-plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaToolMojo.java?rev=359991&r1=359990&r2=359991&view=diff
==============================================================================
--- directory/trunk/apacheds-plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaToolMojo.java
(original)
+++ directory/trunk/apacheds-plugin/src/main/java/org/apache/ldap/server/tools/schema/DirectorySchemaToolMojo.java
Thu Dec 29 21:23:44 2005
@@ -85,9 +85,6 @@
      */
     private boolean verboseOutput;
     
-    // Need to figure this out from the pom - maybe make it a parameter for mojoj and set
expression for pom element
-    private String javaSrcDir = "src/main/java";
-
     /**
      * @parameter expression="${project}"
      * @required
@@ -101,24 +98,21 @@
     }
 
 
-    private void generate( Schema schema ) throws Exception
+    private void generate( BootstrapSchema schema ) throws Exception
     {
-        BootstrapSchema bootstrapSchema = new AbstractBootstrapSchema( schema.getOwner(),

-            schema.getName(), schema.getPkg(), schema.getDependencies() ){};
-
         if ( schema == null )
         {
             throw new NullPointerException( "the schema property must be set" );
         }
 
-        String filePath = sourceDirectory + File.separator + schema.getName() + ".schema";
+        String filePath = sourceDirectory + File.separator + schema.getSchemaName() + ".schema";
         InputStream in = new FileInputStream( filePath );
         OpenLdapSchemaParser parser = new OpenLdapSchemaParser();
         parser.parse( in );
-        generateSchema( bootstrapSchema );
-        generateAttributeTypes( parser, bootstrapSchema );
-        generateObjectClasses( parser, bootstrapSchema );
-        generateRest( bootstrapSchema );
+        generateSchema( schema );
+        generateAttributeTypes( parser, schema );
+        generateObjectClasses( parser, schema );
+        generateRest( schema );
     }
 
 
@@ -325,7 +319,8 @@
     {
         // check to see if any of the classes are available in the java 
         // source directory, if so we return true
-        File defaultFile = new File( javaSrcDir + File.separator + getFilePath( defaultClass
) );
+        File defaultFile = new File( project.getBuild().getSourceDirectory() 
+            + File.separator + getFilePath( defaultClass ) );
         return defaultFile.exists();
     }
 
@@ -338,6 +333,22 @@
     }
     
     
+    private boolean isStale( BootstrapSchema schema )
+    {
+        String pkgPath = schema.getPackageName().replace( '.', File.separatorChar );
+        File dir = new File( outputDirectory, pkgPath );
+        File schemaClassFile = new File( dir, schema.getUnqualifiedClassName() + ".java"
);
+        
+        if ( ! schemaClassFile.exists() )
+        {
+            return true;
+        }
+        
+        File schemaFile = new File( sourceDirectory, schema.getSchemaName() + ".schema" );
+        return schemaFile.lastModified() > schemaClassFile.lastModified();
+    }
+    
+    
     public void execute() throws MojoExecutionException 
     {
         // Bypass if no schemas have yet been defined 
@@ -369,7 +380,7 @@
             {
                 schema.setOwner( defaultOwner );
             }
-        }        
+        } 
        
         // Report configuration if verbose output is enabled
         if ( verboseOutput )
@@ -388,7 +399,18 @@
         {
             try
             {
-                generate( schemas[ii] );
+                BootstrapSchema bootstrapSchema = new AbstractBootstrapSchema( schemas[ii].getOwner(),

+                    schemas[ii].getName(), schemas[ii].getPkg(), schemas[ii].getDependencies()
){};
+
+                if ( isStale( bootstrapSchema ) )
+                {
+                    getLog().info( "Generating " + schemas[ii].getName() + " schema." );
+                    generate( bootstrapSchema );
+                }
+                else
+                {
+                    getLog().info( schemas[ii].getName() + " schema is up to date." );
+                }
             }
             catch ( Exception e )
             {



Mime
View raw message