This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate settings.xml if MAVEN_MIRROR_URL is set (#429)
* Generate settings.xml Signed-off-by: Anatoliy Bazko <abazko@redhat.com>
- Loading branch information
1 parent
87e183a
commit a8889be
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters