ludc
2024-09-12 aed7f0e9be4e88a4ed632f9ca7aca05fa1e7f6b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.vci;
 
import java.io.*;
 
/**
 * 批量上传文件到maven私服
 * @author weidy
 * @date 2021/6/2
 */
public class BatchRedeployJar2Maven {
 
    public static final String MAVEN_PATH = "C:\\developer\\apache-maven-3.8.1\\bin";
 
    public static final String JAR_CLIENT_PATH = "C:\\developer\\platform2020\\platform-runtime-2022\\libs\\modules\\client";
 
    public static final String JAR_COMMON_PATH = "C:\\developer\\platform2020\\platform-runtime-2022\\libs\\modules\\common";
 
    public static final String JAR_SERVER_PATH = "C:\\developer\\platform2020\\platform-runtime-2022\\libs\\modules\\server";
 
    public static final String JAR_BASE_PATH = "C:\\developer\\platform2020\\platform-runtime-2022\\libs\\base";
 
    public static final String SETTINGS = "${user.home}\\.m2";
 
    public static final String GROUP_ID = "com.vci.platform";
 
    public static final String VERSION = "2022.RELEASE";
 
    public static final String URL = "http://nexus.vci-tech.com:9000/repository/maven-releases";
    public static void main(String[] args) {
 
        /**
         * 使用之前请先安装maven,或者直接使用idea的插件
         * 然后修改上方的jar_xxx_path,如果有增加路径可以自行添加
         */
        BatchRedeployJar2Maven redeploy = new BatchRedeployJar2Maven();
        redeploy.redeploy(JAR_CLIENT_PATH);
        redeploy.redeploy(JAR_COMMON_PATH);
        redeploy.redeploy(JAR_SERVER_PATH);
        redeploy.redeploy(JAR_BASE_PATH);
    }
 
    public void redeploy(String path){
        File folder = new File(path);
        if(folder.exists()) {
            File[] files = folder.listFiles();
            if (files != null) {
                System.out.println("扫描文件夹" + path);
                for (File jarFile : files) {
                    String name = jarFile.getName();
                    String nameNotExtension = name;
                    if (name.contains(".")) {
                        nameNotExtension = name.substring(0, name.lastIndexOf("."));
                    }
                    String cmd = "mvn deploy:deploy-file \"-DgroupId=" + GROUP_ID +
                            "\" \"-DartifactId=" + nameNotExtension + "\" \"-Dversion=" + VERSION + "\" \"-Dpackaging=jar\" \"-Durl=" + URL + "\" \"-Dfile=" + jarFile.getAbsolutePath() + "\" \"-DrepositoryId=rdc-releases\"";
 
                    Process proc = null;
                    try {
                        proc = Runtime.getRuntime().exec(new String[]{"cmd", "/C", cmd}, null, new File(MAVEN_PATH));
                        printMessage(proc.getInputStream());
                        printMessage(proc.getErrorStream());
                        proc.waitFor();
                    } catch (IOException | InterruptedException e) {
                        e.printStackTrace();
                    } finally {
                        if (proc != null) {
                            proc.destroy();
                        }
                    }
                    System.out.println("完成" + name);
                }
                System.out.println("完成扫描文件夹" + path);
            }
        }
 
    }
 
    private static void printMessage( final InputStream input) {
        new Thread(new Runnable() {
            public void run() {
                Reader reader =null;
                BufferedReader bf=null;
                String line = null;
                try {
                    reader= new InputStreamReader(input);
                    bf = new BufferedReader(reader);
                    while((line=bf.readLine())!=null) {
                        System.out.println(line);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    try {
                        if (reader != null) {
                            reader.close();
                        }
                        if (bf != null) {
                            bf.close();
                        }
                    }catch (Throwable e){
 
                    }
                }
            }
        }).start();
    }
}