Examples of Enunciate


Examples of org.codehaus.enunciate.main.Enunciate

  /**
   * Builds the base output directory.
   */
  protected void buildBase() throws IOException {
    Enunciate enunciate = getEnunciate();
    File buildDir = getDocsBuildDir();
    buildDir.mkdirs();
    if (this.base == null) {
      InputStream discoveredBase = DocumentationDeploymentModule.class.getResourceAsStream("/META-INF/enunciate/docs-base.zip");
      if (discoveredBase == null) {
        debug("Default base to be used for documentation base.");
        enunciate.extractBase(loadDefaultBase(), buildDir);

        URL discoveredCss = DocumentationDeploymentModule.class.getResource("/META-INF/enunciate/css/style.css");
        if (discoveredCss != null) {
          enunciate.copyResource(discoveredCss, new File(new File(buildDir, "css"), "style.css"));
        }
        else if (this.css != null) {
          enunciate.copyFile(enunciate.resolvePath(this.css), new File(new File(buildDir, "css"), "style.css"));
        }
      }
      else {
        debug("Discovered documentation base at /META-INF/enunciate/docs-base.zip");
        enunciate.extractBase(discoveredBase, buildDir);
      }
    }
    else {
      File baseFile = enunciate.resolvePath(this.base);
      if (baseFile.isDirectory()) {
        debug("Directory %s to be used as the documentation base.", baseFile);
        enunciate.copyDir(baseFile, buildDir);
      }
      else {
        debug("Zip file %s to be extracted as the documentation base.", baseFile);
        enunciate.extractBase(new FileInputStream(baseFile), buildDir);
      }
    }

    for (SchemaInfo schemaInfo : getModel().getNamespacesToSchemas().values()) {
      if (schemaInfo.getProperty("file") != null) {
        File from = (File) schemaInfo.getProperty("file");
        String filename = schemaInfo.getProperty("filename") != null ? (String) schemaInfo.getProperty("filename") : from.getName();
        File to = new File(getDocsBuildDir(), filename);
        enunciate.copyFile(from, to);
      }
    }

    for (WsdlInfo wsdlInfo : getModel().getNamespacesToWSDLs().values()) {
      if (wsdlInfo.getProperty("file") != null) {
        File from = (File) wsdlInfo.getProperty("file");
        String filename = wsdlInfo.getProperty("filename") != null ? (String) wsdlInfo.getProperty("filename") : from.getName();
        File to = new File(getDocsBuildDir(), filename);
        enunciate.copyFile(from, to);
      }
    }

    File wadlFile = getModelInternal().getWadlFile();
    if (wadlFile != null) {
      enunciate.copyFile(wadlFile, new File(getDocsBuildDir(), wadlFile.getName()));
    }

    HashSet<String> explicitArtifacts = new HashSet<String>();
    TreeSet<Artifact> downloads = new TreeSet<Artifact>();
    for (DownloadConfig download : this.downloads) {
      if (download.getArtifact() != null) {
        explicitArtifacts.add(download.getArtifact());
      }
      else if (download.getFile() != null) {
        File downloadFile = enunciate.resolvePath(download.getFile());

        debug("File %s to be added as an extra download.", downloadFile.getAbsolutePath());
        DownloadBundle downloadArtifact = new DownloadBundle(getName(), downloadFile.getName(), downloadFile);

        if (download.getName() != null) {
          downloadArtifact.setName(download.getName());
        }

        if (download.getDescription() != null) {
          downloadArtifact.setDescription(download.getDescription());
        }

        if(download.getShowLink().equals("false")){
          debug("Exporting %s to directory %s.", downloadArtifact.getId(), buildDir);
          downloadArtifact.exportTo(buildDir, enunciate);
        } else {
          downloads.add(downloadArtifact);
        }

      }
    }

    for (Artifact artifact : enunciate.getArtifacts()) {
      if (((artifact instanceof NamedArtifact) && (includeDefaultDownloads)) || (explicitArtifacts.contains(artifact.getId()))) {
        if (artifact.isPublic()) {
          downloads.add(artifact);
        }

        debug("Artifact %s to be added as an extra download.", artifact.getId());
        explicitArtifacts.remove(artifact.getId());
      }
    }

    if (explicitArtifacts.size() > 0) {
      for (String artifactId : explicitArtifacts) {
        warn("WARNING: Unknown artifact '%s'.  Will not be available for download.", artifactId);
      }
    }

    for (Artifact download : downloads) {
      debug("Exporting %s to directory %s.", download.getId(), buildDir);
      download.exportTo(buildDir, enunciate);     
    }

    Set<String> additionalCssFiles = new HashSet<String>();
    for (String additionalCss : getAdditionalCss()) {
      File additionalCssFile = enunciate.resolvePath(additionalCss);
      debug("File %s to be added as an additional css file.", additionalCss);
      enunciate.copyFile(additionalCssFile, new File(buildDir, additionalCssFile.getName()));
      additionalCssFiles.add(additionalCssFile.getName());
    }

    EnunciateFreemarkerModel model = getModel();
    model.put("downloads", downloads);
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

    if (!skip) {
      if (moduleName == null) {
        throw new MojoExecutionException("A module name must be specified in order to check whether it's disabled.");
      }

      Enunciate enunciate = (Enunciate) getPluginContext().get(ConfigMojo.ENUNCIATE_PROPERTY);
      if (enunciate == null) {
        throw new MojoExecutionException("Enunciate mechanism not initialized yet.");
      }
      else if (!enunciate.isModuleEnabled(moduleName)) {
        String message = "Enunciate module '" + moduleName + "' is disabled. See the console output for details.";

        if (this.message != null) {
          message = this.message;
        }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

      catch (Exception e) {
        throw new MojoExecutionException("Problem assembling the enunciate app.", e);
      }
    }

    Enunciate enunciate = (Enunciate) getPluginContext().get(ConfigMojo.ENUNCIATE_PROPERTY);
    if (enunciate == null) {
      throw new MojoExecutionException("No enunciate mechanism found in the project!");
    }
    //now we have to include the generated sources into the compile source roots.
    for (File additionalRoot : enunciate.getAdditionalSourceRoots()) {
      addSourceDirToProject(additionalRoot);
    }
  }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

  /**
   * tests doing the freemarker generate.
   */
  public void testDoFreemarkerGenerate() throws Exception {
    Enunciate enunciate = new Enunciate(new String[0]);
    final EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    model.add(new EndpointInterface(getDeclaration("org.codehaus.enunciate.samples.jaxws.AnotherEndpointInterface")));
    model.add(new EndpointInterface(getDeclaration("org.codehaus.enunciate.samples.jaxws.BasicEndpointInterface")));
    FreemarkerModel.set(model);

View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

   */
  protected Class createWrapperClass(WebMessage message, URL templateURL, String beanFQN) throws Exception {
    setupDefaultModel();

    //generate the java source file.
    Enunciate enunciate = new Enunciate(new String[0]);
    File genDir = enunciate.createTempDir();
    enunciate.setGenerateDir(genDir);
    JAXWSSupportDeploymentModule module = new JAXWSSupportDeploymentModule() {
      @Override
      protected EnunciateFreemarkerModel getModelInternal() {
        return (EnunciateFreemarkerModel) FreemarkerModel.get();
      }
    };
    module.init(enunciate);
    EnunciateFreemarkerModel model = module.getModel();
    model.put("file", new SpecifiedOutputDirectoryFileTransform(genDir));
    model.put("message", message);
    model.put("Introspector", BeansWrapper.getDefaultInstance().getStaticModels().get("java.beans.Introspector"));
    module.processTemplate(templateURL, model);

    Collection<String> srcFiles = enunciate.getJavaFiles(genDir);
    assertEquals("The wrapper bean should have been generated.", 1, srcFiles.size());
    srcFiles.addAll(getAllJavaFiles(getSamplesDir()));
    File buildDir = enunciate.createTempDir();
    enunciate.invokeJavac(getInAPTClasspath(), buildDir, srcFiles.toArray(new String[srcFiles.size()]));
    URLClassLoader loader = new URLClassLoader(new URL[] {buildDir.toURL()}, getClass().getClassLoader());
    Class generatedClass = Class.forName(beanFQN, true, loader);
    assertNotNull(generatedClass);

    return generatedClass;
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

   */
  protected void setupDefaultModel() throws EnunciateException {
    //set up the default root model.
    EnunciateConfiguration config = new EnunciateConfiguration(new ArrayList<DeploymentModule>());
    config.setValidator(new BaseValidator()); //skip the validation...
    Enunciate enunciate = new Enunciate(new String[0]);
    enunciate.setConfig(config);
    new EnunciateAnnotationProcessor(enunciate).process();
  }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

  public void execute() throws MojoExecutionException, MojoFailureException {
    if (this.enunciateArtifactId == null) {
      throw new MojoExecutionException("An enunciate artifact id must be supplied.");
    }

    Enunciate enunciate = (Enunciate) getPluginContext().get(ConfigMojo.ENUNCIATE_PROPERTY);
    if (enunciate == null) {
      throw new MojoExecutionException("No enunciate mechanism found in the project!");
    }

    org.codehaus.enunciate.main.Artifact enunciateArtifact = enunciate.findArtifact(this.enunciateArtifactId);
    if (enunciateArtifact == null) {
      throw new MojoExecutionException("Unknown Enunciate artifact: " + this.enunciateArtifactId + ".");
    }

    File mainArtifact = null;
    File sources = null;
    File javadocs = null;
    if (enunciateArtifact instanceof ClientLibraryArtifact) {
      for (org.codehaus.enunciate.main.Artifact childArtifact : ((ClientLibraryArtifact) enunciateArtifact).getArtifacts()) {
        if (childArtifact instanceof FileArtifact) {
          ArtifactType artifactType = ((FileArtifact) childArtifact).getArtifactType();
          if (artifactType != null) {
            switch (artifactType) {
              case binaries:
                mainArtifact = ((FileArtifact) childArtifact).getFile();
                break;
              case sources:
                sources = ((FileArtifact) childArtifact).getFile();
                break;
              case javadocs:
                javadocs = ((FileArtifact) childArtifact).getFile();
                break;
            }
          }
        }
      }
    }
    else if (enunciateArtifact instanceof FileArtifact) {
      mainArtifact = ((FileArtifact) enunciateArtifact).getFile();
    }
    else {
      try {
        mainArtifact = enunciate.createTempFile(this.enunciateArtifactId, "artifact");
        enunciateArtifact.exportTo(mainArtifact, enunciate);
      }
      catch (IOException e) {
        throw new MojoExecutionException("Unable to create a temp file.", e);
      }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

    module.setTitle("mytitle");
    module.setSplashPackage("org.codehaus.enunciate.samples.docs.pckg1");
    EnunciateConfiguration config = new EnunciateConfiguration(Arrays.asList((DeploymentModule) module));
    config.setExcludeUnreferencedClasses(false);
    config.setIncludeReferencedClasses(false);
    Enunciate enunciate = new Enunciate(getAllJavaFiles(getSamplesDir()));
    enunciate.setConfig(config);
    enunciate.setTarget(Enunciate.Target.BUILD);
    enunciate.setRuntimeClasspath(getInAPTClasspath());
    module.setBase(enunciate.createTempDir().getAbsolutePath());
    ClientLibraryArtifact artifact1 = new ClientLibraryArtifact("module1", "1", "lib1") {

      @Override
      public void exportTo(File file, Enunciate enunciate) throws IOException {
        //no-op
      }
    };
    artifact1.setDescription("my <b>marked up</b> description for artifact 1");

    NamedFileArtifact file = new NamedFileArtifact(null, null, new File("1.1.xml"));
    file.setDescription("my description 1.1");
    artifact1.addArtifact(file);
    file = new NamedFileArtifact(null, null, new File("1.2.xml"));
    file.setDescription("my description 1.2");
    artifact1.addArtifact(file);

    ClientLibraryArtifact artifact2 = new ClientLibraryArtifact("module2", "2", "lib2") {
      @Override
      public void exportTo(File file, Enunciate enunciate) throws IOException {
        //no-op
      }
    };
    artifact2.setDescription("my <b>marked up</b> description for artifact 2");
    file = new NamedFileArtifact(null, null, new File("2.1.xml"));
    file.setDescription("my description 2.1");
    artifact2.addArtifact(file);
    file = new NamedFileArtifact(null, null, new File("2.2.xml"));
    file.setDescription("my description 2.2");
    artifact2.addArtifact(file);

    enunciate.addArtifact(artifact1);
    enunciate.addArtifact(artifact2);
    enunciate.execute();

    File docsXml = new File(enunciate.getGenerateDir(), "docs/docs.xml");
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setValidating(false);
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    builder.setEntityResolver(new EntityResolver() {
      public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
        if (String.valueOf(systemId).endsWith("xhtml1-transitional.dtd")) {
          return new InputSource(TestGenerateDocsXml.this.getClass().getResourceAsStream("xhtml1-transitional.dtd"));
        }
        else if (String.valueOf(systemId).endsWith("xhtml-special.ent")) {
          return new InputSource(TestGenerateDocsXml.this.getClass().getResourceAsStream("xhtml-special.ent"));
        }
        else if (String.valueOf(systemId).endsWith("xhtml-lat1.ent")) {
          return new InputSource(TestGenerateDocsXml.this.getClass().getResourceAsStream("xhtml-lat1.ent"));
        }
        else if (String.valueOf(systemId).endsWith("xhtml-symbol.ent")) {
          return new InputSource(TestGenerateDocsXml.this.getClass().getResourceAsStream("xhtml-symbol.ent"));
        }
        return null;
      }
    });
    Document document = builder.parse(docsXml);
    XPath xpath = XPathFactory.newInstance().newXPath();

    assertEquals("Here is some package documentation. <child>text</child>", xpath.evaluate("/api-docs/documentation", document).trim());
    assertEquals("myco", xpath.evaluate("/api-docs/@copyright", document).trim());

    String packageDocsXPath = "/api-docs/packages/package[@id='%s']/documentation";
    assertEquals("Here is some package documentation. <child>text</child>", xpath.evaluate(String.format(packageDocsXPath, "org.codehaus.enunciate.samples.docs.pckg1"), document).trim());
    assertEquals("Here is some more package documentation.", xpath.evaluate(String.format(packageDocsXPath, "org.codehaus.enunciate.samples.docs.pckg2"), document).trim());

    String packageTagsXPath = "/api-docs/packages/package[@id='%s']/tag[@name='%s']";
    assertEquals("sometag value", xpath.evaluate(String.format(packageTagsXPath, "org.codehaus.enunciate.samples.docs.pckg2", "sometag"), document).trim());

    String typeDocsXPath = "/api-docs/data/schema[@namespace='%s']/types/type[@id='%s']/documentation";
    assertEquals("Text for EnumOne", xpath.evaluate(String.format(typeDocsXPath, "urn:pckg1", "org.codehaus.enunciate.samples.docs.pckg1.EnumOne"), document).trim());
   
    //todo: more testing of the docs xml...

    File libsXml = new File(enunciate.getGenerateDir(), "docs/downloads.xml");
    document = builder.parse(libsXml);
   
    String libDescriptionXPath = "/downloads/download[@name='%s']/description";
    assertEquals("my <b>marked up</b> description for artifact 1", xpath.evaluate(String.format(libDescriptionXPath, "lib1"), document).trim());
    assertEquals("my <b>marked up</b> description for artifact 2", xpath.evaluate(String.format(libDescriptionXPath, "lib2"), document).trim());

    String fileDescriptionXPath = "/downloads/download[@name='%s']/files/file[@name='%s']";
    assertEquals("my description 1.1", xpath.evaluate(String.format(fileDescriptionXPath, "lib1", "1.1.xml"), document).trim());
    assertEquals("my description 1.2", xpath.evaluate(String.format(fileDescriptionXPath, "lib1", "1.2.xml"), document).trim());
    assertEquals("my description 2.1", xpath.evaluate(String.format(fileDescriptionXPath, "lib2", "2.1.xml"), document).trim());
    assertEquals("my description 2.2", xpath.evaluate(String.format(fileDescriptionXPath, "lib2", "2.2.xml"), document).trim());

    //todo: more testing of the downloads xml...

    File indexHtml = new File(enunciate.getBuildDir(), "docs/index.html");
    assertTrue(indexHtml.exists());

    //todo: more testing of the generated HTML...
  }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

    return pckg + "." + simpleName;
  }

  @Override
  protected void doCompile() throws EnunciateException, IOException {
    Enunciate enunciate = getEnunciate();

    //Compile the java files.
    if (!enunciate.isUpToDateWithSources(getCompileDir())) {
      Collection<String> javaSourceFiles = enunciate.getJavaFiles(getClientGenerateDir());
      String clientClasspath = enunciate.getEnunciateBuildClasspath(); //we use the build classpath for client-side jars so you don't have to include client-side dependencies on the server-side.
      if (!isDisableCompile()) {
        enunciate.invokeJavac(clientClasspath, "1.5", "1.5", getClientCompileDir(), new ArrayList<String>(), javaSourceFiles.toArray(new String[javaSourceFiles.size()]));
      }
      else {
        info("Compilation of the java sources has been disabled.");
      }

      for (DeploymentModule module : enunciate.getConfig().getEnabledModules()) {
        if (module instanceof XMLDeploymentModule) {
          XMLDeploymentModule xmlModule = (XMLDeploymentModule) module;
          enunciate.copyDir(xmlModule.getGenerateDir(), getClientCompileDir());
        }
      }

      if (isGenerateJsonJar()) {
        Collection<String> jsonSourceFiles = enunciate.getJavaFiles(getJsonClientGenerateDir());
        clientClasspath = enunciate.getEnunciateBuildClasspath(); //we use the build classpath for client-side jars so you don't have to include client-side dependencies on the server-side.
        if (!isDisableCompile()) {
          enunciate.invokeJavac(clientClasspath, "1.5", "1.5", getJsonClientCompileDir(), new ArrayList<String>(), jsonSourceFiles.toArray(new String[jsonSourceFiles.size()]));
        }
        else {
          info("Compilation of the java json sources has been disabled.");         
        }
      }
View Full Code Here

Examples of org.codehaus.enunciate.main.Enunciate

    return new File(getCompileDir(), "json");
  }

  @Override
  protected void doBuild() throws EnunciateException, IOException {
    Enunciate enunciate = getEnunciate();
    String jarName = getJarName();
    String jsonJarName = getJsonJarName();

    String label = "enunciate";
    if (getLabel() != null) {
      label = getLabel();
    }
    else if ((enunciate.getConfig() != null) && (enunciate.getConfig().getLabel() != null)) {
      label = enunciate.getConfig().getLabel();
    }

    if (jarName == null) {
      jarName = label + "-client.jar";
    }

    if (jsonJarName == null) {
      jsonJarName = label + "-json-client.jar";
    }

    File clientJarFile = null;
    if (!isDisableCompile()) {
      clientJarFile = new File(getBuildDir(), jarName);
      if (!enunciate.isUpToDate(getClientCompileDir(), clientJarFile)) {
        if (isBundleSourcesWithClasses()) {
          enunciate.zip(clientJarFile, getClientCompileDir(), getClientGenerateDir());
        }
        else {
          enunciate.zip(clientJarFile, getClientCompileDir());
        }
      }
      else {
        info("Skipping creation of Java client jar as everything appears up-to-date...");
      }
    }

    File clientSourcesJarFile = null;
    if (!isBundleSourcesWithClasses()) {
      clientSourcesJarFile = new File(getBuildDir(), jarName.replaceFirst("\\.jar", "-sources.jar"));
      if (!enunciate.isUpToDate(getClientGenerateDir(), clientSourcesJarFile)) {
        enunciate.zip(clientSourcesJarFile, getClientGenerateDir());
      }
      else {
        info("Skipping creation of the Java client source jar as everything appears up-to-date...");
      }
    }

    ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "java.client.library", "Java Client Library");
    artifactBundle.setPlatform("Java (Version 5+)");
    artifactBundle.addAlias("jaxws.client.library");
    //read in the description from file:
    artifactBundle.setDescription(readResource("library_description.fmt"));
    if (clientJarFile != null) {
      NamedFileArtifact binariesJar = new NamedFileArtifact(getName(), "java.client.library.binaries", clientJarFile);
      binariesJar.addAlias("jaxws.client.library.binaries");
      binariesJar.setDescription("The binaries for the Java client library.");
      binariesJar.setPublic(false);
      binariesJar.setArtifactType(ArtifactType.binaries);
      artifactBundle.addArtifact(binariesJar);
      enunciate.addArtifact(binariesJar);
    }

    if (clientSourcesJarFile != null) {
      NamedFileArtifact sourcesJar = new NamedFileArtifact(getName(), "java.client.library.sources", clientSourcesJarFile);
      sourcesJar.addAlias("jaxws.client.library.sources");
      sourcesJar.setDescription("The sources for the Java client library.");
      sourcesJar.setPublic(false);
      sourcesJar.setArtifactType(ArtifactType.sources);
      artifactBundle.addArtifact(sourcesJar);
      enunciate.addArtifact(sourcesJar);
    }

    if (clientJarFile != null || clientSourcesJarFile != null) {
      enunciate.addArtifact(artifactBundle);
    }

    if (isGenerateJsonJar()) {
      File jsonClientJarFile = null;
      if (!isDisableCompile()) {
        jsonClientJarFile = new File(getBuildDir(), jsonJarName);
        if (!enunciate.isUpToDate(getJsonClientCompileDir(), jsonClientJarFile)) {
          if (isBundleSourcesWithClasses()) {
            enunciate.zip(jsonClientJarFile, getJsonClientCompileDir(), getJsonClientGenerateDir());
          }
          else {
            enunciate.zip(jsonClientJarFile, getJsonClientCompileDir());
          }
        }
        else {
          info("Skipping creation of Java JSON client jar as everything appears up-to-date...");
        }
      }

      File jsonClientSourcesJarFile = null;
      if (!isBundleSourcesWithClasses()) {
        jsonClientSourcesJarFile = new File(getBuildDir(), jsonJarName.replaceFirst("\\.jar", "-sources.jar"));
        if (!enunciate.isUpToDate(getJsonClientGenerateDir(), jsonClientSourcesJarFile)) {
          enunciate.zip(jsonClientSourcesJarFile, getJsonClientGenerateDir());
        }
        else {
          info("Skipping creation of the Java JSON client source jar as everything appears up-to-date...");
        }
      }

      artifactBundle = new ClientLibraryArtifact(getName(), "java.json.client.library", "Java JSON Client Library");
      artifactBundle.setPlatform("Java (Version 5+)");
      //read in the description from file:
      artifactBundle.setDescription(readResource("json_library_description.fmt"));
      if (jsonClientJarFile != null) {
        NamedFileArtifact binariesJar = new NamedFileArtifact(getName(), "java.json.client.library.binaries", jsonClientJarFile);
        binariesJar.setDescription("The binaries for the Java JSON client library.");
        binariesJar.setPublic(false);
        binariesJar.setArtifactType(ArtifactType.binaries);
        artifactBundle.addArtifact(binariesJar);
        enunciate.addArtifact(binariesJar);
      }

      if (jsonClientSourcesJarFile != null) {
        NamedFileArtifact sourcesJar = new NamedFileArtifact(getName(), "java.json.client.library.sources", jsonClientSourcesJarFile);
        sourcesJar.setDescription("The sources for the Java JSON client library.");
        sourcesJar.setPublic(false);
        sourcesJar.setArtifactType(ArtifactType.sources);
        artifactBundle.addArtifact(sourcesJar);
        enunciate.addArtifact(sourcesJar);
      }

      if (jsonClientJarFile != null || jsonClientSourcesJarFile != null) {
        enunciate.addArtifact(artifactBundle);
      }
    }
  }
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.