mirror of https://github.com/apache/maven.git
- Made the script use curl or wget if available and fallback to java in case none of them are.
- Moved the Java source code to the filesystem.
This commit is contained in:
parent
5a6e53da1c
commit
69369d2ead
|
@ -0,0 +1,38 @@
|
||||||
|
import java.net.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.channels.*;
|
||||||
|
|
||||||
|
public class MavenWrapperDownloader {
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
System.out.println("- Downloader started");
|
||||||
|
String url="http://central.maven.org/maven2/io/takari/maven-wrapper/0.2.1/maven-wrapper-0.2.1.jar";
|
||||||
|
File baseDirectory = new File(args[0]);
|
||||||
|
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||||
|
File outputFile = new File(baseDirectory.getAbsolutePath(), ".mvn/wrapper/maven-wrapper.jar");
|
||||||
|
if(!outputFile.getParentFile().exists()) {
|
||||||
|
outputFile.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -200,69 +200,43 @@ if [ -z "$BASE_DIR" ]; then
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
##########################################################################################
|
||||||
|
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||||
|
# This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||||
|
##########################################################################################
|
||||||
|
|
||||||
|
JAR_URL="http://central.maven.org/maven2/io/takari/maven-wrapper/0.2.1/maven-wrapper-0.2.1.jar"
|
||||||
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
|
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
|
||||||
echo "Found .mvn/wrapper/maven-wrapper.jar"
|
echo "Found .mvn/wrapper/maven-wrapper.jar"
|
||||||
else
|
else
|
||||||
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
||||||
|
if which wget >/dev/null; then
|
||||||
javaClass="/tmp/MavenWrapperDownloader.java"
|
echo "Found wget ... using wget"
|
||||||
if [ ! -e "$javaClass" ]; then
|
wget ‐‐output-document=.mvn/wrapper/maven-wrapper.jar "$JAR_URL"
|
||||||
echo " - Generating MavenWrapperDownloader.java ..."
|
elif which curl >/dev/null; then
|
||||||
# Generating downloader application java class ...
|
echo "Found curl ... using curl"
|
||||||
cat <<EOF >"$javaClass"
|
curl -o .mvn/wrapper/maven-wrapper.jar "$JAR_URL"
|
||||||
import java.net.*;
|
else
|
||||||
import java.io.*;
|
echo "Falling back to using Java to download"
|
||||||
import java.nio.channels.*;
|
javaClass=".mvn/wrapper/MavenWrapperDownloader.java"
|
||||||
|
if [ -e "$javaClass" ]; then
|
||||||
public class MavenWrapperDownloader {
|
if [ ! -e ".mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||||
|
|
||||||
public static void main(String args[]) {
|
|
||||||
System.out.println("- Downloader started");
|
|
||||||
String url="http://central.maven.org/maven2/io/takari/maven-wrapper/0.2.1/maven-wrapper-0.2.1.jar";
|
|
||||||
File baseDirectory = new File(args[0]);
|
|
||||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
|
||||||
File outputFile = new File(baseDirectory.getAbsolutePath(), ".mvn/wrapper/maven-wrapper.jar");
|
|
||||||
if(!outputFile.getParentFile().exists()) {
|
|
||||||
outputFile.getParentFile().mkdirs();
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
classFile=$(dirname "$javaClass")/MavenWrapperDownloader.class
|
|
||||||
if [ ! -e "$classFile" ]; then
|
|
||||||
echo " - Compiling MavenWrapperDownloader.java ..."
|
echo " - Compiling MavenWrapperDownloader.java ..."
|
||||||
# Compiling the Java class
|
# Compiling the Java class
|
||||||
("$JAVA_HOME/bin/javac" "$javaClass")
|
("$JAVA_HOME/bin/javac" "$javaClass")
|
||||||
fi
|
fi
|
||||||
|
if [ -e ".mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||||
# Running the downloader
|
# Running the downloader
|
||||||
echo " - Running MavenWrapperDownloader.java ..."
|
echo " - Running MavenWrapperDownloader.java ..."
|
||||||
echo "$MAVEN_PROJECTBASEDIR"
|
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
|
||||||
("$JAVA_HOME/bin/java" -cp /tmp MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
##########################################################################################
|
||||||
|
# End of extension
|
||||||
|
##########################################################################################
|
||||||
|
|
||||||
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
|
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
|
||||||
if [ "$MVNW_VERBOSE" = true ]; then
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
|
Loading…
Reference in New Issue