Skip to content

Commit

Permalink
restructuring, improved support for commandline
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaRB committed Dec 4, 2023
1 parent 9d216f3 commit 50c0c6b
Show file tree
Hide file tree
Showing 19 changed files with 389 additions and 350 deletions.
26 changes: 15 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

plugins {
id 'application'
id 'antlr'
id 'antlr'
id 'com.github.johnrengelman.shadow' version "8.1.1"
id 'java'
}
Expand All @@ -26,10 +26,19 @@ plugins {
strictly '[2.17.0]'
}
}
implementation(platform('org.junit:junit-bom:5.9.1'))
implementation 'org.junit.jupiter:junit-jupiter:5.9.1'
implementation 'io.github.hakky54:logcaptor:2.7.10'
implementation("org.junit.platform:junit-platform-launcher")

implementation "org.jcommander:jcommander:1.83"
implementation "org.junit.platform:junit-platform-suite:1.8.1"

testRuntimeOnly("org.junit.platform:junit-platform-launcher")

testImplementation(platform('org.junit:junit-bom:5.9.1'))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation 'io.github.hakky54:logcaptor:2.7.10'

}

/** sourceSets {
Expand All @@ -38,18 +47,13 @@ plugins {
}
} */

task(translate, dependsOn: 'classes', type: JavaExec) {
mainClass = 'crml.translator.Main'
classpath = sourceSets.main.runtimeClasspath
}

task(parse, dependsOn: 'classes', type: JavaExec) {
mainClass = 'crml.parser.Main'
task(crmlc, dependsOn: 'classes', type: JavaExec) {
mainClass = 'crml.compiler.CRMLC'
classpath = sourceSets.main.runtimeClasspath
}

application {
mainClass = 'crml.translator.Main'
mainClass = 'crml.compiler.CRMLC'
}

generateGrammarSource {
Expand All @@ -68,7 +72,7 @@ test {

jar {
manifest {
attributes 'Main-Class': 'crml.translator.Main'
attributes 'Main-Class': 'crml.compiler.CRMLC'
attributes 'Multi-Release': 'true'
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;

import java.io.BufferedWriter;
import java.io.File;
Expand All @@ -7,7 +7,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Vector;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
Expand All @@ -19,23 +18,48 @@
import grammar.crmlParser;

import org.apache.logging.log4j.Logger;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.TestPlan;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;


import com.beust.jcommander.JCommander;

import org.apache.logging.log4j.LogManager;

public class Main {
import org.junit.platform.engine.discovery.DiscoverySelectors;


public class CRMLC {

private static final Logger logger = LogManager.getLogger();
SummaryGeneratingListener listener = new SummaryGeneratingListener();


public static void main( String[] args ) throws Exception {

if (args.length == 0)
{
System.out.println("usage: crml.translator.Test path/to/tests/[test.crml] [-o /path/to/output]");
System.out.println(" provide an input directory or a test to translate all or the given .crml files to .mo files");
System.out.println(" provide an output directory via -o on where to write the .mo files");
System.out.println(" if no output directory via -o is given then the .mo files are generated in the current directory");
return;
}
String path = new File(args[0]).getCanonicalPath();
CommandLineArgs cmd = new CommandLineArgs();

JCommander jc = JCommander.newBuilder().addObject(cmd).build();

jc.setProgramName("crmlc");
jc.parse(args);

if (cmd.help) {
jc.usage();
}

// incorrect arguments
if (cmd.files.isEmpty()&&cmd.runTestSuite==null){
System.err.println(" incorrect arguments");
jc.usage();
return;}

// TODO support multiple file loop
String path = new File(cmd.files.get(0)).getCanonicalPath();
logger.trace("Directory for tests: " + path);

File file = new File ( path );
Expand Down Expand Up @@ -142,7 +166,17 @@ public static void parse_file (String dir, String file, String gen_dir, Boolean
logger.error("Uncaught error: "+ e, e);
if (testMode) throw e;
}

}

public void runTestSuite(String packageName) {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(DiscoverySelectors.selectPackage("packageName"))
//.filters(includeClassNamePatterns(".*Test"))
.build();
Launcher launcher = LauncherFactory.create();
TestPlan testPlan = launcher.discover(request);
launcher.registerTestExecutionListeners(listener);
launcher.execute(request);

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;

public class CRMLTranslationException extends Exception{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;

import java.util.HashMap;
import java.util.Iterator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;

import java.util.HashMap;
import java.util.List;
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/crml/compiler/CommandLineArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package crml.compiler;

import java.util.ArrayList;
import java.util.List;

import com.beust.jcommander.Parameter;

public class CommandLineArgs {

@Parameter(names = {"-printAST" }, description = "If set to true will display the AST for the model.")
public Boolean printAST = false;

@Parameter(names = {"-runTestsuite"}, description = "Will run the tests located in the directory provided in parameters. If no directory is provided, will run the project testsuite.")
public String runTestSuite;

@Parameter(names = {"-o"}, description = "Provide an output directory via -o on where to write the .mo files. If no output directory via -o is given then the .mo files are generated in the current directory.")
public String outputDir = "default";

@Parameter(description = "Files to be compiled")
public List<String> files = new ArrayList<>();

@Parameter(names = "-help", help = true)
public boolean help;

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package crml.translator;
package crml.compiler;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import crml.translator.Signature.Type;
import crml.compiler.Signature.Type;

public class OperatorMapping {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;

import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;


import org.antlr.v4.runtime.RuleContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;
import java.util.List;

import grammar.crmlParser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crml.translator;
package crml.compiler;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
49 changes: 0 additions & 49 deletions src/main/java/crml/parser/Main.java

This file was deleted.

Loading

0 comments on commit 50c0c6b

Please sign in to comment.