avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject svn commit: rev 20249 - in avalon/trunk/tools/project/src: main/org/apache/avalon/tools/project main/org/apache/avalon/tools/tasks test/projects/gizmo
Date Sun, 23 May 2004 13:42:13 GMT
Author: mcconnell
Date: Sun May 23 06:42:13 2004
New Revision: 20249

Added:
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/DeliverableTask.java
Modified:
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/project/ProjectTask.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/HomeTask.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/InstallTask.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JarTask.java
   avalon/trunk/tools/project/src/test/projects/gizmo/   (props changed)
   avalon/trunk/tools/project/src/test/projects/gizmo/build.properties
   avalon/trunk/tools/project/src/test/projects/gizmo/build.xml
Log:


Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/project/ProjectTask.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/project/ProjectTask.java	(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/project/ProjectTask.java	Sun
May 23 06:42:13 2004
@@ -37,6 +37,7 @@
  */
 public class ProjectTask extends Sequential
 {
+    private static final String ANT_PROPERTIES = "ant.properties";
     private static final String BUILD_PROPERTIES = "build.properties";
 
     private File m_index;
@@ -93,10 +94,9 @@
         // make sure that the build.properties file is loaded
         //
 
-        Property props = (Property) getProject().createTask( "property" );
-        props.setFile( getPropertiesFile() );
-        props.init();
-        props.execute();
+        readProperties( 
+          new File( getProject().getBaseDir(), ANT_PROPERTIES ) );
+        readProperties( getPropertiesFile() );
 
         //
         // make sure we have a common defintion available
@@ -259,5 +259,13 @@
         {
             throw new BuildException( ioe );
         }
+    }
+
+    private void readProperties( File file ) throws BuildException 
+    {
+        Property props = (Property) getProject().createTask( "property" );
+        props.setFile( file );
+        props.init();
+        props.execute();
     }
 }

