Skip to content

Commit 277c5bc

Browse files
committed
first commit
0 parents  commit 277c5bc

File tree

11 files changed

+687
-0
lines changed

11 files changed

+687
-0
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

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

.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
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.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar

README.md

66 Bytes

tinystruct-netty-http-server

0 commit comments

Comments
 (0)