Commit eded8184 authored by René Schöne's avatar René Schöne
Browse files

Replacing ragconnect parts with ragconnect jar file.

parent 61c612f3
Pipeline #7603 passed with stage
in 1 minute and 15 seconds
variables:
GIT_SUBMODULE_STRATEGY: recursive
services:
- name: "eclipse-mosquitto:1.6.9"
alias: "mqtt"
stages:
- build
- test
build:
image: openjdk:8
stage: build
before_script:
- ls -lah *
script:
- ./gradlew assemble
test:
image: openjdk:8
stage: test
script:
- ./gradlew allTests
artifacts:
reports:
junit: ros2rag.tests/build/test-results/test/TEST-*.xml
[submodule "relast-preprocessor"]
path = relast.preprocessor
url = ../relast-preprocessor.git
package org.jastadd.relast.plugin;
import org.gradle.api.Project;
import org.gradle.api.provider.Property;
/**
* TODO: Add description.
*
* @author rschoene - Initial contribution
*/
public class CompilerLocationExtension {
public Property<String> compilerLocation;
public CompilerLocationExtension(Project project) {
compilerLocation = project.getObjects().property(String.class);
}
public Property<String> getCompilerLocation() {
return compilerLocation;
}
}
package org.jastadd.relast.plugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.tasks.TaskCollection;
import java.util.Set;
/**
* Plugin for RelAst-Test.
*
* @author rschoene - Initial contribution
*/
public class RelastPlugin implements Plugin<Project> {
private Task testTask;
@Override
public void apply(Project project) {
CompilerLocationExtension extension = project.getExtensions().create(
"relastTest",
CompilerLocationExtension.class,
project);
Set<Task> tasks = project.getTasksByName("test", false);
// there should be only one task "test"
testTask = tasks.iterator().next();
TaskCollection<RelastTest> relastTests = project.getTasks().withType(RelastTest.class);
relastTests.forEach(relastTest -> setupRelastTest(relastTest, extension.getCompilerLocation().getOrNull()));
relastTests.whenTaskAdded(relastTest -> setupRelastTest(relastTest, extension.getCompilerLocation().getOrNull()));
}
private void setupRelastTest(RelastTest relastTest, String compilerLocation) {
testTask.dependsOn(relastTest);
relastTest.setCompilerLocation(compilerLocation);
relastTest.setGroup("verification");
}
}
package org.jastadd.relast.plugin;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskAction;
import java.io.IOException;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* RelAst Test Task
*
* @author rschoene - Initial contribution
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public class RelastTest extends DefaultTask {
// configuration from plugin
private String compilerLocation;
// general options
private boolean verbose = false;
// pre-process options
private List<String> relastFiles = new ArrayList<>();
private boolean useJastAddNames;
private boolean resolverHelper;
private boolean writeToFile = true;
private String grammarName;
private String listClass;
private String jastAddList;
private String serializer;
// compile options
private boolean runJastAdd = true;
private String outputDir = "src/test/java-gen/";
private String packageName;
private final List<String> moreInputFiles = new ArrayList<>();
public void setCompilerLocation(String compilerLocation) {
this.compilerLocation = compilerLocation;
}
public boolean isVerbose() {
return verbose;
}
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
// pre-process options
public List<String> getRelastFiles() {
return relastFiles;
}
public void relastFiles(String relastFile) {
this.relastFiles.add(relastFile);
}
public void relastFiles(String[] relastFilesArray) {
this.relastFiles = Arrays.asList(relastFilesArray);
}
public boolean isUseJastAddNames() {
return useJastAddNames;
}
public void setUseJastAddNames(boolean useJastAddNames) {
this.useJastAddNames = useJastAddNames;
}
public boolean isResolverHelper() {
return resolverHelper;
}
public void setResolverHelper(boolean resolverHelper) {
this.resolverHelper = resolverHelper;
}
public boolean isWriteToFile() {
return writeToFile;
}
public void setWriteToFile(boolean writeToFile) {
this.writeToFile = writeToFile;
}
public String getGrammarName() {
return grammarName;
}
public void setGrammarName(String grammarName) {
this.grammarName = grammarName;
}
public String getListClass() {
return listClass;
}
public void setListClass(String listClass) {
this.listClass = listClass;
}
public String getJastAddList() {
return jastAddList;
}
public void setJastAddList(String jastAddList) {
this.jastAddList = jastAddList;
}
public String getSerializer() {
return serializer;
}
public void setSerializer(String serializer) {
this.serializer = serializer;
}
// compile options
public boolean isRunJastAdd() {
return runJastAdd;
}
public void setRunJastAdd(boolean runJastAdd) {
this.runJastAdd = runJastAdd;
}
public String getOutputDir() {
return outputDir;
}
public void setOutputDir(String outputDir) {
this.outputDir = outputDir;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public List<String> getMoreInputFiles() {
return moreInputFiles;
}
public void moreInputFiles(String f) {
this.moreInputFiles.add(f);
}
public void moreInputFiles(String[] fileArray) {
this.moreInputFiles.addAll(Arrays.asList(fileArray));
}
private boolean isSet(String option) {
return option != null && !option.isEmpty();
}
private final String[] genSuffixes = {".ast", ".jadd", "RefResolver.jadd", "ResolverStubs.jrag", "Serializer.jadd"};
private Path pathToAbsoluteProject(String filename) {
return Paths.get(getProject().getProjectDir().getAbsolutePath(), filename);
}
@TaskAction
void runTest() throws IOException {
setGroup("verification");
setDescription("Runs a relast test");
Project project = getProject();
String absoluteProjectPath = project.getProjectDir().getAbsolutePath();
if (isVerbose()) {
System.out.println("Running relast test in " + project.getDisplayName());
System.out.println("relast files: " + getRelastFiles());
System.out.println("Deleting files");
}
// first, delete generated files
List<Path> genFiles = new ArrayList<>();
for (String suffix : genSuffixes) {
genFiles.add(pathToAbsoluteProject(getGrammarName() + suffix));
}
if (isVerbose()) {
System.out.println("gen files: " + genFiles);
}
project.delete(deleteSpec -> {
deleteSpec.delete(genFiles);
if (isSet(getPackageName())) {
deleteSpec.delete(Paths.get(getOutputDir(), getPackageName()));
}
});
// create output directories, if not existing
createDirectory(pathToAbsoluteProject(getOutputDir()));
createDirectory(pathToAbsoluteProject(getGrammarName()).getParent());
if (isVerbose()) {
System.out.println("Pre processing, running relast");
}
// then, run relast pre processing
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
FileCollection runtimeClasspath = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
project.javaexec(javaExecSpec -> {
List<Object> args = new ArrayList<>();
javaExecSpec.setClasspath(runtimeClasspath);
if (compilerLocation != null) {
javaExecSpec.setMain("-jar");
args.add(compilerLocation);
} else {
javaExecSpec.setMain("org.jastadd.relast.compiler.Compiler");
}
args.addAll(getRelastFiles().stream().map(this::pathToAbsoluteProject).collect(Collectors.toList()));
args.add("--quiet");
if (isWriteToFile()) {
args.add("--file");
}
if (isUseJastAddNames()) {
args.add("--useJastAddNames");
}
if (isResolverHelper()) {
args.add("--resolverHelper");
}
if (isSet(getJastAddList())) {
args.add("--jastAddList=" + getJastAddList());
}
if (isSet(getListClass())) {
args.add("--listClass=" + getListClass());
}
if (isSet(getSerializer())) {
args.add("--serializer=" + getSerializer());
}
args.add("--grammarName=" + pathToAbsoluteProject(getGrammarName()));
if (isVerbose()) {
System.out.println("Start relast with args: " + args);
}
javaExecSpec.args(args);
}).assertNormalExitValue();
});
if (isRunJastAdd()) {
if (isVerbose()) {
System.out.println("Compile with JastAdd");
}
// check which files were actually generated
genFiles.removeIf(this::verboseFileNotExists);
// finally, compile generated files
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
FileCollection runtimeClasspath = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
project.javaexec(javaExecSpec -> {
javaExecSpec.setClasspath(runtimeClasspath);
javaExecSpec.setMain("org.jastadd.JastAdd");
List<Object> args = new ArrayList<>();
args.add("--o=" + pathToAbsoluteProject(getOutputDir()));
args.add("--package=" + getPackageName());
if (isSet(getJastAddList())) {
args.add("--List=" + getJastAddList());
}
args.addAll(genFiles);
args.addAll(getMoreInputFiles().stream().map(this::pathToAbsoluteProject).collect(Collectors.toList()));
if (isVerbose()) {
System.out.println("Start JastAdd with args: " + args);
}
javaExecSpec.args(args);
});
});
}
}
private String fileExtension(String filename) {
int indexOfDot = filename.lastIndexOf('.');
return indexOfDot == -1 ? filename : filename.substring(indexOfDot + 1);
}
private boolean verboseFileNotExists(Path path) {
boolean fileDoesNotExist = !Files.exists(path);
if (fileDoesNotExist && isVerbose()) {
System.out.println("Do not include " + path);
}
return fileDoesNotExist;
}
private void createDirectory(Path path) throws IOException {
if (Files.exists(path) && Files.isDirectory(path)) {
return;
}
if (isVerbose()) {
System.out.println("Creating " + path.toAbsolutePath());
}
try {
Files.createDirectories(path);
} catch (FileAlreadyExistsException e) {
System.err.println("Skipping creation of already existing " + path);
} catch (IOException e) {
System.err.println("Could not create output directory " + path);
throw e;
}
}
}
build
src/gen-res/
src/gen/
out/
*.class
apply plugin: 'jastadd'
apply plugin: 'application'
sourceCompatibility = 1.8
mainClassName = 'org.jastadd.ragconnect.compiler.Compiler'
repositories {
jcenter()
}
buildscript {
repositories.jcenter()
dependencies {
classpath 'org.jastadd:jastaddgradle:1.13.3'
}
}
dependencies {
implementation project(':relast.preprocessor')
implementation group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.9.6'
implementation group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '2.11.2'
runtime group: 'org.jastadd', name: 'jastadd', version: '2.3.4'
api group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
}
def versionFile = 'src/main/resources/ragConnectVersion.properties'
def oldProps = new Properties()
try {
file(versionFile).withInputStream { stream -> oldProps.load(stream) }
version = oldProps['version']
} catch (e) {
// this happens, if either the properties file is not present, or cannot be read from
throw new GradleException("File ${versionFile} not found or unreadable. Aborting.", e)
}
task newVersion() {
doFirst {
def props = new Properties()
props['version'] = value
props.store(file(versionFile).newWriter(), null)
}
}
sourceSets {
main {
java.srcDir "src/gen/java"
}
}
test {
useJUnitPlatform()
maxHeapSize = '1G'
}
jar {
manifest {
attributes "Main-Class": 'org.jastadd.ragconnect.compiler.Compiler'
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
task relast(type: JavaExec) {
group = 'Build'
main = "-jar"
args = [
"../libs/relast.jar",
"../relast.preprocessor/src/main/jastadd/RelAst.relast",
"./src/main/jastadd/RagConnect.relast",
"./src/main/jastadd/MustacheNodes.relast",
"./src/main/jastadd/YAML.relast",
"--listClass=java.util.ArrayList",
"--jastAddList=JastAddList",
"--useJastAddNames",
"--file",
"--resolverHelper",
"--grammarName=./src/gen/jastadd/RagConnect"
]
inputs.files("../libs/relast.jar",
"../relast.preprocessor/src/main/jastadd/RelAst.relast",
"./src/main/jastadd/RagConnect.relast",
"./src/main/jastadd/MustacheNodes.relast",
"./src/main/jastadd/YAML.relast")
outputs.files("./src/gen/jastadd/RagConnect.ast",
"./src/gen/jastadd/RagConnect.jadd",
"./src/gen/jastadd/RagConnectRefResolver.jadd",
'./src/gen/jastadd/RagConnectResolverStubs.jrag')
}
jastadd {
configureModuleBuild()
modules {
//noinspection GroovyAssignabilityCheck
module("RagConnect") {
java {
basedir ".."
include "relast.preprocessor/main/**/*.java"
include "relast.preprocessor/gen/**/*.java"
include "ragconnect.base/src/main/**/*.java"
include "ragconnect.base/src/gen/**/*.java"
}
jastadd {
basedir ".."
include "relast.preprocessor/src/main/jastadd/**/*.ast"
include "relast.preprocessor/src/main/jastadd/**/*.jadd"
include "relast.preprocessor/src/main/jastadd/**/*.jrag"
include "ragconnect.base/src/main/jastadd/**/*.ast"
include "ragconnect.base/src/main/jastadd/**/*.jadd"
include "ragconnect.base/src/main/jastadd/**/*.jrag"
include "ragconnect.base/src/gen/jastadd/**/*.ast"
include "ragconnect.base/src/gen/jastadd/**/*.jadd"
include "ragconnect.base/src/gen/jastadd/**/*.jrag"
}
scanner {
basedir ".."
include "ragconnect.base/src/main/jastadd/scanner/Header.flex", [-5]
include "relast.preprocessor/src/main/jastadd/scanner/Preamble.flex", [-4]
include "relast.preprocessor/src/main/jastadd/scanner/Macros.flex", [-3]
include "ragconnect.base/src/main/jastadd/scanner/Macros.flex", [-3]
include "relast.preprocessor/src/main/jastadd/scanner/RulesPreamble.flex", [-2]
include "ragconnect.base/src/main/jastadd/scanner/MappingContent.flex", [-1]
include "ragconnect.base/src/main/jastadd/scanner/Keywords.flex"
include "relast.preprocessor/src/main/jastadd/scanner/Keywords.flex"
include "relast.preprocessor/src/main/jastadd/scanner/Symbols.flex", [1]
include "relast.preprocessor/src/main/jastadd/scanner/RulesPostamble.flex", [2]
}
parser {
basedir ".."
include "ragconnect.base/src/main/jastadd/parser/Preamble.parser"
include "ragconnect.base/src/main/jastadd/parser/RagConnect.parser"
include "relast.preprocessor/src/main/jastadd/parser/RelAst.parser"
}
}
}
cleanGen.doFirst {
delete "src/gen/java/org"
delete "src/gen-res/BuildInfo.properties"
}
preprocessParser.doFirst {
args += ["--no-beaver-symbol"]
}
module = "RagConnect"
astPackage = 'org.jastadd.ragconnect.ast'
parser.name = 'RagConnectParser'
genDir = 'src/gen/java'
buildInfoDir = 'src/gen-res'
scanner.genDir = "src/gen/java/org/jastadd/ragconnect/scanner"
parser.genDir = "src/gen/java/org/jastadd/ragconnect/parser"
jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"]
}
generateAst.dependsOn relast