Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
349 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
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 |
---|---|---|
@@ -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 |
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
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,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') | ||
} |
231 changes: 231 additions & 0 deletions
231
kotlin-ant-griffon/src/main/java/org/codehaus/griffon/kotlin/KotlincTask.java
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,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.")); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
kotlin-ant-griffon/src/main/java/org/codehaus/griffon/kotlin/LoggingHelper.java
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,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); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
kotlin-ant-griffon/src/main/resources/org/codehaus/griffon/kotlin/antlib.xml
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,5 @@ | ||
<antlib> | ||
<taskdef | ||
name = "kotlinc" | ||
classname = "org.codehaus.griffon.kotlin.KotlincTask"/> | ||
</antlib> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Oops, something went wrong.