Add Console Interface parameters, output directory and classpath
This commit is contained in:
parent
f59a7d221e
commit
19989bfe11
1
pom.xml
1
pom.xml
@ -164,6 +164,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<tycho.version>0.23.0</tycho.version>
|
<tycho.version>0.23.0</tycho.version>
|
||||||
|
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
|
||||||
</properties>
|
</properties>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.core;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -9,8 +10,29 @@ public class ConsoleInterface {
|
|||||||
private static final String directory = System.getProperty("user.dir");
|
private static final String directory = System.getProperty("user.dir");
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
||||||
List<File> input = Arrays.asList(args).stream().map((s -> new File(s))).collect(Collectors.toList());
|
List<File> input = new ArrayList<>();
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(input);
|
List<URL> classpath = new ArrayList<>();
|
||||||
|
String outputPath = null;
|
||||||
|
Iterator<String> it = Arrays.asList(args).iterator();
|
||||||
|
while(it.hasNext()){
|
||||||
|
String arg = it.next();
|
||||||
|
if(arg.equals("-d")){
|
||||||
|
outputPath = it.next();
|
||||||
|
}else if(arg.startsWith("-d")) {
|
||||||
|
outputPath = arg.substring(2);
|
||||||
|
}else if(arg.equals("-cp")){
|
||||||
|
String[] cps = it.next().split(":");
|
||||||
|
for(String cp : cps){
|
||||||
|
classpath.add(new URL("file://"+cp));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
input.add(new File(arg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(input, classpath);
|
||||||
compiler.typeInference();
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
101
src/test/java/packages/ConsoleInterfaceTest.java
Normal file
101
src/test/java/packages/ConsoleInterfaceTest.java
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.ConsoleInterface;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
public class ConsoleInterfaceTest extends TestCase {
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSingleJavFile() throws Exception {
|
||||||
|
File f = new File(rootDirectory + "de/test/TestClass.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{rootDirectory + "de/test/TestClass.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/TestClass.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSingleJavFileWithOutputDirectory() throws Exception {
|
||||||
|
File f = new File(rootDirectory + "de/test/output/de/test/TestClass.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{"-d", rootDirectory + "de/test/output/" ,rootDirectory + "de/test/TestClass.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/output/de/test/TestClass.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSingleJavFileWithClassPath() throws Exception {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"/de/test/ToImport.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/ToImport.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/ImportTest.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{"-cp", rootDirectory + "de/test/output/" ,rootDirectory + "de/test/ImportTest.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/ImportTest.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSingleJavFileWithMultipleClassPath() throws Exception {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"/de/test/ToImport.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/ToImport.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/ImportTest.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{"-cp", rootDirectory + "de/test/output/:"+rootDirectory+"de",
|
||||||
|
rootDirectory + "de/test/ImportTest.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/ImportTest.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompileSingleJavFileWithClassPathAndOutputDir() throws Exception {
|
||||||
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"/de/test/ToImport.jav"));
|
||||||
|
compiler.typeInference();
|
||||||
|
compiler.generateBytecode(rootDirectory + "output/");
|
||||||
|
File f = new File(rootDirectory + "output/de/test/ToImport.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/output/de/test/ImportTest.class");
|
||||||
|
if(f.exists() && !f.isDirectory()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleInterface.main(new String[]{"-cp", rootDirectory + "de/test/output/",
|
||||||
|
"-d"+rootDirectory + "de/test/output/" ,rootDirectory + "de/test/ImportTest.jav"});
|
||||||
|
|
||||||
|
f = new File(rootDirectory + "de/test/output/de/test/ImportTest.class");
|
||||||
|
assertTrue(f.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user