use of com.webcohesion.enunciate.util.freemarker.FileDirective in project enunciate by stoicflame.
the class CSharpXMLClientModule method generateSources.
private File generateSources(Map<String, String> packageToNamespaceConversions) {
File srcDir = getSourceDir();
srcDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
ClientPackageForMethod namespaceFor = new ClientPackageForMethod(packageToNamespaceConversions, this.context);
Collection<WsdlInfo> wsdls = new ArrayList<WsdlInfo>();
if (this.jaxwsModule != null) {
wsdls = this.jaxwsModule.getJaxwsContext().getWsdls().values();
}
model.put("wsdls", wsdls);
EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
model.put("schemas", jaxbContext.getSchemas().values());
model.put("baseUri", this.enunciate.getConfiguration().getApplicationRoot());
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
model.put("namespaceFor", namespaceFor);
model.put("findRootElement", new FindRootElementMethod(jaxbContext));
model.put("requestDocumentQName", new RequestDocumentQNameMethod());
model.put("responseDocumentQName", new ResponseDocumentQNameMethod());
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jaxbContext);
model.put("classnameFor", classnameFor);
model.put("listsAsArraysClassnameFor", new ListsAsArraysClientClassnameForMethod(packageToNamespaceConversions, jaxbContext));
model.put("simpleNameFor", new SimpleNameFor(classnameFor));
model.put("csFileName", getSourceFileName());
model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
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);
model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
if (!isUpToDateWithSources(srcDir)) {
debug("Generating the C# client classes...");
URL apiTemplate = isSingleFilePerClass() ? getTemplateURL("api-multiple-files.fmt") : getTemplateURL("api.fmt");
try {
processTemplate(apiTemplate, model);
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping C# code generation because everything appears up-to-date.");
}
this.context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
return srcDir;
}
use of com.webcohesion.enunciate.util.freemarker.FileDirective 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.util.freemarker.FileDirective in project enunciate by stoicflame.
the class GWTJSONOverlayModule method generateClientSources.
protected File generateClientSources() {
File sourceDir = getSourceDir();
sourceDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
Map<String, String> conversions = getClientPackageConversions();
EnunciateJacksonContext jacksonContext = this.jacksonModule != null ? this.jacksonModule.getJacksonContext() : null;
EnunciateJackson1Context jackson1Context = this.jackson1Module != null ? this.jackson1Module.getJacksonContext() : null;
MergedJsonContext jsonContext = new MergedJsonContext(jacksonContext, jackson1Context);
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jsonContext);
model.put("packageFor", new ClientPackageForMethod(conversions, this.context));
model.put("classnameFor", classnameFor);
model.put("simpleNameFor", new SimpleNameForMethod(classnameFor, jsonContext));
model.put("isAccessorOfTypeLong", new IsAccessorOfTypeLongMethod());
model.put("file", new FileDirective(sourceDir, this.enunciate.getLogger()));
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
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);
model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
AntPatternMatcher matcher = new AntPatternMatcher();
matcher.setPathSeparator(".");
boolean upToDate = isUpToDateWithSources(sourceDir);
if (!upToDate) {
try {
debug("Generating the GWT JSON Overlay...");
if (jacksonContext != null) {
for (TypeDefinition typeDefinition : jacksonContext.getTypeDefinitions()) {
if (!typeDefinition.isSimple() && facetFilter.accept(typeDefinition)) {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? getTemplateURL("gwt-enum-type.fmt") : getTemplateURL("gwt-type.fmt");
processTemplate(template, model);
}
}
}
if (jackson1Context != null) {
for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
if (!typeDefinition.isSimple() && facetFilter.accept(typeDefinition)) {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? getTemplateURL("gwt-enum-type.fmt") : getTemplateURL("gwt-type.fmt");
processTemplate(template, model);
}
}
}
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping generation of GWT JSON Overlay as everything appears up-to-date...");
}
context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
return sourceDir;
}
use of com.webcohesion.enunciate.util.freemarker.FileDirective in project enunciate by stoicflame.
the class ObjCXMLClientModule method call.
@Override
public void call(EnunciateContext context) {
if (this.jaxbModule == null || this.jaxbModule.getJaxbContext() == null || this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
info("No JAXB XML data types: Objective-C XML client will not be generated.");
return;
}
if (usesUnmappableElements()) {
warn("Web service API makes use of elements that cannot be handled by the Objective-C XML client. Objective-C XML client will not be generated.");
return;
}
List<String> namingConflicts = JAXBCodeErrors.findConflictingAccessorNamingErrors(this.jaxbModule.getJaxbContext());
if (namingConflicts != null && !namingConflicts.isEmpty()) {
error("JAXB naming conflicts have been found:");
for (String namingConflict : namingConflicts) {
error(namingConflict);
}
error("These naming conflicts are often between the field and it's associated property, in which case you need to use one or two of the following strategies to avoid the conflicts:");
error("1. Explicitly exclude one or the other.");
error("2. Put the annotations on the property instead of the field.");
error("3. Tell JAXB to use a different process for detecting accessors using the @XmlAccessorType annotation.");
throw new EnunciateException("JAXB naming conflicts detected.");
}
EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
Map<String, String> packageIdentifiers = getPackageIdentifiers();
String packageIdentifierPattern = getPackageIdentifierPattern();
if ((packageIdentifierPattern != null)) {
for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
String pckg = typeDefinition.getPackage().getQualifiedName().toString();
if (!packageIdentifiers.containsKey(pckg)) {
try {
packageIdentifiers.put(pckg, String.format(packageIdentifierPattern, pckg.split("\\.", 9)));
} catch (IllegalFormatException e) {
warn("Unable to format package %s with format pattern %s (%s)", pckg, packageIdentifierPattern, e.getMessage());
}
}
}
}
}
Map<String, Object> model = new HashMap<String, Object>();
String slug = getSlug();
model.put("slug", slug);
File srcDir = getSourceDir();
TreeMap<String, String> translations = new TreeMap<String, String>();
translations.put("id", getTranslateIdTo());
model.put("clientSimpleName", new ClientSimpleNameMethod(translations));
List<TypeDefinition> schemaTypes = new ArrayList<TypeDefinition>();
ExtensionDepthComparator comparator = new ExtensionDepthComparator();
for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator);
if (position < 0) {
position = -position - 1;
}
schemaTypes.add(position, typeDefinition);
}
}
model.put("schemaTypes", schemaTypes);
NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod(getTypeDefinitionNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers);
model.put("nameForTypeDefinition", nameForTypeDefinition);
model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers));
TreeMap<String, String> conversions = new TreeMap<String, String>();
for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (typeDefinition.isEnum()) {
conversions.put(typeDefinition.getQualifiedName().toString(), "enum " + nameForTypeDefinition.calculateName(typeDefinition));
} else {
conversions.put(typeDefinition.getQualifiedName().toString(), (String) nameForTypeDefinition.calculateName(typeDefinition));
}
}
}
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jaxbContext);
model.put("classnameFor", classnameFor);
model.put("functionIdentifierFor", new FunctionIdentifierForMethod(nameForTypeDefinition, jaxbContext));
model.put("objcBaseName", slug);
model.put("separateCommonCode", isSeparateCommonCode());
model.put("findRootElement", new FindRootElementMethod(jaxbContext));
model.put("referencedNamespaces", new ReferencedNamespacesMethod(jaxbContext));
model.put("prefix", new PrefixMethod(jaxbContext.getNamespacePrefixes()));
model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
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);
model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
if (!isUpToDateWithSources(srcDir)) {
debug("Generating the C data structures and (de)serialization functions...");
URL apiTemplate = getTemplateURL("api.fmt");
try {
processTemplate(apiTemplate, model);
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping C code generation because everything appears up-to-date.");
}
ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "objc.client.library", "Objective C Client Library");
FileArtifact sourceHeader = new FileArtifact(getName(), "objc.client.h", new File(srcDir, slug + ".h"));
sourceHeader.setPublic(false);
sourceHeader.setArtifactType(ArtifactType.sources);
FileArtifact sourceImpl = new FileArtifact(getName(), "objc.client.m", new File(srcDir, slug + ".m"));
sourceImpl.setPublic(false);
sourceImpl.setArtifactType(ArtifactType.sources);
// read in the description from file
String description = readResource("library_description.fmt", model, nameForTypeDefinition);
artifactBundle.setDescription(description);
artifactBundle.addArtifact(sourceHeader);
artifactBundle.addArtifact(sourceImpl);
if (isSeparateCommonCode()) {
FileArtifact commonSourceHeader = new FileArtifact(getName(), "objc.common.client.h", new File(srcDir, "enunciate-common.h"));
commonSourceHeader.setPublic(false);
commonSourceHeader.setArtifactType(ArtifactType.sources);
commonSourceHeader.setDescription("Common header needed for all projects.");
FileArtifact commonSourceImpl = new FileArtifact(getName(), "objc.common.client.m", new File(srcDir, "enunciate-common.m"));
commonSourceImpl.setPublic(false);
commonSourceImpl.setArtifactType(ArtifactType.sources);
commonSourceImpl.setDescription("Common implementation code needed for all projects.");
artifactBundle.addArtifact(commonSourceHeader);
artifactBundle.addArtifact(commonSourceImpl);
}
this.enunciate.addArtifact(artifactBundle);
}
use of com.webcohesion.enunciate.util.freemarker.FileDirective in project enunciate by stoicflame.
the class CXMLClientModule method call.
@Override
public void call(EnunciateContext context) {
if (this.jaxbModule == null || this.jaxbModule.getJaxbContext() == null || this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
info("No JAXB XML data types: C XML client will not be generated.");
return;
}
if (usesUnmappableElements()) {
warn("Web service API makes use of elements that cannot be handled by the C XML client. C XML client will not be generated.");
return;
}
List<String> namingConflicts = JAXBCodeErrors.findConflictingAccessorNamingErrors(this.jaxbModule.getJaxbContext());
if (namingConflicts != null && !namingConflicts.isEmpty()) {
error("JAXB naming conflicts have been found:");
for (String namingConflict : namingConflicts) {
error(namingConflict);
}
error("These naming conflicts are often between the field and it's associated property, in which case you need to use one or two of the following strategies to avoid the conflicts:");
error("1. Explicitly exclude one or the other.");
error("2. Put the annotations on the property instead of the field.");
error("3. Tell JAXB to use a different process for detecting accessors using the @XmlAccessorType annotation.");
throw new EnunciateException("JAXB naming conflicts detected.");
}
File srcDir = getSourceDir();
srcDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
String slug = getSlug();
Map<String, String> ns2prefix = this.jaxbModule.getJaxbContext().getNamespacePrefixes();
NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod(getTypeDefinitionNamePattern(), slug, ns2prefix);
model.put("nameForTypeDefinition", nameForTypeDefinition);
model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), slug, ns2prefix));
TreeMap<String, String> conversions = new TreeMap<String, String>();
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (typeDefinition.isEnum()) {
conversions.put(typeDefinition.getQualifiedName().toString(), "enum " + nameForTypeDefinition.calculateName(typeDefinition));
} else {
conversions.put(typeDefinition.getQualifiedName().toString(), "struct " + nameForTypeDefinition.calculateName(typeDefinition));
}
}
}
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, this.jaxbModule.getJaxbContext());
model.put("classnameFor", classnameFor);
String sourceFileName = getSourceFileName(slug);
model.put("cFileName", sourceFileName);
model.put("separateCommonCode", isSeparateCommonCode());
model.put("findRootElement", new FindRootElementMethod(this.jaxbModule.getJaxbContext()));
model.put("referencedNamespaces", new ReferencedNamespacesMethod(this.jaxbModule.getJaxbContext()));
model.put("prefix", new PrefixMethod(ns2prefix));
model.put("xmlFunctionIdentifier", new XmlFunctionIdentifierMethod(ns2prefix));
model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
model.put("filename", sourceFileName);
model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
model.put("schemas", this.jaxbModule.getJaxbContext().getSchemas().values());
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
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);
model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
if (!isUpToDateWithSources(srcDir)) {
debug("Generating the C data structures and (de)serialization functions...");
URL apiTemplate = getTemplateURL("api.fmt");
try {
processTemplate(apiTemplate, model);
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping C code generation because everything appears up-to-date.");
}
ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "c.client.library", "C Client Library");
FileArtifact sourceScript = new FileArtifact(getName(), "c.client", new File(srcDir, sourceFileName));
sourceScript.setArtifactType(ArtifactType.sources);
sourceScript.setPublic(false);
// read in the description from file
String description = readResource("library_description.fmt", model, nameForTypeDefinition);
artifactBundle.setDescription(description);
artifactBundle.addArtifact(sourceScript);
if (isSeparateCommonCode()) {
FileArtifact commonSourceHeader = new FileArtifact(getName(), "c.common.client", new File(srcDir, "enunciate-common.c"));
commonSourceHeader.setPublic(false);
commonSourceHeader.setArtifactType(ArtifactType.sources);
commonSourceHeader.setDescription("Common code needed for all projects.");
artifactBundle.addArtifact(commonSourceHeader);
}
this.enunciate.addArtifact(artifactBundle);
}
Aggregations