Unverified Commit ea696f69 authored by Ryan Wisnesky's avatar Ryan Wisnesky Committed by GitHub
Browse files

Merge pull request #132 from babeloff/to-gradle

parents ec0aeeb1 c1fa40f0
......@@ -6,12 +6,17 @@ doc/aqlmanual/aqlmanual.out
doc/aqlmanual/aqlmanual.pdf
doc/aqlmanual/aqlmanual.synctex.gz
doc/aqlmanual/aqlmanual.toc
/target/
build/
buildSrc/build/
.classpath
.idea/
.project
.settings/
.vscode/
fql.iml
*.iml
*.ipr
*.iws
*.dvi
.gradle/
bin/
......@@ -23,17 +23,31 @@ http://categoricaldata.net/fql.jar
For best results, compile using the [Eclipse IDE](https://eclipse.org/jdt/).
### Maven (may or may not work)
### Gradle
git clone https://github.com/CategoricalData/fql.git
cd fql
mvn package
gradle run --args="-p antlr"
or for the default parser
gradle run --args="-p combinator"
Editor Support
--------------
- AQL mode for Emacs https://github.com/epost/aql-mode
In order to prepare the configuration files for an editor.
gradle idea
or
gradle eclipse
The open the project from the appropriate IDE.
License
-------
......
import org.babeloff.ProjectVersion
import org.babeloff.ReleaseVersionTask
import org.babeloff.SnapshotVersionTask
import org.babeloff.plugins.antlr.Antlr4Task
// apply from: 'gradle/foo.gradle'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'application'
apply plugin: 'idea'
apply plugin: 'eclipse'
group = 'net.catdata'
project.ext.versionFile = file('gradle/version.properties')
mainClassName = "catdata.ide.IDE"
task loadVersion {
project.version = ProjectVersion.read(logger, versionFile)
}
task makeReleaseVersion (type: ReleaseVersionTask) {
release = version.release
propFile = versionFile
}
task makeSnapshotVersion (type: SnapshotVersionTask) {
propFile = versionFile
}
task showVersion {
group = 'versioning'
description = 'Prints project version.'
doLast {
logger.quiet "Version : ${project.version}"
}
}
task showDependencies {
doLast {
configurations.getByName('antlr').each{
dependency -> println dependency
}
}
}
description = "Categorical Data IDE"
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
task createDistribution(type: Zip, dependsOn: makeReleaseVersion) {
from jar
from(sourceSets*.allSource) { into 'src' }
from(rootDir) { include versionFile.name }
}
task backupReleaseDistribution(type: Copy) {
from createDistribution.outputs.files
into "$buildDir/backup"
}
task release(dependsOn: backupReleaseDistribution) {
doLast { logger.quiet 'releasing the project...' }
}
configurations {
all { }
}
task antlrGen (type: Antlr4Task) {
maxHeapSize = "64m"
sourceDir = file("${project.rootDir}/src/main/antlr")
lexerGrammar = file("${project.rootDir}/src/main/antlr/catdata/aql/grammar/AqlLexerRules.g4")
parserGrammar = file("${project.rootDir}/src/main/antlr/catdata/aql/grammar/AqlParser.g4")
module = "catdata.aql.grammar"
targetDir = file("${project.buildDir}/generated-src/java/catdata/aql/grammar")
visitor = false
listener = true
}
compileJava.dependsOn antlrGen
wrapper {
gradleVersion = '4.10.1'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
sourceSets {
main {
java {
srcDirs = ['src/main/java','build/generated-src/java']
}
resources {
srcDirs = ["${project.projectDir}/resources"]
}
}
test {
java {
srcDirs = ["${project.projectDir}/src/test/java"]
}
resources {
srcDirs = ["${project.projectDir}/resources"]
}
}
}
idea {
module {
generatedSourceDirs += file("${project.buildDir}/generated-src/java")
downloadJavadoc = true
downloadSources = false
}
}
repositories {
mavenCentral()
maven { url "https://nexus.isis.vanderbilt.edu/repository/maven-releases" }
maven { url "https://nexus.isis.vanderbilt.edu/repository/maven-snapshots" }
}
dependencies {
compile group: 'net.sourceforge.collections', name: 'collections-generic', version:'4.01'
compile group: 'commons-cli', name: 'commons-cli', version:'1.4'
compile group: 'org.apache.commons', name: 'commons-csv', version:'1.5'
compile group: 'org.apache.commons', name: 'commons-exec', version:'1.3'
compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.7'
compile group: 'com.h2database', name: 'h2', version:'1.4.196'
compile group: 'org.glassfish', name: 'javax.json', version:'1.1.2'
compile group: 'jgraph', name: 'jgraph', version:'5.12.3.2'
compile group: 'org.jparsec', name: 'jparsec', version:'3.0'
compile group: 'net.sf.jung', name: 'jung-algorithms', version:'2.1.1'
compile group: 'net.sf.jung', name: 'jung-api', version:'2.1.1'
compile group: 'net.sf.jung', name: 'jung-graph-impl', version:'2.1.1'
compile group: 'net.sf.jung', name: 'jung-visualization', version:'2.1.1'
compile group: 'com.opencsv', name: 'opencsv', version:'4.1'
compile group: 'com.fifesoft', name: 'autocomplete', version:'2.6.1'
compile group: 'com.fifesoft', name: 'rstaui', version:'2.6.1'
compile group: 'com.fifesoft', name: 'rsyntaxtextarea', version:'2.6.1'
compile group: 'es.nitaur.markdown', name: 'txtmark', version:'0.16'
compile group: 'org.antlr', name: 'antlr4-runtime', version:'4.7.1'
// antlr group: 'org.antlr', name: 'antlr4', version: '4.7.1'
testCompileOnly(
'junit:junit:4.12'
)
testImplementation(
'org.junit.jupiter:junit-jupiter-api:5.3.1',
'org.junit.jupiter:junit-jupiter-params:5.3.1'
)
testRuntimeOnly(
'org.junit.jupiter:junit-jupiter-engine:5.3.1',
'org.junit.vintage:junit-vintage-engine:5.3.1'
)
}
test {
useJUnitPlatform()
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.antlr', name: 'antlr4', version:'4.7.1'
}
package org.babeloff
import org.gradle.api.GradleException
import org.gradle.api.logging.Logger
class ProjectVersion {
Integer year
Integer month
Integer day
Boolean release
ProjectVersion(Integer year, Integer month, Integer day) {
this.year = year
this.month = month
this.day = day
this.release = Boolean.FALSE
}
ProjectVersion(Integer year, Integer month, Integer day, Boolean release) {
this.year = year
this.month = month
this.day = day
this.release = release
}
static ProjectVersion read(Logger logger, File versionFile) {
logger.quiet 'Reading the version file.'
if(!versionFile.exists()) {
throw new GradleException("Required version file does not exist: $versionFile.canonicalPath")
}
Properties versionProps = new Properties()
versionFile.withInputStream { stream -> versionProps.load(stream) }
ProjectVersion pv = new ProjectVersion(
versionProps.year.toInteger(),
versionProps.month.toInteger(),
versionProps.day.toInteger(),
versionProps.release.toBoolean())
logger.quiet 'the version specified is: ' + pv.toString()
return pv;
}
@Override
String toString() {
"$year.$month.$day${release ? '' : '-SNAPSHOT'}"
}
}
package org.babeloff
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
class ReleaseVersionTask extends DefaultTask {
@Input Boolean release
@OutputFile File propFile
ReleaseVersionTask() {
group = 'versioning'
description = 'Makes project a release version.'
}
@TaskAction
void start() {
project.version.release = true
ant.propertyfile(file: propFile) {
entry(key: 'release', type: 'string', operation: '=', value: 'true')
}
}
}
package org.babeloff
import java.time.LocalDate
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
class SnapshotVersionTask extends DefaultTask {
@OutputFile File propFile
SnapshotVersionTask() {
group = 'versioning'
description = 'Makes project a release version.'
}
@TaskAction
void start() {
def date = LocalDate.now()
ant.propertyfile(file: propFile) {
entry(key: 'year', type: 'string', operation: '=', value: date.getYear().toString())
entry(key: 'month', type: 'string', operation: '=', value: date.getMonthValue().toString())
entry(key: 'day', type: 'string', operation: '=', value: date.getDayOfMonth())
entry(key: 'release', type: 'string', operation: '=', value: 'false')
}
}
}
package org.babeloff.plugins.antlr;
public class Antlr4Plugin {
}
package org.babeloff.plugins.antlr
import org.gradle.api.GradleException
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory;
import java.nio.file.Files;
import org.antlr.v4.Tool;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
class Antlr4Task extends DefaultTask {
/**
* g grammar FILE str "grammar file"
* l target LIB_DIR str "specify location of grammars, tokens files"
* e encoding CODE str "specify grammar file encoding; e.g., euc-jp"
* f message-format STYLE str "specify output STYLE for messages in antlr, gnu, vs2005"
* p package NAME str "specify a package/namespace for the generated code"
* D override OPT [str] "<option>=value set/override a grammar-level option"
* s show bool "show the constructed properties"
* a atn bool "generate rule augmented transition network diagrams"
* v long-messages bool "show exception details when available for errors and warnings"
* _ listener bool "generate parse tree listener"
* _ visitor bool "generate parse tree visitor"
* d depend bool "generate file dependencies"
* w warn-error bool "treat warnings as errors"
* _ save-lexer bool "extract lexer from combined grammar"
* _ debug-st bool "launch StringTemplate visualizer on generated code"
* _ debug-st-wait bool "wait for STViz to close before continuing"
* _ force-atn bool "use the ATN simulator for all predictions"
* _ log bool "dump lots of logging info to antlr-timestamp.log"]
*/
@Input @Optional String maxHeapSize;
@InputFile String lexerGrammar;
@InputFile String parserGrammar;
@InputDirectory File sourceDir;
@OutputDirectory File targetDir;
@Input @Optional String encoding;
@Input @Optional String msgFormat;
@Input @Optional String module;
@Input @Optional String override;
@Input @Optional Boolean show;
@Input @Optional Boolean atn;
@Input @Optional Boolean longMsg;
@Input @Optional Boolean listener;
@Input @Optional Boolean visitor;
@Input @Optional Boolean depend;
@Input @Optional Boolean warnError;
@Input @Optional Boolean saveLexer;
@Input @Optional Boolean debugStrTempl;
@Input @Optional Boolean debugStrTemplWait;
@Input @Optional Boolean forceAtn;
@Input @Optional Boolean log;
Antlr4Task() {
description = 'An antlr4 grammar generates a java parser'
group = 'org.babeloff'
}
@TaskAction
void start() {
ArrayList<String> args = new ArrayList<>();
args.push('-o');
args.push(targetDir.canonicalFile.toString())
logger.quiet 'target dir: ' + targetDir.canonicalFile
args.push('-lib');
args.push(sourceDir.canonicalFile.toString())
logger.quiet 'source dir: ' + sourceDir.canonicalFile
args.push('-package')
args.push(module)
def lexerArgs = args.clone();
lexerArgs.push(lexerGrammar);
String[] lexerArgsArray = lexerArgs.toArray(new String[lexerArgs.size()]);
logger.quiet 'lexer: ' + lexerArgsArray;
try {
Tool lexerTool = new Tool(lexerArgsArray);
lexerTool.processGrammarsOnCommandLine();
}
catch (Exception ex) {
throw new GradleException(ex.message)
}
// make the token file available to antlr so
// the same tokens get used by the parser as by the lexer.
def parserArgs = args.clone();
if (visitor) ( parserArgs.push('-visitor'))
if (listener) ( parserArgs.push('-listener'))
parserArgs.push(parserGrammar);
String[] parserArgsArray = parserArgs.toArray(new String[parserArgs.size()]);
logger.quiet 'parsing: ' + parserArgsArray;
try {
Tool parserTool = new Tool(parserArgsArray);
parserTool.processGrammarsOnCommandLine();
}
catch (Exception ex) {
throw new GradleException(ex.message)
}
}
}
generateGrammarSource {
maxHeapSize = "64m"
arguments += ["-visitor", "-listener", "-long-messages",
"-package", "catdata.aql.grammar",
"-grammar", "AqlParser.g4"]
}
\ No newline at end of file
#Fri, 07 Sep 2018 16:25:15 -0500
year=0
month=9
day=2
release=false
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi