Skip to content
Permalink
Browse files

Create a new app to hold GenerateSqlSchemaCommand (#409)

* Create a new app to hold GenerateSqlSchemaCommand

GenerateSqlSchemaCommand starts postgresql using testcontainer.
This makes junit etc a runtime dependency, allowing them to get
into release artifacts.

By moving this command to a separate tool, we can remove junit
etc as compile/runtime dependency.
  • Loading branch information
weiminyu committed Dec 13, 2019
1 parent 1143b25 commit 6aaf081489e2926e75ef013317149e8314da4e6c
Showing with 1,164 additions and 155 deletions.
  1. +15 −6 build.gradle
  2. +91 −47 core/build.gradle
  3. +0 −2 core/gradle/dependency-locks/compileClasspath.lockfile
  4. +0 −2 core/gradle/dependency-locks/deploy_jar.lockfile
  5. +3 −0 core/gradle/dependency-locks/devtool.lockfile
  6. +24 −0 core/gradle/dependency-locks/nonprodAnnotationProcessor.lockfile
  7. +3 −0 core/gradle/dependency-locks/nonprodApt.lockfile
  8. +234 −0 core/gradle/dependency-locks/nonprodCompile.lockfile
  9. +232 −0 core/gradle/dependency-locks/nonprodCompileClasspath.lockfile
  10. +3 −0 core/gradle/dependency-locks/nonprodCompileOnly.lockfile
  11. +235 −0 core/gradle/dependency-locks/nonprodRuntime.lockfile
  12. +235 −0 core/gradle/dependency-locks/nonprodRuntimeClasspath.lockfile
  13. +0 −2 core/gradle/dependency-locks/runtimeClasspath.lockfile
  14. +1 −0 core/gradle/dependency-locks/testCompile.lockfile
  15. +1 −0 core/gradle/dependency-locks/testCompileClasspath.lockfile
  16. +1 −0 core/gradle/dependency-locks/testRuntime.lockfile
  17. +1 −0 core/gradle/dependency-locks/testRuntimeClasspath.lockfile
  18. +0 −1 core/src/main/java/google/registry/tools/RegistryTool.java
  19. +37 −0 core/src/nonprod/java/google/registry/tools/DevTool.java
  20. 0 core/src/{main → nonprod}/java/google/registry/tools/GenerateSqlSchemaCommand.java
  21. +1 −1 core/src/test/java/google/registry/tools/GenerateSqlSchemaCommandTest.java
  22. +44 −18 core/src/test/java/google/registry/tools/{RegistryToolTest.java → ToolsTest.java}
  23. +1 −0 dependencies.gradle
  24. +2 −4 java_common.gradle
  25. +0 −2 services/backend/gradle/dependency-locks/compile.lockfile
  26. +0 −2 services/backend/gradle/dependency-locks/compileClasspath.lockfile
  27. +0 −2 services/backend/gradle/dependency-locks/default.lockfile
  28. +0 −2 services/backend/gradle/dependency-locks/runtime.lockfile
  29. +0 −2 services/backend/gradle/dependency-locks/runtimeClasspath.lockfile
  30. +0 −2 services/backend/gradle/dependency-locks/testCompile.lockfile
  31. +0 −2 services/backend/gradle/dependency-locks/testCompileClasspath.lockfile
  32. +0 −2 services/backend/gradle/dependency-locks/testRuntime.lockfile
  33. +0 −2 services/backend/gradle/dependency-locks/testRuntimeClasspath.lockfile
  34. +0 −2 services/default/gradle/dependency-locks/compile.lockfile
  35. +0 −2 services/default/gradle/dependency-locks/compileClasspath.lockfile
  36. +0 −2 services/default/gradle/dependency-locks/default.lockfile
  37. +0 −2 services/default/gradle/dependency-locks/runtime.lockfile
  38. +0 −2 services/default/gradle/dependency-locks/runtimeClasspath.lockfile
  39. +0 −2 services/default/gradle/dependency-locks/testCompile.lockfile
  40. +0 −2 services/default/gradle/dependency-locks/testCompileClasspath.lockfile
  41. +0 −2 services/default/gradle/dependency-locks/testRuntime.lockfile
  42. +0 −2 services/default/gradle/dependency-locks/testRuntimeClasspath.lockfile
  43. +0 −2 services/pubapi/gradle/dependency-locks/compile.lockfile
  44. +0 −2 services/pubapi/gradle/dependency-locks/compileClasspath.lockfile
  45. +0 −2 services/pubapi/gradle/dependency-locks/default.lockfile
  46. +0 −2 services/pubapi/gradle/dependency-locks/runtime.lockfile
  47. +0 −2 services/pubapi/gradle/dependency-locks/runtimeClasspath.lockfile
  48. +0 −2 services/pubapi/gradle/dependency-locks/testCompile.lockfile
  49. +0 −2 services/pubapi/gradle/dependency-locks/testCompileClasspath.lockfile
  50. +0 −2 services/pubapi/gradle/dependency-locks/testRuntime.lockfile
  51. +0 −2 services/pubapi/gradle/dependency-locks/testRuntimeClasspath.lockfile
  52. +0 −2 services/tools/gradle/dependency-locks/compile.lockfile
  53. +0 −2 services/tools/gradle/dependency-locks/compileClasspath.lockfile
  54. +0 −2 services/tools/gradle/dependency-locks/default.lockfile
  55. +0 −2 services/tools/gradle/dependency-locks/runtime.lockfile
  56. +0 −2 services/tools/gradle/dependency-locks/runtimeClasspath.lockfile
  57. +0 −2 services/tools/gradle/dependency-locks/testCompile.lockfile
  58. +0 −2 services/tools/gradle/dependency-locks/testCompileClasspath.lockfile
  59. +0 −2 services/tools/gradle/dependency-locks/testRuntime.lockfile
  60. +0 −2 services/tools/gradle/dependency-locks/testRuntimeClasspath.lockfile
@@ -190,24 +190,33 @@ subprojects {
// Skip no-op project
if (project.name == 'services') return

ext.createUberJar = { taskName, binaryName, mainClass ->
ext.createUberJar = {
taskName,
binaryName,
mainClass,
List<Configuration> configs = [project.configurations.runtimeClasspath],
List<SourceSetOutput> srcOutput = [project.sourceSets.main.output],
List<String> excludes = [] ->
project.tasks.create(
taskName, com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
taskName, com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
mergeServiceFiles()
baseName = binaryName
manifest {
attributes 'Main-Class': mainClass
if (mainClass != '') {
manifest {
attributes 'Main-Class': mainClass
}
}
zip64 = true
classifier = ''
archiveVersion = ''
configurations = [project.configurations.runtimeClasspath]
from project.sourceSets.main.output
configurations = configs
from srcOutput
// Excludes signature files that accompany some dependency jars, like
// bonuncycastle. If they are present, only classes from those signed jars are
// made available to the class loader.
// see https://discuss.gradle.org/t/signing-a-custom-gradle-plugin-thats-downloaded-by-the-build-system-from-github/1365
exclude "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA"
exclude excludes
}
}

@@ -13,6 +13,7 @@
// limitations under the License.

import java.lang.reflect.Constructor
import java.util.Optional

plugins {
id 'java-library'
@@ -89,8 +90,17 @@ sourceSets {
exclude '**/*.xjb'
}
}
nonprod {
java {
compileClasspath += main.output
runtimeClasspath += main.output
}
}
test {
java {
compileClasspath += nonprod.output
runtimeClasspath += nonprod.output

// Javadoc API is deprecated in Java 11 and removed in Java 12.
// TODO(jianglai): re-enable after migrating to the new Javadoc API
if ((JavaVersion.current().majorVersion as Integer) >= 11) {
@@ -112,6 +122,13 @@ configurations {
jaxb
soy
closureCompiler
devtool

nonprodCompile.extendsFrom compile
nonprodRuntime.extendsFrom runtime

testCompile.extendsFrom nonprodCompile
testRuntime.extendsFrom nonprodRuntime

// Published jars that are used for server/schema compatibility tests.
// See <a href="../integration/README.md">the integration project</a>
@@ -147,9 +164,9 @@ dependencies {

// Custom-built objectify jar at commit ecd5165, included in Nomulus
// release.
implementation files(
compile files(
"${rootDir}/third_party/objectify/v4_1/objectify-4.1.3.jar")
testImplementation project(':third_party')
testRuntime project(':third_party')

testRuntime files(sourceSets.test.resources.srcDirs)

@@ -243,6 +260,7 @@ dependencies {
compile deps['org.testcontainers:postgresql']
testCompile deps['org.testcontainers:selenium']
testCompile deps['org.testcontainers:testcontainers']
testCompile deps['pl.pragmatists:JUnitParams']
compile deps['xerces:xmlParserAPIs']
compile deps['xpp3:xpp3']
// This dependency must come after javax.mail:mail as it would otherwise
@@ -718,41 +736,59 @@ task findGoldenImages(type: JavaExec) {
args arguments
}

// To run the nomulus tool with these command line tokens:
Optional<List<String>> getToolArgsList() {
// If "-PtoolArgs=..." is present in the command line, use it to set the args,
// otherwise use the default flag, which is "--args" to set the args.
def toolArgs = rootProject.findProperty("toolArgs")
if (toolArgs != null) {
def delimiter = '|'
toolArgs += delimiter
def argsList = []
def currArg = ''
for (def i = 0; i < toolArgs.length(); i++) {
def currChar = toolArgs[i]
if (currChar != delimiter) {
currArg += currChar
} else if (i != 0 && toolArgs[i - 1] == '\\') {
currArg = currArg.substring(0, currArg.length() - 1) + currChar
} else {
argsList.add(currArg)
currArg = ''
}
}
return Optional.of(argsList)
}
return Optional.empty()
}


// To run the nomulus tools with these command line tokens:
// "--foo", "bar baz", "--qux=quz"
// gradle registryTool --args="--foo 'bar baz' --qux=quz"
// or:
// gradle registryTool --PtoolArgs="--foo|bar baz|--qux=quz"
// Note that the delimiting pipe can be backslash escaped if it is part of a
// parameter.
task registryTool(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'google.registry.tools.RegistryTool'

// If "-PtoolArgs=..." is present in the command line, use it to set the args,
// otherwise use the default flag, which is "--args" to set the args.
doFirst {
def toolArgs = rootProject.findProperty("toolArgs")
if (toolArgs != null) {
def delimiter = '|'
toolArgs += delimiter
def argsList = []
def currArg = ''
for (def i = 0; i < toolArgs.length(); i++) {
def currChar = toolArgs[i]
if (currChar != delimiter) {
currArg += currChar
} else if (i != 0 && toolArgs[i - 1] == '\\') {
currArg = currArg.substring(0, currArg.length() - 1) + currChar
} else {
argsList.add(currArg)
currArg = ''
}
ext.createToolTask = {
taskName,
mainClass,
sourceSet = sourceSets.main ->
project.tasks.create(taskName, JavaExec) {
classpath = sourceSet.runtimeClasspath
main = mainClass

doFirst {
getToolArgsList().ifPresent {
args it
}
args = argsList
}
}
}
createToolTask('registryTool', 'google.registry.tools.RegistryTool')
createToolTask(
'devTool',
'google.registry.tools.DevTool',
sourceSets.nonprod)

task generateGoldenImages(type: FilteringTest) {
tests = ["**/webdriver/*"]
@@ -818,7 +854,6 @@ test {
}.dependsOn(fragileTest, outcastTest, standardTest, registryToolIntegrationTest)

createUberJar('nomulus', 'nomulus', 'google.registry.tools.RegistryTool')
project.nomulus.dependsOn project(':third_party').jar

// A jar with classes and resources from main sourceSet, excluding internal
// data. See comments on configurations.nomulus_test above for details.
@@ -836,26 +871,21 @@ task nomulusFossJar (type: Jar) {

// An UberJar of registry test classes, resources and all dependencies.
// See comments on configurations.nomulus_test above for details.
// TODO(weiminyu): extract shareable code with root.ext.createUberJar
task testUberJar (
type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
mergeServiceFiles()
archiveBaseName = 'nomulus-tests'
createUberJar(
'testUberJar',
'nomulus-tests',
'',
[project.configurations.testRuntimeClasspath],
[project.sourceSets.test.output],
[
// Exclude SQL schema, which is a test dependency.
'sql/flyway/**',
// ShadowJar includes java source files when used on
// sourceSets.test.output.
'**/*.java'
])
tasks.testUberJar {
archiveClassifier = 'alldeps'
zip64 = true
archiveVersion = ''
configurations = [project.configurations.testRuntimeClasspath]
from project.sourceSets.test.output
// Excludes signature files that accompany some dependency jars, like
// bonuncycastle. If they are present, only classes from those signed jars are
// made available to the class loader.
// see https://discuss.gradle.org/t/signing-a-custom-gradle-plugin-thats-downloaded-by-the-build-system-from-github/1365
exclude "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA"
// Exclude SQL schema, which is a test dependency.
exclude 'sql/flyway/**'
// ShadowJar includes java source files when used on sourceSets.test.output.
// They are not needed.
exclude '**/*.java'
}

artifacts {
@@ -884,6 +914,19 @@ task buildToolImage(dependsOn: nomulus, type: Exec) {
commandLine 'docker', 'build', '-t', 'nomulus-tool', '.'
}

// Build the devtool jar.
createUberJar(
'devtool',
'devtool',
'google.registry.tools.DevTool',
[ project.configurations.nonprodRuntimeClasspath ],
[ project.sourceSets.nonprod.output, sourceSets.main.output ],
[ '**/*.java' ])

artifacts {
devtool devtool
}

task copyJsFilesForTestServer(dependsOn: assemble, type: Copy) {
// Unfortunately the test server relies on having some compiled JS/CSS
// in place, so copy it over here
@@ -898,5 +941,6 @@ task runTestServer(dependsOn: copyJsFilesForTestServer, type: JavaExec) {
classpath = sourceSets.test.runtimeClasspath
}

project.build.dependsOn devtool
project.build.dependsOn buildToolImage
project.build.dependsOn ':stage'
@@ -163,7 +163,6 @@ javax.validation:validation-api:1.0.0.GA
javax.xml.bind:jaxb-api:2.3.1
jline:jline:1.0
joda-time:joda-time:2.10.3
junit:junit:4.12
net.bytebuddy:byte-buddy:1.9.11
net.java.dev.jna:jna-platform:5.3.1
net.java.dev.jna:jna:5.3.1
@@ -193,7 +192,6 @@ org.dom4j:dom4j:2.1.1
org.easymock:easymock:3.0
org.glassfish.jaxb:jaxb-runtime:2.3.1
org.glassfish.jaxb:txw2:2.3.1
org.hamcrest:hamcrest-core:1.3
org.hibernate.common:hibernate-commons-annotations:5.1.0.Final
org.hibernate:hibernate-core:5.4.4.Final
org.hibernate:hibernate-hikaricp:5.4.4.Final
@@ -176,7 +176,6 @@ javax.validation:validation-api:1.0.0.GA
javax.xml.bind:jaxb-api:2.3.1
jline:jline:1.0
joda-time:joda-time:2.10.3
junit:junit:4.12
net.bytebuddy:byte-buddy:1.9.11
net.java.dev.jna:jna-platform:5.3.1
net.java.dev.jna:jna:5.3.1
@@ -206,7 +205,6 @@ org.dom4j:dom4j:2.1.1
org.easymock:easymock:3.0
org.glassfish.jaxb:jaxb-runtime:2.3.1
org.glassfish.jaxb:txw2:2.3.1
org.hamcrest:hamcrest-core:1.3
org.hibernate.common:hibernate-commons-annotations:5.1.0.Final
org.hibernate:hibernate-core:5.4.4.Final
org.hibernate:hibernate-hikaricp:5.4.4.Final
@@ -0,0 +1,3 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
@@ -0,0 +1,24 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.github.kevinstern:software-and-algorithms:1.0
com.github.stephenc.jcip:jcip-annotations:1.0-1
com.google.auto:auto-common:0.10
com.google.code.findbugs:jFormatString:3.0.0
com.google.code.findbugs:jsr305:3.0.2
com.google.errorprone:error_prone_annotation:2.3.3
com.google.errorprone:error_prone_annotations:2.3.3
com.google.errorprone:error_prone_check_api:2.3.3
com.google.errorprone:error_prone_core:2.3.3
com.google.errorprone:error_prone_type_annotations:2.3.3
com.google.guava:failureaccess:1.0.1
com.google.guava:guava:27.0.1-jre
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
com.google.j2objc:j2objc-annotations:1.1
com.google.protobuf:protobuf-java:3.4.0
com.googlecode.java-diff-utils:diffutils:1.3.0
org.checkerframework:checker-qual:2.5.3
org.checkerframework:dataflow:2.5.3
org.checkerframework:javacutil:2.5.3
org.codehaus.mojo:animal-sniffer-annotations:1.17
org.pcollections:pcollections:2.1.2
@@ -0,0 +1,3 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.

0 comments on commit 6aaf081

Please sign in to comment.
You can’t perform that action at this time.