brett       2004/03/25 16:18:06

  Modified:    src/java/org/apache/maven Tag: MAVEN-1_0-BRANCH
                        DependencyClasspathBuilder.java MavenUtils.java
               src/java/org/apache/maven/project Tag: MAVEN-1_0-BRANCH
                        Project.java
  Log:
  PR: MAVEN-1193
  Submitted by: dion gillard
  remove "throws Exception"
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.13.4.4  +1 -2      maven/src/java/org/apache/maven/DependencyClasspathBuilder.java
  
  Index: DependencyClasspathBuilder.java
  ===================================================================
  RCS file: /home/cvs/maven/src/java/org/apache/maven/DependencyClasspathBuilder.java,v
  retrieving revision 1.13.4.3
  retrieving revision 1.13.4.4
  diff -u -r1.13.4.3 -r1.13.4.4
  --- DependencyClasspathBuilder.java   1 Mar 2004 22:36:36 -0000       1.13.4.3
  +++ DependencyClasspathBuilder.java   26 Mar 2004 00:18:06 -0000      1.13.4.4
  @@ -51,7 +51,6 @@
        * @throws Exception If an error occurs while creating the classpath.
        */
       public static String build( Project project )
  -        throws Exception
       {
           StringBuffer classpath = new StringBuffer();
   
  
  
  
  1.107.4.13 +118 -64   maven/src/java/org/apache/maven/MavenUtils.java
  
  Index: MavenUtils.java
  ===================================================================
  RCS file: /home/cvs/maven/src/java/org/apache/maven/MavenUtils.java,v
  retrieving revision 1.107.4.12
  retrieving revision 1.107.4.13
  diff -u -r1.107.4.12 -r1.107.4.13
  --- MavenUtils.java   7 Mar 2004 00:01:29 -0000       1.107.4.12
  +++ MavenUtils.java   26 Mar 2004 00:18:06 -0000      1.107.4.13
  @@ -42,7 +42,10 @@
   import org.xml.sax.SAXException;
   import org.xml.sax.XMLReader;
   
  +import javax.xml.parsers.ParserConfigurationException;
   import javax.xml.parsers.SAXParserFactory;
  +
  +import java.beans.IntrospectionException;
   import java.io.ByteArrayOutputStream;
   import java.io.File;
   import java.io.FileInputStream;
  @@ -105,10 +108,10 @@
        *
        * @param projectDescriptor a maven project.xml
        * @return the Maven project object for the given project descriptor
  -     * @throws Exception when any errors occur
  +     * @throws MavenException when any errors occur
        */
       public static Project getProject( File projectDescriptor )
  -        throws Exception
  +        throws MavenException
       {
           return getProject( projectDescriptor, null );
       }
  @@ -118,10 +121,10 @@
        * @param projectDescriptor The file to create the project from
        * @param parentContext the parent Maven Jelly Context
        * @return a new Project
  -     * @throws Exception when any error happens. FIXME
  +     * @throws MavenException when any error happens.
        */
       public static Project getProject( File projectDescriptor, MavenJellyContext 
parentContext )
  -        throws Exception
  +    throws MavenException
       {
           return getProject( projectDescriptor, parentContext, true );
       }
  @@ -134,19 +137,39 @@
        * @param parentContext the parent context for the new project
        * @param useParentPom whether a parent project should be respected
        * @return the MavenSession project object for the given project descriptor
  -     * @throws Exception when any errors occur - TODO [RC2] bad
  +     * @throws MavenException when any errors occur
        */
       public static Project getProject( File projectDescriptor,
                                         MavenJellyContext parentContext,
                                         boolean useParentPom )
  -        throws Exception
  +    throws MavenException
       {
  -        Project project = getNonJellyProject( projectDescriptor, parentContext, 
useParentPom );
  -        project = getJellyProject( project );
  -        project.setFile( projectDescriptor );
  +        Project project = null;
  +        try 
  +        {
  +            project = getNonJellyProject( projectDescriptor, parentContext, 
useParentPom );
  +            project = getJellyProject( project );
  +            project.setFile( projectDescriptor );
   
  -        // Fully initialize the project.
  -        project.initialize();
  +            // Fully initialize the project.
  +            project.initialize();
  +        }
  +        catch (IntrospectionException e)
  +        {
  +            throw new MavenException("Error creating a string from the project", e);
  +        }
  +        catch (IOException e)
  +        {
  +            throw new MavenException("Error reading XML or initializing", e);
  +        }
  +        catch (ParserConfigurationException e)
  +        {
  +            throw new MavenException("Error creating a JAXP Parser", e);
  +        }
  +        catch (SAXException e)
  +        {
  +            throw new MavenException("Error parsing XML", e);
  +        }
   
           return project;
       }
  @@ -172,15 +195,24 @@
        * @param parentContext the parent context for the new project
        * @param useParentPom whether a parent project should be respected
        * @return the project
  -     * @throws Exception when any errors occur - TODO [RC2] bad
  +     * @throws MavenException when there are errors reading the descriptor
  +     * @throws IOException when resolving file names and paths
        */
       private static Project getNonJellyProject( File projectDescriptor,
                                                  MavenJellyContext parentContext,
  -                                               boolean useParentPom )
  -        throws Exception
  +                                               boolean useParentPom ) 
  +    throws MavenException, IOException
       {
           // 1)
  -        Project project = (Project) getProjectBeanReader().parse( projectDescriptor 
);
  +        Project project = null;
  +        try
  +        {
  +                     project = (Project) getProjectBeanReader().parse( 
projectDescriptor );
  +        }
  +        catch (Exception e)
  +        {
  +             throw new MavenException("Error parsing project.xml '" + 
projectDescriptor.getAbsolutePath() + "'");
  +        }
   
           // 2)
           MavenJellyContext context = MavenUtils.createContext( 
projectDescriptor.getParentFile(), parentContext );
  @@ -233,10 +265,10 @@
        * @param includes the pattern that matches a project that you want included
        * @param excludes the pattern that matches a project that you don't want 
included
        * @return a {link List} of [EMAIL PROTECTED] Project}s
  -     * @throws Exception when anything goes wrong. FIXME this is bad
  +     * @throws MavenException when anything goes wrong.
        */
       public static List getProjects( File directory, String includes, String 
excludes )
  -        throws Exception
  +        throws MavenException
       {
           return getProjects( directory, includes, excludes, null );
       }
  @@ -249,13 +281,13 @@
        * @param excludes Patterns to exclude.
        * @param context  the parent context
        * @return a {link List} of [EMAIL PROTECTED] Project}s
  -     * @throws Exception when anything goes wrong. FIXME this is bad
  +     * @throws MavenException when anything goes wrong. FIXME this is bad
        */
       public static List getProjects( File directory,
                                       String includes,
                                       String excludes,
                                       MavenJellyContext context )
  -        throws Exception
  +        throws MavenException
       {
           String[] files = getFiles( directory, includes, excludes );
   
  @@ -275,10 +307,11 @@
        * to create it more than once.
        *
        * @return a [EMAIL PROTECTED] BeanReader} capable of reading [EMAIL PROTECTED] 
