-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate to conventions plugin
- Use indirect task reference for caching - Space-assignment syntax in Groovy DSL has been deprecated - Replace deprecated exec to injected operations - Introduce build-logic convention plugin - Move gradle/utils.gradle definitions to convention plugin - Move allProjects{} definition to convention plugin - Jaxb tasks as a convention plugin - Move doc related to document-conventions plugin - Move jpackage related to jpkg-conventions.gradle - Move launch4j configurations into windows-conventions.gradle - Migrate modules to use org.omegat.java-conventions plugin Signed-off-by: Hiroshi Miura <[email protected]>
- Loading branch information
Showing
58 changed files
with
857 additions
and
1,004 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
plugins { | ||
id 'java-library' | ||
id 'org.omegat.java-conventions' | ||
} | ||
|
||
dependencies { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
plugins { | ||
id 'groovy-gradle-plugin' | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation 'com.github.ben-manes:gradle-versions-plugin:0.51.0' | ||
implementation 'com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.26' | ||
implementation 'com.diffplug.spotless:spotless-plugin-gradle:7.0.0.BETA4' | ||
implementation 'edu.sc.seis.launch4j:launch4j:3.0.6' | ||
} |
48 changes: 48 additions & 0 deletions
48
build-logic/src/main/groovy/org.omegat.common-utilities.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import javax.inject.Inject | ||
|
||
interface InjectedExecOps { | ||
@Inject | ||
ExecOperations getExecOps() | ||
} | ||
|
||
ext.loadProperties = { propFile -> | ||
def config = new Properties() | ||
if (propFile.canRead()) { | ||
propFile.withInputStream { config.load(it) } | ||
} | ||
config | ||
} | ||
|
||
ext { | ||
exePresent = { exe -> | ||
["where $exe", "which $exe"].any { | ||
try { | ||
def findExe = it.execute() | ||
findExe.waitForProcessOutput() | ||
return findExe.exitValue() == 0 | ||
} catch (any) { | ||
return false | ||
} | ||
} | ||
} | ||
|
||
conditions = { List... items -> | ||
items.each { val, str -> | ||
if (!val) { | ||
logger.warn(str) | ||
} | ||
} | ||
items.every { it[0] } | ||
} | ||
|
||
condition = { val, str -> | ||
conditions([val, str]) | ||
} | ||
|
||
replaceRelativePathSegment = { FileCopyDetails deets, pattern, replacement -> | ||
def segs = deets.relativePath.segments.collect { | ||
it =~ pattern ? replacement : it | ||
} | ||
deets.relativePath = new RelativePath(!deets.directory, segs as String[]) | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
build-logic/src/main/groovy/org.omegat.document-conventions.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
plugins { | ||
id 'org.omegat.common-utilities' | ||
} | ||
|
||
tasks.register('manualZips') { | ||
description = 'Build ZIP manuals to bundle into application. Requires container runtime.' | ||
group = 'documentation' | ||
} | ||
|
||
tasks.register('manualPdfs') { | ||
description = 'Build PDF manuals for all languages. Requires container runtime.' | ||
group = 'documentation' | ||
} | ||
|
||
tasks.register('manualHtmls') { | ||
description = 'Build HTML manuals and zip for all languages. Requires container runtime.' | ||
group = 'documentation' | ||
} | ||
|
||
tasks.register('genDocIndex', Copy) { | ||
def docPropsFiles = fileTree(dir: 'doc_src', include: '*/version*.properties').findAll { | ||
file("${it.parent}/OmegaTUsersManual_xinclude full.xml").file } | ||
def langNameExceptions = loadProperties(file('doc_src/lang_exceptions.properties')) | ||
def langInfos = docPropsFiles.toSorted{ it.parentFile.name }.collect { props -> | ||
def docVersion = loadProperties(props).version | ||
['code': props.parentFile.name, 'nomanual': false, 'version': docVersion, | ||
'name': langNameExceptions[props.parentFile.name] ?: | ||
Locale.forLanguageTag(props.parentFile.name.replace('_', '-')).getDisplayName(), | ||
'status': docVersion == omtVersion.version ? 'up-to-date' : 'out-of-date'] } | ||
def inputTemplate = file('doc_src/index_template.html') | ||
def outputIndex = layout.buildDirectory.file("docs/manual/index.html").get().asFile | ||
description = 'Generate the docs index file' | ||
inputs.files docPropsFiles, inputTemplate | ||
outputs.files file(outputIndex) | ||
from inputTemplate | ||
into outputIndex.parent | ||
rename('index_template.html', 'index.html') | ||
expand('languages': langInfos) | ||
filteringCharset = 'UTF-8' | ||
dependsOn manualHtmls | ||
group = 'documentation' | ||
} | ||
|
||
tasks.register('webManual', Sync) { | ||
group = 'documentation' | ||
description = 'Sync the HTML manual files' | ||
dependsOn manualHtmls, genDocIndex | ||
destinationDir = file(layout.buildDirectory.file("docs/htdocs")) | ||
from file(layout.buildDirectory.file("docs/manual")) | ||
from('release') { | ||
include 'doc-license.txt' | ||
} | ||
} | ||
|
||
ext.manualIndexXmls = fileTree(dir: 'doc_src', include: '**/OmegaTUsersManual_xinclude full.xml') | ||
manualIndexXmls.each { xml -> | ||
def lang = xml.parentFile.name | ||
def pdfTaskName = "manualPdf${lang.capitalize()}" | ||
tasks.register(pdfTaskName, Exec) { | ||
inputs.files fileTree(dir: "doc_src/${lang}", includes: ['**/*.xml', 'images/*.png'], | ||
excludes: ['xhtml5/*', 'index.xml']) | ||
outputs.files layout.buildDirectory.file("docs/pdfs/OmegaT_documentation_${lang}.PDF") | ||
onlyIf { | ||
conditions([exePresent('docker') || exePresent('nerdctl'), 'Docker or nerdctl is not installed'], | ||
[!project.hasProperty('forceSkipDocumentBuild'), 'Specified forceSkipDocumentBuild property']) | ||
} | ||
workingDir = 'doc_src' | ||
commandLine './docgen', "-Dlanguage=${lang}", "-Dtarget=../build/docs/pdfs", 'pdf' | ||
doLast { | ||
delete fileTree(dir: "doc_src/${lang}", includes: ['pdf/*', 'index.xml']) | ||
} | ||
} | ||
manualPdfs.dependsOn pdfTaskName | ||
|
||
def htmlTaskName = "manualHtml${lang.capitalize()}" | ||
tasks.register(htmlTaskName, Exec) { | ||
inputs.files fileTree(dir: "doc_src/${lang}", includes: ['**/*.xml', 'images/*.png'], | ||
excludes: ['xhtml5/*', 'index.xml']) | ||
outputs.files fileTree(dir: layout.buildDirectory.file("docs/manual/${lang}/"), | ||
includes: ['*.html', 'OmegaT.css', 'images/*.png', '_wh/**/*.js', '_wh/wh.css']) | ||
onlyIf { | ||
conditions([exePresent('docker') || exePresent('nerdctl'), 'Docker or nerdctl is not installed'], | ||
[!project.hasProperty('forceSkipDocumentBuild'), 'Specified forceSkipDocumentBuild property']) | ||
} | ||
workingDir = 'doc_src' | ||
commandLine './docgen', "-Dlanguage=${lang}", "-Dtarget=../build/docs/manual/${lang}", 'html5' | ||
} | ||
manualHtmls.dependsOn htmlTaskName | ||
|
||
def zipTaskName="manualZip${lang.capitalize()}" | ||
def versionProperties = loadProperties(file("doc_src/${lang}/version_${lang}.properties")) | ||
if (lang.equals("en") || versionProperties.version.equals(omtVersion.version)) { | ||
tasks.register(zipTaskName, Zip) { | ||
from fileTree(dir: layout.buildDirectory.file("docs/manual/${lang}")) | ||
exclude 'docs/manual/index.html' | ||
from fileTree(dir: "doc_src/${lang}", include: '**/version*.properties') | ||
archiveFileName = "${lang}.zip" | ||
destinationDirectory = file("${buildDir}/docs/manuals/") | ||
} | ||
manualZips.dependsOn zipTaskName | ||
tasks.getByName(zipTaskName).dependsOn htmlTaskName | ||
} | ||
} | ||
|
||
tasks.register('firstSteps') { | ||
description = 'Build First pages for all languages at docs/greetings/. Requires Docker.' | ||
group = 'documentation' | ||
} | ||
|
||
tasks.register('updateManuals') { | ||
group = 'documentation' | ||
description = 'Update Instant Start guides and HTML manuals.' | ||
dependsOn manualHtmls, firstSteps, genDocIndex | ||
} | ||
|
||
ext.firstStepsXmls = fileTree(dir: 'doc_src', include: '**/First_Steps.xml') | ||
firstStepsXmls.each { xml -> | ||
def lang = xml.parentFile.name | ||
def taskName = "firstSteps${lang.capitalize()}" | ||
tasks.register(taskName, Exec) { | ||
inputs.files fileTree(dir: "doc_src/${lang}", include: 'First_Steps.xml') | ||
outputs.files fileTree(dir: layout.buildDirectory.file('docs/greetings/'), | ||
includes: ["${lang}/first_steps.html", "${lang}/OmegaT.css"]) | ||
onlyIf { | ||
conditions([exePresent('docker') || exePresent('nerdctl'), 'Docker or nerdctl is not installed'], | ||
[!project.hasProperty('forceSkipDocumentBuild'), 'Specified forceSkipDocumentBuild property']) | ||
} | ||
workingDir = 'doc_src' | ||
commandLine './docgen', "-Dlanguage=${lang}", "-Dtarget=../build/docs/greetings/${lang}", 'first-steps' | ||
} | ||
|
||
firstSteps.dependsOn taskName | ||
} | ||
|
||
ext.instantStartXmls = fileTree(dir: 'doc_src', include: '**/InstantStartGuide.xml') | ||
instantStartXmls.each { xml -> | ||
def lang = xml.parentFile.name | ||
def taskName = "instantStartGuide${lang.capitalize()}" | ||
tasks.register(taskName, Exec) { | ||
inputs.files fileTree(dir: "doc_src/${lang}", includes: ['InstantStartGuide.xml', '**/InstantGuide*png']) | ||
outputs.files fileTree(dir: layout.buildDirectory.file('docs/greetings/'), | ||
includes: ["${lang}/first_steps.html", "${lang}/images/InstantGuide*png", "${lang}/OmegaT.css"]) | ||
onlyIf { | ||
conditions([exePresent('docker') || exePresent('nerdctl'), 'Docker or nerdctl is not installed'], | ||
[!project.hasProperty('forceSkipDocumentBuild'), 'Specified forceSkipDocumentBuild property']) | ||
} | ||
workingDir = 'doc_src' | ||
commandLine './docgen', "-Dlanguage=${lang}", "-Dtarget=../build/docs/greetings/${lang}", 'instant-start' | ||
} | ||
firstSteps.dependsOn taskName | ||
} |
146 changes: 146 additions & 0 deletions
146
build-logic/src/main/groovy/org.omegat.java-conventions.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import com.github.spotbugs.snom.Confidence | ||
|
||
plugins { | ||
id 'java-library' | ||
id 'eclipse' | ||
id 'checkstyle' | ||
id 'jacoco' | ||
id 'com.github.ben-manes.versions' | ||
id 'com.diffplug.spotless' | ||
id 'com.github.spotbugs' | ||
id 'org.omegat.common-utilities' | ||
} | ||
|
||
// Definition of OmegaT versioning | ||
def localPropsFile = file('local.properties') | ||
|
||
// Define target Java version to compatible. | ||
def javaVersion = 11; | ||
|
||
// Flag to detect CI/CD environment | ||
def envIsCi = project.hasProperty('envIsCi') as Boolean | ||
|
||
ext { | ||
if (localPropsFile.file) { | ||
loadProperties(localPropsFile).each { k, v -> | ||
if (!findProperty(k)) { | ||
set(k, v) | ||
} | ||
} | ||
} | ||
providedCoreLibsDir = file('lib/provided/core') | ||
providedModuleLibsDir = file('lib/provided/module') | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(javaVersion) | ||
vendor = JvmVendorSpec.ADOPTIUM | ||
} | ||
} | ||
|
||
tasks.withType(Test).configureEach { | ||
workingDir project.rootProject.projectDir | ||
} | ||
|
||
javadoc { | ||
failOnError = false | ||
options { | ||
jFlags('-Duser.language=en') | ||
addStringOption('locale', 'en_US') | ||
addStringOption('bottom', '<span>Copyright 2000-2023, OmegaT project and contributors</span>') | ||
addStringOption('encoding', 'UTF-8') | ||
addBooleanOption("Xdoclint:none", true) | ||
addBooleanOption('html5', true) | ||
addBooleanOption('frames', false) | ||
addBooleanOption('public', true) | ||
} | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.encoding = "UTF-8" | ||
options.compilerArgs.addAll '-Xlint', '-Werror' | ||
} | ||
|
||
spotbugs { | ||
reportLevel = Confidence.valueOf('HIGH') | ||
} | ||
|
||
tasks.register('spotbugsMainReport') { | ||
def reportFile = file("build/reports/spotbugs/main.txt") | ||
doLast { | ||
if (reportFile.exists()) { | ||
println() | ||
reportFile.readLines().forEach { | ||
println(it) | ||
} | ||
} | ||
} | ||
group = 'verification' | ||
} | ||
|
||
tasks.register('spotbugsTestReport') { | ||
def reportFile = file("build/reports/spotbugs/test.txt") | ||
doLast { | ||
if (reportFile.exists()) { | ||
println() | ||
reportFile.readLines().forEach { | ||
println(it) | ||
} | ||
} | ||
} | ||
group = 'verification' | ||
} | ||
|
||
spotbugsMain { | ||
if (envIsCi) { | ||
extraArgs = ['-longBugCodes'] | ||
jvmArgs = ['-Duser.language=en'] | ||
} | ||
reports { | ||
text.required = envIsCi | ||
html.required = !envIsCi | ||
} | ||
finalizedBy(spotbugsMainReport) | ||
} | ||
|
||
spotbugsTest { | ||
if (envIsCi) { | ||
extraArgs = ['-longBugCodes'] | ||
jvmArgs = ['-Duser.language=en'] | ||
} | ||
reports { | ||
text.required = envIsCi | ||
html.required = !envIsCi | ||
} | ||
finalizedBy(spotbugsTestReport) | ||
} | ||
|
||
checkstyle { | ||
toolVersion = libs.versions.checkstyle.get() | ||
} | ||
checkstyleMain.exclude '**/gen/**' | ||
|
||
spotless { | ||
enforceCheck = false | ||
java { | ||
targetExclude 'src/gen/**' | ||
eclipse().configFile file("${rootDir}/config/spotless/eclipse-formatting.xml") | ||
removeUnusedImports() | ||
} | ||
} | ||
|
||
tasks.withType(Copy).configureEach { | ||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE | ||
} | ||
tasks.withType(Sync).configureEach { | ||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE | ||
} | ||
tasks.withType(Zip).configureEach { | ||
duplicatesStrategy = DuplicatesStrategy.INCLUDE | ||
} |
Oops, something went wrong.