Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 18 additions & 36 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ plugins {
id "groovy"
id "maven-publish"
id "java-gradle-plugin"
id "com.jfrog.bintray" version "1.8.4"
id 'idea'
id 'eclipse'
id 'maven'
}

group = 'no.nils'
version = '0.13-SNAPSHOT'
version = '0.13-TRAVELC.16'

// stay compatible with the crowd
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}

dependencies {
implementation localGroovy()
implementation("com.github.ertugrulcetin:CommentRemover:1.2")

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.5.2'
Expand All @@ -32,6 +35,7 @@ dependencies {

java {
withSourcesJar()
withJavadocJar()
}

test {
Expand All @@ -55,40 +59,18 @@ publishing {
}
}

bintray {
apiUrl = "https://api.bintray.com"
user = System.env.BINTRAY_USER
key = System.env.BINTRAY_API_KEY
wrapper {
gradleVersion = '6.0.1'
}

publications = ['maven'] //When uploading Maven-based publication files
// - AND/OR -
dryRun = false //Whether to run this as dry-run, without deploying
publish = true //If version should be auto published after an upload
pkg {
repo = 'maven'
//userOrg = 'no.nils' //An optional organization name when the repo belongs to one of the user's orgs
name = 'wsdl2java'
desc = 'Gradle wsdl2java plugin'
websiteUrl = 'https://github.com/nilsmagnus/wsdl2java'
issueTrackerUrl = 'https://github.com/nilsmagnus/wsdl2java/issues'
vcsUrl = 'https://github.com/nilsmagnus/wsdl2java.git'
licenses = ['MIT']
labels = ['gradle', 'wsdl2java', 'plugin']
publicDownloadNumbers = true
//Optional version descriptor
version {
name = project.version //Bintray logical version name
desc = ''
//released = '' //2 possible values: date in the format of 'yyyy-MM-dd'T'HH:mm:ss.SSSZZ' OR a java.util.Date instance
vcsTag = project.version
attributes = ['gradle-plugin': 'no.nils.wsdl2java:no.nils:wsdl2java']
//Optional version-level attributes
uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://nexus.travelcdev.com/repository/maven-releases") {
authentication(userName: "admin", password: "travelCompositor123")
}
}
}
}

wrapper {
gradleVersion = '6.0.1'
}

build.doLast { uploadArchives }
8 changes: 2 additions & 6 deletions src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Wsdl2JavaPlugin implements Plugin<Project> {
// Add new configuration for our plugin and add required dependencies to it later.
def wsdl2javaConfiguration = project.configurations.maybeCreate(WSDL2JAVA)

// Get compile configuration and add Java 9+ dependencies if required.
project.configurations.named("compile").configure {
// Get implementation configuration and add Java 9+ dependencies if required.
project.configurations.named("implementation").configure {
it.withDependencies {
if (JavaVersion.current().isJava9Compatible()) {
JAVA_9_DEPENDENCIES.each { dep -> it.add(project.dependencies.create(dep)) }
Expand Down Expand Up @@ -72,10 +72,6 @@ class Wsdl2JavaPlugin implements Plugin<Project> {
it.dependsOn wsdl2JavaTask
}
}

project.sourceSets {
main.java.srcDirs += Wsdl2JavaTask.DESTINATION_DIR
}
}

static Class<Task> getTaskClass(name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class Wsdl2JavaPluginExtension {
@PathSensitive(PathSensitivity.ABSOLUTE)
File wsdlDir = new File(DEFAULT_WSDL_DIR)


@Input
String outputDirectory = "build/generated/"

@Input
List<List<Object>> wsdlsToGenerate

Expand All @@ -21,6 +25,9 @@ class Wsdl2JavaPluginExtension {
@Input
String encoding = Charset.defaultCharset().name()

@Input
boolean removeComments = true

@Input
boolean stabilize = false

Expand Down
45 changes: 35 additions & 10 deletions src/main/groovy/no/nils/wsdl2java/Wsdl2JavaTask.groovy
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package no.nils.wsdl2java

import com.commentremover.app.CommentProcessor
import com.commentremover.app.CommentRemover
import groovy.io.FileType
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.Configuration
import org.gradle.api.tasks.*

import java.nio.charset.Charset
import java.nio.file.Files
import java.security.MessageDigest

@CacheableTask
class Wsdl2JavaTask extends DefaultTask {
static final DESTINATION_DIR = "build/generated/wsdl"

private static final NEWLINE = System.getProperty("line.separator")

@OutputDirectory
File generatedWsdlDir = new File(DESTINATION_DIR)

@InputFiles
@Classpath
Expand Down Expand Up @@ -63,7 +63,9 @@ class Wsdl2JavaTask extends DefaultTask {
throw new TaskExecutionException(this, e)
}
}

if (extension.removeComments) {
removeComments(targetDir)
}
copyToOutputDir(targetDir)
}
}
Expand Down Expand Up @@ -100,7 +102,7 @@ class Wsdl2JavaTask extends DefaultTask {
packagePaths.add("") // add root if no package paths
}

Set<File> packageTargetDirs = packagePaths.collect { subPath -> new File(generatedWsdlDir, subPath) }
Set<File> packageTargetDirs = packagePaths.collect { subPath -> new File(new File(extension.outputDirectory), subPath) }
getLogger().info("Clear target folders {}", packageTargetDirs)
getProject().delete(packageTargetDirs)
}
Expand All @@ -126,7 +128,7 @@ class Wsdl2JavaTask extends DefaultTask {

srcDir.eachFileRecurse(FileType.FILES) { file ->
String relPath = file.getAbsolutePath().substring(srcPathLength)
File target = new File(generatedWsdlDir, relPath)
File target = new File(new File(extension.outputDirectory), relPath)

switchToEncoding(file)

Expand All @@ -139,20 +141,30 @@ class Wsdl2JavaTask extends DefaultTask {
}

protected void switchToEncoding(File file) {
List<String> lines = file.getText().split(NEWLINE)
List<String> lines = Files.readAllLines(file.toPath(), Charset.defaultCharset())
file.delete()

if (extension.stabilize) {
stripCommentDates(lines)
stabilizeCommentLinks(file, lines)
stabilizeXmlElementRef(file, lines)
stabilizeXmlSeeAlso(file, lines)
stripFirstLineIfEmpty(lines)
}

String text = lines.join(NEWLINE) + NEWLINE // want empty line last
println("First line is: ${lines.get(0)}")
String text = lines.join("\n") + "\n" // want empty line last
file.withWriter(extension.encoding) { w -> w.write(text) }
}

void stripFirstLineIfEmpty(List<String> lines) {
if (lines.get(0) == null || lines.get(0).length() < 2) {
println("Removing first line of empty file: ${lines.get(0)}")
lines.remove(0)
}else{
println("Not Removing first line of empty file: ${lines.get(0)}")
}
}

void stripCommentDates(List<String> lines) {
String prevLine = ""
for (ListIterator<String> lix = lines.listIterator(); lix.hasNext();) {
Expand Down Expand Up @@ -261,4 +273,17 @@ class Wsdl2JavaTask extends DefaultTask {
private boolean isObjectFactory(File f) {
return "ObjectFactory.java".equals(f.getName())
}

protected void removeComments(File targetDir) {
println("Removing comments on ${targetDir.getAbsolutePath()}")
def commentRemover = new CommentRemover.CommentRemoverBuilder()
.removeJava(true)
.removeSingleLines(true)
.removeMultiLines(true)
.preserveJavaClassHeaders(false)
.preserveCopyRightHeaders(false)
.startExternalPath(targetDir.getAbsolutePath())
.build()
new CommentProcessor(commentRemover).start()
}
}