avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant MetaGenerateTask.java
Date Sat, 16 Nov 2002 07:05:38 GMT
donaldp     2002/11/15 23:05:38

  Modified:    info/src/java/org/apache/avalon/framework/tools/ant
                        MetaGenerateTask.java
  Added:       info/lib qdox-20021116-patched.jar
  Removed:     info/lib qdox-20021112.jar
  Log:
  Update MetaGenerate task so that it only regenerates the descriptor if the descriptor is
older than source file. Using patched qdox that adds file attribute to JavaSource.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/info/lib/qdox-20021116-patched.jar
  
  	<<Binary file>>
  
  
  1.6       +70 -23    jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant/MetaGenerateTask.java
  
  Index: MetaGenerateTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant/MetaGenerateTask.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MetaGenerateTask.java	16 Nov 2002 06:44:47 -0000	1.5
  +++ MetaGenerateTask.java	16 Nov 2002 07:05:38 -0000	1.6
  @@ -57,6 +57,13 @@
       private boolean m_xmlOutput = true;
   
       /**
  +     * Variable that indicates whether the output
  +     * will be generated only when the source file is
  +     * newer than the destination file.
  +     */
  +    private boolean m_force = false;
  +
  +    /**
        * Set the desitation directory to generate output files to.
        *
        * @param destDir The destination directory
  @@ -77,11 +84,45 @@
       }
   
       /**
  +     * Set force to be true indicating that destination
  +     * files should always be regenerated.
  +     *
  +     * @param force the flag for forcing output
  +     */
  +    public void setForce( boolean force )
  +    {
  +        m_force = force;
  +    }
  +
  +    /**
        * Execute generator task.
        */
       public void execute()
           throws BuildException
       {
  +        validate();
  +
  +        final String message =
  +            "Writing Info descriptors as " + getOutputDescription() + ".";
  +        log( message );
  +
  +        super.execute();
  +
  +        try
  +        {
  +            writeInfoMetaData();
  +        }
  +        catch( final Exception e )
  +        {
  +            throw new BuildException( e.toString(), e );
  +        }
  +    }
  +
  +    /**
  +     * Validate that the parameters are valid.
  +     */
  +    private void validate()
  +    {
           if( null == m_destDir )
           {
               final String message = "DestDir not specified";
  @@ -98,27 +139,22 @@
               final String message = "DestDir could not be created.";
               throw new BuildException( message );
           }
  +    }
   
  -        String message = "Writing Info descriptors as ";
  +    /**
  +     * Return a description of output format to print as debug message.
  +     *
  +     * @return the output formats descriptive name
  +     */
  +    private String getOutputDescription()
  +    {
           if( m_xmlOutput )
           {
  -            message += "xml.";
  +            return "xml";
           }
           else
           {
  -            message += "serialized objects.";
  -        }
  -        log( message );
  -
  -        super.execute();
  -
  -        try
  -        {
  -            writeInfoMetaData();
  -        }
  -        catch( final Exception e )
  -        {
  -            throw new BuildException( e.toString(), e );
  +            return "serialized objects";
           }
       }
   
  @@ -154,6 +190,17 @@
               //then write it out
               if( null != info )
               {
  +                final String classname = javaClass.getFullyQualifiedName();
  +                final File source = javaClass.getParentSource().getFile();
  +                final File dest = getOutputFileForClass(classname);
  +                if( !m_force )
  +                {
  +                    if( dest.exists() &&
  +                        dest.lastModified() >= source.lastModified() );
  +                    {
  +                        continue;
  +                    }
  +                }
                   writeInfo( info );
               }
           }
  @@ -169,15 +216,15 @@
           throws IOException
       {
           final String fqn = info.getDescriptor().getImplementationKey();
  -        final String filename = getOutputFileForClass( fqn );
  -        final OutputStream outputStream = new FileOutputStream( filename );
  +        final File file = getOutputFileForClass( fqn );
  +        final OutputStream outputStream = new FileOutputStream( file );
           try
           {
               getInfoWriter().writeComponentInfo( info, outputStream );
           }
           catch( final Exception e )
           {
  -            log( "Error writing " + filename + ". Cause: " + e );
  +            log( "Error writing " + file + ". Cause: " + e );
           }
           finally
           {
  @@ -204,13 +251,13 @@
       }
   
       /**
  -     * Determine the base file for specified {@link ComponentInfo}.
  +     * Determine the file for specified {@link ComponentInfo}.
        *
        * @param classname the fully qualified name of file to generate
  -     * @return the base file for info
  +     * @return the file for info
        * @throws IOException if unable to determine base file
        */
  -    private String getOutputFileForClass( final String classname )
  +    private File getOutputFileForClass( final String classname )
           throws IOException
       {
           String filename =
  @@ -223,7 +270,7 @@
           {
               filename += ".ser";
           }
  -        return new File( m_destDir, filename ).getCanonicalPath();
  +        return new File( m_destDir, filename ).getCanonicalFile();
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message