Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

...
  • 1 commit
  • 7 files changed
  • 0 commit comments
  • 1 contributor
24 extras/groovy-eclipse-compiler-tests/.classpath
View
@@ -1,6 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2  extras/groovy-eclipse-compiler-tests/pom.xml
View
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler-tests</artifactId>
- <version>2.7.1-01-SNAPSHOT</version>
+ <version>2.7.2-01-SNAPSHOT</version>
<name>Tests for the groovy-eclipse-compiler</name>
<url>http://groovy.codehaus.org/Eclipse+Plugin</url>
15 extras/groovy-eclipse-compiler/pom.xml
View
@@ -58,7 +58,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
- <version>1.8.1</version>
+ <version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
@@ -84,8 +84,17 @@
<id>codehaus.org</id>
<url>http://repository.codehaus.org</url>
</repository>
- </repositories>
-
+ <repository>
+ <id>plexus.snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/plexus-snapshots/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
<build>
<extensions>
<extension>
59 ...as/groovy-eclipse-compiler/src/main/java/org/codehaus/groovy/eclipse/compiler/GroovyEclipseCompiler.java
View
@@ -37,7 +37,9 @@
import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.compiler.CompilerError;
import org.codehaus.plexus.compiler.CompilerException;
+import org.codehaus.plexus.compiler.CompilerMessage;
import org.codehaus.plexus.compiler.CompilerOutputStyle;
+import org.codehaus.plexus.compiler.CompilerResult;
import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
@@ -213,15 +215,15 @@ public GroovyEclipseCompiler() {
}
@SuppressWarnings("rawtypes")
- public List compile(CompilerConfiguration config) throws CompilerException {
+ public CompilerResult performCompile(CompilerConfiguration config) throws CompilerException {
String[] args = createCommandLine(config);
if (args.length == 0) {
getLogger().info("Nothing to compile - all classes are up to date");
- return Collections.emptyList();
+ return new CompilerResult(true, Collections.<CompilerMessage>emptyList());
}
- List<CompilerError> messages;
+ CompilerResult result;
if (config.isFork()) {
String executable = config.getExecutable();
@@ -235,16 +237,16 @@ public List compile(CompilerConfiguration config) throws CompilerException {
}
String groovyEclipseLocation = getGroovyEclipseBatchLocation();
- messages = compileOutOfProcess(config, executable, groovyEclipseLocation, args);
+ result = compileOutOfProcess(config, executable, groovyEclipseLocation, args);
} else {
Progress progress = new Progress();
Main main = new Main(new PrintWriter(System.out), new PrintWriter(System.err), false/* systemExit */,
null/* options */, progress);
- boolean result = main.compile(args);
+ boolean hasResult = main.compile(args);
- messages = formatResult(main, result);
+ result = formatResult(main, hasResult);
}
- return messages;
+ return result;
}
private File[] recalculateStaleFiles(CompilerConfiguration config) throws CompilerException {
@@ -266,15 +268,14 @@ private boolean startsWithHyphen(Object key) {
return null != key && String.class.isInstance(key) && ((String) key).startsWith("-");
}
- private List<CompilerError> formatResult(Main main, boolean result) {
- if (result) {
- return Collections.EMPTY_LIST;
- } else {
- String error = main.globalErrorsCount == 1 ? "error" : "errors";
- String warning = main.globalWarningsCount == 1 ? "warning" : "warnings";
- return Collections.singletonList(new CompilerError("Found " + main.globalErrorsCount + " " + error + " and "
- + main.globalWarningsCount + " " + warning + ".", true));
- }
+ private CompilerResult formatResult(Main main, boolean hasResult) {
+ CompilerResult result = new CompilerResult();
+ result.setSuccess(hasResult);
+ String error = main.globalErrorsCount == 1 ? "error" : "errors";
+ String warning = main.globalWarningsCount == 1 ? "warning" : "warnings";
+ result.setCompilerMessages(Collections.singletonList(new CompilerMessage("Found " + main.globalErrorsCount + " " + error + " and "
+ + main.globalWarningsCount + " " + warning + ".", true)));
+ return result;
}
private List<String> composeSourceFiles(File[] sourceFiles) {
@@ -488,7 +489,7 @@ private boolean startsWithHyphen(Object key) {
* @return List of CompilerError objects with the errors encountered.
* @throws CompilerException
*/
- private List<CompilerError> compileOutOfProcess(CompilerConfiguration config, String executable, String groovyEclipseLocation,
+ private CompilerResult compileOutOfProcess(CompilerConfiguration config, String executable, String groovyEclipseLocation,
String[] args) throws CompilerException {
Commandline cli = new Commandline();
@@ -524,7 +525,7 @@ private boolean startsWithHyphen(Object key) {
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int returnCode;
- List<CompilerError> messages;
+ List<CompilerMessage> messages;
if ((getLogger() != null) && getLogger().isDebugEnabled()) {
File commandLineFile = new File(config.getOutputLocation(), "greclipse."
@@ -552,15 +553,17 @@ private boolean startsWithHyphen(Object key) {
throw new CompilerException("Error while executing the external compiler.", e);
}
+ boolean isSuccess = true;
if ((returnCode != 0) && messages.isEmpty()) {
if (err.getOutput().length() == 0) {
throw new CompilerException("Unknown error trying to execute the external compiler: " + EOL + cli.toString());
} else {
- messages.add(new CompilerError("Failure executing groovy-eclipse compiler:" + EOL + err.getOutput(), true));
+ isSuccess = false;
+ messages.add(new CompilerMessage("Failure executing groovy-eclipse compiler:" + EOL + err.getOutput(), true));
}
}
- return messages;
+ return new CompilerResult(isSuccess, messages);
}
/**
@@ -573,8 +576,8 @@ private boolean startsWithHyphen(Object key) {
* @return List of CompilerError objects
* @throws IOException
*/
- List<CompilerError> parseModernStream(int exitCode, BufferedReader input) throws IOException {
- List<CompilerError> errors = new ArrayList<CompilerError>();
+ List<CompilerMessage> parseModernStream(int exitCode, BufferedReader input) throws IOException {
+ List<CompilerMessage> errors = new ArrayList<CompilerMessage>();
String line;
@@ -593,7 +596,7 @@ private boolean startsWithHyphen(Object key) {
}
if ((buffer.length() == 0) && line.startsWith("error: ")) {
- errors.add(new CompilerError(line, true));
+ errors.add(new CompilerMessage(line, true));
} else if ((buffer.length() == 0) && isNote(line)) {
// skip, JDK 1.5 telling us deprecated APIs are used but
// -Xlint:deprecation isn't set
@@ -627,7 +630,7 @@ private static boolean isNote(String line) {
* output line from the compiler
* @return the CompilerError object
*/
- static CompilerError parseModernError(int exitCode, String error) {
+ static CompilerMessage parseModernError(int exitCode, String error) {
StringTokenizer tokens = new StringTokenizer(error, ":");
boolean isError = exitCode != 0;
@@ -733,13 +736,13 @@ static CompilerError parseModernError(int exitCode, String error) {
endcolumn = context.length();
}
- return new CompilerError(file, isError, line, startcolumn, line, endcolumn, message.trim());
+ return new CompilerMessage(file, isError, line, startcolumn, line, endcolumn, message.trim());
} catch (NoSuchElementException e) {
- return new CompilerError("no more tokens - could not parse error message: " + error, isError);
+ return new CompilerMessage("no more tokens - could not parse error message: " + error, isError);
} catch (NumberFormatException e) {
- return new CompilerError("could not parse error message: " + error, isError);
+ return new CompilerMessage("could not parse error message: " + error, isError);
} catch (Exception e) {
- return new CompilerError("could not parse error message: " + error, isError);
+ return new CompilerMessage("could not parse error message: " + error, isError);
}
}
9 extras/groovy-eclipse-maven-tests/pom.xml
View
@@ -40,7 +40,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<compilerArgument>nowarn</compilerArgument>
@@ -50,7 +50,7 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
- <version>2.7.0-01</version>
+ <version>2.7.1-01-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
@@ -63,6 +63,11 @@
<version>1.2.16</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-compiler-api</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</plugin>
</plugins>
59 extras/groovy-eclipse-maven-tests/src/main/java/com/any/DynamicQuery.groovy
View
@@ -0,0 +1,59 @@
+package com.any
+
+import groovy.transform.TypeChecked
+
+@TypeChecked
+class DynamicQuery {
+
+ public String createQueryNew(Map queryParams, String initial, Map whereClauseElements, List orderBys = []) {
+ validateNoParamsThatAreNotInWhereClauseElements(queryParams, whereClauseElements)
+ String whereClause = makeAndedWhereClause(queryParams, whereClauseElements)
+ initial + (whereClause == "" ? "" : " WHERE " + whereClause) + orderBy(orderBys)
+ }
+
+ private validateNoParamsThatAreNotInWhereClauseElements(Map queryParams, Map whereClauseElements){
+ List invalidKeys = queryParams.findAll {
+ String key, String value ->
+ !whereClauseElements.containsKey(key)}.collect{ Map.Entry it ->it.key}
+ if(! invalidKeys.isEmpty()){
+ throw new IllegalArgumentException("At least one invalid key has been found. Invalid keys are ${invalidKeys}." + " Keys should be in this set: ${whereClauseElements.keySet()}")
+ }
+ }
+
+ private String orderBy(List orderBys){
+ List cleaned = orderBys.findAll{String elem -> stringNotEmpty(elem)}
+ cleaned.isEmpty() ? "" : " ORDER BY " + cleaned.join(" ")
+ }
+
+ public String makeAndedWhereClause(Map queryParams, Map
+whereClauseElements) {
+ and(makeWhereClauseElements(queryParams, whereClauseElements))
+ }
+
+ public String and(List elements){
+ elements.join(" AND ")
+ }
+
+ public List makeWhereClauseElements(Map queryParams, Map
+whereClauseElements) {
+ filterOutIMapEntriesWithEmptyValues(queryParams,
+whereClauseElements).
+ collect {String key, String value ->
+resolveAgainstMap(whereClauseElements, key, value)}
+ }
+
+ private Map filterOutIMapEntriesWithEmptyValues(Map queryParams, Map
+whereClauseElements){
+ queryParams.findAll{String key, String value ->
+stringNotEmpty(value)}
+ }
+
+ private String resolveAgainstMap(Map<String, String>
+whereClauseElements, String key, String value) {
+ "${whereClauseElements[key].replace("@${key}@",value)}"
+ }
+
+ private boolean stringNotEmpty(String str) {
+ str != null && str.trim() != ""
+ }
+}
141 extras/groovy-eclipse-maven-tests/src/test/java/com/any/DynamicQueryTest.groovy
View
@@ -0,0 +1,141 @@
+package com.any
+
+import junit.framework.TestCase
+import groovy.transform.TypeChecked
+
+@TypeChecked
+class DynamicQueryTest extends TestCase {
+ private DynamicQuery queryCreator = new DynamicQuery()
+ String userName = "Byron"
+ String afterDate = "1901"
+ String beforeDate = "1900"
+
+ Map whereClauseElements = [
+ userName: "user = '@userName@'",
+ afterDate: "updatedOn > '@afterDate@'",
+ beforeDate: "updatedOn < '@beforeDate@'",
+ promptName: "ca.configuration.icmInput.description LIKE '%@promptName@%'",
+ customerHhrr:
+"ca.configuration.datamodeBuildLevel.datamode.customer.hhrr = '@customerHhrr@'",
+ datamodeName:
+"ca.configuration.datamodeBuildLevel.datamode.datamode = '@datamodeName@'",
+ buildLabel:
+"ca.configuration.datamodeBuildLevel.buildnumber.label = '@buildLabel@'"
+ ]
+
+ public void testNoWhereClause() {
+ String query = createQuery([:], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca", query)
+ }
+
+ public void testNoWhereClauseAndSortTypeAndOrderTypeNew(){
+ String sortType = "hey"
+ String orderType = "there"
+ String query = createQuery([:], sortType, orderType)
+ assertEquals ("SELECT ca FROM ConfigurationAudit as ca ORDER BY hey there", query)
+ }
+
+ public void testNoWhereClauseAndSortTypeAndNoOrderTypeNew(){
+ String query = createQuery([:], "hey", "")
+ assertEquals ("SELECT ca FROM ConfigurationAudit as ca ORDER BY hey", query)
+ }
+
+ public void testNoWhereClauseAndNoSortTypeAndOrderTypeNew(){
+ String query = createQuery([:], "", "there")
+ assertEquals ("SELECT ca FROM ConfigurationAudit as ca ORDER BY there", query)
+ }
+
+ public void testNoWhereClauseAndNoSortTypeAndNoOrderTypeNew(){
+ String query = createQuery([:], "", "")
+ assertEquals ("SELECT ca FROM ConfigurationAudit as ca", query)
+ }
+
+ public void testOnlyUserName() {
+ String query = createQuery([userName:userName], null, null)
+ assertEquals ("SELECT ca FROM ConfigurationAudit as ca WHERE user = '${userName}'", query)
+ }
+
+ public void testUserNameAndAfterDate() {
+ String query = createQuery([userName:userName,
+afterDate:afterDate], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca WHERE user = '${userName}' AND updatedOn > '${afterDate}'", query)
+ }
+
+ public void testAfterDateAndNoUserName() {
+ userName = null
+ String query = createQuery([userName:userName,
+afterDate:afterDate], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca WHERE updatedOn > '${afterDate}'", query)
+ }
+
+ public void testBeforeDateAndAfterDateAndUserName() {
+ String query = createQuery([userName: userName,afterDate:
+afterDate, beforeDate: beforeDate], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca WHERE user = '${userName}' AND updatedOn > '${afterDate}' AND updatedOn < '${beforeDate}'", query)
+ }
+
+ public void testBeforeDateAndAfterDateAndNoUserNameNew() {
+ String userName = ""
+ String query = createQuery([userName: userName,afterDate:
+afterDate, beforeDate: beforeDate], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca WHERE updatedOn > '${afterDate}' AND updatedOn < '${beforeDate}'", query)
+ }
+
+ public void testBeforeDateAndNoAfterDateAndUserName() {
+ String afterDate = ""
+ String query = createQuery([userName: userName,afterDate:
+afterDate, beforeDate: beforeDate], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca WHERE user = '${userName}' AND updatedOn < '${beforeDate}'", query)
+ }
+
+ public void testBeforeDateAndNoAfterDateAndNoUserName() {
+ String userName = ""
+ String afterDate = ""
+ String query = createQuery([userName: userName,afterDate:
+afterDate, beforeDate: beforeDate], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca WHERE updatedOn < '${beforeDate}'", query)
+ }
+
+ public void testPromptName() {
+ String promptName = "thePrompt"
+ String query = createQuery([promptName:promptName], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca WHERE ca.configuration.icmInput.description LIKE '%thePrompt%'", query)
+ }
+
+ public void testCustomerHhrr() {
+ String customerHhrr = "aCustomer"
+ String query = createQuery([customerHhrr:customerHhrr], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca WHERE ca.configuration.datamodeBuildLevel.datamode.customer.hhrr = 'aCustomer'",
+query)
+ }
+
+ public void testDatamodeName() {
+ String datamodeName = "aDatamodeName"
+ String query = createQuery([datamodeName:datamodeName], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca WHERE ca.configuration.datamodeBuildLevel.datamode.datamode = '${datamodeName}'",
+query)
+ }
+ public void testBuildLabel() {
+ String buildLabel = "aBuildLabel"
+ String query = createQuery([buildLabel:buildLabel], null, null)
+ assertEquals("SELECT ca FROM ConfigurationAudit as ca WHERE ca.configuration.datamodeBuildLevel.buildnumber.label = '${buildLabel}'",
+query)
+ }
+
+ public void testInvalidQueryParam() {
+ String paramThatDoesNotExistAsKeyInWhereClauseElements = "xx"
+ try {
+ createQuery([(paramThatDoesNotExistAsKeyInWhereClauseElements):
+"whoCares?"], null, null)
+ fail()
+ } catch (IllegalArgumentException ex) {
+
+assertTrue(ex.message.contains(paramThatDoesNotExistAsKeyInWhereClauseElements))
+ }
+ }
+
+ private String createQuery(Map queryParams, String sortType, String orderType){
+ queryCreator.createQueryNew(queryParams, "SELECT ca FROM ConfigurationAudit as ca", whereClauseElements, [sortType, orderType])
+ }
+}
+

No commit comments for this range

Something went wrong with that request. Please try again.