/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
![avatar](https://profile-avatar.csdnimg.cn/43b834ae8f2b45a19a717fc9b2dae4b9_weixin_47872288.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
码农研究僧
- 粉丝: 28w+
- 资源: 47
最新资源
- 基于comsol异形超表面的手性消光圆二向色镜技术的研究与应用,COMSOL模拟异形超表面手性消光圆二向色镜的光学特性分析,comsol异形超表面手性消光圆二向色镜 ,comsol; 异形超表面; 手
- 基于Vue框架的安徽携睿门户网站设计源码
- 基于MATLAB与Simulink的Stewart平台PID控制仿真研究:运动学与动力学分析,MATLAB下Stewart平台并联机器人的PID控制Simulink Simscape仿真及运动学与动力
- 排序算法的魔法世界:用C语言揭开数据排列的奥秘
- 基于Vue技术的rcdn-rcjy人才大脑-人才就业系统设计源码
- 基于SSM架构的Vue+JavaScript+CSS+HTML校园论坛平台前端设计源码
- 对称双向半桥LLC谐振变换器仿真模型:闭环PI控制与频率调控方法的高效率表现(Matlab Simulink展示),对称双向半桥LLC谐振变换器的闭环PI控制仿真模型输出与效率展示(Matlab Si
- 基于Vue框架的林清其店铺任务管理设计源码
- 基于微信小程序框架的考研帮JavaScript设计源码仓库
- 基于变时域MPC模型预测控制的超车路径规划控制(Carsim 8.1版安装教程及参考文献附送),基于变时域MPC模型预测控制的超车路径规划控制-使用Carsim 8.1版安装教程及参考论文指引,基于
- 基于Matlab Simulink的多风电场协调虚拟惯性下垂控制及频率特性分析:一次调频,风电渗透率可调,超速减载与变桨控制设计,基于Matlab Simulink的多风电场协调虚拟惯性控制研究:下垂
- 计算机世界的寻宝游戏:用C语言解密五大查找算法
- 三相光储充变流器特性概述:双路MPPT输入,宽电压范围,低THD值,高效并网,支持锂电池,便捷安装,友好操作界面,WIFI APP远程控制 ,三相光储充变流器技术方案:双路MPPT输入,宽电压范围,低
- 基于Python开发的工资分布数据分析系统设计源码
- 基于mpvue框架的wx_shop微信小程序跳蚤市场设计源码
- 多智能体编队与避障技术:人工势场下的拓扑结构变换及队形控制研究,多智能体编队与避障技术:拓扑结构下的队形变换与人工势场应用,多智能体编队与避障 #人工势场#多智能体#编队#避障#拓扑结构#队形变
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)