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- http://www.apache.org/licenses/LICENSE-2.0
10- Unless required by applicable law or agreed to in writing,
11- software distributed under the License is distributed on an
12- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13- KIND, either express or implied. See the License for the
14- specific language governing permissions and limitations
15- under the License.
16- */
17-
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+ */
1816import java .net .*;
1917import java .io .*;
2018import java .nio .channels .*;
2119import java .util .Properties ;
2220
2321public class MavenWrapperDownloader {
2422
23+ private static final String WRAPPER_VERSION = "0.5.3" ;
2524 /**
2625 * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
2726 */
28- private static final String DEFAULT_DOWNLOAD_URL =
29- "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" ;
3029
3130 /**
3231 * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
@@ -74,13 +73,13 @@ public static void main(String args[]) {
7473 }
7574 }
7675 }
77- System .out .println ("- Downloading from: : " + url );
76+ System .out .println ("- Downloading from: " + url );
7877
7978 File outputFile = new File (baseDirectory .getAbsolutePath (), MAVEN_WRAPPER_JAR_PATH );
8079 if (!outputFile .getParentFile ().exists ()) {
8180 if (!outputFile .getParentFile ().mkdirs ()) {
8281 System .out .println (
83- "- ERROR creating output direcrory '" + outputFile .getParentFile ().getAbsolutePath () + "'" );
82+ "- ERROR creating output directory '" + outputFile .getParentFile ().getAbsolutePath () + "'" );
8483 }
8584 }
8685 System .out .println ("- Downloading to: " + outputFile .getAbsolutePath ());
@@ -96,6 +95,16 @@ public static void main(String args[]) {
9695 }
9796
9897 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+ }
99108 URL website = new URL (urlString );
100109 ReadableByteChannel rbc ;
101110 rbc = Channels .newChannel (website .openStream ());
0 commit comments