jvanzyl     2003/11/24 12:07:30

  Modified:    src/bootstrap/org/apache/maven BootstrapTask.java
  Log:
  o formatting
  
  Revision  Changes    Path
  1.18      +142 -135  maven/src/bootstrap/org/apache/maven/BootstrapTask.java
  
  Index: BootstrapTask.java
  ===================================================================
  RCS file: /home/cvs/maven/src/bootstrap/org/apache/maven/BootstrapTask.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- BootstrapTask.java        4 Sep 2003 14:36:51 -0000       1.17
  +++ BootstrapTask.java        24 Nov 2003 20:07:30 -0000      1.18
  @@ -55,11 +55,12 @@
    *
    * ====================================================================
    */
  +
   import java.io.File;
   import java.io.FileWriter;
   import java.io.IOException;
   import java.io.PrintWriter;
  -  
  +
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.List;
  @@ -79,7 +80,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    */
   public class BootstrapTask
  -     extends Task
  +    extends Task
   {
       private BootstrapPomParser bootstrapPomParser;
       private File projectDescriptor;
  @@ -91,45 +92,45 @@
        * Whether verbose logging should be performed
        */
       private boolean verbose = false;
  -    
  +
       /**
        * whether the remote timestamp should be placed on the download file
        */
       private boolean useTimestamp = true;
  -    
  +
       /**
        * whether the task should fail on a HTTP error
        */
       private boolean ignoreErrors = true;
  -    
  +
       /**
        * A URL that the files are relative to
        */
       private String baseUrl;
  -    
  +
       /** whether bootstrap is online */
       private String online;
  -    
  +
       /**
        * Proxy host
        */
       private String proxyHost;
  -    
  +
       /**
        * Proxy port
        */
       private String proxyPort;
  -    
  +
       /**
        * Proxy userName
        */
       private String proxyUserName;
  -    
  +
       /**
        * Proxy password
        */
       private String proxyPassword;
  -    
  +
       /** list of files to process */
       private List files;
   
  @@ -140,7 +141,8 @@
        * Get the directory to put the copy script into.
        * @return the directory
        */
  -    public File getCopyScriptDir() {
  +    public File getCopyScriptDir()
  +    {
           return copyScriptDir;
       }
   
  @@ -148,14 +150,15 @@
        * Set the directory to put the copy script into.
        * @param copyScriptDir the copy script directory
        */
  -    public void setCopyScriptDir(File copyScriptDir) {
  +    public void setCopyScriptDir( File copyScriptDir )
  +    {
           this.copyScriptDir = copyScriptDir;
       }
   
       /**
        * Sets the projectDescriptor attribute of the BootstrapTask object
        */
  -    public void setProjectDescriptor(File projectDescriptor)
  +    public void setProjectDescriptor( File projectDescriptor )
       {
           this.projectDescriptor = projectDescriptor;
       }
  @@ -171,7 +174,7 @@
       /**
        * Sets the basedir attribute of the BootstrapTask object
        */
  -    public void setMavenLocalRepo(File mavenLocalRepo)
  +    public void setMavenLocalRepo( File mavenLocalRepo )
       {
           this.mavenLocalRepo = mavenLocalRepo;
       }
  @@ -189,7 +192,7 @@
       /**
        * Sets the files attribute of the BootstrapTask object
        */
  -    public void setFiles(List files)
  +    public void setFiles( List files )
       {
           this.files = files;
       }
  @@ -207,7 +210,7 @@
        *
        * @param baseUrl A URL that the files are relative to
        */
  -    public void setBaseUrl(String baseUrl)
  +    public void setBaseUrl( String baseUrl )
       {
           this.baseUrl = baseUrl;
       }
  @@ -217,12 +220,12 @@
        *
        * @param proxyHost the host name of the proxy
        */
  -    public void setProxyHost(String proxyHost)
  +    public void setProxyHost( String proxyHost )
       {
  -        if (validProperty(proxyHost))
  +        if ( validProperty( proxyHost ) )
           {
               this.proxyHost = proxyHost;
  -        }            
  +        }
       }
   
       /**
  @@ -230,12 +233,12 @@
        *
        * @param proxyPort the port used to access the proxy, e.g. <code>8080</code>
        */
  -    public void setProxyPort(String proxyPort)
  +    public void setProxyPort( String proxyPort )
       {
  -        if (validProperty(proxyPort))
  +        if ( validProperty( proxyPort ) )
           {
               this.proxyPort = proxyPort;
  -        }            
  +        }
       }
   
       /**
  @@ -243,12 +246,12 @@
        *
        * @param proxyUserName the login used to access the proxy
        */
  -    public void setProxyUserName(String proxyUserName)
  -    {   
  -        if (validProperty(proxyUserName))
  +    public void setProxyUserName( String proxyUserName )
  +    {
  +        if ( validProperty( proxyUserName ) )
           {
               this.proxyUserName = proxyUserName;
  -        }            
  +        }
       }
   
       /**
  @@ -256,12 +259,12 @@
        *
        * @param proxyPassword the password used to access the proxy, e.g. 
<code>8080</code>
        */
  -    public void setProxyPassword(String proxyPassword)
  +    public void setProxyPassword( String proxyPassword )
       {
  -        if (validProperty(proxyPassword))
  +        if ( validProperty( proxyPassword ) )
           {
               this.proxyPassword = proxyPassword;
  -        }            
  +        }
       }
   
       /**
  @@ -269,7 +272,7 @@
        *
        * @param v if "true" then be verbose
        */
  -    public void setVerbose(boolean v)
  +    public void setVerbose( boolean v )
       {
           verbose = v;
       }
  @@ -279,7 +282,7 @@
        *
        * @param v if "true" then don't report download errors up to ant
        */
  -    public void setIgnoreErrors(boolean v)
  +    public void setIgnoreErrors( boolean v )
       {
           ignoreErrors = v;
       }
  @@ -299,7 +302,7 @@
        *
        * @param v "true" to enable file time fetching
        */
  -    public void setUseTimestamp(boolean v)
  +    public void setUseTimestamp( boolean v )
       {
           useTimestamp = v;
       }
  @@ -312,47 +315,50 @@
       public void execute()
           throws BuildException
       {
  -        if (baseUrl == null)
  +        if ( baseUrl == null )
           {
  -            throw new BuildException("baseUrl attribute is required");
  +            throw new BuildException( "baseUrl attribute is required" );
           }
   
  -        if (mavenLocalRepo == null)
  +        if ( mavenLocalRepo == null )
           {
  -            throw new BuildException("mavenLocalRepo attribute is required");
  +            throw new BuildException( "mavenLocalRepo attribute is required" );
           }
   
  -        if (mavenLocalRepo.exists() && !mavenLocalRepo.canWrite())
  +        if ( mavenLocalRepo.exists() && !mavenLocalRepo.canWrite() )
           {
  -            throw new BuildException("Can't write to "
  -                 + mavenLocalRepo.getAbsolutePath());
  +            throw new BuildException( "Can't write to "
  +                                      + mavenLocalRepo.getAbsolutePath() );
           }
  -    
  +
           bootstrapPomParser = new BootstrapPomParser();
  -        bootstrapPomParser.parse(getProjectDescriptor());
  +        bootstrapPomParser.parse( getProjectDescriptor() );
           dependencies = bootstrapPomParser.getDependencies();
   
           List list = new ArrayList();
  -        for (Iterator i = dependencies.iterator(); i.hasNext(); )
  +        for ( Iterator i = dependencies.iterator(); i.hasNext(); )
           {
               Dependency d = (Dependency) i.next();
  -            list.add(getArtifactPath(d, "/"));
  +            list.add( getArtifactPath( d, "/" ) );
           }
  -        
  -        setFiles(list);
  +
  +        setFiles( list );
           // if offline is not set, download dependencies
  -        if ( "-o".equals(getOnline()) == false )
  +        if ( "-o".equals( getOnline() ) == false )
           {
               downloadDependencies();
           }
  -        
  -        createClasspathReference(project, "bootstrap-classpath", list, 
mavenLocalRepo);
  -        createPatternSetReference(project, "bootstrap-patternset", list);
  -        try {
  +
  +        createClasspathReference( project, "bootstrap-classpath", list, 
mavenLocalRepo );
  +        createPatternSetReference( project, "bootstrap-patternset", list );
  +        try
  +        {
               createDependencyCopyScript();
  -        } catch (IOException e) {
  +        }
  +        catch ( IOException e )
  +        {
               // ignore this - if the script is missing the maven script will work as 
before
  -            log("Problem writing copy script: " + e, Project.MSG_WARN);
  +            log( "Problem writing copy script: " + e, Project.MSG_WARN );
           }
       }
   
  @@ -362,59 +368,59 @@
        * @todo this should be generated through some sort of template.
        * @throws IOException if there is a problem writing the script file
        */
  -    private void createDependencyCopyScript() throws IOException 
  +    private void createDependencyCopyScript() throws IOException
       {
  -        if (copyScriptDir == null) 
  +        if ( copyScriptDir == null )
           {
  -            log("Not making the copy script - no directory given to bootstrap 
task", Project.MSG_DEBUG);
  -            return;            
  +            log( "Not making the copy script - no directory given to bootstrap 
task", Project.MSG_DEBUG );
  +            return;
           }
  -        PrintWriter shell = new PrintWriter(new FileWriter(new File(copyScriptDir, 
"install_repo.sh")));
  -        shell.print("#!/bin/sh\n");
  -        shell.print("REPO_DIR=$1\n");
  -        shell.print("if [ -z \"$REPO_DIR\" ]; then echo \"usage: $0 [repository 
directory]\"; exit; fi\n");
  -        shell.print("if [ -z \"$MAVEN_HOME\" ]; then echo \"MAVEN_HOME must be 
set\"; exit; fi\n");
  -        PrintWriter batch = new PrintWriter(new FileWriter(new File(copyScriptDir, 
"install_repo.bat")));
  -        batch.print("@ECHO OFF\r\n");
  -        batch.print("if \"%1\"==\"\" goto usage\r\n");
  -        batch.print("set REPO_DIR=%1\r\n");
  -        batch.print("if \"%MAVEN_HOME%\"==\"\" goto MHusage\r\n");
  -        for (Iterator i = dependencies.iterator(); i.hasNext(); ) 
  +        PrintWriter shell = new PrintWriter( new FileWriter( new File( 
copyScriptDir, "install_repo.sh" ) ) );
  +        shell.print( "#!/bin/sh\n" );
  +        shell.print( "REPO_DIR=$1\n" );
  +        shell.print( "if [ -z \"$REPO_DIR\" ]; then echo \"usage: $0 [repository 
directory]\"; exit; fi\n" );
  +        shell.print( "if [ -z \"$MAVEN_HOME\" ]; then echo \"MAVEN_HOME must be 
set\"; exit; fi\n" );
  +        PrintWriter batch = new PrintWriter( new FileWriter( new File( 
copyScriptDir, "install_repo.bat" ) ) );
  +        batch.print( "@ECHO OFF\r\n" );
  +        batch.print( "if \"%1\"==\"\" goto usage\r\n" );
  +        batch.print( "set REPO_DIR=%1\r\n" );
  +        batch.print( "if \"%MAVEN_HOME%\"==\"\" goto MHusage\r\n" );
  +        for ( Iterator i = dependencies.iterator(); i.hasNext(); )
           {
               Dependency d = (Dependency) i.next();
  -            String path = getArtifactPath(d, "/");
  +            String path = getArtifactPath( d, "/" );
               shell.print(
                   "if [ ! -f $REPO_DIR/"
  -                    + path
  -                    + " ]; then mkdir -p $REPO_DIR/" 
  -                    + d.getArtifactDirectory() 
  -                    + "/jars; cp $MAVEN_HOME/lib/");
  -            if (d.getArtifactDirectory().equals("xml-apis") ||
  -                d.getArtifactDirectory().equals("xerces"))
  +                + path
  +                + " ]; then mkdir -p $REPO_DIR/"
  +                + d.getArtifactDirectory()
  +                + "/jars; cp $MAVEN_HOME/lib/" );
  +            if ( d.getArtifactDirectory().equals( "xml-apis" ) ||
  +                d.getArtifactDirectory().equals( "xerces" ) )
               {
  -                shell.print("endorsed/");
  +                shell.print( "endorsed/" );
               }
  -            shell.print(d.getArtifact() + " $REPO_DIR/" + path + "; fi\n");
  +            shell.print( d.getArtifact() + " $REPO_DIR/" + path + "; fi\n" );
               path = "%REPO_DIR%\\" + d.getArtifactDirectory() + "\\jars";
  -            batch.print("if not exist " + path + " mkdir " + path + "\r\n");
  -            path = getArtifactPath(d, "\\");
  +            batch.print( "if not exist " + path + " mkdir " + path + "\r\n" );
  +            path = getArtifactPath( d, "\\" );
               batch.print(
                   "if not exist \"%REPO_DIR%\\"
  -                    + path
  -                    + "\" copy \"%MAVEN_HOME%\\lib\\");
  -            if (d.getArtifactDirectory().equals("xml-apis") ||
  -                d.getArtifactDirectory().equals("xerces"))
  +                + path
  +                + "\" copy \"%MAVEN_HOME%\\lib\\" );
  +            if ( d.getArtifactDirectory().equals( "xml-apis" ) ||
  +                d.getArtifactDirectory().equals( "xerces" ) )
               {
  -                batch.print("endorsed\\");
  +                batch.print( "endorsed\\" );
               }
  -            batch.print(d.getArtifact() + "\" \"%REPO_DIR%\\" + path + "\"\r\n");
  +            batch.print( d.getArtifact() + "\" \"%REPO_DIR%\\" + path + "\"\r\n" );
           }
  -        batch.print("goto end\r\n");
  -        batch.print(":MHusage\r\n");
  -        batch.print("echo MAVEN_HOME must be set\r\n");
  -        batch.print(":usage\r\n");
  -        batch.print("echo usage: %0 [repository directory]\r\n");
  -        batch.print(":end\r\n");
  +        batch.print( "goto end\r\n" );
  +        batch.print( ":MHusage\r\n" );
  +        batch.print( "echo MAVEN_HOME must be set\r\n" );
  +        batch.print( ":usage\r\n" );
  +        batch.print( "echo usage: %0 [repository directory]\r\n" );
  +        batch.print( ":end\r\n" );
           shell.close();
           batch.close();
       }
  @@ -424,7 +430,7 @@
        * @param d the dependency
        * @return the path to the dependency
        */
  -    private String getArtifactPath(Dependency d, String pathSeparator) 
  +    private String getArtifactPath( Dependency d, String pathSeparator )
       {
           return d.getArtifactDirectory() + pathSeparator + "jars" + pathSeparator + 
d.getArtifact();
       }
  @@ -437,17 +443,17 @@
       public void downloadDependencies()
           throws BuildException
       {
  -        for (Iterator j = getFiles().iterator(); j.hasNext(); )
  +        for ( Iterator j = getFiles().iterator(); j.hasNext(); )
           {
               try
               {
                   String file = (String) j.next();
  -                File destinationFile = new File(mavenLocalRepo, file);
  +                File destinationFile = new File( mavenLocalRepo, file );
   
                   // The directory structure for this project may
                   // not exists so create it if missing.
                   File directory = destinationFile.getParentFile();
  -                if (directory.exists() == false)
  +                if ( directory.exists() == false )
                   {
                       directory.mkdirs();
                   }
  @@ -459,30 +465,30 @@
                   {
                       try
                       {
  -                        HttpUtils.getFile( baseUrl + file, 
  -                                           destinationFile, 
  -                                           ignoreErrors, 
  -                                           useTimestamp, 
  -                                           proxyHost, 
  -                                           proxyPort, 
  +                        HttpUtils.getFile( baseUrl + file,
  +                                           destinationFile,
  +                                           ignoreErrors,
  +                                           useTimestamp,
  +                                           proxyHost,
  +                                           proxyPort,
                                              proxyUserName,
  -                                           proxyPassword);
  +                                           proxyPassword );
                           break;
                       }
  -                    catch (Exception e)
  +                    catch ( Exception e )
                       {
                           numRetries--;
                           continue;
                       }
                   }
  -                if (!destinationFile.exists())
  +                if ( !destinationFile.exists() )
                   {
  -                    throw new Exception("Failed to download " + baseUrl + file);
  +                    throw new Exception( "Failed to download " + baseUrl + file );
                   }
               }
  -            catch (Exception e)
  +            catch ( Exception e )
               {
  -                throw new BuildException(e);
  +                throw new BuildException( e );
               }
           }
       }
  @@ -493,26 +499,26 @@
        * to <code>baseDir</code>
        * @param project the Ant project to create the reference in
        * @param reference the name of the reference to create
  -     * @param list the list of jar files to append to the new classpath 
  +     * @param list the list of jar files to append to the new classpath
        * reference
        * @param baseDir the directory the specified jars are relative to
        */
  -    public static void createClasspathReference(Project project, 
  -                                                String reference,
  -                                                List list,
  -                                                File baseDir)
  +    public static void createClasspathReference( Project project,
  +                                                 String reference,
  +                                                 List list,
  +                                                 File baseDir )
       {
  -        Path classpath = new Path(project);
  +        Path classpath = new Path( project );
   
  -        for (Iterator i = list.iterator(); i.hasNext();)
  +        for ( Iterator i = list.iterator(); i.hasNext(); )
           {
               String jar = (String) i.next();
  -            Path p = new Path(project);
  -            p.setPath(new File(baseDir, jar).getAbsolutePath());
  -            classpath.append(p);
  +            Path p = new Path( project );
  +            p.setPath( new File( baseDir, jar ).getAbsolutePath() );
  +            classpath.append( p );
           }
   
  -        project.addReference(reference, classpath);
  +        project.addReference( reference, classpath );
       }
   
       /**
  @@ -524,49 +530,50 @@
        * @param list the list of lines (Strings) specifying include=, exclude= or
        *  a file name
        */
  -    public static void createPatternSetReference(Project project, 
  -                                                 String reference, 
  -                                                 List list)
  +    public static void createPatternSetReference( Project project,
  +                                                  String reference,
  +                                                  List list )
       {
           StringBuffer includesSb = new StringBuffer();
           StringBuffer excludesSb = new StringBuffer();
           PatternSet patternSet = new PatternSet();
   
  -        for (Iterator i = list.iterator(); i.hasNext();)
  +        for ( Iterator i = list.iterator(); i.hasNext(); )
           {
               String line = (String) i.next();
               line = line.trim();
  -            includesSb.append(line).append(',');
  +            includesSb.append( line ).append( ',' );
           }
   
           String includes = includesSb.toString();
           String excludes = excludesSb.toString();
   
  -        if (includes.length() > 0)
  +        if ( includes.length() > 0 )
           {
               // Remove trailing comma
  -            includes = includes.substring(0, includes.length() - 1);
  -            patternSet.setIncludes(includes);
  +            includes = includes.substring( 0, includes.length() - 1 );
  +            patternSet.setIncludes( includes );
           }
  -        if (excludes.length() > 0)
  +        if ( excludes.length() > 0 )
           {
               // Remove trailing comma
  -            excludes = includes.substring(0, includes.length() - 1);
  -            patternSet.setExcludes(excludes);
  +            excludes = includes.substring( 0, includes.length() - 1 );
  +            patternSet.setExcludes( excludes );
           }
   
  -        project.addReference(reference, patternSet);
  +        project.addReference( reference, patternSet );
       }
   
  -    private boolean validProperty(String property)
  +    private boolean validProperty( String property )
       {
  -        if (property != null && property.length() > 0 && !property.startsWith("${"))
  +        if ( property != null && property.length() > 0 && !property.startsWith( 
"${" ) )
           {
               return true;
           }
  -        
  +
           return false;
  -    }        
  +    }
  +
       /**
        * Returns the online.
        * @return String
  @@ -580,7 +587,7 @@
        * Sets the online.
        * @param online The online to set
        */
  -    public void setOnline(String online)
  +    public void setOnline( String online )
       {
           this.online = online;
       }
  
  
  

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

Reply via email to