Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'private/issue/375' into 0.6-develop
- Loading branch information
Showing
4 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
.../asakusa-gradle-plugins/src/main/groovy/com/asakusafw/gradle/tasks/RunBatchappTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright 2011-2014 Asakusa Framework Team. | ||
* | ||
* 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.asakusafw.gradle.tasks | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.InvalidUserDataException | ||
import org.gradle.api.Nullable | ||
import org.gradle.api.file.FileCollection | ||
import org.gradle.api.internal.tasks.options.Option | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputFiles | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.process.JavaExecSpec | ||
|
||
import com.asakusafw.gradle.tasks.internal.ResolutionUtils | ||
|
||
/** | ||
* Gradle Task for Running Asakusa batch application. | ||
* @since 0.6.1 | ||
*/ | ||
class RunBatchappTask extends DefaultTask { | ||
|
||
/** | ||
* The logback configuration for the tool. | ||
*/ | ||
@Nullable | ||
File logbackConf | ||
|
||
/** | ||
* The max heap size for the tool. | ||
*/ | ||
@Nullable | ||
String maxHeapSize | ||
|
||
/** | ||
* The Java system properties. | ||
*/ | ||
Map<Object, Object> systemProperties = [:] | ||
|
||
/** | ||
* The Java VM arguments. | ||
*/ | ||
List<Object> jvmArgs = [] | ||
|
||
/** | ||
* The tool class path. | ||
*/ | ||
@InputFiles | ||
FileCollection toolClasspath = project.files() | ||
|
||
/** | ||
* The target batch ID. | ||
*/ | ||
@Input | ||
String batchId | ||
|
||
/** | ||
* The target batch arguments. | ||
*/ | ||
@Input | ||
Map<Object, Object> batchArguments = [:] | ||
|
||
/** | ||
* Sets the target batch ID. | ||
* @param batchId the target batch ID | ||
*/ | ||
@Option(option = 'id', description = 'The target batch ID') | ||
void setBatchId(String batchId) { | ||
this.batchId = batchId | ||
} | ||
|
||
@Option(option = 'arguments', description = 'The target batch arguments separated by comma') | ||
void setEncodedBatchArguments(String encoded) { | ||
Map<String, String> args = [:] | ||
StringBuilder buf = new StringBuilder() | ||
boolean sawEscape = false | ||
for (char c in encoded.toCharArray()) { | ||
if (sawEscape) { | ||
buf.append c | ||
sawEscape = false | ||
continue | ||
} else if (c == '\\') { | ||
sawEscape = true | ||
} else if (c == ',') { | ||
addArg buf.toString(), args | ||
buf.setLength 0 | ||
} else { | ||
buf.append c | ||
} | ||
} | ||
addArg buf.toString(), args | ||
getBatchArguments().putAll(args) | ||
} | ||
|
||
private void addArg(String string, Map<String, String> kvs) { | ||
int index = string.indexOf '=' | ||
if (index < 0) { | ||
throw new InvalidUserDataException("Invalid batch argument: \"${string}\"") | ||
} | ||
kvs.put string.substring(0, index), string.substring(index + 1) | ||
} | ||
|
||
/** | ||
* Performs this task. | ||
*/ | ||
@TaskAction | ||
void perform() { | ||
project.javaexec { JavaExecSpec spec -> | ||
spec.main = 'com.asakusafw.testdriver.tools.runner.BatchTestRunner' | ||
spec.classpath = this.getToolClasspath() | ||
spec.jvmArgs = ResolutionUtils.resolveToStringList(this.getJvmArgs()) | ||
if (this.getMaxHeapSize()) { | ||
spec.maxHeapSize = this.getMaxHeapSize() | ||
} | ||
if (this.getLogbackConf()) { | ||
spec.systemProperties += ['logback.configurationFile' : this.getLogbackConf().absolutePath] | ||
} | ||
spec.systemProperties += ResolutionUtils.resolveToStringMap(this.getSystemProperties()) | ||
spec.args += ['--batch', this.getBatchId()] | ||
for (Map.Entry<String, String> entry in ResolutionUtils.resolveToStringMap(this.getBatchArguments()).entrySet()) { | ||
spec.args += ['-A', "${entry.key}=${entry.value}"] | ||
} | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...gradle-plugins/src/main/groovy/com/asakusafw/gradle/tasks/internal/ResolutionUtils.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2011-2014 Asakusa Framework Team. | ||
* | ||
* 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.asakusafw.gradle.tasks.internal | ||
|
||
import java.util.concurrent.Callable | ||
|
||
/** | ||
* Utilities for resolving values. | ||
* @since 0.6.1 | ||
*/ | ||
final class ResolutionUtils { | ||
|
||
/** | ||
* Resolves a value to a string. | ||
* @param value the target value | ||
* @return the resolved string | ||
*/ | ||
static String resolveToString(Object value) { | ||
if (value == null) { | ||
return null | ||
} else if (value instanceof String) { | ||
return value | ||
} else if (value instanceof Closure<?>) { | ||
Closure<?> c = value | ||
return resolveToString(c.call()) | ||
} else if (value instanceof Callable<?>) { | ||
Callable<?> c = value | ||
return resolveToString(c.call()) | ||
} else { | ||
return String.valueOf(value) | ||
} | ||
} | ||
|
||
/** | ||
* Resolves values to a string list. | ||
* @param value the target values | ||
* @return the resolved string list | ||
*/ | ||
static List<String> resolveToStringList(Iterable<?> values) { | ||
List<String> results = [] | ||
for (Object arg in values) { | ||
resolveInto(arg, results) | ||
} | ||
return results | ||
} | ||
|
||
static Map<String, String> resolveToStringMap(Map<?, ?> values) { | ||
Map<String, String> results = [:] | ||
for (Map.Entry<?, ?> entry in values.entrySet()) { | ||
String key = resolveToString(entry.key) | ||
if (key != null) { | ||
results.put key, resolveToString(entry.value) | ||
} | ||
} | ||
return results | ||
} | ||
|
||
private static void resolveInto(Object arg, List<String> results) { | ||
if (arg instanceof String) { | ||
results.add(results) | ||
} else if (arg instanceof Closure<?>) { | ||
Closure<?> c = arg | ||
resolveInto(c.call(), results) | ||
} else if (arg instanceof Callable<?>) { | ||
Callable<?> c = arg | ||
resolveInto(c.call(), results) | ||
} else if (arg instanceof Iterable<?>) { | ||
for (Object element in (Iterable<?>) arg) { | ||
resolveInto(element, results) | ||
} | ||
} else { | ||
resolveInto(String.valueOf(arg), results) | ||
} | ||
} | ||
|
||
private ResolutionUtils() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters