Added a -version option to the compiler

This commit is contained in:
Andrey Breslav
2012-03-17 23:05:23 +04:00
parent cfe39d4025
commit 4231583f66
5 changed files with 80 additions and 16 deletions
+44 -15
View File
@@ -8,7 +8,11 @@
<property name="artifact.output.path" value="${basedir}/out/artifacts"/>
<property name="plugin.xml" value="idea/src/META-INF/plugin.xml"/>
<property name="plugin.xml.bk" value="${plugin.xml}.bk"/>
<property name="plugin.xml.versioned" value="${plugin.xml}.versioned.bk" />
<property name="plugin.xml.versioned" value="${plugin.xml}.versioned" />
<property name="compiler.version.java" value="compiler/cli/src/org/jetbrains/jet/cli/CompilerVersion.java"/>
<property name="compiler.version.java.bk" value="${compiler.version.java}.bk"/>
<property name="compiler.version.java.versioned" value="${compiler.version.java}.versioned" />
<property name="plugin.verifier" value="${basedir}/PluginVerifier/plugin-verifier-1.0-SNAPSHOT.jar"/>
<property name="plugin.zip" value="${artifact.output.path}/kotlin-plugin-${build.number}.zip" />
@@ -42,36 +46,61 @@
<delete dir="${artifact.output.path}" includes="*"/>
</target>
<target name="writeVersionToPluginXml">
<macrodef name="substituteVersionInFile">
<attribute name="target.file"/>
<attribute name="test.string"/>
<attribute name="target.file.bk" default="@{target.file}.bk"/>
<attribute name="target.file.versioned" default="@{target.file}.versioned"/>
<attribute name="token.key" default="snapshot"/>
<attribute name="version" default="${build.number}"/>
<sequential>
<!-- Create backup. Backup will be restored after build end. This will allow to rebuild project without renew
plugin.xml from repository. -->
<copy file="${plugin.xml}" tofile="${plugin.xml.bk}" />
<copy file="@{target.file}" tofile="@{target.file}.bk"/>
<!-- Check that version has correct pattern for substitution -->
<copy todir="">
<fileset file="${plugin.xml.bk}">
<contains text="&lt;version&gt;@snapshot@&lt;/version&gt;"/>
<fileset file="@{target.file.bk}">
<contains text="@{test.string}"/>
</fileset>
<filterchain>
<replacetokens>
<token key="snapshot" value="${build.number}"/>
<token key="@{token.key}" value="@{version}"/>
</replacetokens>
</filterchain>
<mergemapper to="${plugin.xml.versioned}"/>
<mergemapper to="@{target.file.versioned}"/>
</copy>
<!-- If file doesn't exist - there's a problem with original plugin.xml. Probably there's a bad pattern used for version -->
<copy file="${plugin.xml.versioned}" tofile="${plugin.xml}" overwrite="true"/>
<copy file="@{target.file.versioned}" tofile="@{target.file}" overwrite="true"/>
<delete file="${plugin.xml.versioned}" quiet="true"/>
<delete file="@{target.file.versioned}" quiet="true"/>
</sequential>
</macrodef>
<target name="writeVersionToTemplateFiles">
<substituteVersionInFile
target.file="${plugin.xml}"
target.file.bk="${plugin.xml.bk}"
target.file.versioned="${plugin.xml.versioned}"
test.string="&lt;version&gt;@snapshot@&lt;/version&gt;"/>
<substituteVersionInFile
target.file="${compiler.version.java}"
target.file.bk="${compiler.version.java.bk}"
target.file.versioned="${compiler.version.java.versioned}"
test.string="public static final String VERSION = &quot;@snapshot@&quot;;"/>
</target>
<target name="revertPluginXml">
<copy file="${plugin.xml.bk}" tofile="${plugin.xml}" overwrite="true"/>
<delete file="${plugin.xml.bk}" quiet="true"/>
</target>
<target name="revertTemplateFiles">
<copy file="${plugin.xml.bk}" tofile="${plugin.xml}" overwrite="true"/>
<delete file="${plugin.xml.bk}" quiet="true"/>
<target name="pre_build" depends="cleanupArtifacts, unzipDependencies, dist, writeVersionToPluginXml, generateInjectors">
<copy file="${compiler.version.java.bk}" tofile="${compiler.version.java}" overwrite="true"/>
<delete file="${compiler.version.java.bk}" quiet="true"/>
</target>
<target name="pre_build" depends="cleanupArtifacts, unzipDependencies, dist, writeVersionToTemplateFiles, generateInjectors">
</target>
<target name="zipArtifact">
@@ -96,7 +125,7 @@
-->
</target>
<target name="post_build" depends="zipArtifact, revertPluginXml, verifyPlugin"/>
<target name="post_build" depends="zipArtifact, revertTemplateFiles, verifyPlugin"/>
<target name="none">
<fail message="Either specify pre_build or post_build"/>
@@ -59,6 +59,9 @@ public class CompilerArguments {
@Argument(value = "verbose", description = "Enable verbose logging output")
public boolean verbose;
@Argument(value = "version", description = "Display compiler version")
public boolean version;
public String getClasspath() {
return classpath;
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* 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 org.jetbrains.jet.cli;
/**
* @author abreslav
*/
public class CompilerVersion {
// The value of this constant is generated by the build script
// DON'T MODIFY IT
public static final String VERSION = "@snapshot@";
}
@@ -20,6 +20,7 @@ import com.sampullara.cli.Args;
import org.jetbrains.jet.compiler.CompileEnvironment;
import org.jetbrains.jet.compiler.CompileEnvironmentException;
import org.jetbrains.jet.compiler.MessageRenderer;
import org.jetbrains.jet.lang.diagnostics.Severity;
import java.io.PrintStream;
@@ -91,6 +92,11 @@ public class KotlinCompiler {
System.setProperty("java.awt.headless", "true");
MessageRenderer messageRenderer = arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
if (arguments.version) {
errStream.println(messageRenderer.render(Severity.INFO, "Kotlin Compiler version " + CompilerVersion.VERSION, null, -1, -1));
}
CompileEnvironment environment = new CompileEnvironment(messageRenderer, arguments.verbose);
try {
configureEnvironment(environment, arguments, errStream);
@@ -268,7 +268,7 @@ public class JetCompiler implements TranslatingCompiler {
Class<?> kompiler = Class.forName(compilerClassName, true, loader);
Method exec = kompiler.getDeclaredMethod("exec", PrintStream.class, String[].class);
String[] arguments = { "-module", scriptFile.getAbsolutePath(), "-output", path(outputDir), "-tags", "-verbose" };
String[] arguments = { "-module", scriptFile.getAbsolutePath(), "-output", path(outputDir), "-tags", "-verbose", "-version" };
context.addMessage(INFORMATION, "Using kotlinHome=" + kotlinHome, "", -1, -1);
context.addMessage(INFORMATION, "Invoking in-process compiler " + compilerClassName + " with arguments " + Arrays.asList(arguments), "", -1, -1);