use of com.webcohesion.enunciate.EnunciateException 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);
}
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class XmlTypeFactory method loadPackageExplicitTypes.
/**
* Load any explicit schema types specified by the package.
*
* @param pckg The package.
* @param context The context.
* @return Any explicit schema types specified by the package.
*/
protected static Map<String, XmlSchemaType> loadPackageExplicitTypes(PackageElement pckg, EnunciateJaxbContext context) {
Map<String, XmlSchemaType> explicitTypes = new HashMap<String, XmlSchemaType>();
XmlSchemaType schemaTypeInfo = pckg.getAnnotation(XmlSchemaType.class);
XmlSchemaTypes schemaTypes = pckg.getAnnotation(XmlSchemaTypes.class);
if ((schemaTypeInfo != null) || (schemaTypes != null)) {
ArrayList<XmlSchemaType> allSpecifiedTypes = new ArrayList<XmlSchemaType>();
if (schemaTypeInfo != null) {
allSpecifiedTypes.add(schemaTypeInfo);
}
if (schemaTypes != null) {
allSpecifiedTypes.addAll(Arrays.asList(schemaTypes.value()));
}
for (final XmlSchemaType specifiedType : allSpecifiedTypes) {
DecoratedTypeMirror typeMirror = Annotations.mirrorOf(new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return specifiedType.type();
}
}, context.getContext().getProcessingEnvironment(), XmlSchemaType.DEFAULT.class);
if (typeMirror == null) {
throw new EnunciateException(pckg.getQualifiedName() + ": a type must be specified in " + XmlSchemaType.class.getName() + " at the package-level.");
}
if (!(typeMirror instanceof DeclaredType)) {
throw new EnunciateException(pckg.getQualifiedName() + ": only a declared type can be adapted. Offending type: " + typeMirror);
}
explicitTypes.put(((TypeElement) ((DeclaredType) typeMirror).asElement()).getQualifiedName().toString(), specifiedType);
}
}
return Collections.unmodifiableMap(explicitTypes);
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class JaxwsModule method call.
@Override
public void call(EnunciateContext context) {
jaxwsContext = new EnunciateJaxwsContext(this.jaxbModule.getJaxbContext(), isUseSourceParameterNames());
boolean aggressiveWebMethodExcludePolicy = isAggressiveWebMethodExcludePolicy();
Map<String, String> eiPaths = new HashMap<>();
File sunJaxwsXmlFile = getSunJaxwsXmlFile();
if (sunJaxwsXmlFile != null) {
XMLConfiguration config;
try {
config = new XMLConfiguration(sunJaxwsXmlFile);
} catch (ConfigurationException e) {
throw new EnunciateException(e);
}
List<HierarchicalConfiguration> endpoints = config.configurationsAt("endpoint");
for (HierarchicalConfiguration endpoint : endpoints) {
String impl = endpoint.getString("[@implementation]", null);
String urlPattern = endpoint.getString("[@url-pattern]", null);
if (impl != null && urlPattern != null) {
eiPaths.put(impl, urlPattern);
}
}
}
DataTypeDetectionStrategy detectionStrategy = getDataTypeDetectionStrategy();
if (detectionStrategy != DataTypeDetectionStrategy.passive) {
Set<? extends Element> elements = detectionStrategy == DataTypeDetectionStrategy.local ? context.getLocalApiElements() : context.getApiElements();
for (Element declaration : elements) {
try {
if (declaration instanceof TypeElement) {
TypeElement element = (TypeElement) declaration;
XmlRegistry registryMetadata = declaration.getAnnotation(XmlRegistry.class);
if (registryMetadata != null) {
this.jaxbModule.addPotentialJaxbElement(element, new LinkedList<>());
}
if (isEndpointInterface(element)) {
EndpointInterface ei = new EndpointInterface(element, elements, aggressiveWebMethodExcludePolicy, jaxwsContext);
for (EndpointImplementation implementation : ei.getEndpointImplementations()) {
String urlPattern = eiPaths.get(implementation.getQualifiedName().toString());
if (urlPattern != null) {
if (!urlPattern.startsWith("/")) {
urlPattern = "/" + urlPattern;
}
if (urlPattern.endsWith("/*")) {
urlPattern = urlPattern.substring(0, urlPattern.length() - 2) + ei.getServiceName();
}
implementation.setPath(urlPattern);
}
}
jaxwsContext.add(ei);
addReferencedDataTypeDefinitions(ei);
}
}
} catch (RuntimeException e) {
if (e.getClass().getName().endsWith("CompletionFailure")) {
throw new CompletionFailureException(Collections.singletonList(declaration), e);
}
throw e;
}
}
}
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class ExampleUtils method loadCustomExample.
public static Example loadCustomExample(Syntax syntax, String tagName, DecoratedElement element, EnunciateContext context) {
Example example = null;
JavaDoc.JavaDocTagList tagList = element.getJavaDoc().get(tagName);
if (tagList != null) {
for (String value : tagList) {
int firstSpace = JavaDoc.indexOfFirstWhitespace(value);
String mediaType = value.substring(0, firstSpace);
if (syntax.isAssignableToMediaType(mediaType) && (firstSpace + 1) < value.length()) {
String specifiedExample = value.substring(firstSpace + 1).trim();
Reader reader;
try {
if (specifiedExample.startsWith("classpath:")) {
String classpathResource = specifiedExample.substring(10);
if (classpathResource.startsWith("/")) {
classpathResource = classpathResource.substring(1);
}
InputStream resource = context.getResourceAsStream(classpathResource);
if (resource == null) {
throw new IllegalArgumentException("Unable to find /" + classpathResource + " on the classpath.");
}
reader = new InputStreamReader(resource, "UTF-8");
} else if (specifiedExample.startsWith("file:")) {
File file = context.getConfiguration().resolveFile(specifiedExample.substring(5));
if (!file.exists()) {
throw new IllegalArgumentException("Unable to find " + specifiedExample.substring(5) + ".");
}
reader = new FileReader(file);
} else {
reader = new StringReader(specifiedExample);
}
} catch (IOException e) {
throw new EnunciateException(e);
}
try {
example = syntax.parseExample(reader);
} catch (Exception e) {
context.getLogger().warn("Unable to parse @%s tag at %s: %s", tagName, example, e.getMessage());
}
}
}
}
return example;
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class GWTJSONOverlayModule method readLibraryDescription.
/**
* Reads a resource into string form.
*
* @return The string form of the resource.
*/
protected String readLibraryDescription(Map<String, Object> model) {
model.put("sample_resource", findExampleResourceMethod());
URL res = GWTJSONOverlayModule.class.getResource("library_description.fmt");
try {
return processTemplate(res, model);
} catch (TemplateException e) {
throw new EnunciateException(e);
} catch (IOException e) {
throw new EnunciateException(e);
}
}
Aggregations