Misc: Fix compiler argument usages after refactoring

This commit is contained in:
Alexey Sedunov
2017-08-03 02:24:10 +03:00
parent 41e5840298
commit aed9d3899e
13 changed files with 63 additions and 59 deletions
@@ -89,7 +89,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
environment: GradleCompilerEnvironment environment: GradleCompilerEnvironment
): ExitCode { ): ExitCode {
val buildFile = makeModuleFile( val buildFile = makeModuleFile(
args.moduleName, args.moduleName!!,
isTest = false, isTest = false,
outputDir = args.destinationAsFile, outputDir = args.destinationAsFile,
sourcesToCompile = sourcesToCompile, sourcesToCompile = sourcesToCompile,
@@ -66,8 +66,8 @@ open class KaptGenerateStubsTask : KotlinCompile() {
val args = createCompilerArgs() val args = createCompilerArgs()
kotlinCompileTask.setupCompilerArgs(args) kotlinCompileTask.setupCompilerArgs(args)
args.pluginClasspaths = (pluginOptions.classpath + args.pluginClasspaths).toSet().toTypedArray() args.pluginClasspaths = (pluginOptions.classpath + args.pluginClasspaths!!).toSet().toTypedArray()
args.pluginOptions = (pluginOptions.arguments + args.pluginOptions).toTypedArray() args.pluginOptions = (pluginOptions.arguments + args.pluginOptions!!).toTypedArray()
args.verbose = project.hasProperty("kapt.verbose") && project.property("kapt.verbose").toString().toBoolean() == true args.verbose = project.hasProperty("kapt.verbose") && project.property("kapt.verbose").toString().toBoolean() == true
args.classpathAsList = this.compileClasspath.toList() args.classpathAsList = this.compileClasspath.toList()
args.destinationAsFile = this.destinationDir args.destinationAsFile = this.destinationDir
@@ -55,8 +55,8 @@ open class KaptTask : ConventionTask() {
val args = K2JVMCompilerArguments() val args = K2JVMCompilerArguments()
kotlinCompileTask.setupCompilerArgs(args) kotlinCompileTask.setupCompilerArgs(args)
args.pluginClasspaths = (pluginOptions.classpath + args.pluginClasspaths).toSet().toTypedArray() args.pluginClasspaths = (pluginOptions.classpath + args.pluginClasspaths!!).toSet().toTypedArray()
args.pluginOptions = (pluginOptions.arguments + args.pluginOptions).toTypedArray() args.pluginOptions = (pluginOptions.arguments + args.pluginOptions!!).toTypedArray()
args.verbose = project.hasProperty("kapt.verbose") && project.property("kapt.verbose").toString().toBoolean() == true args.verbose = project.hasProperty("kapt.verbose") && project.property("kapt.verbose").toString().toBoolean() == true
val messageCollector = GradleMessageCollector(logger) val messageCollector = GradleMessageCollector(logger)
@@ -43,7 +43,7 @@ internal open class KotlinCompileCommon : AbstractKotlinCompile<K2MetadataCompil
with(args) { with(args) {
classpath = classpathList.joinToString(File.pathSeparator) classpath = classpathList.joinToString(File.pathSeparator)
destination = destinationDir.canonicalPath destination = destinationDir.canonicalPath
freeArgs = sourceRoots.kotlinSourceFiles.map { it.canonicalPath } freeArgs = sourceRoots.kotlinSourceFiles.mapTo(ArrayList<String>()) { it.canonicalPath }
} }
val messageCollector = GradleMessageCollector(logger) val messageCollector = GradleMessageCollector(logger)
@@ -96,11 +96,11 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
@Override @Override
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException { protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
arguments.outputFile = outputFile; arguments.setOutputFile(outputFile);
arguments.noStdlib = true; arguments.setNoStdlib(true);
arguments.metaInfo = metaInfo; arguments.setMetaInfo(metaInfo);
arguments.moduleKind = moduleKind; arguments.setModuleKind(moduleKind);
arguments.main = main; arguments.setMain(main);
List<String> libraries; List<String> libraries;
try { try {
@@ -109,11 +109,11 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
throw new MojoExecutionException("Unresolved dependencies", e); throw new MojoExecutionException("Unresolved dependencies", e);
} }
getLog().debug("libraries: " + libraries); getLog().debug("libraries: " + libraries);
arguments.libraries = StringUtil.join(libraries, File.pathSeparator); arguments.setLibraries(StringUtil.join(libraries, File.pathSeparator));
arguments.sourceMap = sourceMap; arguments.setSourceMap(sourceMap);
arguments.sourceMapPrefix = sourceMapPrefix; arguments.setSourceMapPrefix(sourceMapPrefix);
arguments.sourceMapEmbedSources = sourceMapEmbedSources; arguments.setSourceMapEmbedSources(sourceMapEmbedSources);
if (outputFile != null) { if (outputFile != null) {
ConcurrentMap<String, List<String>> collector = getOutputDirectoriesCollector(); ConcurrentMap<String, List<String>> collector = getOutputDirectoriesCollector();
@@ -131,7 +131,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
} }
} }
arguments.sourceMapSourceRoots = sourceMapSourceRoots.toString(); arguments.setSourceMapSourceRoots(sourceMapSourceRoots.toString());
} }
protected List<String> getClassPathElements() throws DependencyResolutionRequiredException { protected List<String> getClassPathElements() throws DependencyResolutionRequiredException {
@@ -139,11 +139,11 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
@Override @Override
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException { protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
arguments.destination = output; arguments.setDestination(output);
// don't include runtime, it should be in maven dependencies // don't include runtime, it should be in maven dependencies
arguments.noStdlib = true; arguments.setNoStdlib(true);
arguments.javaParameters = this.javaParameters; arguments.setJavaParameters(this.javaParameters);
//noinspection deprecation //noinspection deprecation
if (module != null || testModule != null) { if (module != null || testModule != null) {
@@ -156,35 +156,35 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
String classPathString = join(classpathList, File.pathSeparator); String classPathString = join(classpathList, File.pathSeparator);
if (isJava9Module(sourceRoots)) { if (isJava9Module(sourceRoots)) {
getLog().debug("Module path: " + classPathString); getLog().debug("Module path: " + classPathString);
arguments.javaModulePath = classPathString; arguments.setJavaModulePath(classPathString);
} }
else { else {
getLog().debug("Classpath: " + classPathString); getLog().debug("Classpath: " + classPathString);
arguments.classpath = classPathString; arguments.setClasspath(classPathString);
} }
} }
getLog().debug("Classes directory is " + output); getLog().debug("Classes directory is " + output);
arguments.destination = output; arguments.setDestination(output);
arguments.moduleName = moduleName; arguments.setModuleName(moduleName);
getLog().info("Module name is " + moduleName); getLog().info("Module name is " + moduleName);
if (arguments.noOptimize) { if (arguments.getNoOptimize()) {
getLog().info("Optimization is turned off"); getLog().info("Optimization is turned off");
} }
if (jvmTarget != null) { if (jvmTarget != null) {
arguments.jvmTarget = jvmTarget; arguments.setJvmTarget(jvmTarget);
} }
if (jdkHome != null) { if (jdkHome != null) {
getLog().info("Overriding JDK home path with: " + jdkHome); getLog().info("Overriding JDK home path with: " + jdkHome);
arguments.jdkHome = jdkHome; arguments.setJdkHome(jdkHome);
} }
if (scriptTemplates != null && !scriptTemplates.isEmpty()) { if (scriptTemplates != null && !scriptTemplates.isEmpty()) {
arguments.scriptTemplates = scriptTemplates.toArray(new String[0]); arguments.setScriptTemplates(scriptTemplates.toArray(new String[0]));
} }
} }
@@ -230,7 +230,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
List<File> sourceRoots List<File> sourceRoots
) throws MojoExecutionException { ) throws MojoExecutionException {
for (File sourceRoot : sourceRoots) { for (File sourceRoot : sourceRoots) {
arguments.freeArgs.add(sourceRoot.getPath()); arguments.getFreeArgs().add(sourceRoot.getPath());
} }
return compiler.exec(messageCollector, Services.EMPTY, arguments); return compiler.exec(messageCollector, Services.EMPTY, arguments);
} }
@@ -439,16 +439,16 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
private void configureCompilerArguments(@NotNull A arguments, @NotNull CLICompiler<A> compiler, @NotNull List<File> sourceRoots) throws MojoExecutionException { private void configureCompilerArguments(@NotNull A arguments, @NotNull CLICompiler<A> compiler, @NotNull List<File> sourceRoots) throws MojoExecutionException {
if (getLog().isDebugEnabled()) { if (getLog().isDebugEnabled()) {
arguments.verbose = true; arguments.setVerbose(true);
} }
arguments.suppressWarnings = nowarn; arguments.setSuppressWarnings(nowarn);
arguments.languageVersion = languageVersion; arguments.setLanguageVersion(languageVersion);
arguments.apiVersion = apiVersion; arguments.setApiVersion(apiVersion);
arguments.multiPlatform = multiPlatform; arguments.setMultiPlatform(multiPlatform);
if (experimentalCoroutines != null) { if (experimentalCoroutines != null) {
arguments.coroutinesState = experimentalCoroutines; arguments.setCoroutinesState(experimentalCoroutines);
} }
configureSpecificCompilerArguments(arguments, sourceRoots); configureSpecificCompilerArguments(arguments, sourceRoots);
@@ -460,24 +460,24 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
throw new MojoExecutionException(e.getMessage()); throw new MojoExecutionException(e.getMessage());
} }
if (arguments.noInline) { if (arguments.getNoInline()) {
getLog().info("Method inlining is turned off"); getLog().info("Method inlining is turned off");
} }
List<String> pluginClassPaths = getCompilerPluginClassPaths(); List<String> pluginClassPaths = getCompilerPluginClassPaths();
if (pluginClassPaths != null && !pluginClassPaths.isEmpty()) { if (pluginClassPaths != null && !pluginClassPaths.isEmpty()) {
if (arguments.pluginClasspaths == null || arguments.pluginClasspaths.length == 0) { if (arguments.getPluginClasspaths() == null || arguments.getPluginClasspaths().length == 0) {
arguments.pluginClasspaths = pluginClassPaths.toArray(new String[pluginClassPaths.size()]); arguments.setPluginClasspaths(pluginClassPaths.toArray(new String[pluginClassPaths.size()]));
} else { } else {
for (String path : pluginClassPaths) { for (String path : pluginClassPaths) {
if (ArrayUtil.indexOf(arguments.pluginClasspaths, path) < 0) { if (ArrayUtil.indexOf(arguments.getPluginClasspaths(), path) < 0) {
arguments.pluginClasspaths = ArrayUtil.append(arguments.pluginClasspaths, path); arguments.setPluginClasspaths(ArrayUtil.append(arguments.getPluginClasspaths(), path));
} }
} }
} }
if (getLog().isDebugEnabled()) { if (getLog().isDebugEnabled()) {
getLog().debug("Plugin classpaths are: " + Joiner.on(", ").join(arguments.pluginClasspaths)); getLog().debug("Plugin classpaths are: " + Joiner.on(", ").join(arguments.getPluginClasspaths()));
} }
} }
@@ -494,7 +494,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
getLog().debug("Plugin options are: " + Joiner.on(", ").join(pluginArguments)); getLog().debug("Plugin options are: " + Joiner.on(", ").join(pluginArguments));
} }
arguments.pluginOptions = pluginArguments.toArray(new String[pluginArguments.size()]); arguments.setPluginOptions(pluginArguments.toArray(new String[pluginArguments.size()]));
} }
} }
@@ -88,7 +88,7 @@ public class KotlinTestCompileMojo extends K2JVMCompileMojo {
@Override @Override
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException { protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
classpath = testClasspath; classpath = testClasspath;
arguments.friendPaths = new String[] { output }; arguments.setFriendPaths(new String[] { output });
output = testOutput; output = testOutput;
super.configureSpecificCompilerArguments(arguments, sourceRoots); super.configureSpecificCompilerArguments(arguments, sourceRoots);
} }
@@ -81,13 +81,13 @@ public class KotlinTestJSCompilerMojo extends K2JSCompilerMojo {
@Override @Override
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException { protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
List<String> friends = getOutputDirectoriesCollector().getOrDefault(project.getArtifactId(), Collections.emptyList()); List<String> friends = getOutputDirectoriesCollector().getOrDefault(project.getArtifactId(), Collections.emptyList());
arguments.friendModules = StringUtil.join(friends, File.pathSeparator); arguments.setFriendModules(StringUtil.join(friends, File.pathSeparator));
output = testOutput; output = testOutput;
super.configureSpecificCompilerArguments(arguments, sourceRoots); super.configureSpecificCompilerArguments(arguments, sourceRoots);
arguments.outputFile = outputFile; arguments.setOutputFile(outputFile);
arguments.metaInfo = metaInfo; arguments.setMetaInfo(metaInfo);
} }
@Override @Override
@@ -61,10 +61,10 @@ public class MetadataMojo extends KotlinCompileMojoBase<K2MetadataCompilerArgume
@Override @Override
protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException { protected void configureSpecificCompilerArguments(@NotNull K2MetadataCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
arguments.destination = output; arguments.setDestination(output);
if (!arguments.multiPlatform) { if (!arguments.getMultiPlatform()) {
getLog().info("multiPlatform forced for metadata generation"); getLog().info("multiPlatform forced for metadata generation");
arguments.multiPlatform = true; arguments.setMultiPlatform(true);
} }
List<String> classpathList = filterClassPath(project.getBasedir(), classpath); List<String> classpathList = filterClassPath(project.getBasedir(), classpath);
@@ -73,7 +73,7 @@ public class MetadataMojo extends KotlinCompileMojoBase<K2MetadataCompilerArgume
if (!classpathList.isEmpty()) { if (!classpathList.isEmpty()) {
String classPathString = join(classpathList, File.pathSeparator); String classPathString = join(classpathList, File.pathSeparator);
getLog().debug("Classpath: " + classPathString); getLog().debug("Classpath: " + classPathString);
arguments.classpath = classPathString; arguments.setClasspath(classPathString);
} }
} }
} }
@@ -49,10 +49,10 @@ public class TestMetadataMojo extends MetadataMojo {
output = testOutput; output = testOutput;
super.configureSpecificCompilerArguments(arguments, sourceRoots); super.configureSpecificCompilerArguments(arguments, sourceRoots);
if (arguments.classpath == null) { if (arguments.getClasspath() == null) {
arguments.classpath = productionOutput; arguments.setClasspath(productionOutput);
} else { } else {
arguments.classpath = arguments.classpath + File.pathSeparator + productionOutput; arguments.setClasspath(arguments.getClasspath() + File.pathSeparator + productionOutput);
} }
} }
@@ -83,7 +83,7 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo {
options.add(new KaptOption("correctErrorTypes", correctErrorTypes)); options.add(new KaptOption("correctErrorTypes", correctErrorTypes));
options.add(new KaptOption("processors", annotationProcessors)); options.add(new KaptOption("processors", annotationProcessors));
if (arguments.verbose) { if (arguments.getVerbose()) {
options.add(new KaptOption("verbose", true)); options.add(new KaptOption("verbose", true));
} }
@@ -133,13 +133,17 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo {
} }
String[] kaptOptions = renderKaptOptions(getKaptOptions(arguments, resolvedArtifacts)); String[] kaptOptions = renderKaptOptions(getKaptOptions(arguments, resolvedArtifacts));
arguments.pluginOptions = joinArrays(arguments.pluginOptions, kaptOptions); arguments.setPluginOptions(joinArrays(arguments.getPluginOptions(), kaptOptions));
String jdkToolsJarPath = getJdkToolsJarPath(); String jdkToolsJarPath = getJdkToolsJarPath();
arguments.pluginClasspaths = joinArrays(arguments.pluginClasspaths, arguments.setPluginClasspaths(
(jdkToolsJarPath == null) joinArrays(
? new String[] { resolvedArtifacts.kaptCompilerPluginArtifact } arguments.getPluginClasspaths(),
: new String[] { jdkToolsJarPath, resolvedArtifacts.kaptCompilerPluginArtifact }); (jdkToolsJarPath == null)
? new String[]{resolvedArtifacts.kaptCompilerPluginArtifact}
: new String[]{jdkToolsJarPath, resolvedArtifacts.kaptCompilerPluginArtifact}
)
);
} }
@Nullable @Nullable
@@ -83,7 +83,7 @@ public class KaptTestJvmCompilerMojo extends KaptJVMCompilerMojo {
@Override @Override
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException { protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException {
classpath = testClasspath; classpath = testClasspath;
arguments.friendPaths = new String[] { output }; arguments.setFriendPaths(new String[] { output });
output = testOutput; output = testOutput;
super.configureSpecificCompilerArguments(arguments, sourceRoots); super.configureSpecificCompilerArguments(arguments, sourceRoots);
} }