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

Commit

Permalink
Generate settings.xml if MAVEN_MIRROR_URL is set (#429)
Browse files Browse the repository at this point in the history
* Generate settings.xml

Signed-off-by: Anatoliy Bazko <abazko@redhat.com>
  • Loading branch information
tolusha authored Sep 10, 2019
1 parent f9c2a75 commit fc11a43
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
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

0 comments on commit fc11a43

Please sign in to comment.