 
                        
        
                        
        org.apache.myfaces.trinidadbuild.plugin.jdeveloper.JDeveloperMojo Maven / Gradle / Ivy
/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
package org.apache.myfaces.trinidadbuild.plugin.jdeveloper;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.Xpp3DomWriter;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.xml.sax.SAXException;
  /*
   * Important informational note:
   *
   * The following XML code is similar to what would be seen in a pom file
   * under the maven-jdev-plugin tag if Libraries (e.g. JSP Runtime
   * and JSF 1.2) and Distributed Tag Libraries wanted to be added to the .jpr
   * project.
   *
   * What you see below are the defaults that are put in a project's .jpr
   * automatically without specifying anything.  See replaceLibraries(),
   * replaceTagLibraries() and replaceDefaultTagLibraries().
   *
   * Also note that by setting the property "jdev.plugin.add.libraries" to
   * false in a project's pom.xml file, no libraries will be added, default
   * or otherwise.  In kind, setting the property "jdev.plugin.add.taglibs"
   * to false will result in no tag libraries of any kind being added.
   *
   * As you would expect, the default for both of these properties is "true".
   *
   *   
        org.apache.myfaces.trinidadbuild 
        maven-jdev-plugin 
        1.2.4-SNAPSHOT 
        true 
        
          
            JSP Runtime 
            JSF 1.2 
           
          
            
              
                name 
                JSF HTML 
               
              
                version 
                1.2 
               
              
                jspVersion 
                2.1 
               
              
                tld 
                html_basic.tld 
               
              
                URI 
                http://java.sun.com/jsf/html 
               
             
            
              
                name 
                JSF Core 
               
              
                version 
                1.2 
               
              
                jspVersion 
                2.1 
               
              
                tld 
                jsf_core.tld 
               
              
                URI 
                http://java.sun.com/jsf/core 
               
             
           
         
       
 */
/**
 * Generates the JDeveloper Workspace and Projects
 * from a maven development environment.
 * @version $Id$
 * @goal jdev
 * @execute phase=process-resources
 * @requiresDependencyResolution test
 * @description Goal which generates the JDeveloper Workspace and Projects
 *              from a maven development environment.
 */
