diff --git a/plugin/README.adoc b/plugin/README.adoc new file mode 100644 index 0000000..41bc02b --- /dev/null +++ b/plugin/README.adoc @@ -0,0 +1,7 @@ +# `org.codeartisans.gradle.wsdl-tasks` plugin + +> Yet another Gradle plugin to work with WSDLs + +Only contains tasks for now, no source set magic or anything. +You'll have to wire the tasks yourselves. +Please have a look at the link:sample[sample project] for a sample build script. diff --git a/plugin/build.gradle b/plugin/build.gradle index f19024c..fa032f3 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -1,5 +1,5 @@ group = 'org.codeartisans.gradle' -version = '0.1' +version = '0.2' ext.pluginId = 'org.codeartisans.gradle.wsdl-tasks' buildscript { @@ -16,6 +16,8 @@ repositories { } dependencies { + compileOnly 'com.sun.xml.ws:jaxws-tools:2.2.10' + implementation gradleApi() testImplementation( 'org.spockframework:spock-core:1.0-groovy-2.4' ) { diff --git a/plugin/src/main/java/org/codeartisans/gradle/wsdl/WsImportRunnable.java b/plugin/src/main/java/org/codeartisans/gradle/wsdl/WsImportRunnable.java new file mode 100644 index 0000000..b8f78a8 --- /dev/null +++ b/plugin/src/main/java/org/codeartisans/gradle/wsdl/WsImportRunnable.java @@ -0,0 +1,26 @@ +package org.codeartisans.gradle.wsdl; + +import com.sun.tools.ws.wscompile.WsimportTool; +import java.util.List; +import javax.inject.Inject; + +public class WsImportRunnable implements Runnable { + + private final List arguments; + + @Inject + public WsImportRunnable( List arguments ) { + this.arguments = arguments; + } + + @Override + public void run() { + try { + if( !new WsimportTool( System.out ).run( arguments.toArray( new String[ arguments.size() ] ) ) ) { + throw new RuntimeException( "Unable to import WSDL, see output for more details" ); + } + } catch( Throwable throwable ) { + throw new RuntimeException( "Unable to import WSDL", throwable ); + } + } +} diff --git a/plugin/src/main/java/org/codeartisans/gradle/wsdl/WsdlToJava.java b/plugin/src/main/java/org/codeartisans/gradle/wsdl/WsdlToJava.java index 8fa3821..468f487 100644 --- a/plugin/src/main/java/org/codeartisans/gradle/wsdl/WsdlToJava.java +++ b/plugin/src/main/java/org/codeartisans/gradle/wsdl/WsdlToJava.java @@ -5,9 +5,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import javax.inject.Inject; import org.gradle.api.Action; import org.gradle.api.DefaultTask; -import org.gradle.api.GradleException; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.artifacts.Configuration; import org.gradle.api.file.ConfigurableFileCollection; @@ -16,9 +16,10 @@ import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.OutputDirectory; import org.gradle.api.tasks.TaskAction; -import org.gradle.process.ExecResult; -import org.gradle.process.JavaExecSpec; import org.gradle.util.ConfigureUtil; +import org.gradle.workers.IsolationMode; +import org.gradle.workers.WorkerConfiguration; +import org.gradle.workers.WorkerExecutor; public class WsdlToJava extends DefaultTask { @@ -71,20 +72,17 @@ public void processWsdls() throws IOException { } private void processWsdl( Wsdl wsdl ) { - List arguments = wsImportArgumentsFor( wsdl ); - - ExecResult result = getProject().javaexec( new Action() { + getWorkerExecutor().submit( WsImportRunnable.class, new Action() { @Override - public void execute( JavaExecSpec spec ) { - spec.setArgs( arguments ); - spec.setClasspath( jaxwsToolsConfiguration ); - spec.setMain( "com.sun.tools.ws.WsImport" ); + public void execute( WorkerConfiguration config ) { + config.setDisplayName( "Import WSDL " + wsdl.getName() + " into " + wsdl.getPackageName() ); + config.setParams( wsImportArgumentsFor( wsdl ) ); + config.getForkOptions().jvmArgs( + "-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl" ); + config.setIsolationMode( IsolationMode.PROCESS ); + config.classpath( jaxwsToolsConfiguration.getFiles() ); } } ); - - if( result.getExitValue() != 0 ) { - throw new GradleException( "Error running wsimport, see output for details" ); - } } private List wsImportArgumentsFor( Wsdl wsdl ) { @@ -109,4 +107,9 @@ private List wsImportArgumentsFor( Wsdl wsdl ) { arguments.add( wsdlFile.getAbsolutePath() ); return arguments; } + + @Inject + protected WorkerExecutor getWorkerExecutor() { + throw new UnsupportedOperationException(); + } } diff --git a/sample/asciinema.html b/sample/asciinema.html index 36956a6..2e7e4e1 100644 --- a/sample/asciinema.html +++ b/sample/asciinema.html @@ -2,12 +2,16 @@ - + + - + diff --git a/sample/build.gradle b/sample/build.gradle index e2696c3..7a937b7 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,6 +1,6 @@ plugins { id "com.gradle.build-scan" version "1.8" - id "org.codeartisans.gradle.wsdl-tasks" version "0.1" apply false + id "org.codeartisans.gradle.wsdl-tasks" version "0.2" apply false } buildScan {
javaExecjavaExecWorker Processes
+ + +