jvanzyl     02/05/30 05:02:47

  Modified:    src/java/org/apache/maven MavenUtils.java
  Log:
  - Using betwixt and not the mapper now
  
    Created some utility methods for creating project, profiles and workspaces.
    All the mapping is now performed by betwixt.
  
  Revision  Changes    Path
  1.19      +71 -39    jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java
  
  Index: MavenUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- MavenUtils.java   29 May 2002 13:46:24 -0000      1.18
  +++ MavenUtils.java   30 May 2002 12:02:47 -0000      1.19
  @@ -71,8 +71,6 @@
   import org.apache.commons.betwixt.io.BeanWriter;
   import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
   
  -import org.apache.commons.xo.Mapper;
  -
   import org.apache.tools.ant.DirectoryScanner;
   
   /**
  @@ -80,7 +78,7 @@
    * necessary patternsets and paths required to build the project.
    *
    * @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: MavenUtils.java,v 1.18 2002/05/29 13:46:24 jvanzyl Exp $
  + * @version $Id: MavenUtils.java,v 1.19 2002/05/30 12:02:47 jvanzyl Exp $
    */
   public class MavenUtils
   {
  @@ -89,6 +87,34 @@
        */
       private final static String PROJECT_CLASS =
           "org.apache.maven.project.Project";
  +    
  +    /**
  +     * Create a BeanReader that is setup to parse XML in the
  +     * standard Maven/Turbine format.
  +     *
  +     * @param clazz Class that the XML is mapped to
  +     * @return An initialized BeanReader
  +     */
  +    public static BeanReader createBeanReader(Class clazz)
  +        throws Exception
  +    {
  +        XMLIntrospector introspector = new XMLIntrospector();
  +
  +        // set elements for attributes to true
  +        introspector.setAttributesForPrimitives(false);
  +
  +        // wrap collections in an XML element
  +        //introspector.setWrapCollectionsInElement(true);
  +
  +        // turn bean elements into lower case
  +        introspector.setNameMapper(new DecapitalizeNameMapper());
  +
  +        BeanReader reader = new BeanReader();
  +        reader.setXMLIntrospector(introspector);
  +        reader.registerBeanClass(clazz);
  +        
  +        return reader;
  +    }
   
       /**
        * Create a Project object given a file descriptor.
  @@ -113,31 +139,39 @@
       public static Project getProject(File projectDescriptor)
           throws Exception
       {
  -        Mapper mapper = new Mapper();
  -        Project project = (Project) mapper.map(projectDescriptor,
  -            PROJECT_CLASS);
  +        BeanReader reader = createBeanReader(Project.class);
  +        Project project = (Project) reader.parse(new 
FileInputStream(projectDescriptor));
  +        
           return project;
  +    }
   
  -        /*
  -        XMLIntrospector introspector = new XMLIntrospector();
  -
  -        // set elements for attributes to true
  -        introspector.setAttributesForPrimitives(false);
  -
  -        // wrap collections in an XML element
  -        //introspector.setWrapCollectionsInElement(true);
  -
  -        // turn bean elements into lower case
  -        introspector.setNameMapper(new DecapitalizeNameMapper());
  -
  -        BeanReader reader = new BeanReader();
  -        reader.setXMLIntrospector(introspector);
  -        reader.registerBeanClass(Project.class);
  +    /**
  +     * Create a Profile object given a file descriptor.
  +     *
  +     * @param profileDescriptor A reactor profile
  +     * @return the Maven profile object for the given profile descriptor
  +     * @throws Exception when any errors occur
  +     */
  +    public static Profile getProfile(String profileDescriptor)
  +        throws Exception
  +    {
  +        return getProfile(new File(profileDescriptor));
  +    }
   
  -        Project project = (Project) reader.parse(new 
FileInputStream(projectDescriptor));
  +    /**
  +     * Create a Profile object given a file descriptor.
  +     *
  +     * @param profileDescriptor a maven profile descriptor
  +     * @return the Maven profile object for the given profile descriptor
  +     * @throws Exception when any errors occur
  +     */
  +    public static Profile getProfile(File profileDescriptor)
  +        throws Exception
  +    {
  +        BeanReader reader = createBeanReader(Profile.class);
  +        Profile profile = (Profile) reader.parse(new 
FileInputStream(profileDescriptor));
           
  -        return project;
  -        */
  +        return profile;
       }
   
       /**
  @@ -174,17 +208,16 @@
                                            File mavenLocalRepo)
           throws Exception
       {
  -        // Create our workspace
  -        Mapper workspaceMapper = new Mapper();
  -        Workspace workspace = (Workspace) workspaceMapper.map(
  -            workspaceDescriptor, Workspace.class.getName());
  -
  -        // Create our profile
  -        Mapper profileMapper = new Mapper();
  -        Profile profile = (Profile) profileMapper.map(profileDescriptor,
  -            Profile.class.getName());
  +        // Create our workspace.
  +        BeanReader workspaceReader = createBeanReader(Workspace.class);
  +        Workspace workspace = (Workspace) workspaceReader.parse(new 
FileInputStream(workspaceDescriptor));
  +        
  +        // Create our profile.
  +        Profile profile = getProfile(profileDescriptor);
  +        
  +        // Set the workspace profile.
           workspace.setProfile(profile);
  -
  +        
           // Create our set of project.
           for (Iterator i = profile.getProjectIds().iterator(); i.hasNext(); )
           {
  @@ -192,14 +225,13 @@
               // This should take care of any trailing slashes, or the directory
               // formatted in any arbitrary fashion. I don't want to expect a
               // particular format because people do everything different.
  -            File baseDir = new File(new File(mavenLocalRepo, "project"),
  -                projectId);
  +            File baseDir = new File(new File(mavenLocalRepo, "project"), 
  +                                    projectId);
               File projectDescriptor = new File(baseDir, "project.xml");
   
               // Map the project descriptors and add them to the profile.
  -            Mapper projectMapper = new Mapper();
  -            Project project = (Project) projectMapper.map(projectDescriptor,
  -                Project.class.getName());
  +            Project project = getProject(projectDescriptor);
  +            
               profile.addProject(project);
           }
   
  
  
  

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

Reply via email to