Giter VIP home page Giter VIP logo

gradle-plugin-jflex's Introduction

gradle-plugin-jflex

A Gradle plugin for JFlex

Compatibility

Date Plugin Gradle JFLex
2020-05-13 1.4.0 6.4 1.8.2

Usage

plugins {
   id "org.xbib.gradle.plugin.jflex" version "1.4.0"
}

Gradle will look for your JFlex files in the source sets you specified. By default, it looks with the pattern **/*.jflex under src/main/jflex and src/test/jflex.

You can set up the source sets like this:

sourceSets {
  main {
     jflex {
       srcDir "src/main/jflex"
     }
     java {
       srcDir "$buildDir/my-generated-sources/jflex"
     }
  }
}

The lastJava srcDir definition will be used as the base for the JFLex target path. If not given, the JFlex target path for generated Java source follows the pattern:

${project.buildDir}/generated/sources/jflex

The JFlex target path will be added automatically to the java compile task source directory of the source set.

Parameter support

The following parameters can be set in a global jflex extension in the gradle script. See also https://jflex.de/manual.html

Name Description
encoding the file encoding
rootDirectory the root directory used by JFlex (modification discouraged since the directories are derived from gradle source set)
skel uses external skeleton in UTF-8 encoding. This is mainly for JFlex maintenance and special low level customisations. Use only when you know what you are doing! JFlex comes with a skeleton file in the src directory that reflects exactly the internal, pre-compiled skeleton and can be used with the skel option.
verbose display generation progress messages (disabled by default)
jlex tries even harder to comply to JLex interpretation of specs
no_minimize skip the DFA minimisation step during scanner generation
no_backup don't write backup files if this is true
unused_warning warn about unused macros (by default false)
progress progress dots will be printed (by default false)
dot If true, jflex will write graphviz .dot files for generated automata (by default, false)
time If true, jflex will print time statistics about the generation process (by default false)
dump If true, you will be flooded with information, e.g. dfa tables (by default, false)
legacy_dot dot (.) meta character matches [^\n] instead of [^\n\r\u000B\u000C\u0085\u2028\u2029]
statistics print output statistics (by default, false)

Credits

gradle-plugin-jflex is a plugin based on gradle-jflex-plugin which was written by Tom Lee.

License

Copyright (C) 2015-2020 Jörg Prante

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

gradle-plugin-jflex's People

Contributors

dcabasson avatar imoverclocked avatar jprante avatar ryandens avatar singingbush avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gradle-plugin-jflex's Issues

Sometimes gradle-plugin-jflex overwrites sourceset modifications made by previous plugins or task

Problem:

Sometime the gradle-plugin-jflex overwrites modifications made by plugins or tasks (applied before gradle-plugin-jflex plugin).

An example can be found in stalb/JFlex_Example:

plugins {
    id 'java'
    id "org.xbib.gradle.plugin.jflex" version "1.7.0" apply false
}
repositories {
    mavenCentral()
}
def copyJava = tasks.register("copyJava", Copy) {
	from 'src/main/custom/'
	into "${project.buildDir}/generated/sources/custom/java/testJFlex"
}
sourceSets {
    main {
        java {
        	srcDir copyJava
        }
    }
}
apply plugin: "org.xbib.gradle.plugin.jflex"

The main Java SourceDirectorySet should contains copyJava output and generateJflex output,
However when gradle-plugin-jflex plugin is applied after the main Java SourceDirectorySet configuration,
the output of copyJava disappears from the SourceDirectorySet.

In fact, since the output of the copyJava task is not in the main java SourceDirectorySet anymore, it will not be even considered as a dependency of compileJava.
So running ./gradlew compileJava will not trigger the copyJava task which output will not be compiled.

If plugins which modify the java SourceDirectorySet are applied before gradle-plugin-jflex plugin, their modifications can also be overwritten.

Expected behavior:

gradle-plugin-jflex plugin should not overwrite SourceDirectorySet additions made by plugins or tasks applied previously.

In the example, running the compileJava task should trigger both generateJflex and copyJava tasks
and all their Java outputs should be compiled by compileJava.

feature request: alternative JFlex versions

annoyingly when writing a lexer for an Intellij plugin it seems I have to use a version of JFlex that has been patched by JetBrains. I currently use a locally built jar for de.jflex:jflex:1.7.0-SNAPSHOT.

instead of your plugin specifying compile "de.jflex:jflex:1.6.1" in the dependencies perhaps it should use compileOnly so that the user is responsible for including a JFlex version that suites their needs.

Another option could to have a configuration option that allows the user to specify a jflex version which the plugin will then download and use.

Set up package fro the output

With legacy maven jflex plugin I was able to generate the output sources to a corresponding package:

/src/generated-sources/my/package/is/in/path/Lexer.java

However with the gradle plugin, it generates the file directly in the base path:

/src/generated-sources/Lexer.java

Only configuration option is

     java {
       srcDir "$buildDir/my-generated-sources/jflex"
     }

But I guess that is not meant to set up the package root. Am I understanding something wrongly?

Plugin not respecting `buildDir`

Hi! I've set the following in build.gradle

allprojects { buildDir = ".build" }

And yet, the outputted file is still stored in build/generated-src. How do I fix this?

Couldn't install with mavenCentral option in README

Although I couldn't install the plugin from the official doc, I did found your example and quick and easy solution with:

plugins {
 id 'org.xbib.gradle.plugin.jflex' version '1.1.0'
}

So, I suggest that you note that for newer versions of gradle we can use this option.

And also it would be nice if we could specify the jflex directory and jflex output directory.

Thanks man, nice plugin.

Feature Request: Allow parameters to be passed to Jflex

I am needing to build a variant of a lucene jflex parser, which involves passing the skeleton paramter to jflex. As such, I am unable to use your plugin, which is SO darn nice! I would suggest just allowing user specified arbitrary parameters, which would meet my need but also others.

If Jflex input is defined as the output of another task, Jflex generation fails

Problem description

If Jflex input is defined as the output of another task, this will not be taken into account by Jflex tasks.

An example can be found in stalb/JFlex_Example2:

plugins {
    id "org.xbib.gradle.plugin.jflex" version "1.7.0"
}

repositories {
    mavenCentral()
}

def copyJflex = tasks.register("copyJflex", Copy) {
    from 'src/main/custom/'
    into "${project.buildDir}/generated/sources/custom/jflex/"
}

sourceSets {
    main {
        jflex {
            srcDir copyJflex
        }
    }
}

The main Jflex SourceDirectorySet should contains copyJflex output, however this is not the case.

In fact the generateJflex task doesn't consider copyJflex as a dependency, so running generateJflex won't trigger copyJflex task and will produce nothing.

Expected behavior

  • The generateJflex task should depend on the copyJflex task.
  • Running the generateJflex task should trigger the copyJflex task and its output processed by Jflex.

Publish gradle-plugin-jflex to maven central?

Hi! I'd like to switch over from using @thomaslee's gradle-jflex-plugin to yours (as discussed recently in an issue in that project). However, I'm a little hesitant to pull in a build plugin from a random personal domain :) Would it be possible to get your plugin published to the maven central repository?

Pb when configuring JFlexTask directly

Problem description

If you configure JFlexTask directly (not using the jflex extension) this can lead to unexpected behavior.

Example 1 (see stalb/JFlex_Example3)

When using the following configuration (build.gradle)

plugins {
    id "org.xbib.gradle.plugin.jflex" version "1.7.0"
}

repositories {
    mavenCentral()
}

tasks.named('generateJflex').configure {
   // write output into custom location .
   target = file("${project.buildDir}/generated/sources/jflexCustom/")
}

the JFlex java source file is generated into ${project.buildDir}/generated/sources/jflexCustom/ as expected
but it is not compiled by the compileJava task, which actually looks into ${project.buildDir}/generated/sources/main/.

Example 2 (see stalb/JFlex_Example4)

When using the following configuration (build.gradle)

plugins {
    id "org.xbib.gradle.plugin.jflex" version "1.7.0"
}

repositories {
    mavenCentral()
}

tasks.named('generateJflex').configure {
   // enable legacy behavior of writing directly into Java source directory
   writeIntoJavaSrc = true
}

the JFlex java source file is generated into ${project.buildDir}/generated/sources/main/ instead of src/main/java/.
So the writeIntoJavaSrc flag specified for the generateJflex task is not taken into account as I would expect it to be.

Expected behavior

Example1: the java compiler should compile the java file produced by the JFlexTask.

Example 2: the java file produced by the JFlexTask should written in the Java source directory.

Issue with version 1.4.0

When using version 1.4.0, the jflex task is not available for some reason. I do not run into this issue when using version 1.3.0 of this plugin.

Using 1.3.0

λ cat build.gradle
plugins {
 id 'org.xbib.gradle.plugin.jflex' version '1.3.0'
}

λ gradle jflex

BUILD SUCCESSFUL in 432ms
1 actionable task: 1 up-to-date

Using 1.4.0

λ cat build.gradle
plugins {
 id 'org.xbib.gradle.plugin.jflex' version '1.4.0'
}

λ gradle jflex

FAILURE: Build failed with an exception.

* What went wrong:
Task 'jflex' not found in root project 'jflex-example'.

* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 420ms

I tested this with several gradle versions.

Gradle publication

Hi,

as the jcenter/bintray were turned off it seems the plugin cannot be currently used.

Eg.

curl -v 'https://plugins.gradle.org/m2/org/xbib/gradle/plugin/gradle-plugin-jflex/1.5.0/gradle-plugin-jflex-1.5.0.module'

< HTTP/1.1 303 See Other
< Location: https://jcenter.bintray.com/org/xbib/gradle/plugin/gradle-plugin-jflex/1.5.0/gradle-plugin-jflex-1.5.0.module

An the jcenter link is then dead.

Question about how to use the jflex plugin

Hi,
May I ask how to use the plugin ? I am not experienced with Gradle.
If I do as you presented on the plugin page, no java class is generated.
Do I have to create a task and specify some output folder ( I had like this in ant task ) ?
I mean in ant I had something like below. But only with
apply plugin: 'org.xbib.gradle.plugin.jflex'
gradle does nothing. Do I miss something ?

<target name="JFlexLexers" description="distribution" >
    <jflex file="build/installers/flex/bash.flex" outdir="dbs-app/src/main/java/com/wisecoders/dbs/sql/editor/lexers"/>
</target>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.