use of org.apache.cxf.tools.wadlto.WADLToJava in project cxf by apache.
the class AbstractCodeGeneratorMojo method callCodeGenerator.
protected Bus callCodeGenerator(WadlOption option, Bus bus, Set<URI> classPath) throws MojoExecutionException {
File outputDirFile = option.getOutputDir();
outputDirFile.mkdirs();
URI basedir = project.getBasedir().toURI();
for (URI wadlURI : option.getWadlURIs(basedir, getResourceLoader())) {
File doneFile = getDoneFile(basedir, wadlURI);
if (!shouldRun(option, doneFile, wadlURI)) {
return bus;
}
doneFile.delete();
List<String> list = option.generateCommandLine(outputDirFile, basedir, wadlURI, getLog().isDebugEnabled());
String[] args = list.toArray(new String[list.size()]);
getLog().debug("Calling wadl2java with args: " + Arrays.toString(args));
if (!"false".equals(fork)) {
Set<URI> artifactsPath = new LinkedHashSet<URI>();
for (Artifact a : pluginArtifacts) {
File file = a.getFile();
if (file == null) {
throw new MojoExecutionException("Unable to find file for artifact " + a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
}
artifactsPath.add(file.toURI());
}
addPluginArtifact(artifactsPath);
artifactsPath.addAll(classPath);
runForked(artifactsPath, WADLToJava.class, args);
} else {
if (bus == null) {
bus = BusFactory.newInstance().createBus();
BusFactory.setThreadDefaultBus(bus);
}
try {
new WADLToJava(args).run(new ToolContext());
} catch (Throwable e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
}
try {
doneFile.createNewFile();
} catch (Throwable e) {
getLog().warn("Could not create marker file " + doneFile.getAbsolutePath());
getLog().debug(e);
}
}
return bus;
}
use of org.apache.cxf.tools.wadlto.WADLToJava in project cxf by apache.
the class WADLToJavaTest method testGenerateJAXBToStringAndEqualsAndHashCode.
@Test
public void testGenerateJAXBToStringAndEqualsAndHashCode() throws Exception {
try {
String[] args = new String[] { "-d", output.getCanonicalPath(), "-p", "custom.service", "-async getName,delete", "-compile", "-xjc-XtoString", "-xjc-Xequals", "-xjc-XhashCode", getLocation("/wadl/bookstore.xml") };
WADLToJava tool = new WADLToJava(args);
tool.run(new ToolContext());
assertNotNull(output.list());
verifyFiles("java", true, false, "superbooks", "custom.service");
verifyFiles("class", true, false, "superbooks", "custom.service");
List<Class<?>> schemaClassFiles = getSchemaClassFiles();
assertEquals(4, schemaClassFiles.size());
for (Class<?> c : schemaClassFiles) {
c.getMethod("toString");
c.getMethod("hashCode");
c.getMethod("equals", Object.class);
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.wadlto.WADLToJava in project cxf by apache.
the class WADLToJavaTest method testGenerateJAXBToString.
@Test
public void testGenerateJAXBToString() throws Exception {
try {
String[] args = new String[] { "-d", output.getCanonicalPath(), "-p", "custom.service", "-async getName,delete", "-compile", "-xjc-episode " + output.getAbsolutePath() + "/test.episode", "-xjc-XtoString", getLocation("/wadl/bookstore.xml") };
WADLToJava tool = new WADLToJava(args);
tool.run(new ToolContext());
assertNotNull(output.list());
verifyFiles("java", true, false, "superbooks", "custom.service");
verifyFiles("class", true, false, "superbooks", "custom.service");
assertTrue(new File(output.getAbsolutePath() + "/test.episode").exists());
List<Class<?>> schemaClassFiles = getSchemaClassFiles();
assertEquals(4, schemaClassFiles.size());
for (Class<?> c : schemaClassFiles) {
c.getMethod("toString");
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.wadlto.WADLToJava in project cxf by apache.
the class WADLToJavaTest method testCodeGenInterfaces.
@Test
public void testCodeGenInterfaces() {
try {
String[] args = new String[] { "-d", output.getCanonicalPath(), "-p", "custom.service", "-tMap", "{http://www.w3.org/2001/XMLSchema}date=java.util.List..String", "-async getName,delete", "-inheritResourceParams first", "-compile", getLocation("/wadl/bookstore.xml") };
WADLToJava tool = new WADLToJava(args);
tool.run(new ToolContext());
assertNotNull(output.list());
verifyFiles("java", true, false, "superbooks", "custom.service");
verifyFiles("class", true, false, "superbooks", "custom.service");
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.cxf.tools.wadlto.WADLToJava in project cxf by apache.
the class ForkOnceCodeGenerator method main.
public static void main(String[] args) throws Exception {
File file = new File(args[0]);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
while (line != null) {
int i = Integer.parseInt(line);
if (i == -1) {
reader.close();
return;
}
String[] wargs = new String[i];
for (int x = 0; x < i; x++) {
wargs[x] = reader.readLine();
}
new WADLToJava(wargs).run(new ToolContext());
line = reader.readLine();
}
reader.close();
}
Aggregations