Skip to content

Commit

Permalink
Upgrade to Kotlin M2
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 2, 2012
1 parent 29e2384 commit be6e488
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 14 deletions.
11 changes: 11 additions & 0 deletions .gitignore
@@ -1,2 +1,13 @@
target
release_notes.md
build
kotlin-griffonPluginFixes.iml
kotlin-griffonPlugins.iml
kotlin.iml
.idea
kotlin-griffonPluginFixes.iml
kotlin-griffonPlugins.iml
kotlin.iml
*.ipl
*.iws
.gradle
4 changes: 2 additions & 2 deletions KotlinGriffonPlugin.groovy
Expand Up @@ -21,9 +21,9 @@ class KotlinGriffonPlugin {
// the plugin version
String version = '0.2'
// the version or versions of Griffon the plugin is designed for
String griffonVersion = '0.9.5 > *'
String griffonVersion = '1.0.0 > *'
// the other plugins this plugin depends on
Map dependsOn = ['lang-bridge': '0.5']
Map dependsOn = ['lang-bridge': '0.6.1']
// resources that are included in plugin packaging
List pluginIncludes = []
// the plugin license
Expand Down
6 changes: 3 additions & 3 deletions application.properties
@@ -1,5 +1,5 @@
#Griffon Metadata file
#Fri Apr 13 11:32:23 CEST 2012
app.griffon.version=0.9.5
#Mon Jul 02 15:52:44 CEST 2012
app.griffon.version=1.0.0
app.name=kotlin
plugins.lang-bridge=0.5
plugins.lang-bridge=0.6.1
6 changes: 3 additions & 3 deletions griffon-app/conf/BuildConfig.groovy
Expand Up @@ -20,11 +20,11 @@ griffon.project.dependency.resolution = {
/*
// pluginDirPath is only available when installed
String basePath = pluginDirPath? "${pluginDirPath}/" : ''
flatDir name: "kotlinLibDir", dirs: ["${basePath}lib"]
flatDir name: "kotlinLibDir", dirs: ["${basePath}lib/kotlin/lib"]
*/
}
dependencies {
String kotlinVersion = '0.1.2090'
String kotlinVersion = '0.1.2580'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}
}
Expand All @@ -49,4 +49,4 @@ log4j = {
'org.apache.karaf',
'groovyx.net'
warn 'griffon'
}
}
20 changes: 20 additions & 0 deletions kotlin-ant-griffon/build.gradle
@@ -0,0 +1,20 @@
apply plugin: 'java'
apply plugin: 'idea'

repositories {
mavenCentral()
mavenRepo url: 'http://repository.jetbrains.com/all'
flatDir name: 'kotlin', dirs: ["../lib/kotlin/lib"]
}

dependencies {
compile "org.apache.ant:ant:1.8.2",
"org.apache.ant:ant:-launcher1.8.2",
"org.jetbrains.kotlin:kotlin-ant:0.1.2580",
"org.jetbrains.kotlin:kotlin-compiler:0.1.2580"
}

task updatePluginDeps(type: Copy) {
from "$buildDir/libs"
destinationDir file('../lib/kotlin/lib')
}
@@ -0,0 +1,231 @@
package org.codehaus.griffon.kotlin;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.util.GlobPatternMapper;
import org.apache.tools.ant.util.SourceFileScanner;
import org.jetbrains.jet.buildtools.core.BytecodeCompiler;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.jvm.compiler.*;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.jetbrains.jet.buildtools.core.Util.getPath;

