You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wagon-commits@maven.apache.org by mi...@apache.org on 2004/06/19 16:16:21 UTC

cvs commit: maven-wagon/wagon-api/src/test/java/org/apache/maven/wagon PathUtilsTest.java

michal      2004/06/19 07:16:21

  Modified:    wagon-api/src/main/java/org/apache/maven/wagon/providers/file
                        FileWagon.java
               wagon-api/src/main/java/org/apache/maven/wagon
                        WagonTestCase.java WagonUtils.java
               wagon-api/src/test/java/org/apache/maven/wagon
                        PathUtilsTest.java
  Log:
  added utility method for executing "put" operation for entire directory. This will be useful for deployment of websites
  
  Revision  Changes    Path
  1.7       +6 -3      maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/providers/file/FileWagon.java
  
  Index: FileWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/providers/file/FileWagon.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FileWagon.java	9 Jun 2004 19:36:10 -0000	1.6
  +++ FileWagon.java	19 Jun 2004 14:16:21 -0000	1.7
  @@ -66,9 +66,12 @@
          
           File f = new File( getRepository().getBasedir(), resource );
   
  -        if ( f.getParentFile() != null && !f.getParentFile().exists() )
  +        File dir = f.getParentFile();
  +
  +        if ( dir != null && !dir.exists() )
           {
  -            if ( !f.getParentFile().mkdirs() )
  +
  +            if ( !dir.mkdirs() )
               {
                   String msg = "Some of the requied directories do not exist and could not be create. " +
                   		"Requested path:  "  + f.getAbsolutePath();
  
  
  
  1.9       +3 -1      maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/WagonTestCase.java
  
  Index: WagonTestCase.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/WagonTestCase.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- WagonTestCase.java	9 Jun 2004 03:11:22 -0000	1.8
  +++ WagonTestCase.java	19 Jun 2004 14:16:21 -0000	1.9
  @@ -178,7 +178,9 @@
       private void message( String message )
       {
           System.out.println( "---------------------------------------------------------------------------------------------------------" );
  +
           System.out.println( message );
  +
           System.out.println( "---------------------------------------------------------------------------------------------------------" );
       }
   
  
  
  
  1.4       +65 -3     maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/WagonUtils.java
  
  Index: WagonUtils.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/main/java/org/apache/maven/wagon/WagonUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WagonUtils.java	3 Jun 2004 18:27:00 -0000	1.3
  +++ WagonUtils.java	19 Jun 2004 14:16:21 -0000	1.4
  @@ -22,6 +22,8 @@
   
   import java.io.File;
   import java.io.IOException;
  +import java.util.LinkedList;
  +import java.util.List;
   
   
   /**
  @@ -94,6 +96,66 @@
           
            
       }
  -        
  -    
  +
  +
  +    public static void putDirectory( File dir, Wagon wagon,  boolean includeBasdir )
  +            throws ResourceDoesNotExistException, TransferFailedException, AuthorizationException
  +    {
  +
  +        LinkedList queue = new LinkedList();
  +
  +        if ( includeBasdir )
  +        {
  +            queue.add( dir.getName() );
  +        }
  +        else
  +        {
  +           queue.add( "" );
  +        }
  +
  +        while ( !queue.isEmpty() )
  +        {
  +
  +            String path = ( String ) queue.removeFirst();
  +
  +
  +            File currentDir = new File ( dir, path);
  +
  +            System.out.println( "Processing dir: " + currentDir );
  +
  +            File[] files = currentDir.listFiles();
  +
  +            for (int i = 0; i < files.length; i++)
  +            {
  +                File file = files[i];
  +
  +                System.out.println( "Processing file: " + file );
  +
  +                String resource;
  +
  +                if ( path.length() > 0 )
  +                {
  +                    resource = path + "/"  + file.getName();
  +                }
  +                else
  +                {
  +                    resource = file.getName();
  +
  +                }
  +
  +                if ( file.isDirectory() )
  +                {
  +                    queue.add( resource );
  +                }
  +                else
  +                {
  +                    wagon.put(  file, resource );
  +                }
  +
  +            }
  +
  +        }
  +
  +    }
  +
   }
  
  
  
  1.3       +11 -1     maven-wagon/wagon-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java
  
  Index: PathUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PathUtilsTest.java	3 Jun 2004 18:27:01 -0000	1.2
  +++ PathUtilsTest.java	19 Jun 2004 14:16:21 -0000	1.3
  @@ -28,24 +28,33 @@
       public void testFilenameResolving()
       {
           assertEquals( "filename", PathUtils.filename( "dir/filename" ) );
  +
           assertEquals( "filename", PathUtils.filename( "filename" ) );
  +
           assertEquals( "filename", PathUtils.filename( "dir1/dir2/filename" ) );
       }
   
       public void testDirResolving()
       {
           assertEquals( "dir", PathUtils.dirname( "dir/filename" ) );
  +
           assertEquals( "", PathUtils.dirname( "filename" ) );
  +
           assertEquals( "dir1/dir2", PathUtils.dirname( "dir1/dir2/filename" ) );
       }
   
       public void testDirSpliting()
       {
           final String path = "a/b/c";
  +
           final String[] dirs = PathUtils.dirnames( path );
  +
           assertNotNull( dirs );
  +
           assertEquals( 2, dirs.length );
  +
           assertEquals( "a", dirs[0] );
  +
           assertEquals( "b", dirs[1] );
   
       }
  @@ -55,6 +64,7 @@
           assertEquals(
                   "www.codehaus.org",
                   PathUtils.host( "http://www.codehaus.org" ) );
  +
           assertEquals( "localhost", PathUtils.host( null ) );
   
       }
  
  
  

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