werken      2002/07/22 13:10:43

  Modified:    src/bin  forehead.conf
               src/java/org/apache/maven/app Maven.java
                        MavenJellyContext.java PluginManager.java
               src/plugins-build/xdoc/src/java/org/apache/maven
                        DVSLBean.java
  Added:       src/java/org/apache/maven/app App.java
  Log:
  Separated application logic away from maven javabean.
  
  Revision  Changes    Path
  1.3       +1 -1      jakarta-turbine-maven/src/bin/forehead.conf
  
  Index: forehead.conf
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/bin/forehead.conf,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- forehead.conf     9 Jul 2002 13:27:43 -0000       1.2
  +++ forehead.conf     22 Jul 2002 20:10:43 -0000      1.3
  @@ -3,7 +3,7 @@
   +java.home
   +tools.jar
   
  -=[root.maven] org.apache.maven.app.Maven
  +=[root.maven] org.apache.maven.app.App
   
   [root]
   
  
  
  
  1.75      +158 -900  jakarta-turbine-maven/src/java/org/apache/maven/app/Maven.java
  
  Index: Maven.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/Maven.java,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- Maven.java        19 Jul 2002 00:29:04 -0000      1.74
  +++ Maven.java        22 Jul 2002 20:10:43 -0000      1.75
  @@ -96,8 +96,6 @@
   import java.net.URL;
   import java.net.MalformedURLException;
   
  -import java.text.BreakIterator;
  -
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Collections;
  @@ -108,6 +106,7 @@
   import java.util.List;
   import java.util.Properties;
   import java.util.StringTokenizer;
  +import java.util.Stack;
   
   /**
    * Command-line entry-point to maven.
  @@ -143,10 +142,7 @@
       /** Log. */
       private static final Log log = LogFactory.getLog(PluginManager.class);
   
  -    /** Default console width - for formatting output - 78 */
  -    private static final int CONSOLE_WIDTH = 80;
  -
  -    private static Maven INSTANCE = new Maven();
  +    private static final Stack INSTANCES = new Stack();
   
       // ------------------------------------------------------------
       //     Instance members
  @@ -176,9 +172,6 @@
       /** List of string goal names on the command-line. */
       private List goalNames;
   
  -    /** Aggregate properties. */
  -    private Properties properties;
  -
       /** Maven project. */
       private Project project;
   
  @@ -194,15 +187,6 @@
       /** Jelly's output. */
       private XMLOutput output;
   
  -    /** Jelly's underlying writer. */
  -    private Writer writer;
  -
  -    /** Saved original console System.out. */
  -    private PrintStream consoleOut;
  -
  -    /** Saved original console System.err. */
  -    private PrintStream consoleErr;
  -
       /** Plugin Manager */
       private PluginManager pluginManager;
   
  @@ -215,11 +199,13 @@
   
       /** Construct.
        */
  -    public Maven()
  +    public Maven(File mavenHome) 
       {
  -        this.properties = new Properties();
  +        setMavenHome( mavenHome );
           this.werkzProject = new com.werken.werkz.Project();
           this.pluginManager = new PluginManager();
  +        this.goalNames = new ArrayList( 3 );
  +        initializeJelly();
       }
   
       // ------------------------------------------------------------
  @@ -230,9 +216,12 @@
        *
        *  @param projectFile The project descriptor file.
        */
  -    public void setProjectFile(File projectFile)
  +    public void setProjectFile(File projectFile) throws Exception
       {
           this.projectFile = projectFile;
  +        initializeProject();
  +        initializeAnt();
  +        initializeTagLibs();
       }
   
       /** Retrieve the project descriptor file.
  @@ -300,7 +289,7 @@
        *
        *  @return The project descriptor.
        */
  -    private Project getProject()
  +    public Project getProject()
       {
           return this.project;
       }
  @@ -314,6 +303,10 @@
           return this.antProject;
       }
   
  +    /** Retrieve the Ant project.
  +     *
  +     *  @return The ant project.
  +     */
       public org.apache.tools.ant.Project getBaseAntProject()
       {
           return this.antProject;
  @@ -323,7 +316,7 @@
        * retrieve the werkz project object
        * @return the {@link com.werken.werkz.Project Werkz Project}
        */
  -    private com.werken.werkz.Project getWerkzProject()
  +    public com.werken.werkz.Project getWerkzProject()
       {
           return this.werkzProject;
       }
  @@ -399,13 +392,14 @@
           return this.goalNames;
       }
   
  -    /** Retrieve aggregated properties.
  -     *
  -     *  @return Aggregated properties.
  -     */
  -    public Properties getProperties()
  +    public void addGoalName(String goalName)
       {
  -        return this.properties;
  +        this.goalNames.add( goalName );
  +    }
  +
  +    public void addGoalNames(List goalNames)
  +    {
  +        this.goalNames.addAll( goalNames );
       }
   
       /** Retrieve the Jelly context.
  @@ -430,11 +424,16 @@
        *
        *  @return The output sink.
        */
  -    private XMLOutput getXMLOutput()
  +    public XMLOutput getXMLOutput()
       {
           return this.output;
       }
   
  +    public void setXMLOutput(XMLOutput output)
  +    {
  +        this.output = output;
  +    }
  +
       /**
        * Set the project verifier.
        */
  @@ -484,66 +483,9 @@
               + "; dir=" + getDir()
               + "; projectFile=" + getProjectFile()
               + "; goalNames=" + getGoalNames()
  -            + "; props=" + getProperties()
               + "]";
       }
   
  -    /** Perform initialization.
  -     *
  -     *  @param args The command-line arguments.
  -     *
  -     *  @throws ParseException If there is an error parsing the
  -     *          command-line.
  -     *  @throws IOException If there is an error while
  -     *          reading the project descriptor.
  -     *  @throws MalformedURLException If any of the the URLs denoting
  -     *          the local or remote repositories is malformed.
  -     *  @throws DescriptorException when there are errors creating the
  -     *          descriptor from a file
  -     */
  -    public void initializeCore(String[] args) throws
  -        ParseException, IOException, MalformedURLException,Exception
  -    {
  -
  -        setMavenHome(new File(System.getProperty("maven.home")));
  -
  -        parseCommandLine(args);
  -
  -        initializeJelly();
  -
  -        loadProperties();
  -
  -        checkOnline();
  -
  -        initializeProject();
  -
  -        initializeAnt();
  -        initializeIO();
  -        initializeTagLibs();
  -
  -        System.setProperty("user.dir",
  -                           getDir().getPath());
  -    }
  -
  -    private void checkOnline()
  -    {
  -        if ( getProperty( "maven.mode.online" ) != null )
  -        {
  -            return;
  -        }
  -
  -        if ( getCli().hasOption( 'o' ) )
  -        {
  -            getJellyContext().setVariable( "maven.mode.online",
  -                                           Boolean.FALSE );
  -        }
  -        else
  -        {
  -            getJellyContext().setVariable( "maven.mode.online",
  -                                           Boolean.TRUE );
  -        }
  -    }
  -
       /** Load the maven project descriptor.
        *
        *  @throws DescriptorException If there is an error while
  @@ -556,17 +498,20 @@
       }
   
       /** Initialize Jelly.
  -     *
  -     *  @throws MalformedURLException If the url specifying
  -     *          MAVEN_HOME/bin is malformed, which is highly
  -     *          unlikely, but technically possible.
        */
  -    private void initializeJelly() throws MalformedURLException
  +    private void initializeJelly() 
       {
  -        this.jellyContext = new MavenJellyContext(getMavenBin().toURL(),
  -                                                  this.properties);
  -
  -        initializeJellyVariables();
  +        try
  +        {
  +            this.jellyContext = new MavenJellyContext(getMavenBin().toURL());
  +            
  +            initializeJellyVariables();
  +        }
  +        catch (MalformedURLException e)
  +        {
  +            // this really should not occur...
  +            e.printStackTrace();
  +        }
       }
   
       /** Initialize common core <code>JellyContext</code> variables.
  @@ -616,7 +561,6 @@
           this.jellyContext.registerTagLibrary("",
                                                jeezTagLib);
   
  -        // Register Maven taglibs
           this.jellyContext.registerTagLibrary("jelly:maven",
                                                new MavenTagLibrary());
       }
  @@ -638,49 +582,12 @@
                                          antProject );
       }
   
  -    /**
  -     *  Initialize the IO streams.
  -     *
  -     * @throws IOException on error creating XML output and handling System.err
  -     *         and out
  -     */
  -    private void initializeIO() throws IOException
  -    {
  -        this.consoleOut = System.out;
  -        this.consoleErr = System.err;
  -
  -        this.writer = new OutputStreamWriter(this.consoleOut);
  -        this.output = XMLOutput.createXMLOutput(writer, false);
  -
  -        GrantProject project = getAntProject();
  -
  -        JellyBuildListener listener = new JellyBuildListener(output);
  -
  -        if (getCli().hasOption('x')
  -             ||
  -             getCli().hasOption('X'))
  -        {
  -            listener.isDebug(true);
  -        }
  -
  -        project.addBuildListener(listener);
  -
  -        PrintStream demuxOut = new PrintStream(new DemuxOutputStream(project,
  -                                                                     false));
  -
  -        PrintStream demuxErr = new PrintStream(new DemuxOutputStream(project,
  -                                                                     true));
  -
  -        System.setOut(demuxOut);
  -        System.setErr(demuxErr);
  -    }
  -
       /** Perform pre-build initialization.
        *
        *  @throws Exception If an error occurs while performing
        *          runtime initialization.
        */
  -    private void runtimeInitialization() throws Exception
  +    void runtimeInitialization() throws Exception
       {
           initializeDriver();
           createProjectVerifier();
  @@ -705,7 +612,8 @@
           }
   
           File driverProperties = new File(mavenBin, "driver.properties");
  -        loadProps(driverProperties);
  +
  +        loadProperties( driverProperties );
   
           JellyUtils.runScript(driver,
                                 getMavenBin().toURL(),
  @@ -728,312 +636,138 @@
           pluginManager.initializePlugins();
       }
   
  -    /** Run maven.
  -     *
  -     *  @throws Exception If an error occurs.
  -     */
  -    private void attainGoals() throws Exception
  -    {
  -        JellyContext context = getJellyContext();
  -
  -        context.setVariable("goals",
  -                            getGoalNames());
  -
  -        runGoals(goalNames);
  -    }
  -
  -
  -    /** Display helpful information regarding
  -     *  all documented goals.
  +     /**
  +     * Create project verifier
        */
  -    private void displayGoals()
  +    private ProjectVerifier createProjectVerifier()
  +        throws Exception
       {
  +        String localRepoProp = getProperty("maven.repo.local");
   
  -        System.out.println();
  -        String title = "Available [Plugins] / Goals";
  -        System.out.println(title);
  -        System.out.println(format("", title.length(), '`'));
  -
  -        Collection goals = getWerkzProject().getGoals();
  -
  -        List list = new ArrayList(goals);
  +        if (localRepoProp == null)
  +        {
  +            localRepoProp = getProperty("lib.repo");
   
  -        // sort by name
  -        Comparator comparator = new Comparator() {
  -            public int compare(Object o1, Object o2)
  +            if (localRepoProp != null)
               {
  -                Goal g1 = (Goal) o1;
  -                Goal g2 = (Goal) o2;
  -                return g1.getName().compareTo(g2.getName());
  +                System.out.println("----------------------------------------");
  +                System.out.println("DEPRECATION WARNING");
  +                System.out.println("");
  +                System.out.println(" The usage of the lib.repo property has");
  +                System.out.println(" been deprecated.");
  +                System.out.println("");
  +                System.out.println(" The lib.repo property has been replaced ");
  +                System.out.println(" with the maven.repo.local property");
  +                System.out.println("");
  +                System.out.println(" An easy solution is to simply add this");
  +                System.out.println(" line to your build.properties:");
  +                System.out.println("");
  +                System.out.println("   maven.repo.local=${lib.repo}");
  +                System.out.println("");
  +                System.out.println("----------------------------------------");
               }
  -        };
  -        Collections.sort(list, comparator);
  -
  +        }
   
  -        Iterator goalIter = list.iterator();
  -        Goal eachGoal = null;
  -        int wrapIndent = 30;
  -        String lastPluginName = "";
  -        String msgPrefix = "";
  -        String goalDescription = null;
  -        String goalName = null;
  -        String pluginName;
  -        boolean hasDesc = false;
  -        boolean newPlugin = false;
  -        boolean firstLine = true;
  -        boolean haveGoalsWithNoDescription = false;
  -
  -        while (goalIter.hasNext())
  -        {
  -            eachGoal = (Goal) goalIter.next(); // goal object
  -            goalDescription = eachGoal.getDescription();
  -            goalName = eachGoal.getName(); // ex. java:jar
  -
  -            StringTokenizer st = new StringTokenizer(goalName, ":");
  -            pluginName = st.nextToken(); //ex. java
  -            newPlugin = !pluginName.equals(lastPluginName);
  -
  -            /*
  -             * prepare the description
  -             */
  -            if(goalDescription == null)
  +        if (localRepoProp == null)
  +        {
  +            localRepoProp = getProperty("lib.repo");
  +            if (localRepoProp == null)
               {
  -                hasDesc = false;
  +                throw new RepoConfigException("maven.repo.local not set");
               }
               else
               {
  -                goalDescription = goalDescription.trim();
  -                hasDesc = goalDescription.length() != 0;
  +                // FIXME: display warning here
               }
  +        }
   
  +        String remoteRepoProp = getProperty("maven.repo.remote");
   
  -            if (newPlugin)
  -            {
  -                // starting new section
  -                lastPluginName = pluginName;
  -
  -                if(st.hasMoreTokens())
  -                {
  -                  // uh oh we have no default goal defined
  -                  wrapIndent = 30;
  -                  msgPrefix = "  " + st.nextToken() + " ";
  -                  if (msgPrefix.trim().length() == 0)
  -                  {
  -                      msgPrefix = "  ( NO GOAL NAME ) ";
  -                  }
  -                  msgPrefix = format(msgPrefix, wrapIndent, '.') + " ";
  -                  // +1 pad for space on the end
  -                  wrapIndent++;
  -
  -                  /*
  -                   * if the goal found for a new plugin is not the default
  -                   * goal, then we make the plugin description something that
  -                   * makes clear there is no default goal defined
  -                   */
  -                  msgPrefix = pluginName
  -                              + "] ( NO DEFAULT GOAL )\n"
  -                              + msgPrefix;
  -                }
  -                else
  -                {
  -                    // we are dealing with the default goal
  -                    msgPrefix = pluginName + "]";
  +        if (remoteRepoProp == null)
  +        {
  +            throw new RepoConfigException("maven.repo.remote not set");
  +        }
   
  -                    if(hasDesc)
  -                    {
  -                        msgPrefix += " : ";
  -                        wrapIndent = msgPrefix.length();
  -                    }
  -                }
  +        File localRepo = new File(localRepoProp);
   
  -                // the first line of display goals should not start a new line
  -                if(firstLine)
  -                {
  -                      msgPrefix = "[" + msgPrefix;
  -                      firstLine = false;
  -                }
  -                else
  -                {
  -                    msgPrefix = "\n[" + msgPrefix;
  -                }
  +        if (!localRepo.exists())
  +        {
  +            System.err.println("Directory '" + localRepo + "' does not exist.");
  +            System.err.println("Attempting to create.");
   
  -                if(hasDesc)
  -                {
  -                    System.out.println(msgPrefix
  -                       + wrapConsoleMessage(goalDescription, wrapIndent,
  -                                              CONSOLE_WIDTH));
  -                }
  -                else
  -                {
  -                  System.out.println(msgPrefix + " ( NO DESCRIPTION ) ");
  -                }
  -            }
  -            else
  +            if (!localRepo.mkdirs())
               {
  -                if(hasDesc)
  -                {
  -                    wrapIndent = 30; // where the indent begins for all goals
  -                    // protect against a plugin called "plugin:"
  -                    if(st.hasMoreTokens())
  -                    {
  -                        // not a new plugin so also not the first line of plugin 
section
  -                        // and not a goal with just a plugin name; there must be 
nextToken
  -                        msgPrefix = "  " + st.nextToken() + " ";
  -                        //protect against empty goal names
  -                        if (msgPrefix.trim().length() == 0)
  -                        {
  -                            msgPrefix = "  ( NO GOAL ) ";
  -                        }
  -
  -                    }
  -                    else
  -                    {
  -                        msgPrefix = "  ( NO GOAL ) ";
  -                    }
  -
  -                    msgPrefix = format(msgPrefix, wrapIndent, '.') + " ";
  -                    wrapIndent += 1; // for spaces used to pad the prefix
  -
  -                    System.out.println(msgPrefix
  -                        + wrapConsoleMessage(goalDescription, wrapIndent,
  -                                              CONSOLE_WIDTH));
  -                }
  -                else
  -                {
  -                    haveGoalsWithNoDescription = true;
  -                }
  +                throw new RepoConfigException("Unable to create directory '"
  +                    + localRepo + "'");
               }
           }
   
  -        if (haveGoalsWithNoDescription)
  +        if (!localRepo.isDirectory())
           {
  -            System.out.println();
  -            System.out.println();
  -            System.out.println("Non documented goals : ");
  -            System.out.println();
  -            goalIter = list.iterator();
  -            while (goalIter.hasNext())
  -            {
  -                eachGoal = (Goal) goalIter.next();
  -                goalDescription = eachGoal.getDescription();
  -
  -                /*
  -                 * prepare the description
  -                 */
  -                if(goalDescription == null)
  -                {
  -                    hasDesc = false;
  -                }
  -                else
  -                {
  -                    hasDesc = goalDescription.trim().length() != 0;
  -                }
  -
  -                if (goalDescription == null)
  -                {
  -                    System.out.println("  " + eachGoal.getName());
  -                }
  -            }
  +            throw new RepoConfigException(localRepo + " is not a directory.");
           }
  -    }
  -
   
  -    /**
  -     * Nicely wraps a message for console output, using a word BreakIterator
  -     * instance to determine wrapping breaks.
  -     *
  -     * @param msg the string message for the console
  -     * @param wrapIndent the number of characters to indent all lines
  -     * after the first one
  -     * @param lineWidth the console width that determines where to wrap
  -     * @return the message wrapped for the console
  -     */
  -    private String wrapConsoleMessage(String msg, int wrapIndent, int lineWidth)
  -    {
  -        int offset = lineWidth - wrapIndent;
  -        if (msg.length() <= offset)
  +        if (!localRepo.canWrite())
           {
  -            return msg;
  +            throw new RepoConfigException(localRepo + " is not writable.");
           }
  -        else
  -        {
  -            BreakIterator bIter = BreakIterator.getWordInstance();
  -            StringBuffer buf = new StringBuffer();
  -            String newLine = "\n";
  -            String pad = " ";
  -            int currentPos = 0;
  -            bIter.setText(msg);
  -
  -            while (offset < bIter.getText().getEndIndex())
  -            {
  -                if (Character.isWhitespace(bIter.getText().first()))
  -                {
  -                  // remove leading whitespace and continue
  -                  msg = msg.substring(1);
  -                  bIter.setText(msg);
  -                  continue;
  -                }
   
  -                // get the last boundary before the specified offset
  -                currentPos = bIter.preceding(offset);
  -                // append from the start to currentPos
  -                buf.append(msg.substring(0, currentPos));
  -                // start next line
  -                buf.append(newLine);
  -
  -                //pad with spaces to create indent
  -                for (int i = 0; i != wrapIndent && i < lineWidth; i++)
  -                {
  -                  buf.append(pad);
  -                }
  +        projectVerifier = new ProjectVerifier();
   
  -                // set the text of the break iterator to be the rest
  -                // of the string not already appended
  -                msg = msg.substring(currentPos);
  +        projectVerifier.setMavenRemoteRepo(remoteRepoProp);
  +        projectVerifier.setMavenLocalRepo(localRepoProp);
  +        projectVerifier.setMavenProject(getProject());
  +        projectVerifier.setProject(getAntProject());
  +        String proxyHost = getProperty("maven.proxy.host");
  +        if (proxyHost != null)
  +        {
  +            projectVerifier.setProxyHost(proxyHost);
  +            projectVerifier.setProxyPort(getProperty("maven.proxy.port"));
  +            projectVerifier.setProxyUserName(getProperty("maven.proxy.username"));
  +            projectVerifier.setProxyPassword(getProperty("maven.proxy.password"));
  +        }
   
  -                //reset the text for another go
  -                bIter.setText(msg);
  -            }
  +        return projectVerifier;
  +    }
   
  -            // remove leading whitespace and continue
  -            while (Character.isWhitespace(msg.charAt(0)))
  -            {
  -                msg = msg.substring(1);
  -            }
  -            buf.append(msg);
  -            return buf.toString();
  -        }
  +    /**
  +     * Verify a project. Basically make sure the dependencies are
  +     * present and do a basic sanity check.
  +     */
  +    public void verifyProject() throws Exception
  +    {
  +        getProjectVerifier().setMavenProject(getProject());
  +        getProjectVerifier().doExecute();
       }
   
   
  -    /** Produce a formatted/padded string.
  -     *
  -     *  @param orig The string to format.
  -     *  @param width The width of the resulting formatted string.
  -     *  @param pad The trailing pad character.
  +
  +    /** Run maven.
        *
  -     *  @return The formatted string, or the original string
  -     *          if the length is already >= <code>width</code>.
  +     *  @throws Exception If an error occurs.
        */
  -    private String format(String orig, int width, char pad)
  +    public void attainGoals() throws Exception
       {
  -        if (orig.length() >= width)
  +        try
           {
  -            return orig;
  -        }
  +            INSTANCES.push( this );
   
  -        StringBuffer buf = new StringBuffer().append(orig);
  -
  -        int diff = width - orig.length();
  -
  -        for (int i = 0; i < diff; ++i)
  +            JellyContext context = getJellyContext();
  +            
  +            context.setVariable("goals",
  +                                getGoalNames());
  +            
  +            runGoals(goalNames);
  +        }
  +        finally
           {
  -            buf.append(pad);
  +            INSTANCES.pop();
           }
  -
  -        return buf.toString();
       }
   
  +
  +
  +
       /** Load the project's maven script.
        *
        *  @throws Exception if there is an error loading
  @@ -1138,151 +872,34 @@
           }
       }
   
  -    /** Parse the command-line.
  -     *
  -     *  <p>
  -     *  In addition to parsing the command-line, this will
  -     *  set the appropriate internal flags an options to
  -     *  allow for further execution.
  -     *  </p>
  -     *
  -     *  @param args The command-line arguments.
  -     *
  -     *  @throws ParseException If an error occurs during parsing.
  -     */
  -    private void parseCommandLine(String[] args) throws ParseException
  +    public void setProperty(String name,
  +                            String value)
       {
  -        this.cli = CLIManager.parse(args);
  +        setVariable( name,
  +                     value );
  +    }
   
  -        if (this.cli.hasOption('d'))
  -        {
  -            setDir(new File(cli.getOptionValue('d')));
  -        }
  +    public void setVariable(String name,
  +                            Object value)
  +    {
  +        getJellyContext().setVariable( name,
  +                                       value );
  +    }
   
  -        if (this.cli.hasOption('p'))
  +    /** Load the specified properties file into the aggregate
  +     *  properties.
  +     *
  +     *  @param propsFile The properties file to load.
  +     */
  +    public void loadProperties(File propsFile)
  +    {
  +        if (!propsFile.exists())
           {
  -            setProjectFileName(cli.getOptionValue('p'));
  -            setProjectFile(new File(getProjectFileName()));
  +            log.debug("No properties file: " + propsFile);
           }
           else
           {
  -            setProjectFileName(PROJECT_DESCRIPTOR_FILE_NAME);
  -            setProjectFile(new File(getDir(), getProjectFileName()));
  -        }
  -
  -        File projectBuildFile = new File(getDir(),
  -                                         PROJECT_BUILD_FILE_NAME);
  -
  -        if (projectBuildFile.exists())
  -        {
  -            setProjectBuildFile(projectBuildFile);
  -        }
  -
  -        this.goalNames = cli.getArgList();
  -    }
  -
  -    /** Set a property based upon a commandline
  -     *  <code>name=value</code> string.
  -     *
  -     *  @param defStr The <code>name=value</code> string.
  -     */
  -    private void setCliProperty(String defStr)
  -    {
  -        String name  = null;
  -        String value = null;
  -        int equalLoc = defStr.indexOf("=");
  -
  -        if (equalLoc <= 0)
  -        {
  -            name  = defStr.trim();
  -            value = "true";
  -        }
  -        else
  -        {
  -            name = defStr.substring(0,
  -                                    equalLoc).trim();
  -
  -            value = defStr.substring(equalLoc + 1).trim();
  -        }
  -
  -        this.properties.put(name,
  -                            value);
  -    }
  -
  -    /** Load the properties chain.
  -     *
  -     *  <p>
  -     *  This loads properties files with the following priority:
  -     *  <ol>
  -     *    <li>$PROJECT/build.properties</li>
  -     *    <li>$HOME/build.properties</li>
  -     *    <li>$PROJECT/project.properties</li>
  -     *    <li>--system properties--</li>
  -     *  </ol>
  -     */
  -    private void loadProperties()
  -    {
  -        //!! FIXME: the value for the remote repo shouldn't be hard-coded.
  -        this.properties.setProperty("maven.repo.remote",
  -            "http://jakarta.apache.org/turbine/jars2/";);
  -
  -        Enumeration propNames = System.getProperties().propertyNames();
  -        String      eachName  = null;
  -
  -        while (propNames.hasMoreElements())
  -        {
  -            eachName = (String) propNames.nextElement();
  -
  -            this.properties.setProperty(eachName,
  -                                        System.getProperty(eachName));
  -        }
  -
  -        String propsFileName = null;
  -
  -        File propsFile = null;
  -
  -        propsFile = new File(getDir(),
  -                             "project.properties");
  -
  -        loadProps(propsFile);
  -
  -        propsFile = new File(System.getProperty("user.home"),
  -                             "build.properties");
  -
  -        loadProps(propsFile);
  -
  -        propsFile = new File(getDir(),
  -                             "build.properties");
  -
  -        loadProps(propsFile);
  -
  -
  -        if (getCli().hasOption('D'))
  -        {
  -            String[] defStrs = getCli().getOptionValues('D');
  -
  -            for (int i = 0; i < defStrs.length; ++i)
  -            {
  -                setCliProperty(defStrs[i]);
  -            }
  -        }
  -
  -    }
  -
  -    /** Load the specified properties file into the aggregate
  -     *  properties.
  -     *
  -     *  @param propsFile The properties file to load.
  -     */
  -    private void loadProps(File propsFile)
  -    {
  -        if (!propsFile.exists())
  -        {
  -            log.debug("No properties file: " + propsFile);
  -        }
  -        else
  -        {
  -            log.debug("Properties file: " + propsFile);
  +            log.debug("Properties file: " + propsFile);
           }
   
           FileInputStream in = null;
  @@ -1373,377 +990,18 @@
           }
       }
   
  -    /**
  -     * Create project verifier
  -     */
  -    private ProjectVerifier createProjectVerifier()
  -        throws Exception
  -    {
  -        String localRepoProp = getProperty("maven.repo.local");
  -
  -        if (localRepoProp == null)
  -        {
  -            localRepoProp = getProperty("lib.repo");
  -
  -            if (localRepoProp != null)
  -            {
  -                System.out.println("----------------------------------------");
  -                System.out.println("DEPRECATION WARNING");
  -                System.out.println("");
  -                System.out.println(" The usage of the lib.repo property has");
  -                System.out.println(" been deprecated.");
  -                System.out.println("");
  -                System.out.println(" The lib.repo property has been replaced ");
  -                System.out.println(" with the maven.repo.local property");
  -                System.out.println("");
  -                System.out.println(" An easy solution is to simply add this");
  -                System.out.println(" line to your build.properties:");
  -                System.out.println("");
  -                System.out.println("   maven.repo.local=${lib.repo}");
  -                System.out.println("");
  -                System.out.println("----------------------------------------");
  -            }
  -        }
  -
  -        if (localRepoProp == null)
  -        {
  -            localRepoProp = getProperty("lib.repo");
  -            if (localRepoProp == null)
  -            {
  -                throw new RepoConfigException("maven.repo.local not set");
  -            }
  -            else
  -            {
  -                // FIXME: display warning here
  -            }
  -        }
  -
  -        String remoteRepoProp = getProperty("maven.repo.remote");
  -
  -        if (remoteRepoProp == null)
  -        {
  -            throw new RepoConfigException("maven.repo.remote not set");
  -        }
  -
  -        File localRepo = new File(localRepoProp);
  -
  -        if (!localRepo.exists())
  -        {
  -            System.err.println("Directory '" + localRepo + "' does not exist.");
  -            System.err.println("Attempting to create.");
  -
  -            if (!localRepo.mkdirs())
  -            {
  -                throw new RepoConfigException("Unable to create directory '"
  -                    + localRepo + "'");
  -            }
  -        }
  -
  -        if (!localRepo.isDirectory())
  -        {
  -            throw new RepoConfigException(localRepo + " is not a directory.");
  -        }
  -
  -        if (!localRepo.canWrite())
  -        {
  -            throw new RepoConfigException(localRepo + " is not writable.");
  -        }
  -
  -        projectVerifier = new ProjectVerifier();
  -
  -        projectVerifier.setMavenRemoteRepo(remoteRepoProp);
  -        projectVerifier.setMavenLocalRepo(localRepoProp);
  -        projectVerifier.setMavenProject(getProject());
  -        projectVerifier.setProject(getAntProject());
  -        String proxyHost = getProperty("maven.proxy.host");
  -        if (proxyHost != null)
  -        {
  -            projectVerifier.setProxyHost(proxyHost);
  -            projectVerifier.setProxyPort(getProperty("maven.proxy.port"));
  -            projectVerifier.setProxyUserName(getProperty("maven.proxy.username"));
  -            projectVerifier.setProxyPassword(getProperty("maven.proxy.password"));
  -        }
  -
  -        return projectVerifier;
  -    }
  -
  -    /**
  -     * Verify a project. Basically make sure the dependencies are
  -     * present and do a basic sanity check.
  -     */
  -    public void verifyProject() throws Exception
  -    {
  -        getProjectVerifier().setMavenProject(getProject());
  -        getProjectVerifier().doExecute();
  -    }
  -
  -    /**
  -     * Prints the Maven header to System.out
  -     */
  -    private void printConsoleMavenHeader()
  -    {
  -      System.out.println(" __  __");
  -      System.out.println("|  \\/  |__ Jakarta _ ___");
  -      System.out.println("| |\\/| / _` \\ V / -_) ' \\  ~ intelligent projects ~");
  -      System.out.println("|_|  |_\\__,_|\\_/\\___|_||_|   v. " + APP_VERSION);
  -    }
  -
  -    /**
  -     * Prints the Project header to System.out
  -     *
  -     * @param mavenProject the project the print
  -     */
  -    private void printConsoleProjectHeader(Project mavenProject)
  -    {
  -        System.out.println(mavenProject.getName() + " ("
  -          + mavenProject.getId() + ") "
  -          + mavenProject.getCurrentVersion());
  -        System.out.println(getDir());
  -    }
  -
  -    /** Objectized version of main().
  -     *
  -     *  @param args Command-line arguments.
  -     */
  -    public void doMain(String[] args)
  -    {
  -        boolean done = false;
  -
  -        Date fullStart = new Date();
  -
  -        try
  -        {
  -            initializeCore(args);
  -        }
  -        catch (ParseException e)
  -        {
  -            System.err.println(e.getLocalizedMessage());
  -            CLIManager.displayHelp();
  -            done = true;
  -        }
  -        catch (IOException e)
  -        {
  -            System.err.println(e.getLocalizedMessage());
  -            done = true;
  -        }
  -        catch (Exception e)
  -        {
  -            System.err.println(e.getLocalizedMessage());
  -            done = true;
  -        }
  -
  -        if (done)
  -        {
  -            System.out.println("");
  -            return;
  -        }
  -
  -        if (getCli().hasOption('h'))
  -        {
  -            CLIManager.displayHelp();
  -            System.out.println("");
  -            return;
  -        }
  -
  -        Date buildStart = new Date();
  -
  -        Project mavenProject = getProject();
  -
  -        if ( ! getCli().hasOption( 'b' ) )
  -        {
  -            printConsoleMavenHeader();
  -            System.out.println();
  -        }
  -        printConsoleProjectHeader(mavenProject);
  -        System.out.println();
  -
  -        boolean failed = false;
  -
  -        try
  -        {
  -            runtimeInitialization();
  -
  -            if (this.cli.hasOption('g'))
  -            {
  -                displayGoals();
  -                System.out.println("");
  -                return;
  -            }
  -            else
  -            {
  -                verifyProject();
  -                attainGoals();
  -            }
  -        }
  -        catch (UnknownGoalException e)
  -        {
  -            failed = true;
  -            System.err.println("BUILD FAILED");
  -            System.err.println("Goal \"" + e.getGoalName()
  -                               + "\" does not exist in this project.");
  -        }
  -        catch (RepoConfigException e)
  -        {
  -            failed = true;
  -            System.err.println(e.getLocalizedMessage());
  -        }
  -        catch (NoActionDefinitionException e)
  -        {
  -            failed = true;
  -            System.err.println("INTERNAL ERROR");
  -            System.err.println("Reference made to goal '" + e.getGoal().getName()
  -                + "' which has no definition.");
  -            System.out.println("");
  -            return;
  -        }
  -        catch (UnattainableGoalException e)
  -        {
  -            failed = true;
  -
  -            System.out.println("");
  -            System.err.println("BUILD FAILED");
  -
  -            String msg = null;
  -
  -            String fileName    = null;
  -            String elementName = null;
  -
  -            int    lineNumber = -1;
  -            int    column     = -1;
  -
  -            Throwable rootCause = e.getRootCause();
  -
  -            if (rootCause != null)
  -            {
  -                if (rootCause instanceof JellyException)
  -                {
  -                    JellyException jellyEx = (JellyException) rootCause;
  -
  -                    fileName    = jellyEx.getFileName();
  -                    elementName = jellyEx.getElementName();
  -
  -                    lineNumber  = jellyEx.getLineNumber();
  -                    column      = jellyEx.getColumnNumber();
  -
  -                    rootCause = jellyEx.getCause();
  -
  -                    if (rootCause == null)
  -                    {
  -                        msg = jellyEx.getReason();
  -                    }
  -                    else
  -                    {
  -                        if (getCli().hasOption('e'))
  -                        {
  -                            rootCause.printStackTrace();
  -                        }
  -
  -                        msg = rootCause.getLocalizedMessage();
  -
  -                        if (msg == null)
  -                        {
  -                            msg = rootCause.getClass().getName();
  -                        }
  -                    }
  -                }
  -                else
  -                {
  -                    rootCause.printStackTrace();
  -                    msg = rootCause.getLocalizedMessage();
  -
  -                    if (msg == null)
  -                    {
  -                        msg = rootCause.getClass().getName();
  -                    }
  -                }
  -            }
  -            else
  -            {
  -                msg = e.getLocalizedMessage();
  -            }
  -
  -            if (fileName != null)
  -            {
  -                System.err.println("File...... " + fileName);
  -                System.err.println("Element... " + elementName);
  -                System.err.println("Line...... " + lineNumber);
  -                System.err.println("Column.... " + column);
  -            }
  -
  -            System.err.println(msg);
  -
  -            if (getCli().hasOption('X'))
  -            {
  -                e.printStackTrace();
  -            }
  -        }
  -        catch (JellyException e)
  -        {
  -            String fileName    = e.getFileName();
  -            String elementName = e.getElementName();
  -
  -            int lineNumber  = e.getLineNumber();
  -            int column      = e.getColumnNumber();
  -
  -            String msg = e.getReason();
  -
  -            System.err.println("File...... " + fileName);
  -            System.err.println("Element... " + elementName);
  -            System.err.println("Line...... " + lineNumber);
  -            System.err.println("Column.... " + column);
  -
  -            System.err.println(msg);
  -        }
  -        catch (Exception e)
  -        {
  -            failed = true;
  -            e.printStackTrace();
  -        }
  -
  -        if (!failed)
  -        {
  -            System.out.println("BUILD SUCCESSFUL");
  -        }
  -
  -        Date fullStop = new Date();
  -
  -        //long initDiff = buildStart.getTime() - fullStart.getTime();
  -        //long buildDiff = fullStop.getTime() - buildStart.getTime();
  -        long fullDiff = fullStop.getTime() - fullStart.getTime();
  -
  -        // System.out.println("Setup time: " + formatTime(initDiff));
  -        // System.out.println("Build time: " + formatTime(buildDiff));
  -        System.out.println("Total time: " + formatTime(fullDiff));
  -
  -        System.out.println("");
  -    }
  -
  -    static String formatTime(long ms)
  -    {
  -        long secs = ms / 1000;
  -
  -        secs = secs % 60;
  -
  -        return secs + " seconds";
  -    }
  -
  -
       // ------------------------------------------------------------
       //     Class methods
       // ------------------------------------------------------------
   
       public static Maven getInstance()
       {
  -        return INSTANCE;
  +        return (Maven) INSTANCES.peek();
       }
   
  -    /** Run maven.
  -     *
  -     *  @param args The command-line arguments.
  -     */
  -    public static void main(String[] args)
  +    public static void main(String args[])
       {
  -        getInstance().doMain(args);
  +        App.main( args );
       }
   }
   
  
  
  
  1.12      +2 -21     
