166166# Java build tools (Maven, Gradle, sbt) do not honor HTTP_PROXY/HTTPS_PROXY env vars
167167# and need explicit proxy configuration files
168168if [ -n " $HTTP_PROXY " ]; then
169- # Extract proxy host and port from HTTP_PROXY (format: http://IP:PORT)
170- PROXY_HOST=" ${HTTP_PROXY# http:// } "
171- PROXY_HOST=" ${PROXY_HOST%:* } "
172- PROXY_PORT=" ${SQUID_PROXY_PORT:- 3128} "
169+ # Determine proxy host and port for JVM tools.
170+ # Prefer SQUID_PROXY_HOST/SQUID_PROXY_PORT (set by docker-manager.ts) over parsing HTTP_PROXY,
171+ # since HTTP_PROXY parsing is brittle (doesn't handle https://, credentials, IPv6, etc.)
172+ if [ -n " $SQUID_PROXY_HOST " ] && [ -n " $SQUID_PROXY_PORT " ]; then
173+ PROXY_HOST=" $SQUID_PROXY_HOST "
174+ PROXY_PORT=" $SQUID_PROXY_PORT "
175+ else
176+ # Fallback: extract from HTTP_PROXY (format: http://HOST:PORT)
177+ PROXY_HOST=" ${HTTP_PROXY# http:// } "
178+ PROXY_HOST=" ${PROXY_HOST# https:// } "
179+ PROXY_HOST=" ${PROXY_HOST#*@ } " # strip credentials if present
180+ PROXY_PORT=" ${PROXY_HOST##*: } " # extract port after last colon
181+ PROXY_HOST=" ${PROXY_HOST%:* } " # strip port
182+ PROXY_PORT=" ${PROXY_PORT:- 3128} " # default port
183+ fi
173184
174185 # Determine path prefix for config files (chroot-aware, same pattern as .claude.json)
175186 if [ " ${AWF_CHROOT_ENABLED} " = " true" ]; then
@@ -181,8 +192,10 @@ if [ -n "$HTTP_PROXY" ]; then
181192 echo " [entrypoint] Pre-seeding JVM build tool proxy configuration (${PROXY_HOST} :${PROXY_PORT} )..."
182193
183194 # Maven proxy config (~/.m2/settings.xml)
195+ # Only create if the file does not already exist, to avoid clobbering user-provided settings
184196 mkdir -p " ${JVM_HOME_PREFIX} /.m2"
185- cat > " ${JVM_HOME_PREFIX} /.m2/settings.xml" << MAVEN_EOF
197+ if [ ! -f " ${JVM_HOME_PREFIX} /.m2/settings.xml" ]; then
198+ cat > " ${JVM_HOME_PREFIX} /.m2/settings.xml" << MAVEN_EOF
186199<settings>
187200 <proxies>
188201 <proxy>
@@ -202,24 +215,43 @@ if [ -n "$HTTP_PROXY" ]; then
202215 </proxies>
203216</settings>
204217MAVEN_EOF
205- chown awfuser:awfuser " ${JVM_HOME_PREFIX} /.m2/settings.xml" 2> /dev/null || true
206- echo " [entrypoint] ✓ Created Maven proxy config (${JVM_HOME_PREFIX} /.m2/settings.xml)"
218+ chown awfuser:awfuser " ${JVM_HOME_PREFIX} /.m2/settings.xml" 2> /dev/null || true
219+ echo " [entrypoint] ✓ Created Maven proxy config (${JVM_HOME_PREFIX} /.m2/settings.xml)"
220+ else
221+ echo " [entrypoint] ✓ Maven settings.xml already exists, skipping proxy config creation"
222+ fi
207223
208224 # Gradle proxy config (~/.gradle/gradle.properties)
225+ # Only create if the file does not already exist, to avoid clobbering user-provided settings
226+ # (e.g., org.gradle.jvmargs, build cache settings, private repo credentials)
209227 mkdir -p " ${JVM_HOME_PREFIX} /.gradle"
210- cat > " ${JVM_HOME_PREFIX} /.gradle/gradle.properties" << GRADLE_EOF
228+ if [ ! -f " ${JVM_HOME_PREFIX} /.gradle/gradle.properties" ]; then
229+ cat > " ${JVM_HOME_PREFIX} /.gradle/gradle.properties" << GRADLE_EOF
211230systemProp.http.proxyHost=${PROXY_HOST}
212231systemProp.http.proxyPort=${PROXY_PORT}
213232systemProp.https.proxyHost=${PROXY_HOST}
214233systemProp.https.proxyPort=${PROXY_PORT}
215234GRADLE_EOF
216- chown awfuser:awfuser " ${JVM_HOME_PREFIX} /.gradle/gradle.properties" 2> /dev/null || true
217- echo " [entrypoint] ✓ Created Gradle proxy config (${JVM_HOME_PREFIX} /.gradle/gradle.properties)"
235+ chown awfuser:awfuser " ${JVM_HOME_PREFIX} /.gradle/gradle.properties" 2> /dev/null || true
236+ echo " [entrypoint] ✓ Created Gradle proxy config (${JVM_HOME_PREFIX} /.gradle/gradle.properties)"
237+ else
238+ echo " [entrypoint] ✓ Gradle gradle.properties already exists, skipping proxy config creation"
239+ fi
218240
219241 # sbt/JVM proxy config via JAVA_TOOL_OPTIONS
220242 # This covers sbt and any JVM tool that reads standard system properties
221- export JAVA_TOOL_OPTIONS=" ${JAVA_TOOL_OPTIONS:- } -Dhttp.proxyHost=${PROXY_HOST} -Dhttp.proxyPort=${PROXY_PORT} -Dhttps.proxyHost=${PROXY_HOST} -Dhttps.proxyPort=${PROXY_PORT} "
222- echo " [entrypoint] ✓ Set JAVA_TOOL_OPTIONS with proxy flags"
243+ # Also set nonProxyHosts from NO_PROXY to prevent JVM tools from proxying localhost traffic
244+ NON_PROXY_RAW=" ${NO_PROXY:- ${no_proxy:- } } "
245+ JVM_PROXY_FLAGS=" -Dhttp.proxyHost=${PROXY_HOST} -Dhttp.proxyPort=${PROXY_PORT} -Dhttps.proxyHost=${PROXY_HOST} -Dhttps.proxyPort=${PROXY_PORT} "
246+ if [ -n " $NON_PROXY_RAW " ]; then
247+ # Convert comma-separated NO_PROXY to Java's pipe-separated nonProxyHosts format
248+ NON_PROXY_HOSTS=$( printf ' %s' " $NON_PROXY_RAW " | tr ' ,' ' |' | tr -d ' ' )
249+ JVM_PROXY_FLAGS=" ${JVM_PROXY_FLAGS} -Dhttp.nonProxyHosts=${NON_PROXY_HOSTS} -Dhttps.nonProxyHosts=${NON_PROXY_HOSTS} "
250+ echo " [entrypoint] ✓ Set JAVA_TOOL_OPTIONS with proxy and nonProxyHosts flags"
251+ else
252+ echo " [entrypoint] ✓ Set JAVA_TOOL_OPTIONS with proxy flags"
253+ fi
254+ export JAVA_TOOL_OPTIONS=" ${JAVA_TOOL_OPTIONS:- } ${JVM_PROXY_FLAGS} "
223255fi
224256
225257# Print proxy environment
0 commit comments