use of com.webcohesion.enunciate.Enunciate in project enunciate by stoicflame.
the class TestEnunciateIDLModule method testAgainstFullAPI.
/**
* Tests the xml artifact generation against the "full" API.
*/
public void testAgainstFullAPI() throws Exception {
Map<String, String> prefixes = new HashMap<String, String>();
prefixes.put(FULL_NAMESPACE, "full");
prefixes.put(DATA_NAMESPACE, "data");
prefixes.put(CITE_NAMESPACE, "cite");
Properties testProperties = new Properties();
testProperties.load(TestEnunciateIDLModule.class.getResourceAsStream("/test.properties"));
String samplePath = testProperties.getProperty("api.sample.dir");
assertNotNull(samplePath);
File sampleDir = new File(samplePath);
assertTrue(sampleDir.exists());
Enunciate engine = new Enunciate().addSourceDir(sampleDir).loadConfiguration(TestEnunciateIDLModule.class.getResourceAsStream("test-idl-module-config.xml")).loadDiscoveredModules();
String cp = System.getProperty("java.class.path");
String[] path = cp.split(File.pathSeparator);
List<File> classpath = new ArrayList<File>(path.length);
for (String element : path) {
File entry = new File(element);
if (entry.exists() && !new File(entry, "test.properties").exists()) {
classpath.add(entry);
}
}
engine.setClasspath(classpath);
engine.run();
IDLModule idlModule = null;
for (EnunciateModule candidate : engine.getModules()) {
if (candidate instanceof IDLModule) {
idlModule = (IDLModule) candidate;
break;
}
}
assertNotNull(idlModule);
assertNotNull(idlModule.jaxbModule);
assertNotNull(idlModule.jaxwsModule);
assertNotNull(idlModule.jaxrsModule);
final Map<String, String> schemas = new HashMap<String, String>();
for (SchemaInfo schemaInfo : idlModule.jaxbModule.getJaxbContext().getSchemas().values()) {
assertNotNull(schemaInfo.getSchemaFile());
assertTrue(schemaInfo.getSchemaFile() instanceof JaxbSchemaFile);
String filename = ((JaxbSchemaFile) schemaInfo.getSchemaFile()).filename;
assertNotNull(filename);
if (prefixes.containsKey(schemaInfo.getNamespace())) {
assertEquals(prefixes.get(schemaInfo.getNamespace()) + ".xsd", filename);
}
StringWriter schemaOut = new StringWriter();
((JaxbSchemaFile) schemaInfo.getSchemaFile()).writeTo(schemaOut);
schemaOut.flush();
schemas.put(filename, schemaOut.toString());
}
WsdlInfo fullWsdlInfo = idlModule.jaxwsModule.getJaxwsContext().getWsdls().get(FULL_NAMESPACE);
assertNotNull(fullWsdlInfo);
assertEquals("full.wsdl", fullWsdlInfo.getFilename());
assertNotNull(fullWsdlInfo.getWsdlFile());
assertTrue(fullWsdlInfo.getWsdlFile() instanceof JaxwsWsdlFile);
JaxwsWsdlFile fullWsdl = (JaxwsWsdlFile) fullWsdlInfo.getWsdlFile();
assertEquals("full.wsdl", fullWsdl.filename);
final StringWriter output = new StringWriter();
fullWsdl.writeTo(output);
output.flush();
// make sure the wsdl is built correctly
WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
Definition definition = wsdlReader.readWSDL(new InMemoryWSDLLocator(output, schemas));
assertEquals(FULL_NAMESPACE, definition.getTargetNamespace());
Types types = definition.getTypes();
List extensibilityElements = types.getExtensibilityElements();
assertEquals(1, extensibilityElements.size());
ExtensibilityElement ee = (ExtensibilityElement) extensibilityElements.get(0);
assertEquals(new QName(W3C_XML_SCHEMA_NS_URI, "schema"), ee.getElementType());
Schema schema = (Schema) ee;
Map imports = schema.getImports();
assertEquals(3, imports.size());
assertNotNull(imports.get(DATA_NAMESPACE));
assertNotNull(imports.get(CITE_NAMESPACE));
assertNotNull(imports.get(null));
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
Element schemaElement = schema.getElement();
// these namespaces need to be explicitly added because the transformer won't see any references to them...
schemaElement.setAttribute("xmlns:data", DATA_NAMESPACE);
schemaElement.setAttribute("xmlns:cite", CITE_NAMESPACE);
schemaElement.setAttribute("xmlns:full", FULL_NAMESPACE);
// write out the wsdl schema to its xml form so we can parse it with XSOM...
DOMSource source = new DOMSource(schemaElement);
StringWriter fullSchemaOutput = new StringWriter();
StreamResult result = new StreamResult(fullSchemaOutput);
transformer.transform(source, result);
fullSchemaOutput.flush();
// set up the XSOM Parser.
final InputSource fullSource = new InputSource(new StringReader(fullSchemaOutput.toString()));
fullSource.setSystemId("file:/");
XSOMParser parser = new XSOMParser(new JAXPParser());
// throw all errors and warnings.
parser.setErrorHandler(new ThrowEverythingHandler());
parser.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
String xsd = schemas.get(systemId.substring("file:/".length()));
if (xsd == null) {
return null;
}
InputSource source = new InputSource(new StringReader(xsd));
source.setSystemId("file:/");
return source;
}
});
// make sure the schema included in the wsdl is correct.
parser.parse(fullSource);
XSSchemaSet schemaSet = parser.getResult();
XSSchema wsdlSchema = schemaSet.getSchema(FULL_NAMESPACE);
assertNotNull(wsdlSchema);
// make sure the data schema is imported and correct.
XSSchema dataSchema = schemaSet.getSchema(DATA_NAMESPACE);
assertNotNull(dataSchema);
assertDataSchemaStructure(dataSchema);
// make sure the cite schema is imported and correct.
XSSchema citeSchema = schemaSet.getSchema(CITE_NAMESPACE);
assertNotNull(citeSchema);
assertCiteSchemaStructure(citeSchema);
// now verify the rest of the WSDL...
assertWebServiceDefinition(definition);
}
use of com.webcohesion.enunciate.Enunciate 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.Enunciate in project coprhd-controller by CoprHD.
the class DocGenerator method main.
public static void main(String[] args) throws Exception {
List<String> files = new ArrayList<String>();
for (int i = 0; i < packages.length; i++) {
collectFiles(new File(packages[i]), files);
}
EnunciateConfiguration config = new EnunciateConfiguration();
config.setDefaultTitle("Bourne API");
Enunciate e = new Enunciate();
File buildDir = new File(args[0]);
if (!buildDir.exists()) {
buildDir.mkdir();
}
File intermediateDir = new File(buildDir, "docs_xml");
if (!intermediateDir.exists()) {
intermediateDir.mkdir();
}
e.addSourceDir(buildDir);
e.getApiRegistry();
e.run();
}
use of com.webcohesion.enunciate.Enunciate in project coprhd-controller by CoprHD.
the class DocGenerator method main.
public static void main(String[] args) throws Exception {
List<String> files = new ArrayList<String>();
for (int i = 0; i < packages.length; i++) {
collectFiles(new File(packages[i]), files);
}
EnunciateConfiguration config = new EnunciateConfiguration();
config.setDefaultTitle("Bourne API");
Enunciate e = new Enunciate();
File buildDir = new File(args[0]);
if (!buildDir.exists()) {
buildDir.mkdir();
}
File intermediateDir = new File(buildDir, "docs_xml");
if (!intermediateDir.exists()) {
intermediateDir.mkdir();
}
e.addSourceDir(buildDir);
e.getApiRegistry();
e.run();
}
use of com.webcohesion.enunciate.Enunciate in project coprhd-controller by CoprHD.
the class DocGenerator method main.
public static void main(String[] args) throws Exception {
List<String> files = new ArrayList<String>();
for (int i = 0; i < packages.length; i++) {
collectFiles(new File(packages[i]), files);
}
EnunciateConfiguration config = new EnunciateConfiguration();
config.setDefaultTitle("Bourne API");
Enunciate e = new Enunciate();
File buildDir = new File(args[0]);
if (!buildDir.exists()) {
buildDir.mkdir();
}
File intermediateDir = new File(buildDir, "docs_xml");
if (!intermediateDir.exists()) {
intermediateDir.mkdir();
}
e.addSourceDir(buildDir);
e.getApiRegistry();
e.run();
}
Aggregations