public class JDeveloperMojo
  extends AbstractMojo
{
  /**
   * Libraries to include in Classpath.
   * @parameter
   */
  private String[] libraries;
  /**
   * List of source root directories
   * @parameter
   */
  private File[] sourceRoots;
  /**
   * Does project have tests? Used to determine if the
   * maven-jdev-plugin needs to create a -test.jpr
   * @parameter expression="${jdev.project.has.tests}" default-value="false"
   */
  private boolean projectHasTests;
  
  /**
   * List of source root directories for the test project
   * @parameter
   */
  private File[] testSourceRoots;
  /**
   * List of resource root directories
   * @parameter
   */
  private File[] resourceRoots;
  /**
   * List of resource root directories for the test project
   * @parameter
   */
  private File[] testResourceRoots;
  /**
   * Force the Mojo to use the default project.xml or
   * workspace.xml file to be used in creation of the
   * workspace file (.jws) or project file (.jpr). Otherwise,
   * if a .jws or .jpr exists, it will be used instead.
   * @parameter expression="${force}" default-value=false
   *
   */
  private boolean force;
  /**
   * Compiler to be used by JDeveloper. "Ojc" is the default.  
   * If this parameter is absent or anything other than "Javac", "Ojc" will
   * be used.
   * @parameter expression="${jdev.compiler}" default-value="Ojc"
   */
  private String compiler;
  /**
   * Make the entire project before each run.  Running anything in the
   * project will automatically trigger a make of the entire project
   * followed by the run.
   * @parameter expression="${jdev.make.project}" default-value="false"
   */
  private boolean makeProject;
  /**
   * Default file to be run when JDeveloper project is run.
   * @parameter expression="${jdev.run.target}"
   */
  private String runTarget;
  /**
   * Create JDeveloper Workspace and Project Files that correspond to
   * the format used
   * @parameter expression="${jdev.release}" default-value="10.1.3.0.4"
   */
  private String release;
  /**
   * Name of the Maven Project
   * @parameter expression="${project}"
   * @required
   * @readonly
   */
  private MavenProject project;
  /**
   * List of reactorProjects
   * @parameter expression="${reactorProjects}"
   * @required
   * @readonly
   */
  private List reactorProjects;
  /**
   * Tag library directory used by each distributed jsf tag library
   *
   * @parameter expression="${jdev.tag.lib.dir}"
   */
  private String tagLibDirectory;
  /**
   * Tag libraries and their properties.
   * @parameter
   */
  private Properties[] distributedTagLibraries;
  /**
   * JVM javaOptions found under 
   * Project Properties->Run/Debug/Profile->Launch Settings->Java Options
   * in JDeveloper. "-ea" is the default for "enableAssertions".  
   * @parameter expression="${jdev.jvm.java.options}" default-value="-ea"
   */
  private String javaOptions;
  /**
   * Execute the Mojo.
   */
  public void execute()
    throws MojoExecutionException
  {
    _parseRelease();
    if (_releaseMajor >= 11)
    {
      tagLibDirectory = 
        "@oracle.home@/modules/oracle.jsf_1.2.9/glassfish.jsf_1.2.9.0.jar!/META-INF";
    }
    else
    {
      tagLibDirectory =
        "@oracle.home@lib/java/shared/oracle.jsf/1.2/jsf-ri.jar!/META-INF";
    }
    
    try
    {
      generateWorkspace();
      generateProject();
      generateTestProject();
    }
    catch (IOException e)
    {
      throw new MojoExecutionException(e.getMessage());
    }
  }
  private void generateWorkspace()
    throws MojoExecutionException, IOException
  {
    if (!project.getCollectedProjects().isEmpty())
    {
      getLog().info("Generating JDeveloper " + release + " workspace: " +
                    project.getArtifactId());
      File workspaceFile = getJWorkspaceFile(project);
      try
      {
        Xpp3Dom workspaceDOM = readWorkspaceDOM(workspaceFile);
        replaceProjects(workspaceFile.getParentFile(), workspaceDOM);
        writeDOM(workspaceFile, workspaceDOM);
      }
      catch (XmlPullParserException e)
      {
        throw new MojoExecutionException("Error generating workspace", e);
      }
    }
  }
  private void generateProject()
    throws IOException, MojoExecutionException
  {
    if (!"pom".equals(project.getPackaging()))
    {
      File projectFile = getJProjectFile(project);
      // Get Project Properties to tell Mojo whether or not to add
      // library refs and taglibs to the project.
      Properties props = project.getProperties();
      String addLibs = (String)props.get(_PROPERTY_ADD_LIBRARY);
      String addTagLibs = (String)props.get(_PROPERTY_ADD_TAGLIBS);
      _addLibraries = (addLibs == null)
        ? true : (new Boolean(addLibs)).booleanValue();
      _addTagLibs   = (addTagLibs == null)
        ? true : (new Boolean(addTagLibs)).booleanValue();
      // TODO: read configuration for war:war goal
      File webappDir = new File(project.getBasedir(), "src/main/webapp");
      // TODO: read configuration for compiler:complie goal
      File outputDir =
        new File(project.getBuild().getDirectory(), "classes");
      MavenProject executionProject = project.getExecutionProject();
      List compileSourceRoots = executionProject.getCompileSourceRoots();
      if (sourceRoots != null)
      {
        for (int i = 0; i < sourceRoots.length; i++)
        {
          compileSourceRoots.add(sourceRoots[i].getAbsolutePath());
        }
      }
      List compileResourceRoots = executionProject.getResources();
      if (resourceRoots != null)
      {
        for (int i = 0; i < resourceRoots.length; i++)
        {
          Resource resource = new Resource();
          resource.setDirectory(resourceRoots[i].getAbsolutePath());
          compileResourceRoots.add(resource);
        }
      }
      getLog().info("Generating JDeveloper " + release + " Project " +
                    project.getArtifactId());
      Set pluginArtifacts = new LinkedHashSet();
      pluginArtifacts.addAll(project.getPluginArtifacts());
      // Note: include "compile", "provided", "system" and "runtime" scopes
      Set compileArtifacts = new LinkedHashSet();
      compileArtifacts.addAll(project.getCompileArtifacts());
      compileArtifacts.addAll(project.getRuntimeArtifacts());
      // Note: separate "runtime" vs. "compile" dependencies in JDeveloper?
      generateProject(projectFile, project.getArtifactId(),
                      project.getPackaging(), project.getDependencies(),
                      new ArrayList(compileArtifacts), compileSourceRoots,
                      compileResourceRoots,
                      Collections.singletonList(webappDir.getPath()),
                      outputDir);
    }
  }
  private void generateTestProject()
    throws IOException, MojoExecutionException
  {
    if (!"pom".equals(project.getPackaging()) && projectHasTests)
    {
      File projectFile = getJProjectTestFile(project);
      // Get Project Properties to tell Mojo whether or not to add
      // library refs and taglibs to the project.
      Properties props = project.getProperties();
      String addLibs = (String)props.get(_PROPERTY_ADD_LIBRARY);
      String addTagLibs = (String)props.get(_PROPERTY_ADD_TAGLIBS);
      _addLibraries = (addLibs == null)
        ? true : (new Boolean(addLibs)).booleanValue();
      _addTagLibs   = (addTagLibs == null)
        ? true : (new Boolean(addTagLibs)).booleanValue();
      File webappDir = new File(project.getBasedir(), "src/test/webapp");
      // TODO: read configuration for compiler:testCompile goal
      File outputDir =
        new File(project.getBuild().getDirectory(), "test-classes");
      // self dependency needed for test project
      List testDependencies = new ArrayList(project.getTestDependencies());
      Dependency selfDependency = new Dependency();
      selfDependency.setArtifactId(project.getArtifactId());
      selfDependency.setGroupId(project.getGroupId());
      selfDependency.setType(project.getPackaging());
      testDependencies.add(selfDependency);
      MavenProject executionProject = project.getExecutionProject();
      List compileSourceRoots =
        executionProject.getTestCompileSourceRoots();
      for (int i = 0; i < testSourceRoots.length; i++)
      {
        compileSourceRoots.add(testSourceRoots[i].getAbsolutePath());
      }
      List compileResourceRoots = executionProject.getTestResources();
      if (testResourceRoots != null)
      {
        for (int i = 0; i < testResourceRoots.length; i++)
        {
          Resource resource = new Resource();
          resource.setDirectory(testSourceRoots[i].getAbsolutePath());
          compileResourceRoots.add(resource);
        }
      }
      getLog().info("Generating JDeveloper " + release + " Project " +
                    project.getArtifactId() + "-test");
      // Note: all artifacts implicitly included in "test" scope
      generateProject(projectFile, project.getArtifactId() + "-test",
                      project.getPackaging(), testDependencies,
                      project.getTestArtifacts(), compileSourceRoots,
                      compileResourceRoots,
                      Collections.singletonList(webappDir.getPath()),
                      outputDir);
    }
  }
  private void generateProject(File projectFile, String projectName,
                               String packaging, List dependencies,
                               List artifacts, List sourceRoots,
                               List resourceRoots, List webSourceRoots,
                               File outputDir)
    throws IOException, MojoExecutionException
  {
    try
    {
      File projectDir = projectFile.getParentFile();
      Xpp3Dom projectDOM = readProjectDOM(projectFile);
      replaceWebappInfo(projectName, projectDOM);
      replaceSourcePaths(projectDir, sourceRoots, resourceRoots,
                         projectDOM);
      //replaceResourcePaths(projectDir, resourceRoots, projectDOM);
      replaceWebSourcePaths(projectDir, webSourceRoots, projectDOM);
      replaceDependencies(projectDir, dependencies, projectDOM);
      replaceLibraries(projectDir, artifacts, projectDOM);
      replaceTagLibraries(projectDOM);
      replaceOutputDirectory(projectDir, outputDir, projectDOM);
      replaceParameters(projectName, projectDOM);
      writeDOM(projectFile, projectDOM);
      /* Not needed in release 11 where .tld files are obtained
      ** From jar's META-INF dir, not in WEB-INF dir as in v10
      */
      if ( (_releaseMajor < 11) && ("war".equals(packaging)) )
        copyTagLibraries(projectDir, dependencies, artifacts);
    }
    catch (XmlPullParserException e)
    {
      throw new MojoExecutionException("Error generating project", e);
    }
  }
  private void replaceProjects(File workspaceDir, Xpp3Dom workspaceDOM)
    throws XmlPullParserException
  {
    // /jws:workspace
    //   /list[@n="listOfChildren"]
    Xpp3Dom sourceDOM = workspaceDOM.getChild("list");
    // 
    //    
    Xpp3Dom targetDOM = new Xpp3Dom("list");
    for (Iterator i = project.getCollectedProjects().iterator(); i.hasNext(); )
    {
      MavenProject collectedProject = (MavenProject) i.next();
      boolean projHasTests = false;
      // Added in V11
      if (_releaseMajor >= 11)
      {
        Properties props = collectedProject.getProperties();
        String hasTests = (String)props.get(_PROPERTY_HAS_TESTS);
        projHasTests = "true".equalsIgnoreCase(hasTests);
      }
      getLog().info("projHasTests is " + Boolean.valueOf(projHasTests).toString());
      // if a child project is also a workspace, then don't 
      // put it in the .jws file.  It will have its own .jws
      // file.
      if (!"pom".equals(collectedProject.getPackaging()))
      {
        File projectFile = getJProjectFile(collectedProject);
        
        targetDOM.addChild(createProjectReferenceDOM(workspaceDir,
                                                     projectFile));
  
        File testProjectFile = getJProjectTestFile(collectedProject);
        /*
        ** In V11, we don't create a -test.jpr if 
        ** a project does not have any tests.
        */
        if (_releaseMajor >= 11)
        {
          if (projHasTests)
          {
            targetDOM.addChild(createProjectReferenceDOM(workspaceDir, 
                                                         testProjectFile));
          }
        }
        else
        {
          targetDOM.addChild(createProjectReferenceDOM(workspaceDir, 
                                                       testProjectFile));
        }      
      }
    }
    // TODO: use a better merge algorithm
    removeChildren(sourceDOM);
    // make sure to pass Boolean.FALSE to allow
    // multiple child elements with the same name
    Xpp3Dom.mergeXpp3Dom(sourceDOM, targetDOM, Boolean.FALSE);
  }
  private void replaceWebSourcePaths(File projectDir, List sourceRoots,
                                     Xpp3Dom projectDOM)
    throws XmlPullParserException
  {
    // /jpr:project
    //   /hash[@n="oracle.jdeveloper.model.J2eeSettings"]
    //     /hash[@n="webContentSet"]
    //       /list[@n="url-path"]
    Xpp3Dom pathsDOM =
      findNamedChild(projectDOM, "hash", "oracle.jdeveloper.model.J2eeSettings");
    Xpp3Dom contentSetDOM =
      findNamedChild(pathsDOM, "hash", "webContentSet");
    Xpp3Dom sourceDOM = findNamedChild(contentSetDOM, "list", "url-path");
    //
    // 
    //   
    //     
// 
    //
    // sort the artifacts
    Collections.sort(artifacts, new Comparator()
        {
          public int compare(Object a, Object b)
          {
            Artifact arta = (Artifact) a;
            Artifact artb = (Artifact) b;
            return arta.getId().compareTo(artb.getId());
          }
        });
    List libraryRefs = new LinkedList();
    for (Iterator i = artifacts.iterator(); i.hasNext(); )
    {
      Artifact artifact = (Artifact) i.next();
      if (!isDependentProject(artifact.getDependencyConflictId()))
      {
        String id = artifact.getId();
        String path = getRelativeFile(projectDir, artifact.getFile());
        // libraryDefinitions entry
        Xpp3Dom hashDOM = new Xpp3Dom("hash");
        Xpp3Dom listDOM = new Xpp3Dom("list");
        listDOM.setAttribute("n", "classPath");
        Xpp3Dom urlDOM = new Xpp3Dom("url");
        urlDOM.setAttribute("path", path);
        urlDOM.setAttribute("jar-entry", "");
        listDOM.addChild(urlDOM);
        hashDOM.addChild(listDOM);
        Xpp3Dom valueDOM = new Xpp3Dom("value");
        valueDOM.setAttribute("n", "deployedByDefault");
        valueDOM.setAttribute("v", "true");
        hashDOM.addChild(valueDOM);
        valueDOM = new Xpp3Dom("value");
        valueDOM.setAttribute("n", "description");
        valueDOM.setAttribute("v", id);
        hashDOM.addChild(valueDOM);
        valueDOM = new Xpp3Dom("value");
        valueDOM.setAttribute("n", "id");
        valueDOM.setAttribute("v", id);
        hashDOM.addChild(valueDOM);
        targetDefsDOM.addChild(hashDOM);
        libraryRefs.add(id);
      }
    }
    // This boolean is set by specifying the jdev.plugin.add.libraries
    // property at the top of a project's pom file.  There are projects
    // that don't need these libraries in their .jpr files to compile and this
    // property allows them to be excluded.
    //
    // IMPORTANT NOTE: if this property is set in a project,
    // then libraries will NOT be added, even though they
    // may be specified under the maven-jdev-plugin.
    if (_addLibraries)
    {
      // Add libraries.  The default libraries can be
      // overridden in the trunk/toplevel pom file.
      if (_releaseMajor >= 11)
      {
        // Add the default libraries
        libraryRefs.add(0,"JSF 1.2");
        libraryRefs.add(0,"JSP Runtime");
      }
      // Add the libraries
      if (libraries != null)
      {
        for (int i = 0; i < libraries.length; i++)
        {
          // Default libraries for release 11 were already
          // added above.
          if (   (_releaseMajor >= 11)
              && (   ("JSF 1.2".equalsIgnoreCase(libraries[i]))
                  || ("JSP Runtime".equalsIgnoreCase(libraries[i]))
                 )
             )
          {
            continue;
          }
          // Add the library
          libraryRefs.add(0, libraries[i]);
        }
      }
    }
    //
    // libraryReferences
    //
    // 
    //    
    //
    Collections.sort(libraryRefs);
    for (Iterator i = libraryRefs.iterator(); i.hasNext(); )
    {
      String id = (String) i.next();
      // libraryReferences entry
      Xpp3Dom hashDOM = new Xpp3Dom("hash");
      Xpp3Dom valueDOM = new Xpp3Dom("value");
      valueDOM.setAttribute("n", "id");
      valueDOM.setAttribute("v", id);
      hashDOM.addChild(valueDOM);
      valueDOM = new Xpp3Dom("value");
      valueDOM.setAttribute("n", "isJDK");
      valueDOM.setAttribute("v", "false");
      hashDOM.addChild(valueDOM);
      targetRefsDOM.addChild(hashDOM);
    }
    // First, add JSP Runtime dependency if src/main/webapp exists
    // TODO: use a better merge algorithm
    removeChildren(sourceDefsDOM);
    removeChildren(sourceRefsDOM);
    // make sure to pass Boolean.FALSE to allow
    // multiple child elements with the same name
    Xpp3Dom.mergeXpp3Dom(sourceDefsDOM, targetDefsDOM, Boolean.FALSE);
    Xpp3Dom.mergeXpp3Dom(sourceRefsDOM, targetRefsDOM, Boolean.FALSE);
  }
  private void replaceLocalTagLibraries(Xpp3Dom targetLibsDOM)
    throws XmlPullParserException
  {
    TldContentHandler tldHandler = new TldContentHandler();
    String path = null;
    // Loop through all the .tld files in the WEB-INF dir
    // Parse each and get the values needed for the TagLibraries
    // hash in the .jpr file.
    try
    {
      File webInfDir =
        new File(project.getBasedir(), "src/main/webapp/WEB-INF");
      if (webInfDir == null)
        return;
      File[] files = webInfDir.listFiles();
      if (files == null)
        return;
      Xpp3Dom hashDOM = null;
      Xpp3Dom valueDOM = null;
      for (int i = 0; i < files.length; i++)
      {
        path = files[i].getPath();
        if (path.endsWith(".tld"))
        {
          hashDOM = new Xpp3Dom("hash");
          // we have a tag library.  Parse it and
          // get the values needed for the .jpr file
          // Parse
          tldHandler.parseTld(files[i]);
          // call gettors to get the values
          valueDOM = new Xpp3Dom("value");
          valueDOM.setAttribute("n", "jspVersion");
          valueDOM.setAttribute("v", tldHandler.getJspVersion());
          hashDOM.addChild(valueDOM);
          valueDOM = new Xpp3Dom("value");
          valueDOM.setAttribute("n", "name");
          valueDOM.setAttribute("v", tldHandler.getName());
          hashDOM.addChild(valueDOM);
          valueDOM = new Xpp3Dom("value");
          valueDOM.setAttribute("n", "prefix");
          valueDOM.setAttribute("v", tldHandler.getPrefix());
          hashDOM.addChild(valueDOM);
          valueDOM = new Xpp3Dom("value");
          valueDOM.setAttribute("n", "tldURL");
          valueDOM.setAttribute("v",
            "WEB-INF/" + path.substring(path.indexOf("WEB-INF") +  8));
          hashDOM.addChild(valueDOM);
          valueDOM = new Xpp3Dom("value");
          valueDOM.setAttribute("n", "URI");
          valueDOM.setAttribute("v", tldHandler.getURI());
          hashDOM.addChild(valueDOM);
          valueDOM = new Xpp3Dom("value");
          valueDOM.setAttribute("n", "version");
          valueDOM.setAttribute("v", tldHandler.getVersion());
          hashDOM.addChild(valueDOM);
          // Add each file's hash to the tag-libraries "list"
          targetLibsDOM.addChild(hashDOM);
        } // endif
      } // endfor
      return;
    }
    catch (SAXException saxex)
    {
      getLog().info("SAX Parse Exception parsing " + path + ": " +
                    saxex.getMessage(), saxex);
    }
    catch (IOException ioe)
    {
      getLog().info("Unable to open an InputStream to " + path, ioe);
    }
    catch (ParserConfigurationException pce)
    {
      getLog().info("Unable to create SAX parser for " + path, pce);
    }
  }
  private void replaceTagLibraries(Xpp3Dom projectDOM)
    throws XmlPullParserException
  {
    // This boolean is set by specifying the jdev.plugin.add.taglibs
    // property at the top of a project's pom file.  There are projects
    // that don't need taglibs in their .jpr files to compile and this
    // allows them to be excluded.
    if (!_addTagLibs)
      return;
    // /jpr:project
    //   /hash[@n="oracle.jdevimpl.webapp.jsp.libraries.model.ProjectTagLibraries"]
    //       /list[@n="tag-libaries"]
    Xpp3Dom projectTagsDOM =
      findNamedChild(projectDOM, "hash", "oracle.jdevimpl.webapp.jsp.libraries.model.ProjectTagLibraries");
    Xpp3Dom tagLibsDOM =
      findNamedChild(projectTagsDOM, "list", "tag-libraries");
    Xpp3Dom targetLibsDOM = new Xpp3Dom("list");
    //
    // tagLibraryDefinitions
    //
    //
    //  
    //     
    //   
    //
    // Parent "hash"
    Xpp3Dom hashDOM = null;
    //  0)
    {
      // Process each distributed Tag Library
      for (int i = 0; i < distributedTagLibraries.length; i++)
      {
        Properties disTagLib = distributedTagLibraries[i];
        String nameName = null;
        String nameValue = null;
        String versionName = null;
        String versionValue = null;
        // Create parent hash for each taglib
        hashDOM = new Xpp3Dom("hash");
        // baseLibrary "hash" for each taglib
        Xpp3Dom hashBaseDOM = new Xpp3Dom("hash");
        hashBaseDOM.setAttribute("n", "baseLibrary");
        // Add baseLibrary hash to parent hash
        hashDOM.addChild(hashBaseDOM);
        // Process each property of the taglib
        for (Enumeration keys = disTagLib.propertyNames();
             keys.hasMoreElements(); )
        {
          // Get the name value pair
          String name = (String) keys.nextElement();
          String value = (String) disTagLib.get(name);
          // Put the name and version values
          // inside the baseLibrary hash.
          // This only happens once per taglib
          if ("name".equals(name))
          {
            nameName = name;
            nameValue = value;
            // n="name, v= in baseLibrary
            valueDOM = new Xpp3Dom("value");
            valueDOM.setAttribute("n", name);
            valueDOM.setAttribute("v", value);
            hashBaseDOM.addChild(valueDOM);
            // Duplicate the "name"   in baseLibrary
            valueDOM = new Xpp3Dom("value");
            valueDOM.setAttribute("n", name);
            valueDOM.setAttribute("v", value);
            hashBaseDOM.addChild(valueDOM);
            // Duplicate the "version"  in parent hash
            valueDOM = new Xpp3Dom("value");
            valueDOM.setAttribute("n", versionName);
            valueDOM.setAttribute("v", versionValue);
            hashDOM.addChild(valueDOM);
          }
          else
          {
            if ("tld".equals(name))
            {
              // Did not want to have a URL in the pom file.
              // I just wanted the user to specify the name
              // of the tld file.  So we fix it for JDev
              // here.
              name += "URL";
              value = tagLibDirectory + "/" + value;
            }
            valueDOM = new Xpp3Dom("value");
            valueDOM.setAttribute("n", name);
            valueDOM.setAttribute("v", value);
            hashDOM.addChild(valueDOM);
          }
        } //endfor processing each property
        // We are done with this disTagLib
        // Add it to the targetLibsDOM
        if (hashDOM != null)
          targetLibsDOM.addChild(hashDOM);
      } // endfor processing each distributed tag lib
    } //endif
    else
    {
      // Use Default tag library configuration.  See comment before
      // replaceTagLibraries.
      replaceDefaultTagLibraries(projectDOM, targetLibsDOM);
    }
    // Generate .jpr entries from the .tld files in the project's
    // src/main/webapp/WEB-INF directory.
    replaceLocalTagLibraries(targetLibsDOM);
    // First, add JSP Runtime dependency if src/main/webapp exists
    // TODO: use a better merge algorithm
    removeChildren(tagLibsDOM);
    // make sure to pass Boolean.FALSE to allow
    // multiple child elements with the same name
    Xpp3Dom.mergeXpp3Dom(tagLibsDOM, targetLibsDOM, Boolean.FALSE);
  }
  private void replaceDefaultTagLibraries(Xpp3Dom projectDOM,
                                          Xpp3Dom targetLibsDOM)
    throws XmlPullParserException
  {
    // Begin JSF HTML Tag lib
    Xpp3Dom hashDOM     = new Xpp3Dom("hash");
    Xpp3Dom hashBaseDOM = new Xpp3Dom("hash");
    Xpp3Dom valueDOM    = null;
    hashBaseDOM.setAttribute("n", "baseLibrary");
    // Add baseLibrary hash to parent hash
    hashDOM.addChild(hashBaseDOM);
    // Create parent hash for each taglib
    //        hashDOM = new Xpp3Dom("hash");
    // baseLibrary "hash" for each taglib
    // Xpp3Dom hashBaseDOM = new Xpp3Dom("hash");
    //        hashBaseDOM.setAttribute("n", "baseLibrary");
    // n="name, v= in baseLibrary
    valueDOM = new Xpp3Dom("value");
    valueDOM.setAttribute("n", "name");
    valueDOM.setAttribute("v", "JSF HTML");
    hashBaseDOM.addChild(valueDOM);
    // Duplicate the "name"   in baseLibrary
    valueDOM = new Xpp3Dom("value");
    valueDOM.setAttribute("n", "version");
    valueDOM.setAttribute("v", "1.2");
    hashBaseDOM.addChild(valueDOM);
    // Duplicate the "version"  in baseLibrary
    valueDOM = new Xpp3Dom("value");
    valueDOM.setAttribute("n", "version");
    valueDOM.setAttribute("v", "1.2");
    hashBaseDOM.addChild(valueDOM);
    // Duplicate the "version" = 11) && (projectName != null))
    {
      replaceCompiler(projectDOM);
      replaceMakeProjectAndRunTarget(projectDOM);
    }
  }
  private void replaceCompiler(Xpp3Dom projectDOM)
    throws XmlPullParserException
  {
    // /jpr:project
    // 
    //   
    //      
           © 2015 - 2025 Weber Informatics LLC | Privacy Policy