/**
* Copy of {@code org.jetbrains.jet.buildtools.ant.BytecodeCompilerTask} with further customizations.
*
* @author Andres Almiray
*/
public class KotlincTask extends MatchingTask {
protected final LoggingHelper log = new LoggingHelper(this);

protected File output;
protected File jar;
protected File stdlib;
protected Path src;
protected File module;
protected Path compileClasspath;
protected boolean includeRuntime = true;
protected boolean force;

public void setOutput(File output) {
this.output = output;
}

public void setJar(File jar) {
this.jar = jar;
}

public void setStdlib(File stdlib) {
this.stdlib = stdlib;
}

public void setModule(File module) {
this.module = module;
}

public void setIncludeRuntime(boolean includeRuntime) {
this.includeRuntime = includeRuntime;
}

public Path createSrc() {
if (src == null) {
src = new Path(getProject());
}
return src.createPath();
}

public void setSrcdir(final Path dir) {
assert dir != null;

if (src == null) {
src = dir;
} else {
src.append(dir);
}
}

public Path getSrcdir() {
return src;
}

/**
* Set the classpath to be used for this compilation.
*
* @param classpath an Ant Path object containing the compilation classpath.
*/
public void setClasspath(Path classpath) {
if (this.compileClasspath == null) {
this.compileClasspath = classpath;
} else {
this.compileClasspath.append(classpath);
}
}


/**
* Adds a reference to a classpath defined elsewhere.
*
* @param ref a reference to a classpath.
*/
public void setClasspathRef(Reference ref) {
if (this.compileClasspath == null) {
this.compileClasspath = new Path(getProject());
}
this.compileClasspath.createPath().setRefid(ref);
}

/**
* Set the nested {@code <classpath>} to be used for this compilation.
*
* @param classpath an Ant Path object containing the compilation classpath.
*/
public void addConfiguredClasspath(Path classpath) {
setClasspath(classpath);
}


@Override
public void execute() {
GlobPatternMapper mapper = new GlobPatternMapper();
mapper.setFrom("*.kt");
mapper.setTo("*.class");

int count = 0;
String[] list = src.list();

List<String> sources = new ArrayList<String>();

for (int i = 0; i < list.length; i++) {
File basedir = getProject().resolveFile(list[i]);

if (!basedir.exists()) {
throw new CompileEnvironmentException("Source directory does not exist: " + basedir);
}

DirectoryScanner scanner = getDirectoryScanner(basedir);
String[] includes = scanner.getIncludedFiles();

if (force) {
log.debug("Forcefully including all files from: " + basedir);

for (int j = 0; j < includes.length; j++) {
File file = new File(basedir, includes[j]);
log.debug(" " + file);

sources.add(file.getAbsolutePath());
count++;
}
} else {
log.debug("Including changed files from: " + basedir);

SourceFileScanner sourceScanner = new SourceFileScanner(this);
File[] files = sourceScanner.restrictAsFiles(includes, basedir, output, mapper);

for (int j = 0; j < files.length; j++) {
log.debug(" " + files[j]);

sources.add(files[j].getAbsolutePath());
count++;
}
}
}

if (count > 0) {
log.info("Compiling " + count + " source file" + (count > 1 ? "s" : "") + " to " + output);
compile(sources);
} else {
log.info("No sources found to compile");
}
}

private void compile(List<String> sources) {
System.out.println("==============");
System.out.println(sources);
System.out.println("==============");
final BytecodeCompiler compiler = new BytecodeCompiler();
final String stdlibPath = (this.stdlib != null ? getPath(this.stdlib) : null);
final String[] classpath = (this.compileClasspath != null ? this.compileClasspath.list() : null);

try {
K2JVMCompileEnvironmentConfiguration configuration = env(compiler, stdlibPath, classpath);

boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSourceDirectories(configuration, sources, null, output.getAbsolutePath(), false, true);
if (!success) {
throw new BuildException(errorMessage(false));
}
} catch (Exception e) {
throw new BuildException(errorMessage(true), e);
}
}

// -- From org.jetbrains.jet.buildtools.core.BytecodeCompiler

/**
* Creates new instance of {@link org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration} instance using the arguments specified.
*
* @param stdlib path to "kotlin-runtime.jar", only used if not null and not empty
* @param classpath compilation classpath, only used if not null and not empty
* @return compile environment instance
*/
private K2JVMCompileEnvironmentConfiguration env(BytecodeCompiler compiler, String stdlib, String[] classpath) {
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
JetCoreEnvironment environment = new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), dependencies);
K2JVMCompileEnvironmentConfiguration
env = new K2JVMCompileEnvironmentConfiguration(environment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR, false, Collections.<String>emptyList());

if ((stdlib != null) && (stdlib.trim().length() > 0)) {
File file = new File(stdlib);
CompileEnvironmentUtil.addToClasspath(env.getEnvironment(), file);
}

if ((classpath != null) && (classpath.length > 0)) {
CompileEnvironmentUtil.addToClasspath(env.getEnvironment(), classpath);
}

// lets register any compiler plugins
env.getCompilerPlugins().addAll(compiler.getCompilerPlugins());

return env;
}

/**
* Retrieves compilation error message.
*
* @param exceptionThrown whether compilation failed due to exception thrown
* @return compilation error message
*/
private static String errorMessage(boolean exceptionThrown) {
return String.format("Compilation failed" +
(exceptionThrown ? "" : ", see \"ERROR:\" messages above for more details."));
}
}
@@ -0,0 +1,56 @@
/*
* Copyright 2003-2007 the original author or authors.
*
* 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.codehaus.griffon.kotlin;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;

/**
* Helper to make logging from Ant easier.
*
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
* @version $Id$
*/
public class LoggingHelper {
private Task owner;

public LoggingHelper(final Task owner) {
assert owner != null;

this.owner = owner;
}

public void error(final String msg) {
owner.log(msg, Project.MSG_ERR);
}

public void warn(final String msg) {
owner.log(msg, Project.MSG_WARN);
}

public void info(final String msg) {
owner.log(msg, Project.MSG_INFO);
}

public void verbose(final String msg) {
owner.log(msg, Project.MSG_VERBOSE);
}

public void debug(final String msg) {
owner.log(msg, Project.MSG_DEBUG);
}
}
@@ -0,0 +1,5 @@
<antlib>
<taskdef
name = "kotlinc"
classname = "org.codehaus.griffon.kotlin.KotlincTask"/>
</antlib>
Binary file modified lib/kotlin/lib/alt/kotlin-jdk-headers.jar
Binary file not shown.
Binary file added lib/kotlin/lib/kotlin-ant-0.1.2580.jar
Binary file not shown.
Binary file added lib/kotlin/lib/kotlin-ant-griffon.jar
Binary file not shown.
Binary file removed lib/kotlin/lib/kotlin-build-tools.jar
Binary file not shown.
Binary file modified lib/kotlin/lib/kotlin-compiler.jar
Binary file not shown.
Binary file modified lib/kotlin/lib/kotlin-runtime.jar
Binary file not shown.
7 changes: 6 additions & 1 deletion scripts/_Events.groovy
Expand Up @@ -26,10 +26,15 @@ eventCompileStart = {
}

eventStatsStart = { pathToInfo ->
String filetype = '.kt'
if(!pathToInfo.find{ it.path == 'src.commons'} ) {
pathToInfo << [name: 'Common Sources', path: 'src.commons', filetype: ['.groovy','.java']]
}
if(!pathToInfo.find{ it.path == 'src.kotlin'} ) {
pathToInfo << [name: 'Kotlin Sources', path: 'src.kotlin', filetype: ['.kt', '.kts', '.jetl']]
pathToInfo << [name: 'Kotlin Sources', path: 'src.kotlin', filetype: [filetype]]
}
['models', 'views', 'controllers', 'services'].each { path ->
List filetypes = pathToInfo.find { it.path == path }.filetype
if (!filetypes.contains(filetype)) filetypes << filetype
}
}

0 comments on commit be6e488

Please sign in to comment.