Author: mcconnell
Date: Sat Jun 12 09:28:55 2004
New Revision: 21148

Modified:
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Context.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Home.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/ArtifactTask.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/JUnitTestTask.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JarTask.java
   avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PluginTask.java
Log:
cleaning up property handling and adding support for disabling of unit test execution 
at system level

Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Context.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Context.java      
 (original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Context.java      
 Sat Jun 12 09:28:55 2004
@@ -20,6 +20,10 @@
 import java.io.File;

 import java.util.Hashtable;

 import java.util.Map;

+import java.text.SimpleDateFormat;

+import java.util.Date;

+import java.util.SimpleTimeZone;

+import java.util.TimeZone;

 

 import org.apache.tools.ant.BuildException;

 import org.apache.tools.ant.Task;

@@ -322,4 +326,17 @@
         }

         return new File( root, path );

     }

+

+    public static String getSignature()

+    {

+        return getSignature( new Date() );

+    }

+

+    public static String getSignature( Date date )

+    {

+        SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMdd.HHmmss" );

+        sdf.setTimeZone( TimeZone.getTimeZone( "UTC" ) );

+        return sdf.format( date );

+    }

+

 }


Modified: avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Home.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Home.java  
(original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/home/Home.java  Sat 
Jun 12 09:28:55 2004
@@ -69,8 +69,8 @@
     public static final String KEY = "project.home";

     public static final String HOME_KEY = "project.home";

 

-    private static final String USER_PROPERTIES = "user.properties";

-    private static final String BUILD_PROPERTIES = "build.properties";

+    public static final String AVALON_HOME_KEY = "avalon.home";

+    public static final String AVALON_REPOSITORY_KEY = "avalon.repository";

 

     //-------------------------------------------------------------

     // mutable state

@@ -78,12 +78,10 @@
 

     private boolean m_init = false;

 

-    private String m_id;

-

     private Home m_home;

     private Repository m_repository;

     private File m_system;

-    private File m_file;

+    private File m_index;

 

     private final Hashtable m_resources = new Hashtable();

     private BuildListener m_listener;

@@ -92,38 +90,33 @@
     // constructor

     //-------------------------------------------------------------

 

-    public Home( Project project, String id )

+    public Home( Project project, File index )

     {

         setProject( project );

-        m_id = id;

-        setupHome();

-    }

+        m_index = index;

+        log( "Building system definition." );

+        try

+        {

+            m_system = m_index.getParentFile();

 

-    //-------------------------------------------------------------

-    // Task

-    //-------------------------------------------------------------

+            Element root = ElementHelper.getRootElement( m_index );

+            final Element repo = ElementHelper.getChild( root, "repository" );

+            final Element resources = ElementHelper.getChild( root, "resources" );

+            final Element projects = ElementHelper.getChild( root, "projects" );

 

-    private String getHomeID()

-    {

-        if( null == m_id )

-        {

-            return KEY;

-        }

-        else

-        {

-            return m_id;

-        }

-    }

+            //

+            // construct the repository, build the definition of the available 

+            // resources and projects used within the system and associate a build

+            // listener

+            //

 

-    private Home getHome()

-    {

-        if( m_home != null )

-        {

-            return m_home;

+            m_repository = createRepository( repo );

+            buildResourceList( resources );

+            buildProjectList( projects );

         }

-        else

+        catch( Throwable e )

         {

-            return this;

+            throw new BuildException( e );

         }

     }

 

@@ -281,40 +274,9 @@
         return repository;

     }

 

-    private void setupHome()

-    {

-        Project project = getProject();

-        log( "Building system definition." );

-        try

-        {

-            File index = getIndexFile();

-            m_system = index.getParentFile();

-            setupProperties( project, m_system );

-            Element root = ElementHelper.getRootElement( index );

-            final Element repo = ElementHelper.getChild( root, "repository" );

-            final Element resources = ElementHelper.getChild( root, "resources" );

-            final Element projects = ElementHelper.getChild( root, "projects" );

-

-            //

-            // construct the repository, build the definition of the available 

-            // resources and projects used within the system and associate a build

-            // listener

-            //

-

-            m_repository = createRepository( repo );

-            buildResourceList( resources );

-            buildProjectList( projects );

-

-        }

-        catch( Throwable e )

-        {

-            throw new BuildException( e );

-        }

-    }

-

     private File getIndexFile()

     {

-        if( null != m_file ) return m_file;

+        if( null != m_index ) return m_index;

 

         String path = project.getProperty( KEY );

         if( null != path )

@@ -347,31 +309,6 @@
         }

     }

 

-    private void setupProperties( Project project, File dir )

-    {

-        setupUserProperties( project, dir );

-        setupBuildProperties( project, dir );

-    }

-

-    private void setupUserProperties( Project project, File basedir )

-    {

-        File user = Context.getFile( basedir, USER_PROPERTIES );

-        readProperties( project, user );

-    }

