11/*
2- Licensed to the Apache Software Foundation (ASF) under one
3- or more contributor license agreements. See the NOTICE file
4- distributed with this work for additional information
5- regarding copyright ownership. The ASF licenses this file
6- to you under the Apache License, Version 2.0 (the
7- "License"); you may not use this file except in compliance
8- with the License. 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,
13- software distributed under the License is distributed on an
14- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15- KIND, either express or implied. See the License for the
16- specific language governing permissions and limitations
17- under the License.
18- */
19-
2+ * Copyright 2007-present the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
2016import java .net .*;
2117import java .io .*;
2218import java .nio .channels .*;
2319import java .util .Properties ;
2420
2521public class MavenWrapperDownloader {
2622
23+ private static final String WRAPPER_VERSION = "0.5.4" ;
2724 /**
2825 * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
2926 */
30- private static final String DEFAULT_DOWNLOAD_URL =
31- "https://repo. maven.apache.org/maven2/io/takari/maven -wrapper/0.4.2/maven-wrapper-0.4.2 .jar" ;
27+ private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+ + WRAPPER_VERSION + "/ maven-wrapper-" + WRAPPER_VERSION + " .jar" ;
3229
3330 /**
3431 * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
@@ -76,13 +73,13 @@ public static void main(String args[]) {
7673 }
7774 }
7875 }
79- System .out .println ("- Downloading from: : " + url );
76+ System .out .println ("- Downloading from: " + url );
8077
8178 File outputFile = new File (baseDirectory .getAbsolutePath (), MAVEN_WRAPPER_JAR_PATH );
8279 if (!outputFile .getParentFile ().exists ()) {
8380 if (!outputFile .getParentFile ().mkdirs ()) {
8481 System .out .println (
85- "- ERROR creating output direcrory '" + outputFile .getParentFile ().getAbsolutePath () + "'" );
82+ "- ERROR creating output directory '" + outputFile .getParentFile ().getAbsolutePath () + "'" );
8683 }
8784 }
8885 System .out .println ("- Downloading to: " + outputFile .getAbsolutePath ());
@@ -98,6 +95,16 @@ public static void main(String args[]) {
9895 }
9996
10097 private static void downloadFileFromURL (String urlString , File destination ) throws Exception {
98+ if (System .getenv ("MVNW_USERNAME" ) != null && System .getenv ("MVNW_PASSWORD" ) != null ) {
99+ String username = System .getenv ("MVNW_USERNAME" );
100+ char [] password = System .getenv ("MVNW_PASSWORD" ).toCharArray ();
101+ Authenticator .setDefault (new Authenticator () {
102+ @ Override
103+ protected PasswordAuthentication getPasswordAuthentication () {
104+ return new PasswordAuthentication (username , password );
105+ }
106+ });
107+ }
101108 URL website = new URL (urlString );
102109 ReadableByteChannel rbc ;
103110 rbc = Channels .newChannel (website .openStream ());
0 commit comments