Search in sources :

Example 1 with EnunciateConfiguration

use of com.webcohesion.enunciate.EnunciateConfiguration in project coprhd-controller by CoprHD.

the class DocGenerator method main.

public static void main(String[] args) throws Exception {
    List<String> files = new ArrayList<String>();
    for (int i = 0; i < packages.length; i++) {
        collectFiles(new File(packages[i]), files);
    }
    EnunciateConfiguration config = new EnunciateConfiguration();
    config.setDefaultTitle("Bourne API");
    Enunciate e = new Enunciate();
    File buildDir = new File(args[0]);
    if (!buildDir.exists()) {
        buildDir.mkdir();
    }
    File intermediateDir = new File(buildDir, "docs_xml");
    if (!intermediateDir.exists()) {
        intermediateDir.mkdir();
    }
    e.addSourceDir(buildDir);
    e.getApiRegistry();
    e.run();
}
Also used : EnunciateConfiguration(com.webcohesion.enunciate.EnunciateConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) Enunciate(com.webcohesion.enunciate.Enunciate)

Example 2 with EnunciateConfiguration

use of com.webcohesion.enunciate.EnunciateConfiguration in project coprhd-controller by CoprHD.

the class DocGenerator method main.

public static void main(String[] args) throws Exception {
    List<String> files = new ArrayList<String>();
    for (int i = 0; i < packages.length; i++) {
        collectFiles(new File(packages[i]), files);
    }
    EnunciateConfiguration config = new EnunciateConfiguration();
    config.setDefaultTitle("Bourne API");
    Enunciate e = new Enunciate();
    File buildDir = new File(args[0]);
    if (!buildDir.exists()) {
        buildDir.mkdir();
    }
    File intermediateDir = new File(buildDir, "docs_xml");
    if (!intermediateDir.exists()) {
        intermediateDir.mkdir();
    }
    e.addSourceDir(buildDir);
    e.getApiRegistry();
    e.run();
}
Also used : EnunciateConfiguration(com.webcohesion.enunciate.EnunciateConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) Enunciate(com.webcohesion.enunciate.Enunciate)

Example 3 with EnunciateConfiguration

use of com.webcohesion.enunciate.EnunciateConfiguration in project coprhd-controller by CoprHD.

the class DocGenerator method main.

public static void main(String[] args) throws Exception {
    List<String> files = new ArrayList<String>();
    for (int i = 0; i < packages.length; i++) {
        collectFiles(new File(packages[i]), files);
    }
    EnunciateConfiguration config = new EnunciateConfiguration();
    config.setDefaultTitle("Bourne API");
    Enunciate e = new Enunciate();
    File buildDir = new File(args[0]);
    if (!buildDir.exists()) {
        buildDir.mkdir();
    }
    File intermediateDir = new File(buildDir, "docs_xml");
    if (!intermediateDir.exists()) {
        intermediateDir.mkdir();
    }
    e.addSourceDir(buildDir);
    e.getApiRegistry();
    e.run();
}
Also used : EnunciateConfiguration(com.webcohesion.enunciate.EnunciateConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) Enunciate(com.webcohesion.enunciate.Enunciate)

Example 4 with EnunciateConfiguration

use of com.webcohesion.enunciate.EnunciateConfiguration in project enunciate by stoicflame.

