modified the JS compiler so that it can have definitions and library sources specified or discovered on the classpath; so for example we can then discover the kotlin standard library kotlin that needs to be compiled; plus the JS library definitions (which map to the kotlin-lib.js file)

This commit is contained in:
James Strachan
2012-05-30 15:50:06 +01:00
parent ae12b4e5fc
commit 4cff5f9759
10 changed files with 206 additions and 116 deletions
+1 -4
View File
@@ -65,11 +65,8 @@
<module>examples/kotlin-java-example</module>
<!--
TODO temporary disabled until we can get the kotlin/dom code compiled as JS
<module>examples/browser-example</module>
-->
<module>examples/js-example</module>
<module>examples/browser-example</module>
</modules>
<dependencies>
+51 -26
View File
@@ -56,32 +56,57 @@
<version>2.9</version>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>1.5</version>
<configuration>
<projectsDirectory>src/it</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<!--This could speed up test by providing local repo as remote repo for test but might be tricky on different OS-->
<!--<settingsFile>src/it/settings.xml</settingsFile>-->
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<postBuildHookScript>verify.bsh</postBuildHookScript>
<streamLogs>true</streamLogs>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<!--<phase>package</phase>-->
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<!--
moved the integration test into a profile so we can disable this
for example this integration test doesn't work if offline
-->
<profile>
<id>integrationTest</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>1.5</version>
<configuration>
<projectsDirectory>src/it</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<!--This could speed up test by providing local repo as remote repo for test but might be tricky on different OS-->
<!--<settingsFile>src/it/settings.xml</settingsFile>-->
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<postBuildHookScript>verify.bsh</postBuildHookScript>
<streamLogs>true</streamLogs>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<!--<phase>package</phase>-->
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- allows the integration test to be disabled (for example if you are offline) -->
<profile>
<id>noTest</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
</profiles>
</project>
@@ -5,6 +5,8 @@ import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.FileUtils;
import org.jetbrains.k2js.config.ClassPathLibraryDefintionsConfig;
import org.jetbrains.k2js.config.ClassPathLibrarySourcesLoader;
import java.io.File;
import java.io.FileWriter;
@@ -19,13 +21,21 @@ import java.io.PrintWriter;
*/
public class JSSourceJarMojo extends AbstractMojo {
/**
* The Kotlin JavaScript library source code
* The Kotlin JavaScript library source code; the library code to be compiled to JavaScript
*
* @required
* @parameter expression="${jsLibrarySourceDir}"
*/
private File librarySourceDir;
/**
* The Kotlin JavaScript definition source code; the kotlin code used to define APIs available in the kotlin-lib.js file
*
* @required
* @parameter expression="${jsDefinitionSourceDir}"
*/
private File definitionSourceDir;
/**
* The directory for the copied code
*
@@ -41,7 +51,7 @@ public class JSSourceJarMojo extends AbstractMojo {
getLog().warn("Source directory does not exist: " + librarySourceDir);
} else {
try {
File metaInfFile = new File(outputDir, "META-INF/services/org.jetbrains.kotlin.js.librarySource");
File metaInfFile = new File(outputDir, ClassPathLibrarySourcesLoader.META_INF_SERVICES_FILE);
metaInfFile.getParentFile().mkdirs();
FileUtils.copyDirectoryStructure(librarySourceDir, outputDir);
@@ -54,6 +64,21 @@ public class JSSourceJarMojo extends AbstractMojo {
throw new MojoFailureException(e.getMessage(), e);
}
}
if (definitionSourceDir.exists()) {
try {
File metaInfFile = new File(outputDir, ClassPathLibraryDefintionsConfig.META_INF_SERVICES_FILE);
metaInfFile.getParentFile().mkdirs();
FileUtils.copyDirectoryStructure(definitionSourceDir, outputDir);
// now lets generate the META-INF/services/org.jetbrains.kotlin.js.libraryDefinitions file
PrintWriter writer = new PrintWriter(new FileWriter(metaInfFile));
appendSourceFiles(writer, definitionSourceDir.getCanonicalPath(), definitionSourceDir);
writer.close();
} catch (IOException e) {
throw new MojoFailureException(e.getMessage(), e);
}
}
}
private void appendSourceFiles(PrintWriter writer, String rootPath, File currentDir) throws IOException {