use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class AssembleBaseMojo method postProcess.
@Override
protected void postProcess(Enunciate enunciate) {
super.postProcess(enunciate);
File webInfClasses = new File(new File(new File(this.webappDirectory), "WEB-INF"), "classes");
webInfClasses.mkdirs();
Set<com.webcohesion.enunciate.artifacts.Artifact> artifacts = enunciate.getArtifacts();
for (Artifact artifact : artifacts) {
if (artifact.isBelongsOnServerSideClasspath()) {
try {
artifact.exportTo(webInfClasses, enunciate);
} catch (IOException e) {
throw new EnunciateException(e);
}
}
}
}
use of com.webcohesion.enunciate.EnunciateException 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);
}
use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.
the class RubyJSONClientModule 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: Ruby JSON client will not be generated.");
return;
}
detectAccessorNamingErrors();
if (usesUnmappableElements()) {
warn("Web service API makes use of elements that cannot be handled by the Ruby JSON client. Ruby JSON client will not be generated.");
return;
}
Map<String, String> packageToModuleConversions = getPackageToModuleConversions();
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 (!packageToModuleConversions.containsKey(pckg)) {
packageToModuleConversions.put(pckg, packageToModule(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 (!packageToModuleConversions.containsKey(pckg)) {
packageToModuleConversions.put(pckg, packageToModule(pckg));
}
schemaTypes.add(typeDefinition);
}
}
File srcDir = getSourceDir();
Map<String, Object> model = new HashMap<String, Object>();
model.put("schemaTypes", schemaTypes);
model.put("schemaTypes", schemaTypes);
model.put("packages2modules", packageToModuleConversions);
model.put("moduleFor", new ClientPackageForMethod(packageToModuleConversions, this.context));
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToModuleConversions, jacksonContext, jackson1Context);
model.put("classnameFor", classnameFor);
SimpleNameWithParamsMethod simpleNameFor = new SimpleNameWithParamsMethod(classnameFor);
model.put("simpleNameFor", simpleNameFor);
model.put("rubyFileName", 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 Ruby JSON data classes...");
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 Ruby code generation because everything appears up-to-date.");
}
ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "ruby.json.client.library", "Ruby JSON Client Library");
artifactBundle.setPlatform("Ruby");
FileArtifact sourceScript = new FileArtifact(getName(), "ruby.json.client", new File(srcDir, getSourceFileName()));
// binaries and sources are the same thing in ruby
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