Search in sources :

Example 1 with Namespace

use of com.webcohesion.enunciate.api.datatype.Namespace in project enunciate by stoicflame.

the class DocsModule method call.

@Override
public void call(EnunciateContext context) {
    try {
        File docsDir = getDocsDir();
        String subDir = getDocsSubdir();
        if (subDir != null) {
            docsDir = new File(docsDir, subDir);
        }
        if (!isUpToDateWithSources(docsDir)) {
            Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
            facetIncludes.addAll(getFacetIncludes());
            Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
            facetExcludes.addAll(getFacetExcludes());
            FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
            ApiRegistrationContext registrationContext = new DocsRegistrationContext(this.apiRegistry, facetFilter);
            List<ResourceApi> resourceApis = this.apiRegistry.getResourceApis(registrationContext);
            Set<Syntax> syntaxes = this.apiRegistry.getSyntaxes(registrationContext);
            List<ServiceApi> serviceApis = this.apiRegistry.getServiceApis(registrationContext);
            Set<Artifact> documentationArtifacts = findDocumentationArtifacts();
            if (syntaxes.isEmpty() && serviceApis.isEmpty() && resourceApis.isEmpty() && documentationArtifacts.isEmpty()) {
                warn("No documentation generated: there are no data types, services, or resources to document.");
                return;
            }
            // make sure the docs dir exists.
            docsDir.mkdirs();
            Map<String, Object> model = new HashMap<String, Object>();
            String intro = this.enunciate.getConfiguration().readDescription(context, false, registrationContext.getTagHandler());
            if (intro != null) {
                model.put("apiDoc", intro);
            }
            String copyright = this.enunciate.getConfiguration().getCopyright();
            if (copyright != null) {
                model.put("copyright", copyright);
            }
            String title = this.enunciate.getConfiguration().getTitle();
            model.put("title", title == null ? "Web Service API" : title);
            // extract out the documentation base
            String cssPath = buildBase(docsDir);
            if (cssPath != null) {
                model.put("cssFile", cssPath);
            }
            model.put("file", new FileDirective(docsDir, this.enunciate.getLogger()));
            model.put("apiRelativePath", getRelativePathToRootDir());
            model.put("includeApplicationPath", isIncludeApplicationPath());
            model.put("includeDataTypesHomeIndex", isIncludeDataTypesHomeIndex());
            model.put("favicon", getFavicon());
            // iterate through schemas and make sure the schema is copied to the docs dir
            for (Syntax syntax : syntaxes) {
                for (Namespace namespace : syntax.getNamespaces()) {
                    if (namespace.getSchemaFile() != null) {
                        namespace.getSchemaFile().writeTo(docsDir);
                    }
                }
            }
            model.put("data", syntaxes);
            for (ResourceApi resourceApi : resourceApis) {
                if (resourceApi.getWadlFile() != null) {
                    resourceApi.getWadlFile().writeTo(docsDir);
                }
            }
            model.put("resourceApis", resourceApis);
            InterfaceDescriptionFile swaggerUI = this.apiRegistry.getSwaggerUI();
            if (swaggerUI != null) {
                swaggerUI.writeTo(docsDir);
                model.put("swaggerUI", swaggerUI);
            }
            // iterate through wsdls and make sure the wsdl is copied to the docs dir
            for (ServiceApi serviceApi : serviceApis) {
                for (ServiceGroup serviceGroup : serviceApi.getServiceGroups()) {
                    if (serviceGroup.getWsdlFile() != null) {
                        serviceGroup.getWsdlFile().writeTo(docsDir);
                    }
                }
            }
            model.put("serviceApis", serviceApis);
            model.put("downloads", copyDocumentationArtifacts(documentationArtifacts, docsDir));
            model.put("indexPageName", getIndexPageName());
            model.put("disableMountpoint", isDisableRestMountpoint());
            model.put("additionalCssFiles", getAdditionalCss());
            model.put("disableResourceLinks", isDisableResourceLinks());
            processTemplate(getDocsTemplateURL(), model);
        } else {
            info("Skipping documentation source generation as everything appears up-to-date...");
        }
        this.enunciate.addArtifact(new FileArtifact(getName(), "docs", docsDir));
    } catch (IOException e) {
        throw new EnunciateException(e);
    } catch (TemplateException e) {
        throw new EnunciateException(e);
    }
}
Also used : ServiceGroup(com.webcohesion.enunciate.api.services.ServiceGroup) FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ServiceApi(com.webcohesion.enunciate.api.services.ServiceApi) EnunciateException(com.webcohesion.enunciate.EnunciateException) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) TemplateException(freemarker.template.TemplateException) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) ClientLibraryJavaArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryJavaArtifact) Artifact(com.webcohesion.enunciate.artifacts.Artifact) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) Namespace(com.webcohesion.enunciate.api.datatype.Namespace) ResourceApi(com.webcohesion.enunciate.api.resources.ResourceApi) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) Syntax(com.webcohesion.enunciate.api.datatype.Syntax)

Aggregations

EnunciateException (com.webcohesion.enunciate.EnunciateException)1 Namespace (com.webcohesion.enunciate.api.datatype.Namespace)1 Syntax (com.webcohesion.enunciate.api.datatype.Syntax)1 ResourceApi (com.webcohesion.enunciate.api.resources.ResourceApi)1 ServiceApi (com.webcohesion.enunciate.api.services.ServiceApi)1 ServiceGroup (com.webcohesion.enunciate.api.services.ServiceGroup)1 Artifact (com.webcohesion.enunciate.artifacts.Artifact)1 ClientLibraryArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)1 ClientLibraryJavaArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryJavaArtifact)1 FileArtifact (com.webcohesion.enunciate.artifacts.FileArtifact)1 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)1 FileDirective (com.webcohesion.enunciate.util.freemarker.FileDirective)1 TemplateException (freemarker.template.TemplateException)1