From a6566139eeddb125cc45079bd612c4c4ca2625c5 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 11 Dec 2014 19:43:45 +0300 Subject: [PATCH] Minor, fix style issues in ant tasks --- .idea/runConfigurations/Integration_Tests.xml | 6 +++ .../jet/buildtools/ant/Kotlin2JsTask.kt | 8 +--- .../jet/buildtools/ant/Kotlin2JvmTask.kt | 47 ++++--------------- .../buildtools/ant/KotlinCompilerBaseTask.kt | 31 +++--------- 4 files changed, 24 insertions(+), 68 deletions(-) diff --git a/.idea/runConfigurations/Integration_Tests.xml b/.idea/runConfigurations/Integration_Tests.xml index 6f516f4adba..4f0e5c55cdf 100644 --- a/.idea/runConfigurations/Integration_Tests.xml +++ b/.idea/runConfigurations/Integration_Tests.xml @@ -23,8 +23,14 @@ + + + diff --git a/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsTask.kt b/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsTask.kt index f43e6e5e7b9..c75dbf28907 100644 --- a/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsTask.kt +++ b/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsTask.kt @@ -21,10 +21,6 @@ import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.jet.cli.js.K2JSCompiler import java.io.File -/** - * Kotlin JavaScript compiler Ant task. - * http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html - */ public class Kotlin2JsTask : KotlinCompilerBaseTask() { override val arguments = K2JSCompilerArguments() override val compiler = K2JSCompiler() @@ -52,13 +48,13 @@ public class Kotlin2JsTask : KotlinCompilerBaseTask() { } override fun fillSpecificArguments() { - arguments.outputFile = getPath(output!!) + arguments.outputFile = output!!.canonicalPath arguments.noStdlib = noStdlib // TODO: write test library?.let { - arguments.libraryFiles = it.list().map { getPath(File(it)) }.copyToArray() + arguments.libraryFiles = it.list().map { File(it).canonicalPath }.copyToArray() } arguments.outputPrefix = outputPrefix?.canonicalPath diff --git a/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JvmTask.kt b/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JvmTask.kt index 3e9abf7e7ee..6585934c330 100644 --- a/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JvmTask.kt +++ b/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JvmTask.kt @@ -18,24 +18,12 @@ package org.jetbrains.jet.buildtools.ant import org.apache.tools.ant.types.Path import org.apache.tools.ant.types.Reference - +import org.jetbrains.jet.cli.jvm.K2JVMCompiler +import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments import java.io.File import java.io.File.pathSeparator -import org.jetbrains.jet.cli.jvm.K2JVMCompiler -import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments -import com.intellij.openapi.util.io.FileUtilRt - - -/** - * Kotlin bytecode compiler Ant task. - *

- * See - * http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html - * http://evgeny-goldin.org/javadoc/ant/develop.html - * http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javac.java?view=markup. - */ -public class Kotlin2JvmTask : KotlinCompilerBaseTask() { +public class Kotlin2JvmTask : KotlinCompilerBaseTask() { override val arguments = K2JVMCompilerArguments() override val compiler = K2JVMCompiler() @@ -51,43 +39,28 @@ public class Kotlin2JvmTask : KotlinCompilerBaseTask() return externalAnnotations!!.createPath() } - /** - * Set the classpath to be used for this compilation. - * - * @param classpath an Ant Path object containing the compilation classpath. - */ public fun setClasspath(classpath: Path) { - if (this.compileClasspath == null) { - this.compileClasspath = classpath + if (compileClasspath == null) { + compileClasspath = classpath } else { - this.compileClasspath!!.append(classpath) + compileClasspath!!.append(classpath) } } - /** - * Adds a reference to a classpath defined elsewhere. - * - * @param ref a reference to a classpath. - */ public fun setClasspathRef(ref: Reference) { - if (this.compileClasspath == null) { - this.compileClasspath = Path(getProject()) + if (compileClasspath == null) { + compileClasspath = Path(getProject()) } - this.compileClasspath!!.createPath().setRefid(ref) + compileClasspath!!.createPath().setRefid(ref) } - /** - * Set the nested {@code } to be used for this compilation. - * - * @param classpath an Ant Path object containing the compilation classpath. - */ public fun addConfiguredClasspath(classpath: Path) { setClasspath(classpath) } override fun fillSpecificArguments() { - arguments.destination = getPath(output!!) + arguments.destination = output!!.canonicalPath val classpath = arrayListOf() compileClasspath?.let { classpath.addAll(it.list()) } diff --git a/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt b/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt index 17afd5695eb..11cd18a0061 100644 --- a/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt +++ b/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt @@ -19,7 +19,6 @@ package org.jetbrains.jet.buildtools.ant import org.apache.tools.ant.Task import org.apache.tools.ant.types.Path import org.apache.tools.ant.types.Reference -import org.jetbrains.jet.cli.common.messages.MessageCollectorPlainTextToStream import java.io.File import org.apache.tools.ant.BuildException import org.jetbrains.jet.cli.common.ExitCode @@ -27,25 +26,9 @@ import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments import org.jetbrains.jet.cli.common.CLICompiler import org.apache.tools.ant.types.Commandline import com.sampullara.cli.Args -import java.io.IOException -import org.jetbrains.jet.config import org.jetbrains.jet.cli.common.messages.PrintingMessageCollector import org.jetbrains.jet.cli.common.messages.MessageRenderer - -/** - * {@code file.getCanonicalPath()} convenience wrapper. - * - * @param file - file to get its canonical path. - * @return file's canonical path - */ -fun getPath(file: File): String { - try { - return file.getCanonicalPath() - } - catch (e: IOException) { - throw RuntimeException("Failed to resolve canonical file of [$file]: $e", e) - } -} +import org.jetbrains.jet.config.Services /** * Base class for Kotlin compiler Ant tasks. @@ -90,7 +73,7 @@ public abstract class KotlinCompilerBaseTask : Task private fun fillArguments() { val sourcePaths = src ?: throw BuildException("\"src\" should be specified") - arguments.freeArgs = sourcePaths.list().map { getPath(File(it)) } + arguments.freeArgs = sourcePaths.list().map { File(it).canonicalPath } output ?: throw BuildException("\"output\" should be specified") @@ -98,7 +81,7 @@ public abstract class KotlinCompilerBaseTask : Task arguments.verbose = verbose arguments.version = printVersion - val args = additionalArguments.flatMap { it.getParts()!!.toList() } + val args = additionalArguments.flatMap { it.getParts().toList() } try { Args.parse(arguments, args.copyToArray()) } @@ -109,15 +92,13 @@ public abstract class KotlinCompilerBaseTask : Task fillSpecificArguments() } - final override fun execute(): Unit { + final override fun execute() { fillArguments() - val outputPath = getPath(output!!) - - log("Compiling ${arguments.freeArgs} => [${outputPath}]"); + log("Compiling ${arguments.freeArgs} => [${output!!.canonicalPath}]"); val collector = PrintingMessageCollector(System.err, MessageRenderer.PLAIN, arguments.verbose) - val exitCode = compiler.exec(collector, config.Services.EMPTY, arguments) + val exitCode = compiler.exec(collector, Services.EMPTY, arguments) if (exitCode != ExitCode.OK) { throw BuildException("Compilation finished with exit code $exitCode")