-

-    private void setupBuildProperties( Project project, File basedir )

-    {

-        File build = Context.getFile( basedir, BUILD_PROPERTIES );

-        readProperties( project, build );

-    }

-

-    private void readProperties( Project project, File file ) throws BuildException 

-    {

-        Property props = (Property) project.createTask( "property" );

-        props.setFile( file );

-        props.init();

-        props.execute();

-    }

 

    /*

     public void build( Definition definition )


Modified: 
avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/ArtifactTask.java
==============================================================================
--- 
avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/ArtifactTask.java 
(original)
+++ 
avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/ArtifactTask.java 
Sat Jun 12 09:28:55 2004
@@ -203,10 +203,8 @@
               + file;
             throw new BuildException( error );
         }
-        SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
-        sdf.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
         Date created = new Date( file.lastModified() );
-        return sdf.format( created );
+        return Context.getSignature( created );
     }
 
     private void writeClasspath( final Writer writer, final Definition def )

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    
 Sat Jun 12 09:28:55 2004
@@ -24,6 +24,7 @@
 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.Property;

 import org.apache.tools.ant.taskdefs.Jar;

 import org.apache.tools.ant.types.FileSet;

 import org.apache.tools.ant.types.Path;

@@ -41,71 +42,88 @@
 public class HomeTask extends ContextualTask

 {

     private static final String CACHE_DIR_KEY = "project.home.cache.dir";

+    private static final String USER_PROPERTIES = "user.properties";

+    private static final String BUILD_PROPERTIES = "build.properties";

 

     private static Home HOME;

 

-    private String m_id;

-

-   /**

-    * Set the home ref id to the system home.  If not supplied the 

-    * default system home 'project.home' id will apply.

-    *

-    * @param id a home id

-    */

-    public void setRefid( String id )

-    {

-        m_id = id;

-    }

-

     public void init() 

     {

         if( !isInitialized() )

         {

             super.init();

+            Project project = getProject();

+            File index = getIndexFile();

+            setupProperties( project, index.getParentFile() );

             if( null == HOME )

             {

-                HOME = new Home( getProject(), Home.KEY );

+                HOME = new Home( project, index );

             }

-            getProject().addReference( Home.KEY, HOME );

+            project.addReference( Home.KEY, HOME );

+            

             getProject().setNewProperty( 

               CACHE_DIR_KEY, 

               HOME.getRepository().getCacheDirectory().toString() );

         }

     }

 

-    private String getHomeID()

+    private void setupProperties( Project project, File dir )

     {

-        if( null == m_id )

-        {

-            return Home.KEY;

-        }

-        else

-        {

-            return m_id;

-        }

+        setupUserProperties( project, dir );

+        setupBuildProperties( project, dir );

     }

 

-    private Home getHomeFromReference( String id )

+    private void setupUserProperties( Project project, File dir )

     {

-        Object object = getProject().getReference( id );

-        if( null == object )

-        {

-            return null;

-        }

-        if( object instanceof Home )

+        File user = Context.getFile( dir, USER_PROPERTIES );

+        readProperties( project, user );

+    }

+

+    private void setupBuildProperties( Project project, File dir )

+    {

+        File build = Context.getFile( dir, BUILD_PROPERTIES );

+        readProperties( project, build );

+    }

+

+    private void readProperties( Project project, File file ) throws BuildException 

+    {

+        Property props = (Property) project.createTask( "property" );

+        props.init();

+        props.setFile( file );

+        props.execute();

+    }

+

+    private File getIndexFile()

+    {

+        String path = getProject().getProperty( Home.KEY );

+        if( null != path )

         {

-            return (Home) object;

+            File index = Context.getFile( project.getBaseDir(), path );

+            if( index.exists() )

+            {

+                if( index.isDirectory() )

+                {

+                    return new File( index, "index.xml" );

+                }

+                else

+                {

+                    return index;

+                }

+            }

+            else

+            {

+                final String error = 

+                  "Property value 'project.home' references a non-existant file: "

+                  + index;

+                throw new BuildException( error );

+            }

         }

         else

         {

             final String error = 

-              "System home ref id '" + id 

-              + "' declared or implied in task [" 

-              + getTaskName() 

-              + "] in the project ["

-              + getProject().getName() 

-              + "] references a object that is not a system home.";

+              "Cannot continue due to unresolved 'project.home' property.";

             throw new BuildException( error );

         }

     }

+

 }


Modified: 
avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java
==============================================================================
--- 
avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java   
     (original)
+++ 
avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/JUnitTestTask.java   
     Sat Jun 12 09:28:55 2004
