diff --git a/README.md b/README.md index e8b4e92..d03ad49 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,25 @@ __Maven__ ``` +### shaded jar + +There is a shaded jar available that contains the lib including shaded versions of its transitive dependencies. +Use this if you experience issues with having multiple versions of antlr on the classpath. + +__Gradle__ +```gradle +implementation "org.mini2Dx:gettext-lib-all:1.9.2" +``` + +__Maven__ +```xml + + org.mini2Dx + gettext-lib-all + 1.9.2 + +``` + ### Gradle Plugin The Gradle plugin can parse files and generate a .pot based on the source code. diff --git a/build.gradle b/build.gradle index 1e2694d..4be223d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,224 +1,264 @@ buildscript { repositories { - mavenLocal() + mavenLocal() mavenCentral() jcenter() maven { url 'https://plugins.gradle.org/m2/' } } dependencies { - classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.9.0' + classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.9.0' + classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0' } } -if(project.hasProperty('ossrhUser') && project.hasProperty("release")) { - apply plugin: "io.codearte.nexus-staging" +if (project.hasProperty('ossrhUser') && project.hasProperty("release")) { + apply plugin: "io.codearte.nexus-staging" - nexusStaging { - packageGroup = 'org.mini2Dx' - username = ossrhUser - password = ossrhPassword - } + nexusStaging { + packageGroup = 'org.mini2Dx' + username = ossrhUser + password = ossrhPassword + } } ext { - antlrVersion = '4.7.3' - - junitVersion="4.8.1" - jmockVersion="2.5.1" + antlrVersion = '4.7.3' + + junitVersion = "4.8.1" + jmockVersion = "2.5.1" } subprojects { apply plugin: "eclipse" apply plugin: "idea" - + tasks.eclipse.doLast { - delete ".project" - } - - repositories { - mavenLocal() - mavenCentral() - maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } - maven { url "https://oss.sonatype.org/content/repositories/releases/" } - maven { url 'https://maven.google.com' } - } + delete ".project" + } + + repositories { + mavenLocal() + mavenCentral() + maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } + maven { url "https://oss.sonatype.org/content/repositories/releases/" } + maven { url 'https://maven.google.com' } + } } def mavenProjects() { - subprojects.findAll { !it.name.contains('antlr') } + subprojects.findAll { !it.name.contains('antlr') } } -def projectVersion = '1.9.1'; +def projectVersion = '1.9.2-SNAPSHOT'; def docProjects() { - subprojects.findAll { !it.name.contains('gradle') && !it.name.contains('antlr') } + subprojects.findAll { !it.name.contains('gradle') && !it.name.contains('antlr') } +} + +def commonPomConfig = { + pom -> + pom.with { + url = 'https://github.com/mini2Dx/gettext' + + licenses { + license { + name = 'Apache License 2.0' + url = 'https://opensource.org/licenses/Apache-2.0' + } + } + + developers { + developer { + id = 'tomcashman' + name = 'Thomas Cashman' + email = 'thomascashman404@gmail.com' + } + } + + scm { + connection = 'scm:git:https://github.com/mini2Dx/gettext.git' + developerConnection = 'scm:git:git@github.com:mini2Dx/gettext.git' + url = 'https://github.com/mini2Dx/gettext.git' + } + } } configure(mavenProjects()) { - apply plugin: "signing" - apply plugin: "maven" - apply plugin: "java" - - group = 'org.mini2Dx' - version = projectVersion - - apply plugin: "java" - - sourceCompatibility = 1.7 - targetCompatibility = 1.7 - - compileJava.options.encoding = 'UTF-8' - compileTestJava.options.encoding = 'UTF-8' - - task sourcesJar(type: Jar) { - classifier = 'sources' - from sourceSets.main.allSource - } - - task javadocJar(type: Jar) { - classifier = 'javadoc' - from javadoc - } - - tasks.withType(Test) { - systemProperty "file.encoding", "UTF-8" - } - - artifacts { - archives javadocJar, sourcesJar - } - - if(project.hasProperty('ossrhUser')) { - signing { - sign configurations.archives - } - - uploadArchives { - repositories { - mavenDeployer { - // POM signature - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - // Target repository - repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: ossrhUser, password: ossrhPassword) - } - pom.project { - name project.name - description project.description - packaging 'jar' - url 'https://github.com/mini2Dx/gettext' - - scm { - connection 'scm:git:https://github.com/mini2Dx/gettext.git' - developerConnection 'scm:git:git@github.com:mini2Dx/gettext.git' - url 'https://github.com/mini2Dx/gettext.git' - } - - licenses { - license { - name 'Apache License 2.0' - url 'https://opensource.org/licenses/Apache-2.0' - distribution 'repo' - } - } - - developers { - developer { - id = 'tomcashman' - name = 'Thomas Cashman' - email = 'thomascashman404@gmail.com' - } - } - } - } - } - } - } + apply plugin: "signing" + apply plugin: "maven-publish" + apply plugin: "java" + + group = 'org.mini2Dx' + version = projectVersion + + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + + compileJava.options.encoding = 'UTF-8' + compileTestJava.options.encoding = 'UTF-8' + + java { + withJavadocJar() + withSourcesJar() + } + + tasks.withType(Test) { + systemProperty "file.encoding", "UTF-8" + } + + publishing { + repositories { + maven { + url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + + if (project.hasProperty('ossrhUser')) { + credentials { + username ossrhUser + password ossrhPassword + } + } + } + } + + publications { + mavenJava(MavenPublication) { + from components.java + commonPomConfig pom + } + } + } + + if (project.hasProperty('ossrhUser')) { + signing { + sign publishing.publications.mavenJava + } + } } project(":gettext-antlr") { - apply plugin: 'antlr' - - description = 'ANTLR4 grammar for GNU gettext' - - sourceCompatibility = 1.7 - targetCompatibility = 1.7 - - dependencies { - antlr "com.tunnelvisionlabs:antlr4:$antlrVersion" - } - - generateGrammarSource { - arguments += ["-package", "org.mini2Dx.gettext.antlr"] - } + apply plugin: 'antlr' + + description = 'ANTLR4 grammar for GNU gettext' + + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + + dependencies { + antlr "com.tunnelvisionlabs:antlr4:$antlrVersion" + } + + generateGrammarSource { + arguments += ["-package", "org.mini2Dx.gettext.antlr"] + } } project(":gettext-lib") { description = 'Library for using GNU gettext' - + task copyAntlrSourcesToProject(type: Copy, dependsOn: project(":gettext-antlr").compileJava) { - from "$projectDir/../gettext-antlr/build/generated-src/antlr/main/" - into "$projectDir/src/main/java/org/mini2Dx/gettext/antlr/" - } - - dependencies { - compile "com.tunnelvisionlabs:antlr4-runtime:$antlrVersion" - - testCompile "junit:junit:$junitVersion" - testCompile "org.jmock:jmock-legacy:$jmockVersion" - testCompile "org.jmock:jmock-junit4:$jmockVersion" - } - - compileJava.dependsOn copyAntlrSourcesToProject + from "$projectDir/../gettext-antlr/build/generated-src/antlr/main/" + into "$projectDir/src/main/java/org/mini2Dx/gettext/antlr/" + } + + dependencies { + compile "com.tunnelvisionlabs:antlr4-runtime:$antlrVersion" + + testCompile "junit:junit:$junitVersion" + testCompile "org.jmock:jmock-legacy:$jmockVersion" + testCompile "org.jmock:jmock-junit4:$jmockVersion" + } + + compileJava.dependsOn copyAntlrSourcesToProject +} + +project(":gettext-lib-all") { + + apply plugin: 'com.github.johnrengelman.shadow' + + dependencies { + compile project(":gettext-lib") + } + + shadowJar { + archiveClassifier.set('') + relocate 'org.antlr', 'mini2dx.shadow.org.antlr' + exclude 'META-INF/services/*' + } + + publishing { + publications { + shadow(MavenPublication) { publication -> + project.shadow.component(publication) + + commonPomConfig publication.pom + } + } + } + + if (project.hasProperty('ossrhUser')) { + signing { + sign publishing.publications.shadow + } + } +} + + +project(":gettext-lib-all-example") { + + dependencies { + implementation project(path: ":gettext-lib-all", configuration: "shadow") + testImplementation "junit:junit:$junitVersion" + } + + publishMavenJavaPublicationToMavenRepository.enabled = false + publishToMavenLocal.enabled = false + publishMavenJavaPublicationToMavenLocal.enabled = false + publish.enabled = false } project(":gettext-xlsx") { - description = 'Library to convert .po files to/from xlsx' - - dependencies { - compile project(":gettext-lib") - compile "org.apache.poi:poi-ooxml:4.1.2" - - testCompile "junit:junit:$junitVersion" - testCompile "org.jmock:jmock-legacy:$jmockVersion" - testCompile "org.jmock:jmock-junit4:$jmockVersion" - } - - if(!project.version.contains("SNAPSHOT")) { - task docs(type: Javadoc) { - failOnError = false - title = 'gettext' - source docProjects().collect {p -> p.sourceSets.main.allJava } - classpath = files(docProjects().collect {p -> p.sourceSets.main.compileClasspath}) - destinationDir = rootProject.file("docs/javadoc/${projectVersion}") - } - } + description = 'Library to convert .po files to/from xlsx' + + dependencies { + compile project(":gettext-lib") + compile "org.apache.poi:poi-ooxml:4.1.2" + + testCompile "junit:junit:$junitVersion" + testCompile "org.jmock:jmock-legacy:$jmockVersion" + testCompile "org.jmock:jmock-junit4:$jmockVersion" + } + + if (!project.version.contains("SNAPSHOT")) { + task docs(type: Javadoc) { + failOnError = false + title = 'gettext' + source docProjects().collect { p -> p.sourceSets.main.allJava } + classpath = files(docProjects().collect { p -> p.sourceSets.main.compileClasspath }) + destinationDir = rootProject.file("docs/javadoc/${projectVersion}") + } + } } project(":gettext-gradle-plugin") { - apply plugin: 'groovy' - apply plugin: 'antlr' + apply plugin: 'groovy' + apply plugin: 'antlr' - description = 'Gradle plugin for generating .pot files from source files' + description = 'Gradle plugin for generating .pot files from source files' - dependencies { - compile gradleApi() - compile localGroovy() + dependencies { + compile gradleApi() + compile localGroovy() - compile project(":gettext-lib") - compile "com.tunnelvisionlabs:antlr4-runtime:$antlrVersion" + compile project(":gettext-lib") + compile "com.tunnelvisionlabs:antlr4-runtime:$antlrVersion" - antlr "com.tunnelvisionlabs:antlr4:$antlrVersion" - - testCompile "junit:junit:$junitVersion" - testCompile gradleTestKit() - } + antlr "com.tunnelvisionlabs:antlr4:$antlrVersion" - generateGrammarSource { - arguments += ["-package", "org.mini2Dx.gettext.plugin.antlr"] - } -} + testCompile "junit:junit:$junitVersion" + testCompile gradleTestKit() + } -task wrapper(type: Wrapper) { - gradleVersion = '4.10.3' + generateGrammarSource { + arguments += ["-package", "org.mini2Dx.gettext.plugin.antlr"] + } } diff --git a/gettext-lib-all-example/src/test/java/org/mini2Dx/all/LibTest.java b/gettext-lib-all-example/src/test/java/org/mini2Dx/all/LibTest.java new file mode 100644 index 0000000..6a9877a --- /dev/null +++ b/gettext-lib-all-example/src/test/java/org/mini2Dx/all/LibTest.java @@ -0,0 +1,28 @@ +package org.mini2Dx.all; + +import org.junit.Assert; +import org.junit.Test; +import org.mini2Dx.gettext.*; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Locale; + +public class LibTest { + @Test + public void testReadWritePoFile() throws IOException { + final PoFile expected = new PoFile(Locale.ENGLISH, LibTest.class.getResourceAsStream("/sample_en.po")); + final File tmpFile = Files.createTempFile("", ".po").toFile(); + expected.saveTo(tmpFile); + + final PoFile result = new PoFile(Locale.ENGLISH, tmpFile); + + Assert.assertEquals(expected.getEntries().size(), result.getEntries().size()); + for(int i = 0; i < expected.getEntries().size(); i++) { + final TranslationEntry expectedEntry = expected.getEntries().get(i); + final TranslationEntry resultEntry = result.getEntries().get(i); + Assert.assertEquals(expectedEntry, resultEntry); + } + } +} diff --git a/gettext-lib-all-example/src/test/resources/sample_en.po b/gettext-lib-all-example/src/test/resources/sample_en.po new file mode 100644 index 0000000..614baf7 --- /dev/null +++ b/gettext-lib-all-example/src/test/resources/sample_en.po @@ -0,0 +1,23 @@ +# translator-comments +#. extracted-comments +#: src/msgcmp.java:322 +msgid "Unknown \"system\" error" +msgstr "Unknown \"system\" error" + +#: src/msgcmp.java:323 +#, java-format +msgid "found {0} fatal error" +msgid_plural "found {0} fatal errors" +msgstr[0] "found {0} fatal error" +msgstr[1] "found {0} fatal errors" + +# Translator comments +#| msgctxt previous-context +#| msgid previous-untranslated-string +msgid "" +"Here is an example of how one might continue a very long string\n" +"for the common case the string represents multi-line output.\n" +msgstr "" +"Here is an example of how one might continue a very long string\n" +"for the common case the string represents multi-line output.\n" + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index a5fe1cb..94336fc 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1d5b29f..442d913 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip diff --git a/settings.gradle b/settings.gradle index b61f087..e6d84e1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,3 @@ -include "gettext-antlr", "gettext-lib", "gettext-xlsx", "gettext-gradle-plugin" +include "gettext-antlr", "gettext-lib", "gettext-xlsx", "gettext-gradle-plugin", "gettext-lib-all", "gettext-lib-all-example" rootProject.name = "gettext" \ No newline at end of file