blob: 846d82707bf98481df798454af8ce1956f9cbf68 [file] [log] [blame]
pierventre16709162020-07-16 20:48:24 +02001#!/bin/bash
pierventre83611422020-08-14 22:53:15 +02002
pierventre16709162020-07-16 20:48:24 +02003#
4# Copyright 2020-present Open Networking Foundation
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
pierventre83611422020-08-14 22:53:15 +020018
19http_proxy=${http_proxy:-}
20https_proxy=${https_proxy:-}
21no_proxy=${no_proxy:-}
22
pierventre16709162020-07-16 20:48:24 +020023if [ -f mvn_settings.custom.xml ] ; then
24 cp mvn_settings.custom.xml mvn_settings.xml
25 exit 0
26fi
27
28cat << EOF > mvn_settings.xml
29<?xml version="1.0" encoding="UTF-8"?>
30
31<!--
32Licensed to the Apache Software Foundation (ASF) under one
33or more contributor license agreements. See the NOTICE file
34distributed with this work for additional information
35regarding copyright ownership. The ASF licenses this file
36to you under the Apache License, Version 2.0 (the
37"License"); you may not use this file except in compliance
38with the License. You may obtain a copy of the License at
39
40 http://www.apache.org/licenses/LICENSE-2.0
41
42Unless required by applicable law or agreed to in writing,
43software distributed under the License is distributed on an
44"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
45KIND, either express or implied. See the License for the
46specific language governing permissions and limitations
47under the License.
48-->
49
50<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
51 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
52 xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
53 <!--PROXY-->
54 <!--EXTRA-->
Daniele Morof969c742022-01-03 22:01:00 +010055 <!--MIRRORS-->
pierventre16709162020-07-16 20:48:24 +020056</settings>
57EOF
58
59if [ "$http_proxy$https_proxy" != "" ] ; then
60 echo " <proxies>" >> mvn_settings.proxy.xml
61 for PROTOCOL in http https ; do
62 proxy="${PROTOCOL}_proxy"
63 proxy="${!proxy}"
64 if [ "$proxy" = "" ] ; then continue ; fi
65
66 # username/password not yet included
67 PROXY_HOST=$(echo "$proxy" | sed "s@.*://@@;s/.*@//;s@:.*@@")
68 PROXY_PORT=$(echo "$proxy" | sed "s@.*://@@;s@.*:@@;s@/.*@@")
69 NON_PROXY=$(echo "$no_proxy" | sed "s@,@|@g")
70
71 echo " <proxy>
72 <id>$PROTOCOL</id>
73 <active>true</active>
74 <protocol>$PROTOCOL</protocol>
75 <host>$PROXY_HOST</host>
76 <port>$PROXY_PORT</port>
77 <nonProxyHosts>$NON_PROXY</nonProxyHosts>
78 </proxy>" >> mvn_settings.proxy.xml
79 done
80 echo " </proxies>" >> mvn_settings.proxy.xml
81
82 sed -i '/<!--PROXY-->/r mvn_settings.proxy.xml' mvn_settings.xml
83 rm mvn_settings.proxy.xml
84fi
85
Daniele Morof969c742022-01-03 22:01:00 +010086if [ "$USE_LOCAL_SNAPSHOT_ARTIFACTS" == "true" ]; then
87 # When using local SNAPSHOT artifacts, we need to prevent maven to fetch from the Sonatype repository.
88 # However, we need to point to a valid maven repository otherwise maven fails. For this reason we
89 # mirror snapshots to maven central (that won't contain any SNAPSHOT artifacts).
90 echo " <mirrors>
91 <mirror>
92 <id>central_snapshots</id>
93 <name>central_snapshots</name>
94 <url>https://repo.maven.apache.org/maven2</url>
95 <mirrorOf>snapshots</mirrorOf>
96 </mirror>
97 </mirrors>" >> mvn_settings.mirror.xml
98 sed -i '' -e '/<!--MIRRORS-->/r mvn_settings.mirror.xml' mvn_settings.xml
99 rm mvn_settings.mirror.xml
100fi
101
pierventre16709162020-07-16 20:48:24 +0200102if [ -f mvn_settings.extra.xml ] ; then
103 sed -i 's/<!--EXTRA-->/r mvn_settings.extra.xml' mvn_settings.xml
104fi