Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve classpath manifest file construction #842

Merged
merged 1 commit into from
Sep 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions java_stub_template/file/file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,36 +293,30 @@ function create_and_run_classpath_jar() {
# Build class path as one single string separated by spaces
MANIFEST_CLASSPATH=""
if is_windows; then
IFS=';'
CLASSPATH_SEPARATOR=";"
URI_PREFIX="file:/" # e.g. "file:/C:/temp/foo.jar"
else
IFS=':'
CLASSPATH_SEPARATOR=":"
URI_PREFIX="file:$(pwd)/" # e.g. "file:/usr/local/foo.jar"
fi
for x in $CLASSPATH; do
# Add file:/ prefix and escaped space characters, it should be a URI.
x="${URI_PREFIX}${x// /%20}"
MANIFEST_CLASSPATH="$MANIFEST_CLASSPATH $x"
done
unset IFS

URI_PREFIX=${URI_PREFIX//\//\\/}
MANIFEST_CLASSPATH="${CLASSPATH_SEPARATOR}${CLASSPATH}"

MANIFEST_CLASSPATH=$(sed "s/ /%20/g" <<< "${MANIFEST_CLASSPATH}")
MANIFEST_CLASSPATH=$(sed "s/$CLASSPATH_SEPARATOR/ $URI_PREFIX/g" <<< "${MANIFEST_CLASSPATH}")

# Create manifest file
MANIFEST_FILE="$(mktemp -t XXXXXXXX.jar_manifest)"

(
echo "Manifest-Version: 1.0"

CLASSPATH_LINE="Class-Path:$MANIFEST_CLASSPATH"
# No line in the MANIFEST.MF file may be longer than 72 bytes.
# A space prefix indicates the line is still the content of the last attribute.
IFS=$'\n'
WRAPPED_LINES=($(echo "$CLASSPATH_LINE" | fold -w 71))
for ((i = 0; i < "${#WRAPPED_LINES[*]}"; i += 1)); do
PREFIX=" "
if ((i == 0)); then
PREFIX=""
fi
echo "$PREFIX${WRAPPED_LINES[$i]}"
done
CLASSPATH_MANIFEST_LINES=$(sed -E $'s/(.{71})/\\1\\\n /g' <<< "${CLASSPATH_LINE}")
echo "$CLASSPATH_MANIFEST_LINES"
echo "Created-By: Bazel"
) >$MANIFEST_FILE

Expand Down