Skip to content

Commit

Permalink
worker-processes
Browse files Browse the repository at this point in the history
  • Loading branch information
eskatos committed Jun 17, 2017
1 parent e2b10af commit 2f12e8e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
7 changes: 7 additions & 0 deletions plugin/README.adoc
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = 'org.codeartisans.gradle'
version = '0.1'
version = '0.2'
ext.pluginId = 'org.codeartisans.gradle.wsdl-tasks'

buildscript {
Expand All @@ -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' ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> arguments;

@Inject
public WsImportRunnable( List<String> 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 );
}
}
}
31 changes: 17 additions & 14 deletions plugin/src/main/java/org/codeartisans/gradle/wsdl/WsdlToJava.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -71,20 +72,17 @@ public void processWsdls() throws IOException {
}

private void processWsdl( Wsdl wsdl ) {
List<String> arguments = wsImportArgumentsFor( wsdl );

ExecResult result = getProject().javaexec( new Action<JavaExecSpec>() {
getWorkerExecutor().submit( WsImportRunnable.class, new Action<WorkerConfiguration>() {
@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<String> wsImportArgumentsFor( Wsdl wsdl ) {
Expand All @@ -109,4 +107,9 @@ private List<String> wsImportArgumentsFor( Wsdl wsdl ) {
arguments.add( wsdlFile.getAbsolutePath() );
return arguments;
}

@Inject
protected WorkerExecutor getWorkerExecutor() {
throw new UnsupportedOperationException();
}
}
8 changes: 6 additions & 2 deletions sample/asciinema.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
<body>
<table width="100%">
<tr>
<td width="100%"><a target="_blank" href="https://scans.gradle.com/s/732f6mvpa7srs/timeline">javaExec</a></td>
<td width="50%"><a target="_blank" href="https://scans.gradle.com/s/732f6mvpa7srs/timeline">javaExec</a></td>
<td width="50%"><a target="_blank" href="https://scans.gradle.com/s/ysqj27bfholw6/timeline">Worker Processes</a></td>
</tr>
<tr>
<td width="100%">
<td width="50%">
<script type="text/javascript" src="https://asciinema.org/a/05z1g9wht6pz9104ve7ti480z.js" id="asciicast-05z1g9wht6pz9104ve7ti480z" async data-autoplay="true" data-t="0" data-size="small"></script>
</td>
<td width="50%">
<script type="text/javascript" src="https://asciinema.org/a/0usq52077dx6yxp4lzs66wz5c.js" id="asciicast-0usq52077dx6yxp4lzs66wz5c" data-autoplay="true" data-t="0" async data-size="small"></script>
</td>
</body>
</html>

2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 2f12e8e

Please sign in to comment.