use of com.webcohesion.enunciate.artifacts.ClientLibraryArtifact in project enunciate by stoicflame.
the class InstallArtifactBaseMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (this.enunciateArtifactId == null) {
throw new MojoExecutionException("An id of the enunciate artifact to be installed must be configured.");
}
Enunciate enunciate = (Enunciate) getPluginContext().get(ConfigMojo.ENUNCIATE_PROPERTY);
if (enunciate == null) {
throw new MojoExecutionException("No enunciate mechanism found in the project!");
}
com.webcohesion.enunciate.artifacts.Artifact artifact = enunciate.findArtifact(this.enunciateArtifactId);
if (artifact == null) {
throw new MojoExecutionException("Unknown Enunciate artifact: " + this.enunciateArtifactId + ".");
}
File mainArtifact = null;
File sources = null;
File javadocs = null;
if (artifact instanceof ClientLibraryArtifact) {
for (com.webcohesion.enunciate.artifacts.Artifact childArtifact : ((ClientLibraryArtifact) artifact).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;
}
}
}
}
if (mainArtifact == null) {
throw new MojoExecutionException("Unable to install artifact '" + this.enunciateArtifactId + "': no binaries available. This is likely because the '" + artifact.getModule() + "' module didn't compile the binaries.");
}
} else if (artifact instanceof FileArtifact) {
mainArtifact = ((FileArtifact) artifact).getFile();
} else {
try {
mainArtifact = enunciate.createTempFile(this.enunciateArtifactId, "artifact");
} catch (IOException e) {
throw new MojoExecutionException("Unable to create a temp file.", e);
}
}
if (this.packaging == null) {
String artifactName = mainArtifact != null ? mainArtifact.getName() : null;
if (artifactName != null) {
int dotIndex = artifactName.indexOf('.');
if (dotIndex > 0 && (dotIndex + 1 < artifactName.length())) {
this.packaging = artifactName.substring(dotIndex + 1);
}
}
}
if (this.packaging == null) {
throw new MojoExecutionException("Unable to determine the packaging of enunciate artifact " + enunciateArtifactId + ". Please specify it in the configuration.");
}
setPrivateField("packaging", this.packaging);
if (this.groupId == null) {
this.groupId = this.project.getGroupId();
}
setPrivateField("groupId", this.groupId);
if (this.artifactId == null) {
this.artifactId = this.project.getArtifactId() + "-client";
}
setPrivateField("artifactId", this.artifactId);
if (this.version == null) {
this.version = this.project.getVersion();
}
setPrivateField("version", this.version);
setPrivateField("file", mainArtifact);
setPrivateField("sources", sources);
setPrivateField("javadoc", javadocs);
super.execute();
}
use of com.webcohesion.enunciate.artifacts.ClientLibraryArtifact in project enunciate by stoicflame.
the class DocsModule method copyDocumentationArtifacts.
protected List<Download> copyDocumentationArtifacts(Set<Artifact> artifacts, File outputDir) throws IOException {
ArrayList<Download> downloads = new ArrayList<Download>();
for (Artifact artifact : artifacts) {
debug("Exporting %s to directory %s.", artifact.getId(), outputDir);
artifact.exportTo(outputDir, this.enunciate);
if (artifact instanceof SpecifiedArtifact && !((SpecifiedArtifact) artifact).isShowLink()) {
continue;
}
Download download = new Download();
download.setSlug("artifact_" + artifact.getId().replace('.', '_'));
download.setName(artifact.getName());
download.setDescription(artifact.getDescription());
download.setCreated(artifact.getCreated());
if (artifact instanceof ClientLibraryJavaArtifact) {
download.setGroupId(((ClientLibraryJavaArtifact) artifact).getGroupId());
download.setArtifactId(((ClientLibraryJavaArtifact) artifact).getArtifactId());
download.setVersion(((ClientLibraryJavaArtifact) artifact).getVersion());
}
Collection<? extends Artifact> childArtifacts = (artifact instanceof ClientLibraryArtifact) ? ((ClientLibraryArtifact) artifact).getArtifacts() : (artifact instanceof SpecifiedArtifact) ? Arrays.asList(((SpecifiedArtifact) artifact).getFile()) : Arrays.asList(artifact);
ArrayList<DownloadFile> downloadFiles = new ArrayList<DownloadFile>();
for (Artifact childArtifact : childArtifacts) {
DownloadFile downloadFile = new DownloadFile();
downloadFile.setDescription(childArtifact.getDescription());
downloadFile.setName(childArtifact.getName());
downloadFile.setSize(getDisplaySize(childArtifact.getSize()));
downloadFiles.add(downloadFile);
}
download.setFiles(downloadFiles);
downloads.add(download);
}
return downloads;
}
use of com.webcohesion.enunciate.artifacts.ClientLibraryArtifact in project enunciate by stoicflame.
the class CSharpXMLClientModule method packageArtifacts.
private void packageArtifacts(File srcDir, File compileDir) {
File packageDir = getPackageDir();
packageDir.mkdirs();
if (!isUpToDateWithSources(packageDir)) {
try {
// we want to zip up the source file, too, so we'll just copy it to the compile dir.
enunciate.copyDir(srcDir, compileDir);
File bundle = new File(packageDir, getBundleFileName());
boolean anyFiles = enunciate.zip(bundle, compileDir);
if (anyFiles) {
ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "csharp.client.library", "C# Client Library");
artifactBundle.setPlatform(".NET 2.0");
StringBuilder builder = new StringBuilder("C# source code");
boolean docsExist = new File(compileDir, getDocXmlFileName()).exists();
boolean dllExists = new File(compileDir, getDLLFileName()).exists();
if (docsExist && dllExists) {
builder.append(", the assembly, and the XML docs");
} else if (dllExists) {
builder.append("and the assembly");
}
artifactBundle.setDescription((String) context.getProperty(LIRBARY_DESCRIPTION_PROPERTY));
FileArtifact binariesJar = new FileArtifact(getName(), "dotnet.client.bundle", bundle);
binariesJar.setArtifactType(ArtifactType.binaries);
binariesJar.setDescription(String.format("The %s for the C# client library.", builder.toString()));
binariesJar.setPublic(false);
artifactBundle.addArtifact(binariesJar);
enunciate.addArtifact(artifactBundle);
}
} catch (IOException e) {
throw new EnunciateException(e);
}
}
}
use of com.webcohesion.enunciate.artifacts.ClientLibraryArtifact 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.artifacts.ClientLibraryArtifact in project enunciate by stoicflame.
the class PHPJSONClientModule method call.
@Override
public void call(EnunciateContext context) {
if ((this.jacksonModule == null || this.jacksonModule.getJacksonContext() == null || this.jacksonModule.getJacksonContext().getTypeDefinitions().isEmpty()) && (this.jackson1Module == null || this.jackson1Module.getJacksonContext() == null || this.jackson1Module.getJacksonContext().getTypeDefinitions().isEmpty())) {
info("No Jackson JSON data types: PHP JSON client will not be generated.");
return;
}
detectAccessorNamingErrors();
if (usesUnmappableElements()) {
warn("Web service API makes use of elements that cannot be handled by the PHP JSON client. PHP JSON client will not be generated.");
return;
}
Map<String, String> packageToNamespaceConversions = getPackageToNamespaceConversions();
List<DecoratedTypeElement> schemaTypes = new ArrayList<DecoratedTypeElement>();
ExtensionDepthComparator comparator = new ExtensionDepthComparator();
EnunciateJacksonContext jacksonContext = null;
EnunciateJackson1Context jackson1Context = null;
if (this.jacksonModule != null) {
jacksonContext = this.jacksonModule.getJacksonContext();
for (TypeDefinition typeDefinition : jacksonContext.getTypeDefinitions()) {
String pckg = typeDefinition.getPackage().getQualifiedName().toString();
if (!packageToNamespaceConversions.containsKey(pckg)) {
packageToNamespaceConversions.put(pckg, packageToNamespace(pckg));
}
int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator);
if (position < 0) {
position = -position - 1;
}
schemaTypes.add(position, typeDefinition);
}
}
if (this.jackson1Module != null) {
jackson1Context = this.jackson1Module.getJacksonContext();
for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
String pckg = typeDefinition.getPackage().getQualifiedName().toString();
if (!packageToNamespaceConversions.containsKey(pckg)) {
packageToNamespaceConversions.put(pckg, packageToNamespace(pckg));
}
schemaTypes.add(typeDefinition);
}
}
File srcDir = getSourceDir();
Map<String, Object> model = new HashMap<String, Object>();
model.put("schemaTypes", schemaTypes);
model.put("namespaceFor", new ClientPackageForMethod(packageToNamespaceConversions, this.context));
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jacksonContext, jackson1Context);
model.put("classnameFor", classnameFor);
model.put("typeNameFor", new TypeNameForMethod(packageToNamespaceConversions, jacksonContext, jackson1Context));
model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
model.put("phpFileName", getSourceFileName());
model.put("file", new FileDirective(srcDir, 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));
if (!isUpToDateWithSources(srcDir)) {
debug("Generating the PHP data 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 PHP code generation because everything appears up-to-date.");
}
File packageDir = getPackageDir();
packageDir.mkdirs();
File bundle = new File(packageDir, getBundleFileName());
boolean anyFiles = bundle.exists();
if (!isUpToDateWithSources(packageDir)) {
try {
anyFiles = enunciate.zip(bundle, srcDir);
} catch (IOException e) {
throw new EnunciateException(e);
}
}
if (anyFiles) {
ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "php.json.client.library", "PHP JSON Client Library");
artifactBundle.setPlatform("PHP");
FileArtifact sourceScript = new FileArtifact(getName(), "php.json.client", bundle);
// binaries and sources are the same thing in php
sourceScript.setArtifactType(ArtifactType.binaries);
sourceScript.setPublic(false);
// read in the description from file
String description = readResource("library_description.fmt", model);
artifactBundle.setDescription(description);
artifactBundle.addArtifact(sourceScript);
this.enunciate.addArtifact(artifactBundle);
}
}
Aggregations