@@ -47,6 +47,8 @@
  */

 public class JUnitTestTask extends SystemTask

 {

+    public static final String TEST_ENABLED_KEY = "project.test.enabled";

+

     public static final String TEST_KEY = "project.test";

     public static final String TEST_VALUE = "test";

 

@@ -100,6 +102,13 @@
     public void execute() throws BuildException 

     {

         Project project = getProject();

+

+        String enabled = project.getProperty( TEST_ENABLED_KEY );

+        if(( null != enabled ) && enabled.equals( "false" ))

+        {

+            return;

+        }

+

         File build = getContext().getBuildDirectory();

 

         String testPath = project.getProperty( TEST_SRC_KEY );


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     
 Sat Jun 12 09:28:55 2004
@@ -28,6 +28,8 @@
 import org.apache.tools.ant.taskdefs.Jar;

 import org.apache.tools.ant.taskdefs.Mkdir;

 import org.apache.tools.ant.taskdefs.Checksum;

+import org.apache.tools.ant.taskdefs.Manifest;

+import org.apache.tools.ant.taskdefs.ManifestException;

 import org.apache.tools.ant.taskdefs.Execute;

 import org.apache.tools.ant.types.FileSet;

 import org.apache.tools.ant.types.Path;

@@ -49,6 +51,8 @@
     public static final String JAR_EXT = "jar";

     public static final String ASC_EXT = "asc";

     public static final String GPG_EXE_KEY = "project.gpg.exe";

+    public static final String JAR_MAIN_KEY = "project.jar.main.class";

+    public static final String JAR_CLASSPATH_KEY = "project.jar.classpath";

     

     public void execute() throws BuildException 

     {

@@ -57,12 +61,13 @@
         File deliverables = 

           getContext().getDeliverablesDirectory();

 

+        Definition def = getHome().getDefinition( getKey() );

         File jarFile = getJarFile( deliverables );

         if( classes.exists() )

         {

             try

             {

-                boolean modified = jar( classes, jarFile );

+                boolean modified = jar( def, classes, jarFile );

                 if( modified )

                 {

                     checksum( jarFile );

@@ -100,7 +105,7 @@
         }

     }

 

-    private boolean jar( File classes, File jarFile )

+    private boolean jar( Definition def, File classes, File jarFile )

     {

         File dir = jarFile.getParentFile();

         mkDir( dir );

@@ -110,15 +115,69 @@
         {

             modified = jarFile.lastModified();

         }

+

  

         Jar jar = (Jar) getProject().createTask( "jar" );

         jar.setDestFile( jarFile );

         jar.setBasedir( classes );

         jar.setIndex( true );

+        addManifest( jar, def );

         jar.init();

         jar.execute();

 

         return jarFile.lastModified() > modified;

+    }

+

+    private void addManifest( Jar jar, Definition def )

+    {

+        try

+        {

+            Manifest manifest = new Manifest();

+            Manifest.Section main = manifest.getMainSection();

+

+            addAttribute( main, "Created-By", "Apache Avalon" );

+            addAttribute( main, "Built-By", System.getProperty( "user.name" ) );

+            addAttribute( main, "Extension-Name", def.getInfo().getName() );

+            addAttribute( main, "Specification-Vendor", "The Apache Software 
Foundation Avalon Project" );

+

+            if( null != def.getInfo().getVersion() )

+            {

+                addAttribute( main, "Specification-Version", 
def.getInfo().getVersion() );

+            }

+            else

+            {

+                addAttribute( main, "Specification-Version", "1.0" );

+            }

+            addAttribute( main, "Implementation-Vendor", "The Apache Software 
Foundation Avalon Project" );

+            addAttribute( main, "Implementation-Vendor-Id", "org.apache.avalon" );

+            addAttribute( main, "Implementation-Version", "123" );

+

+            String classpath = getProject().getProperty( JAR_CLASSPATH_KEY );

+            if( null != classpath )

+            {

+                addAttribute( main, "Class-Path", classpath );

+            }

+

+            String mainClass = getProject().getProperty( JAR_MAIN_KEY );

+            if( null != mainClass )

+            {

+                addAttribute( main, "Main-Class", mainClass );

+            }

+            

+            jar.addConfiguredManifest( manifest );

+        }

+        catch( Throwable e )

+        {

+            throw new BuildException( e );

+        }

+    }

+

+    private void addAttribute( 

+      Manifest.Section section, String name, String value )

+      throws ManifestException

+    {

+        Manifest.Attribute attribute = new Manifest.Attribute( name, value );

+        section.addConfiguredAttribute( attribute );

     }

 

     private void checksum( File jar )


Modified: 
avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PluginTask.java
==============================================================================
--- avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PluginTask.java  
 (original)
+++ avalon/trunk/tools/project/src/main/org/apache/avalon/tools/tasks/PluginTask.java  
 Sat Jun 12 09:28:55 2004
@@ -87,8 +87,6 @@
             Resource resource = new Resource( getHome(), info );

             File file = resource.getArtifact( project );

 

-            //File file = getHome().getRepository().getResource( project, resource );

-

             //

             // create a utility data object from the defintion

             //


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to