Add Console Interface parameters, output directory and classpath

This commit is contained in:
JanUlrich 2019-12-26 19:43:00 +01:00
parent f59a7d221e
commit 19989bfe11
3 changed files with 126 additions and 2 deletions

View File

@ -164,6 +164,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<tycho.version>0.23.0</tycho.version>
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
</properties>
<distributionManagement>
<repository>

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.core;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;
@ -9,8 +10,29 @@ public class ConsoleInterface {
private static final String directory = System.getProperty("user.dir");
public static void main(String[] args) throws IOException, ClassNotFoundException {
List<File> input = Arrays.asList(args).stream().map((s -> new File(s))).collect(Collectors.toList());
JavaTXCompiler compiler = new JavaTXCompiler(input);
List<File> input = new ArrayList<>();
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.generateBytecode(outputPath);
}
}

View 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());
}
}