Skip to content

Commit 2840bc3

Browse files
committed
Merge branch 'command-line-script-improvements' of https://github.com/cboehme/metafacture-core into cboehme-command-line-script-improvements
2 parents fce7708 + 27bdb57 commit 2840bc3

File tree

7 files changed

+159
-26
lines changed

7 files changed

+159
-26
lines changed

.gitattributes

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
*.bat eol=crlf
1818
*.sh eol=lf
1919

20+
# The batch script can only handle the config
21+
# properly if it uses crlf as end-of-line marker:
22+
src/main/config/java-options.conf eol=crlf
23+
2024
# Denote all files that are truly binary and should not be modified:
2125
*.bz2 binary
2226
*.bzip2 binary
2327
*.gz binary
2428
*.gzip binary
25-
*.xz binary
29+
*.xz binary

pom.xml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,30 @@
149149
<plugin>
150150
<artifactId>maven-assembly-plugin</artifactId>
151151
<version>2.2.1</version>
152-
<configuration>
153-
<descriptors>
154-
<descriptor>/src/main/assembly/assembly.xml</descriptor>
155-
</descriptors>
156-
<archive>
157-
<manifest>
158-
<mainClass>org.culturegraph.mf.Flux</mainClass>
159-
<addClasspath>true</addClasspath>
160-
<classpathPrefix>lib/</classpathPrefix>
161-
</manifest>
162-
<manifestEntries>
163-
<git-commit>${buildNumber}</git-commit>
164-
</manifestEntries>
165-
</archive>
166-
</configuration>
152+
<executions>
153+
<execution>
154+
<id>create-distribution-package</id>
155+
<phase>package</phase>
156+
<goals>
157+
<goal>single</goal>
158+
</goals>
159+
<configuration>
160+
<descriptors>
161+
<descriptor>/src/main/assembly/assembly.xml</descriptor>
162+
</descriptors>
163+
<archive>
164+
<manifest>
165+
<mainClass>org.culturegraph.mf.Flux</mainClass>
166+
<addClasspath>true</addClasspath>
167+
<classpathPrefix>lib/</classpathPrefix>
168+
</manifest>
169+
<manifestEntries>
170+
<git-commit>${buildNumber}</git-commit>
171+
</manifestEntries>
172+
</archive>
173+
</configuration>
174+
</execution>
175+
</executions>
167176
</plugin>
168177

169178
<plugin>

src/main/assembly/assembly.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@
5353
<fileMode>0755</fileMode>
5454
<lineEnding>lf</lineEnding>
5555
</fileSet>
56+
<fileSet>
57+
<directory>${project.basedir}/src/main/config/</directory>
58+
<outputDirectory>config/</outputDirectory>
59+
<includes>
60+
<include>java-options.conf</include>
61+
<include>log4j.xml</include>
62+
</includes>
63+
<directoryMode>0755</directoryMode>
64+
<fileMode>0644</fileMode>
65+
<lineEnding>crlf</lineEnding>
66+
</fileSet>
5667
<fileSet>
5768
<directory>examples/</directory>
5869
<outputDirectory>examples/</outputDirectory>

src/main/config/java-options.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# JVM options in this file are passed to the java command.
2+
# Environment variables can be specified by prefixing them
3+
# with $ (e.g. $VAR). The variable $METAFACTURE_HOME refers
4+
# to the folder containing the flux start-up script.
5+
# Undefined variables remain in the configuration.
6+
7+
-Xmx512m
8+
-Dlog4j.configuration="file:///$METAFACTURE_HOME/config/log4j.xml"
9+
10+
# Append additional options defined in the
11+
# environment (The start-up script ensures
12+
# that this variable is always defined):
13+
$FLUX_JAVA_OPTIONS

src/main/config/log4j.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
33

44
<log4j:configuration>
5-
<appender name="stout" class="org.apache.log4j.ConsoleAppender">
5+
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
66
<layout class="org.apache.log4j.PatternLayout">
77
<param name="ConversionPattern"
88
value="%-5p [%t] [%c{1}] %m%n" />
@@ -12,7 +12,7 @@
1212

1313
<root>
1414
<priority value="info" />
15-
<appender-ref ref="stout" />
15+
<appender-ref ref="stdout" />
1616
</root>
1717

1818
</log4j:configuration>

src/main/scripts/flux.bat

