diff --git a/client/pom.xml b/client/pom.xml index 1f54640f..bfb34fcc 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -13,6 +13,10 @@ + + org.jetbrains.kotlin + kotlin-stdlib + joda-time joda-time @@ -90,6 +94,68 @@ + + 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 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 5456449f..e2d5c32d 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 @@ -105,7 +105,7 @@ public class CodebaseMerger { public MergeResult merge(Codebase original, Codebase modified, Codebase destination) { MergeResult.Builder resultBuilder = MergeResult.builder(); File mergedDir = filesystem.getTemporaryDirectory("merged_codebase_"); - RepositoryExpression mergedExpression = RepositoryExpression.create("merged"); + RepositoryExpression mergedExpression = new RepositoryExpression("merged"); resultBuilder.setMergedCodebase(Codebase.create(mergedDir, "merged", mergedExpression)); Set filesToMerge = Sets.union(findFiles(destination), findFiles(modified)); 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 ef84fa02..a8319844 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 @@ -24,8 +24,8 @@ public class EditedCodebaseProcessor implements CodebaseProcessor{@code - * Minimalism - * Abstract Expressionism - * Postmodernism - * Is it?" - * - Living Color, "Type" from the album "Time's Up" - * } - */ -// TODO(cgruber) @Autovalue or at least fix hashcode and equals. -abstract class AbstractExpression extends Expression { - - @Override - EditExpression editWith(Operation editOp) { - return EditExpression.create(this, editOp); - } - - @Override - public EditExpression editWith(String editorName, Map editorOptions) { - Term term = Term.create(editorName).withOptions(editorOptions); - Operation op = Operation.create(Operator.EDIT, term); - return editWith(op); - } - - @Override - public TranslateExpression translateTo(String projectSpace) { - Term term = Term.create(projectSpace); - Operation op = Operation.create(Operator.TRANSLATE, term); - return translateTo(op); - } - - @Override - TranslateExpression translateTo(Operation translateOp) { - return TranslateExpression.create(this, translateOp); - } - - @Override - public abstract String toString(); - - -} diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/BinaryExpression.java b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/BinaryExpression.java deleted file mode 100644 index ab471b36..00000000 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/BinaryExpression.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.google.devtools.moe.client.codebase.expressions; - -import static com.google.common.base.Preconditions.checkState; - -import java.util.HashSet; -import java.util.Set; - -/** Bundles the API in common for operator/operand style expressions. */ -abstract class BinaryExpression extends AbstractExpression { - - public abstract Expression operand(); - - public abstract Operation operation(); - - @Override - public String toString() { - return "" + operand() + operation(); - } - - protected static void validateOperand(Expression e) { - validateOperand(new HashSet<>(), e); - } - - protected static void validateOperand(Set visited, Expression e) { - if (e instanceof BinaryExpression) { - validateOperand(visited, (BinaryExpression) e); - } - } - - protected static void validateOperand(Set visited, BinaryExpression e) { - checkState( - !visited.contains(e.operand()), - "Cyclic inclusion in Expressions. Start from a RepositoryExpression."); - visited.add(e.operand()); - validateOperand(visited, e.operand()); - } -} diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/EditExpression.java b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/EditExpression.java deleted file mode 100644 index affb2851..00000000 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/EditExpression.java +++ /dev/null @@ -1,46 +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.expressions; - -import com.google.auto.value.AutoValue; -import com.google.common.base.Preconditions; - -/** - * An expression encapsulating the transformation of the given Expression's Codebase via the - * application of an {@link com.google.devtools.moe.client.translation.editors.Editor}. For example, - * - *
{@code
- * new RepositoryExpression("myRepo").editWith("myEditor", { "option1": "foo" })
- * }
- * - * returns an EditExpression for - * - *
{@code "myRepo|myEditor(option1=foo)"}
- * - * . - */ -@AutoValue -public abstract class EditExpression extends BinaryExpression { - /** Package-only constructor visible by tests and the autovalue generated code. */ - EditExpression() {} - - public static EditExpression create(Expression operand, Operation operation) { - Preconditions.checkArgument(Operator.EDIT.equals(operation.operator())); - validateOperand(operand); - return new AutoValue_EditExpression(operand, operation); - } -} diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/EditExpression.kt b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/EditExpression.kt new file mode 100644 index 00000000..508dc59e --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/EditExpression.kt @@ -0,0 +1,35 @@ +/* + * 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.expressions + +/** + * An expression encapsulating the transformation of the given Expression's Codebase via the + * application of an [com.google.devtools.moe.client.translation.editors.Editor]. For example, + * + *
`new RepositoryExpression("myRepo").editWith("myEditor", { "option1": "foo" })
+`
* + * + * returns an EditExpression for + * + *
`"myRepo|myEditor(option1=foo)"`
+ * + * . + */ +data class EditExpression +internal constructor(val operand: Expression, val operation: Operation) : Expression() { + override fun toString(): String = "$operand$operation" +} diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Expression.java b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Expression.java deleted file mode 100644 index c5b9fb71..00000000 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Expression.java +++ /dev/null @@ -1,53 +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.expressions; - -import java.util.Map; - -/** - * An API for objects describing a {@link com.google.devtools.moe.client.codebase.Codebase}. A - * {@code Codebase} is described lazily by editing or translating a given expression. Then {@link - * com.google.devtools.moe.client.codebase.ExpressionEngine#createCodebase(Expression,com.google.devtools.moe.client.project.ProjectContext)} - * is called to create the materialized {@code Codebase} from the {@link Expression}, in a given - * {@link com.google.devtools.moe.client.project.ProjectContext}. Different Expression types will - * have an associated {@link com.google.devtools.moe.client.codebase.CodebaseProcessor} which may - * offer different alterations from the base {@link RepositoryExpression}. Expressions should be - * immutable, and all implementations of the transformations should return new Expressions. - */ -public abstract class Expression { - /** - * Transform this expression with the given translation {@link Operation}. For example, given an - * Expression encapsulating "foo(revision=3)", calling expression.translateTo("public") yields an - * expression encapsulating "foo(revision=3)>public". - */ - public abstract TranslateExpression translateTo(String projectSpace); - - /** A version of translateTo() used by the parser. */ - abstract TranslateExpression translateTo(Operation translateOp); - - /** - * Transform this expression with the given editing {@link Operation}. For example, given an - * Expression encapsulating "foo(revision=3)", calling expression.editWith("editor", { "option1": - * "foo", "option2": "bar" }) yields an expression encapsulating - * "foo(revision=3)|editor(option1=foo,option2=bar)". - */ - public abstract EditExpression editWith(String editorName, Map editorOptions); - - /** A version of editWith() used by the parser. */ - abstract EditExpression editWith(Operation editOp); - -} diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Expression.kt b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Expression.kt new file mode 100644 index 00000000..04b6ed13 --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Expression.kt @@ -0,0 +1,59 @@ +/* + * 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.expressions + +/** + * An API for objects describing a [com.google.devtools.moe.client.codebase.Codebase]. A + * `Codebase` is described lazily by editing or translating a given expression. Then + * [com.google.devtools.moe.client.codebase.ExpressionEngine.createCodebase] + * is called to create the materialized `Codebase` from the [Expression], in a given + * [com.google.devtools.moe.client.project.ProjectContext]. Different Expression types will + * have an associated [com.google.devtools.moe.client.codebase.CodebaseProcessor] which may + * offer different alterations from the base [RepositoryExpression]. Expressions should be + * immutable, and all implementations of the transformations should return new Expressions. + */ +abstract class Expression { + /** + * Transform this expression with the given translation [Operation]. For example, given an + * Expression encapsulating "foo(revision=3)", calling expression.translateTo("public") yields an + * expression encapsulating "foo(revision=3)>public". + */ + fun translateTo(projectSpace: String): TranslateExpression { + val term = Term(projectSpace) + val op = Operation(Operator.TRANSLATE, term) + return translateTo(op) + } + + /** A version of translateTo() used by the parser. */ + protected fun translateTo(translateOp: Operation): TranslateExpression = + TranslateExpression(this, translateOp) + + /** + * Transform this expression with the given editing [Operation]. For example, given an + * Expression encapsulating "foo(revision=3)", calling expression.editWith("editor", { "option1": + * "foo", "option2": "bar" }) yields an expression encapsulating + * "foo(revision=3)|editor(option1=foo,option2=bar)". + */ + fun editWith(editorName: String, editorOptions: Map): EditExpression { + val term = Term(editorName).withOptions(editorOptions) + val op = Operation(Operator.EDIT, term) + return editWith(op) + } + + /** A version of editWith() used by the parser. */ + protected fun editWith(editOp: Operation): EditExpression = EditExpression(this, editOp) +} diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operation.java b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operation.kt similarity index 69% rename from client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operation.java rename to client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operation.kt index 2903f2b4..23f392d8 100644 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operation.java +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operation.kt @@ -16,26 +16,11 @@ package com.google.devtools.moe.client.codebase.expressions; -import com.google.auto.value.AutoValue; - /** * An Operation in the MOE Expression Language is an operator followed by a term. * *

E.g., |patch(file="/path/to/path.txt") or >public */ -@AutoValue -public abstract class Operation { - - public abstract Operator operator(); - - public abstract Term term(); - - @Override - public String toString() { - return "" + operator() + term(); - } - - static Operation create(Operator operator, Term term) { - return new AutoValue_Operation(operator, term); - } +data class Operation(val operator: Operator, val term: Term) { + override fun toString(): String = "$operator$term" } diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operator.java b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operator.kt similarity index 54% rename from client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operator.java rename to client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operator.kt index 5ebfd71f..5ef099e1 100644 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operator.java +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Operator.kt @@ -14,33 +14,21 @@ * limitations under the License. */ -package com.google.devtools.moe.client.codebase.expressions; +package com.google.devtools.moe.client.codebase.expressions -/** - * Operators in the MOE Codebase Expression Language. - */ -public enum Operator { +/** Operators in the MOE Codebase Expression Language. */ +enum class Operator constructor(private val op: Char) { EDIT('|'), TRANSLATE('>'); - private final char op; - - Operator(char op) { - this.op = op; - } - - @Override - public String toString() { - return String.valueOf(op); - } + override fun toString() = op.toString() - public static Operator getOperator(char c) throws IllegalArgumentException { - if (c == '|') { - return EDIT; - } - if (c == '>') { - return TRANSLATE; - } - throw new IllegalArgumentException("Invalid operator: " + c); + companion object { + @JvmStatic fun getOperator(c: Char): Operator = + when (c) { + '|' -> EDIT + '>' -> TRANSLATE + else -> throw IllegalArgumentException("Invalid operator: $c") + } } } diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Parser.java b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Parser.java index bd6a1659..44ade541 100644 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Parser.java +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Parser.java @@ -28,11 +28,11 @@ /** * Parser for Terms; useful for various Expression Languages * - * This allows MOE to embed options in one string instead of having many - * orthogonal flags. + *

This allows MOE to embed options in one string instead of having many orthogonal flags. * - * The syntax for a Term is: + *

The syntax for a Term is: * + *

{@code
  * TERM -> LITERAL OPTIONS
  * OPTIONS ->
  * OPTIONS -> (OPTIONLIST)
@@ -42,20 +42,25 @@
  * OPTION -> LITERAL = LITERAL
  * LITERAL -> alphanumeric+
  * LITERAL -> "[^"]"*
+ * }
* - * Examples: + *

Examples: * + *

{@code
  * internal
  * internal(revision=45)
  * public
  * file(path="/path/to/public.tar")
+ * }
* - * Users should use the high-level functions: + *

Users should use the high-level functions: + * + *

{@code
  * parseOperator
  * parseTerm
  * parseTermCompletely
  * tokenize
- *
+ * }
*/ public class Parser { @@ -82,9 +87,9 @@ public static Expression parseExpression(String toParse) throws ParseError { StreamTokenizer t = Parser.tokenize(toParse); Term creator = Parser.parseTerm(t); List operations = Parser.parseOperationList(t); - Expression ex = RepositoryExpression.create(creator); + Expression ex = new RepositoryExpression(creator); for (Operation op : operations) { - switch (op.operator()) { + switch (op.getOperator()) { case EDIT: ex = ex.editWith(op); break; @@ -92,7 +97,7 @@ public static Expression parseExpression(String toParse) throws ParseError { ex = ex.translateTo(op); break; default: - throw new ParseError("Unexpected operator: " + op.operator()); + throw new ParseError("Unexpected operator: " + op.getOperator()); } } return ex; @@ -106,7 +111,7 @@ public static RepositoryExpression parseRepositoryExpression(String toParse) thr StreamTokenizer t = Parser.tokenize(toParse); Term creator = Parser.parseTerm(t); List operations = Parser.parseOperationList(t); - RepositoryExpression ex = RepositoryExpression.create(creator); + RepositoryExpression ex = new RepositoryExpression(creator); if (!operations.isEmpty()) { throw new ParseError( "Expression must represent a simple repository, e.g. 'internal(revision=3)'."); @@ -185,8 +190,7 @@ static Map parseOptions(StreamTokenizer input) throws ParseError /** * Parses a Term. * - * @param input text to parse - * + * @param input text to parse * @return the parsed term */ public static Term parseTerm(StreamTokenizer input) throws ParseError { @@ -198,7 +202,7 @@ public static Term parseTerm(StreamTokenizer input) throws ParseError { String identifier = input.sval; Map options = parseOptions(input); - return Term.create(identifier).withOptions(options); + return new Term(identifier).withOptions(options); } catch (IOException e) { throw new ParseError(e.getMessage()); } @@ -207,7 +211,7 @@ public static Term parseTerm(StreamTokenizer input) throws ParseError { /** * Determines if the input is exhausted. * - * @param input the input tokenizer + * @param input the input tokenizer */ private static boolean isInputExhausted(StreamTokenizer input) throws ParseError { try { @@ -224,8 +228,7 @@ private static boolean isInputExhausted(StreamTokenizer input) throws ParseError /** * Parses a Term from input, throwing an error if the input contains more than a Term. * - * @param input text to parse - * + * @param input text to parse * @return the parsed term * @throws ParseError if the string is not exactly a Term */ @@ -258,7 +261,7 @@ public static List parseOperationList(StreamTokenizer input) throws P while (!Parser.isInputExhausted(input)) { Operator operator = parseOperator(input); Term t = Parser.parseTerm(input); - operations.add(Operation.create(operator, t)); + operations.add(new Operation(operator, t)); } return operations.build(); } diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpression.java b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpression.java deleted file mode 100644 index 7b8abcc3..00000000 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpression.java +++ /dev/null @@ -1,71 +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.expressions; - -import com.google.auto.value.AutoValue; -import java.util.Map; - -/** - * An {@link Expression} describing a repository checkout. This is the starting point for building - * Expressions, e.g.: new - * RepositoryExpression("myGitRepo").atRevision("a983ef").translateTo("public"). - */ -@AutoValue -public abstract class RepositoryExpression extends AbstractExpression { - - public abstract Term term(); - - /** - * Add an option name-value pair to the expression, e.g. "myRepo" -> "myRepo(revision=4)". - */ - public RepositoryExpression withOption(String optionName, String optionValue) { - return RepositoryExpression.create(term().withOption(optionName, optionValue)); - } - - /** Add multiple options to a repository. */ - public RepositoryExpression withOptions(Map options) { - return RepositoryExpression.create(term().withOptions(options)); - } - - /** - * A helper method for adding a "revision" option with the given value. - */ - public RepositoryExpression atRevision(String revId) { - return withOption("revision", revId); - } - - public String getRepositoryName() { - return term().identifier(); - } - - public String getOption(String optionName) { - return term().options().get(optionName); - } - - @Override - public String toString() { - return term().toString(); - } - - public static RepositoryExpression create(String repositoryName) { - return create(Term.create(repositoryName)); - } - - static RepositoryExpression create(Term term) { - return new AutoValue_RepositoryExpression(term); - } -} diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpression.kt b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpression.kt new file mode 100644 index 00000000..c47e007d --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpression.kt @@ -0,0 +1,44 @@ +/* + * 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.expressions + +/** + * An [Expression] describing a repository checkout. This is the starting point for building + * Expressions, e.g.: `RepositoryExpression("myGitRepo").atRevision("12345").translateTo("public").` + */ +data class RepositoryExpression(val term: Term) : Expression() { + + constructor(repositoryName: String) : this(Term(repositoryName)) + + val repositoryName: String + get() = term.identifier + + /** Add an option name-value pair to the expression, e.g. "myRepo" -> "myRepo(revision=4)". */ + fun withOption(optionName: String, optionValue: String): RepositoryExpression = + RepositoryExpression(term.withOption(optionName, optionValue)) + + /** Add multiple options to a repository. */ + fun withOptions(options: Map): RepositoryExpression = + RepositoryExpression(term.withOptions(options)) + + /** A helper method for adding a "revision" option with the given value. */ + fun atRevision(revId: String): RepositoryExpression = withOption("revision", revId) + + fun getOption(optionName: String): String? = term.options[optionName] + + override fun toString(): String = term.toString() +} diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Term.java b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Term.java deleted file mode 100644 index a0dc8061..00000000 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Term.java +++ /dev/null @@ -1,89 +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.expressions; - -import com.google.auto.value.AutoValue; -import com.google.auto.value.extension.memoized.Memoized; -import com.google.common.base.CharMatcher; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSortedMap; -import java.util.Map; -import java.util.Map.Entry; - -/** - * A Term in the MOE Expression Language. - * - *

An identifier with optional parameters. E.g., "foo" or "internal(revision=45)" - */ -@AutoValue -public abstract class Term { - - public abstract String identifier(); - - public abstract ImmutableSortedMap options(); - - /** - * Add an option name-value pair to the Term, e.g. "myRepo" -> "myRepo(revision=4)". - */ - public Term withOption(String optionName, String optionValue) { - return new AutoValue_Term( - identifier(), - ImmutableSortedMap.naturalOrder() - .putAll(options()) - .put(optionName, optionValue) - .build()); - } - - /** Add multiple name-value pairs to the Term, e.g. "myRepo" -> "myRepo(revision=4, bar=blah)". */ - public Term withOptions(Map moreOptions) { - return new AutoValue_Term( - identifier(), - ImmutableSortedMap.naturalOrder() - .putAll(options()) - .putAll(moreOptions) - .build()); - } - - private static String maybeQuote(String s) { - if (CharMatcher.javaLetterOrDigit().matchesAllOf(s)) { - return s; - } - return "\"" + s + "\""; - } - - @Memoized - @Override - public String toString() { - ImmutableMap.Builder quotedMap = ImmutableMap.builder(); - for (Entry entry : options().entrySet()) { - quotedMap.put(maybeQuote(entry.getKey()), maybeQuote(entry.getValue())); - } - StringBuilder result = new StringBuilder(); - result.append(maybeQuote(identifier())); - if (!options().isEmpty()) { - result.append("("); - Joiner.on(',').withKeyValueSeparator('=').appendTo(result, quotedMap.build()); - result.append(")"); - } - return result.toString(); - } - - public static Term create(String identifier) { - return new AutoValue_Term(identifier, ImmutableSortedMap.of()); - } -} diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Term.kt b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Term.kt new file mode 100644 index 00000000..4d9667da --- /dev/null +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/Term.kt @@ -0,0 +1,74 @@ +/* + * 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.expressions + +import com.google.common.base.CharMatcher +import com.google.common.base.Joiner +import com.google.common.collect.ImmutableMap +import com.google.common.collect.ImmutableSortedMap + +/** + * A Term in the MOE Expression Language. + ** + * An identifier with optional parameters. E.g., `foo` or `internal(revision=45)` + */ +data class Term @JvmOverloads constructor( + var identifier: String, + var options: ImmutableSortedMap = ImmutableSortedMap.of() +) { + + /** + * Add an option name-value pair to the Term, e.g. "myRepo" -> "myRepo(revision=4)". + */ + fun withOption(optionName: String, optionValue: String): Term { + return Term( + identifier, + ImmutableSortedMap.naturalOrder() + .putAll(options) + .put(optionName, optionValue) + .build()) + } + + /** Add multiple name-value pairs to the Term, e.g. "myRepo" -> "myRepo(revision=4, bar=blah)". */ + fun withOptions(moreOptions: Map): Term { + return Term( + identifier, + ImmutableSortedMap.naturalOrder() + .putAll(options) + .putAll(moreOptions) + .build()) + } + + private fun maybeQuote(string: String): String { + return if (CharMatcher.javaLetterOrDigit().matchesAllOf(string)) string else "\"${string}\"" + } + + override fun toString(): String { + val quotedMap = ImmutableMap.builder() + for (entry in options.entries) { + quotedMap.put(maybeQuote(entry.key), maybeQuote(entry.value)) + } + val result = StringBuilder() + result.append(maybeQuote(identifier)) + if (!options.isEmpty()) { + result.append("(") + Joiner.on(',').withKeyValueSeparator('=').appendTo(result, quotedMap.build()) + result.append(")") + } + return result.toString() + } +} diff --git a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/TranslateExpression.java b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/TranslateExpression.kt similarity index 57% rename from client/src/main/java/com/google/devtools/moe/client/codebase/expressions/TranslateExpression.java rename to client/src/main/java/com/google/devtools/moe/client/codebase/expressions/TranslateExpression.kt index ab04ba36..0a955fee 100644 --- a/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/TranslateExpression.java +++ b/client/src/main/java/com/google/devtools/moe/client/codebase/expressions/TranslateExpression.kt @@ -14,29 +14,24 @@ * limitations under the License. */ -package com.google.devtools.moe.client.codebase.expressions; +package com.google.devtools.moe.client.codebase.expressions -import com.google.auto.value.AutoValue; -import com.google.common.base.Preconditions; /** * An expression encapsulating the transformation of the given Expression's Codebase via the - * application of a {@link com.google.devtools.moe.client.translation.pipeline.TranslationPipeline}. + * application of a [com.google.devtools.moe.client.translation.pipeline.TranslationPipeline]. * For example, new RepositoryExpression("myRepo").translateTo("public") returns a * TranslateExpression for "myRepo>public". */ -@AutoValue -public abstract class TranslateExpression extends BinaryExpression { - /** Package-only constructor visible by tests and the autovalue generated code. */ - TranslateExpression() {} +data class TranslateExpression(val operand: Expression, val operation: Operation) : Expression() { /** * Returns a new TranslateExpression performing this translation with the given reference * to-codebase. This is used by inverse translation, for example when inspecting changes such as * renamings in the reference to-codebase for the purpose of inverting those renamings. */ - public TranslateExpression withReferenceTargetCodebase(Expression referenceTargetCodebase) { - return withOption("referenceTargetCodebase", referenceTargetCodebase.toString()); + fun withReferenceTargetCodebase(referenceTargetCodebase: Expression): TranslateExpression { + return withOption("referenceTargetCodebase", referenceTargetCodebase.toString()) } /** @@ -44,19 +39,14 @@ public TranslateExpression withReferenceTargetCodebase(Expression referenceTarge * from-codebase. This is used by inverse translation when merging two sets of changes, the input * codebase and the reference to-codebase, onto a reference from-codebase. */ - public TranslateExpression withReferenceFromCodebase(Expression referenceFromCodebase) { - return withOption("referenceFromCodebase", referenceFromCodebase.toString()); + fun withReferenceFromCodebase(referenceFromCodebase: Expression): TranslateExpression { + return withOption("referenceFromCodebase", referenceFromCodebase.toString()) } - private TranslateExpression withOption(String key, String value) { - return TranslateExpression.create( - operand(), - Operation.create(operation().operator(), operation().term().withOption(key, value))); + private fun withOption(key: String, value: String): TranslateExpression { + return TranslateExpression( + operand, Operation(this.operation.operator, this.operation.term.withOption(key, value))) } - public static TranslateExpression create(Expression operand, Operation operation) { - Preconditions.checkArgument(Operator.TRANSLATE.equals(operation.operator())); - validateOperand(operand); - return new AutoValue_TranslateExpression(operand, operation); - } + override fun toString(): String = "$operand$operation" } 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 f4b5edda..8e035a64 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 @@ -125,8 +125,7 @@ private RepositoryEquivalence determineEquivalence(Revision fromRevision, Revisi } private Codebase createCodebaseForRevision(Revision rev, String translateSpace) { - Expression expression = - RepositoryExpression.create(rev.repositoryName()).atRevision(rev.revId()); + Expression expression = new RepositoryExpression(rev.repositoryName()).atRevision(rev.revId()); if (translateSpace != null) { expression = expression.translateTo(translateSpace); } 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 f4a2d4f4..d7bd9297 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 @@ -140,7 +140,7 @@ protected int performDirectiveBehavior() { RepositoryEquivalence lastRecordedEquivalence = migrations.get(0).sinceEquivalence(); RepositoryExpression targetRepositoryPointOfEquivalency = - RepositoryExpression.create(migrationConfig.getToRepository()); + new RepositoryExpression(migrationConfig.getToRepository()); if (lastRecordedEquivalence != null) { targetRepositoryPointOfEquivalency = targetRepositoryPointOfEquivalency.atRevision( @@ -184,9 +184,8 @@ protected int performDirectiveBehavior() { // For each migration, the reference to-codebase for inverse translation is the Writer, // since it contains the latest changes (i.e. previous migrations) to the to-repository. Expression referenceTargetCodebase = - RepositoryExpression.create(migrationConfig.getToRepository()) + new RepositoryExpression(migrationConfig.getToRepository()) .withOption("localroot", targetCodebaseWriter.getRoot().getAbsolutePath()); - try (Task oneMigrationTask = ui.newTask( "perform_individual_migration", @@ -202,7 +201,7 @@ protected int performDirectiveBehavior() { String targetProjectSpace = config.getRepositoryConfig(migration.toRepository()).getProjectSpace(); Expression fromExpression = - RepositoryExpression.create(migration.fromRepository()) + new RepositoryExpression(migration.fromRepository()) .atRevision(mostRecentFromRev.revId()) .translateTo(targetProjectSpace) .withReferenceTargetCodebase(referenceTargetCodebase); 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 fbc15bea..bef582a2 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 @@ -177,8 +177,7 @@ protected int performBranchMigration( return 0; // autoclosed. } - RepositoryExpression toRepoExp = - RepositoryExpression.create(migrationConfig.getToRepository()); + RepositoryExpression toRepoExp = new RepositoryExpression(migrationConfig.getToRepository()); Writer toWriter; try { toWriter = writerFactory.createWriter(toRepoExp, context); @@ -190,7 +189,7 @@ protected int performBranchMigration( // For each migration, the reference to-codebase for inverse translation is the Writer, // since it contains the latest changes (i.e. previous migrations) to the to-repository. Expression referenceTargetCodebase = - RepositoryExpression.create(migrationConfig.getToRepository()) + new RepositoryExpression(migrationConfig.getToRepository()) .withOption("localroot", toWriter.getRoot().getAbsolutePath()); try (Task performMigration = @@ -206,7 +205,7 @@ protected int performBranchMigration( String toProjectSpace = config.getRepositoryConfig(migration.toRepository()).getProjectSpace(); Expression fromExpression = - RepositoryExpression.create(migration.fromRepository()) + new RepositoryExpression(migration.fromRepository()) .atRevision(mostRecentFromRev.revId()) .translateTo(toProjectSpace) .withReferenceTargetCodebase(referenceTargetCodebase); 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 156975ec..2a90a082 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 @@ -102,7 +102,7 @@ protected int performDirectiveBehavior() { Codebase sourceCodebase; try { Expression sourceExpression = - RepositoryExpression.create(fromRepoEx.getRepositoryName()) + new RepositoryExpression(fromRepoEx.getRepositoryName()) .atRevision(revs.get(0).revId()) .translateTo(toProjectSpace); sourceCodebase = expressionEngine.createCodebase(sourceExpression, context); diff --git a/client/src/main/java/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreator.java b/client/src/main/java/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreator.java index 8ff3c9fe..06ce1124 100644 --- a/client/src/main/java/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreator.java +++ b/client/src/main/java/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreator.java @@ -103,6 +103,6 @@ public Codebase create(Map options) throws CodebaseCreationError return Codebase.create( archiveLocation, projectSpace, - RepositoryExpression.create(headClone.getRepositoryName()).withOptions(options)); + new RepositoryExpression(headClone.getRepositoryName()).withOptions(options)); } } 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 50267f9e..c6e238d3 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 @@ -77,8 +77,6 @@ public Codebase create(Map options) throws CodebaseCreationError Utils.filterFiles(exportPath, nonIgnoredFilePred, filesystem); return Codebase.create( - exportPath, - config.getProjectSpace(), - RepositoryExpression.create(name).withOptions(options)); + exportPath, config.getProjectSpace(), new RepositoryExpression(name).withOptions(options)); } } diff --git a/client/src/main/java/com/google/devtools/moe/client/testing/DummyCodebaseCreator.java b/client/src/main/java/com/google/devtools/moe/client/testing/DummyCodebaseCreator.java index 1fc8b149..88165e31 100644 --- a/client/src/main/java/com/google/devtools/moe/client/testing/DummyCodebaseCreator.java +++ b/client/src/main/java/com/google/devtools/moe/client/testing/DummyCodebaseCreator.java @@ -43,6 +43,6 @@ public Codebase create(Map options) throws CodebaseCreationError return Codebase.create( new File("/dummy/codebase/" + name + "/" + revId), projectSpace, - RepositoryExpression.create(name)); + new RepositoryExpression(name)); } } diff --git a/client/src/main/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java b/client/src/main/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java index ef1ede26..89ae908a 100644 --- a/client/src/main/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java +++ b/client/src/main/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java @@ -67,7 +67,7 @@ public Codebase create(Map options) throws CodebaseCreationError File codebasePath = getCodebasePath(new File(source)); String projectSpace = options.containsKey(PROJECT_SPACE_OPTION) ? options.get(PROJECT_SPACE_OPTION) : "public"; - RepositoryExpression expression = RepositoryExpression.create("file").withOptions(options); + RepositoryExpression expression = new RepositoryExpression("file").withOptions(options); return Codebase.create(codebasePath, projectSpace, expression); } diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/CodebaseTest.java b/client/src/test/java/com/google/devtools/moe/client/codebase/CodebaseTest.java index 9e19d89b..0b0eab94 100644 --- a/client/src/test/java/com/google/devtools/moe/client/codebase/CodebaseTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/codebase/CodebaseTest.java @@ -27,10 +27,10 @@ public class CodebaseTest extends TestCase { public void testCheckProjectSpace() throws Exception { - Codebase c = Codebase.create(new File("/foo"), "internal", RepositoryExpression.create("foo")); + Codebase c = Codebase.create(new File("/foo"), "internal", new RepositoryExpression("foo")); c.checkProjectSpace("internal"); try { - c = Codebase.create(new File("/foo"), "internal", RepositoryExpression.create("foo")); + c = Codebase.create(new File("/foo"), "internal", new RepositoryExpression("foo")); c.checkProjectSpace("public"); fail(); } catch (MoeProblem expected) { 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 index d4400621..f17b639e 100644 --- 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 @@ -25,8 +25,8 @@ 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.NoopFileSystem; 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; @@ -60,7 +60,7 @@ public class ExpressionProcessingTest extends TestCase { private final FileSystem noopFs = new NoopFileSystem(); public void testNoSuchRepository() throws Exception { - RepositoryExpression repositoryExpression = RepositoryExpression.create("foo"); + RepositoryExpression repositoryExpression = new RepositoryExpression("foo"); RepositoryCodebaseProcessor repositoryCodebaseProcessor = new RepositoryCodebaseProcessor(ui, () -> null); MoeProblem err = @@ -86,7 +86,7 @@ public void testFileCodebaseCreator() throws Exception { mockFs.setLifetime(EasyMock.eq(copyLocation), EasyMock.anyObject()); mockFs.cleanUpTempDirs(); - RepositoryExpression repoEx = RepositoryExpression.create("file").withOption("path", "/foo"); + RepositoryExpression repoEx = new RepositoryExpression("file").withOption("path", "/foo"); control.replay(); Codebase c = expressionEngine.createCodebase(repoEx, new NoopProjectContext()); @@ -99,7 +99,7 @@ public void testFileCodebaseCreator() throws Exception { public void testNoSuchEditor() throws Exception { ProjectContext context = new NoopProjectContext(); - RepositoryExpression repoExpression = RepositoryExpression.create("testrepo"); + RepositoryExpression repoExpression = new RepositoryExpression("testrepo"); ExpressionEngine expressionEngine = control.createMock(ExpressionEngine.class); expect(expressionEngine.createCodebase(repoExpression, context)).andReturn(mockRepoCodebase); EditedCodebaseProcessor processor = new EditedCodebaseProcessor(ui, expressionEngine); @@ -128,7 +128,7 @@ public ImmutableMap translators() { }; ExpressionEngine expressionEngine = control.createMock(ExpressionEngine.class); - RepositoryExpression repositoryExpression = RepositoryExpression.create("testrepo"); + RepositoryExpression repositoryExpression = new RepositoryExpression("testrepo"); expect(expressionEngine.createCodebase(repositoryExpression, context)) .andReturn(mockRepoCodebase); expect(mockRepoCodebase.projectSpace()).andReturn("internal").times(2); @@ -182,11 +182,11 @@ public ImmutableMap editors() { } }; - Codebase firstCb = Codebase.create(firstDir, "foo", RepositoryExpression.create("foo")); + Codebase firstCb = Codebase.create(firstDir, "foo", new RepositoryExpression("foo")); - Codebase secondCb = Codebase.create(secondDir, "public", RepositoryExpression.create("foo2")); + Codebase secondCb = Codebase.create(secondDir, "public", new RepositoryExpression("foo2")); - Codebase finalCb = Codebase.create(finalDir, "public", RepositoryExpression.create("foo3")); + Codebase finalCb = Codebase.create(finalDir, "public", new RepositoryExpression("foo3")); expect(cc.create(ImmutableMap.of())).andReturn(firstCb); expect(translatorEditor.edit(firstCb, ImmutableMap.of())).andReturn(secondCb); diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/ParserTest.java b/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/ParserTest.java index de3c7547..9bd91f4e 100644 --- a/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/ParserTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/ParserTest.java @@ -93,8 +93,8 @@ public void assertParseTermCompletely( String input, String identifier, ImmutableMap options) throws Parser.ParseError { Term r = Parser.parseTermCompletely(input); - assertEquals(identifier, r.identifier()); - assertEquals(options, r.options()); + assertEquals(identifier, r.getIdentifier()); + assertEquals(options, r.getOptions()); } public void assertParseTermCompletelyFails(String input, String errorMessage) { @@ -104,9 +104,9 @@ public void assertParseTermCompletelyFails(String input, String errorMessage) { "Successfully parsed invalid string: " + input + " into " - + r.identifier() + + r.getIdentifier() + " and " - + r.options()); + + r.getOptions()); } catch (Parser.ParseError e) { assertEquals("Cannot parse: " + errorMessage, e.getMessage()); } @@ -135,8 +135,8 @@ public void testParseTermCompletely() throws Exception { public void assertParseTerm(String input, String identifier, ImmutableMap options) throws Parser.ParseError { Term r = Parser.parseTerm(Parser.tokenize(input)); - assertEquals(identifier, r.identifier()); - assertEquals(options, r.options()); + assertEquals(identifier, r.getIdentifier()); + assertEquals(options, r.getOptions()); } public void assertParseTermFails(String input, String errorMessage) { @@ -146,9 +146,9 @@ public void assertParseTermFails(String input, String errorMessage) { "Successfully parsed invalid string: " + input + " into " - + r.identifier() + + r.getIdentifier() + " and " - + r.options()); + + r.getOptions()); } catch (Parser.ParseError e) { assertEquals("Cannot parse: " + errorMessage, e.getMessage()); } @@ -198,8 +198,8 @@ public void assertOperationListRoundTrip(String expected, String input) throws E List terms = Parser.parseOperationList(tokenize(input)); StringBuilder r = new StringBuilder(); for (Operation op : terms) { - r.append(op.operator()); - r.append(op.term()); + r.append(op.getOperator()); + r.append(op.getTerm()); } assertEquals(expected, r.toString()); } @@ -218,42 +218,41 @@ private void testParseExHelper(String exString, Expression ex) throws Exception public void testParseExpression() throws Exception { - testParseExHelper("internal", RepositoryExpression.create("internal")); + testParseExHelper("internal", new RepositoryExpression("internal")); testParseExHelper( - "internal(revision=1)", - RepositoryExpression.create("internal").withOption("revision", "1")); + "internal(revision=1)", new RepositoryExpression("internal").withOption("revision", "1")); testParseExHelper( - "internal>public", RepositoryExpression.create("internal").translateTo("public")); + "internal>public", new RepositoryExpression("internal").translateTo("public")); testParseExHelper( "internal(revision=1)>public", - RepositoryExpression.create("internal").atRevision("1").translateTo("public")); + new RepositoryExpression("internal").atRevision("1").translateTo("public")); testParseExHelper( - "internal|editor", RepositoryExpression.create("internal").editWith("editor", EMPTY_MAP)); + "internal|editor", new RepositoryExpression("internal").editWith("editor", EMPTY_MAP)); testParseExHelper( "internal(revision=1)|editor", - RepositoryExpression.create("internal") + new RepositoryExpression("internal") .withOption("revision", "1") .editWith("editor", EMPTY_MAP)); testParseExHelper( "internal|editor(locale=\"en_US\")", - RepositoryExpression.create("internal") + new RepositoryExpression("internal") .editWith("editor", ImmutableMap.of("locale", "en_US"))); testParseExHelper( "internal(revision=1)|editor(locale=\"en_US\")", - RepositoryExpression.create("internal") + new RepositoryExpression("internal") .withOption("revision", "1") .editWith("editor", ImmutableMap.of("locale", "en_US"))); testParseExHelper( "internal(revision=1)|editor(locale=\"en_US\")>public", - RepositoryExpression.create("internal") + new RepositoryExpression("internal") .withOption("revision", "1") .editWith("editor", ImmutableMap.of("locale", "en_US")) .translateTo("public")); @@ -265,14 +264,14 @@ private void testParseRepoExHelper(String exString, RepositoryExpression ex) thr } public void testParseRepositoryExpression() throws Exception { - testParseRepoExHelper("internal", RepositoryExpression.create("internal")); + testParseRepoExHelper("internal", new RepositoryExpression("internal")); testParseRepoExHelper( - "internal(revision=1)", RepositoryExpression.create("internal").atRevision("1")); + "internal(revision=1)", new RepositoryExpression("internal").atRevision("1")); testParseRepoExHelper( "file(path=\"/tmp\",projectSpace=internal)", - RepositoryExpression.create("file") + new RepositoryExpression("file") .withOption("path", "/tmp") .withOption("projectSpace", "internal")); diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpressionTest.java b/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpressionTest.java deleted file mode 100644 index b6ca8372..00000000 --- a/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpressionTest.java +++ /dev/null @@ -1,78 +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.expressions; - -import com.google.common.collect.ImmutableMap; -import com.google.devtools.moe.client.MoeProblem; -import com.google.devtools.moe.client.NoopFileSystemModule; -import com.google.devtools.moe.client.SystemCommandRunner; -import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.codebase.WriterFactory; -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.testing.DummyRepositoryFactory; -import com.google.devtools.moe.client.testing.TestingModule; -import javax.inject.Inject; -import javax.inject.Singleton; -import junit.framework.TestCase; - -public class RepositoryExpressionTest extends TestCase { - - @Inject Ui ui; - - // TODO(cgruber): Rework these when statics aren't inherent in the design. - @dagger.Component( - modules = {TestingModule.class, SystemCommandRunner.Module.class, NoopFileSystemModule.class}) - @Singleton - interface Component { - void inject(RepositoryExpressionTest instance); - } - - private WriterFactory writerFactory; - - @Override - protected void setUp() throws Exception { - super.setUp(); - Component c = DaggerRepositoryExpressionTest_Component.create(); - c.inject(this); - writerFactory = new WriterFactory(ui); - } - - public void testMakeWriter_NonexistentRepository() throws Exception { - try { - RepositoryExpression expression = RepositoryExpression.create("internal"); - writerFactory.createWriter(expression, new NoopProjectContext()); - fail(); - } catch (MoeProblem expected) { - assertEquals("No such repository 'internal' in the config. Found: []", expected.getMessage()); - } - } - - public void testMakeWriter_DummyRepository() throws Exception { - final RepositoryType.Factory repositoryFactory = new DummyRepositoryFactory(); - ProjectContext context = - new NoopProjectContext() { - @Override - public ImmutableMap repositories() { - return ImmutableMap.of("internal", repositoryFactory.create("internal", null)); - } - }; - RepositoryExpression expression = RepositoryExpression.create("internal"); - writerFactory.createWriter(expression, context); - } -} diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpressionTest.kt b/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpressionTest.kt new file mode 100644 index 00000000..9fe837d0 --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/RepositoryExpressionTest.kt @@ -0,0 +1,74 @@ +/* + * 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.expressions + +import com.google.common.collect.ImmutableMap +import com.google.common.truth.Truth.assertThat +import com.google.devtools.moe.client.SystemCommandRunner +import com.google.devtools.moe.client.MoeProblem +import com.google.devtools.moe.client.NoopFileSystemModule +import com.google.devtools.moe.client.codebase.WriterFactory +import com.google.devtools.moe.client.project.ProjectContext.NoopProjectContext +import com.google.devtools.moe.client.repositories.RepositoryType +import com.google.devtools.moe.client.testing.DummyRepositoryFactory +import com.google.devtools.moe.client.testing.TestingModule +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import javax.inject.Inject +import javax.inject.Singleton + +@RunWith(JUnit4::class) +class RepositoryExpressionTest { + + @Inject lateinit var writerFactory: WriterFactory + + init { + val component = DaggerRepositoryExpressionTest_Component.create() + component.inject(this) + } + + // TODO(cgruber): Rework these when statics aren't inherent in the design. + @dagger.Component(modules = + arrayOf(TestingModule::class, SystemCommandRunner.Module::class, NoopFileSystemModule::class)) + @Singleton + internal interface Component { + fun inject(test: RepositoryExpressionTest) + } + + @Test + fun testMakeWriter_NonexistentRepository() { + val error = Assert.assertThrows(MoeProblem::class.java) { + writerFactory.createWriter(RepositoryExpression("internal"), NoopProjectContext()) + } + assertThat(error) + .hasMessageThat() + .isEqualTo("No such repository 'internal' in the config. Found: []") + } + + @Test + fun testMakeWriter_DummyRepository() { + val repositoryFactory = DummyRepositoryFactory() + val context = object : NoopProjectContext() { + override fun repositories(): ImmutableMap { + return ImmutableMap.of("internal", repositoryFactory.create("internal", null)) + } + } + writerFactory.createWriter(RepositoryExpression("internal"), context) + } +} diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/TermTest.java b/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/TermTest.java deleted file mode 100644 index 367efcaf..00000000 --- a/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/TermTest.java +++ /dev/null @@ -1,39 +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.expressions; - -import junit.framework.TestCase; - -public class TermTest extends TestCase { - - public void testToString() throws Exception { - Term t; - - t = Term.create("internal"); - assertEquals("internal", t.toString()); - - t = Term.create("internal").withOption("foo", "bar"); - assertEquals("internal(foo=bar)", t.toString()); - - t = Term.create("internal").withOption("foo", "bar").withOption("baz", "quux"); - // We sort arguments. - assertEquals("internal(baz=quux,foo=bar)", t.toString()); - - t = Term.create("inte rnal").withOption("foo", "bar").withOption("baz", "qu ux"); - assertEquals("\"inte rnal\"(baz=\"qu ux\",foo=bar)", t.toString()); - } -} diff --git a/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/TermTest.kt b/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/TermTest.kt new file mode 100644 index 00000000..e7412d2a --- /dev/null +++ b/client/src/test/java/com/google/devtools/moe/client/codebase/expressions/TermTest.kt @@ -0,0 +1,44 @@ +/* + * 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.expressions + +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(JUnit4::class) +class TermTest { + @Test fun testSimpleToString() { + assertThat(Term("internal").toString()).isEqualTo("internal") + } + + @Test fun testToStringWithOption() { + val term = Term("internal").withOption("foo", "bar") + assertThat(term.toString()).isEqualTo("internal(foo=bar)") + } + + @Test fun testToStringWithSortedOptions() { + val term = Term("internal").withOption("foo", "bar").withOption("baz", "quux") + assertThat(term.toString()).isEqualTo("internal(baz=quux,foo=bar)") + } + + @Test fun testToStringWithSpaces() { + val term = Term("inte rnal").withOption("foo", "bar").withOption("baz", "qu ux") + assertThat(term.toString()).isEqualTo("\"inte rnal\"(baz=\"qu ux\",foo=bar)") + } +} 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 a5eba2f4..544be22b 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 @@ -40,7 +40,7 @@ public class GitWriterTest extends TestCase { private final File codebaseRoot = new File("/codebase"); private final File writerRoot = new File("/writer"); private final String projectSpace = "public"; - private final RepositoryExpression cExp = RepositoryExpression.create(projectSpace); + private final RepositoryExpression cExp = new RepositoryExpression(projectSpace); private final Codebase codebase = Codebase.create(codebaseRoot, projectSpace, cExp); private final GitClonedRepository mockRevClone = control.createMock(GitClonedRepository.class); private final RepositoryConfig mockRepoConfig = control.createMock(RepositoryConfig.class); 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 482ab48c..70a3d67c 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 @@ -39,8 +39,7 @@ public class HgWriterTest extends TestCase { private static final File CODEBASE_ROOT = new File("/codebase"); private static final File WRITER_ROOT = new File("/writer"); private static final String PROJECT_SPACE = "public"; - private static final RepositoryExpression CODEBASE_EXPR = - RepositoryExpression.create(PROJECT_SPACE); + private static final RepositoryExpression CODEBASE_EXPR = new RepositoryExpression(PROJECT_SPACE); private final IMocksControl control = EasyMock.createControl(); private final FileSystem mockFs = control.createMock(FileSystem.class); 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 d6793f91..3f22f76e 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 @@ -95,7 +95,7 @@ private File f(String filename) { private RepositoryExpression e( String creatorIdentifier, ImmutableMap creatorOptions) { - return RepositoryExpression.create(creatorIdentifier).withOptions(creatorOptions); + return new RepositoryExpression(creatorIdentifier).withOptions(creatorOptions); } public void testPutEmptyCodebase() throws Exception { diff --git a/client/src/test/java/com/google/devtools/moe/client/tools/CodebaseDifferenceTest.java b/client/src/test/java/com/google/devtools/moe/client/tools/CodebaseDifferenceTest.java index 7c7bf7fa..fac84058 100644 --- a/client/src/test/java/com/google/devtools/moe/client/tools/CodebaseDifferenceTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/tools/CodebaseDifferenceTest.java @@ -31,9 +31,9 @@ public class CodebaseDifferenceTest extends TestCase { private final FileSystem filesystem = mock(FileSystem.class); private final Codebase c1 = - Codebase.create(new File("/1"), "internal", RepositoryExpression.create("ignored")); + Codebase.create(new File("/1"), "internal", new RepositoryExpression("ignored")); private final Codebase c2 = - Codebase.create(new File("/2"), "internal", RepositoryExpression.create("ignored")); + Codebase.create(new File("/2"), "internal", new RepositoryExpression("ignored")); private final File f1 = new File("/1/foo"); private final File f2 = new File("/2/foo"); private final FileDifference.FileDiffer fileDiffer = mock(FileDifference.FileDiffer.class); diff --git a/client/src/test/java/com/google/devtools/moe/client/tools/PatchCodebaseDifferenceRendererTest.java b/client/src/test/java/com/google/devtools/moe/client/tools/PatchCodebaseDifferenceRendererTest.java index 75b68e70..4327fd9f 100644 --- a/client/src/test/java/com/google/devtools/moe/client/tools/PatchCodebaseDifferenceRendererTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/tools/PatchCodebaseDifferenceRendererTest.java @@ -25,7 +25,7 @@ public class PatchCodebaseDifferenceRendererTest extends TestCase { private static Codebase makeCodebase(String name) throws Exception { - return Codebase.create(new File("/" + name), "public", RepositoryExpression.create(name)); + return Codebase.create(new File("/" + name), "public", new RepositoryExpression(name)); } public void testRender() throws Exception { 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 bba0b41e..f75e8c8a 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 @@ -50,10 +50,10 @@ public void testEdit() throws Exception { RenamingEditor inverseRenamey = new RenamingEditor(mockFs, gson, "renamey", config); Codebase input = - Codebase.create(new File("/input"), "public", RepositoryExpression.create("input")); + Codebase.create(new File("/input"), "public", new RepositoryExpression("input")); Codebase destination = Codebase.create( - new File("/destination"), "public", RepositoryExpression.create("destination")); + new File("/destination"), "public", new RepositoryExpression("destination")); expect(mockFs.getTemporaryDirectory("inverse_rename_run_")).andReturn(new File("/output")); diff --git a/client/src/test/java/com/google/devtools/moe/client/translation/editors/PatchingEditorTest.java b/client/src/test/java/com/google/devtools/moe/client/translation/editors/PatchingEditorTest.java index fa83934e..320c4505 100644 --- a/client/src/test/java/com/google/devtools/moe/client/translation/editors/PatchingEditorTest.java +++ b/client/src/test/java/com/google/devtools/moe/client/translation/editors/PatchingEditorTest.java @@ -41,7 +41,7 @@ public void testNoSuchPatchFile() throws Exception { File patcherRun = new File("/patcher_run_foo"); File codebaseFile = new File("/codebase"); Codebase codebase = - Codebase.create(codebaseFile, "internal", RepositoryExpression.create("ignored")); + Codebase.create(codebaseFile, "internal", new RepositoryExpression("ignored")); Map options = new HashMap<>(); options.put("file", "notFile"); @@ -65,7 +65,7 @@ public void testPatching() throws Exception { File codebaseFile = new File("/codebase"); Codebase codebase = - Codebase.create(codebaseFile, "internal", RepositoryExpression.create("ignored")); + Codebase.create(codebaseFile, "internal", new RepositoryExpression("ignored")); Map options = new HashMap<>(); options.put("file", "/patchfile"); 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 09113110..2e05efad 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 @@ -114,7 +114,7 @@ public void testCopyDirectoryAndRename() throws Exception { public void testEdit() throws Exception { File codebaseFile = new File("/codebase/"); Codebase codebase = - Codebase.create(codebaseFile, "internal", RepositoryExpression.create("ignored")); + Codebase.create(codebaseFile, "internal", new RepositoryExpression("ignored")); File oldSubFile = new File("/codebase/moe.txt"); File renameRun = new File("/rename_run_foo"); 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 c2924b10..ea2d9d65 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 @@ -54,7 +54,7 @@ public void testScrubbing() throws Exception { Lazy executable = EagerLazy.fromInstance(scrubberBin); Codebase codebase = - Codebase.create(codebaseFile, "internal", RepositoryExpression.create("ignored")); + Codebase.create(codebaseFile, "internal", new RepositoryExpression("ignored")); expect(fileSystem.getTemporaryDirectory("scrubber_run_")).andReturn(scrubberRun); expect( 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 dd2d64ea..8151137b 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 @@ -46,7 +46,7 @@ public void testShellStuff() throws Exception { File codebaseFile = new File("/codebase"); Codebase codebase = - Codebase.create(codebaseFile, "internal", RepositoryExpression.create("ignored")); + Codebase.create(codebaseFile, "internal", new RepositoryExpression("ignored")); expect(fileSystem.getTemporaryDirectory("shell_run_")).andReturn(shellRun); fileSystem.copyDirectory(codebaseFile, shellRun); diff --git a/pom.xml b/pom.xml index 8a9f59db..260fd48a 100644 --- a/pom.xml +++ b/pom.xml @@ -8,25 +8,32 @@ client + 1.2.30 2.9.9 - 23.0 + 25.1-jre 2.8.1 2.5.0 1.1 - 2.11 - 1.5 + 2.16 + 1.6.2 1.0-beta5 - 0.4.4 + 0.8.0 3.0.2 2.32 4.13-SNAPSHOT - 0.35 + 0.42 3.1 1.9.5 - 2.1.1 + 2.3.1 + true + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + joda-time joda-time @@ -128,11 +135,19 @@ src/main/java + + **/*.java + **/*.kt + src/test/java + + **/*.java + **/*.kt +