Project projects}
  -     * @throws Exception when anything goes wrong. FIXME this is bad
  +     * @throws IntrospectionException when creating a bean reader
  +     * @throws SAXException when an error occurs parsing the XML
  +     * @throws ParserConfigurationException when a JAXP parser can't be created
        */
  -    private static BeanReader getProjectBeanReader()
  -        throws Exception
  +    private static BeanReader getProjectBeanReader() throws IntrospectionException, 
SAXException, ParserConfigurationException
       {
           if ( projectBeanReader == null )
           {
  @@ -294,10 +327,13 @@
        *
        * @param project the maven POM
        * @return Jelly interpolated project.
  -     * @throws Exception when anything goes wrong. FIXME this is bad
  +     * @throws IntrospectionException when there are errors creating a string from 
the project for interpolation
  +     * @throws SAXException when reading the interpolated POM fails
  +     * @throws IOException when there are errors reading
  +     * @throws ParserConfigurationException when a JAXP parser can't be created
        */
  -    private static Project getJellyProject( Project project )
  -        throws Exception
  +    private static Project getJellyProject( Project project ) 
  +    throws IOException, SAXException, IntrospectionException, 
ParserConfigurationException
       {
           // Keep a copy of the original context
           MavenJellyContext originalContext = project.getContext();
  @@ -331,12 +367,13 @@
        * @param project the project to resolve
        * @param context the context to retrieve variables from
        * @return a project with no unresolved elements.
  -     * @throws Exception when there is an error getting the project as a string
        * @throws IOException if there is an error parsing the project
        * @throws SAXException if there is a sax error parsing the project
  +     * @throws IntrospectionException when there are errors creating a string from 
the project
  +     * @throws ParserConfigurationException when a JAXP parser can't be created
        */
       private static Project getInterpolatedPOM(Project project, JellyContext context)
  -        throws Exception, IOException, SAXException
  +        throws IOException, SAXException, IntrospectionException, 
ParserConfigurationException
       {
           String projectString = getProjectString(project);
           Expression e = JellyUtils.decomposeExpression( projectString, 
mavenExpressionFactory, context );
  @@ -348,12 +385,29 @@
       /**
        * @return an [EMAIL PROTECTED] InputStream} for the given project
        * @param project a [EMAIL PROTECTED] Project maven project}
  -     * @throws Exception when anything goes wrong. FIXME this is bad
  +     * @throws IOException when reading the string fails
  +     * @throws SAXException when parsing the interpolated POM fails
  +     * @throws IntrospectionException when writing the POM to XML
        */
       public static InputStream getProjectInputStream( Project project )
  -        throws Exception
  +    throws MavenException
       {
  -        return new StringInputStream( getProjectString( project ) );
  +        try
  +        {
  +            return new StringInputStream( getProjectString( project ) );
  +        }
  +        catch (IOException e)
  +        {
  +            throw new MavenException("Error writing the project",e);
  +        }
  +        catch (IntrospectionException e)
  +        {
  +            throw new MavenException("Error introspecting the project", e);
  +        }
  +        catch (SAXException e)
  +        {
  +            throw new MavenException("Error parsing the project as XML", e);
  +        }
       }
   
       /**
  @@ -361,10 +415,11 @@
        *
        * @param project MavenSession project to turn into an XML representation.
        * @return XML representation of the project
  -     * @throws Exception when anything goes wrong. FIXME this is bad
  +     * @throws IOException writing the project fails
  +     * @throws IntrospectionException when there are problems writing the project 
bean as a string
  +     * @throws SAXException when there are problems writing the project bean as a 
string
        */
  -    public static String getProjectString( Project project )
  -        throws Exception
  +    private static String getProjectString( Project project ) throws IOException, 
IntrospectionException, SAXException
       {
           ByteArrayOutputStream projectStream = new ByteArrayOutputStream();
           BeanWriter beanWriter = new BeanWriter( projectStream );
  @@ -434,12 +489,12 @@
        *
        * @param clazz the class to register with the reader
        * @return a [EMAIL PROTECTED] BeanReader bean reader}
  -     * @throws Exception when an error occurs trying to determine
  -     *      properties of the class provided
  -     * @throws Exception when anything goes wrong. FIXME this is bad
  +     * @throws IntrospectionException when there are errors registering the 
provided class
  +     * @throws SAXException when there are errors getting an XML reader
  +     * @throws ParserConfigurationException when there are errors getting an XML 
reader
        */
  -    public static BeanReader createBeanReader( Class clazz )
  -        throws Exception
  +    public static BeanReader createBeanReader( Class clazz ) 
  +    throws IntrospectionException, SAXException, ParserConfigurationException
       {
           BeanReader beanReader = new BeanReader( getXMLReader() );
           beanReader.setRules( new ExtendedBaseRules() );
  @@ -489,10 +544,10 @@
        * Get the XMLReader to use for processing XML related resources.
        *
        * @return an XMLReader which is pooled per thread
  -     * @throws Exception If an error occurs while creating the XMLReader.
  +     * @throws SAXException when the reader can't be created
  +     * @throws ParserConfigurationException when the reader can't be created
        */
  -    public static XMLReader getXMLReader()
  -        throws Exception
  +    public static XMLReader getXMLReader() throws SAXException, 
ParserConfigurationException
       {
           XMLReader parser = (XMLReader) xmlReaderPool.get();
           if ( parser == null )
  @@ -507,10 +562,10 @@
        * Creates a new XMLReader instance
        *
        * @return XMLReader used for parsing XML related maven resource.
  -     * @throws Exception If an error occurs while creating the reader.
  +     * @throws SAXException If there are errors creating the reader
  +     * @throws ParserConfigurationException If there are errors creating the SAX 
parser to use
        */
  -    private static XMLReader createXMLReader()
  -        throws Exception
  +    private static XMLReader createXMLReader() throws SAXException, 
ParserConfigurationException
       {
           SAXParserFactory factory = SAXParserFactory.newInstance();
   
  @@ -767,28 +822,31 @@
   
               if ( context.getVariable( key ) == null )
               {
  -                String literalValue = (String) map.get( key );
  +                value = map.get( key );
   
  -                try
  +                if ( value instanceof String )
                   {
  -                    Expression expr = CompositeExpression.parse( literalValue, 
factory );
  -
  -                    if ( expr != null )
  +                    try
                       {
  -                        value = expr;
  +                        String literalValue = (String) value;
  +                        Expression expr = CompositeExpression.parse( literalValue, 
factory );
  +    
  +                        if ( expr != null )
  +                        {
  +                            value = expr;
  +                        }
  +                        else
  +                        {
  +                            value = literalValue;
  +                        }
                       }
  -                    else
  +                    catch ( Exception e )
                       {
  -                        value = literalValue;
  +                        // do nothing.
  +                        log.debug( "Unexpected error evaluating expression", e );
                       }
  -
  -                    context.setVariable( key, value );
  -                }
  -                catch ( Exception e )
  -                {
  -                    // do nothing.
  -                    log.debug("Unexpected error evaluating expression", e);
                   }
  +                context.setVariable( key, value );
               }
           }
       }
  @@ -882,10 +940,8 @@
            * @param namespace the namespace
            * @param name the tag name
            * @param text the body text
  -         * @throws Exception when any errors occur
            */
           public void body(String namespace, String name, String text)
  -            throws Exception
           {
               this.value = text;
           }
  @@ -894,10 +950,8 @@
            * Finish off this element.
            * @param namespace the namespace of the element
            * @param elementName the name of the element
  -         * @throws Exception when any errors occur
            */
           public void end(String namespace, String elementName)
  -            throws Exception
           {
               BaseObject baseObject = (BaseObject) getDigester().peek();
               String name = getDigester().getCurrentElementName();
  
  
  
  No                   revision
  No                   revision
  1.91.4.17 +3 -2      maven/src/java/org/apache/maven/project/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/maven/src/java/org/apache/maven/project/Project.java,v
  retrieving revision 1.91.4.16
  retrieving revision 1.91.4.17
  diff -u -r1.91.4.16 -r1.91.4.17
  --- Project.java      23 Mar 2004 23:43:35 -0000      1.91.4.16
  +++ Project.java      26 Mar 2004 00:18:06 -0000      1.91.4.17
  @@ -34,6 +34,7 @@
   import org.dom4j.io.SAXReader;
   
   import java.io.File;
  +import java.io.IOException;
   import java.io.InputStreamReader;
   import java.util.ArrayList;
   import java.util.HashMap;
  @@ -1319,7 +1320,7 @@
        * 
        * @throws Exception If an error occurs during project initialization.
        */
  -    public void initialize() throws Exception
  +    public void initialize() throws IOException
       {
           if ( initialized )
           {
  
  
  

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

Reply via email to