首页>代码>基于SpringBoot框架开发的简单商城后台管理系统>/myshop/.mvn/wrapper/MavenWrapperDownloader.java
001/*
002Licensed to the Apache Software Foundation (ASF) under one
003or more contributor license agreements.  See the NOTICE file
004distributed with this work for additional information
005regarding copyright ownership.  The ASF licenses this file
006to you under the Apache License, Version 2.0 (the
007"License"); you may not use this file except in compliance
008with the License.  You may obtain a copy of the License at
009 
011 
012Unless required by applicable law or agreed to in writing,
013software distributed under the License is distributed on an
014"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015KIND, either express or implied.  See the License for the
016specific language governing permissions and limitations
017under the License.
018*/
019 
020import java.io.File;
021import java.io.FileInputStream;
022import java.io.FileOutputStream;
023import java.io.IOException;
024import java.net.URL;
025import java.nio.channels.Channels;
026import java.nio.channels.ReadableByteChannel;
027import java.util.Properties;
028 
029public class MavenWrapperDownloader {
030 
031    /**
032     * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
033     */
034    private static final String DEFAULT_DOWNLOAD_URL =
036 
037    /**
038     * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
039     * use instead of the default one.
040     */
041    private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
042            ".mvn/wrapper/maven-wrapper.properties";
043 
044    /**
045     * Path where the maven-wrapper.jar will be saved to.
046     */
047    private static final String MAVEN_WRAPPER_JAR_PATH =
048            ".mvn/wrapper/maven-wrapper.jar";
049 
050    /**
051     * Name of the property which should be used to override the default download url for the wrapper.
052     */
053    private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
054 
055    public static void main(String args[]) {
056        System.out.println("- Downloader started");
057        File baseDirectory = new File(args[0]);
058        System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
059 
060        // If the maven-wrapper.properties exists, read it and check if it contains a custom
061        // wrapperUrl parameter.
062        File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
063        String url = DEFAULT_DOWNLOAD_URL;
064        if (mavenWrapperPropertyFile.exists()) {
065            FileInputStream mavenWrapperPropertyFileInputStream = null;
066            try {
067                mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
068                Properties mavenWrapperProperties = new Properties();
069                mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
070                url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
071            } catch (IOException e) {
072                System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
073            } finally {
074                try {
075                    if (mavenWrapperPropertyFileInputStream != null) {
076                        mavenWrapperPropertyFileInputStream.close();
077                    }
078                } catch (IOException e) {
079                    // Ignore ...
080                }
081            }
082        }
083        System.out.println("- Downloading from: : " + url);
084 
085        File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
086        if (!outputFile.getParentFile().exists()) {
087            if (!outputFile.getParentFile().mkdirs()) {
088                System.out.println(
089                        "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
090            }
091        }
092        System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
093        try {
094            downloadFileFromURL(url, outputFile);
095            System.out.println("Done");
096            System.exit(0);
097        } catch (Throwable e) {
098            System.out.println("- Error downloading");
099            e.printStackTrace();
100            System.exit(1);
101        }
102    }
103 
104    private static void downloadFileFromURL(String urlString, File destination) throws Exception {
105        URL website = new URL(urlString);
106        ReadableByteChannel rbc;
107        rbc = Channels.newChannel(website.openStream());
108        FileOutputStream fos = new FileOutputStream(destination);
109        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
110        fos.close();
111        rbc.close();
112    }
113 
114}
最近下载更多
林间听风  LV10 6月24日
C544350851  LV27 6月2日
15578157792  LV7 2024年10月24日
artemiszer0  LV2 2024年7月4日
zhezhizzzz  LV2 2024年6月29日
TY0165  LV20 2024年6月26日
计科一班  LV7 2024年6月18日
yyhrhv  LV8 2024年5月30日
llllllK  LV5 2024年5月13日
Luck_ZDM  LV12 2024年4月12日
最近浏览更多
C544350851  LV27 6月2日
sn764889012 4月16日
暂无贡献等级
cainiao1101 2月11日
暂无贡献等级
王愉悦  LV4 2024年12月3日
haomc052829  LV4 2024年12月3日
yoyo123  LV1 2024年11月26日
wanglonggggg 2024年11月8日
暂无贡献等级
yangchengshuai  LV16 2024年10月29日
15578157792  LV7 2024年10月24日
bluerstar  LV1 2024年10月23日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友