Parses Cron Expressions of the following format:
- (Minute) (hour) (day of month) (month) (day of week) (command)
*
means all possible time units-
a range of time units,
a comma separated list of individual time units/
intervals time units, the left value is the starting value and the right value is the max value
For example given the input argument:
3,45/15 0 1,15 * 1-5 /usr/bin/find
The output should be:
minute 3 18 33 45 48
hour 0
day of month 1 15
month 1 2 3 4 5 6 7 8 9 10 11 12
day of week 1 2 3 4 5
command /usr/bin/find
./gradlew run --args="3,45/15 0 1,15 * 1-5 /usr/bin/find"
or
./gradlew run --args="-arguments 3,45/15 0 1,15 * 1-5 /usr/bin/find"
The build will build two jars:
- A plain jar that is built for use a library at build/libs/cron-parser.jar
- A shadow jar that is built for running as a standalone application build/libs/cron-parser-all.jar
To run the shadow jar if you are planning to pass any arguments with *
notation you may
need to configure your terminal to disable globbing. I found that using zsh shell on my mac this was
and issue. If I try to run the following command:
java -jar build/libs/cron-expression-parser-java-{version}-all.jar 3,45/15 0 1,15 * 1-5 /usr/bin/find
or
java -jar build/libs/cron-expression-parser-java-{version}-all.jar -arguments 3,45/15 0 1,15 * 1-5 /usr/bin/find
Then the following output is returned:
notation parser not found for value gradlew.bat
As you can see the *
has been expanded to include files/folders
from the current directory where the command is being run. This can be fixed by
running the following command to disable globbing:
set -o noglob
Once globbing has been disabled, when the jar command list above is run again the following output will be displayed:
minute 3 18 33 45 48
hour 0
day of month 1 15
month 1 2 3 4 5 6 7 8 9 10 11 12
day of week 1 2 3 4 5
command /usr/bin/find
// cleans build directories
// prints currentVersion
// formats code
// builds code
// runs tests
// checks for gradle issues
// checks dependency versions
./gradlew clean currentVersion dependencyUpdates lintGradle spotlessApply build
The code in this project was originally written in this exercises repo it was extracted out into its this repo once it became reasonably large. The original commit history can be found there.
A new version of the parser is published on each successful pipeline run against the master branch. You can download the runnable jar using the following URL (with the latest version inserted)
https://repo1.maven.org/maven2/com/github/michaelruocco/cron-expression-parser-java/{version}/cron-expression-parser-java-{version}-all.jar
When the jar is downloaded you can run it using the following command:
java -jar cron-expression-parser-java-{version}-all.jar 3,45/15 0 1,15 * 1-5 /usr/bin/find
Don't forget to run set -o noglob
as mentioned previously above to turn of globbing if using a fresh terminal!
The library jar can also be used in a maven or gradle project using the standard dependency definitions outlined
https://search.maven.org/artifact/com.github.michaelruocco/cron-expression-parser-java