svn commit: rev 21512 - avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks

[email protected]
Newsgroups gmane.comp.jakarta.avalon.cvs
Message-ID <[email protected]>
Author: mcconnell
Date: Sun Jun 20 10:38:20 2004
New Revision: 21512

Modified:
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/HomeTask.java
Log:


Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/HomeTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/HomeTask.java	(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/HomeTask.java	Sun Jun 20 10:38:20 2004
@@ -19,6 +19,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.FileNotFoundException;
 
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.Project;
@@ -50,6 +51,13 @@
 
     private static Home HOME;
 
+    private String m_path;
+
+    public void setIndex( String path )
+    {
+        m_path = path;        
+    }
+
     public void init()
     {
         if( !isInitialized() )
@@ -77,7 +85,8 @@
         String system = project.getProperty( SYSTEM_KEY );
         if(( null == system ) || "".equals( system ))
         {
-            return index.getParentFile();
+            File systemHome = index.getParentFile();
+            return systemHome;
         }
         else
         {
@@ -120,35 +129,51 @@
 
     private File getIndexFile()
     {
-        String path = getProject().getProperty( Home.KEY );
-        if( null != path )
+        if( null != m_path )
+        {
+            File index = Context.getFile( project.getBaseDir(), m_path );
+            return resolve( index );
+        }
+        else
         {
-            File index = Context.getFile( project.getBaseDir(), path );
-            if( index.exists() )
+
+            //
+            // try to resolve using ${project.home}
+            //
+
+            String path = getProject().getProperty( Home.KEY );
+            if( null != path )
             {
-                if( index.isDirectory() )
-                {
-                    return new File( index, "index.xml" );
-                }
-                else
-                {
-                    return index;
-                }
+                File root = Context.getFile( project.getBaseDir(), path );
+                return resolve( root );
             }
             else
             {
                 final String error = 
-                  "Property value 'project.home' references a non-existant file: "
-                  + index;
+                  "Property value 'project.home' is not defined.";
                 throw new BuildException( error );
             }
         }
+    }
+
+    private File resolve( File index )
+    {
+        if( index.exists() )
+        {
+            if( index.isDirectory() )
+            {
+                return resolve( new File( index, "index.xml" ) );
+            }
+            else
+            {
+                return index;
+            }
+        }
         else
         {
-            final String error = 
-              "Cannot continue due to unresolved 'project.home' property.";
-            throw new BuildException( error );
+            FileNotFoundException e =
+              new FileNotFoundException( index.toString() );
+            throw new BuildException( e );
         }
     }
-
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.