100644100755
Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
@echo off
2-
java -Xmx512M -jar "%~dp0${project.build.finalName}.jar" %*
1+
@ECHO OFF
2+
3+
SETLOCAL EnableDelayedExpansion
4+
5+
SET METAFACTURE_HOME=%~dp0
6+
7+
REM Use the java command available on the path by default.
8+
REM Define FLUX_JAVA_BIN in your environment to use a
9+
REM different executable.
10+
IF "x%FLUX_JAVA_BIN%" == "x" (
11+
SET FLUX_JAVA_BIN=java
12+
)
13+
14+
SET JAVA_OPTS_FILE="%METAFACTURE_HOME%\config\java-options.conf"
15+
SET JAR_FILE="%METAFACTURE_HOME%${project.build.finalName}.jar"
16+
17+
REM Read JVM options from configuration file. Lines starting
18+
REM with # are treated as comments. Empty lines are ignored.
19+
REM
20+
REM The space character at the end of the following
21+
REM line is important and must not be removed:
22+
SET JAVA_OPTS=
23+
<%JAVA_OPTS_FILE% (
24+
FOR /F %%I IN ('FINDSTR /N "^" %JAVA_OPTS_FILE%') DO (
25+
SET /P LINE=
26+
IF NOT "x!LINE!" == "x" (
27+
SET FIRST=!LINE:~0,1!
28+
IF NOT "!FIRST!" == "#" (
29+
SET JAVA_OPTS=!JAVA_OPTS! !LINE!
30+
)
31+
)
32+
SET LINE=
33+
)
34+
)
35+
36+
REM Substitute environment variables in the configuration.
37+
REM Undefined variables remain in the configuration. Since
38+
REM FLUX_JAVA_OPTIONS is included in the configuration by
39+
REM default we make sure that it can always be substituted.
40+
IF "x%FLUX_JAVA_OPTIONS%" == "x" (
41+
REM The space character at the end of the following
42+
REM line is important and must not be removed:
43+
SET FLUX_JAVA_OPTIONS=
44+
)
45+
FOR /F "tokens=1,* delims==" %%I IN ('SET') DO (
46+
SET JAVA_OPTS=!JAVA_OPTS:$%%I=%%J!
47+
)
48+
49+
REM Start flux:
50+
%FLUX_JAVA_BIN% !JAVA_OPTS! -jar %JAR_FILE% %*
51+
52+
ENDLOCAL

src/main/scripts/flux.sh

100644100755
Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,59 @@
11
#!/bin/bash
22

3-
dir=`dirname $0`
3+
METAFACTURE_HOME=$( dirname "$( realpath "$0" )" )
44

5-
jarfile="${project.build.finalName}.jar"
5+
# Fix path if running under cygwin:
6+
if uname | grep -iq cygwin ; then
7+
METAFACTURE_HOME=$( cygpath -am "$METAFACTURE_HOME" )
8+
fi
9+
10+
# Use the java command available on the path by default.
11+
# Define FLUX_JAVA_BIN in your environment to use a
12+
# different executable.
13+
if [ -z "$FLUX_JAVA_BIN" ] ; then
14+
FLUX_JAVA_BIN=java
15+
fi
16+
17+
java_opts_file="$METAFACTURE_HOME/config/java-options.conf"
18+
jar_file="$METAFACTURE_HOME/${project.build.finalName}.jar"
19+
20+
# Load java options from configuration file. Lines starting
21+
# with # are treated as comments. Empty lines are ignored.
22+
java_opts=$( cat "$java_opts_file" | grep -v "^#" | tr "\n\r" " " )
623

7-
if uname | grep -iq cygwin; then
8-
java -Xmx512M -jar "`cygpath -am $dir/$jarfile`" $*
9-
else
10-
java -Xmx512M -jar "$dir/$jarfile" $*
24+
# Substitute environment variables. Undefined variables
25+
# remain in the configuration. Since FLUX_JAVA_OPTIONS is
26+
# included in the configuration by default we make sure that
27+
# it can always be substituted.
28+
if [ -z "$FLUX_JAVA_OPTIONS" ] ; then
29+
FLUX_JAVA_OPTIONS=
1130
fi
31+
# This sed script turns the output of set into a sed script
32+
# which replaces the dollar prefixed name of each environment
33+
# variable with its value:
34+
vars_to_script=$( cat <<'EOF'
35+
s/\\/\\\\/g ;
36+
s/!/\\!/g ;
37+
s/='(.*)'$/=\1/ ;
38+
s/^([^=]+)=(.*)$/s!\\$\1!\2!g ; /g
39+
EOF
40+
)
41+
substitute_vars_script=$( set | sed -r "$vars_to_script" )
42+
# Substitute environment variables in the java options:
43+
java_opts=$( echo "$java_opts" | sed "$substitute_vars_script")
1244

45+
# Turn java options string into an array to allow passing
46+
# the options as command parameters. Options may be partially
47+
# quoted with single or double quotes and may contain
48+
# escape sequences. Quotes are removed after splitting because
49+
# the shell quotes the parameters again:
50+
option_pattern="[^\"' ]*(\"[^\"\\]*(\\\\.[^\"\\]*)*\"|'[^'\\]*(\\\\.[^'\\]*)*'|\\.[^\"' ]*)*"
51+
remove_quotes="s/(^[\"'])|(([^\\])[\"'])/\3/g"
52+
java_opts_array=()
53+
while read line ; do
54+
line=$( echo "$line" | sed -r "$remove_quotes" )
55+
java_opts_array+=("$line")
56+
done < <( echo "$java_opts" | grep -Eo "$option_pattern" )
1357

58+
# Start flux:
59+
"$FLUX_JAVA_BIN" "${java_opts_array[@]}" -jar "$jar_file" "$@"

0 commit comments

Comments
 (0)