Examples of Enunciate


Examples of org.codehaus.enunciate.main.Enunciate

    //no-op; we do our generation at the build phase...
  }

  @Override
  protected void doCompile() throws EnunciateException, IOException {
    Enunciate enunciate = getEnunciate();
    if (getWebAppConfig() != null && !getWebAppConfig().isDoCompile()) {
      debug("Compilation has been disabled.  No server-side classes will be compiled, nor will any resources be copied.");
      return;
    }

    final File compileDir = getCompileDir();
    if (!enunciate.isUpToDateWithSources(compileDir)) {
      enunciate.compileSources(compileDir);

      if (getWebAppConfig() != null && !getWebAppConfig().getCopyResources().isEmpty()) {
        AntPatternMatcher matcher = new AntPatternMatcher();
        for (CopyResources copyResource : getWebAppConfig().getCopyResources()) {
          String pattern = copyResource.getPattern();
          if (pattern == null) {
            throw new EnunciateException("A pattern must be specified for copying resources.");
          }

          if (!matcher.isPattern(pattern)) {
            warn("'%s' is not a valid pattern.  Resources NOT copied!", pattern);
            continue;
          }

          File basedir;
          if (copyResource.getDir() == null) {
            File configFile = enunciate.getConfigFile();
            if (configFile != null) {
              basedir = configFile.getAbsoluteFile().getParentFile();
            }
            else {
              basedir = new File(System.getProperty("user.dir"));
            }
          }
          else {
            basedir = enunciate.resolvePath(copyResource.getDir());
          }

          for (String file : enunciate.getFiles(basedir, new PatternFileFilter(basedir, pattern, matcher))) {
            enunciate.copyFile(new File(file), basedir, compileDir);
          }
        }
      }
    }
    else {
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

    }
  }

  @Override
  protected void doBuild() throws IOException, EnunciateException {
    Enunciate enunciate = getEnunciate();
    File buildDir = getBuildDir();

    if (!enunciate.isUpToDateWithSources(buildDir)) {
      copyPreBase();

      debug("Building the expanded WAR in %s", buildDir);

      if (getWebAppConfig() != null && !getWebAppConfig().getGlobalServletFilters().isEmpty()) {
        Set<String> allServletNames = new TreeSet<String>();
        for (WebAppFragment fragment : enunciate.getWebAppFragments()) {
          if (fragment.getServlets() != null) {
            for (WebAppComponent servletComponent : fragment.getServlets()) {
              allServletNames.add(servletComponent.getName());
            }
          }
        }
        for (FilterComponent filter : getWebAppConfig().getGlobalServletFilters()) {
          filter.setServletNames(allServletNames);
          filter.setDispatchers(new TreeSet<String>(Arrays.asList("FORWARD", "REQUEST")));
        }
        BaseWebAppFragment fragment = new BaseWebAppFragment("global-servlet-filters");
        fragment.setFilters(getWebAppConfig().getGlobalServletFilters());
        enunciate.addWebAppFragment(fragment);
      }

      for (WebAppFragment fragment : enunciate.getWebAppFragments()) {
        if (fragment.getBaseDir() != null) {
          enunciate.copyDir(fragment.getBaseDir(), buildDir);
        }
      }

      if (getWebAppConfig() == null || getWebAppConfig().isDoCompile()) {
        //copy the compiled classes to WEB-INF/classes.
        File webinf = new File(buildDir, "WEB-INF");
        File webinfClasses = new File(webinf, "classes");
        enunciate.copyDir(getCompileDir(), webinfClasses);
      }

      if (getWebAppConfig() == null || getWebAppConfig().isDoLibCopy()) {
        doLibCopy();
      }
      else {
        debug("Lib copy has been disabled.  No libs will be copied, nor any manifest written.");
      }

      generateWebXml();

      copyPostBase();
    }
    else {
      info("Skipping the build of the expanded war as everything appears up-to-date...");
    }

    //export the expanded application directory.
    enunciate.addArtifact(new FileArtifact(getName(), "app.dir", buildDir));
  }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

  /**
   * Copy the post base.
   */
  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 {
        debug("Extracting postBase zip file %s to %s...", postBase, buildDir);
        enunciate.extractBase(new FileInputStream(postBase), buildDir);
      }
    }
  }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

  /**
   * 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 {
        debug("Extracting preBase zip file %s to %s...", preBase, buildDir);
        enunciate.extractBase(new FileInputStream(preBase), buildDir);
      }
    }
  }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

  /**
   * generates web.xml to WEB-INF. Pass it through a stylesheet, if specified.
   */
  protected void generateWebXml() throws IOException, EnunciateException {
    Enunciate enunciate = getEnunciate();
    File buildDir = getBuildDir();
    File webinf = new File(buildDir, "WEB-INF");
    webinf.mkdirs();
    File destWebXML = new File(webinf, "web.xml");

    File configDir = getGenerateDir();
    File webXML = new File(configDir, "web.xml");
    EnunciateFreemarkerModel model = getModel();
    model.setFileOutputDirectory(configDir);
    try {
      //delayed to the "build" phase to enable modules to supply their web app fragments.
      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());
        Transformer transformer = TransformerFactory.newInstance().newTransformer(source);
        debug("Transforming %s to %s.", mergedWebXml, destWebXML);
        transformer.transform(new StreamSource(new FileReader(mergedWebXml)), new StreamResult(destWebXML));
      }
      catch (TransformerException e) {
        throw new EnunciateException("Error during transformation of the web.xml (stylesheet " + transformURL + ", file " + mergedWebXml + ")", e);
      }
    }
    else {
      enunciate.copyFile(mergedWebXml, destWebXML);
    }
  }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

   * Copies the classpath elements to WEB-INF.
   *
   * @throws java.io.IOException
   */
  protected void doLibCopy() throws IOException {
    Enunciate enunciate = getEnunciate();
    File buildDir = getBuildDir();
    File webinf = new File(buildDir, "WEB-INF");
    File webinfClasses = new File(webinf, "classes");
    File webinfLib = new File(webinf, "lib");

    //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();
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

  @Override
  protected void doPackage() throws EnunciateException, IOException {
    if (getWebAppConfig() == null || getWebAppConfig().isDoPackage()) {
      File buildDir = getBuildDir();
      File warFile = getWarFile();
      Enunciate enunciate = getEnunciate();

      if (!enunciate.isUpToDate(buildDir, warFile)) {
        if (!warFile.getParentFile().exists()) {
          warFile.getParentFile().mkdirs();
        }

        debug("Creating %s", warFile.getAbsolutePath());

        enunciate.zip(warFile, buildDir);
      }
      else {
        info("Skipping war file creation as everything appears up-to-date...");
      }

      enunciate.addArtifact(new FileArtifact(getName(), "war.file", warFile));
    }
    else {
      debug("Packaging has been disabled.  No packaging will be performed.");
    }
  }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

  /**
   * Package-private constructor for testing purposes.
   */
  EnunciateAnnotationProcessor() throws EnunciateException {
    this(new Enunciate(new String[0], new EnunciateConfiguration()));
  }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

  @Override
  protected void doBuild() throws EnunciateException, IOException {
    super.doBuild();

    Enunciate enunciate = getEnunciate();

    File webappDir = getBuildDir();
    webappDir.mkdirs();
    File webinf = new File(webappDir, "WEB-INF");
    getEnunciate().copyDir(getConfigGenerateDir(), webinf);

    BaseWebAppFragment webappFragment = new BaseWebAppFragment(getName());
    webappFragment.setBaseDir(webappDir);
    List<WebAppComponent> servlets = new ArrayList<WebAppComponent>();
    ArrayList<WebAppComponent> filters = new ArrayList<WebAppComponent>();
    for (WsdlInfo wsdlInfo : getModel().getNamespacesToWSDLs().values()) {
      TreeSet<String> urlMappings = new TreeSet<String>();
      for (EndpointInterface endpointInterface : wsdlInfo.getEndpointInterfaces()) {
        WebAppComponent servletComponent = new WebAppComponent();
        servletComponent.setName("jaxws-" + endpointInterface.getServiceName());
        String servletClass = isSpringEnabled() ? "org.codehaus.enunciate.modules.jaxws_ri.WSSpringServlet" : "com.sun.xml.ws.transport.http.servlet.WSServlet";
        servletComponent.setClassname(servletClass);
        String soapPath = String.valueOf(endpointInterface.getMetaData().get("soapPath"));
        if (soapPath != null) {
          servletComponent.setUrlMappings(new TreeSet<String>(Arrays.asList(soapPath)));
          servlets.add(servletComponent);
          urlMappings.add(soapPath);
        }
      }

      String redirectLocation = (String) wsdlInfo.getProperty("redirectLocation");
      if (redirectLocation != null && isUseWsdlRedirectFilter()) {
        WebAppComponent wsdlFilter = new WebAppComponent();
        wsdlFilter.setName("wsdl-redirect-filter-" + wsdlInfo.getId());
        wsdlFilter.setClassname(WSDLRedirectFilter.class.getName());
        wsdlFilter.addInitParam(WSDLRedirectFilter.WSDL_LOCATION_PARAM, redirectLocation);
        wsdlFilter.setUrlMappings(urlMappings);
        filters.add(wsdlFilter);
      }
    }
    webappFragment.setServlets(servlets);
    webappFragment.setFilters(filters);
    if (!isSpringEnabled()) {
      webappFragment.setListeners(Arrays.asList("com.sun.xml.ws.transport.http.servlet.WSServletContextListener"));
    }
    enunciate.addWebAppFragment(webappFragment);
  }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

  @Override
  protected void doBuild() throws EnunciateException, IOException {
    super.doBuild();

    Enunciate enunciate = getEnunciate();

    File webappDir = getBuildDir();
    webappDir.mkdirs();
    File webinf = new File(webappDir, "WEB-INF");

    BaseWebAppFragment webappFragment = new BaseWebAppFragment(getName());
    webappFragment.setBaseDir(webappDir);

    ArrayList<WebAppComponent> servlets = new ArrayList<WebAppComponent>();
    ArrayList<WebAppComponent> filters = new ArrayList<WebAppComponent>();
    if (enableJaxws) {
      //jax-ws servlet config.
      WebAppComponent jaxwsServletComponent = new WebAppComponent();
      jaxwsServletComponent.setName("cxf-jaxws");
      jaxwsServletComponent.setClassname(CXFServlet.class.getName());
      TreeSet<String> jaxwsUrlMappings = new TreeSet<String>();
      for (WsdlInfo wsdlInfo : getModel().getNamespacesToWSDLs().values()) {
        TreeSet<String> urlMappingsForNs = new TreeSet<String>();
        for (EndpointInterface endpointInterface : wsdlInfo.getEndpointInterfaces()) {
          urlMappingsForNs.add(String.valueOf(endpointInterface.getMetaData().get("soapPath")));
        }
        jaxwsUrlMappings.addAll(urlMappingsForNs);

        String redirectLocation = (String) wsdlInfo.getProperty("redirectLocation");
        if (redirectLocation != null && isUseWsdlRedirectFilter()) {
          WebAppComponent wsdlFilter = new WebAppComponent();
          wsdlFilter.setName("wsdl-redirect-filter-" + wsdlInfo.getId());
          wsdlFilter.setClassname(WSDLRedirectFilter.class.getName());
          wsdlFilter.addInitParam(WSDLRedirectFilter.WSDL_LOCATION_PARAM, redirectLocation);
          wsdlFilter.setUrlMappings(urlMappingsForNs);
          filters.add(wsdlFilter);
        }
      }
      jaxwsServletComponent.setUrlMappings(jaxwsUrlMappings);
      File transform = null;
      if (jaxwsServletTransform != null) {
        transform = enunciate.resolvePath(jaxwsServletTransform);
      }

      transformAndCopy(new File(getGenerateDir(), "cxf-jaxws-servlet.xml"), new File(webinf, "cxf-jaxws-servlet.xml"), transform);
      jaxwsServletComponent.addInitParam("config-location", "/WEB-INF/cxf-jaxws-servlet.xml");
      servlets.add(jaxwsServletComponent);

      WebAppComponent filterComponent = new WebAppComponent();
      filterComponent.setName("cxf-filter");
      filterComponent.setClassname(CXFAdaptedServletFilter.class.getName());
      filterComponent.setUrlMappings(jaxwsUrlMappings);
      filters.add(filterComponent);
    }

    if (enableJaxrs) {
      WebAppComponent jaxrsServletComponent = new WebAppComponent();
      jaxrsServletComponent.setName("cxf-jaxrs");
      jaxrsServletComponent.setClassname(CXFServlet.class.getName());
      TreeSet<String> jaxrsUrlMappings = new TreeSet<String>();
      for (RootResource rootResource : getModel().getRootResources()) {
        for (ResourceMethod resourceMethod : rootResource.getResourceMethods(true)) {
          for (Set<String> subcontextList : ((Map<String, Set<String>>) resourceMethod.getMetaData().get("subcontexts")).values()) {
            for (String subcontext : subcontextList) {
              jaxrsUrlMappings.add(subcontext + "/*");
            }
          }
        }
      }

      jaxrsServletComponent.setUrlMappings(jaxrsUrlMappings);
      File transform = null;
      if (jaxrsServletTransform != null) {
        transform = enunciate.resolvePath(jaxrsServletTransform);
      }

      transformAndCopy(new File(getGenerateDir(), "cxf-jaxrs-servlet.xml"), new File(webinf, "cxf-jaxrs-servlet.xml"), transform);
      jaxrsServletComponent.addInitParam("config-location", "/WEB-INF/cxf-jaxrs-servlet.xml");
      servlets.add(jaxrsServletComponent);
    }
    webappFragment.setServlets(servlets);
    webappFragment.setFilters(filters);
    enunciate.addWebAppFragment(webappFragment);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.