the class ConfigMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skipEnunciate) {
        getLog().info("[ENUNCIATE] Skipping enunciate per configuration.");
        return;
    }
    Enunciate enunciate = new Enunciate();
    // set up the logger.
    enunciate.setLogger(new MavenEnunciateLogger());
    // set the build dir.
    enunciate.setBuildDir(this.buildDir);
    // load the config.
    EnunciateConfiguration config = enunciate.getConfiguration();
    File configFile = this.configFile;
    if (configFile == null) {
        configFile = new File(project.getBasedir(), "enunciate.xml");
    }
    if (configFile.exists()) {
        getLog().info("[ENUNCIATE] Using enunciate configuration at " + configFile.getAbsolutePath());
        try {
            loadConfig(enunciate, configFile);
            config.setBase(configFile.getParentFile());
        } catch (Exception e) {
            throw new MojoExecutionException("Problem with enunciate config file " + configFile, e);
        }
    } else if (this.configFile != null) {
        throw new MojoFailureException("Enunciate config file \"" + this.configFile + "\" does not exist");
    } else {
        getLog().debug("[ENUNCIATE] Default config file does not exist");
    }
    // set the default configured label.
    config.setDefaultSlug(project.getArtifactId());
    if (StringUtils.isNotBlank(title)) {
        config.setDefaultTitle(title);
    }
    String defaultDescription = getDefaultDescription();
    if (defaultDescription != null) {
        config.setDefaultDescription(defaultDescription);
    }
    if (project.getVersion() != null && !"".equals(project.getVersion().trim())) {
        config.setDefaultVersion(project.getVersion());
    }
    List contributors = project.getContributors();
    if (contributors != null && !contributors.isEmpty()) {
        List<EnunciateConfiguration.Contact> contacts = new ArrayList<EnunciateConfiguration.Contact>(contributors.size());
        for (Object c : contributors) {
            Contributor contributor = (Contributor) c;
            contacts.add(new EnunciateConfiguration.Contact(contributor.getName(), contributor.getUrl(), contributor.getEmail()));
        }
        config.setDefaultContacts(contacts);
    }
    List licenses = project.getLicenses();
    if (licenses != null && !licenses.isEmpty()) {
        License license = (License) licenses.get(0);
        config.setDefaultApiLicense(new EnunciateConfiguration.License(license.getName(), license.getUrl(), null, null));
    }
    // set the class paths.
    setClasspathAndSourcepath(enunciate);
    // load any modules on the classpath.
    List<URL> pluginClasspath = buildPluginClasspath();
    ServiceLoader<EnunciateModule> moduleLoader = ServiceLoader.load(EnunciateModule.class, new URLClassLoader(pluginClasspath.toArray(new URL[pluginClasspath.size()]), Thread.currentThread().getContextClassLoader()));
    for (EnunciateModule module : moduleLoader) {
        enunciate.addModule(module);
    }
    // set the compiler arguments.
    List<String> compilerArgs = new ArrayList<String>();
    String sourceVersion = findSourceVersion();
    if (sourceVersion != null) {
        compilerArgs.add("-source");
        compilerArgs.add(sourceVersion);
    }
    String targetVersion = findTargetVersion();
    if (targetVersion != null) {
        compilerArgs.add("-target");
        compilerArgs.add(targetVersion);
    }
    String sourceEncoding = this.encoding;
    if (sourceEncoding != null) {
        compilerArgs.add("-encoding");
        compilerArgs.add(sourceEncoding);
    }
    if (this.compilerArgs != null) {
        compilerArgs.addAll(Arrays.asList(this.compilerArgs));
    }
    enunciate.getCompilerArgs().addAll(compilerArgs);
    // includes.
    if (this.includes != null) {
        for (String include : this.includes) {
            enunciate.addInclude(include);
        }
    }
    // excludes.
    if (this.excludes != null) {
        for (String exclude : this.excludes) {
            enunciate.addExclude(exclude);
        }
    }
    // exports.
    if (this.exports != null) {
        for (String exportId : this.exports.keySet()) {
            String filename = this.exports.get(exportId);
            if (filename == null || "".equals(filename)) {
                throw new MojoExecutionException("Invalid (empty or null) filename for export " + exportId + ".");
            }
            File exportFile = new File(filename);
            if (!exportFile.isAbsolute()) {
                exportFile = new File(this.exportsDir, filename);
            }
            enunciate.addExport(exportId, exportFile);
        }
    }
    Set<String> enunciateAddedSourceDirs = new TreeSet<String>();
    List<EnunciateModule> modules = enunciate.getModules();
    if (modules != null) {
        Set<String> projectExtensions = new TreeSet<String>(this.projectExtensions == null ? Collections.<String>emptyList() : Arrays.asList(this.projectExtensions));
        for (EnunciateModule module : modules) {
            // configure the project with the module project extensions.
            if (projectExtensions.contains(module.getName()) && module instanceof ProjectExtensionModule) {
                ProjectExtensionModule extensions = (ProjectExtensionModule) module;
                for (File projectSource : extensions.getProjectSources()) {
                    String sourceDir = projectSource.getAbsolutePath();
                    enunciateAddedSourceDirs.add(sourceDir);
                    if (!project.getCompileSourceRoots().contains(sourceDir)) {
                        getLog().debug("[ENUNCIATE] Adding '" + sourceDir + "' to the compile source roots.");
                        project.addCompileSourceRoot(sourceDir);
                    }
                }
                for (File testSource : extensions.getProjectTestSources()) {
                    project.addTestCompileSourceRoot(testSource.getAbsolutePath());
                }
                for (File resourceDir : extensions.getProjectResourceDirectories()) {
                    Resource restResource = new Resource();
                    restResource.setDirectory(resourceDir.getAbsolutePath());
                    project.addResource(restResource);
                }
                for (File resourceDir : extensions.getProjectTestResourceDirectories()) {
                    Resource resource = new Resource();
                    resource.setDirectory(resourceDir.getAbsolutePath());
                    project.addTestResource(resource);
                }
            }
            applyAdditionalConfiguration(module);
        }
    }
    // add any new source directories to the project.
    Set<File> sourceDirs = new HashSet<File>();
    Collection<String> sourcePaths = this.sources == null || this.sources.length == 0 ? (Collection<String>) project.getCompileSourceRoots() : Arrays.asList(this.sources);
    for (String sourcePath : sourcePaths) {
        File sourceDir = new File(sourcePath);
        if (!enunciateAddedSourceDirs.contains(sourceDir.getAbsolutePath())) {
            sourceDirs.add(sourceDir);
        } else {
            getLog().info("[ENUNCIATE] " + sourceDir + " appears to be added to the source roots by Enunciate.  Excluding from original source roots....");
        }
    }
    for (File sourceDir : sourceDirs) {
        enunciate.addSourceDir(sourceDir);
    }
    postProcessConfig(enunciate);
    try {
        enunciate.run();
    } catch (Exception e) {
        Throwable t = unwrap(e);
        if (t instanceof EnunciateException) {
            throw new MojoExecutionException(t.getMessage(), t);
        }
        throw new MojoExecutionException("Error invoking Enunciate.", e);
    }
    if (this.artifacts != null) {
        for (Artifact projectArtifact : artifacts) {
            if (projectArtifact.getEnunciateArtifactId() == null) {
                getLog().warn("[ENUNCIATE] No enunciate export id specified.  Skipping project artifact...");
                continue;
            }
            com.webcohesion.enunciate.artifacts.Artifact artifact = null;
            for (com.webcohesion.enunciate.artifacts.Artifact enunciateArtifact : enunciate.getArtifacts()) {
                if (projectArtifact.getEnunciateArtifactId().equals(enunciateArtifact.getId()) || enunciateArtifact.getAliases().contains(projectArtifact.getEnunciateArtifactId())) {
                    artifact = enunciateArtifact;
                    break;
                }
            }
            if (artifact != null) {
                try {
                    File tempExportFile = enunciate.createTempFile(project.getArtifactId() + "-" + projectArtifact.getClassifier(), projectArtifact.getArtifactType());
                    artifact.exportTo(tempExportFile, enunciate);
                    projectHelper.attachArtifact(project, projectArtifact.getArtifactType(), projectArtifact.getClassifier(), tempExportFile);
                } catch (IOException e) {
                    throw new MojoExecutionException("Error exporting Enunciate artifact.", e);
                }
            } else {
                getLog().warn("[ENUNCIATE] Enunciate artifact '" + projectArtifact.getEnunciateArtifactId() + "' not found in the project...");
            }
        }
    }
    postProcess(enunciate);
    getPluginContext().put(ConfigMojo.ENUNCIATE_PROPERTY, enunciate);
}
Also used : EnunciateConfiguration(com.webcohesion.enunciate.EnunciateConfiguration) License(org.apache.maven.model.License) Contributor(org.apache.maven.model.Contributor) ProjectExtensionModule(com.webcohesion.enunciate.module.ProjectExtensionModule) URL(java.net.URL) Enunciate(com.webcohesion.enunciate.Enunciate) EnunciateException(com.webcohesion.enunciate.EnunciateException) EnunciateModule(com.webcohesion.enunciate.module.EnunciateModule) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Resource(org.apache.maven.model.Resource) IOException(java.io.IOException) EnunciateException(com.webcohesion.enunciate.EnunciateException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) SAXException(org.xml.sax.SAXException) URLClassLoader(java.net.URLClassLoader) File(java.io.File)

Aggregations

Enunciate (com.webcohesion.enunciate.Enunciate)4 EnunciateConfiguration (com.webcohesion.enunciate.EnunciateConfiguration)4 File (java.io.File)4 ArrayList (java.util.ArrayList)3 EnunciateException (com.webcohesion.enunciate.EnunciateException)1 EnunciateModule (com.webcohesion.enunciate.module.EnunciateModule)1 ProjectExtensionModule (com.webcohesion.enunciate.module.ProjectExtensionModule)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Contributor (org.apache.maven.model.Contributor)1 License (org.apache.maven.model.License)1 Resource (org.apache.maven.model.Resource)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)1 SAXException (org.xml.sax.SAXException)1