Skip to content

Commit c18f15c

Browse files
committed
add ci workflow
1 parent c7f8d32 commit c18f15c

File tree

5 files changed

+610
-0
lines changed

5 files changed

+610
-0
lines changed
+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
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+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
private static final String WRAPPER_VERSION = "0.5.6";
23+
/**
24+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
25+
*/
26+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
27+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
28+
29+
/**
30+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
31+
* use instead of the default one.
32+
*/
33+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
34+
".mvn/wrapper/maven-wrapper.properties";
35+
36+
/**
37+
* Path where the maven-wrapper.jar will be saved to.
38+
*/
39+
private static final String MAVEN_WRAPPER_JAR_PATH =
40+
".mvn/wrapper/maven-wrapper.jar";
41+
42+
/**
43+
* Name of the property which should be used to override the default download url for the wrapper.
44+
*/
45+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
46+
47+
public static void main(String args[]) {
48+
System.out.println("- Downloader started");
49+
File baseDirectory = new File(args[0]);
50+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
51+
52+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
53+
// wrapperUrl parameter.
54+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
55+
String url = DEFAULT_DOWNLOAD_URL;
56+
if(mavenWrapperPropertyFile.exists()) {
57+
FileInputStream mavenWrapperPropertyFileInputStream = null;
58+
try {
59+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
60+
Properties mavenWrapperProperties = new Properties();
61+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
62+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
63+
} catch (IOException e) {
64+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
65+
} finally {
66+
try {
67+
if(mavenWrapperPropertyFileInputStream != null) {
68+
mavenWrapperPropertyFileInputStream.close();
69+
}
70+
} catch (IOException e) {
71+
// Ignore ...
72+
}
73+
}
74+
}
75+
System.out.println("- Downloading from: " + url);
76+
77+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
78+
if(!outputFile.getParentFile().exists()) {
79+
if(!outputFile.getParentFile().mkdirs()) {
80+
System.out.println(
81+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
82+
}
83+
}
84+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
85+
try {
86+
downloadFileFromURL(url, outputFile);
87+
System.out.println("Done");
88+
System.exit(0);
89+
} catch (Throwable e) {
90+
System.out.println("- Error downloading");
91+
e.printStackTrace();
92+
System.exit(1);
93+
}
94+
}
95+
96+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
97+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
98+
String username = System.getenv("MVNW_USERNAME");
99+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
100+
Authenticator.setDefault(new Authenticator() {
101+
@Override
102+
protected PasswordAuthentication getPasswordAuthentication() {
103+
return new PasswordAuthentication(username, password);
104+
}
105+
});
106+
}
107+
URL website = new URL(urlString);
108+
ReadableByteChannel rbc;
109+
rbc = Channels.newChannel(website.openStream());
110+
FileOutputStream fos = new FileOutputStream(destination);
111+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
112+
fos.close();
113+
rbc.close();
114+
}
115+
116+
}

.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.

.mvn/wrapper/maven-wrapper.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

0 commit comments

Comments
 (0)