Search in sources :

Example 1 with WADLToJava

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) WADLToJava(org.apache.cxf.tools.wadlto.WADLToJava) ToolContext(org.apache.cxf.tools.common.ToolContext) File(java.io.File) URI(java.net.URI) DocumentArtifact(org.apache.cxf.maven_plugin.common.DocumentArtifact) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with WADLToJava

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();
    }
}
Also used : WADLToJava(org.apache.cxf.tools.wadlto.WADLToJava) ToolContext(org.apache.cxf.tools.common.ToolContext) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 3 with WADLToJava

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();
    }
}
Also used : WADLToJava(org.apache.cxf.tools.wadlto.WADLToJava) ToolContext(org.apache.cxf.tools.common.ToolContext) File(java.io.File) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 4 with WADLToJava

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();
    }
}
Also used : WADLToJava(org.apache.cxf.tools.wadlto.WADLToJava) ToolContext(org.apache.cxf.tools.common.ToolContext) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 5 with WADLToJava

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();
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) WADLToJava(org.apache.cxf.tools.wadlto.WADLToJava) ToolContext(org.apache.cxf.tools.common.ToolContext) File(java.io.File)

Aggregations

ToolContext (org.apache.cxf.tools.common.ToolContext)5 WADLToJava (org.apache.cxf.tools.wadlto.WADLToJava)5 File (java.io.File)3 URISyntaxException (java.net.URISyntaxException)3 Test (org.junit.Test)3 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 URI (java.net.URI)1 LinkedHashSet (java.util.LinkedHashSet)1 DocumentArtifact (org.apache.cxf.maven_plugin.common.DocumentArtifact)1 Artifact (org.apache.maven.artifact.Artifact)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1