Skip to content
Snippets Groups Projects
Commit 56ced9b5 authored by Johannes Mey's avatar Johannes Mey
Browse files

Feature/versioning

parent bfa206ad
Branches
Tags
No related merge requests found
plugins { plugins {
id 'java-library' id 'java-library'
id 'application'
id 'org.jastadd' id 'org.jastadd'
id 'java' id 'java'
id 'idea' id 'idea'
...@@ -7,11 +8,18 @@ plugins { ...@@ -7,11 +8,18 @@ plugins {
id 'com.github.ben-manes.versions' version '0.34.0' id 'com.github.ben-manes.versions' version '0.34.0'
} }
ext {
mainClassName = 'org.jastadd.relast.compiler.RelastSourceToSourceCompiler'
}
// set the main class name for `gradle run`
application.mainClassName = "${mainClassName}"
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8
repositories { repositories {
jcenter() mavenCentral()
} }
sourceSets { sourceSets {
...@@ -25,6 +33,7 @@ sourceSets { ...@@ -25,6 +33,7 @@ sourceSets {
task modelJar(type: Jar) { task modelJar(type: Jar) {
group = "build" group = "build"
archiveBaseName = 'model' archiveBaseName = 'model'
archiveVersion = ''
from sourceSets.model.output from sourceSets.model.output
} }
...@@ -37,7 +46,7 @@ dependencies { ...@@ -37,7 +46,7 @@ dependencies {
modelImplementation group: 'org.jastadd', name: 'jastadd', version: '2.3.4' modelImplementation group: 'org.jastadd', name: 'jastadd', version: '2.3.4'
modelImplementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' modelImplementation group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
compileOnly files(modelJar.archiveFile.get()) implementation files(modelJar.archiveFile.get())
api group: 'org.jastadd', name: 'jastadd', version: '2.3.4' api group: 'org.jastadd', name: 'jastadd', version: '2.3.4'
api group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11' api group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
implementation group: 'com.github.jknack', name: 'handlebars', version: '4.2.0' implementation group: 'com.github.jknack', name: 'handlebars', version: '4.2.0'
...@@ -56,6 +65,27 @@ dependencies { ...@@ -56,6 +65,27 @@ dependencies {
testFixturesApi group: 'commons-io', name: 'commons-io', version: '2.8.0' testFixturesApi group: 'commons-io', name: 'commons-io', version: '2.8.0'
} }
def versionFile = 'src/main/resources/preprocessor.properties'
def versionProps = new Properties()
try {
file(versionFile).withInputStream { stream -> versionProps.load(stream) }
version = versionProps['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)
}
jar {
manifest {
attributes "Main-Class": "${mainClassName}"
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
test { test {
useJUnitPlatform() useJUnitPlatform()
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
package org.jastadd; package org.jastadd;
import org.jastadd.option.ArgumentParser; import org.jastadd.option.ArgumentParser;
import org.jastadd.option.FlagOption;
import org.jastadd.option.Option; import org.jastadd.option.Option;
import java.io.PrintStream; import java.io.PrintStream;
...@@ -70,6 +71,11 @@ public class PreprocessorConfiguration extends org.jastadd.Configuration { ...@@ -70,6 +71,11 @@ public class PreprocessorConfiguration extends org.jastadd.Configuration {
if (options.containsKey(option.name())) { if (options.containsKey(option.name())) {
System.err.println("Unable to add option '" + option.name() + "', because there is a JastAdd option with the same name."); System.err.println("Unable to add option '" + option.name() + "', because there is a JastAdd option with the same name.");
} else { } else {
if (option.name().equals("help") && option instanceof FlagOption) {
this.helpOption = (FlagOption) option;
} else if (option.name().equals("version") && option instanceof FlagOption) {
this.versionOption = (FlagOption) option;
}
argParser.addOption(option); argParser.addOption(option);
options.put(option.name(), option); options.put(option.name(), option);
} }
......
...@@ -5,6 +5,8 @@ import org.jastadd.option.FlagOption; ...@@ -5,6 +5,8 @@ import org.jastadd.option.FlagOption;
import org.jastadd.option.Option; import org.jastadd.option.Option;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public abstract class AbstractCompiler { public abstract class AbstractCompiler {
...@@ -13,7 +15,7 @@ public abstract class AbstractCompiler { ...@@ -13,7 +15,7 @@ public abstract class AbstractCompiler {
protected ArrayList<Option<?>> options; protected ArrayList<Option<?>> options;
private PreprocessorConfiguration configuration; private PreprocessorConfiguration configuration;
public AbstractCompiler(String name, boolean jastaddCompliant) { protected AbstractCompiler(String name, boolean jastaddCompliant) {
this.name = name; this.name = name;
this.jastAddCompliant = jastaddCompliant; this.jastAddCompliant = jastaddCompliant;
} }
...@@ -33,6 +35,16 @@ public abstract class AbstractCompiler { ...@@ -33,6 +35,16 @@ public abstract class AbstractCompiler {
return 0; return 0;
} }
if (configuration.shouldPrintVersion()) {
try {
ResourceBundle resources = ResourceBundle.getBundle("preprocessor");
System.out.println(getName() + ", version " + resources.getString("version"));
} catch (MissingResourceException e) {
System.out.println(getName() + ", unknown version");
}
return 0;
}
return compile(); return compile();
} }
......
...@@ -15,7 +15,7 @@ public class RelastSourceToSourceCompiler extends RelAstProcessor { ...@@ -15,7 +15,7 @@ public class RelastSourceToSourceCompiler extends RelAstProcessor {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
new RelastSourceToSourceCompiler("relast-preprocessor", true).run(args); new RelastSourceToSourceCompiler("Relational RAGs Source-To-Source Compiler", false).run(args);
} catch (CompilerException e) { } catch (CompilerException e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
System.exit(-1); System.exit(-1);
......
version=1.0.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment