Package org.codehaus.enunciate.config.war

Examples of org.codehaus.enunciate.config.war.WebAppConfig


   */
  protected void copyPostBase() throws IOException {
    Enunciate enunciate = getEnunciate();
    File buildDir = getBuildDir();
    //extract a post base if specified.
    WebAppConfig webAppConfig = getWebAppConfig();
    if ((webAppConfig != null) && (webAppConfig.getPostBase() != null)) {
      File postBase = enunciate.resolvePath(webAppConfig.getPostBase());
      if (postBase.isDirectory()) {
        debug("Copying postBase directory %s to %s...", postBase, buildDir);
        enunciate.copyDir(postBase, buildDir);
      }
      else {
View Full Code Here


   * Copy the pre base.
   */
  protected void copyPreBase() throws IOException {
    Enunciate enunciate = getEnunciate();
    File buildDir = getBuildDir();
    WebAppConfig webAppConfig = getWebAppConfig();
    if ((webAppConfig != null) && (webAppConfig.getPreBase() != null)) {
      File preBase = enunciate.resolvePath(webAppConfig.getPreBase());
      if (preBase.isDirectory()) {
        debug("Copying preBase directory %s to %s...", preBase, buildDir);
        enunciate.copyDir(preBase, buildDir);
      }
      else {
View Full Code Here

      model.put("displayName", model.getEnunciateConfig().getLabel());
      model.put("webAppFragments", enunciate.getWebAppFragments());
      List<WebAppResource> envEntries = Collections.<WebAppResource>emptyList();
      List<WebAppResource> resourceEnvRefs = Collections.<WebAppResource>emptyList();
      List<WebAppResource> resourceRefs = Collections.<WebAppResource>emptyList();
      WebAppConfig webAppConfig = getWebAppConfig();
      if (webAppConfig != null) {
        envEntries = webAppConfig.getEnvEntries();
        resourceEnvRefs = webAppConfig.getResourceEnvRefs();
        resourceRefs = webAppConfig.getResourceRefs();
      }
      model.put("envEntries", envEntries);
      model.put("resourceEnvRefs", resourceEnvRefs);
      model.put("resourceRefs", resourceRefs);
      if (webAppConfig != null) {
        model.put("webappAttributes", webAppConfig.getWebXmlAttributes());
      }
      processTemplate(getWebXmlTemplateURL(), model);
    }
    catch (TemplateException e) {
      throw new EnunciateException("Error processing web.xml template file.", e);
    }

    File mergedWebXml = webXML;
    WebAppConfig webAppConfig = getWebAppConfig();
    if ((webAppConfig != null) && (webAppConfig.getMergeWebXMLURL() != null || webAppConfig.getMergeWebXML() != null)) {
      URL webXmlToMerge = webAppConfig.getMergeWebXMLURL();
      if (webXmlToMerge == null) {
        webXmlToMerge = enunciate.resolvePath(webAppConfig.getMergeWebXML()).toURL();
      }

      try {
        Document source1Doc = loadMergeXml(webXmlToMerge.openStream());
        NodeModel.simplify(source1Doc);
        Document source2Doc = loadMergeXml(new FileInputStream(webXML));
        NodeModel.simplify(source2Doc);

        Map<String, String> mergedAttributes = new HashMap<String, String>();
        NamedNodeMap source2Attributes = source2Doc.getDocumentElement().getAttributes();
        for (int i = 0; i < source2Attributes.getLength(); i++) {
          mergedAttributes.put(source2Attributes.item(i).getNodeName(), source2Attributes.item(i).getNodeValue());
        }
        NamedNodeMap source1Attributes = source1Doc.getDocumentElement().getAttributes();
        for (int i = 0; i < source1Attributes.getLength(); i++) {
          mergedAttributes.put(source1Attributes.item(i).getNodeName(), source1Attributes.item(i).getNodeValue());
        }

        model.put("source1", NodeModel.wrap(source1Doc.getDocumentElement()));
        model.put("source2", NodeModel.wrap(source2Doc.getDocumentElement()));
        model.put("mergedAttributes", mergedAttributes);
        processTemplate(getMergeWebXmlTemplateURL(), model);
      }
      catch (TemplateException e) {
        throw new EnunciateException("Error while merging web xml files.", e);
      }

      File mergeTarget = new File(getGenerateDir(), "merged-web.xml");
      if (!mergeTarget.exists()) {
        throw new EnunciateException("Error: " + mergeTarget + " doesn't exist.");
      }

      debug("Merged %s and %s into %s...", webXmlToMerge, webXML, mergeTarget);
      mergedWebXml = mergeTarget;
    }

    if ((webAppConfig != null) && (webAppConfig.getWebXMLTransformURL() != null || webAppConfig.getWebXMLTransform() != null)) {
      URL transformURL = webAppConfig.getWebXMLTransformURL();
      if (transformURL == null) {
        transformURL = enunciate.resolvePath(webAppConfig.getWebXMLTransform()).toURI().toURL();
      }

      debug("web.xml transform has been specified as %s.", transformURL);
      try {
        StreamSource source = new StreamSource(transformURL.openStream());
View Full Code Here

    //initialize the include filters.
    AntPatternMatcher pathMatcher = new AntPatternMatcher();
    pathMatcher.setPathSeparator(File.separator);
    List<File> explicitIncludes = new ArrayList<File>();
    List<String> includePatterns = new ArrayList<String>();
    WebAppConfig webAppConfig = getWebAppConfig();
    if (webAppConfig != null) {
      for (IncludeExcludeLibs el : webAppConfig.getIncludeLibs()) {
        if (el.getFile() != null) {
          //add explicit files to the include files list.
          explicitIncludes.add(el.getFile());
        }

        String pattern = el.getPattern();
        if (pattern != null) {
          //normalize the pattern to the platform.
          pattern = pattern.replace('/', File.separatorChar);
          if (pathMatcher.isPattern(pattern)) {
            //make sure that the includes pattern list only has patterns.
            includePatterns.add(pattern);
          }
          else {
            warn("Pattern '%s' is not a valid pattern, so it will not be applied.", pattern);
          }
        }
      }
    }

    if (includePatterns.isEmpty()) {
      //if no include patterns are specified, the implicit pattern is "**/*".
      String starPattern = "**" + File.separatorChar + "*";
      debug("No include patterns have been specified.  Using the implicit '%s' pattern.", starPattern);
      includePatterns.add(starPattern);
    }

    List<String> warLibs = new ArrayList<String>();
    if (webAppConfig == null || webAppConfig.isIncludeClasspathLibs()) {
      debug("Using the Enunciate classpath as the initial list of libraries to be passed through the include/exclude filter.");
      //prime the list of libs to include in the war with what's on the enunciate classpath.
      warLibs.addAll(Arrays.asList(enunciate.getEnunciateRuntimeClasspath().split(File.pathSeparator)));
    }

    // Apply the "in filter" (i.e. the filter that specifies the files to be included).
    List<File> includedLibs = new ArrayList<File>();
    for (String warLib : warLibs) {
      File libFile = new File(warLib);
      if (libFile.exists()) {
        for (String includePattern : includePatterns) {
          String absolutePath = libFile.getAbsolutePath();
          if (absolutePath.startsWith(File.separator)) {
            //lob off the beginning "/" for Linux boxes.
            absolutePath = absolutePath.substring(1);
          }
          if (pathMatcher.match(includePattern, absolutePath)) {
            debug("Library '%s' passed the include filter. It matches pattern '%s'.", libFile.getAbsolutePath(), includePattern);
            includedLibs.add(libFile);
            break;
          }
          else if (enunciate.isDebug()) {
            debug("Library '%s' did NOT match include pattern '%s'.", includePattern);
          }
        }
      }
    }

    //Now, with what's left, apply the "exclude filter".
    boolean excludeDefaults = webAppConfig == null || webAppConfig.isExcludeDefaultLibs();
    List<String> manifestClasspath = new ArrayList<String>();
    Iterator<File> toBeIncludedIt = includedLibs.iterator();
    while (toBeIncludedIt.hasNext()) {
      File toBeIncluded = toBeIncludedIt.next();
      if (excludeDefaults && knownExclude(toBeIncluded)) {
        toBeIncludedIt.remove();
      }
      else if (webAppConfig != null) {
        for (IncludeExcludeLibs excludeLibs : webAppConfig.getExcludeLibs()) {
          boolean exclude = false;
          if ((excludeLibs.getFile() != null) && (excludeLibs.getFile().equals(toBeIncluded))) {
            exclude = true;
            debug("%s was explicitly excluded.", toBeIncluded);
          }
          else {
            String pattern = excludeLibs.getPattern();
            if (pattern != null) {
              pattern = pattern.replace('/', File.separatorChar);
              if (pathMatcher.isPattern(pattern)) {
                String absolutePath = toBeIncluded.getAbsolutePath();
                if (absolutePath.startsWith(File.separator)) {
                  //lob off the beginning "/" for Linux boxes.
                  absolutePath = absolutePath.substring(1);
                }

                if (pathMatcher.match(pattern, absolutePath)) {
                  exclude = true;
                  debug("%s was excluded because it matches pattern '%s'", toBeIncluded, pattern);
                }
              }
            }
          }

          if (exclude) {
            toBeIncludedIt.remove();
            if ((excludeLibs.isIncludeInManifest()) && (!toBeIncluded.isDirectory())) {
              //include it in the manifest anyway.
              manifestClasspath.add(toBeIncluded.getName());
              debug("'%s' will be included in the manifest classpath.", toBeIncluded.getName());
            }
            break;
          }
        }
      }
    }

    //now add the lib files that are explicitly included.
    includedLibs.addAll(explicitIncludes);

    //now we've got the final list, copy the libs.
    for (File includedLib : includedLibs) {
      if (includedLib.isDirectory()) {
        debug("Adding the contents of %s to WEB-INF/classes.", includedLib);
        enunciate.copyDir(includedLib, webinfClasses);
      }
      else {
        debug("Including %s in WEB-INF/lib.", includedLib);
        enunciate.copyFile(includedLib, includedLib.getParentFile(), webinfLib);
      }
    }

    // write the manifest file.
    Manifest manifest = webAppConfig == null ? WebAppConfig.getDefaultManifest() : webAppConfig.getManifest();
    if ((manifestClasspath.size() > 0) && (manifest.getMainAttributes().getValue("Class-Path") == null)) {
      StringBuilder manifestClasspathValue = new StringBuilder();
      Iterator<String> manifestClasspathIt = manifestClasspath.iterator();
      while (manifestClasspathIt.hasNext()) {
        String entry = manifestClasspathIt.next();
View Full Code Here

   * The war file to create.
   *
   * @return The war file to create.
   */
  public File getWarFile() {
    WebAppConfig config = getWebAppConfig();
    if (config != null && config.getWar() != null) {
      return getEnunciate().resolvePath(config.getWar());
    }
    else {
      String filename = "enunciate.war";
      if (getEnunciate().getConfig().getLabel() != null) {
        filename = getEnunciate().getConfig().getLabel() + ".war";
View Full Code Here

  }

  @Override
  public File getBuildDir() {
    File buildDir = null;
    WebAppConfig webAppConfig = getWebAppConfig();
    if (webAppConfig != null && webAppConfig.getDir() != null) {
      buildDir = getEnunciate().resolvePath(webAppConfig.getDir());
      buildDir.mkdirs();
    }
    return buildDir == null ? super.getBuildDir() : buildDir;
  }
View Full Code Here

  }

  @Override
  protected void postProcessConfig(EnunciateConfiguration config) {
    super.postProcessConfig(config);
    WebAppConfig webAppConfig = config.getWebAppConfig();
    if (webAppConfig == null) {
      webAppConfig = new WebAppConfig();
      config.setWebAppConfig(webAppConfig);
    }
    webAppConfig.setDoCompile(false);
    webAppConfig.setDoLibCopy(false);
    webAppConfig.setDoPackage(false);
    webAppConfig.setDir(new File(webappDirectory).getAbsolutePath());
  }
View Full Code Here

  }

  @Override
  protected EnunciateConfiguration createEnunciateConfiguration() {
    EnunciateConfiguration config = super.createEnunciateConfiguration();
    WebAppConfig webAppConfig = config.getWebAppConfig();
    if (webAppConfig == null) {
      webAppConfig = new WebAppConfig();
      config.setWebAppConfig(webAppConfig);
    }
    webAppConfig.setDisabled(true);
    return config;
  }
View Full Code Here

    }
  }

  @Override
  public void doFreemarkerGenerate() throws IOException, TemplateException {
    WebAppConfig webAppConfig = enunciate.getConfig().getWebAppConfig();
    if (webAppConfig == null) {
      webAppConfig = new WebAppConfig();
      enunciate.getConfig().setWebAppConfig(webAppConfig);
    }
    webAppConfig.addWebXmlAttribute("version", "3.0");
    webAppConfig.addWebXmlAttribute("xmlns", "http://java.sun.com/xml/ns/javaee");
    webAppConfig.addWebXmlAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    webAppConfig.addWebXmlAttribute("xsi:schemaLocation", "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd");
  }
View Full Code Here

TOP

Related Classes of org.codehaus.enunciate.config.war.WebAppConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.