Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Generate settings.xml if MAVEN_MIRROR_URL is set #429

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions dockerfiles/remote-plugin-java11/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ RUN apk --no-cache add openjdk11 --repository=http://dl-cdn.alpinelinux.org/alpi
&& apk add procps nss \
&& chmod 777 /home/theia
ENV JAVA_HOME /usr/lib/jvm/default-jvm/
ADD etc/before-start.sh /before-start.sh
WORKDIR /projects
44 changes: 44 additions & 0 deletions dockerfiles/remote-plugin-java11/etc/before-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh
#
# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

set_maven_mirror() {
local m2="$HOME"/.m2
local settingsXML="$m2"/settings.xml

[ ! -d "$m2" ] && mkdir -p "$m2"

if [ ! -f "$settingsXML" ]; then
echo "<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\"" >> "$settingsXML"
echo " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" >> "$settingsXML"
echo " xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0" >> "$settingsXML"
echo " https://maven.apache.org/xsd/settings-1.0.0.xsd\">" >> "$settingsXML"
echo " <mirrors>" >> "$settingsXML"
echo " <mirror>" >> "$settingsXML"
echo " <url>\${env.MAVEN_MIRROR_URL}</url>" >> "$settingsXML"
echo " <mirrorOf>external:*</mirrorOf>" >> "$settingsXML"
echo " </mirror>" >> "$settingsXML"
echo " </mirrors>" >> "$settingsXML"
echo "</settings>" >> "$settingsXML"
else
if ! grep -q "<url>\${env.MAVEN_MIRROR_URL}</url>" "$settingsXML"; then
if grep -q "<mirrors>" "$settingsXML"; then
sed -i 's/<mirrors>/<mirrors>\n <mirror>\n <url>${env.MAVEN_MIRROR_URL}<\/url>\n <mirrorOf>external:\*<\/mirrorOf>\n <\/mirror>/' "$settingsXML"
else
sed -i 's/<\/settings>/ <mirrors>\n <mirror>\n <url>${env.MAVEN_MIRROR_URL}<\/url>\n <mirrorOf>external:*<\/mirrorOf>\n <\/mirror>\n <\/mirrors>\n<\/settings>/' "$settingsXML"
fi
fi
fi
}

[ ! -z "$MAVEN_MIRROR_URL" ] && set_maven_mirror
return 0
1 change: 1 addition & 0 deletions dockerfiles/remote-plugin-java8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
FROM ${BUILD_ORGANIZATION}/${BUILD_PREFIX}-theia-endpoint-runtime:${BUILD_TAG}
RUN apk --update --no-cache add openjdk8 procps nss
ENV JAVA_HOME /usr/lib/jvm/default-jvm/
ADD etc/before-start.sh /before-start.sh
WORKDIR /projects
43 changes: 43 additions & 0 deletions dockerfiles/remote-plugin-java8/etc/before-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh
#
# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#
set_maven_mirror() {
local m2="$HOME"/.m2
local settingsXML="$m2"/settings.xml

[ ! -d "$m2" ] && mkdir -p "$m2"

if [ ! -f "$settingsXML" ]; then
echo "<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\"" >> "$settingsXML"
echo " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" >> "$settingsXML"
echo " xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0" >> "$settingsXML"
echo " https://maven.apache.org/xsd/settings-1.0.0.xsd\">" >> "$settingsXML"
echo " <mirrors>" >> "$settingsXML"
echo " <mirror>" >> "$settingsXML"
echo " <url>\${env.MAVEN_MIRROR_URL}</url>" >> "$settingsXML"
echo " <mirrorOf>external:*</mirrorOf>" >> "$settingsXML"
echo " </mirror>" >> "$settingsXML"
echo " </mirrors>" >> "$settingsXML"
echo "</settings>" >> "$settingsXML"
else
if ! grep -q "<url>\${env.MAVEN_MIRROR_URL}</url>" "$settingsXML"; then
if grep -q "<mirrors>" "$settingsXML"; then
sed -i 's/<mirrors>/<mirrors>\n <mirror>\n <url>${env.MAVEN_MIRROR_URL}<\/url>\n <mirrorOf>external:\*<\/mirrorOf>\n <\/mirror>/' "$settingsXML"
else
sed -i 's/<\/settings>/ <mirrors>\n <mirror>\n <url>${env.MAVEN_MIRROR_URL}<\/url>\n <mirrorOf>external:*<\/mirrorOf>\n <\/mirror>\n <\/mirrors>\n<\/settings>/' "$settingsXML"
fi
fi
fi
}

[ ! -z "$MAVEN_MIRROR_URL" ] && set_maven_mirror
return 0
2 changes: 2 additions & 0 deletions dockerfiles/theia-endpoint-runtime/etc/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ trap 'responsible_shutdown' SIGHUP SIGTERM SIGINT

cd ${HOME}

[ -f "/before-start.sh" ] && . "/before-start.sh"

# run theia endpoint
node /home/theia/lib/node/plugin-remote.js &

Expand Down