mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Adds CLI tool to run TeaVM
This commit is contained in:
parent
c459f3779a
commit
0e8b3d23bb
1
pom.xml
1
pom.xml
|
@ -77,6 +77,7 @@
|
||||||
<module>teavm-jso</module>
|
<module>teavm-jso</module>
|
||||||
<module>teavm-html4j</module>
|
<module>teavm-html4j</module>
|
||||||
<module>teavm-samples</module>
|
<module>teavm-samples</module>
|
||||||
|
<module>teavm-cli</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
4
teavm-cli/.gitignore
vendored
Normal file
4
teavm-cli/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/target
|
||||||
|
/.settings
|
||||||
|
/.classpath
|
||||||
|
/.project
|
55
teavm-cli/pom.xml
Normal file
55
teavm-cli/pom.xml
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<!--
|
||||||
|
Copyright 2014 Alexey Andreev.
|
||||||
|
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.teavm</groupId>
|
||||||
|
<artifactId>teavm</artifactId>
|
||||||
|
<version>0.2-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>teavm-cli</artifactId>
|
||||||
|
|
||||||
|
<name>TeaVM CLI</name>
|
||||||
|
<description>TeaVM command line tools</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.teavm</groupId>
|
||||||
|
<artifactId>teavm-core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-cli</groupId>
|
||||||
|
<artifactId>commons-cli</artifactId>
|
||||||
|
<version>1.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* 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.teavm.cli;
|
||||||
|
|
||||||
|
import org.teavm.tooling.TeaVMToolLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||||
|
*/
|
||||||
|
class ConsoleTeaVMToolLog implements TeaVMToolLog {
|
||||||
|
@Override
|
||||||
|
public void info(String text) {
|
||||||
|
System.out.println("INFO: " + text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(String text) {
|
||||||
|
System.out.println("DEBUG: " + text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warning(String text) {
|
||||||
|
System.out.println("WARNING: " + text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String text) {
|
||||||
|
System.out.println("ERROR: " + text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String text, Throwable e) {
|
||||||
|
System.out.println("INFO: " + text);
|
||||||
|
e.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(String text, Throwable e) {
|
||||||
|
System.out.println("DEBUG: " + text);
|
||||||
|
e.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warning(String text, Throwable e) {
|
||||||
|
System.out.println("WARNING: " + text);
|
||||||
|
e.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String text, Throwable e) {
|
||||||
|
System.out.println("ERROR: " + text);
|
||||||
|
e.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
}
|
142
teavm-cli/src/main/java/org/teavm/cli/TeaVMRunner.java
Normal file
142
teavm-cli/src/main/java/org/teavm/cli/TeaVMRunner.java
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* 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.teavm.cli;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import org.apache.commons.cli.*;
|
||||||
|
import org.teavm.tooling.RuntimeCopyOperation;
|
||||||
|
import org.teavm.tooling.TeaVMTool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||||
|
*/
|
||||||
|
public class TeaVMRunner {
|
||||||
|
@SuppressWarnings("static-access")
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Options options = new Options();
|
||||||
|
options.addOption(OptionBuilder
|
||||||
|
.withArgName("directory")
|
||||||
|
.hasArg()
|
||||||
|
.withDescription("a directory where to put generated files (current directory by default)")
|
||||||
|
.withLongOpt("targetdir")
|
||||||
|
.create('d'));
|
||||||
|
options.addOption(OptionBuilder
|
||||||
|
.withArgName("file")
|
||||||
|
.hasArg()
|
||||||
|
.withDescription("a file where to put decompiled classes (classes.js by default)")
|
||||||
|
.withLongOpt("targetfile")
|
||||||
|
.create('f'));
|
||||||
|
options.addOption(OptionBuilder
|
||||||
|
.withDescription("causes TeaVM to generate minimized JavaScript file")
|
||||||
|
.withLongOpt("minify")
|
||||||
|
.create("m"));
|
||||||
|
options.addOption(OptionBuilder
|
||||||
|
.hasArg()
|
||||||
|
.withDescription("how to attach runtime. Possible values are: separate|merge|none")
|
||||||
|
.withLongOpt("runtime")
|
||||||
|
.create("r"));
|
||||||
|
options.addOption(OptionBuilder
|
||||||
|
.withDescription("causes TeaVM to include default main page")
|
||||||
|
.create("mainpage"));
|
||||||
|
options.addOption(OptionBuilder
|
||||||
|
.withDescription("causes TeaVM to log bytecode")
|
||||||
|
.create("logbytecode"));
|
||||||
|
options.addOption(OptionBuilder
|
||||||
|
.hasArg()
|
||||||
|
.withDescription("how many threads should TeaVM run")
|
||||||
|
.withLongOpt("threads")
|
||||||
|
.create("t"));
|
||||||
|
|
||||||
|
if (args.length == 0) {
|
||||||
|
printUsage(options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CommandLineParser parser = new PosixParser();
|
||||||
|
CommandLine commandLine;
|
||||||
|
try {
|
||||||
|
commandLine = parser.parse(options, args);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
printUsage(options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TeaVMTool tool = new TeaVMTool();
|
||||||
|
tool.setBytecodeLogging(commandLine.hasOption("logbytecode"));
|
||||||
|
if (commandLine.hasOption("d")) {
|
||||||
|
tool.setTargetDirectory(new File(commandLine.getOptionValue("d")));
|
||||||
|
}
|
||||||
|
if (commandLine.hasOption("f")) {
|
||||||
|
tool.setTargetFileName(commandLine.getOptionValue("f"));
|
||||||
|
}
|
||||||
|
if (commandLine.hasOption("m")) {
|
||||||
|
tool.setMinifying(true);
|
||||||
|
} else {
|
||||||
|
tool.setMinifying(false);
|
||||||
|
}
|
||||||
|
if (commandLine.hasOption("r")) {
|
||||||
|
switch (commandLine.getOptionValue("r")) {
|
||||||
|
case "separate":
|
||||||
|
tool.setRuntime(RuntimeCopyOperation.SEPARATE);
|
||||||
|
break;
|
||||||
|
case "merge":
|
||||||
|
tool.setRuntime(RuntimeCopyOperation.MERGED);
|
||||||
|
break;
|
||||||
|
case "none":
|
||||||
|
tool.setRuntime(RuntimeCopyOperation.NONE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.err.println("Wrong parameter for -r option specified");
|
||||||
|
printUsage(options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (commandLine.hasOption("mainpage")) {
|
||||||
|
tool.setMainPageIncluded(true);
|
||||||
|
}
|
||||||
|
if (commandLine.hasOption("t")) {
|
||||||
|
try {
|
||||||
|
tool.setNumThreads(Integer.parseInt(commandLine.getOptionValue("t")));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.err.println("Wrong parameter for -t option specified");
|
||||||
|
printUsage(options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
args = commandLine.getArgs();
|
||||||
|
if (args.length > 1) {
|
||||||
|
System.err.println("Unexpected arguments");
|
||||||
|
printUsage(options);
|
||||||
|
return;
|
||||||
|
} else if (args.length == 1) {
|
||||||
|
tool.setMainClass(args[0]);
|
||||||
|
}
|
||||||
|
tool.setLog(new ConsoleTeaVMToolLog());
|
||||||
|
|
||||||
|
try {
|
||||||
|
tool.generate();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
System.exit(-2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printUsage(Options options) {
|
||||||
|
HelpFormatter formatter = new HelpFormatter();
|
||||||
|
formatter.printHelp("java " + TeaVMRunner.class.getName() + "[OPTIONS] [qualified.main.Class]", options);
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
|
@ -212,7 +212,7 @@ public class TeaVMTool {
|
||||||
if (mainPageIncluded) {
|
if (mainPageIncluded) {
|
||||||
String text;
|
String text;
|
||||||
try (Reader reader = new InputStreamReader(classLoader.getResourceAsStream(
|
try (Reader reader = new InputStreamReader(classLoader.getResourceAsStream(
|
||||||
"org/teavm/maven/main.html"), "UTF-8")) {
|
"org/teavm/tooling/main.html"), "UTF-8")) {
|
||||||
text = IOUtils.toString(reader).replace("${classes.js}", targetFileName);
|
text = IOUtils.toString(reader).replace("${classes.js}", targetFileName);
|
||||||
}
|
}
|
||||||
File mainPageFile = new File(targetDirectory, "main.html");
|
File mainPageFile = new File(targetDirectory, "main.html");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user