Added: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/DeliverableTask.java
==============================================================================
--- (empty file)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/DeliverableTask.java
Sun May 23 06:42:13 2004
@@ -0,0 +1,79 @@
+/* 
+ * Copyright 2004 Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.tools.tasks;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Copy;
+import org.apache.tools.ant.taskdefs.Jar;
+import org.apache.tools.ant.taskdefs.Checksum;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+
+import org.apache.avalon.tools.home.Home;
+import org.apache.avalon.tools.project.Definition;
+
+/**
+ * Load a goal. 
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
+ */
+public abstract class DeliverableTask extends HomeTask
+{
+    public static final String DELIVERABLES_KEY = "avalon.target.deliverables";
+    public static final String DELIVERABLES_VALUE = "deliverables";
+
+    public static File getTargetDeliverablesDirectory( Project project )
+    {
+        File target = PrepareTask.getTargetDirectory( project );
+        String deliverables = project.getProperty( DELIVERABLES_KEY );
+        return new File( target, deliverables );
+    }
+
+    public static File getTargetDeliverablesTypeDirectory( 
+      Project project, Definition def )
+    {
+        File deliverables = getTargetDeliverablesDirectory( project );
+        return new File( deliverables, def.getInfo().getType() + "s" );
+    }
+
+    public void init() throws BuildException 
+    {
+        super.init();
+        setProjectProperty( DELIVERABLES_KEY, DELIVERABLES_VALUE );
+        createDirectory( getTargetDeliverablesTypeDirectory() );
+    }
+
+    protected File getTargetDeliverablesDirectory()
+    {
+        return getTargetDeliverablesDirectory( getProject() );
+    }
+
+    protected File getTargetDeliverablesTypeDirectory()
+    {
+        return getTargetDeliverablesTypeDirectory( 
+          getProject(), getDefinition() );
+    }
+
+}

Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/HomeTask.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/HomeTask.java	(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/HomeTask.java	Sun May
23 06:42:13 2004
@@ -23,13 +23,16 @@
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.taskdefs.Property;
+import org.apache.tools.ant.taskdefs.Delete;
 import org.apache.tools.ant.taskdefs.Mkdir;
 
 import org.apache.avalon.tools.home.Home;
 import org.apache.avalon.tools.project.Definition;
 
 /**
- * Load a goal. 
+ * Abstract task that provides convinience opperations including 
+ * access to the current project defintion and the system home 
+ * model and repository.  
  *
  * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
  * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
@@ -46,17 +49,17 @@
         m_definition = m_home.getDefinition( key );
     }
 
-    public Home getHome()
+    protected Home getHome()
     {
         return m_home;
     }
 
-    public Definition getDefinition()
+    protected Definition getDefinition()
     {
         return m_definition;
     }
 
-    public void setProjectProperty( String key, String value )
+    protected void setProjectProperty( String key, String value )
     {
         Property props = (Property) getProject().createTask( "property" );
         props.setName( key );
@@ -65,11 +68,26 @@
         props.execute();
     }
 
-    public void createDirectory( File dir )
+    protected void createDirectory( File dir )
     {
         Mkdir mkdir = (Mkdir) getProject().createTask( "mkdir" );
         mkdir.setDir( dir );
         mkdir.init();
         mkdir.execute();
+    }
+
+    protected void delete( File file )
+    {
+        delete( file, true );
+    }
+
+    protected void delete( File file, boolean verbose )
+    {
+        Delete delete = (Delete) getProject().createTask( "delete" );
+        delete.setFile( file );
+        delete.setVerbose( verbose );
+        delete.setQuiet( true );
+        delete.init();
+        delete.execute();
     }
 }

Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/InstallTask.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/InstallTask.java	(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/InstallTask.java	Sun
May 23 06:42:13 2004
@@ -36,36 +36,30 @@
  * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
  * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
  */
-public class InstallTask extends HomeTask
+public class InstallTask extends DeliverableTask
 {
     public void execute() throws BuildException 
     {
-        String filename = JarTask.getJarFilename( getDefinition() );
-        File jar = JarTask.getJarFile( getProject(), getDefinition() );
-        if( jar.exists() )
+        File deliverables = getTargetDeliverablesDirectory();
+        if( deliverables.exists() )
         {
-            install();
+            install( deliverables );
         }
     }
 
-    private void install()
+    private void install( File deliverables )
     {
         FileSet fileset = new FileSet();
-        fileset.setDir( PrepareTask.getTargetDirectory( getProject() ) );
-        String filename = JarTask.getJarFilename( getDefinition() );
-        fileset.createInclude().setName( filename );
-        fileset.createInclude().setName( filename + "." + JarTask.MD5_EXT );
+        fileset.setDir( deliverables );
+        fileset.createInclude().setName( "**/*" );
 
         File cache = getHome().getRepository().getCacheDirectory();
         String group = getDefinition().getInfo().getGroup();
-        String type = getDefinition().getInfo().getType();
-        File repoGroup = new File( cache, group );
-        File repoType = new File( repoGroup, type + "s" );
+        File target = new File( cache, group );
 
         Copy copy = (Copy) getProject().createTask( "copy" );
+        copy.setTodir( target );
         copy.addFileset( fileset );
-        copy.setTodir( repoType );
-
         copy.init();
         copy.execute();
     }

Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JarTask.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JarTask.java	(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JarTask.java	Sun May
23 06:42:13 2004
@@ -24,8 +24,10 @@
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.taskdefs.Copy;
+import org.apache.tools.ant.taskdefs.Delete;
 import org.apache.tools.ant.taskdefs.Jar;
 import org.apache.tools.ant.taskdefs.Checksum;
+import org.apache.tools.ant.taskdefs.Execute;
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.Path;
 
@@ -38,10 +40,11 @@
  * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
  * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
  */
-public class JarTask extends HomeTask
+public class JarTask extends DeliverableTask
 {
     public static final String MD5_EXT = "md5";
     public static final String JAR_EXT = "jar";
+    public static final String ASC_EXT = "asc";
 
     public static String getJarFilename( Definition def )
     {
@@ -58,9 +61,9 @@
 
     public static File getJarFile( Project project, Definition def )
     {
-        File target = PrepareTask.getTargetDirectory( project );
+        File type = getTargetDeliverablesTypeDirectory( project, def );
         String filename = getJarFilename( def );
-        return new File( target, filename );
+        return new File( type, filename );
     }
 
     public void execute() throws BuildException 
@@ -70,8 +73,16 @@
         File jarFile = getJarFile();
         if( classes.exists() )
         {
-            jar( classes, jarFile );
-            checksum( jarFile );
+            try
+            {
+                boolean modified = jar( classes, jarFile );
+                checksum( jarFile, modified );
+                asc( jarFile, modified );
+            }
+            catch( IOException ioe )
+            {
+                throw new BuildException( ioe );
+            }
         }
     }
 
@@ -80,21 +91,59 @@
         return getJarFile( getProject(), getDefinition() );
     }
 
-    private void jar( File classes, File jarFile )
+    private boolean jar( File classes, File jarFile )
     {
+        long modified = -1;
+        if( jarFile.exists() )
+        {
+            modified = jarFile.lastModified();
+        }
+ 
         Jar jar = (Jar) getProject().createTask( "jar" );
         jar.setDestFile( jarFile );
         jar.setBasedir( classes );
+        jar.setIndex( true );
         jar.init();
         jar.execute();
+
+        return jarFile.lastModified() > modified;
     }
 
-    private void checksum( File jarFile )
+    private void checksum( File jar, boolean modified )
     {
+        if( modified )
+        {
+            log( "Creating md5 checksum" );
+        }
+
         Checksum checksum = (Checksum) getProject().createTask( "checksum" );
-        checksum.setFile( jarFile );
+        checksum.setFile( jar );
         checksum.setFileext( "." + MD5_EXT );
         checksum.init();
         checksum.execute();
+    }
+
+    private void asc( File jar, boolean modified ) throws IOException
+    {
+        File md5 = new File( jar.toString() + "." + ASC_EXT );
+        if( modified )
+        {
+            if( md5.exists() )
+            {
+                md5.delete();
+            }
+
+            String gpg = getProject().getProperty( "avalon.gpg.exe" );
+            if( null != gpg )
+            {
+                log( "Creating asc signature" );
+                Execute execute = new Execute();
+                execute.setCommandline( 
+                  new String[]{ gpg, "-a", "-b", jar.toString() } );
+                execute.setWorkingDirectory( getProject().getBaseDir() );
+                execute.setSpawn( true );
+                execute.execute();
+            }
+        }
     }
 }

Modified: avalon/trunk/tools/project/src/test/projects/gizmo/build.properties
==============================================================================
--- avalon/trunk/tools/project/src/test/projects/gizmo/build.properties	(original)
+++ avalon/trunk/tools/project/src/test/projects/gizmo/build.properties	Sun May 23 06:42:13
2004
@@ -1 +1 @@
-#avalon.target = targetx
\ No newline at end of file
+#avalon.target = targetx

Modified: avalon/trunk/tools/project/src/test/projects/gizmo/build.xml
==============================================================================
--- avalon/trunk/tools/project/src/test/projects/gizmo/build.xml	(original)
+++ avalon/trunk/tools/project/src/test/projects/gizmo/build.xml	Sun May 23 06:42:13 2004
@@ -1,12 +1,17 @@
 
-<project name="gizmo" default="" basedir="." 
+<project name="gizmo" default="install" basedir="." 
     xmlns:x="antlib:org.apache.avalon.tools"> 
 
-  <x:project index="../../index.xml">
+  <x:project index="../../index.xml"/>
+
+  <target name="build">
     <x:prepare/>
     <x:javac/>
     <x:jar/>
+  </target>
+
+  <target name="install" depends="build">
     <x:install/>
-  </x:project>
+  </target>
 
 </project>

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


Mime
View raw message