diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 00000000..f9ed608c --- /dev/null +++ b/.bazelignore @@ -0,0 +1 @@ +.hg/ diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..50f79eaf --- /dev/null +++ b/.bazelrc @@ -0,0 +1,3 @@ +build --javacopt=-Aautovaluegson.defaultCollectionsToEmpty=true +build --strategy=KotlinCompile=worker + diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000..944880fa --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +3.2.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..33c9622a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,75 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: + - master + - main + - release* + pull_request: + branches: + - master + - main +jobs: + test-macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Mount caches + uses: actions/cache@v2 + with: + path: | + "/home/runner/.cache/bazel" + "/home/runner/.m2/repository" + key: caches-${{ runner.os }} + - name: Install bazelisk + run: | + curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.5.0/bazelisk-darwin-amd64" + mkdir -p "${GITHUB_WORKSPACE}/bin/" + mv bazelisk-darwin-amd64 "${GITHUB_WORKSPACE}/bin/bazel" + chmod a+x "${GITHUB_WORKSPACE}/bin/bazel" + echo "::set-env name=BAZELISK_GITHUB_TOKEN::${{ secrets.GITHUB_TOKEN }}" + "${GITHUB_WORKSPACE}/bin/bazel" version + - name: Build All + run: | + "${GITHUB_WORKSPACE}/bin/bazel" build //... + - name: Test All + run: | + "${GITHUB_WORKSPACE}/bin/bazel" test //... + + test-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Mount caches + uses: actions/cache@v2 + with: + path: | + "/home/runner/.cache/bazel" + "/home/runner/.m2/repository" + key: caches-${{ runner.os }} + - name: Install bazelisk + run: | + curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.5.0/bazelisk-linux-amd64" + mkdir -p "${GITHUB_WORKSPACE}/bin/" + mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel" + chmod a+x "${GITHUB_WORKSPACE}/bin/bazel" + echo "::set-env name=BAZELISK_GITHUB_TOKEN::${{ secrets.GITHUB_TOKEN }}" + "${GITHUB_WORKSPACE}/bin/bazel" version + - name: Build All + run: | + "${GITHUB_WORKSPACE}/bin/bazel" build //... + - name: Test All + run: | + "${GITHUB_WORKSPACE}/bin/bazel" test //... + diff --git a/.gitignore b/.gitignore index d60688ac..eb3edd48 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,18 @@ -build/ +# maven target/ + +# eclipse .project .classpath .settings/ .factorypath + +# Idea/AndroidStudio +.idea/ +*.iml +*.ipr + +#Bazel +bazel-* +.aswb/ +.ijwb/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6d578465..00000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: java - -jdk: - - oraclejdk8 - -# https://github.com/travis-ci/travis-ci/issues/3259#issuecomment-130860338 -addons: - apt: - packages: - - oracle-java8-installer - -install: mvn -P!standard-with-extra-repos -U install clean --fail-never --quiet -DskipTests=true -Dinvoker.skip=true - -script: mvn -P!standard-with-extra-repos -U verify --fail-at-end -Dsource.skip=true -Dmaven.javadoc.skip=true - -env: - global: - - secure: "P1EUlOHwhpR2FB/Hot5rrHkg6oyCPsVJ0ejKcHdiVH6Ydaag8xYt/fRvfrIW3G4XK/UXWtLrDYvWEZxdJ0EWQhGbl9vUKipZQljYYYRsLG4x0LrQMphX88eF3NjIpB9DTiveJswEtSB/Ad8/OJVe0+ob76AIhsqUbxQIWxJPtkgqDEzTDU76QceTVZ7BJHxcUDY8C3nO6pD+rnMYHt9yM66H+77eT+vBFBkkvieEQCCZyB3IBsX4LsKzETInz7ZQE85oNRkd4fHYIvvnHGPoqxn1wHWQf9HGQZsZ1fxO+4lM/UOKw+b5ic1rIisabSNIrLZme0vA/QdPsEwTgC1oach3p5jZcWJj+6n+KfPDHgpXjWg2h0LHnPdXnjiNPRY3nL8aUtAxSCUU+zhcI4vzIKSzAlaDN59Kb6PfLJkJWF09+t34yhzCqvaKLQzvEolrqHHfFfD278ARc4W+HqK3qusBLdHG1FpTMgH/EzrRknIm2zVsSt2JaZKDuZNPbUmmufASv0T51knvU8fJaa18Z9JKFfYX1LV1fDRv6nmzzVXrczeUMUgONE+8u+KdCWQrtIAnstzq1fGwTCNx9QOf8EdzJw28BF5/MPhs2BgzrueP5aV/aiXu4dfFG6fte/S8mM91qzUNOU0vSycuQA7VwUYKFo6RPNMgFBnA5kPQQbM=" - - secure: "F9NnyiQXzTsb1sO+ikn+wyf6vNQj0QAti76O2BG6NXpzQ9N1vhhIOlHlJKjNmB9N7ydRrCEx1wCdYl3p4CwUtJ3GC4BppvwpRz1VEjKUSuBSz4V6ANrhK2bhslc6ztieZCJkrTGued2bPEFAUzsZIGjSVTx+ArKfE0QEbjKOCQim1W5WKMYDLnYxs4XfQj0CmQFgsfbj02UIM+5nk4i2PUHdNhSlG8U39V+F0htdUPWRPBLEUx6pn56lTpANlFVK2xQXAHIYfGr9qNAXW1w06XMIIc9XQFTgnim0MCCGMmNZYYmOlLMK4KGjNERE48ftJttrHqlNP8CZKRw1DpdnGgfpJr/YquhIhm8uTzioP7uvRJPNJ9tH36/wXgL10D0M9d5Nw4qFMWNGj/BFsetF+uHEQnjDOb9sRpnAG3/0Gw0Y9FyC92kOvOSpe+uDMN/ZOV1tqbBNmfg27u8CLUYB2S+3gllouwRqtJug9PeOq5Qq6DigWEcCOjaURoYwXAzgmHQB0MJswl69FZu7wc14bpx23bLmwtLHaxU9WxviQp7pQeJjYKNnPQEQPakAhy4uXAf/eUIyKLQYuUeNS3rcM9FZhIgkPbBDr6TNRPUZk6HXZ1etsm1d1ZKAXLDTEsArTZ/rIHwa0B7bFGrtR8lsFzBp8QEh2aoUBOHfm/qGVrs=" - - secure: "NMy5OMMkXMqWeCpUpBT+EN0YoJd/xoQUPklDXZOljiIfy2uZzmV5hhfbG8lNBTZPHN2zVIQxHZ8dKJ4q290zA07CNkIPh3vK3SRFyKnJ3oL+oELJUKUtMcJyMc91aIcYhztq2829ZWaw9PSdOvt21PKnOiBOXBn8AVCHIeJjw8okXgJJlCK+GWSa21UcvbMDG1T+OJrwMhnn/t09KdWy0vDUvPKU2slgkZIPMmy1JbxJnDP548K1P4lMtJ2XYZ+x+PDeyyWwaPAE8ZJND9av0TXMBgnS6uuntNFm54ABTUAQxDUmdc3qTtd3TLtCHoP2r2bs45M01Sj8LXUU1CtEGA6ktp57qeMcHgWC04n/+BRpjIDvM5S0+n4exENTOjcVxMIc2TgWp7L1HWd0qBxdnGdhuX8BweV74ZoBzW+Dw1RBPcFzx9sMM9yIcnQUjtNiC71QAZ85KTX3DMWJxmv/tUjJlTRmaGbIgWbeSIZ2aB9EF6A1PUGDvkgnVwUXd2epvYn/egvUfTXY7TiCug8D/I8ZcvFbulspKQnjFHOLskKIwBP0Jjed0FJz422Ip5AsnT239V4p9OEF+GMWYVIZoJhUuShubyrLG2qiVCvRW8640CaH84F+YDERuvMdHI2Kgod6DjezkQtXahUwto76e9wuseBoZTklfWwIfJ1isVc=" - -after_success: - - util/generate-latest-docs.sh - - util/publish-snapshot-on-commit.sh - -branches: - except: - - gh-pages - -notifications: - email: cgruber@google.com - -cache: - directories: - - $HOME/.m2 - diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..892c94aa --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,3 @@ +exports_files([ + "build_substitution_templates.bzl", +]) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 446f73e1..46dd51dc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,6 +23,8 @@ note that a Google, Inc. copyright line must appear in every copyright notice. All files are released with the Apache 2.0 license and any new files may only be accepted under the terms of that license. + + Before your code can be accepted into the project you must sign the [Individual Contributor License Agreement (CLA)][1]. diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 00000000..dbe9cb88 --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,9 @@ +# Contributors + +These authors have supplied code or other contributions to this repository. + +- Google, Inc. + - various employees +- Christian Gruber + +> Note: If your contribution is not accounted for here, please submit a pull request with an update. \ No newline at end of file diff --git a/README.md b/README.md index b3d63a45..15396e73 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,11 @@ *Make Open Easy* [![LICENSE](https://img.shields.io/badge/license-Apache-blue.svg)](https://github.com/google/MOE/blob/master/LICENSE) -[![Travis CI](https://img.shields.io/travis/google/MOE.svg)](https://travis-ci.org/google/MOE) -[![GitHub Issues](https://img.shields.io/github/issues/google/MOE.svg)](https://github.com/google/MOE/issues) -[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/google/MOE.svg)](https://github.com/google/MOE/pulls) +[![CI](https://github.com/cgruber/MOE/workflows/CI/badge.svg)](https://github.com/cgruber/MOE/actions?query=workflow%3ACI) +[![GitHub Issues](https://img.shields.io/github/issues/cgruber/MOE.svg)](https://github.com/cgruber/MOE/issues) +[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/cgruber/MOE.svg)](https://github.com/cgruber/MOE/pulls) + +> Note: This is a personal fork by [cgruber](http://github.com/cgruber) ## Introduction @@ -37,13 +39,12 @@ documentation update, which is forthcoming. ### Building MOE -1. Install Apache Maven 3.1 if you don't already have it + 1. Install [Bazelisk](http://github.com/bazelbuild/bazelisk) 2. Checkout the Java-MOE source `git clone git@github.com:google/MOE.git` - 3. In the top-level directory that contains the build.xml file, run: - - `mvn install` - - `util/make-binary.sh` - 4. The moe client binary should be created at `client/target/moe` - + 3. In the top level directory that contains the WORKSPACE file, run: + - `bazel build //client:moe` + 4. The moe client binary should be created at `bazel-bin/client/moe` + 5. (optionally) install the client somewhere in your `$PATH` ### Running MOE @@ -52,16 +53,12 @@ Once you have the `moe` binary, you should be able to simply run: ## Contributing -Contributing to MOE is subject to the guidelines in the CONTRIBUTING.md file, -which, in brief, requires that contributors sign the [Individual Contributor -License Agreement (CLA)][CLA]. - -[CLA]: https://cla.developers.google.com/ - +Contributing to MOE is subject to the guidelines in the CONTRIBUTING.md file ## License ``` + Copyright 2011 The Moe Authors. All Rights Reserved. Copyright 2011 Google, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 00000000..57d303c6 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,102 @@ +workspace(name = "moe") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +# Rules and tooling versions +RULES_KOTLIN_VERSION = "legacy-1.4.0-rc3" +RULES_KOTLIN_SHA = "da0e6e1543fcc79e93d4d93c3333378f3bd5d29e82c1bc2518de0dbe048e6598" + + +MAVEN_REPOSITORY_RULES_VERSION = "2.0.0-alpha-3" +MAVEN_REPOSITORY_RULES_SHA = "853976a2e4908f010568aad8f47b1a1e87e258f33b114e6e92599dc2779938c4" +KOTLIN_VERSION = "1.3.72" +KOTLINC_ROOT = "https://github.com/JetBrains/kotlin/releases/download" +KOTLINC_URL = "{root}/v{v}/kotlin-compiler-{v}.zip".format(root = KOTLINC_ROOT, v = KOTLIN_VERSION) +KOTLINC_SHA = "ccd0db87981f1c0e3f209a1a4acb6778f14e63fe3e561a98948b5317e526cc6c" + + +# Rules and tools repositories +http_archive( + name = "io_bazel_rules_kotlin", + sha256 = RULES_KOTLIN_SHA, + urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % RULES_KOTLIN_VERSION], +) + +http_archive( + name = "maven_repository_rules", + sha256 = MAVEN_REPOSITORY_RULES_SHA, + strip_prefix = "bazel_maven_repository-%s" % MAVEN_REPOSITORY_RULES_VERSION, + type = "zip", + urls = ["https://github.com/square/bazel_maven_repository/archive/%s.zip" % MAVEN_REPOSITORY_RULES_VERSION], +) + +# Setup Kotlin +load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") +kotlin_repositories(compiler_release = { "urls": [KOTLINC_URL], "sha256": KOTLINC_SHA }) +kt_register_toolchains() + + +# Setup maven repository handling. +load("@maven_repository_rules//maven:maven.bzl", "maven_repository_specification") +load(":workspace_maven_substitutes.bzl", "snippets") +maven_repository_specification( + name = "maven", + artifacts = { + "args4j:args4j:2.32": { "insecure": True }, + "cglib:cglib-nodep:2.2.2": { "insecure": True }, + "com.google.auto.factory:auto-factory:1.0-beta6": { + "insecure": True, + "build_snippet": snippets.AUTO_FACTORY.format(version = "1.0-beta6"), + }, + "com.google.auto.value:auto-value-annotations:1.6.3": { "insecure": True }, + "com.google.auto.value:auto-value:1.6.3": { + "insecure": True, + "build_snippet": snippets.AUTO_VALUE.format(version = "1.6.3"), + }, + "com.google.auto:auto-common:0.10": { "insecure": True }, + "com.google.code.findbugs:jsr305:3.0.2": { "insecure": True }, + "com.google.code.gson:gson:2.8.1": { "insecure": True }, + "com.google.dagger:dagger-compiler:2.21": { "insecure": True }, + "com.google.dagger:dagger-producers:2.21": { "insecure": True }, + "com.google.dagger:dagger-spi:2.21": { "insecure": True }, + "com.google.dagger:dagger:2.21": { + "insecure": True, + "build_snippet": snippets.DAGGER.format(version = "2.21"), + }, + "com.google.errorprone:error_prone_annotations:2.3.1": { "insecure": True }, + "com.google.errorprone:javac-shaded:9+181-r4173-1": { "insecure": True }, + "com.google.googlejavaformat:google-java-format:1.6": { "insecure": True }, + "com.google.guava:guava:27.0.1-jre": { "insecure": True }, + "com.google.guava:failureaccess:1.0.1": { "insecure": True }, + "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava": { "insecure": True }, + "com.google.j2objc:j2objc-annotations:1.1": { "insecure": True }, + "com.google.truth:truth:0.42": { "insecure": True }, + "com.googlecode.java-diff-utils:diffutils:1.3.0": { "insecure": True }, + "com.mikesamuel:json-sanitizer:1.1": { "insecure": True }, + "com.nhaarman:mockito-kotlin:1.6.0": { "insecure": True }, + "com.ryanharter.auto.value:auto-value-gson-annotations:0.8.0": { "insecure": True }, + "com.ryanharter.auto.value:auto-value-gson:0.8.0": { "insecure": True }, + "com.squareup.okhttp:okhttp:2.5.0": { "insecure": True }, + "com.squareup.okio:okio:1.6.0": { "insecure": True }, + "com.squareup:javapoet:1.11.1": { "insecure": True }, + "javax.annotation:jsr250-api:1.0": { "insecure": True }, + "javax.inject:javax.inject:1": { "insecure": True }, + "joda-time:joda-time:2.9.9": { "insecure": True }, + "junit:junit:4.13-beta-1": { "insecure": True }, + "net.bytebuddy:byte-buddy:1.9.7": { "insecure": True }, + "net.bytebuddy:byte-buddy-agent:1.9.7": { "insecure": True }, + "org.checkerframework:checker-compat-qual:2.5.3": { "insecure": True }, + "org.checkerframework:checker-qual:2.5.3": { "insecure": True }, + "org.codehaus.mojo:animal-sniffer-annotations:1.14": { "insecure": True }, + "org.easymock:easymock:3.1": { "insecure": True }, + "org.jetbrains:annotations:13.0": { "insecure": True }, + "org.jetbrains.kotlin:kotlin-reflect:%s" % KOTLIN_VERSION: { "insecure": True }, + "org.jetbrains.kotlin:kotlin-stdlib:%s" % KOTLIN_VERSION: { "insecure": True }, + "org.jetbrains.kotlin:kotlin-stdlib-common:%s" % KOTLIN_VERSION: { "insecure": True }, + "org.mockito:mockito-core:2.24.0": { "insecure": True }, + "org.objenesis:objenesis:2.6": { "insecure": True }, + "org.hamcrest:hamcrest-core:1.3": { "insecure": True }, + }, + dependency_target_substitutes = { + "com.google.dagger": {"@maven//com/google/dagger:dagger": "@maven//com/google/dagger:dagger-api"}, + }, +) diff --git a/client/BUILD.bazel b/client/BUILD.bazel new file mode 100644 index 00000000..2a74ae7f --- /dev/null +++ b/client/BUILD.bazel @@ -0,0 +1,17 @@ +load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library", "kt_jvm_binary") + +java_binary( + name = "client-bin", + main_class = "com.google.devtools.moe.client.Moe", + runtime_deps = ["//client/src/main/java/com/google/devtools/moe/client"], +) + +genrule( + name = "moe", + outs = ["moe"], + srcs = [ + "//util:java-exec-prefix", + ":client-bin_deploy.jar" + ], + cmd_bash = "cat $(location //util:java-exec-prefix) $(location :client-bin_deploy.jar) > $@", +) \ No newline at end of file diff --git a/client/pom.xml b/client/pom.xml deleted file mode 100644 index bfb34fcc..00000000 --- a/client/pom.xml +++ /dev/null @@ -1,192 +0,0 @@ - - 4.0.0 - - com.google.devtools - moe-parent - 1.0-SNAPSHOT - - moe - MOE Client - - A tool that synchronizes multiple source code repositories, allowing for migration of commits, - mapping of folders, scrubbing and other transformation of data (and commit metadata), etc. - - - - - org.jetbrains.kotlin - kotlin-stdlib - - - joda-time - joda-time - - - com.google.guava - guava - - - com.google.code.gson - gson - - - com.squareup.okhttp - okhttp - - - com.mikesamuel - json-sanitizer - - - com.google.dagger - dagger - - - com.google.dagger - dagger-compiler - provided - - - com.google.auto.value - auto-value - provided - - - com.google.auto.factory - auto-factory - provided - - - com.ryanharter.auto.value - auto-value-gson - provided - - - com.google.errorprone - error_prone_annotations - provided - - - com.google.code.findbugs - jsr305 - true - - - args4j - args4j - - - junit - junit - - - com.google.truth - truth - - - org.easymock - easymock - - - org.mockito - mockito-core - - - - - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - - - kapt - kapt - - - ${project.basedir}/src/main/java - - - - - compile - compile - compile - - - src/main/java - - - - - test-compile - test-compile - test-compile - - - src/test/java - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - default-compile - none - - - - default-testCompile - none - - - java-compile - compile - compile - - - java-test-compile - test-compile - testCompile - - - - - maven-shade-plugin - - - package - - shade - - - false - true - true - executable - - - com.google.devtools.moe.client.Moe - - - - - *:auto-value - *:auto-factory - *:dagger-compiler - *:junit - org.hamcrest:* - - - - - - - - - diff --git a/client/src/main/java/com/google/devtools/moe/client/AbstractMoeExecutable.java b/client/src/main/java/com/google/devtools/moe/client/AbstractMoeExecutable.java index 8586876f..f4817d4f 100644 --- a/client/src/main/java/com/google/devtools/moe/client/AbstractMoeExecutable.java +++ b/client/src/main/java/com/google/devtools/moe/client/AbstractMoeExecutable.java @@ -24,7 +24,7 @@ import com.google.devtools.moe.client.directives.Directive; import com.google.devtools.moe.client.directives.Directives; import com.google.devtools.moe.client.options.OptionsParser; -import com.google.devtools.moe.client.project.InvalidProject; + import java.io.IOException; import java.util.logging.ConsoleHandler; import java.util.logging.Level; diff --git a/client/src/main/java/com/google/devtools/moe/client/BUILD.bazel b/client/src/main/java/com/google/devtools/moe/client/BUILD.bazel new file mode 100644 index 00000000..5380042f --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/BUILD.bazel @@ -0,0 +1,50 @@ +load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library", "kt_jvm_binary") + +package(default_visibility = ["//client:__subpackages__"]) + +CORE_SRCS = [ + "FileSystem.java", + "Lifetimes.java", + "InvalidProject.java", + "MoeProblem.java", + "MoeUserProblem.java", + "NoopFileSystem.java", + "NoopFileSystemModule.java", + "Ui.java", + "Utils.java", +] +java_library( + name = "core", + srcs = CORE_SRCS, + deps = [ + "//client/src/main/java/com/google/devtools/moe/client/qualifiers", + "@maven//com/google/dagger", + "@maven//com/google/errorprone:error_prone_annotations", + "@maven//com/google/guava", + "@maven//joda-time", + ], +) + + +java_library( + name = "client", + srcs = glob(["**/*.java"], exclude = CORE_SRCS), + deps = [ + ":core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "//client/src/main/java/com/google/devtools/moe/client/config", + "//client/src/main/java/com/google/devtools/moe/client/gson", + "//client/src/main/java/com/google/devtools/moe/client/qualifiers", + "@maven//args4j", + "@maven//com/google/auto/factory", + "@maven//com/google/auto/value", + "@maven//com/google/dagger", + "@maven//com/google/guava", + "@maven//com/google/code/gson", + "@maven//com/squareup/okhttp", + "@maven//com/mikesamuel:json-sanitizer", + "@maven//com/google/errorprone:error_prone_annotations", + "@maven//com/google/code/findbugs:jsr305", + "@maven//joda-time", + ], +) diff --git a/client/src/main/java/com/google/devtools/moe/client/gson/GsonModule.java b/client/src/main/java/com/google/devtools/moe/client/GsonModule.java similarity index 80% rename from client/src/main/java/com/google/devtools/moe/client/gson/GsonModule.java rename to client/src/main/java/com/google/devtools/moe/client/GsonModule.java index cacaeea1..e5ce7c19 100644 --- a/client/src/main/java/com/google/devtools/moe/client/gson/GsonModule.java +++ b/client/src/main/java/com/google/devtools/moe/client/GsonModule.java @@ -13,12 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.devtools.moe.client.gson; +package com.google.devtools.moe.client; import static com.google.gson.FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.MoeTypeAdapterFactory; +import com.google.devtools.moe.client.config.ConfigTypeAdapterFactory; import com.google.devtools.moe.client.database.RepositoryEquivalence; +import com.google.devtools.moe.client.gson.ImmutableListDeserializer; +import com.google.devtools.moe.client.gson.JsonObjectDeserializer; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; @@ -26,9 +30,7 @@ import dagger.Provides; import javax.inject.Singleton; -/** - * A Dagger module to provide and configure Gson - */ +/** A Dagger module to provide and configure Gson */ @Module public final class GsonModule { // TODO(user): eliminate this and make provideGson package private @@ -37,6 +39,7 @@ public final class GsonModule { new GsonBuilder() .setPrettyPrinting() .setFieldNamingPolicy(LOWER_CASE_WITH_UNDERSCORES) + .registerTypeAdapterFactory(ConfigTypeAdapterFactory.create()) .registerTypeAdapterFactory(MoeTypeAdapterFactory.create()) .registerTypeHierarchyAdapter(ImmutableList.class, new ImmutableListDeserializer()) .registerTypeHierarchyAdapter( diff --git a/client/src/main/java/com/google/devtools/moe/client/project/InvalidProject.java b/client/src/main/java/com/google/devtools/moe/client/InvalidProject.java similarity index 97% rename from client/src/main/java/com/google/devtools/moe/client/project/InvalidProject.java rename to client/src/main/java/com/google/devtools/moe/client/InvalidProject.java index 4c6d0a41..3f6f605c 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/InvalidProject.java +++ b/client/src/main/java/com/google/devtools/moe/client/InvalidProject.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.devtools.moe.client.project; +package com.google.devtools.moe.client; import com.google.common.base.Strings; diff --git a/client/src/main/java/com/google/devtools/moe/client/MoeModule.java b/client/src/main/java/com/google/devtools/moe/client/MoeModule.java index 770c4d52..03d16cb7 100644 --- a/client/src/main/java/com/google/devtools/moe/client/MoeModule.java +++ b/client/src/main/java/com/google/devtools/moe/client/MoeModule.java @@ -19,10 +19,9 @@ import com.google.devtools.moe.client.codebase.ExpressionModule; import com.google.devtools.moe.client.database.FileDb; import com.google.devtools.moe.client.directives.Directives; -import com.google.devtools.moe.client.gson.GsonModule; import com.google.devtools.moe.client.options.OptionsModule; import com.google.devtools.moe.client.project.FileReadingProjectContextFactory; -import com.google.devtools.moe.client.project.ProjectConfig; +import com.google.devtools.moe.client.config.ProjectConfig; import com.google.devtools.moe.client.project.ProjectContext; import com.google.devtools.moe.client.project.ProjectContext.NoopProjectContext; import com.google.devtools.moe.client.project.ProjectContextFactory; diff --git a/client/src/main/java/com/google/devtools/moe/client/gson/MoeTypeAdapterFactory.java b/client/src/main/java/com/google/devtools/moe/client/MoeTypeAdapterFactory.java similarity index 95% rename from client/src/main/java/com/google/devtools/moe/client/gson/MoeTypeAdapterFactory.java rename to client/src/main/java/com/google/devtools/moe/client/MoeTypeAdapterFactory.java index 378b632a..9f36a9dc 100644 --- a/client/src/main/java/com/google/devtools/moe/client/gson/MoeTypeAdapterFactory.java +++ b/client/src/main/java/com/google/devtools/moe/client/MoeTypeAdapterFactory.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.devtools.moe.client.gson; +package com.google.devtools.moe.client; import com.google.gson.TypeAdapterFactory; import com.ryanharter.auto.value.gson.GsonTypeAdapterFactory; diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/Codebase.java b/client/src/main/java/com/google/devtools/moe/client/codebase/Codebase.java index 37d4db45..5597badb 100644 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/Codebase.java +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/Codebase.java @@ -34,11 +34,11 @@ */ @AutoValue public abstract class Codebase implements Keepable { - public abstract File path(); + public abstract File root(); @Override public Collection toKeep() { - return asList(path().toPath()); + return asList(root().toPath()); } public abstract String projectSpace(); @@ -57,8 +57,8 @@ public Collection toKeep() { * @param expression an expression that generates this Codebase. This expression identifies the * Codebase. */ - public static Codebase create(File path, String projectSpace, Expression expression) { - return new AutoValue_Codebase(path, projectSpace, expression); + public static Codebase create(File root, String projectSpace, Expression expression) { + return new AutoValue_Codebase(root, projectSpace, expression); } @Override @@ -73,19 +73,19 @@ public String toString() { */ @Override public boolean equals(Object other) { - return other instanceof Codebase && path().equals(((Codebase) other).path()); + return other instanceof Codebase && root().equals(((Codebase) other).root()); } @Override public int hashCode() { - return path().hashCode(); + return root().hashCode(); } /** * @return the path of a file in this Codebase */ public File getFile(String relativeFilename) { - return new File(path(), relativeFilename); + return new File(root(), relativeFilename); } /** @@ -109,7 +109,7 @@ public void checkProjectSpace(String projectSpace) { * or translating by "imprinting" them with the EditExpression or TranslateExpression. */ public Codebase copyWithExpression(Expression newExpression) { - return Codebase.create(path(), projectSpace(), newExpression); + return Codebase.create(root(), projectSpace(), newExpression); } /** @@ -118,6 +118,6 @@ public Codebase copyWithExpression(Expression newExpression) { * space it was translated to. */ public Codebase copyWithProjectSpace(String newProjectSpace) { - return Codebase.create(path(), newProjectSpace, expression()); + return Codebase.create(root(), newProjectSpace, expression()); } } diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/CodebaseMerger.java b/client/src/main/java/com/google/devtools/moe/client/codebase/CodebaseMerger.java index e2d5c32d..c43f9e06 100644 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/CodebaseMerger.java +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/CodebaseMerger.java @@ -118,7 +118,7 @@ public MergeResult merge(Codebase original, Codebase modified, Codebase destinat } private Set findFiles(Codebase codebase) { - return makeFilenamesRelative(filesystem.findFiles(codebase.path()), codebase.path()); + return makeFilenamesRelative(filesystem.findFiles(codebase.root()), codebase.root()); } private boolean areDifferent(String filename, File x, File y) { @@ -211,7 +211,7 @@ void generateMergedFile( // Merges the changes that lead from origFile to modFile into mergedFile (which is a copy // of destFile). After, mergedFile will have the combined changes of modFile and destFile. cmd.runCommand( - resultBuilder.mergedCodebase().path().getAbsolutePath(), + resultBuilder.mergedCodebase().root().getAbsolutePath(), "merge", ImmutableList.of( mergedFile.getAbsolutePath(), origFile.getAbsolutePath(), modFile.getAbsolutePath())); @@ -248,7 +248,7 @@ public abstract static class MergeResult { /** Print the results of a merge to the UI. */ public void report(Ui ui) { - ui.message("Merged codebase generated at: %s", mergedCodebase().path().getAbsolutePath()); + ui.message("Merged codebase generated at: %s", mergedCodebase().root().getAbsolutePath()); if (failedFiles().isEmpty()) { ui.message("%d files merged successfully. No merge conflicts.", mergedFiles().size()); } else { diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/EditedCodebaseProcessor.java b/client/src/main/java/com/google/devtools/moe/client/codebase/EditedCodebaseProcessor.java index a8319844..cf0d15b9 100644 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/EditedCodebaseProcessor.java +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/EditedCodebaseProcessor.java @@ -33,7 +33,7 @@ public Codebase createCodebase(EditExpression expression, ProjectContext context try (Task task = ui.newTask( - "edit", "Editing %s with editor %s", codebaseToEdit.path(), editor.getDescription())) { + "edit", "Editing %s with editor %s", codebaseToEdit.root(), editor.getDescription())) { return task.keep( editor.edit(codebaseToEdit, expression.getOperation().getTerm().getOptions())) .copyWithExpression(expression); diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/LocalWorkspace.java b/client/src/main/java/com/google/devtools/moe/client/codebase/LocalWorkspace.java index 7313db58..cf19f53a 100644 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/LocalWorkspace.java +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/LocalWorkspace.java @@ -17,7 +17,7 @@ package com.google.devtools.moe.client.codebase; import com.google.devtools.moe.client.FileSystem.Lifetime; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import java.io.File; import javax.annotation.Nullable; diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/TranslatedCodebaseProcessor.java b/client/src/main/java/com/google/devtools/moe/client/codebase/TranslatedCodebaseProcessor.java index 3d68a2b7..6c7ce421 100644 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/TranslatedCodebaseProcessor.java +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/TranslatedCodebaseProcessor.java @@ -45,7 +45,7 @@ public Codebase createCodebase(TranslateExpression expression, ProjectContext co ui.newTask( "translate", "Translating %s from project space \"%s\" to \"%s\"", - codebaseToTranslate.path(), + codebaseToTranslate.root(), codebaseToTranslate.projectSpace(), toProjectSpace)) { @@ -56,7 +56,7 @@ public Codebase createCodebase(TranslateExpression expression, ProjectContext co // Don't mark the translated codebase for persistence if it wasn't allocated by the // Translator. if (translatedCodebase.equals(codebaseToTranslate)) { - translateTask.result().append(translatedCodebase.path() + " (unmodified)"); + translateTask.result().append(translatedCodebase.root() + " (unmodified)"); } else { translateTask.keep(translatedCodebase); } diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/BUILD.bazel b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/BUILD.bazel new file mode 100644 index 00000000..bcf1ff32 --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/BUILD.bazel @@ -0,0 +1,11 @@ +load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library", "kt_jvm_binary") + +package(default_visibility = ["//client:__subpackages__"]) + +kt_jvm_library( + name = "expressions", + srcs = glob(["*.java", "*.kt"]), + deps = [ + "@maven//com/google/guava", + ], +) \ No newline at end of file diff --git a/client/src/main/java/com/google/devtools/moe/client/config/BUILD.bazel b/client/src/main/java/com/google/devtools/moe/client/config/BUILD.bazel new file mode 100644 index 00000000..9dec294b --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/config/BUILD.bazel @@ -0,0 +1,15 @@ +package(default_visibility = ["//client:__subpackages__"]) + +java_library( + name = "config", + srcs = glob(["*.java", "*.kt"]), + javacopts = ["-Aautovaluegson.defaultCollectionsToEmpty=true"], + deps = [ + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/gson", + "@maven//com/google/code/findbugs:jsr305", + "@maven//com/google/auto/value", + "@maven//com/google/code/gson", + "@maven//com/google/guava", + ], +) \ No newline at end of file diff --git a/client/src/main/java/com/google/devtools/moe/client/config/ConfigTypeAdapterFactory.java b/client/src/main/java/com/google/devtools/moe/client/config/ConfigTypeAdapterFactory.java new file mode 100644 index 00000000..478690aa --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/config/ConfigTypeAdapterFactory.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.devtools.moe.client.config; + +import com.google.gson.TypeAdapterFactory; +import com.ryanharter.auto.value.gson.GsonTypeAdapterFactory; + +@GsonTypeAdapterFactory +public abstract class ConfigTypeAdapterFactory implements TypeAdapterFactory { + public static TypeAdapterFactory create() { + return new AutoValueGson_ConfigTypeAdapterFactory(); + } +} diff --git a/client/src/main/java/com/google/devtools/moe/client/project/EditorConfig.java b/client/src/main/java/com/google/devtools/moe/client/config/EditorConfig.java similarity index 89% rename from client/src/main/java/com/google/devtools/moe/client/project/EditorConfig.java rename to client/src/main/java/com/google/devtools/moe/client/config/EditorConfig.java index 9fce21c9..dc17c37b 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/EditorConfig.java +++ b/client/src/main/java/com/google/devtools/moe/client/config/EditorConfig.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.google.devtools.moe.client.project; +package com.google.devtools.moe.client.config; import com.google.auto.value.AutoValue; -import com.google.devtools.moe.client.translation.editors.Editor; +import com.google.devtools.moe.client.InvalidProject; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.TypeAdapter; @@ -30,7 +30,7 @@ @AutoValue public abstract class EditorConfig { @Nullable - public abstract Editor.Type type(); + public abstract EditorType type(); @Nullable @SerializedName("scrubber_config") // TODO(cushon): remove pending rharter/auto-value-gson#18 @@ -47,12 +47,12 @@ public abstract class EditorConfig { public abstract boolean useRegex(); // TODO(cgruber): Push validation around the whole structure. - void validate() throws InvalidProject { + public void validate() throws InvalidProject { InvalidProject.assertNotNull(type(), "Missing type in editor"); } public static EditorConfig create( - Editor.Type type, + EditorType type, ScrubberConfig scrubberConfig, String commandString, JsonObject mappings, diff --git a/client/src/main/java/com/google/devtools/moe/client/config/EditorType.java b/client/src/main/java/com/google/devtools/moe/client/config/EditorType.java new file mode 100644 index 00000000..f763c9ea --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/config/EditorType.java @@ -0,0 +1,14 @@ +package com.google.devtools.moe.client.config; + +/** + * Enum of all known editor implementations. + * + * All values are valid JSON editor types. + */ +public enum EditorType { + identity, + scrubber, + patcher, + shell, + renamer +} diff --git a/client/src/main/java/com/google/devtools/moe/client/repositories/MetadataScrubberConfig.java b/client/src/main/java/com/google/devtools/moe/client/config/MetadataScrubberConfig.java similarity index 93% rename from client/src/main/java/com/google/devtools/moe/client/repositories/MetadataScrubberConfig.java rename to client/src/main/java/com/google/devtools/moe/client/config/MetadataScrubberConfig.java index 20108d4b..795db7f9 100644 --- a/client/src/main/java/com/google/devtools/moe/client/repositories/MetadataScrubberConfig.java +++ b/client/src/main/java/com/google/devtools/moe/client/config/MetadataScrubberConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.devtools.moe.client.repositories; +package com.google.devtools.moe.client.config; import com.google.common.collect.ImmutableList; @@ -30,7 +30,7 @@ public class MetadataScrubberConfig { /** * Formatting for changelog adapted from fromRepository for commits in toRepository. See - * {@link DescriptionMetadataScrubber}. + * {@link com.google.devtools.moe.client.repositories.DescriptionMetadataScrubber}. */ private String logFormat = "{description}\n\n\tChange on {date} by {author}\n"; diff --git a/client/src/main/java/com/google/devtools/moe/client/migrations/MigrationConfig.java b/client/src/main/java/com/google/devtools/moe/client/config/MigrationConfig.java similarity index 90% rename from client/src/main/java/com/google/devtools/moe/client/migrations/MigrationConfig.java rename to client/src/main/java/com/google/devtools/moe/client/config/MigrationConfig.java index b95256c4..ce557a77 100644 --- a/client/src/main/java/com/google/devtools/moe/client/migrations/MigrationConfig.java +++ b/client/src/main/java/com/google/devtools/moe/client/config/MigrationConfig.java @@ -14,11 +14,10 @@ * limitations under the License. */ -package com.google.devtools.moe.client.migrations; +package com.google.devtools.moe.client.config; import com.google.devtools.moe.client.gson.GsonUtil; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.repositories.MetadataScrubberConfig; +import com.google.devtools.moe.client.InvalidProject; /** * Configuration for a MOE migration. diff --git a/client/src/main/java/com/google/devtools/moe/client/project/ProjectConfig.java b/client/src/main/java/com/google/devtools/moe/client/config/ProjectConfig.java similarity index 74% rename from client/src/main/java/com/google/devtools/moe/client/project/ProjectConfig.java rename to client/src/main/java/com/google/devtools/moe/client/config/ProjectConfig.java index b2070716..5bd87c3a 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/ProjectConfig.java +++ b/client/src/main/java/com/google/devtools/moe/client/config/ProjectConfig.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.devtools.moe.client.project; +package com.google.devtools.moe.client.config; import com.google.auto.value.AutoValue; import com.google.common.base.Strings; @@ -22,18 +22,10 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedSet; import com.google.devtools.moe.client.MoeProblem; -import com.google.devtools.moe.client.gson.GsonModule; -import com.google.devtools.moe.client.gson.JsonStructureChecker; -import com.google.devtools.moe.client.migrations.MigrationConfig; +import com.google.devtools.moe.client.InvalidProject; import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonParser; import com.google.gson.TypeAdapter; import com.google.gson.annotations.SerializedName; -import com.google.gson.stream.JsonReader; -import com.google.json.JsonSanitizer; -import java.io.StringReader; import java.util.Map; import javax.annotation.Nullable; @@ -135,7 +127,7 @@ public ScrubberConfig findScrubberConfig(String fromRepository, String toReposit return (translator == null) ? null : translator.scrubber(); } - void validate() throws InvalidProject { + public void validate() throws InvalidProject { InvalidProject.assertFalse(Strings.isNullOrEmpty(name()), "Must specify a name"); InvalidProject.assertFalse(repositories().isEmpty(), "Must specify repositories"); @@ -153,37 +145,6 @@ void validate() throws InvalidProject { } } - public static ProjectConfig parse(String configText) throws InvalidProject { - ProjectConfig config = null; - if (configText != null) { - try { - JsonReader configReader = new JsonReader(new StringReader(configText)); - configReader.setLenient(true); - JsonElement configJsonElement = new JsonParser().parse(configReader); - if (configJsonElement != null) { - // Config files often contain JavaScript idioms like comments, single quoted strings, - // and trailing commas in lists. - // Check that the JSON parsed from configText is structurally the same as that - // produced when it is interpreted by GSON in lax mode. - String normalConfigText = JsonSanitizer.sanitize(configText); - JsonElement normalConfigJsonElement = new JsonParser().parse(normalConfigText); - JsonStructureChecker.requireSimilar(configJsonElement, normalConfigJsonElement); - - Gson gson = GsonModule.provideGson(); // TODO(user): Remove this static reference. - config = gson.fromJson(configText, ProjectConfig.class); - } - } catch (JsonParseException e) { - throw new InvalidProject(e, "Could not parse MOE config: " + e.getMessage()); - } - } - - if (config == null) { - throw new InvalidProject("Could not parse MOE config"); - } - config.validate(); - return config; - } - public static TypeAdapter typeAdapter(Gson gson) { return new AutoValue_ProjectConfig.GsonTypeAdapter(gson); } diff --git a/client/src/main/java/com/google/devtools/moe/client/project/RepositoryConfig.java b/client/src/main/java/com/google/devtools/moe/client/config/RepositoryConfig.java similarity index 87% rename from client/src/main/java/com/google/devtools/moe/client/project/RepositoryConfig.java rename to client/src/main/java/com/google/devtools/moe/client/config/RepositoryConfig.java index 6168435a..24987341 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/RepositoryConfig.java +++ b/client/src/main/java/com/google/devtools/moe/client/config/RepositoryConfig.java @@ -14,16 +14,16 @@ * limitations under the License. */ -package com.google.devtools.moe.client.project; +package com.google.devtools.moe.client.config; -import static com.google.devtools.moe.client.project.InvalidProject.assertFalse; -import static com.google.devtools.moe.client.project.InvalidProject.assertNotNull; +import static com.google.devtools.moe.client.InvalidProject.assertFalse; +import static com.google.devtools.moe.client.InvalidProject.assertNotNull; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.devtools.moe.client.gson.GsonUtil; -import com.google.devtools.moe.client.repositories.RepositoryType; +import com.google.devtools.moe.client.InvalidProject; import com.google.gson.annotations.SerializedName; import java.util.List; @@ -174,21 +174,6 @@ public List getExecutableFilePatterns() { return executableFileRes; } - /** - * Validates that the supplied - * {@link com.google.devtools.moe.client.repositories.RepositoryType.Factory} targets the - * correct repo type, throwing an {@link InvalidProject} exception if it does not. - */ - public void checkType(RepositoryType.Factory repositoryFactory) throws InvalidProject { - if (!repositoryFactory.type().equals(getType())) { - // TODO(cgruber): Make it so this can't happen at runtime, ever, and throw AssertionError. - throw new InvalidProject( - "Invalid repository type '%s' for %s", - getType(), - repositoryFactory.getClass().getSimpleName()); - } - } - /** * Modified copy creator, that supplies a clone with the branch field altered. */ @@ -212,7 +197,7 @@ public RepositoryConfig copyWithUrl(String url) { * * @throws InvalidProject an error describing an error in the project configuration. */ - void validate() { + public void validate() { assertNotNull(getType(), "Must set repository type."); assertFalse(getType().trim().isEmpty(), "Must set repository type."); } diff --git a/client/src/main/java/com/google/devtools/moe/client/project/ScrubberConfig.java b/client/src/main/java/com/google/devtools/moe/client/config/ScrubberConfig.java similarity index 95% rename from client/src/main/java/com/google/devtools/moe/client/project/ScrubberConfig.java rename to client/src/main/java/com/google/devtools/moe/client/config/ScrubberConfig.java index 6663eea2..c39a7d7e 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/ScrubberConfig.java +++ b/client/src/main/java/com/google/devtools/moe/client/config/ScrubberConfig.java @@ -1,5 +1,6 @@ -package com.google.devtools.moe.client.project; +package com.google.devtools.moe.client.config; +import com.google.devtools.moe.client.InvalidProject; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.ArrayList; @@ -84,7 +85,7 @@ public String getUsernamesFile() { /** * Called by ProjectContextFactory to update usernamesConfig with external usernames file. */ - void updateUsernames(UsernamesConfig usernamesConfig) { + public void updateUsernames(UsernamesConfig usernamesConfig) { addUsernames(usernamesToScrub, usernamesConfig.getScrubbableUsernames()); addUsernames(usernamesToPublish, usernamesConfig.getPublishableUsernames()); // reset usernamesFile to null so that we don't read the file again diff --git a/client/src/main/java/com/google/devtools/moe/client/project/StepConfig.java b/client/src/main/java/com/google/devtools/moe/client/config/StepConfig.java similarity index 92% rename from client/src/main/java/com/google/devtools/moe/client/project/StepConfig.java rename to client/src/main/java/com/google/devtools/moe/client/config/StepConfig.java index 8ef762b6..9335d27e 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/StepConfig.java +++ b/client/src/main/java/com/google/devtools/moe/client/config/StepConfig.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.google.devtools.moe.client.project; +package com.google.devtools.moe.client.config; +import com.google.devtools.moe.client.InvalidProject; import com.google.gson.annotations.SerializedName; /** diff --git a/client/src/main/java/com/google/devtools/moe/client/project/TranslatorConfig.java b/client/src/main/java/com/google/devtools/moe/client/config/TranslatorConfig.java similarity index 88% rename from client/src/main/java/com/google/devtools/moe/client/project/TranslatorConfig.java rename to client/src/main/java/com/google/devtools/moe/client/config/TranslatorConfig.java index efee54d5..90f535df 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/TranslatorConfig.java +++ b/client/src/main/java/com/google/devtools/moe/client/config/TranslatorConfig.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.google.devtools.moe.client.project; +package com.google.devtools.moe.client.config; + +import com.google.devtools.moe.client.InvalidProject; -import com.google.devtools.moe.client.translation.editors.Editor; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -52,7 +53,7 @@ public boolean isInverse() { public ScrubberConfig scrubber() { if (getSteps() != null) { for (StepConfig step : getSteps()) { - if (step.getEditorConfig().type() == Editor.Type.scrubber) { + if (step.getEditorConfig().type() == EditorType.scrubber) { return step.getEditorConfig().scrubberConfig(); } } @@ -64,14 +65,14 @@ public List scrubbers() { if (getSteps() != null) { return getSteps().stream() .map(StepConfig::getEditorConfig) - .filter(ec -> ec.type() == Editor.Type.scrubber) + .filter(ec -> ec.type() == EditorType.scrubber) .map(EditorConfig::scrubberConfig) .collect(Collectors.toList()); } return new ArrayList<>(0); } - void validate() throws InvalidProject { + public void validate() throws InvalidProject { InvalidProject.assertNotEmpty(fromProjectSpace, "Translator requires from_project_space"); InvalidProject.assertNotEmpty(toProjectSpace, "Translator requires to_project_space"); if (inverse) { diff --git a/client/src/main/java/com/google/devtools/moe/client/project/UsernamesConfig.java b/client/src/main/java/com/google/devtools/moe/client/config/UsernamesConfig.java similarity index 89% rename from client/src/main/java/com/google/devtools/moe/client/project/UsernamesConfig.java rename to client/src/main/java/com/google/devtools/moe/client/config/UsernamesConfig.java index 7456cb69..95aceeef 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/UsernamesConfig.java +++ b/client/src/main/java/com/google/devtools/moe/client/config/UsernamesConfig.java @@ -1,4 +1,4 @@ -package com.google.devtools.moe.client.project; +package com.google.devtools.moe.client.config; import java.util.List; diff --git a/client/src/main/java/com/google/devtools/moe/client/database/Bookkeeper.java b/client/src/main/java/com/google/devtools/moe/client/database/Bookkeeper.java index 8e035a64..3aeca5c1 100644 --- a/client/src/main/java/com/google/devtools/moe/client/database/Bookkeeper.java +++ b/client/src/main/java/com/google/devtools/moe/client/database/Bookkeeper.java @@ -27,9 +27,9 @@ import com.google.devtools.moe.client.codebase.ExpressionEngine; import com.google.devtools.moe.client.codebase.expressions.Expression; import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; -import com.google.devtools.moe.client.migrations.MigrationConfig; +import com.google.devtools.moe.client.config.MigrationConfig; import com.google.devtools.moe.client.project.ProjectContext; -import com.google.devtools.moe.client.project.TranslatorConfig; +import com.google.devtools.moe.client.config.TranslatorConfig; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.repositories.RevisionHistory; import com.google.devtools.moe.client.repositories.RevisionHistory.SearchType; diff --git a/client/src/main/java/com/google/devtools/moe/client/database/FileDb.java b/client/src/main/java/com/google/devtools/moe/client/database/FileDb.java index 5249a15b..50bc8c48 100644 --- a/client/src/main/java/com/google/devtools/moe/client/database/FileDb.java +++ b/client/src/main/java/com/google/devtools/moe/client/database/FileDb.java @@ -22,8 +22,8 @@ import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.database.Db.HasDbStorage; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.ProjectConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.ProjectConfig; import com.google.devtools.moe.client.qualifiers.Argument; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.testing.DummyDb; diff --git a/client/src/main/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java b/client/src/main/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java index 1febfcb9..7b8028ae 100644 --- a/client/src/main/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java +++ b/client/src/main/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java @@ -68,7 +68,7 @@ protected int performDirectiveBehavior() { try (Task task = ui.newTask("create_codebase", "Creating codebase %s", codebase)) { Codebase realCodebase = task.keep(expressionEngine.createCodebase(Parser.parseExpression(codebase), context)); - ui.message("Codebase \"%s\" created at %s", realCodebase, realCodebase.path()); + ui.message("Codebase \"%s\" created at %s", realCodebase, realCodebase.root()); maybeWriteTar(realCodebase); } catch (CommandException e) { throw new MoeProblem(e, "Error creating codebase tarfile"); @@ -89,7 +89,7 @@ private void maybeWriteTar(Codebase codebase) throws CommandException { } cmd.runCommand( - codebase.path().getAbsolutePath(), + codebase.root().getAbsolutePath(), "tar", ImmutableList.of("--mtime=1980-01-01", "--owner=0", "--group=0", "-c", "-f", tarfile, ".")); diff --git a/client/src/main/java/com/google/devtools/moe/client/directives/DetermineMigrationsDirective.java b/client/src/main/java/com/google/devtools/moe/client/directives/DetermineMigrationsDirective.java index fb291c7c..fe17ca2b 100644 --- a/client/src/main/java/com/google/devtools/moe/client/directives/DetermineMigrationsDirective.java +++ b/client/src/main/java/com/google/devtools/moe/client/directives/DetermineMigrationsDirective.java @@ -19,7 +19,7 @@ import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.migrations.Migration; -import com.google.devtools.moe.client.migrations.MigrationConfig; +import com.google.devtools.moe.client.config.MigrationConfig; import com.google.devtools.moe.client.migrations.Migrator; import com.google.devtools.moe.client.project.ProjectContext; import com.google.devtools.moe.client.repositories.RepositoryType; diff --git a/client/src/main/java/com/google/devtools/moe/client/directives/Directive.java b/client/src/main/java/com/google/devtools/moe/client/directives/Directive.java index 3ae4c9af..e36041b8 100644 --- a/client/src/main/java/com/google/devtools/moe/client/directives/Directive.java +++ b/client/src/main/java/com/google/devtools/moe/client/directives/Directive.java @@ -17,7 +17,7 @@ package com.google.devtools.moe.client.directives; import com.google.devtools.moe.client.options.MoeOptions; -import com.google.devtools.moe.client.project.InvalidProject; +import com.google.devtools.moe.client.InvalidProject; /** * A Directive is what MOE should do in this run. diff --git a/client/src/main/java/com/google/devtools/moe/client/directives/GithubPullDirective.java b/client/src/main/java/com/google/devtools/moe/client/directives/GithubPullDirective.java index b698ef63..4e667343 100644 --- a/client/src/main/java/com/google/devtools/moe/client/directives/GithubPullDirective.java +++ b/client/src/main/java/com/google/devtools/moe/client/directives/GithubPullDirective.java @@ -24,8 +24,8 @@ import com.google.devtools.moe.client.github.GithubAPI.PullRequest; import com.google.devtools.moe.client.github.GithubClient; import com.google.devtools.moe.client.github.PullRequestUrl; -import com.google.devtools.moe.client.project.ProjectConfig; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.ProjectConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import dagger.Provides; import dagger.multibindings.IntoMap; import dagger.multibindings.StringKey; diff --git a/client/src/main/java/com/google/devtools/moe/client/directives/MagicDirective.java b/client/src/main/java/com/google/devtools/moe/client/directives/MagicDirective.java index d7bd9297..ee00c060 100644 --- a/client/src/main/java/com/google/devtools/moe/client/directives/MagicDirective.java +++ b/client/src/main/java/com/google/devtools/moe/client/directives/MagicDirective.java @@ -32,11 +32,11 @@ import com.google.devtools.moe.client.database.Bookkeeper; import com.google.devtools.moe.client.database.RepositoryEquivalence; import com.google.devtools.moe.client.migrations.Migration; -import com.google.devtools.moe.client.migrations.MigrationConfig; +import com.google.devtools.moe.client.config.MigrationConfig; import com.google.devtools.moe.client.migrations.Migrator; -import com.google.devtools.moe.client.project.ProjectConfig; +import com.google.devtools.moe.client.config.ProjectConfig; import com.google.devtools.moe.client.project.ProjectContext; -import com.google.devtools.moe.client.project.ScrubberConfig; +import com.google.devtools.moe.client.config.ScrubberConfig; import com.google.devtools.moe.client.repositories.RepositoryType; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.writer.DraftRevision; diff --git a/client/src/main/java/com/google/devtools/moe/client/directives/MigrateBranchDirective.java b/client/src/main/java/com/google/devtools/moe/client/directives/MigrateBranchDirective.java index bef582a2..0dcb9181 100644 --- a/client/src/main/java/com/google/devtools/moe/client/directives/MigrateBranchDirective.java +++ b/client/src/main/java/com/google/devtools/moe/client/directives/MigrateBranchDirective.java @@ -37,12 +37,12 @@ import com.google.devtools.moe.client.database.RepositoryEquivalence; import com.google.devtools.moe.client.database.RepositoryEquivalenceMatcher.Result; import com.google.devtools.moe.client.migrations.Migration; -import com.google.devtools.moe.client.migrations.MigrationConfig; +import com.google.devtools.moe.client.config.MigrationConfig; import com.google.devtools.moe.client.migrations.Migrator; -import com.google.devtools.moe.client.project.ProjectConfig; +import com.google.devtools.moe.client.config.ProjectConfig; import com.google.devtools.moe.client.project.ProjectContext; -import com.google.devtools.moe.client.project.RepositoryConfig; -import com.google.devtools.moe.client.project.ScrubberConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; +import com.google.devtools.moe.client.config.ScrubberConfig; import com.google.devtools.moe.client.repositories.Repositories; import com.google.devtools.moe.client.repositories.RepositoryType; import com.google.devtools.moe.client.repositories.Revision; diff --git a/client/src/main/java/com/google/devtools/moe/client/directives/OneMigrationDirective.java b/client/src/main/java/com/google/devtools/moe/client/directives/OneMigrationDirective.java index 2a90a082..4d6846e8 100644 --- a/client/src/main/java/com/google/devtools/moe/client/directives/OneMigrationDirective.java +++ b/client/src/main/java/com/google/devtools/moe/client/directives/OneMigrationDirective.java @@ -27,10 +27,10 @@ import com.google.devtools.moe.client.codebase.expressions.Parser.ParseError; import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; import com.google.devtools.moe.client.migrations.Migrator; -import com.google.devtools.moe.client.project.ProjectConfig; +import com.google.devtools.moe.client.config.ProjectConfig; import com.google.devtools.moe.client.project.ProjectContext; -import com.google.devtools.moe.client.project.RepositoryConfig; -import com.google.devtools.moe.client.project.ScrubberConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; +import com.google.devtools.moe.client.config.ScrubberConfig; import com.google.devtools.moe.client.repositories.RepositoryType; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.repositories.RevisionMetadata; diff --git a/client/src/main/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java b/client/src/main/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java index 4421015b..46312ab4 100644 --- a/client/src/main/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java +++ b/client/src/main/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java @@ -24,6 +24,7 @@ import com.google.devtools.moe.client.Utils; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.LocalWorkspace; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.RevisionMetadata; import com.google.devtools.moe.client.writer.DraftRevision; import com.google.devtools.moe.client.writer.Writer; @@ -63,7 +64,7 @@ public File getRoot() { /** * Returns the regexes, a la {@link - * com.google.devtools.moe.client.project.RepositoryConfig#getIgnoreFilePatterns()}, of filepaths + * RepositoryConfig#getIgnoreFilePatterns()}, of filepaths * to ignore in this Writer. For example, an Hg implementation of this method would return the * getIgnoreFileRes() in its RepositoryConfig along with any Hg-specific paths in its LocalClone, * such as "^.hg/.*". Otherwise, this Writer would attempt to modify hg-metadata files. @@ -75,7 +76,7 @@ private DraftRevision putCodebase(Codebase incomingChangeCodebase) { Set codebaseFiles = Utils.makeFilenamesRelative( - filesystem.findFiles(incomingChangeCodebase.path()), incomingChangeCodebase.path()); + filesystem.findFiles(incomingChangeCodebase.root()), incomingChangeCodebase.root()); Set writerRepoFiles = Utils.filterByRegEx( Utils.makeFilenamesRelative(filesystem.findFiles(getRoot()), getRoot()), diff --git a/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java b/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java index bb9a15f3..ed566329 100644 --- a/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java +++ b/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java @@ -27,7 +27,7 @@ import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.codebase.LocalWorkspace; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import java.io.File; import java.io.IOException; import java.nio.file.Paths; diff --git a/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitCodebaseCreator.java b/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitCodebaseCreator.java index ecb44318..61e96003 100644 --- a/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitCodebaseCreator.java +++ b/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitCodebaseCreator.java @@ -22,7 +22,7 @@ import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.codebase.LocalWorkspace; import com.google.devtools.moe.client.dvcs.AbstractDvcsCodebaseCreator; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.RevisionHistory; /** diff --git a/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java b/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java index 13db12df..a541ef6c 100644 --- a/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java +++ b/client/src/main/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java @@ -24,8 +24,8 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.RepositoryType; import javax.inject.Inject; @@ -58,7 +58,7 @@ public String type() { @Override public RepositoryType create(final String name, final RepositoryConfig config) throws InvalidProject { - config.checkType(this); + checkType(config); final String url = config.getUrl(); if (isNullOrEmpty(url)) { diff --git a/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java b/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java index 46b78d9a..b1732513 100644 --- a/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java +++ b/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java @@ -27,7 +27,7 @@ import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.codebase.LocalWorkspace; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import java.io.File; import java.io.IOException; import java.util.List; diff --git a/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgCodebaseCreator.java b/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgCodebaseCreator.java index 23b5e51a..f2473d04 100644 --- a/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgCodebaseCreator.java +++ b/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgCodebaseCreator.java @@ -22,7 +22,7 @@ import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.codebase.LocalWorkspace; import com.google.devtools.moe.client.dvcs.AbstractDvcsCodebaseCreator; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.RevisionHistory; import java.io.File; diff --git a/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java b/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java index 91e6565b..ee1c5b37 100644 --- a/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java +++ b/client/src/main/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java @@ -24,8 +24,8 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.RepositoryType; import java.io.File; import javax.inject.Inject; @@ -66,7 +66,7 @@ public String type() { @Override public RepositoryType create(final String name, final RepositoryConfig config) throws InvalidProject { - config.checkType(this); + checkType(config); final String url = config.getUrl(); if (isNullOrEmpty(url)) { diff --git a/client/src/main/java/com/google/devtools/moe/client/gson/BUILD.bazel b/client/src/main/java/com/google/devtools/moe/client/gson/BUILD.bazel new file mode 100644 index 00000000..497e36fd --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/gson/BUILD.bazel @@ -0,0 +1,16 @@ +package(default_visibility = ["//client:__subpackages__"]) + +java_library( + name = "gson", + srcs = glob(["*.java"]), + deps = [ + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//args4j", + "@maven//com/google/auto/value", + "@maven//com/google/guava", + "@maven//com/google/code/gson", + "@maven//com/mikesamuel:json-sanitizer", + "@maven//com/google/code/findbugs:jsr305", + "@maven//joda-time", + ], +) \ No newline at end of file diff --git a/client/src/main/java/com/google/devtools/moe/client/gson/ImmutableListDeserializer.java b/client/src/main/java/com/google/devtools/moe/client/gson/ImmutableListDeserializer.java index bbcca176..01a15d0d 100644 --- a/client/src/main/java/com/google/devtools/moe/client/gson/ImmutableListDeserializer.java +++ b/client/src/main/java/com/google/devtools/moe/client/gson/ImmutableListDeserializer.java @@ -25,7 +25,7 @@ import java.lang.reflect.Type; import java.util.List; -final class ImmutableListDeserializer implements JsonDeserializer> { +public final class ImmutableListDeserializer implements JsonDeserializer> { @Override public ImmutableList deserialize( JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { diff --git a/client/src/main/java/com/google/devtools/moe/client/gson/JsonStructureChecker.java b/client/src/main/java/com/google/devtools/moe/client/gson/JsonStructureChecker.java index 53e0000b..36b8adbd 100644 --- a/client/src/main/java/com/google/devtools/moe/client/gson/JsonStructureChecker.java +++ b/client/src/main/java/com/google/devtools/moe/client/gson/JsonStructureChecker.java @@ -17,7 +17,7 @@ package com.google.devtools.moe.client.gson; import com.google.common.base.Joiner; -import com.google.devtools.moe.client.project.InvalidProject; +import com.google.devtools.moe.client.InvalidProject; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; diff --git a/client/src/main/java/com/google/devtools/moe/client/migrations/Migrator.java b/client/src/main/java/com/google/devtools/moe/client/migrations/Migrator.java index 9ff439f4..292f8a78 100644 --- a/client/src/main/java/com/google/devtools/moe/client/migrations/Migrator.java +++ b/client/src/main/java/com/google/devtools/moe/client/migrations/Migrator.java @@ -22,14 +22,15 @@ import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; +import com.google.devtools.moe.client.config.MigrationConfig; import com.google.devtools.moe.client.database.Db; import com.google.devtools.moe.client.database.RepositoryEquivalence; import com.google.devtools.moe.client.database.RepositoryEquivalenceMatcher; import com.google.devtools.moe.client.database.RepositoryEquivalenceMatcher.Result; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.ScrubberConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.ScrubberConfig; import com.google.devtools.moe.client.repositories.MetadataScrubber; -import com.google.devtools.moe.client.repositories.MetadataScrubberConfig; +import com.google.devtools.moe.client.config.MetadataScrubberConfig; import com.google.devtools.moe.client.repositories.RepositoryType; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.repositories.RevisionHistory; diff --git a/client/src/main/java/com/google/devtools/moe/client/project/FileReadingProjectContextFactory.java b/client/src/main/java/com/google/devtools/moe/client/project/FileReadingProjectContextFactory.java index 4ba75866..1262720f 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/FileReadingProjectContextFactory.java +++ b/client/src/main/java/com/google/devtools/moe/client/project/FileReadingProjectContextFactory.java @@ -17,9 +17,14 @@ package com.google.devtools.moe.client.project; import com.google.devtools.moe.client.FileSystem; +import com.google.devtools.moe.client.InvalidProject; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.Ui.Task; import com.google.devtools.moe.client.codebase.ExpressionEngine; +import com.google.devtools.moe.client.config.ProjectConfig; +import com.google.devtools.moe.client.config.ScrubberConfig; +import com.google.devtools.moe.client.config.TranslatorConfig; +import com.google.devtools.moe.client.config.UsernamesConfig; import com.google.devtools.moe.client.repositories.Repositories; import com.google.devtools.moe.client.translation.editors.Editors; import com.google.gson.Gson; @@ -48,7 +53,7 @@ public ProjectConfig loadConfiguration(String configFilename) throws InvalidProj String configText; try (Task t = ui.newTask("read_config", "Reading config file from %s", configFilename)) { configText = fileSystem.fileToString(new File(configFilename)); - return ProjectConfig.parse(configText); + return ProjectConfigs.parse(configText); } catch (IOException e) { throw new InvalidProject("Config File \"" + configFilename + "\" not accessible."); } diff --git a/client/src/main/java/com/google/devtools/moe/client/project/ProjectConfigs.java b/client/src/main/java/com/google/devtools/moe/client/project/ProjectConfigs.java new file mode 100644 index 00000000..3a5ad522 --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/project/ProjectConfigs.java @@ -0,0 +1,48 @@ +package com.google.devtools.moe.client.project; + +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.ProjectConfig; +import com.google.devtools.moe.client.GsonModule; +import com.google.devtools.moe.client.gson.JsonStructureChecker; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonParser; +import com.google.gson.stream.JsonReader; +import com.google.json.JsonSanitizer; + +import java.io.StringReader; + +/** Produces a project config from a JSON string representation. */ +public class ProjectConfigs { + public static ProjectConfig parse(String configText) throws InvalidProject { + ProjectConfig config = null; + if (configText != null) { + try { + JsonReader configReader = new JsonReader(new StringReader(configText)); + configReader.setLenient(true); + JsonElement configJsonElement = new JsonParser().parse(configReader); + if (configJsonElement != null) { + // Config files often contain JavaScript idioms like comments, single quoted strings, + // and trailing commas in lists. + // Check that the JSON parsed from configText is structurally the same as that + // produced when it is interpreted by GSON in lax mode. + String normalConfigText = JsonSanitizer.sanitize(configText); + JsonElement normalConfigJsonElement = new JsonParser().parse(normalConfigText); + JsonStructureChecker.requireSimilar(configJsonElement, normalConfigJsonElement); + + Gson gson = GsonModule.provideGson(); // TODO(user): Remove this static reference. + config = gson.fromJson(configText, ProjectConfig.class); + } + } catch (JsonParseException e) { + throw new InvalidProject(e, "Could not parse MOE config: " + e.getMessage()); + } + } + + if (config == null) { + throw new InvalidProject("Could not parse MOE config"); + } + config.validate(); + return config; + } +} diff --git a/client/src/main/java/com/google/devtools/moe/client/project/ProjectContext.java b/client/src/main/java/com/google/devtools/moe/client/project/ProjectContext.java index a0e254a9..15b90538 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/ProjectContext.java +++ b/client/src/main/java/com/google/devtools/moe/client/project/ProjectContext.java @@ -20,7 +20,8 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedSet; import com.google.devtools.moe.client.MoeProblem; -import com.google.devtools.moe.client.migrations.MigrationConfig; +import com.google.devtools.moe.client.config.ProjectConfig; +import com.google.devtools.moe.client.config.MigrationConfig; import com.google.devtools.moe.client.repositories.RepositoryType; import com.google.devtools.moe.client.translation.editors.Editor; import com.google.devtools.moe.client.translation.pipeline.TranslationPath; diff --git a/client/src/main/java/com/google/devtools/moe/client/project/ProjectContextFactory.java b/client/src/main/java/com/google/devtools/moe/client/project/ProjectContextFactory.java index da0bd80f..732480e4 100644 --- a/client/src/main/java/com/google/devtools/moe/client/project/ProjectContextFactory.java +++ b/client/src/main/java/com/google/devtools/moe/client/project/ProjectContextFactory.java @@ -20,9 +20,15 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import com.google.devtools.moe.client.InvalidProject; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.ExpressionEngine; -import com.google.devtools.moe.client.migrations.MigrationConfig; +import com.google.devtools.moe.client.config.EditorConfig; +import com.google.devtools.moe.client.config.ProjectConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; +import com.google.devtools.moe.client.config.StepConfig; +import com.google.devtools.moe.client.config.TranslatorConfig; +import com.google.devtools.moe.client.config.MigrationConfig; import com.google.devtools.moe.client.repositories.Repositories; import com.google.devtools.moe.client.repositories.RepositoryType; import com.google.devtools.moe.client.translation.editors.Editor; diff --git a/client/src/main/java/com/google/devtools/moe/client/qualifiers/BUILD.bazel b/client/src/main/java/com/google/devtools/moe/client/qualifiers/BUILD.bazel new file mode 100644 index 00000000..0e75f29b --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/qualifiers/BUILD.bazel @@ -0,0 +1,9 @@ +package(default_visibility = ["//client:__subpackages__"]) + +java_library( + name = "qualifiers", + srcs = glob(["*.java"]), + deps = [ + "@maven//javax/inject:javax_inject", + ], +) diff --git a/client/src/main/java/com/google/devtools/moe/client/repositories/DescriptionMetadataScrubber.java b/client/src/main/java/com/google/devtools/moe/client/repositories/DescriptionMetadataScrubber.java index 4e9bca89..12fbf3a3 100644 --- a/client/src/main/java/com/google/devtools/moe/client/repositories/DescriptionMetadataScrubber.java +++ b/client/src/main/java/com/google/devtools/moe/client/repositories/DescriptionMetadataScrubber.java @@ -18,6 +18,7 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.config.MetadataScrubberConfig; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; diff --git a/client/src/main/java/com/google/devtools/moe/client/repositories/MetadataScrubber.java b/client/src/main/java/com/google/devtools/moe/client/repositories/MetadataScrubber.java index de78615c..b5782819 100644 --- a/client/src/main/java/com/google/devtools/moe/client/repositories/MetadataScrubber.java +++ b/client/src/main/java/com/google/devtools/moe/client/repositories/MetadataScrubber.java @@ -18,6 +18,8 @@ import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; +import com.google.devtools.moe.client.config.MetadataScrubberConfig; + import dagger.Binds; import dagger.multibindings.IntKey; import dagger.multibindings.IntoMap; diff --git a/client/src/main/java/com/google/devtools/moe/client/repositories/MetadataUsernameScrubber.java b/client/src/main/java/com/google/devtools/moe/client/repositories/MetadataUsernameScrubber.java index e9c1008c..a72ffcaa 100644 --- a/client/src/main/java/com/google/devtools/moe/client/repositories/MetadataUsernameScrubber.java +++ b/client/src/main/java/com/google/devtools/moe/client/repositories/MetadataUsernameScrubber.java @@ -16,6 +16,8 @@ package com.google.devtools.moe.client.repositories; +import com.google.devtools.moe.client.config.MetadataScrubberConfig; + import javax.inject.Inject; /** diff --git a/client/src/main/java/com/google/devtools/moe/client/repositories/OriginalAuthorMetadataScrubber.java b/client/src/main/java/com/google/devtools/moe/client/repositories/OriginalAuthorMetadataScrubber.java index fe59e6f2..e9149751 100644 --- a/client/src/main/java/com/google/devtools/moe/client/repositories/OriginalAuthorMetadataScrubber.java +++ b/client/src/main/java/com/google/devtools/moe/client/repositories/OriginalAuthorMetadataScrubber.java @@ -17,6 +17,8 @@ package com.google.devtools.moe.client.repositories; import com.google.devtools.moe.client.Ui; +import com.google.devtools.moe.client.config.MetadataScrubberConfig; + import javax.annotation.Nullable; import javax.inject.Inject; diff --git a/client/src/main/java/com/google/devtools/moe/client/repositories/PublicSectionMetadataScrubber.java b/client/src/main/java/com/google/devtools/moe/client/repositories/PublicSectionMetadataScrubber.java index b0e1f2cf..6c12a3e7 100644 --- a/client/src/main/java/com/google/devtools/moe/client/repositories/PublicSectionMetadataScrubber.java +++ b/client/src/main/java/com/google/devtools/moe/client/repositories/PublicSectionMetadataScrubber.java @@ -18,6 +18,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Splitter; +import com.google.devtools.moe.client.config.MetadataScrubberConfig; import java.util.List; import java.util.regex.Pattern; diff --git a/client/src/main/java/com/google/devtools/moe/client/repositories/Repositories.java b/client/src/main/java/com/google/devtools/moe/client/repositories/Repositories.java index f98e4924..e4532054 100644 --- a/client/src/main/java/com/google/devtools/moe/client/repositories/Repositories.java +++ b/client/src/main/java/com/google/devtools/moe/client/repositories/Repositories.java @@ -21,8 +21,8 @@ import com.google.common.collect.ImmutableMap; import com.google.devtools.moe.client.dvcs.git.GitRepositoryFactory; import com.google.devtools.moe.client.dvcs.hg.HgRepositoryFactory; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.noop.NoopRepositoryFactory; import com.google.devtools.moe.client.svn.SvnRepositoryFactory; import dagger.Binds; diff --git a/client/src/main/java/com/google/devtools/moe/client/repositories/RepositoryType.java b/client/src/main/java/com/google/devtools/moe/client/repositories/RepositoryType.java index 69bbab0f..54bc2cd5 100644 --- a/client/src/main/java/com/google/devtools/moe/client/repositories/RepositoryType.java +++ b/client/src/main/java/com/google/devtools/moe/client/repositories/RepositoryType.java @@ -18,8 +18,8 @@ import com.google.auto.value.AutoValue; import com.google.devtools.moe.client.codebase.CodebaseCreator; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.writer.WriterCreator; /** @@ -60,5 +60,22 @@ public interface Factory { */ // TODO(cgruber): Consider making this an abstract class with a template method for validation. RepositoryType create(String name, RepositoryConfig config) throws InvalidProject; + + + /** + * Validates that the supplied + * {@link com.google.devtools.moe.client.repositories.RepositoryType.Factory} targets the + * correct repo type, throwing an {@link InvalidProject} exception if it does not. + */ + default void checkType(RepositoryConfig config) throws InvalidProject { + if (!this.type().equals(config.getType())) { + // TODO(cgruber): Make it so this can't happen at runtime, ever, and throw AssertionError. + throw new InvalidProject( + "Invalid repository type '%s' for %s", + config.getType(), + this.getClass().getSimpleName()); + } + } + } } diff --git a/client/src/main/java/com/google/devtools/moe/client/repositories/noop/NoopRepositoryFactory.java b/client/src/main/java/com/google/devtools/moe/client/repositories/noop/NoopRepositoryFactory.java index 1cb9d6df..7129c10d 100644 --- a/client/src/main/java/com/google/devtools/moe/client/repositories/noop/NoopRepositoryFactory.java +++ b/client/src/main/java/com/google/devtools/moe/client/repositories/noop/NoopRepositoryFactory.java @@ -20,8 +20,8 @@ import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreationError; import com.google.devtools.moe.client.codebase.CodebaseCreator; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.RepositoryType; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.repositories.RevisionHistory; diff --git a/client/src/main/java/com/google/devtools/moe/client/svn/SvnCodebaseCreator.java b/client/src/main/java/com/google/devtools/moe/client/svn/SvnCodebaseCreator.java index c6e238d3..d7b4c2db 100644 --- a/client/src/main/java/com/google/devtools/moe/client/svn/SvnCodebaseCreator.java +++ b/client/src/main/java/com/google/devtools/moe/client/svn/SvnCodebaseCreator.java @@ -25,7 +25,7 @@ import com.google.devtools.moe.client.codebase.CodebaseCreationError; import com.google.devtools.moe.client.codebase.CodebaseCreator; import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.Revision; import java.io.File; import java.util.Map; diff --git a/client/src/main/java/com/google/devtools/moe/client/svn/SvnRepositoryFactory.java b/client/src/main/java/com/google/devtools/moe/client/svn/SvnRepositoryFactory.java index e3dd9859..8c6d4484 100644 --- a/client/src/main/java/com/google/devtools/moe/client/svn/SvnRepositoryFactory.java +++ b/client/src/main/java/com/google/devtools/moe/client/svn/SvnRepositoryFactory.java @@ -20,8 +20,8 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.RepositoryType; import javax.inject.Inject; @@ -49,7 +49,7 @@ public String type() { @Override public RepositoryType create(String name, RepositoryConfig config) throws InvalidProject { - config.checkType(this); + checkType(config); String url = config.getUrl(); if (isNullOrEmpty(url)) { diff --git a/client/src/main/java/com/google/devtools/moe/client/svn/SvnWriter.java b/client/src/main/java/com/google/devtools/moe/client/svn/SvnWriter.java index 3d410ba8..0ebc7be4 100644 --- a/client/src/main/java/com/google/devtools/moe/client/svn/SvnWriter.java +++ b/client/src/main/java/com/google/devtools/moe/client/svn/SvnWriter.java @@ -24,7 +24,7 @@ import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.Utils; import com.google.devtools.moe.client.codebase.Codebase; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.repositories.RevisionMetadata; import com.google.devtools.moe.client.writer.DraftRevision; @@ -88,7 +88,7 @@ private DraftRevision putCodebase(Codebase c) { .build(); Set codebaseFiles = - Utils.makeFilenamesRelative(filesystem.findFiles(c.path()), c.path()); + Utils.makeFilenamesRelative(filesystem.findFiles(c.root()), c.root()); Set writerFiles = Utils.filterByRegEx( Utils.makeFilenamesRelative(filesystem.findFiles(rootDirectory), rootDirectory), diff --git a/client/src/main/java/com/google/devtools/moe/client/svn/SvnWriterCreator.java b/client/src/main/java/com/google/devtools/moe/client/svn/SvnWriterCreator.java index 701f3fe5..d989ce9a 100644 --- a/client/src/main/java/com/google/devtools/moe/client/svn/SvnWriterCreator.java +++ b/client/src/main/java/com/google/devtools/moe/client/svn/SvnWriterCreator.java @@ -20,7 +20,7 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.Utils; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.writer.Writer; import com.google.devtools.moe.client.writer.WriterCreator; diff --git a/client/src/main/java/com/google/devtools/moe/client/testing/DummyRepositoryFactory.java b/client/src/main/java/com/google/devtools/moe/client/testing/DummyRepositoryFactory.java index 9444f392..8799a1ba 100644 --- a/client/src/main/java/com/google/devtools/moe/client/testing/DummyRepositoryFactory.java +++ b/client/src/main/java/com/google/devtools/moe/client/testing/DummyRepositoryFactory.java @@ -18,7 +18,7 @@ import com.google.common.collect.ImmutableList; import com.google.devtools.moe.client.codebase.CodebaseCreator; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.RepositoryType; import com.google.devtools.moe.client.repositories.RevisionHistory; import com.google.devtools.moe.client.writer.WriterCreator; diff --git a/client/src/main/java/com/google/devtools/moe/client/testing/InMemoryProjectContextFactory.java b/client/src/main/java/com/google/devtools/moe/client/testing/InMemoryProjectContextFactory.java index 793a173c..527e9510 100644 --- a/client/src/main/java/com/google/devtools/moe/client/testing/InMemoryProjectContextFactory.java +++ b/client/src/main/java/com/google/devtools/moe/client/testing/InMemoryProjectContextFactory.java @@ -16,13 +16,13 @@ package com.google.devtools.moe.client.testing; -import static com.google.devtools.moe.client.project.ProjectConfig.parse; +import static com.google.devtools.moe.client.project.ProjectConfigs.parse; import com.google.common.annotations.VisibleForTesting; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.ExpressionEngine; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.ProjectConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.ProjectConfig; import com.google.devtools.moe.client.project.ProjectContextFactory; import com.google.devtools.moe.client.repositories.Repositories; import com.google.devtools.moe.client.translation.editors.Editors; diff --git a/client/src/main/java/com/google/devtools/moe/client/tools/CodebaseDiffer.java b/client/src/main/java/com/google/devtools/moe/client/tools/CodebaseDiffer.java index 021287d7..a6373759 100644 --- a/client/src/main/java/com/google/devtools/moe/client/tools/CodebaseDiffer.java +++ b/client/src/main/java/com/google/devtools/moe/client/tools/CodebaseDiffer.java @@ -41,8 +41,8 @@ public CodebaseDiffer(FileDiffer differ, FileSystem filesystem) { public CodebaseDifference diffCodebases(Codebase codebase1, Codebase codebase2) { Set filenames = Sets.union( - Utils.makeFilenamesRelative(filesystem.findFiles(codebase1.path()), codebase1.path()), - Utils.makeFilenamesRelative(filesystem.findFiles(codebase2.path()), codebase2.path())); + Utils.makeFilenamesRelative(filesystem.findFiles(codebase1.root()), codebase1.root()), + Utils.makeFilenamesRelative(filesystem.findFiles(codebase2.root()), codebase2.root())); ImmutableSet.Builder fileDiffs = ImmutableSet.builder(); diff --git a/client/src/main/java/com/google/devtools/moe/client/translation/editors/Editor.java b/client/src/main/java/com/google/devtools/moe/client/translation/editors/Editor.java index 83250f51..a8666312 100644 --- a/client/src/main/java/com/google/devtools/moe/client/translation/editors/Editor.java +++ b/client/src/main/java/com/google/devtools/moe/client/translation/editors/Editor.java @@ -17,7 +17,7 @@ package com.google.devtools.moe.client.translation.editors; import com.google.devtools.moe.client.codebase.Codebase; -import com.google.devtools.moe.client.project.EditorConfig; +import com.google.devtools.moe.client.config.EditorConfig; import java.util.Map; /** @@ -48,16 +48,4 @@ public interface Factory { Editor newEditor(String name, EditorConfig config); } - /** - * Enum of all known editor implementations. - * - * All values are valid JSON editor types. - */ - public enum Type { - identity, - scrubber, - patcher, - shell, - renamer; - } } diff --git a/client/src/main/java/com/google/devtools/moe/client/translation/editors/Editors.java b/client/src/main/java/com/google/devtools/moe/client/translation/editors/Editors.java index 693a12a4..1c443c9e 100644 --- a/client/src/main/java/com/google/devtools/moe/client/translation/editors/Editors.java +++ b/client/src/main/java/com/google/devtools/moe/client/translation/editors/Editors.java @@ -16,16 +16,17 @@ package com.google.devtools.moe.client.translation.editors; -import static com.google.devtools.moe.client.translation.editors.Editor.Type.identity; -import static com.google.devtools.moe.client.translation.editors.Editor.Type.patcher; -import static com.google.devtools.moe.client.translation.editors.Editor.Type.renamer; -import static com.google.devtools.moe.client.translation.editors.Editor.Type.scrubber; -import static com.google.devtools.moe.client.translation.editors.Editor.Type.shell; +import static com.google.devtools.moe.client.config.EditorType.identity; +import static com.google.devtools.moe.client.config.EditorType.patcher; +import static com.google.devtools.moe.client.config.EditorType.renamer; +import static com.google.devtools.moe.client.config.EditorType.scrubber; +import static com.google.devtools.moe.client.config.EditorType.shell; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; -import com.google.devtools.moe.client.project.EditorConfig; -import com.google.devtools.moe.client.project.InvalidProject; +import com.google.devtools.moe.client.config.EditorType; +import com.google.devtools.moe.client.config.EditorConfig; +import com.google.devtools.moe.client.InvalidProject; import dagger.Binds; import dagger.MapKey; import dagger.multibindings.IntoMap; @@ -38,10 +39,10 @@ */ public class Editors { - private final ImmutableMap editorFactories; + private final ImmutableMap editorFactories; @Inject - Editors(Map editorFactories) { + Editors(Map editorFactories) { this.editorFactories = ImmutableMap.copyOf(editorFactories); } @@ -66,7 +67,7 @@ public InverseEditor makeInverseEditorFromConfig(String name, EditorConfig origi */ @MapKey @interface EditorKey { - Editor.Type value(); + EditorType value(); } /** The default editor types available for moe configuration, arranged as a Map. */ diff --git a/client/src/main/java/com/google/devtools/moe/client/translation/editors/IdentityEditor.java b/client/src/main/java/com/google/devtools/moe/client/translation/editors/IdentityEditor.java index 2f6a3c9b..c95e9f23 100644 --- a/client/src/main/java/com/google/devtools/moe/client/translation/editors/IdentityEditor.java +++ b/client/src/main/java/com/google/devtools/moe/client/translation/editors/IdentityEditor.java @@ -18,8 +18,8 @@ import com.google.auto.factory.AutoFactory; import com.google.devtools.moe.client.codebase.Codebase; -import com.google.devtools.moe.client.project.EditorConfig; -import com.google.devtools.moe.client.project.InvalidProject; +import com.google.devtools.moe.client.config.EditorConfig; +import com.google.devtools.moe.client.InvalidProject; import java.util.Map; /** An IdentityEditor returns the same Codebase. */ diff --git a/client/src/main/java/com/google/devtools/moe/client/translation/editors/InverseEditor.java b/client/src/main/java/com/google/devtools/moe/client/translation/editors/InverseEditor.java index 332b60d8..b0293593 100644 --- a/client/src/main/java/com/google/devtools/moe/client/translation/editors/InverseEditor.java +++ b/client/src/main/java/com/google/devtools/moe/client/translation/editors/InverseEditor.java @@ -16,7 +16,7 @@ package com.google.devtools.moe.client.translation.editors; import com.google.devtools.moe.client.codebase.Codebase; -import com.google.devtools.moe.client.project.InvalidProject; +import com.google.devtools.moe.client.InvalidProject; import java.util.Map; /** diff --git a/client/src/main/java/com/google/devtools/moe/client/translation/editors/PatchingEditor.java b/client/src/main/java/com/google/devtools/moe/client/translation/editors/PatchingEditor.java index 64c91843..2d1f3b1f 100644 --- a/client/src/main/java/com/google/devtools/moe/client/translation/editors/PatchingEditor.java +++ b/client/src/main/java/com/google/devtools/moe/client/translation/editors/PatchingEditor.java @@ -25,7 +25,7 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.codebase.Codebase; -import com.google.devtools.moe.client.project.EditorConfig; +import com.google.devtools.moe.client.config.EditorConfig; import java.io.File; import java.io.IOException; import java.util.Map; @@ -72,9 +72,9 @@ public Codebase edit(Codebase input, Map options) { throw new MoeProblem("cannot read file %s", patchFilePath); } try { - filesystem.copyDirectory(input.path(), tempDir); + filesystem.copyDirectory(input.root(), tempDir); } catch (IOException e) { - throw new MoeProblem(e, "Failed to copy directory %s to %s", input.path(), tempDir); + throw new MoeProblem(e, "Failed to copy directory %s to %s", input.root(), tempDir); } try { cmd.runCommand( diff --git a/client/src/main/java/com/google/devtools/moe/client/translation/editors/RenamingEditor.java b/client/src/main/java/com/google/devtools/moe/client/translation/editors/RenamingEditor.java index 9485ea4e..2f449fa4 100644 --- a/client/src/main/java/com/google/devtools/moe/client/translation/editors/RenamingEditor.java +++ b/client/src/main/java/com/google/devtools/moe/client/translation/editors/RenamingEditor.java @@ -29,8 +29,8 @@ import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.Utils; import com.google.devtools.moe.client.codebase.Codebase; -import com.google.devtools.moe.client.project.EditorConfig; -import com.google.devtools.moe.client.project.InvalidProject; +import com.google.devtools.moe.client.config.EditorConfig; +import com.google.devtools.moe.client.InvalidProject; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.File; @@ -159,11 +159,11 @@ public Codebase edit(Codebase input, Map options) { File tempDir = filesystem.getTemporaryDirectory("rename_run_"); try { copyDirectoryAndRename( - input.path().getAbsoluteFile(), - input.path().getAbsoluteFile(), + input.root().getAbsoluteFile(), + input.root().getAbsoluteFile(), tempDir.getAbsoluteFile()); } catch (IOException e) { - throw new MoeProblem(e, "Failed to copy %s to %s", input.path(), tempDir); + throw new MoeProblem(e, "Failed to copy %s to %s", input.root(), tempDir); } return Codebase.create(tempDir, input.projectSpace(), input.expression()); } @@ -178,14 +178,14 @@ public Codebase inverseEdit( private void inverseRenameAndCopy(Codebase input, File destination, Codebase reference) { Set renamedFilenames = - Utils.makeFilenamesRelative(filesystem.findFiles(input.path()), input.path()); + Utils.makeFilenamesRelative(filesystem.findFiles(input.root()), input.root()); Map renamedToReferenceMap = makeRenamedToReferenceMap( - Utils.makeFilenamesRelative(filesystem.findFiles(reference.path()), reference.path())); + Utils.makeFilenamesRelative(filesystem.findFiles(reference.root()), reference.root())); for (String renamedFilename : renamedFilenames) { String inverseRenamedFilename = inverseRename(renamedFilename, renamedToReferenceMap); - copyFile(renamedFilename, inverseRenamedFilename, input.path(), destination); + copyFile(renamedFilename, inverseRenamedFilename, input.root(), destination); } } diff --git a/client/src/main/java/com/google/devtools/moe/client/translation/editors/ScrubbingEditor.java b/client/src/main/java/com/google/devtools/moe/client/translation/editors/ScrubbingEditor.java index 369488eb..bf049b37 100644 --- a/client/src/main/java/com/google/devtools/moe/client/translation/editors/ScrubbingEditor.java +++ b/client/src/main/java/com/google/devtools/moe/client/translation/editors/ScrubbingEditor.java @@ -24,9 +24,9 @@ import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseMerger; -import com.google.devtools.moe.client.project.EditorConfig; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.ScrubberConfig; +import com.google.devtools.moe.client.config.EditorConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.ScrubberConfig; import com.google.devtools.moe.client.tools.TarUtils; import com.google.gson.Gson; import dagger.Lazy; @@ -99,7 +99,7 @@ public Codebase edit(Codebase input, Map options) { // TODO(dbentley): allow configuring the scrubber config "--config_data", (scrubberConfig == null) ? "{}" : gson.toJson(scrubberConfig), - input.path().getAbsolutePath())); + input.root().getAbsolutePath())); } catch (CommandRunner.CommandException | IOException e) { throw new MoeProblem(e, "Problem executing the scrubber: %s", e.getMessage()); } diff --git a/client/src/main/java/com/google/devtools/moe/client/translation/editors/ShellEditor.java b/client/src/main/java/com/google/devtools/moe/client/translation/editors/ShellEditor.java index e23a6de0..743ab112 100644 --- a/client/src/main/java/com/google/devtools/moe/client/translation/editors/ShellEditor.java +++ b/client/src/main/java/com/google/devtools/moe/client/translation/editors/ShellEditor.java @@ -23,7 +23,7 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.codebase.Codebase; -import com.google.devtools.moe.client.project.EditorConfig; +import com.google.devtools.moe.client.config.EditorConfig; import java.io.File; import java.io.IOException; import java.util.Map; @@ -72,9 +72,9 @@ public String getDescription() { public Codebase edit(Codebase input, Map options) { File tempDir = filesystem.getTemporaryDirectory("shell_run_"); try { - filesystem.copyDirectory(input.path(), tempDir); + filesystem.copyDirectory(input.root(), tempDir); } catch (IOException e) { - throw new MoeProblem(e, "Failed to copy directory %s to %s", input.path(), tempDir); + throw new MoeProblem(e, "Failed to copy directory %s to %s", input.root(), tempDir); } try { cmd.runCommand(tempDir.getAbsolutePath(), "bash", ImmutableList.of("-c", this.commandString)); diff --git a/client/src/test/java/com/google/devtools/moe/client/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/BUILD.bazel new file mode 100644 index 00000000..2eac1fb9 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/BUILD.bazel @@ -0,0 +1,68 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "AbstractFileSystemTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +java_library( + name = "testlib", + srcs = ["NullFileSystemModule.java"], + deps = [ + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/dagger", + "@maven//com/google/code/findbugs:jsr305", + ], +) + +jvm_unit_test( + name = "SystemCommandRunnerTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "SystemFileSystemTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/dagger", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//javax/inject:javax_inject", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "TaskTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "UtilsTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/codebase/BUILD.bazel new file mode 100644 index 00000000..f3b5d114 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/codebase/BUILD.bazel @@ -0,0 +1,43 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "CodebaseMergerTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/mockito:mockito-core", + "@maven//org/objenesis", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "CodebaseTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "@maven//com/google/dagger", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "ExpressionProcessingTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "//client/src/test/java/com/google/devtools/moe/client/testing", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/objenesis", + "@maven//javax/inject:javax_inject", + "@maven//junit", + ], +) \ No newline at end of file diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java b/client/src/test/java/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java index 64512fcd..e7117f8e 100644 --- a/client/src/test/java/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java @@ -88,7 +88,7 @@ public class CodebaseMergerTest { @Before public void setUp() { - when(merged.path()).thenReturn(mergedCodebaseLocation); + when(merged.root()).thenReturn(mergedCodebaseLocation); when(merged.getFile("foo")).thenReturn(new File(mergedCodebaseLocation, "foo")); when(fileSystem.getTemporaryDirectory("merged_codebase_")).thenReturn(mergedCodebaseLocation); @@ -316,9 +316,9 @@ public void testGenerateMergedFileNoOrigConflict() throws Exception { public void testMerge() throws Exception { Ui ui = mock(Ui.class); - when(orig.path()).thenReturn(new File("orig")); - when(dest.path()).thenReturn(new File("dest")); - when(mod.path()).thenReturn(new File("mod")); + when(orig.root()).thenReturn(new File("orig")); + when(dest.root()).thenReturn(new File("dest")); + when(mod.root()).thenReturn(new File("mod")); when(fileSystem.exists(origFile)).thenReturn(true); when(fileSystem.exists(destFile)).thenReturn(true); when(fileSystem.exists(modFile)).thenReturn(true); diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/ExpressionProcessingTest.java b/client/src/test/java/com/google/devtools/moe/client/codebase/ExpressionProcessingTest.java deleted file mode 100644 index f17b639e..00000000 --- a/client/src/test/java/com/google/devtools/moe/client/codebase/ExpressionProcessingTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2011 Google, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.devtools.moe.client.codebase; - -import static com.google.common.truth.Truth.assertThat; -import static org.easymock.EasyMock.expect; -import static org.junit.Assert.assertThrows; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.FileSystem; -import com.google.devtools.moe.client.FileSystem.Lifetime; -import com.google.devtools.moe.client.MoeProblem; -import com.google.devtools.moe.client.NoopFileSystem; -import com.google.devtools.moe.client.SystemCommandRunner; -import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.codebase.expressions.EditExpression; -import com.google.devtools.moe.client.codebase.expressions.Expression; -import com.google.devtools.moe.client.codebase.expressions.Parser; -import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; -import com.google.devtools.moe.client.codebase.expressions.TranslateExpression; -import com.google.devtools.moe.client.project.ProjectContext; -import com.google.devtools.moe.client.project.ProjectContext.NoopProjectContext; -import com.google.devtools.moe.client.repositories.RepositoryType; -import com.google.devtools.moe.client.repositories.RevisionHistory; -import com.google.devtools.moe.client.testing.TestingUtils; -import com.google.devtools.moe.client.translation.editors.Editor; -import com.google.devtools.moe.client.translation.pipeline.ForwardTranslationPipeline; -import com.google.devtools.moe.client.translation.pipeline.TranslationPath; -import com.google.devtools.moe.client.translation.pipeline.TranslationPipeline; -import com.google.devtools.moe.client.translation.pipeline.TranslationStep; -import com.google.devtools.moe.client.writer.WriterCreator; -import java.io.File; -import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; - -public class ExpressionProcessingTest extends TestCase { - private final IMocksControl control = EasyMock.createControl(); - private final Codebase mockRepoCodebase = control.createMock(Codebase.class); - private final FileSystem mockFs = control.createMock(FileSystem.class); - - private final Ui ui = new Ui(System.err); - private final CommandRunner commandRunner = new SystemCommandRunner(); - private final FileSystem noopFs = new NoopFileSystem(); - - public void testNoSuchRepository() throws Exception { - RepositoryExpression repositoryExpression = new RepositoryExpression("foo"); - RepositoryCodebaseProcessor repositoryCodebaseProcessor = - new RepositoryCodebaseProcessor(ui, () -> null); - MoeProblem err = - assertThrows( - MoeProblem.class, - () -> - repositoryCodebaseProcessor.createCodebase( - repositoryExpression, new NoopProjectContext())); - assertThat(err).hasMessageThat().contains("No such repository 'foo' in the config. Found: []"); - } - - public void testFileCodebaseCreator() throws Exception { - Ui ui = new Ui(System.err, mockFs); - ExpressionEngine expressionEngine = - TestingUtils.expressionEngineWithRepo(ui, mockFs, commandRunner); - File srcLocation = new File("/foo"); - expect(mockFs.exists(srcLocation)).andReturn(true); - expect(mockFs.isDirectory(srcLocation)).andReturn(true); - File copyLocation = new File("/tmp/copy"); - expect(mockFs.getTemporaryDirectory("file_codebase_copy_")).andReturn(copyLocation); - // Short-circuit Utils.copyDirectory(). - mockFs.copyDirectory(srcLocation, copyLocation); - mockFs.setLifetime(EasyMock.eq(copyLocation), EasyMock.anyObject()); - mockFs.cleanUpTempDirs(); - - RepositoryExpression repoEx = new RepositoryExpression("file").withOption("path", "/foo"); - - control.replay(); - Codebase c = expressionEngine.createCodebase(repoEx, new NoopProjectContext()); - control.verify(); - - assertThat(c.path()).isEqualTo(copyLocation); - assertThat(c.projectSpace()).isEqualTo("public"); - assertThat(c.expression()).isEqualTo(repoEx); - } - - public void testNoSuchEditor() throws Exception { - ProjectContext context = new NoopProjectContext(); - RepositoryExpression repoExpression = new RepositoryExpression("testrepo"); - ExpressionEngine expressionEngine = control.createMock(ExpressionEngine.class); - expect(expressionEngine.createCodebase(repoExpression, context)).andReturn(mockRepoCodebase); - EditedCodebaseProcessor processor = new EditedCodebaseProcessor(ui, expressionEngine); - - EditExpression editExpression = repoExpression.editWith("noSuchEditor", ImmutableMap.of()); - - control.replay(); - - CodebaseCreationError error = - assertThrows( - CodebaseCreationError.class, () -> processor.createCodebase(editExpression, context)); - assertThat(error).hasMessageThat().contains("no editor noSuchEditor"); - } - - public void testNoSuchTranslator() throws Exception { - final TranslationPath translationPath = TranslationPath.create("foo", "bar"); - final TranslationPipeline pipeline = - new ForwardTranslationPipeline( - ui, ImmutableList.of(new TranslationStep("quux", null))); - ProjectContext context = - new NoopProjectContext() { - @Override - public ImmutableMap translators() { - return ImmutableMap.of(translationPath, pipeline); - } - }; - - ExpressionEngine expressionEngine = control.createMock(ExpressionEngine.class); - RepositoryExpression repositoryExpression = new RepositoryExpression("testrepo"); - expect(expressionEngine.createCodebase(repositoryExpression, context)) - .andReturn(mockRepoCodebase); - expect(mockRepoCodebase.projectSpace()).andReturn("internal").times(2); - TranslatedCodebaseProcessor processor = new TranslatedCodebaseProcessor(ui, expressionEngine); - - TranslateExpression translateExpression = repositoryExpression.translateTo("public"); - - control.replay(); - CodebaseCreationError error = - assertThrows( - CodebaseCreationError.class, - () -> processor.createCodebase(translateExpression, context)); - - assertThat(error) - .hasMessageThat() - .contains("Could not find translator from project space \"internal\" to \"public\""); - assertThat(error).hasMessageThat().contains("Translators only available for [foo>bar]"); - } - - public void testParseAndEvaluate() throws Exception { - final RevisionHistory rh = control.createMock(RevisionHistory.class); - final CodebaseCreator cc = control.createMock(CodebaseCreator.class); - final WriterCreator wc = control.createMock(WriterCreator.class); - final Editor e = control.createMock(Editor.class); - Editor translatorEditor = control.createMock(Editor.class); - - File firstDir = new File("/first"); - File secondDir = new File("/second"); - File finalDir = new File("/final"); - - final TranslationPath tPath = TranslationPath.create("foo", "public"); - final TranslationPipeline t = - new ForwardTranslationPipeline( - ui, ImmutableList.of(new TranslationStep("quux", translatorEditor))); - - ProjectContext context = - new NoopProjectContext() { - @Override - public ImmutableMap repositories() { - return ImmutableMap.of("foo", RepositoryType.create("foo", rh, cc, wc)); - } - - @Override - public ImmutableMap translators() { - return ImmutableMap.of(tPath, t); - } - - @Override - public ImmutableMap editors() { - return ImmutableMap.of("bar", e); - } - }; - - Codebase firstCb = Codebase.create(firstDir, "foo", new RepositoryExpression("foo")); - - Codebase secondCb = Codebase.create(secondDir, "public", new RepositoryExpression("foo2")); - - Codebase finalCb = Codebase.create(finalDir, "public", new RepositoryExpression("foo3")); - - expect(cc.create(ImmutableMap.of())).andReturn(firstCb); - expect(translatorEditor.edit(firstCb, ImmutableMap.of())).andReturn(secondCb); - expect(e.getDescription()).andReturn(""); - expect(e.edit(secondCb, ImmutableMap.of())).andReturn(finalCb); - - control.replay(); - Expression expression = Parser.parseExpression("foo>public|bar"); - ExpressionEngine expressionEngine = - TestingUtils.expressionEngineWithRepo(ui, noopFs, commandRunner); - Codebase c = expressionEngine.createCodebase(expression, context); - - control.verify(); - assertThat(c.path()).isEqualTo(finalDir); - assertThat(c.projectSpace()).isEqualTo("public"); - assertThat(c.expression().toString()).isEqualTo("foo>public|bar"); - } -} diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/ExpressionProcessingTest.kt b/client/src/test/java/com/google/devtools/moe/client/codebase/ExpressionProcessingTest.kt new file mode 100644 index 00000000..bd3ada69 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/codebase/ExpressionProcessingTest.kt @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2011 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.devtools.moe.client.codebase + +import com.google.common.truth.Truth.assertThat +import org.easymock.EasyMock.expect +import org.junit.Assert.assertThrows + +import com.google.common.collect.ImmutableList +import com.google.common.collect.ImmutableMap +import com.google.devtools.moe.client.FileSystem +import com.google.devtools.moe.client.MoeProblem +import com.google.devtools.moe.client.NoopFileSystem +import com.google.devtools.moe.client.SystemCommandRunner +import com.google.devtools.moe.client.Ui +import com.google.devtools.moe.client.codebase.expressions.Parser +import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression +import com.google.devtools.moe.client.project.ProjectContext.NoopProjectContext +import com.google.devtools.moe.client.repositories.RepositoryType +import com.google.devtools.moe.client.repositories.RevisionHistory +import com.google.devtools.moe.client.testing.TestingUtils +import com.google.devtools.moe.client.translation.editors.Editor +import com.google.devtools.moe.client.translation.pipeline.ForwardTranslationPipeline +import com.google.devtools.moe.client.translation.pipeline.TranslationPath +import com.google.devtools.moe.client.translation.pipeline.TranslationPipeline +import com.google.devtools.moe.client.translation.pipeline.TranslationStep +import com.google.devtools.moe.client.writer.WriterCreator +import java.io.File +import junit.framework.TestCase +import org.easymock.EasyMock + +class ExpressionProcessingTest : TestCase() { + private val control = EasyMock.createControl() + private val mockRepoCodebase = control.createMock(Codebase::class.java) + private val mockFs = control.createMock(FileSystem::class.java) + + private val ui = Ui(System.err) + private val commandRunner = SystemCommandRunner() + private val noopFs = NoopFileSystem() + + @Throws(Exception::class) + fun testNoSuchRepository() { + val repositoryExpression = RepositoryExpression("foo") + val repositoryCodebaseProcessor = RepositoryCodebaseProcessor(ui) { null } + val err = assertThrows( + MoeProblem::class.java + ) { + repositoryCodebaseProcessor.createCodebase( + repositoryExpression, NoopProjectContext()) + } + assertThat(err).hasMessageThat().contains("No such repository 'foo' in the config. Found: []") + } + + @Throws(Exception::class) + fun testFileCodebaseCreator() { + val ui = Ui(System.err, mockFs) + val expressionEngine = TestingUtils.expressionEngineWithRepo(ui, mockFs, commandRunner) + val srcLocation = File("/foo") + expect(mockFs.exists(srcLocation)).andReturn(true) + expect(mockFs.isDirectory(srcLocation)).andReturn(true) + val copyLocation = File("/tmp/copy") + expect(mockFs.getTemporaryDirectory("file_codebase_copy_")).andReturn(copyLocation) + // Short-circuit Utils.copyDirectory(). + mockFs.copyDirectory(srcLocation, copyLocation) + mockFs.setLifetime(EasyMock.eq(copyLocation), EasyMock.anyObject()) + mockFs.cleanUpTempDirs() + + val repoEx = RepositoryExpression("file").withOption("path", "/foo") + + control.replay() + val c = expressionEngine.createCodebase(repoEx, NoopProjectContext()) + control.verify() + + assertThat(c.root()).isEqualTo(copyLocation) + assertThat(c.projectSpace()).isEqualTo("public") + assertThat(c.expression()).isEqualTo(repoEx) + } + + @Throws(Exception::class) + fun testNoSuchEditor() { + val context = NoopProjectContext() + val repoExpression = RepositoryExpression("testrepo") + val expressionEngine = control.createMock(ExpressionEngine::class.java) + expect(expressionEngine.createCodebase(repoExpression, context)).andReturn(mockRepoCodebase) + val processor = EditedCodebaseProcessor(ui, expressionEngine) + + val editExpression = repoExpression.editWith("noSuchEditor", ImmutableMap.of()) + + control.replay() + + val error = assertThrows( + CodebaseCreationError::class.java) { processor.createCodebase(editExpression, context) } + assertThat(error).hasMessageThat().contains("no editor noSuchEditor") + } + + @Throws(Exception::class) + fun testNoSuchTranslator() { + val translationPath = TranslationPath.create("foo", "bar") + val pipeline = ForwardTranslationPipeline( + ui, ImmutableList.of(TranslationStep("quux", null))) + val context = object : NoopProjectContext() { + override fun translators(): ImmutableMap { + return ImmutableMap.of(translationPath, pipeline) + } + } + + val expressionEngine = control.createMock(ExpressionEngine::class.java) + val repositoryExpression = RepositoryExpression("testrepo") + expect(expressionEngine.createCodebase(repositoryExpression, context)) + .andReturn(mockRepoCodebase) + expect(mockRepoCodebase.projectSpace()).andReturn("internal").times(2) + val processor = TranslatedCodebaseProcessor(ui, expressionEngine) + + val translateExpression = repositoryExpression.translateTo("public") + + control.replay() + val error = assertThrows( + CodebaseCreationError::class.java + ) { processor.createCodebase(translateExpression, context) } + + assertThat(error) + .hasMessageThat() + .contains("Could not find translator from project space \"internal\" to \"public\"") + assertThat(error).hasMessageThat().contains("Translators only available for [foo>bar]") + } + + @Throws(Exception::class) + fun testParseAndEvaluate() { + val rh = control.createMock(RevisionHistory::class.java) + val cc = control.createMock(CodebaseCreator::class.java) + val wc = control.createMock(WriterCreator::class.java) + val e = control.createMock(Editor::class.java) + val translatorEditor = control.createMock(Editor::class.java) + + val firstDir = File("/first") + val secondDir = File("/second") + val finalDir = File("/final") + + val tPath = TranslationPath.create("foo", "public") + val t = ForwardTranslationPipeline( + ui, ImmutableList.of(TranslationStep("quux", translatorEditor))) + + val context = object : NoopProjectContext() { + override fun repositories(): ImmutableMap { + return ImmutableMap.of("foo", RepositoryType.create("foo", rh, cc, wc)) + } + + override fun translators(): ImmutableMap { + return ImmutableMap.of(tPath, t) + } + + override fun editors(): ImmutableMap { + return ImmutableMap.of("bar", e) + } + } + + val firstCb = Codebase.create(firstDir, "foo", RepositoryExpression("foo")) + + val secondCb = Codebase.create(secondDir, "public", RepositoryExpression("foo2")) + + val finalCb = Codebase.create(finalDir, "public", RepositoryExpression("foo3")) + + expect(cc.create(ImmutableMap.of())).andReturn(firstCb) + expect(translatorEditor.edit(firstCb, ImmutableMap.of())).andReturn(secondCb) + expect(e.description).andReturn("") + expect(e.edit(secondCb, ImmutableMap.of())).andReturn(finalCb) + + control.replay() + val expression = Parser.parseExpression("foo>public|bar") + val expressionEngine = TestingUtils.expressionEngineWithRepo(ui, noopFs, commandRunner) + val c = expressionEngine.createCodebase(expression, context) + + control.verify() + assertThat(c.root()).isEqualTo(finalDir) + assertThat(c.projectSpace()).isEqualTo("public") + assertThat(c.expression().toString()).isEqualTo("foo>public|bar") + } +} diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/BUILD.bazel new file mode 100644 index 00000000..9dfb7e04 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/BUILD.bazel @@ -0,0 +1,38 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "ParserTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "RepositoryExpressionTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "//client/src/main/java/com/google/devtools/moe/client/qualifiers", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "@maven//com/google/dagger", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//javax/inject:javax_inject", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "TermTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + diff --git a/client/src/test/java/com/google/devtools/moe/client/database/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/database/BUILD.bazel new file mode 100644 index 00000000..0a9c576c --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/database/BUILD.bazel @@ -0,0 +1,39 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "FileDbTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//cglib:cglib-nodep", + "@maven//com/google/code/gson", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/mockito:mockito-core", + "@maven//org/objenesis", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "RepositoryEquivalenceMatcherTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//joda-time", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "RepositoryEquivalenceTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//com/google/truth", + "@maven//junit", + ], +) \ No newline at end of file diff --git a/client/src/test/java/com/google/devtools/moe/client/database/FileDbTest.java b/client/src/test/java/com/google/devtools/moe/client/database/FileDbTest.java index dad0ad4e..b24185b5 100644 --- a/client/src/test/java/com/google/devtools/moe/client/database/FileDbTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/database/FileDbTest.java @@ -26,8 +26,8 @@ import com.google.common.collect.Iterables; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.SystemFileSystem; -import com.google.devtools.moe.client.gson.GsonModule; -import com.google.devtools.moe.client.project.InvalidProject; +import com.google.devtools.moe.client.GsonModule; +import com.google.devtools.moe.client.InvalidProject; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.testing.DummyDb; import com.google.gson.Gson; diff --git a/client/src/test/java/com/google/devtools/moe/client/database/RepositoryEquivalenceMatcherTest.java b/client/src/test/java/com/google/devtools/moe/client/database/RepositoryEquivalenceMatcherTest.java index ebea9cd0..adea9073 100644 --- a/client/src/test/java/com/google/devtools/moe/client/database/RepositoryEquivalenceMatcherTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/database/RepositoryEquivalenceMatcherTest.java @@ -17,8 +17,8 @@ package com.google.devtools.moe.client.database; import com.google.common.collect.ImmutableList; -import com.google.devtools.moe.client.gson.GsonModule; -import com.google.devtools.moe.client.project.InvalidProject; +import com.google.devtools.moe.client.GsonModule; +import com.google.devtools.moe.client.InvalidProject; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.repositories.RevisionGraph; import com.google.devtools.moe.client.repositories.RevisionMetadata; diff --git a/client/src/test/java/com/google/devtools/moe/client/directives/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/directives/BUILD.bazel new file mode 100644 index 00000000..f170d050 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/directives/BUILD.bazel @@ -0,0 +1,136 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "BookkeepingDirectiveTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/test/java/com/google/devtools/moe/client/testing", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "ChangeDirectiveTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/test/java/com/google/devtools/moe/client/testing", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "CreateCodebaseDirectiveTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/test/java/com/google/devtools/moe/client/testing", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "DetermineMetadataDirectiveTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//joda-time", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "FindEquivalenceDirectiveTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "GithubPullDirectiveTest", + resources = [ + "//client/src/test/java/com/google/devtools/moe/client/github:resources", + ], + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//com/google/code/gson", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "HighestRevisionDirectiveTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "LastEquivalenceDirectiveTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "MigrateBranchDirectiveTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/truth", + "@maven//joda-time", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "NoteEquivalenceDirectiveTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/objenesis", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "OneMigrationDirectiveTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/test/java/com/google/devtools/moe/client/testing", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) diff --git a/client/src/test/java/com/google/devtools/moe/client/directives/BookkeepingDirectiveTest.java b/client/src/test/java/com/google/devtools/moe/client/directives/BookkeepingDirectiveTest.java index d6a5253f..a29a3a8e 100644 --- a/client/src/test/java/com/google/devtools/moe/client/directives/BookkeepingDirectiveTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/directives/BookkeepingDirectiveTest.java @@ -33,7 +33,7 @@ import com.google.devtools.moe.client.database.FileDb; import com.google.devtools.moe.client.database.RepositoryEquivalence; import com.google.devtools.moe.client.database.SubmittedMigration; -import com.google.devtools.moe.client.gson.GsonModule; +import com.google.devtools.moe.client.GsonModule; import com.google.devtools.moe.client.project.ProjectContext; import com.google.devtools.moe.client.repositories.Repositories; import com.google.devtools.moe.client.repositories.RepositoryType; diff --git a/client/src/test/java/com/google/devtools/moe/client/directives/GithubPullDirectiveTest.java b/client/src/test/java/com/google/devtools/moe/client/directives/GithubPullDirectiveTest.java index 5b13fc63..43f053c5 100644 --- a/client/src/test/java/com/google/devtools/moe/client/directives/GithubPullDirectiveTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/directives/GithubPullDirectiveTest.java @@ -26,8 +26,8 @@ import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.github.GithubAPI.PullRequest; import com.google.devtools.moe.client.github.PullRequestUrl; -import com.google.devtools.moe.client.gson.GsonModule; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.GsonModule; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.gson.Gson; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/client/src/test/java/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreatorTest.java b/client/src/test/java/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreatorTest.java index adca78c7..36c83623 100644 --- a/client/src/test/java/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreatorTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreatorTest.java @@ -25,7 +25,7 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.LocalWorkspace; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.repositories.RevisionHistory; import java.io.File; @@ -75,7 +75,7 @@ public void testCreate_noGivenRev() throws Exception { Codebase codebase = codebaseCreator.create(Collections.emptyMap()); - assertEquals(new File(archiveTempDir), codebase.path()); + assertEquals(new File(archiveTempDir), codebase.root()); assertEquals("public", codebase.projectSpace()); assertEquals("mockrepo", codebase.expression().toString()); @@ -96,7 +96,7 @@ public void testCreate_givenRev() throws Exception { Codebase codebase = codebaseCreator.create(ImmutableMap.of("revision", givenRev)); - assertEquals(new File(archiveTempDir), codebase.path()); + assertEquals(new File(archiveTempDir), codebase.root()); assertEquals("public", codebase.projectSpace()); assertEquals("mockrepo(revision=" + givenRev + ")", codebase.expression().toString()); diff --git a/client/src/test/java/com/google/devtools/moe/client/dvcs/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/dvcs/BUILD.bazel new file mode 100644 index 00000000..79c47f7e --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/dvcs/BUILD.bazel @@ -0,0 +1,28 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "AbstractDvcsCodebaseCreatorTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/objenesis", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "DvcsDraftRevisionTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//cglib:cglib-nodep", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/objenesis", + "@maven//junit", + ], +) \ No newline at end of file diff --git a/client/src/test/java/com/google/devtools/moe/client/dvcs/git/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/dvcs/git/BUILD.bazel new file mode 100644 index 00000000..956b2761 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/dvcs/git/BUILD.bazel @@ -0,0 +1,48 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "GitClonedRepositoryTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/objenesis", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "GitRevisionHistoryTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/objenesis", + "@maven//joda-time", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "GitWriterTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/objenesis", + "@maven//junit", + ], +) \ No newline at end of file diff --git a/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepositoryTest.java b/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepositoryTest.java index 2b2c8e32..a4b46156 100644 --- a/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepositoryTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepositoryTest.java @@ -25,7 +25,7 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import java.io.File; import java.util.List; import junit.framework.TestCase; diff --git a/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitRevisionHistoryTest.java b/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitRevisionHistoryTest.java index c1c01bf1..0939421a 100644 --- a/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitRevisionHistoryTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitRevisionHistoryTest.java @@ -31,8 +31,8 @@ import com.google.devtools.moe.client.database.RepositoryEquivalence; import com.google.devtools.moe.client.database.RepositoryEquivalenceMatcher; import com.google.devtools.moe.client.database.RepositoryEquivalenceMatcher.Result; -import com.google.devtools.moe.client.gson.GsonModule; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.GsonModule; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.repositories.RevisionHistory.SearchType; import com.google.devtools.moe.client.repositories.RevisionMetadata; diff --git a/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitWriterTest.java b/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitWriterTest.java index 544be22b..0b644b1b 100644 --- a/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitWriterTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/dvcs/git/GitWriterTest.java @@ -25,7 +25,7 @@ import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.writer.DraftRevision; import java.io.File; import junit.framework.TestCase; diff --git a/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/BUILD.bazel new file mode 100644 index 00000000..bcc3f015 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/BUILD.bazel @@ -0,0 +1,49 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "HgClonedRepositoryTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/objenesis", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "HgRevisionHistoryTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/objenesis", + "@maven//joda-time", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "HgWriterTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//org/easymock", + "@maven//org/objenesis", + "@maven//joda-time", + "@maven//junit", + ], +) \ No newline at end of file diff --git a/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepositoryTest.java b/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepositoryTest.java index 1c75f4d8..33d7ffa6 100644 --- a/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepositoryTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepositoryTest.java @@ -25,7 +25,7 @@ import com.google.devtools.moe.client.FileSystem.Lifetime; import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import java.io.File; import junit.framework.TestCase; import org.easymock.EasyMock; diff --git a/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistoryTest.java b/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistoryTest.java index d50f7501..f12bad67 100644 --- a/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistoryTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistoryTest.java @@ -29,8 +29,8 @@ import com.google.devtools.moe.client.database.RepositoryEquivalence; import com.google.devtools.moe.client.database.RepositoryEquivalenceMatcher; import com.google.devtools.moe.client.database.RepositoryEquivalenceMatcher.Result; -import com.google.devtools.moe.client.gson.GsonModule; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.GsonModule; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.repositories.RevisionHistory.SearchType; import com.google.devtools.moe.client.repositories.RevisionMetadata; diff --git a/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgWriterTest.java b/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgWriterTest.java index 70a3d67c..ca780d50 100644 --- a/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgWriterTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/dvcs/hg/HgWriterTest.java @@ -25,7 +25,7 @@ import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.RevisionMetadata; import com.google.devtools.moe.client.writer.DraftRevision; import java.io.File; diff --git a/client/src/test/java/com/google/devtools/moe/client/github/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/github/BUILD.bazel new file mode 100644 index 00000000..e77f60c4 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/github/BUILD.bazel @@ -0,0 +1,19 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +filegroup( + name = "resources", + srcs = ["pull_request.json"], + visibility = ["//client/src/test:__subpackages__"], +) + +jvm_unit_test( + name = "GithubClientTest", + resources = [":resources"], + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//com/google/code/gson", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) diff --git a/client/src/test/java/com/google/devtools/moe/client/github/GithubClientTest.java b/client/src/test/java/com/google/devtools/moe/client/github/GithubClientTest.java index ea16dbbd..5049c4d4 100644 --- a/client/src/test/java/com/google/devtools/moe/client/github/GithubClientTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/github/GithubClientTest.java @@ -17,7 +17,7 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.devtools.moe.client.gson.MoeTypeAdapterFactory; +import com.google.devtools.moe.client.MoeTypeAdapterFactory; import com.google.common.io.Resources; import com.google.devtools.moe.client.github.GithubAPI.IssueState; import com.google.devtools.moe.client.github.GithubAPI.PullRequest; diff --git a/client/src/test/java/com/google/devtools/moe/client/options/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/options/BUILD.bazel new file mode 100644 index 00000000..f58dcb26 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/options/BUILD.bazel @@ -0,0 +1,11 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "OptionsModuleTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) diff --git a/client/src/test/java/com/google/devtools/moe/client/project/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/project/BUILD.bazel new file mode 100644 index 00000000..3dfbdc7e --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/project/BUILD.bazel @@ -0,0 +1,34 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "ProjectConfigTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "RepositoryConfigTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "ScrubberConfigTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//com/google/truth", + "@maven//junit", + ], +) diff --git a/client/src/test/java/com/google/devtools/moe/client/project/ProjectConfigTest.java b/client/src/test/java/com/google/devtools/moe/client/project/ProjectConfigTest.java index a66fa335..99220465 100644 --- a/client/src/test/java/com/google/devtools/moe/client/project/ProjectConfigTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/project/ProjectConfigTest.java @@ -16,6 +16,9 @@ package com.google.devtools.moe.client.project; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.ProjectConfig; + import static com.google.common.truth.Truth.assertThat; import junit.framework.TestCase; @@ -24,7 +27,7 @@ public class ProjectConfigTest extends TestCase { public void testValidConfig() throws Exception { ProjectConfig p = - ProjectConfig.parse("{'name': 'foo', 'repositories': {'public': {'type': 'blah'}}}"); + ProjectConfigs.parse("{'name': 'foo', 'repositories': {'public': {'type': 'blah'}}}"); assertEquals("foo", p.name()); } @@ -127,7 +130,7 @@ public void testMigration1() { private void assertInvalidConfig(String text, String error) { try { - ProjectConfig.parse(text); + ProjectConfigs.parse(text); fail("Expected error"); } catch (InvalidProject e) { assertEquals(error, e.getMessage()); @@ -146,7 +149,7 @@ public void testConfigWithMultipleRepositories() throws Exception { public void testConfigWithScrubberConfig() throws Exception { // The scrubber config should not be parsed. ProjectConfig p = - ProjectConfig.parse( + ProjectConfigs.parse( "{\"name\": \"foo\"," + " \"scrubber_config\": {\"a\": 1, \"b\": 2}," + " \"repositories\": {\"internal\": {\"type\":\"svn\"}}" @@ -157,7 +160,7 @@ public void testConfigWithScrubberConfig() throws Exception { public void testDatabaseFile() { ProjectConfig p = - ProjectConfig.parse( + ProjectConfigs.parse( "{" + " 'name': 'foo'," + " 'database_uri': '/foo/bar/database.json'," @@ -170,7 +173,7 @@ public void testDatabaseFile() { public void testDatabaseFileNull() { ProjectConfig p = - ProjectConfig.parse("{'name': 'foo', 'repositories': {'x': {'type': 'blah'} } }"); + ProjectConfigs.parse("{'name': 'foo', 'repositories': {'x': {'type': 'blah'} } }"); assertThat(p.databaseUri()).isNull(); } diff --git a/client/src/test/java/com/google/devtools/moe/client/project/RepositoryConfigTest.java b/client/src/test/java/com/google/devtools/moe/client/project/RepositoryConfigTest.java index 29496504..30e65f01 100644 --- a/client/src/test/java/com/google/devtools/moe/client/project/RepositoryConfigTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/project/RepositoryConfigTest.java @@ -19,7 +19,9 @@ import static com.google.common.truth.Truth.assertThat; import com.google.common.base.Joiner; -import com.google.devtools.moe.client.gson.GsonModule; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.RepositoryConfig; +import com.google.devtools.moe.client.GsonModule; import junit.framework.TestCase; diff --git a/client/src/test/java/com/google/devtools/moe/client/project/ScrubberConfigTest.java b/client/src/test/java/com/google/devtools/moe/client/project/ScrubberConfigTest.java index 1881cdbc..9f1aed90 100644 --- a/client/src/test/java/com/google/devtools/moe/client/project/ScrubberConfigTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/project/ScrubberConfigTest.java @@ -1,7 +1,8 @@ package com.google.devtools.moe.client.project; -import com.google.devtools.moe.client.gson.GsonModule; +import com.google.devtools.moe.client.config.ScrubberConfig; +import com.google.devtools.moe.client.GsonModule; import junit.framework.TestCase; diff --git a/client/src/test/java/com/google/devtools/moe/client/repositories/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/repositories/BUILD.bazel new file mode 100644 index 00000000..4794669d --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/repositories/BUILD.bazel @@ -0,0 +1,83 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "DescriptionMetadataScrubberTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//com/google/truth", + "@maven//joda-time", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "MetadataUsernameScrubberTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//joda-time", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "OriginalAuthorMetadataScrubberTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//com/google/truth", + "@maven//joda-time", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "PublicSectionMetadataScrubberTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//joda-time", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "RepositoriesTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "RevisionMetadataTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//joda-time", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "RevisionTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//com/google/code/gson", + "@maven//com/google/truth", + "@maven//junit", + ], +) diff --git a/client/src/test/java/com/google/devtools/moe/client/repositories/DescriptionMetadataScrubberTest.java b/client/src/test/java/com/google/devtools/moe/client/repositories/DescriptionMetadataScrubberTest.java index 412af193..fb1a1549 100644 --- a/client/src/test/java/com/google/devtools/moe/client/repositories/DescriptionMetadataScrubberTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/repositories/DescriptionMetadataScrubberTest.java @@ -16,6 +16,8 @@ package com.google.devtools.moe.client.repositories; +import com.google.devtools.moe.client.config.MetadataScrubberConfig; + import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; diff --git a/client/src/test/java/com/google/devtools/moe/client/repositories/MetadataUsernameScrubberTest.java b/client/src/test/java/com/google/devtools/moe/client/repositories/MetadataUsernameScrubberTest.java index a36e05c3..afa11dca 100644 --- a/client/src/test/java/com/google/devtools/moe/client/repositories/MetadataUsernameScrubberTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/repositories/MetadataUsernameScrubberTest.java @@ -20,6 +20,8 @@ import static com.google.devtools.moe.client.testing.DummyRevisionHistory.parseLegacyFields; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.config.MetadataScrubberConfig; + import java.util.List; import junit.framework.TestCase; import org.joda.time.DateTime; diff --git a/client/src/test/java/com/google/devtools/moe/client/repositories/OriginalAuthorMetadataScrubberTest.java b/client/src/test/java/com/google/devtools/moe/client/repositories/OriginalAuthorMetadataScrubberTest.java index ac636595..cdbd6d89 100644 --- a/client/src/test/java/com/google/devtools/moe/client/repositories/OriginalAuthorMetadataScrubberTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/repositories/OriginalAuthorMetadataScrubberTest.java @@ -20,6 +20,8 @@ import static com.google.devtools.moe.client.testing.DummyRevisionHistory.parseLegacyFields; import com.google.devtools.moe.client.Ui; +import com.google.devtools.moe.client.config.MetadataScrubberConfig; + import java.io.ByteArrayOutputStream; import java.util.concurrent.atomic.AtomicBoolean; import junit.framework.TestCase; diff --git a/client/src/test/java/com/google/devtools/moe/client/repositories/RepositoriesTest.java b/client/src/test/java/com/google/devtools/moe/client/repositories/RepositoriesTest.java index c7b61ea3..c5cdb3e0 100644 --- a/client/src/test/java/com/google/devtools/moe/client/repositories/RepositoriesTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/repositories/RepositoriesTest.java @@ -20,8 +20,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.devtools.moe.client.project.InvalidProject; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.InvalidProject; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.testing.DummyRepositoryFactory; import junit.framework.TestCase; import org.easymock.EasyMock; diff --git a/client/src/test/java/com/google/devtools/moe/client/repositories/RevisionTest.java b/client/src/test/java/com/google/devtools/moe/client/repositories/RevisionTest.java index 71385a36..714c6bda 100644 --- a/client/src/test/java/com/google/devtools/moe/client/repositories/RevisionTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/repositories/RevisionTest.java @@ -17,7 +17,7 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.devtools.moe.client.gson.GsonModule; +import com.google.devtools.moe.client.GsonModule; import com.google.gson.Gson; import junit.framework.TestCase; diff --git a/client/src/test/java/com/google/devtools/moe/client/svn/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/svn/BUILD.bazel new file mode 100644 index 00000000..9ce7d959 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/svn/BUILD.bazel @@ -0,0 +1,74 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "SvnCodebaseCreatorTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "SvnDraftRevisionTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "SvnRevisionHistoryTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//joda-time", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "SvnWriterCreatorTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//com/google/dagger", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "SvnWriterTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/config", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "@maven//com/google/dagger", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//javax/inject:javax_inject", + "@maven//joda-time", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) diff --git a/client/src/test/java/com/google/devtools/moe/client/svn/SvnCodebaseCreatorTest.java b/client/src/test/java/com/google/devtools/moe/client/svn/SvnCodebaseCreatorTest.java index 6688f2d6..fcdefb86 100644 --- a/client/src/test/java/com/google/devtools/moe/client/svn/SvnCodebaseCreatorTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/svn/SvnCodebaseCreatorTest.java @@ -25,7 +25,7 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreator; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.Revision; import java.io.File; import junit.framework.TestCase; @@ -69,7 +69,7 @@ public void testExportExplicitRevision() throws Exception { CodebaseCreator cc = new SvnCodebaseCreator(fileSystem, "testing", mockConfig, revisionHistory, util); Codebase r = cc.create(ImmutableMap.of("revision", "46")); - assertEquals("/dummy/path/45", r.path().getAbsolutePath()); + assertEquals("/dummy/path/45", r.root().getAbsolutePath()); assertEquals("internal", r.projectSpace()); control.verify(); } diff --git a/client/src/test/java/com/google/devtools/moe/client/svn/SvnRevisionHistoryTest.java b/client/src/test/java/com/google/devtools/moe/client/svn/SvnRevisionHistoryTest.java index 4f5dad1e..e8f3f250 100644 --- a/client/src/test/java/com/google/devtools/moe/client/svn/SvnRevisionHistoryTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/svn/SvnRevisionHistoryTest.java @@ -27,7 +27,7 @@ import com.google.devtools.moe.client.database.RepositoryEquivalence; import com.google.devtools.moe.client.database.RepositoryEquivalenceMatcher; import com.google.devtools.moe.client.database.RepositoryEquivalenceMatcher.Result; -import com.google.devtools.moe.client.gson.GsonModule; +import com.google.devtools.moe.client.GsonModule; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.repositories.RevisionHistory.SearchType; import com.google.devtools.moe.client.repositories.RevisionMetadata; diff --git a/client/src/test/java/com/google/devtools/moe/client/svn/SvnWriterCreatorTest.java b/client/src/test/java/com/google/devtools/moe/client/svn/SvnWriterCreatorTest.java index 86c7ec3c..57df00d6 100644 --- a/client/src/test/java/com/google/devtools/moe/client/svn/SvnWriterCreatorTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/svn/SvnWriterCreatorTest.java @@ -24,7 +24,7 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.Revision; import com.google.devtools.moe.client.testing.TestingModule; import dagger.Provides; diff --git a/client/src/test/java/com/google/devtools/moe/client/svn/SvnWriterTest.java b/client/src/test/java/com/google/devtools/moe/client/svn/SvnWriterTest.java index 3f22f76e..da8a2000 100644 --- a/client/src/test/java/com/google/devtools/moe/client/svn/SvnWriterTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/svn/SvnWriterTest.java @@ -28,7 +28,7 @@ import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; -import com.google.devtools.moe.client.project.RepositoryConfig; +import com.google.devtools.moe.client.config.RepositoryConfig; import com.google.devtools.moe.client.repositories.RevisionMetadata; import com.google.devtools.moe.client.testing.TestingModule; import com.google.devtools.moe.client.writer.DraftRevision; diff --git a/client/src/test/java/com/google/devtools/moe/client/testing/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/testing/BUILD.bazel new file mode 100644 index 00000000..392015b3 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/testing/BUILD.bazel @@ -0,0 +1,50 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +java_library( + name = "testing", + srcs = ["TestingUtils.java"], + visibility = ["//client/src/test:__subpackages__"], + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/dagger", + "@maven//javax/inject:javax_inject", + ], +) + +jvm_unit_test( + name = "DummyRevisionHistoryTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//joda-time", + "@maven//junit", + "@maven//org/mockito:mockito-core", + ], +) + +jvm_unit_test( + name = "FileCodebaseCreatorTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "InMemoryFileSystemTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) diff --git a/client/src/test/java/com/google/devtools/moe/client/tools/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/tools/BUILD.bazel new file mode 100644 index 00000000..3d96f742 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/tools/BUILD.bazel @@ -0,0 +1,54 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "CodebaseDifferenceTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/mockito:mockito-core", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "FileDifferenceTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "PatchCodebaseDifferenceRendererTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + ], +) + +jvm_unit_test( + name = "TarUtilsTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) diff --git a/client/src/test/java/com/google/devtools/moe/client/translation/editors/BUILD.bazel b/client/src/test/java/com/google/devtools/moe/client/translation/editors/BUILD.bazel new file mode 100644 index 00000000..68ca1cc6 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/translation/editors/BUILD.bazel @@ -0,0 +1,85 @@ +load("//tools/build_defs:tests.bzl", "jvm_unit_test") + +jvm_unit_test( + name = "InverseRenamingEditorTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/code/gson", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "PatchingEditorTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "@maven//cglib:cglib-nodep", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "RenamingEditorTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/code/gson", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "ScrubbingEditorTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//com/google/dagger", + "@maven//cglib:cglib-nodep", + "@maven//com/google/code/gson", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) + +jvm_unit_test( + name = "ShellEditorTest", + deps = [ + "//client/src/main/java/com/google/devtools/moe/client", + "//client/src/main/java/com/google/devtools/moe/client:core", + "//client/src/main/java/com/google/devtools/moe/client/codebase/expressions", + "//client/src/main/java/com/google/devtools/moe/client/config", + "@maven//cglib:cglib-nodep", + "@maven//com/google/code/gson", + "@maven//com/google/guava", + "@maven//com/google/truth", + "@maven//junit", + "@maven//org/easymock", + "@maven//org/objenesis", + ], +) diff --git a/client/src/test/java/com/google/devtools/moe/client/translation/editors/InverseRenamingEditorTest.java b/client/src/test/java/com/google/devtools/moe/client/translation/editors/InverseRenamingEditorTest.java index f75e8c8a..d7eaca03 100644 --- a/client/src/test/java/com/google/devtools/moe/client/translation/editors/InverseRenamingEditorTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/translation/editors/InverseRenamingEditorTest.java @@ -16,7 +16,7 @@ package com.google.devtools.moe.client.translation.editors; -import static com.google.devtools.moe.client.translation.editors.Editor.Type.renamer; +import static com.google.devtools.moe.client.config.EditorType.renamer; import static org.easymock.EasyMock.expect; import com.google.common.collect.ImmutableMap; @@ -24,9 +24,9 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; -import com.google.devtools.moe.client.gson.GsonModule; -import com.google.devtools.moe.client.project.EditorConfig; -import com.google.devtools.moe.client.project.ScrubberConfig; +import com.google.devtools.moe.client.GsonModule; +import com.google.devtools.moe.client.config.EditorConfig; +import com.google.devtools.moe.client.config.ScrubberConfig; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -80,7 +80,7 @@ public void testEdit() throws Exception { Codebase inverseRenamed = inverseRenamey.inverseEdit( input, null /*referenceFrom*/, destination, ImmutableMap.of()); - assertEquals(new File("/output"), inverseRenamed.path()); + assertEquals(new File("/output"), inverseRenamed.root()); control.verify(); } diff --git a/client/src/test/java/com/google/devtools/moe/client/translation/editors/RenamingEditorTest.java b/client/src/test/java/com/google/devtools/moe/client/translation/editors/RenamingEditorTest.java index 2e05efad..5ba84412 100644 --- a/client/src/test/java/com/google/devtools/moe/client/translation/editors/RenamingEditorTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/translation/editors/RenamingEditorTest.java @@ -16,7 +16,7 @@ package com.google.devtools.moe.client.translation.editors; -import static com.google.devtools.moe.client.translation.editors.Editor.Type.renamer; +import static com.google.devtools.moe.client.config.EditorType.renamer; import static org.easymock.EasyMock.expect; import com.google.common.collect.ImmutableMap; @@ -24,9 +24,9 @@ import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; -import com.google.devtools.moe.client.gson.GsonModule; -import com.google.devtools.moe.client.project.EditorConfig; -import com.google.devtools.moe.client.project.ScrubberConfig; +import com.google.devtools.moe.client.GsonModule; +import com.google.devtools.moe.client.config.EditorConfig; +import com.google.devtools.moe.client.config.ScrubberConfig; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.JsonParser; diff --git a/client/src/test/java/com/google/devtools/moe/client/translation/editors/ScrubbingEditorTest.java b/client/src/test/java/com/google/devtools/moe/client/translation/editors/ScrubbingEditorTest.java index ea2d9d65..80dc6820 100644 --- a/client/src/test/java/com/google/devtools/moe/client/translation/editors/ScrubbingEditorTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/translation/editors/ScrubbingEditorTest.java @@ -16,7 +16,7 @@ package com.google.devtools.moe.client.translation.editors; -import static com.google.devtools.moe.client.translation.editors.Editor.Type.scrubber; +import static com.google.devtools.moe.client.config.EditorType.scrubber; import static org.easymock.EasyMock.expect; import com.google.common.base.Joiner; @@ -26,9 +26,9 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; -import com.google.devtools.moe.client.gson.GsonModule; -import com.google.devtools.moe.client.project.EditorConfig; -import com.google.devtools.moe.client.project.ScrubberConfig; +import com.google.devtools.moe.client.GsonModule; +import com.google.devtools.moe.client.config.EditorConfig; +import com.google.devtools.moe.client.config.ScrubberConfig; import com.google.devtools.moe.client.tools.EagerLazy; import com.google.devtools.moe.client.tools.TarUtils; import com.google.gson.Gson; diff --git a/client/src/test/java/com/google/devtools/moe/client/translation/editors/ShellEditorTest.java b/client/src/test/java/com/google/devtools/moe/client/translation/editors/ShellEditorTest.java index 8151137b..ab7e189b 100644 --- a/client/src/test/java/com/google/devtools/moe/client/translation/editors/ShellEditorTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/translation/editors/ShellEditorTest.java @@ -16,7 +16,7 @@ package com.google.devtools.moe.client.translation.editors; -import static com.google.devtools.moe.client.translation.editors.Editor.Type.shell; +import static com.google.devtools.moe.client.config.EditorType.shell; import static org.easymock.EasyMock.expect; import com.google.common.collect.ImmutableMap; @@ -24,9 +24,9 @@ import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.expressions.RepositoryExpression; -import com.google.devtools.moe.client.gson.GsonModule; -import com.google.devtools.moe.client.project.EditorConfig; -import com.google.devtools.moe.client.project.ScrubberConfig; +import com.google.devtools.moe.client.GsonModule; +import com.google.devtools.moe.client.config.EditorConfig; +import com.google.devtools.moe.client.config.ScrubberConfig; import com.google.gson.JsonObject; import java.io.File; import java.util.ArrayList; diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 260fd48a..00000000 --- a/pom.xml +++ /dev/null @@ -1,175 +0,0 @@ - - 4.0.0 - com.google.devtools - moe-parent - 1.0-SNAPSHOT - pom - - client - - - 1.2.30 - 2.9.9 - 25.1-jre - 2.8.1 - 2.5.0 - 1.1 - 2.16 - 1.6.2 - 1.0-beta5 - 0.8.0 - 3.0.2 - 2.32 - 4.13-SNAPSHOT - 0.42 - 3.1 - 1.9.5 - 2.3.1 - true - - - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - joda-time - joda-time - ${joda.time.version} - - - com.google.guava - guava - ${guava.version} - - - com.google.code.gson - gson - ${gson.version} - - - com.squareup.okhttp - okhttp - ${okhttp.version} - - - com.mikesamuel - json-sanitizer - ${json.sanitizer.version} - - - com.google.dagger - dagger - ${dagger.version} - - - com.google.dagger - dagger-compiler - ${dagger.version} - provided - - - com.google.auto.value - auto-value - ${auto.value.version} - provided - - - com.google.auto.factory - auto-factory - ${auto.factory.version} - provided - - - com.ryanharter.auto.value - auto-value-gson - ${auto.value.gson.version} - provided - - - com.google.errorprone - error_prone_annotations - ${errorprone.version} - provided - - - com.google.code.findbugs - jsr305 - ${jsr305.version} - true - - - args4j - args4j - 2.32 - - - junit - junit - ${junit.version} - test - - - com.google.truth - truth - ${truth.version} - test - - - org.easymock - easymock - ${easymock.version} - test - - - org.mockito - mockito-core - ${mockito.version} - test - - - - - - - src/main/java - - **/*.java - **/*.kt - - - - - - src/test/java - - **/*.java - **/*.kt - - - - - - - maven-compiler-plugin - - 1.8 - 1.8 - - - - maven-jar-plugin - 2.5 - - - - - - - sonatype-snapshots - https://oss.sonatype.org/content/repositories/snapshots/ - - - diff --git a/tools/auto/generated/javax/annotation/BUILD.bazel b/tools/auto/generated/javax/annotation/BUILD.bazel new file mode 100644 index 00000000..d434dc95 --- /dev/null +++ b/tools/auto/generated/javax/annotation/BUILD.bazel @@ -0,0 +1,12 @@ +# A stand-in for the javax.annotation.Generated annotation which several annotation processors depend on, +# but which disappeared after Java8. Later versions don't rely on the loaded class, so this can be removed +# once MOE is upgraded to versions of the annotation processors which dynamically detect the right annotation +# to emit. + +java_library( + name = "generated", + srcs = [ + "Generated.java", + ], + visibility = ["//visibility:public"] +) \ No newline at end of file diff --git a/tools/auto/generated/javax/annotation/Generated.java b/tools/auto/generated/javax/annotation/Generated.java new file mode 100644 index 00000000..f12ecd31 --- /dev/null +++ b/tools/auto/generated/javax/annotation/Generated.java @@ -0,0 +1,13 @@ +package javax.annotation; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +@Retention(SOURCE) +@Target({TYPE}) +public @interface Generated { + String[] value(); + String date() default ""; + String comments() default ""; +} \ No newline at end of file diff --git a/tools/build_defs/BUILD.bazel b/tools/build_defs/BUILD.bazel new file mode 100644 index 00000000..de28c3d7 --- /dev/null +++ b/tools/build_defs/BUILD.bazel @@ -0,0 +1 @@ +exports_files(["tests.bzl"]) \ No newline at end of file diff --git a/tools/build_defs/tests.bzl b/tools/build_defs/tests.bzl new file mode 100644 index 00000000..cdb65a0b --- /dev/null +++ b/tools/build_defs/tests.bzl @@ -0,0 +1,42 @@ +# +# Convenience test rules. +# +load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library", "kt_jvm_binary") + +def jvm_unit_test(name, srcs = [], size = "small", **kwargs): + """Wraps a kt_jvm_library and java_test.""" + + # If unspecified, try to get the test source named after the test file. + if not bool(srcs): + srcs = native.glob(["%s.*" % name]) + srcs = [x for x in srcs if x.endswith(".java") or x.endswith(".kt")] + if bool(srcs) and len(srcs) > 1: + fail("More than one test src file %s: %s" % (name, srcs)) + elif bool(srcs) and srcs[0].endswith(".kt"): + test_file = srcs[0] + lib_name = "%s_testlib" % name + kt_jvm_library( + name = lib_name, + srcs = srcs, + testonly = 1, + **kwargs + ) + elif bool(srcs) and srcs[0].endswith(".java"): + test_file = srcs[0] + lib_name = "%s_testlib" % name + native.java_library( + name = lib_name, + srcs = srcs, + testonly = 1, + **kwargs + ) + elif bool(srcs): + fail("Invalid test file %s. Must be a java or kotlin file." % srcs) + else: + fail("Missing a test file for %s" % name) + + native.java_test( + name = name, + size = size, + runtime_deps = [lib_name], + ) \ No newline at end of file diff --git a/util/BUILD.bazel b/util/BUILD.bazel new file mode 100644 index 00000000..1adc8a9d --- /dev/null +++ b/util/BUILD.bazel @@ -0,0 +1 @@ +exports_files(["java-exec-prefix"]) \ No newline at end of file diff --git a/util/generate-latest-docs.sh b/util/generate-latest-docs.sh deleted file mode 100755 index 7e120569..00000000 --- a/util/generate-latest-docs.sh +++ /dev/null @@ -1,25 +0,0 @@ -# - -if [ "$TRAVIS_REPO_SLUG" == "google/MOE" ] && \ - [ "$TRAVIS_JDK_VERSION" == "oraclejdk7" ] && \ - [ "$TRAVIS_PULL_REQUEST" == "false" ] && \ - [ "$TRAVIS_BRANCH" == "master" ]; then - echo -e "Publishing javadoc...\n" - - mvn javadoc:aggregate - TARGET="$(pwd)/target" - - cd $HOME - git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/google/MOE gh-pages > /dev/null - - cd gh-pages - git config --global user.email "travis@travis-ci.org" - git config --global user.name "travis-ci" - git rm -rf api/latest - mv ${TARGET}/site/apidocs api/latest - git add -A -f api/latest - git commit -m "Latest javadoc on successful travis build $TRAVIS_BUILD_NUMBER auto-pushed to gh-pages" - git push -fq origin gh-pages > /dev/null - - echo -e "Published Javadoc to gh-pages.\n" -fi diff --git a/util/java-exec-prefix b/util/java-exec-prefix index 96cc5465..8efda6db 100644 --- a/util/java-exec-prefix +++ b/util/java-exec-prefix @@ -14,26 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -JAR_FILE=`which "$0" 2>/dev/null` - -if [[ -n "$JAVA_HOME" ]]; then - JAVA_CMD="$JAVA_HOME/bin/java" - if [[ ! -f $JAVA_CMD ]]; then - echo "Cannot find java binary at $JAVA_CMD" - exit 1 - fi -else - if [[ ! `which java` ]]; then - echo "Cannot find java binary on the executable PATH" - exit 1 - fi - JAVA_CMD=`which java` -fi - -if [[ ! -x $JAVA_CMD ]]; then - echo "Java command is not executable: $JAVA_CMD" - exit 1 -fi - -"$JAVA_CMD" $JVM_ARGS -jar $0 "$@" -exit 1 +MYSELF=$(which "$0" 2>/dev/null) +[ $? -gt 0 ] && [ -f "$0" ] && MYSELF="./$0" +JAVA_CMD=java +[ -n "$JAVA_HOME" ] && JAVA_CMD="$JAVA_HOME/bin/java" +exec "$JAVA_CMD" $JAVA_ARGS -jar "$MYSELF" "$@" +exit 1 diff --git a/util/make-binary.sh b/util/make-binary.sh deleted file mode 100755 index 09702419..00000000 --- a/util/make-binary.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -cmd_dir=$(cd `dirname "$0"` && pwd) -target_dir="$(dirname $cmd_dir)/client/target" -jar_file=${target_dir}/moe-*-executable.jar -if [ ! -f ${jar_file} ]; then - echo "Monolithic executable jar not found in ${target_dir}" - exit 1 -fi -cat ${cmd_dir}/java-exec-prefix ${jar_file} > ${target_dir}/moe -chmod a+x ${target_dir}/moe -echo "MOE Mac/Unix excecutable created at ${target_dir}/moe" diff --git a/workspace_maven_substitutes.bzl b/workspace_maven_substitutes.bzl new file mode 100644 index 00000000..14db362d --- /dev/null +++ b/workspace_maven_substitutes.bzl @@ -0,0 +1,94 @@ + +_DAGGER = """ +java_library( + name = "dagger", + exports = [ + ":dagger-api", + "@maven//javax/inject:javax_inject", + ], + exported_plugins = [":plugin"], + visibility = ["//visibility:public"], +) + +raw_jvm_import( + name = "dagger-api", + jar = "@com_google_dagger_dagger//maven", + visibility = ["//visibility:public"], + deps = [ + "@maven//javax/inject:javax_inject", + ], +) + +java_plugin( + name = "plugin", + processor_class = "dagger.internal.codegen.ComponentProcessor", + generates_api = True, + deps = [":dagger-compiler"], +) +""" + +_AUTO_FACTORY = """ +java_library( + name = "factory", + exports = [ + "@maven//com/google/auto/factory:auto-factory", + ], + exported_plugins = [":plugin"], + neverlink = True, # this is only needed at compile-time, for code-gen. + visibility = ["//visibility:public"], +) + +raw_jvm_import( + name = "auto-factory", + jar = "@com_google_auto_factory_auto_factory//maven", + visibility = ["//visibility:public"], +) + +java_plugin( + name = "plugin", + processor_class = "com.google.auto.factory.processor.AutoFactoryProcessor", + generates_api = True, + deps = [":auto-factory"], +) +""" + +_AUTO_VALUE = """ +java_library( + name = "value", + exports = [ + ":auto-value-annotations", + "@maven//com/ryanharter/auto/value:auto-value-gson-annotations", + ], + exported_plugins = [":plugin", ":gson-plugin"], + visibility = ["//visibility:public"], +) + +raw_jvm_import( + name = "auto-value", + jar = "@com_google_auto_value_auto_value//maven", + visibility = ["@maven//com/ryanharter/auto/value:__subpackages__"], +) + +java_plugin( + name = "plugin", + processor_class = "com.google.auto.value.processor.AutoValueProcessor", + generates_api = True, + deps = [":auto-value"], +) + +java_plugin( + name = "gson-plugin", + processor_class = "com.ryanharter.auto.value.gson.AutoValueGsonAdapterFactoryProcessor", + generates_api = True, + deps = [ + "@//tools/auto/generated/javax/annotation:generated", # For compiling with java9+ + "@maven//com/ryanharter/auto/value:auto-value-gson", + ], +) +""" + +snippets = struct( + AUTO_VALUE = _AUTO_VALUE, + AUTO_FACTORY = _AUTO_FACTORY, + DAGGER = _DAGGER, +) \ No newline at end of file