jakarta-turbine-maven/src/java/org/apache/maven/app/MavenJellyContext.java
  
  Index: MavenJellyContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/MavenJellyContext.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- MavenJellyContext.java    15 Jul 2002 17:47:00 -0000      1.11
  +++ MavenJellyContext.java    22 Jul 2002 20:10:43 -0000      1.12
  @@ -79,9 +79,6 @@
    */
   public class MavenJellyContext extends JellyContext
   {
  -    /** Backing properties. */
  -    private Hashtable props;
  -
       /** Ant project. */
       private Project antProject;
   
  @@ -91,15 +88,11 @@
       /** Construct.
        *
        *  @param rootContext The root context.
  -     *  @param props Backing-store of properties.
        */
  -    public MavenJellyContext(URL rootContext,
  -                             Hashtable props)
  +    public MavenJellyContext(URL rootContext)
       {
           super(rootContext);
   
  -        this.props = props;
  -
           this.asProps = new JellyProps();
       }
       
  @@ -110,7 +103,6 @@
       public MavenJellyContext(MavenJellyContext parent)
       {
           super(parent);
  -        this.props = parent.props;
           this.asProps = parent.asProps;
       }
   
  @@ -192,29 +184,18 @@
        */
       public Object getVariable(String name)
       {
  -        // System.err.println("getVariable(" + name + ")");
  -
  -        Object value = this.props.get(name);
  -
  -        if (value == null)
  -        {
  -            value = super.getVariable(name);
  -        }
  +        Object value = super.getVariable(name);
   
           if (value instanceof String)
           {
  -            // System.err.println("getVariable(" + name + ") is-a string");
               value = ProjectHelper.replaceProperties(getAntProject(),
                                                       (String) value,
                                                       this.asProps);
           }
           else if (value instanceof Expression)
           {
  -            // System.err.println("getVariable(" + name + ") is-a expression");
               value = ((Expression) value).evaluate(this);
           }
  -
  -        // System.err.println("getVariable(" + name + ") -> " + value);
   
           return value;
       }
  
  
  
  1.20      +4 -1      
jakarta-turbine-maven/src/java/org/apache/maven/app/PluginManager.java
  
  Index: PluginManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/app/PluginManager.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- PluginManager.java        22 Jul 2002 13:12:16 -0000      1.19
  +++ PluginManager.java        22 Jul 2002 20:10:43 -0000      1.20
  @@ -306,8 +306,11 @@
               if (classloader != null)
               {
                   DefaultJarArtifact dja = new DefaultJarArtifact();
  +
                   dja.setDependency(dependency);            
  -                File jarFile = new File(getProjectVerifier().getMavenLocalRepo(), 
dja.getPath());
  +
  +                File jarFile = new File(getProjectVerifier().getMavenLocalRepo(),
  +                                        dja.getPath());
   
                   log.debug("jarFile: " + jarFile);
                   
  
  
  
  1.1                  jakarta-turbine-maven/src/java/org/apache/maven/app/App.java
  
  Index: App.java
  ===================================================================
  package org.apache.maven.app;
  
  import org.apache.maven.project.Project;
  
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.tags.werkz.JellyBuildListener;
  import org.apache.commons.cli.ParseException;
  import org.apache.commons.cli.CommandLine;
  
  import org.apache.tools.ant.DemuxOutputStream;
  
  import com.werken.werkz.Goal;
  import com.werken.werkz.UnattainableGoalException;
  import com.werken.werkz.NoActionDefinitionException;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.PrintStream;
  import java.io.OutputStreamWriter;
  import java.io.Writer;
  import java.net.MalformedURLException;
  import java.text.BreakIterator;
  import java.util.Date;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.StringTokenizer;
  import java.util.Enumeration;
  
  public class App
  {
      /** Default console width - for formatting output - 78 */
      private static final int CONSOLE_WIDTH = 80;
  
      private Maven maven;
  
      private CommandLine commandLine;
  
      /** Saved original console System.out. */
      private PrintStream consoleOut;
  
      /** Saved original console System.err. */
      private PrintStream consoleErr;
  
      /** Jelly's underlying writer. */
      private Writer writer;
  
      public App(Maven maven)
      {
          this.maven = maven;
      }
  
      public Maven getMaven()
      {
          return this.maven;
      }
  
      protected CommandLine getCli()
      {
          return this.commandLine;
      }
  
      /** Parse the command-line.
       *
       *  <p>
       *  In addition to parsing the command-line, this will
       *  set the appropriate internal flags an options to
       *  allow for further execution.
       *  </p>
       *
       *  @param args The command-line arguments.
       *
       *  @throws ParseException If an error occurs during parsing.
       */
      private void parseCommandLine(String[] args) throws ParseException, Exception
      {
          this.commandLine = CLIManager.parse(args);
  
          if ( getCli().hasOption('d') )
          {
              getMaven().setDir(new File( getCli().getOptionValue('d')));
          }
          else
          {
              getMaven().setDir( new File( System.getProperty( "user.dir" ) ) );
          }
  
          if ( getCli().hasOption('p') )
          {
              getMaven().setProjectFileName( getCli().getOptionValue('p') );
              getMaven().setProjectFile( new File( getMaven().getProjectFileName() ) );
          }
          else
          {
              getMaven().setProjectFileName(Maven.PROJECT_DESCRIPTOR_FILE_NAME);
              getMaven().setProjectFile(new File( getMaven().getDir(), 
getMaven().getProjectFileName()));
          }
  
          File projectBuildFile = new File( getMaven().getDir(),
                                            Maven.PROJECT_BUILD_FILE_NAME);
  
          if (projectBuildFile.exists())
          {
              getMaven().setProjectBuildFile( projectBuildFile );
          }
          
          getMaven().addGoalNames( getCli().getArgList() );
      }
  
      /** Perform initialization.
       *
       *  @param args The command-line arguments.
       *
       *  @throws ParseException If there is an error parsing the
       *          command-line.
       *  @throws IOException If there is an error while
       *          reading the project descriptor.
       *  @throws MalformedURLException If any of the the URLs denoting
       *          the local or remote repositories is malformed.
       */
      public void initializeCore(String[] args)
          throws ParseException, IOException, MalformedURLException,Exception
      {
  
          parseCommandLine(args);
          loadProperties();
  
          checkOnline();
  
          initializeIO();
  
          System.setProperty("user.dir",
                             getMaven().getDir().getPath());
      }
  
      /**
       *  Initialize the IO streams.
       *
       * @throws IOException on error creating XML output and handling System.err
       *         and out
       */
      protected void initializeIO() throws IOException
      {
          this.consoleOut = System.out;
          this.consoleErr = System.err;
          
          this.writer = new OutputStreamWriter(this.consoleOut);
          XMLOutput output = XMLOutput.createXMLOutput(writer, false);
  
          org.apache.tools.ant.Project project = getMaven().getBaseAntProject();
  
          JellyBuildListener listener = new JellyBuildListener(output);
  
          project.addBuildListener(listener);
  
          if (getCli().hasOption('x')
               ||
               getCli().hasOption('X'))
          {
              listener.isDebug(true);
          }
  
          PrintStream demuxOut = new PrintStream(new DemuxOutputStream(project,
                                                                       false));
  
          PrintStream demuxErr = new PrintStream(new DemuxOutputStream(project,
                                                                       true));
  
          System.setOut(demuxOut);
          System.setErr(demuxErr);
  
          getMaven().setXMLOutput( output );
      }
  
      private void checkOnline()
      {
          if ( getMaven().getProperty( "maven.mode.online" ) != null )
          {
              return;
          }
  
          if ( getCli().hasOption( 'o' ) )
          {
              getMaven().setVariable( "maven.mode.online",
                                      Boolean.FALSE );
          }
          else
          {
              getMaven().setVariable( "maven.mode.online",
                                      Boolean.TRUE );
          }
      }
  
      /** Load the properties chain.
       *
       *  @task Fix the hardcoded maven.repo.remote
       *
       *  <p>
       *  This loads properties files with the following priority:
       *  <ol>
       *    <li>$PROJECT/build.properties</li>
       *    <li>$HOME/build.properties</li>
       *    <li>$PROJECT/project.properties</li>
       *    <li>--system properties--</li>
       *  </ol>
       */
      private void loadProperties()
      {
          //!! FIXME: the value for the remote repo shouldn't be hard-coded.
  
          getMaven().setProperty("maven.repo.remote",
                                 "http://jakarta.apache.org/turbine/jars2/";);
  
          Enumeration propNames = System.getProperties().propertyNames();
          String      eachName  = null;
  
          while (propNames.hasMoreElements())
          {
              eachName = (String) propNames.nextElement();
  
              getMaven().setProperty( eachName,
                                      System.getProperty( eachName ) );
          }
  
          String propsFileName = null;
  
          File propsFile = null;
  
          propsFile = new File( getMaven().getDir(),
                                "project.properties" );
          
          getMaven().loadProperties( propsFile );
          
          propsFile = new File( System.getProperty("user.home"),
                                "build.properties" );
  
          getMaven().loadProperties( propsFile );
          
          propsFile = new File( getMaven().getDir(),
                                "build.properties" );
  
          getMaven().loadProperties( propsFile );
  
  
          if (getCli().hasOption('D'))
          {
              String[] defStrs = getCli().getOptionValues('D');
  
              for (int i = 0; i < defStrs.length; ++i)
              {
                  setCliProperty(defStrs[i]);
              }
          }
      }
  
      /** Set a property based upon a commandline
       *  <code>name=value</code> string.
       *
       *  @param defStr The <code>name=value</code> string.
       */
      private void setCliProperty(String defStr)
      {
          String name  = null;
          String value = null;
          int equalLoc = defStr.indexOf("=");
  
          if (equalLoc <= 0)
          {
              name  = defStr.trim();
              value = "true";
          }
          else
          {
              name = defStr.substring(0,
                                      equalLoc).trim();
  
              value = defStr.substring(equalLoc + 1).trim();
          }
  
          getMaven().setProperty( name,
                                  value );
      }
  
      public void doMain(String[] args)
      {
          boolean done = false;
          
          Date fullStart = new Date();
  
          try
          {
              initializeCore(args);
          }
          catch (ParseException e)
          {
              System.err.println(e.getLocalizedMessage());
              CLIManager.displayHelp();
              done = true;
          }
          catch (IOException e)
          {
              System.err.println(e.getLocalizedMessage());
              done = true;
          }
          catch (Exception e)
          {
              System.err.println(e.getLocalizedMessage());
              done = true;
          }
  
          if (done)
          {
              System.out.println("");
              return;
          }
  
          if (getCli().hasOption('h'))
          {
              CLIManager.displayHelp();
              System.out.println("");
              return;
          }
  
          Date buildStart = new Date();
  
          Project mavenProject = getMaven().getProject();
  
          if ( ! getCli().hasOption( 'b' ) )
          {
              printConsoleMavenHeader();
              System.out.println();
          }
  
          printConsoleProjectHeader(mavenProject);
          System.out.println();
  
          boolean failed = false;
  
          try
          {
              getMaven().runtimeInitialization();
  
              if ( getCli().hasOption('g'))
              {
                  displayGoals();
                  System.out.println("");
                  return;
              }
              else
              {
                  getMaven().verifyProject();
                  getMaven().attainGoals();
              }
          }
          catch (UnknownGoalException e)
          {
              failed = true;
              System.err.println("BUILD FAILED");
              System.err.println("Goal \"" + e.getGoalName()
                                 + "\" does not exist in this project.");
          }
          catch (RepoConfigException e)
          {
              failed = true;
              System.err.println(e.getLocalizedMessage());
          }
          catch (NoActionDefinitionException e)
          {
              failed = true;
              System.err.println("INTERNAL ERROR");
              System.err.println("Reference made to goal '" + e.getGoal().getName()
                  + "' which has no definition.");
              System.out.println("");
              return;
          }
          catch (UnattainableGoalException e)
          {
              failed = true;
  
              System.out.println("");
              System.err.println("BUILD FAILED");
  
              String msg = null;
  
              String fileName    = null;
              String elementName = null;
  
              int    lineNumber = -1;
              int    column     = -1;
  
              Throwable rootCause = e.getRootCause();
  
              if (rootCause != null)
              {
                  if (rootCause instanceof JellyException)
                  {
                      JellyException jellyEx = (JellyException) rootCause;
  
                      fileName    = jellyEx.getFileName();
                      elementName = jellyEx.getElementName();
  
                      lineNumber  = jellyEx.getLineNumber();
                      column      = jellyEx.getColumnNumber();
  
                      rootCause = jellyEx.getCause();
  
                      if (rootCause == null)
                      {
                          msg = jellyEx.getReason();
                      }
                      else
                      {
                          if (getCli().hasOption('e'))
                          {
                              rootCause.printStackTrace();
                          }
  
                          msg = rootCause.getLocalizedMessage();
  
                          if (msg == null)
                          {
                              msg = rootCause.getClass().getName();
                          }
                      }
                  }
                  else
                  {
                      rootCause.printStackTrace();
                      msg = rootCause.getLocalizedMessage();
  
                      if (msg == null)
                      {
                          msg = rootCause.getClass().getName();
                      }
                  }
              }
              else
              {
                  msg = e.getLocalizedMessage();
              }
  
              if (fileName != null)
              {
                  System.err.println("File...... " + fileName);
                  System.err.println("Element... " + elementName);
                  System.err.println("Line...... " + lineNumber);
                  System.err.println("Column.... " + column);
              }
  
              System.err.println(msg);
  
              if (getCli().hasOption('X'))
              {
                  e.printStackTrace();
              }
          }
          catch (JellyException e)
          {
              String fileName    = e.getFileName();
              String elementName = e.getElementName();
  
              int lineNumber  = e.getLineNumber();
              int column      = e.getColumnNumber();
  
              String msg = e.getReason();
  
              System.err.println("File...... " + fileName);
              System.err.println("Element... " + elementName);
              System.err.println("Line...... " + lineNumber);
              System.err.println("Column.... " + column);
  
              System.err.println(msg);
          }
          catch (Exception e)
          {
              failed = true;
              e.printStackTrace();
          }
  
          if (!failed)
          {
              System.out.println("BUILD SUCCESSFUL");
          }
  
          Date fullStop = new Date();
  
          long fullDiff = fullStop.getTime() - fullStart.getTime();
  
          System.out.println("Total time: " + formatTime(fullDiff));
  
          System.out.println("");
      }
  
      /**
       * Prints the Maven header to System.out
       */
      protected void printConsoleMavenHeader()
      {
        System.out.println(" __  __");
        System.out.println("|  \\/  |__ Jakarta _ ___");
        System.out.println("| |\\/| / _` \\ V / -_) ' \\  ~ intelligent projects ~");
        System.out.println("|_|  |_\\__,_|\\_/\\___|_||_|   v. " + Maven.APP_VERSION);
      }
  
      /**
       * Prints the Project header to System.out
       *
       * @param mavenProject the project the print
       */
      protected void printConsoleProjectHeader(Project mavenProject)
      {
          System.out.println(mavenProject.getName() + " ("
            + mavenProject.getId() + ") "
            + mavenProject.getCurrentVersion());
          System.out.println( getMaven().getDir());
      }
      /** Display helpful information regarding
       *  all documented goals.
       */
      protected void displayGoals()
      {
  
          System.out.println();
          String title = "Available [Plugins] / Goals";
          System.out.println(title);
          System.out.println(format("", title.length(), '`'));
  
          Collection goals = getMaven().getWerkzProject().getGoals();
  
          List list = new ArrayList(goals);
  
          // sort by name
          Comparator comparator = new Comparator() {
              public int compare(Object o1, Object o2)
              {
                  Goal g1 = (Goal) o1;
                  Goal g2 = (Goal) o2;
                  return g1.getName().compareTo(g2.getName());
              }
          };
          Collections.sort(list, comparator);
  
  
          Iterator goalIter = list.iterator();
          Goal eachGoal = null;
          int wrapIndent = 30;
          String lastPluginName = "";
          String msgPrefix = "";
          String goalDescription = null;
          String goalName = null;
          String pluginName;
          boolean hasDesc = false;
          boolean newPlugin = false;
          boolean firstLine = true;
          boolean haveGoalsWithNoDescription = false;
  
          while (goalIter.hasNext())
          {
              eachGoal = (Goal) goalIter.next(); // goal object
              goalDescription = eachGoal.getDescription();
              goalName = eachGoal.getName(); // ex. java:jar
  
              StringTokenizer st = new StringTokenizer(goalName, ":");
              pluginName = st.nextToken(); //ex. java
              newPlugin = !pluginName.equals(lastPluginName);
  
              /*
               * prepare the description
               */
              if(goalDescription == null)
              {
                  hasDesc = false;
              }
              else
              {
                  goalDescription = goalDescription.trim();
                  hasDesc = goalDescription.length() != 0;
              }
  
  
              if (newPlugin)
              {
                  // starting new section
                  lastPluginName = pluginName;
  
                  if(st.hasMoreTokens())
                  {
                    // uh oh we have no default goal defined
                    wrapIndent = 30;
                    msgPrefix = "  " + st.nextToken() + " ";
                    if (msgPrefix.trim().length() == 0)
                    {
                        msgPrefix = "  ( NO GOAL NAME ) ";
                    }
                    msgPrefix = format(msgPrefix, wrapIndent, '.') + " ";
                    // +1 pad for space on the end
                    wrapIndent++;
  
                    /*
                     * if the goal found for a new plugin is not the default
                     * goal, then we make the plugin description something that
                     * makes clear there is no default goal defined
                     */
                    msgPrefix = pluginName
                                + "] ( NO DEFAULT GOAL )\n"
                                + msgPrefix;
                  }
                  else
                  {
                      // we are dealing with the default goal
                      msgPrefix = pluginName + "]";
  
                      if(hasDesc)
                      {
                          msgPrefix += " : ";
                          wrapIndent = msgPrefix.length();
                      }
                  }
  
                  // the first line of display goals should not start a new line
                  if(firstLine)
                  {
                        msgPrefix = "[" + msgPrefix;
                        firstLine = false;
                  }
                  else
                  {
                      msgPrefix = "\n[" + msgPrefix;
                  }
  
                  if(hasDesc)
                  {
                      System.out.println(msgPrefix
                         + wrapConsoleMessage(goalDescription, wrapIndent,
                                                CONSOLE_WIDTH));
                  }
                  else
                  {
                    System.out.println(msgPrefix + " ( NO DESCRIPTION ) ");
                  }
              }
              else
              {
                  if(hasDesc)
                  {
                      wrapIndent = 30; // where the indent begins for all goals
                      // protect against a plugin called "plugin:"
                      if(st.hasMoreTokens())
                      {
                          // not a new plugin so also not the first line of plugin 
section
                          // and not a goal with just a plugin name; there must be 
nextToken
                          msgPrefix = "  " + st.nextToken() + " ";
                          //protect against empty goal names
                          if (msgPrefix.trim().length() == 0)
                          {
                              msgPrefix = "  ( NO GOAL ) ";
                          }
  
                      }
                      else
                      {
                          msgPrefix = "  ( NO GOAL ) ";
                      }
  
                      msgPrefix = format(msgPrefix, wrapIndent, '.') + " ";
                      wrapIndent += 1; // for spaces used to pad the prefix
  
                      System.out.println(msgPrefix
                          + wrapConsoleMessage(goalDescription, wrapIndent,
                                                CONSOLE_WIDTH));
                  }
                  else
                  {
                      haveGoalsWithNoDescription = true;
                  }
              }
          }
  
          if (haveGoalsWithNoDescription)
          {
              System.out.println();
              System.out.println();
              System.out.println("Non documented goals : ");
              System.out.println();
              goalIter = list.iterator();
              while (goalIter.hasNext())
              {
                  eachGoal = (Goal) goalIter.next();
                  goalDescription = eachGoal.getDescription();
  
                  /*
                   * prepare the description
                   */
                  if(goalDescription == null)
                  {
                      hasDesc = false;
                  }
                  else
                  {
                      hasDesc = goalDescription.trim().length() != 0;
                  }
  
                  if (goalDescription == null)
                  {
                      System.out.println("  " + eachGoal.getName());
                  }
              }
          }
      }
  
      /** Produce a formatted/padded string.
       *
       *  @param orig The string to format.
       *  @param width The width of the resulting formatted string.
       *  @param pad The trailing pad character.
       *
       *  @return The formatted string, or the original string
       *          if the length is already >= <code>width</code>.
       */
      protected String format(String orig,
                              int width,
                              char pad)
      {
          if (orig.length() >= width)
          {
              return orig;
          }
  
          StringBuffer buf = new StringBuffer().append(orig);
  
          int diff = width - orig.length();
  
          for (int i = 0; i < diff; ++i)
          {
              buf.append(pad);
          }
  
          return buf.toString();
      }
  
      /**
       * Nicely wraps a message for console output, using a word BreakIterator
       * instance to determine wrapping breaks.
       *
       * @param msg the string message for the console
       * @param wrapIndent the number of characters to indent all lines
       * after the first one
       * @param lineWidth the console width that determines where to wrap
       * @return the message wrapped for the console
       */
      protected String wrapConsoleMessage(String msg,
                                          int wrapIndent,
                                          int lineWidth)
      {
          int offset = lineWidth - wrapIndent;
          if (msg.length() <= offset)
          {
              return msg;
          }
          else
          {
              BreakIterator bIter = BreakIterator.getWordInstance();
              StringBuffer buf = new StringBuffer();
              String newLine = "\n";
              String pad = " ";
              int currentPos = 0;
              bIter.setText(msg);
  
              while (offset < bIter.getText().getEndIndex())
              {
                  if (Character.isWhitespace(bIter.getText().first()))
                  {
                    // remove leading whitespace and continue
                    msg = msg.substring(1);
                    bIter.setText(msg);
                    continue;
                  }
  
                  // get the last boundary before the specified offset
                  currentPos = bIter.preceding(offset);
                  // append from the start to currentPos
                  buf.append(msg.substring(0, currentPos));
                  // start next line
                  buf.append(newLine);
  
                  //pad with spaces to create indent
                  for (int i = 0; i != wrapIndent && i < lineWidth; i++)
                  {
                    buf.append(pad);
                  }
  
                  // set the text of the break iterator to be the rest
                  // of the string not already appended
                  msg = msg.substring(currentPos);
  
                  //reset the text for another go
                  bIter.setText(msg);
              }
  
              // remove leading whitespace and continue
              while (Character.isWhitespace(msg.charAt(0)))
              {
                  msg = msg.substring(1);
              }
              buf.append(msg);
              return buf.toString();
          }
      }
  
      protected static String formatTime(long ms)
      {
          long secs = ms / 1000;
          secs = secs % 60;
          return secs + " seconds";
      }
  
      public static void main(String[] args)
      {
          File mavenHome = new File(System.getProperty("maven.home"));
  
          Maven maven = new Maven(mavenHome);
  
          App app = new App( maven );
  
          app.doMain( args );
      }
  
  }
  
  
  
  1.2       +2 -1      
jakarta-turbine-maven/src/plugins-build/xdoc/src/java/org/apache/maven/DVSLBean.java
  
  Index: DVSLBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/plugins-build/xdoc/src/java/org/apache/maven/DVSLBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DVSLBean.java     21 Jul 2002 04:05:29 -0000      1.1
  +++ DVSLBean.java     22 Jul 2002 20:10:43 -0000      1.2
  @@ -354,7 +354,8 @@
           }
           catch (Exception ee)
           {
  -            throw new Exception("Error loading the toolbox : " + ee);
  +            // throw new Exception("Error loading the toolbox : " + ee);
  +            throw ee;
           }
   
           /*
  
  
  

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

Reply via email to