From 9ac8021d5511265422fa01bafb82791055e49360 Mon Sep 17 00:00:00 2001 From: vrossello Date: Tue, 16 Mar 2021 13:19:51 +0100 Subject: [PATCH 1/3] Compile scope is deprecated and removed in gradle 7.0 --- src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPlugin.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPlugin.groovy b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPlugin.groovy index c0d705d..985aa42 100644 --- a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPlugin.groovy +++ b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPlugin.groovy @@ -26,8 +26,8 @@ class Wsdl2JavaPlugin implements Plugin { // 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)) } From 768d07316824b8b284d031f38e7782ca64adcff3 Mon Sep 17 00:00:00 2001 From: vrossello Date: Thu, 27 Jan 2022 16:28:41 +0100 Subject: [PATCH 2/3] Quitar comentarios y primera linea --- build.gradle | 48 ++++++------------- .../wsdl2java/Wsdl2JavaPluginExtension.groovy | 3 ++ .../no/nils/wsdl2java/Wsdl2JavaTask.groovy | 27 ++++++++++- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/build.gradle b/build.gradle index e86418c..26f0415 100644 --- a/build.gradle +++ b/build.gradle @@ -2,13 +2,13 @@ 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.3' // stay compatible with the crowd sourceCompatibility = JavaVersion.VERSION_1_6 @@ -16,10 +16,14 @@ targetCompatibility = JavaVersion.VERSION_1_6 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' @@ -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 } diff --git a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPluginExtension.groovy b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPluginExtension.groovy index 38cdf48..bdacfb9 100644 --- a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPluginExtension.groovy +++ b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPluginExtension.groovy @@ -21,6 +21,9 @@ class Wsdl2JavaPluginExtension { @Input String encoding = Charset.defaultCharset().name() + @Input + boolean removeComments = true + @Input boolean stabilize = false diff --git a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaTask.groovy b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaTask.groovy index b422cee..9f87263 100644 --- a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaTask.groovy +++ b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaTask.groovy @@ -4,8 +4,11 @@ import groovy.io.FileType import org.gradle.api.DefaultTask import org.gradle.api.artifacts.Configuration import org.gradle.api.tasks.* +import org.gradle.internal.component.external.model.ComponentVariant import java.security.MessageDigest +import com.commentremover.app.CommentRemover +import com.commentremover.app.CommentProcessor @CacheableTask class Wsdl2JavaTask extends DefaultTask { @@ -63,7 +66,9 @@ class Wsdl2JavaTask extends DefaultTask { throw new TaskExecutionException(this, e) } } - + if (extension.removeComments) { + removeComments(targetDir) + } copyToOutputDir(targetDir) } } @@ -147,12 +152,19 @@ class Wsdl2JavaTask extends DefaultTask { stabilizeCommentLinks(file, lines) stabilizeXmlElementRef(file, lines) stabilizeXmlSeeAlso(file, lines) + stripFirstLineIfEmpty(lines) } String text = lines.join(NEWLINE) + NEWLINE // want empty line last file.withWriter(extension.encoding) { w -> w.write(text) } } + void stripFirstLineIfEmpty(List lines) { + if("".equals(lines.get(0))) { + lines.remove(0) + } + } + void stripCommentDates(List lines) { String prevLine = "" for (ListIterator lix = lines.listIterator(); lix.hasNext();) { @@ -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() + } } From 6fe13e824ae6c347692e48166b42a1070c9e8a1e Mon Sep 17 00:00:00 2001 From: vrossello Date: Thu, 27 Jan 2022 17:33:48 +0100 Subject: [PATCH 3/3] Customizar el directorio de salida --- build.gradle | 8 +++--- .../no/nils/wsdl2java/Wsdl2JavaPlugin.groovy | 4 --- .../wsdl2java/Wsdl2JavaPluginExtension.groovy | 4 +++ .../no/nils/wsdl2java/Wsdl2JavaTask.groovy | 26 +++++++++---------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index 26f0415..6bbd58e 100644 --- a/build.gradle +++ b/build.gradle @@ -8,14 +8,13 @@ plugins { } group = 'no.nils' -version = '0.13-TRAVELC.3' +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" } @@ -36,6 +35,7 @@ dependencies { java { withSourcesJar() + withJavadocJar() } test { diff --git a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPlugin.groovy b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPlugin.groovy index 985aa42..ada3932 100644 --- a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPlugin.groovy +++ b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPlugin.groovy @@ -72,10 +72,6 @@ class Wsdl2JavaPlugin implements Plugin { it.dependsOn wsdl2JavaTask } } - - project.sourceSets { - main.java.srcDirs += Wsdl2JavaTask.DESTINATION_DIR - } } static Class getTaskClass(name) { diff --git a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPluginExtension.groovy b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPluginExtension.groovy index bdacfb9..8e11952 100644 --- a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPluginExtension.groovy +++ b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaPluginExtension.groovy @@ -12,6 +12,10 @@ class Wsdl2JavaPluginExtension { @PathSensitive(PathSensitivity.ABSOLUTE) File wsdlDir = new File(DEFAULT_WSDL_DIR) + + @Input + String outputDirectory = "build/generated/" + @Input List> wsdlsToGenerate diff --git a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaTask.groovy b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaTask.groovy index 9f87263..aeb8302 100644 --- a/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaTask.groovy +++ b/src/main/groovy/no/nils/wsdl2java/Wsdl2JavaTask.groovy @@ -1,23 +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 org.gradle.internal.component.external.model.ComponentVariant +import java.nio.charset.Charset +import java.nio.file.Files import java.security.MessageDigest -import com.commentremover.app.CommentRemover -import com.commentremover.app.CommentProcessor @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 @@ -105,7 +102,7 @@ class Wsdl2JavaTask extends DefaultTask { packagePaths.add("") // add root if no package paths } - Set packageTargetDirs = packagePaths.collect { subPath -> new File(generatedWsdlDir, subPath) } + Set packageTargetDirs = packagePaths.collect { subPath -> new File(new File(extension.outputDirectory), subPath) } getLogger().info("Clear target folders {}", packageTargetDirs) getProject().delete(packageTargetDirs) } @@ -131,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) @@ -144,7 +141,7 @@ class Wsdl2JavaTask extends DefaultTask { } protected void switchToEncoding(File file) { - List lines = file.getText().split(NEWLINE) + List lines = Files.readAllLines(file.toPath(), Charset.defaultCharset()) file.delete() if (extension.stabilize) { @@ -154,14 +151,17 @@ class Wsdl2JavaTask extends DefaultTask { 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 lines) { - if("".equals(lines.get(0))) { + 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)}") } }