You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/02/15 12:05:01 UTC
[maven-studies] branch maven-wrapper updated: Set parent to
maven-parent 34 For a successful build fix issues reported by
apache-rat-plugin and maven-checkstyle-plugin
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch maven-wrapper
in repository https://gitbox.apache.org/repos/asf/maven-studies.git
The following commit(s) were added to refs/heads/maven-wrapper by this push:
new 4128ffa Set parent to maven-parent 34 For a successful build fix issues reported by apache-rat-plugin and maven-checkstyle-plugin
4128ffa is described below
commit 4128ffa116f27a8f971615a45380fdfae6637174
Author: rfscholte <rf...@apache.org>
AuthorDate: Sat Feb 15 13:03:58 2020 +0100
Set parent to maven-parent 34
For a successful build fix issues reported by apache-rat-plugin and maven-checkstyle-plugin
---
.mvn/wrapper/MavenWrapperDownloader.java | 117 ---
.mvn/wrapper/maven-wrapper.jar | Bin 47774 -> 0 bytes
.mvn/wrapper/maven-wrapper.properties | 3 -
CHANGELOG.md | 195 -----
README.md | 193 ----
mvnw | 310 -------
mvnw.cmd | 182 ----
pom.xml | 25 +-
.../apache/maven/wrapper/BootstrapMainStarter.java | 76 +-
.../apache/maven/wrapper/DefaultDownloader.java | 314 ++++---
.../java/org/apache/maven/wrapper/Downloader.java | 34 +-
.../java/org/apache/maven/wrapper/Installer.java | 348 ++++----
src/main/java/org/apache/maven/wrapper/Logger.java | 50 +-
.../org/apache/maven/wrapper/MavenWrapperMain.java | 255 +++---
.../org/apache/maven/wrapper/PathAssembler.java | 212 +++--
.../maven/wrapper/SystemPropertiesHandler.java | 94 +-
.../apache/maven/wrapper/WrapperConfiguration.java | 150 ++--
.../org/apache/maven/wrapper/WrapperExecutor.java | 250 +++---
.../wrapper/cli/AbstractCommandLineConverter.java | 71 +-
.../AbstractPropertiesCommandLineConverter.java | 86 +-
.../wrapper/cli/CommandLineArgumentException.java | 46 +-
.../maven/wrapper/cli/CommandLineConverter.java | 46 +-
.../maven/wrapper/cli/CommandLineOption.java | 212 +++--
.../maven/wrapper/cli/CommandLineParser.java | 968 ++++++++++++---------
.../maven/wrapper/cli/ParsedCommandLine.java | 197 +++--
.../maven/wrapper/cli/ParsedCommandLineOption.java | 76 +-
.../cli/ProjectPropertiesCommandLineConverter.java | 63 +-
.../cli/SystemPropertiesCommandLineConverter.java | 62 +-
src/main/provisio/wrapper.xml | 16 -
.../org/apache/maven/wrapper/DownloaderTest.java | 19 +
.../org/apache/maven/wrapper/InstallerTest.java | 19 +
.../maven/wrapper/SystemPropertiesHandlerTest.java | 19 +
.../apache/maven/wrapper/WrapperExecutorTest.java | 19 +
.../org/apache/maven/wrapper/wrapper.properties | 16 +
34 files changed, 2183 insertions(+), 2560 deletions(-)
diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java
deleted file mode 100644
index b901097..0000000
--- a/.mvn/wrapper/MavenWrapperDownloader.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.net.*;
-import java.io.*;
-import java.nio.channels.*;
-import java.util.Properties;
-
-public class MavenWrapperDownloader {
-
- private static final String WRAPPER_VERSION = "0.5.6";
- /**
- * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
- */
- private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
- + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
-
- /**
- * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
- * use instead of the default one.
- */
- private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
- ".mvn/wrapper/maven-wrapper.properties";
-
- /**
- * Path where the maven-wrapper.jar will be saved to.
- */
- private static final String MAVEN_WRAPPER_JAR_PATH =
- ".mvn/wrapper/maven-wrapper.jar";
-
- /**
- * Name of the property which should be used to override the default download url for the wrapper.
- */
- private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
-
- public static void main(String args[]) {
- System.out.println("- Downloader started");
- File baseDirectory = new File(args[0]);
- System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
-
- // If the maven-wrapper.properties exists, read it and check if it contains a custom
- // wrapperUrl parameter.
- File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
- String url = DEFAULT_DOWNLOAD_URL;
- if(mavenWrapperPropertyFile.exists()) {
- FileInputStream mavenWrapperPropertyFileInputStream = null;
- try {
- mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
- Properties mavenWrapperProperties = new Properties();
- mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
- url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
- } catch (IOException e) {
- System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
- } finally {
- try {
- if(mavenWrapperPropertyFileInputStream != null) {
- mavenWrapperPropertyFileInputStream.close();
- }
- } catch (IOException e) {
- // Ignore ...
- }
- }
- }
- System.out.println("- Downloading from: " + url);
-
- File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
- if(!outputFile.getParentFile().exists()) {
- if(!outputFile.getParentFile().mkdirs()) {
- System.out.println(
- "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
- }
- }
- 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);
- }
- }
-
- private static void downloadFileFromURL(String urlString, File destination) throws Exception {
- if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
- String username = System.getenv("MVNW_USERNAME");
- char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
- Authenticator.setDefault(new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password);
- }
- });
- }
- 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();
- }
-
-}
diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar
deleted file mode 100644
index 41c70a7..0000000
Binary files a/.mvn/wrapper/maven-wrapper.jar and /dev/null differ
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
deleted file mode 100644
index 2743cab..0000000
--- a/.mvn/wrapper/maven-wrapper.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
-wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
-
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index f656285..0000000
--- a/CHANGELOG.md
+++ /dev/null
@@ -1,195 +0,0 @@
-# Changelog
-
-The [git commit history](https://github.com/takari/maven-wrapper/commits/master)
-is the detailed source of all changes. The following provides most information
-at an easier glance.
-
-## Version 0.5.5 - 2019-12-04
-
-- Update to Maven 3.6.3
-
-## Version 0.5.5 - 2019-04-16
-
-- Updated default URL to jar in MavenWrapperDownloader
- - fixes https://github.com/takari/maven-wrapper/issues/118
-- Update to Maven 3.6.1
-
-## Version 0.5.4 - 2019-03-26
-
-- Adapt mvnw.cmd to also honour MVNW_VERBOSE
- - see https://github.com/takari/maven-wrapper/pull/115
- - contributed by Brian de Alwis https://github.com/briandealwis
-- Provide a 'standardized' way to retrieve CLI arguments
- - same as mvn itself
- - see https://github.com/takari/maven-wrapper/pull/113
- - contributed by Guy Brand https://github.com/guylabs
-- Ensure correct executable flag setting
- - fixes https://github.com/takari/maven-wrapper/issues/78
- - contributed by Manfred Moser - http://www.simpligility.com
-- Updated documentation to include plugin version
-
-## Version 0.5.3 - 2019-02-25
-
-- MVNW_REPOURL check bug in mvnw
- - fixes https://github.com/takari/maven-wrapper/issues/109
- - see https://github.com/takari/maven-wrapper/pull/111
- - contributed by Piotrek Żygieło https://github.com/pzygielo and
- Sebastian Peters https://github.com/sepe81,
-
-Release performed by Manfred Moser - http://www.simpligility.com
-
-## Version 0.5.2 - 2019-02-20
-
-- Re-applied TLS1.2 fix for Windows
- - see https://github.com/takari/maven-wrapper/pull/108
- - contributed by Ralph Schaer https://github.com/ralscha
-
-Release performed by Manfred Moser - http://www.simpligility.com
-
-## Version 0.5.1 - 2019-02-19
-
-- Corrected check for MVNW_REPOURL in mvnw.cmd
- - fixes https://github.com/takari/maven-wrapper/issues/106
- - see https://github.com/takari/maven-wrapper/pull/107
- - contributed by Manfred Moser http://www.simpligility.com
-
-Release performed by Manfred Moser - http://www.simpligility.com
-
-## Version 0.5.0 - 2019-02-18
-
-- update to Maven 3.6.0 as default
-- Use TLS 1.2 on Windows
- - see https://github.com/takari/maven-wrapper/pull/89
- - contributed by Julian Hyde https://github.com/julianhyde
-- Fix compile path for cygwin
- - see https://github.com/takari/maven-wrapper/pull/83
- - contributed by Dániel Kovács https://github.com/AFulgens
-- Fix for path with spaces on Windows
- - see https://github.com/takari/maven-wrapper/pull/101
- - contributed by Paul Stöhr https://github.com/CiTuX
-- Support for authentication to corporate repository manager
- - see https://github.com/takari/maven-wrapper/pull/96
- - see https://github.com/takari/maven-wrapper/pull/86
- - contributed by Sebastian Peters https://github.com/sepe81,
- Sander Wartenberg https://github.com/sanderino666 and
- Manfred Moser http://www.simpligility.com
-- Consistent license header across all Java source
- - see https://github.com/takari/maven-wrapper/pull/105
- - fixes https://github.com/takari/maven-wrapper/issues/104
- - contributed by Manfred Moser http://www.simpligility.com
-- Support MVNW_REPOURL environment variable usage
- - during wrapper install and wrapper usage
- - for wrapper and maven distro download
- - in scripts and wrapper binary
- - contributed by Manfred Moser http://www.simpligility.com
-
-Release performed by Manfred Moser - http://www.simpligility.com
-
-## Version 0.4.2 - 2018-07-02
-
-- update to Maven 3.5.4 as default
-- dependency updates
-- end of line in properties file
-- parent pom upgrade
-
-Release performed by Manfred Moser - http://www.simpligility.com
-
-## Version 0.4.0 - 2018-02-19
-
-- Allow for wrapper to work without the jar file
- - see https://github.com/takari/maven-wrapper/pull/60
- - see https://github.com/takari/maven-wrapper/pull/70
- - fixed https://github.com/takari/maven-wrapper/issues/24
- - contributed by Christofer Dutz https://github.com/chrisdutz
- - and Manfred Moser - http://www.simpligility.com
-- Change URLs used to official Maven repo URL
- - done as part of above changes
-
-Release performed by Manfred Moser - http://www.simpligility.com
-
-## Version 0.3.0 - 2017-10-25
-
-- Set title on shell window in Windows
- - see https://github.com/takari/maven-wrapper/pull/66
- - contributed by https://github.com/hcgpragt
-- Change default Maven version to 3.5.2 in wrapper config
- - contributed by Manfred Moser - http://www.simpligility.com
-- Respect MVNW_VERBOSE when printing progress reporting and diagnostic info
- - see https://github.com/takari/maven-wrapper/pull/67
- - contributed by Konstantin Sobolev https://github.com/eprst
-- Smaller chunk size for download progress reporting
- - contributed by Manfred Moser - http://www.simpligility.com
-
-Release performed by Manfred Moser - http://www.simpligility.com
-
-## Version 0.2.2 and 0.2.3 - 2017-09-12
-
-- Print out Maven Wrapper version with each invocation
- - see https://github.com/takari/maven-wrapper/pull/48
- - contributed by Tadaya Tsuyukubo - https://github.com/ttddyy
-- Verbose mode
- - only print out basedir and version in verbose mode
- - set by environment variable MVNW_VERBOSE="true"
- - fixed NPE with https://github.com/takari/maven-wrapper/pull/65
- - contributed by Manfred Moser - http://www.simpligility.com
- - and Tadaya Tsuyukubo https://github.com/ttddyy
-
-Release performed by Manfred Moser - http://www.simpligility.com
-
-## Version 0.2.1 - 2017-04-21
-
-- Compile wrapper with Java 1.5 language level to allow usage with Java1.5 +
- - see https://github.com/takari/maven-wrapper/pull/45
- - contributed by Mark Chesney - https://github.com/mches
-
-Release performed by Manfred Moser - http://www.simpligility.com
-
-## Version 0.2.0 - 2017-04-17
-
-- Use Apple-recommended strategy for locating JAVA_HOME
- - see https://github.com/takari/maven-wrapper/pull/14
- - contributed by Karsten Sperling - https://github.com/ksperling
-- Be defensive about creating directories for files
- - see https://github.com/takari/maven-wrapper/pull/29
- - contributed by Dave Syer - https://github.com/dsyer
-- Fix for paths with spaces on Windows
- - see https://github.com/takari/maven-wrapper/pull/21
- - contributed by Andreas Ahlenstorf - https://github.com/aahlenst
- - also see https://github.com/takari/maven-wrapper/pull/33
- - contributed by https://github.com/vicaya
- - fixes https://github.com/takari/maven-wrapper/issues/31
- - tested on Linux, OSX and Windows
-- Removed unused MAVEN_CMD_LINE_ARGS
- - see https://github.com/takari/maven-wrapper/pull/28
- - contributed by Michal Domagala - https://github.com/michaldo
-- Fix for stale wrapper jar file
- - see https://github.com/takari/maven-wrapper/pull/36
- - contributed by Mark Chesney - https://github.com/mches
- - and Manfred Moser - http://www.simpligility.com
- - fixes https://github.com/takari/maven-wrapper/issues/37
-- Plugin and other project updates
- - contributed by Manfred Moser - http://www.simpligility.com
-- Support for spaces in path on Unix
- - see https://github.com/takari/maven-wrapper/pull/25
- - contributed by https://github.com/beverage
- - and Manfred Moser - http://www.simpligility.com
-- Upgraded default Maven version to 3.5.0
- - contributed by Manfred Moser - http://www.simpligility.com
- - and Fred Bricon
-- Support for simple shell like dash
- - fixes https://github.com/takari/maven-wrapper/issues/34
- - tested by Manfred Moser - http://www.simpligility.com
-- Support for Solaris
- - see https://github.com/takari/maven-wrapper/pull/40
- - fixes https://github.com/takari/maven-wrapper/issues/34
- - contributed by Pelisse Romain https://github.com/rpelisse
-
-Release performed by Manfred Moser - http://www.simpligility.com
-
-## Version 0.1.6 - 2016-10-17
-
-See the commit [git commit history](https://github.com/takari/maven-wrapper/commits/master).
-
-## Version 0.1.5 and earlier
-
-See the commit [git commit history](https://github.com/takari/maven-wrapper/commits/master).
diff --git a/README.md b/README.md
deleted file mode 100644
index cd432b9..0000000
--- a/README.md
+++ /dev/null
@@ -1,193 +0,0 @@
-# Maven Wrapper
-
-The Maven Wrapper is an easy way to ensure a user of your Maven build has
-everything necessary to run your Maven build.
-
-_Why might this be necessary?_ Maven to date has been very stable for users, is
-available on most systems or is easy to procure: but with many of the recent
-changes in Maven it will be easier for users to have a fully encapsulated build
-setup provided by the project. With the Maven Wrapper this is very easy to do
-and it's a great idea borrowed from Gradle.
-
-The easiest way to setup the Maven Wrapper for your project is to use the
-[Takari Maven Plugin][1] with its provided `wrapper` goal. To add or update all
-the necessary Maven Wrapper files to your project execute the following command:
-
-```bash
-mvn -N io.takari:maven:0.7.7:wrapper
-```
-
-> Note: The default usage should be `mvn -N io.takari:maven:wrapper` but for
-> some users this seem to result in usage of an old version of the wrapper and
-> therefore installation of older Maven defaults and so on.
-
-Normally you instruct users to install a specific version of Apache Maven, put
-it on the PATH and then run the `mvn` command like the following:
-
-```bash
-mvn clean install
-```
-
-But now, with a Maven Wrapper setup, you can instruct users to run wrapper
-scripts:
-
-```bash
-./mvnw clean install
-```
-
-or on Windows
-
-```bash
-mvnw.cmd clean install
-```
-
-A normal Maven build will be executed with the one important change that if the
-user doesn't have the necessary version of Maven specified in
-`.mvn/wrapper/maven-wrapper.properties` it will be downloaded for the user
-first, installed and then used.
-
-Subsequent uses of `mvn`/`mvnw.cmd` use the previously downloaded, specific
-version as needed.
-
-## Supported Systems
-
-The wrapper should work on various operating systems including
-
-* Linux (numerous versions, tested on Ubuntu and CentOS)
-* OSX / macOS
-* Windows (various newer versions)
-* Solaris (10 and 11)
-
-For all those *nix operating systems, various shells should work including
-
-* sh
-* bash
-* dash
-* zsh
-
-In terms of Apache Maven versions itself, the wrapper should work with any Maven
-3.x version and it defaults to the latest release - currently 3.6.3. We do NOT
-plan to support the deprecated, EOL'ed Maven 2.x.
-
-The maven-wrapper itself is compiled to work with Java 5. The Takari Maven
-Plugin for installation however uses Java 7. Once the wrapper is installed with
-the plugin you should be able to use the wrapper on the project with Java 5 and
-up. This is however not really tested by the committers.
-
-## Changes
-
-Please check out the [changelog](./CHANGELOG.md) for more information about our
-releases.
-
-## Verbose Mode
-
-The wrapper supports a verbose mode in which it outputs further information. It
-is activated by setting the `MVNW_VERBOSE` environment variable to `true`.
-
-By default it is off.
-
-## Usage without Binary JAR
-
-By default, the Maven Wrapper JAR archive is added to the using project as small
-binary file `.mvn/wrapper/maven-wrapper.jar`. It is used to bootstrap the
-download and invocation of Maven from the wrapper shell scripts.
-
-If your project is not allowed to contain binary files like this, you can
-configure your version control system to exclude checkin/commit of the wrapper
-jar.
-
-If the JAR is not found to be available by the scripts they will attempt to
-download the file from the URL specified in
-`.mvn/wrapper/maven-wrapper.properties` under `wrapperUrl` and put it in place.
-The download is attempted via curl, wget and, as last resort, by compiling the
-`./mvn/wrapper/MavenWrapperDownloader.java` file and executing the resulting
-class.
-
-If your Maven repository is password protected you can specify your username via
-the environment variable `MVNW_USERNAME` and the password via the environment
-variable `MVNW_PASSWORD`.
-
-## Using a Different Version of Maven
-
-To switch the version of Maven used to build a project you can initialize it
-using:
-
-```bash
-mvn -N io.takari:maven:0.7.7:wrapper -Dmaven=3.5.4
-```
-
-which works for any version except snapshots. Once you have a wrapper you can
-change its version by setting the `distributionUrl` in
-`.mvn/wrapper/maven-wrapper.properties`, e.g.
-
-```bash
-distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
-```
-
-## Using Basic Authentication for Distribution Download
-
-To download Maven from a location that requires Basic Authentication you have 2
-options:
-
-1. Set the environment variables MVNW_USERNAME and MVNW_PASSWORD
-
- or
-
-2. add user and password to the distributionUrl like that:
-`distributionUrl=https://username:password@<yourserver>/maven2/org/apache/maven/apache-maven/3.2.1/apache-maven-3.2.1-bin.zip`
-
-[1]: https://github.com/takari/takari-maven-plugin
-
-## Specifying Maven Distribution Base Path
-
-This is a feature of Maven itself and the wrapper just happens to take it into
-account. Simply set `MAVEN_USER_HOME` to the desired path and the wrapper uses
-it as the base of the Maven distro installation.
-
-See https://www.lewuathe.com/maven-wrapper-home.html and
-https://github.com/takari/maven-wrapper/issues/17
-
-## Using a Maven Repository Manager
-
-When using an internal Maven repository manager you have two options:
-
-1. Just set the correct URL to wrapper jar and Maven distro in
- `maven-wrapper.properties` in your project
-2. Leave the default URL in the project pointing to Maven Central and set the
- environment variable `MVNW_REPOURL` to your repo manager URL such as
- `https://repo.example.com/central-repo-proxy`.
-
-If `MVNW_REPOURL` is set during the wrapper installation with the
-takari-maven-plugin, the URL is used in the maven-wrapper.properties file.
-
-If not set, but your mirror URL in your settings.xml is configured, it will be
-used.
-
-## Developing and Releasing
-
-To test Maven wrapper usage:
-
-- ensure you are building on a Unix filesystem with correct mounting for
- executable flag setting
-- build the maven-wrapper as snapshot version
-- update version in takari-maven-plugin
-- build takari-maven-plugin
-- use on test project with takari-maven-plugin version
-
-```bash
-mvn -N -X io.takari:maven:0.7.7-SNAPSHOT:wrapper
-```
-
-For release
-
-- make sure version in mvnw files, MavenWrapperDownloader.java and config files
- and pom files is new upcoming release
-- cut maven release with usual release plugin usage
-- update maven plugin to release version
-- release it as well
-
-Updating Maven version:
-
-- update URL in maven-wrapper/.mvn/wrapper/maven-wrapper.properties
-- update URL in MavenWrapperMain
-- updated DEFAULT_MAVEN_VER parameter in takari-maven-plugin WrapperMojo class
diff --git a/mvnw b/mvnw
deleted file mode 100755
index 41c0f0c..0000000
--- a/mvnw
+++ /dev/null
@@ -1,310 +0,0 @@
-#!/bin/sh
-# ----------------------------------------------------------------------------
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-# ----------------------------------------------------------------------------
-
-# ----------------------------------------------------------------------------
-# Maven Start Up Batch script
-#
-# Required ENV vars:
-# ------------------
-# JAVA_HOME - location of a JDK home dir
-#
-# Optional ENV vars
-# -----------------
-# M2_HOME - location of maven2's installed home dir
-# MAVEN_OPTS - parameters passed to the Java VM when running Maven
-# e.g. to debug Maven itself, use
-# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
-# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
-# ----------------------------------------------------------------------------
-
-if [ -z "$MAVEN_SKIP_RC" ] ; then
-
- if [ -f /etc/mavenrc ] ; then
- . /etc/mavenrc
- fi
-
- if [ -f "$HOME/.mavenrc" ] ; then
- . "$HOME/.mavenrc"
- fi
-
-fi
-
-# OS specific support. $var _must_ be set to either true or false.
-cygwin=false;
-darwin=false;
-mingw=false
-case "`uname`" in
- CYGWIN*) cygwin=true ;;
- MINGW*) mingw=true;;
- Darwin*) darwin=true
- # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
- # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
- if [ -z "$JAVA_HOME" ]; then
- if [ -x "/usr/libexec/java_home" ]; then
- export JAVA_HOME="`/usr/libexec/java_home`"
- else
- export JAVA_HOME="/Library/Java/Home"
- fi
- fi
- ;;
-esac
-
-if [ -z "$JAVA_HOME" ] ; then
- if [ -r /etc/gentoo-release ] ; then
- JAVA_HOME=`java-config --jre-home`
- fi
-fi
-
-if [ -z "$M2_HOME" ] ; then
- ## resolve links - $0 may be a link to maven's home
- PRG="$0"
-
- # need this for relative symlinks
- while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG="`dirname "$PRG"`/$link"
- fi
- done
-
- saveddir=`pwd`
-
- M2_HOME=`dirname "$PRG"`/..
-
- # make it fully qualified
- M2_HOME=`cd "$M2_HOME" && pwd`
-
- cd "$saveddir"
- # echo Using m2 at $M2_HOME
-fi
-
-# For Cygwin, ensure paths are in UNIX format before anything is touched
-if $cygwin ; then
- [ -n "$M2_HOME" ] &&
- M2_HOME=`cygpath --unix "$M2_HOME"`
- [ -n "$JAVA_HOME" ] &&
- JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
- [ -n "$CLASSPATH" ] &&
- CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
-fi
-
-# For Mingw, ensure paths are in UNIX format before anything is touched
-if $mingw ; then
- [ -n "$M2_HOME" ] &&
- M2_HOME="`(cd "$M2_HOME"; pwd)`"
- [ -n "$JAVA_HOME" ] &&
- JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
-fi
-
-if [ -z "$JAVA_HOME" ]; then
- javaExecutable="`which javac`"
- if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
- # readlink(1) is not available as standard on Solaris 10.
- readLink=`which readlink`
- if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
- if $darwin ; then
- javaHome="`dirname \"$javaExecutable\"`"
- javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
- else
- javaExecutable="`readlink -f \"$javaExecutable\"`"
- fi
- javaHome="`dirname \"$javaExecutable\"`"
- javaHome=`expr "$javaHome" : '\(.*\)/bin'`
- JAVA_HOME="$javaHome"
- export JAVA_HOME
- fi
- fi
-fi
-
-if [ -z "$JAVACMD" ] ; then
- if [ -n "$JAVA_HOME" ] ; then
- if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
- # IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
- else
- JAVACMD="$JAVA_HOME/bin/java"
- fi
- else
- JAVACMD="`which java`"
- fi
-fi
-
-if [ ! -x "$JAVACMD" ] ; then
- echo "Error: JAVA_HOME is not defined correctly." >&2
- echo " We cannot execute $JAVACMD" >&2
- exit 1
-fi
-
-if [ -z "$JAVA_HOME" ] ; then
- echo "Warning: JAVA_HOME environment variable is not set."
-fi
-
-CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
-
-# traverses directory structure from process work directory to filesystem root
-# first directory with .mvn subdirectory is considered project base directory
-find_maven_basedir() {
-
- if [ -z "$1" ]
- then
- echo "Path not specified to find_maven_basedir"
- return 1
- fi
-
- basedir="$1"
- wdir="$1"
- while [ "$wdir" != '/' ] ; do
- if [ -d "$wdir"/.mvn ] ; then
- basedir=$wdir
- break
- fi
- # workaround for JBEAP-8937 (on Solaris 10/Sparc)
- if [ -d "${wdir}" ]; then
- wdir=`cd "$wdir/.."; pwd`
- fi
- # end of workaround
- done
- echo "${basedir}"
-}
-
-# concatenates all lines of a file
-concat_lines() {
- if [ -f "$1" ]; then
- echo "$(tr -s '\n' ' ' < "$1")"
- fi
-}
-
-BASE_DIR=`find_maven_basedir "$(pwd)"`
-if [ -z "$BASE_DIR" ]; then
- exit 1;
-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.
-##########################################################################################
-if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Found .mvn/wrapper/maven-wrapper.jar"
- fi
-else
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
- fi
- if [ -n "$MVNW_REPOURL" ]; then
- jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
- else
- jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
- fi
- while IFS="=" read key value; do
- case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
- esac
- done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Downloading from: $jarUrl"
- fi
- wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
- if $cygwin; then
- wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
- fi
-
- if command -v wget > /dev/null; then
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Found wget ... using wget"
- fi
- if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
- wget "$jarUrl" -O "$wrapperJarPath"
- else
- wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
- fi
- elif command -v curl > /dev/null; then
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Found curl ... using curl"
- fi
- if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
- curl -o "$wrapperJarPath" "$jarUrl" -f
- else
- curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
- fi
-
- else
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Falling back to using Java to download"
- fi
- javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
- # For Cygwin, switch paths to Windows format before running javac
- if $cygwin; then
- javaClass=`cygpath --path --windows "$javaClass"`
- fi
- if [ -e "$javaClass" ]; then
- if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
- if [ "$MVNW_VERBOSE" = true ]; then
- echo " - Compiling MavenWrapperDownloader.java ..."
- fi
- # Compiling the Java class
- ("$JAVA_HOME/bin/javac" "$javaClass")
- fi
- if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
- # Running the downloader
- if [ "$MVNW_VERBOSE" = true ]; then
- echo " - Running MavenWrapperDownloader.java ..."
- fi
- ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
- fi
- fi
- fi
-fi
-##########################################################################################
-# End of extension
-##########################################################################################
-
-export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
-if [ "$MVNW_VERBOSE" = true ]; then
- echo $MAVEN_PROJECTBASEDIR
-fi
-MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
-
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin; then
- [ -n "$M2_HOME" ] &&
- M2_HOME=`cygpath --path --windows "$M2_HOME"`
- [ -n "$JAVA_HOME" ] &&
- JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
- [ -n "$CLASSPATH" ] &&
- CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
- [ -n "$MAVEN_PROJECTBASEDIR" ] &&
- MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
-fi
-
-# Provide a "standardized" way to retrieve the CLI args that will
-# work with both Windows and non-Windows executions.
-MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
-export MAVEN_CMD_LINE_ARGS
-
-WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
-
-exec "$JAVACMD" \
- $MAVEN_OPTS \
- -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
- "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
- ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
diff --git a/mvnw.cmd b/mvnw.cmd
deleted file mode 100644
index 8611571..0000000
--- a/mvnw.cmd
+++ /dev/null
@@ -1,182 +0,0 @@
-@REM ----------------------------------------------------------------------------
-@REM Licensed to the Apache Software Foundation (ASF) under one
-@REM or more contributor license agreements. See the NOTICE file
-@REM distributed with this work for additional information
-@REM regarding copyright ownership. The ASF licenses this file
-@REM to you under the Apache License, Version 2.0 (the
-@REM "License"); you may not use this file except in compliance
-@REM with the License. You may obtain a copy of the License at
-@REM
-@REM http://www.apache.org/licenses/LICENSE-2.0
-@REM
-@REM Unless required by applicable law or agreed to in writing,
-@REM software distributed under the License is distributed on an
-@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-@REM KIND, either express or implied. See the License for the
-@REM specific language governing permissions and limitations
-@REM under the License.
-@REM ----------------------------------------------------------------------------
-
-@REM ----------------------------------------------------------------------------
-@REM Maven Start Up Batch script
-@REM
-@REM Required ENV vars:
-@REM JAVA_HOME - location of a JDK home dir
-@REM
-@REM Optional ENV vars
-@REM M2_HOME - location of maven2's installed home dir
-@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
-@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
-@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
-@REM e.g. to debug Maven itself, use
-@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
-@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
-@REM ----------------------------------------------------------------------------
-
-@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
-@echo off
-@REM set title of command window
-title %0
-@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
-@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
-
-@REM set %HOME% to equivalent of $HOME
-if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
-
-@REM Execute a user defined script before this one
-if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
-@REM check for pre script, once with legacy .bat ending and once with .cmd ending
-if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
-if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
-:skipRcPre
-
-@setlocal
-
-set ERROR_CODE=0
-
-@REM To isolate internal variables from possible post scripts, we use another setlocal
-@setlocal
-
-@REM ==== START VALIDATION ====
-if not "%JAVA_HOME%" == "" goto OkJHome
-
-echo.
-echo Error: JAVA_HOME not found in your environment. >&2
-echo Please set the JAVA_HOME variable in your environment to match the >&2
-echo location of your Java installation. >&2
-echo.
-goto error
-
-:OkJHome
-if exist "%JAVA_HOME%\bin\java.exe" goto init
-
-echo.
-echo Error: JAVA_HOME is set to an invalid directory. >&2
-echo JAVA_HOME = "%JAVA_HOME%" >&2
-echo Please set the JAVA_HOME variable in your environment to match the >&2
-echo location of your Java installation. >&2
-echo.
-goto error
-
-@REM ==== END VALIDATION ====
-
-:init
-
-@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
-@REM Fallback to current working directory if not found.
-
-set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
-IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
-
-set EXEC_DIR=%CD%
-set WDIR=%EXEC_DIR%
-:findBaseDir
-IF EXIST "%WDIR%"\.mvn goto baseDirFound
-cd ..
-IF "%WDIR%"=="%CD%" goto baseDirNotFound
-set WDIR=%CD%
-goto findBaseDir
-
-:baseDirFound
-set MAVEN_PROJECTBASEDIR=%WDIR%
-cd "%EXEC_DIR%"
-goto endDetectBaseDir
-
-:baseDirNotFound
-set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
-cd "%EXEC_DIR%"
-
-:endDetectBaseDir
-
-IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
-
-@setlocal EnableExtensions EnableDelayedExpansion
-for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
-@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
-
-:endReadAdditionalConfig
-
-SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
-set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
-set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
-
-set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
-
-FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
- IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
-)
-
-@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
-@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
-if exist %WRAPPER_JAR% (
- if "%MVNW_VERBOSE%" == "true" (
- echo Found %WRAPPER_JAR%
- )
-) else (
- if not "%MVNW_REPOURL%" == "" (
- SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
- )
- if "%MVNW_VERBOSE%" == "true" (
- echo Couldn't find %WRAPPER_JAR%, downloading it ...
- echo Downloading from: %DOWNLOAD_URL%
- )
-
- powershell -Command "&{"^
- "$webclient = new-object System.Net.WebClient;"^
- "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
- "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
- "}"^
- "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
- "}"
- if "%MVNW_VERBOSE%" == "true" (
- echo Finished downloading %WRAPPER_JAR%
- )
-)
-@REM End of extension
-
-@REM Provide a "standardized" way to retrieve the CLI args that will
-@REM work with both Windows and non-Windows executions.
-set MAVEN_CMD_LINE_ARGS=%*
-
-%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
-if ERRORLEVEL 1 goto error
-goto end
-
-:error
-set ERROR_CODE=1
-
-:end
-@endlocal & set ERROR_CODE=%ERROR_CODE%
-
-if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
-@REM check for post script, once with legacy .bat ending and once with .cmd ending
-if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
-if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
-:skipRcPost
-
-@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
-if "%MAVEN_BATCH_PAUSE%" == "on" pause
-
-if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
-
-exit /B %ERROR_CODE%
diff --git a/pom.xml b/pom.xml
index ea78ee8..3bfaa6a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,14 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>io.takari</groupId>
- <artifactId>takari</artifactId>
- <version>27</version>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-parent</artifactId>
+ <version>34</version>
</parent>
-
<artifactId>maven-wrapper</artifactId>
- <version>0.5.7-SNAPSHOT</version>
- <packaging>provisio</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+
<name>Maven Wrapper</name>
<licenses>
<license>
@@ -18,7 +17,7 @@
</license>
</licenses>
<properties>
- <takari.javaSourceVersion>1.5</takari.javaSourceVersion>
+ <javaVersion>8</javaVersion>
</properties>
<dependencies>
<dependency>
@@ -60,16 +59,4 @@
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>io.takari.maven.plugins</groupId>
- <artifactId>provisio-maven-plugin</artifactId>
- <!-- careful - upgrade to 0.1.50 causes problem with extraction of tar.gz
- instead of into .mvn/wrapper it looses the .mvn path and extracts to wrapper -->
- <version>0.1.46</version>
- <extensions>true</extensions>
- </plugin>
- </plugins>
- </build>
</project>
diff --git a/src/main/java/org/apache/maven/wrapper/BootstrapMainStarter.java b/src/main/java/org/apache/maven/wrapper/BootstrapMainStarter.java
index 30dc4f5..e18660a 100644
--- a/src/main/java/org/apache/maven/wrapper/BootstrapMainStarter.java
+++ b/src/main/java/org/apache/maven/wrapper/BootstrapMainStarter.java
@@ -1,19 +1,23 @@
+package org.apache.maven.wrapper;
+
/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper;
import java.io.File;
import java.lang.reflect.Method;
@@ -23,30 +27,34 @@ import java.net.URLClassLoader;
/**
* @author Hans Dockter
*/
-public class BootstrapMainStarter {
- public void start(String[] args, File mavenHome) throws Exception {
- File mavenJar = findLauncherJar(mavenHome);
- URLClassLoader contextClassLoader = new URLClassLoader(new URL[] {
- mavenJar.toURI().toURL()
- }, ClassLoader.getSystemClassLoader().getParent());
- Thread.currentThread().setContextClassLoader(contextClassLoader);
- Class<?> mainClass = contextClassLoader.loadClass("org.codehaus.plexus.classworlds.launcher.Launcher");
+public class BootstrapMainStarter
+{
+ public void start( String[] args, File mavenHome )
+ throws Exception
+ {
+ File mavenJar = findLauncherJar( mavenHome );
+ URLClassLoader contextClassLoader = new URLClassLoader( new URL[] { mavenJar.toURI().toURL() },
+ ClassLoader.getSystemClassLoader().getParent() );
+ Thread.currentThread().setContextClassLoader( contextClassLoader );
+ Class<?> mainClass = contextClassLoader.loadClass( "org.codehaus.plexus.classworlds.launcher.Launcher" );
- System.setProperty("maven.home", mavenHome.getAbsolutePath());
- System.setProperty("classworlds.conf", new File(mavenHome, "/bin/m2.conf").getAbsolutePath());
+ System.setProperty( "maven.home", mavenHome.getAbsolutePath() );
+ System.setProperty( "classworlds.conf", new File( mavenHome, "/bin/m2.conf" ).getAbsolutePath() );
- Method mainMethod = mainClass.getMethod("main", String[].class);
- mainMethod.invoke(null, new Object[] {
- args
- });
- }
+ Method mainMethod = mainClass.getMethod( "main", String[].class );
+ mainMethod.invoke( null, new Object[] { args } );
+ }
- private File findLauncherJar(File mavenHome) {
- for (File file : new File(mavenHome, "boot").listFiles()) {
- if (file.getName().matches("plexus-classworlds-.*\\.jar")) {
- return file;
- }
+ private File findLauncherJar( File mavenHome )
+ {
+ for ( File file : new File( mavenHome, "boot" ).listFiles() )
+ {
+ if ( file.getName().matches( "plexus-classworlds-.*\\.jar" ) )
+ {
+ return file;
+ }
+ }
+ throw new RuntimeException( String.format( "Couldn't locate the Maven launcher JAR in Maven distribution '%s'.",
+ mavenHome ) );
}
- throw new RuntimeException(String.format("Could not locate the Maven launcher JAR in Maven distribution '%s'.", mavenHome));
- }
}
diff --git a/src/main/java/org/apache/maven/wrapper/DefaultDownloader.java b/src/main/java/org/apache/maven/wrapper/DefaultDownloader.java
index 1056477..a665d1f 100644
--- a/src/main/java/org/apache/maven/wrapper/DefaultDownloader.java
+++ b/src/main/java/org/apache/maven/wrapper/DefaultDownloader.java
@@ -1,21 +1,24 @@
+package org.apache.maven.wrapper;
+
/*
- * Copyright 2007-present the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper;
-
import static org.apache.maven.wrapper.MavenWrapperMain.MVNW_PASSWORD;
import static org.apache.maven.wrapper.MavenWrapperMain.MVNW_USERNAME;
@@ -35,145 +38,192 @@ import java.net.URLConnection;
/**
* @author Hans Dockter
*/
-public class DefaultDownloader implements Downloader {
- private static final int PROGRESS_CHUNK = 500000;
-
- private static final int BUFFER_SIZE = 10000;
+public class DefaultDownloader
+ implements Downloader
+{
+ private static final int PROGRESS_CHUNK = 500000;
- private final String applicationName;
+ private static final int BUFFER_SIZE = 10000;
- private final String applicationVersion;
+ private final String applicationName;
- public DefaultDownloader(String applicationName, String applicationVersion) {
- this.applicationName = applicationName;
- this.applicationVersion = applicationVersion;
- configureProxyAuthentication();
- configureAuthentication();
- }
+ private final String applicationVersion;
- private void configureProxyAuthentication() {
- if (System.getProperty("http.proxyUser") != null) {
- Authenticator.setDefault(new SystemPropertiesProxyAuthenticator());
+ public DefaultDownloader( String applicationName, String applicationVersion )
+ {
+ this.applicationName = applicationName;
+ this.applicationVersion = applicationVersion;
+ configureProxyAuthentication();
+ configureAuthentication();
}
- }
-
- private void configureAuthentication() {
- if (System.getProperty("MVNW_USERNAME") != null && System.getProperty("MVNW_PASSWORD") != null && System.getProperty("http.proxyUser") == null) {
- Authenticator.setDefault(new Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(System.getProperty("MVNW_USERNAME"), System.getProperty("MVNW_PASSWORD").toCharArray());
- }
- });
+
+ private void configureProxyAuthentication()
+ {
+ if ( System.getProperty( "http.proxyUser" ) != null )
+ {
+ Authenticator.setDefault( new SystemPropertiesProxyAuthenticator() );
+ }
}
- }
- public void download(URI address, File destination) throws Exception {
- if (destination.exists()) {
- return;
+ private void configureAuthentication()
+ {
+ if ( System.getProperty( "MVNW_USERNAME" ) != null && System.getProperty( "MVNW_PASSWORD" ) != null
+ && System.getProperty( "http.proxyUser" ) == null )
+ {
+ Authenticator.setDefault( new Authenticator()
+ {
+ protected PasswordAuthentication getPasswordAuthentication()
+ {
+ return new PasswordAuthentication( System.getProperty( "MVNW_USERNAME" ),
+ System.getProperty( "MVNW_PASSWORD" ).toCharArray() );
+ }
+ } );
+ }
}
- destination.getParentFile().mkdirs();
-
- downloadInternal(address, destination);
- }
-
- private void downloadInternal(URI address, File destination) throws Exception {
- OutputStream out = null;
- URLConnection conn;
- InputStream in = null;
- try {
- URL url = address.toURL();
- out = new BufferedOutputStream(new FileOutputStream(destination));
- conn = url.openConnection();
- addBasicAuthentication(address, conn);
- final String userAgentValue = calculateUserAgent();
- conn.setRequestProperty("User-Agent", userAgentValue);
- in = conn.getInputStream();
- byte[] buffer = new byte[BUFFER_SIZE];
- int numRead;
- long progressCounter = 0;
- while ((numRead = in.read(buffer)) != -1) {
- progressCounter += numRead;
- if (progressCounter / PROGRESS_CHUNK > 0) {
- Logger.info(".");
- progressCounter = progressCounter - PROGRESS_CHUNK;
+
+ public void download( URI address, File destination )
+ throws Exception
+ {
+ if ( destination.exists() )
+ {
+ return;
}
- out.write(buffer, 0, numRead);
- }
- } finally {
- Logger.info("");
- if (in != null) {
- in.close();
- }
- if (out != null) {
- out.close();
- }
+ destination.getParentFile().mkdirs();
+
+ downloadInternal( address, destination );
}
- }
- private void addBasicAuthentication(URI address, URLConnection connection) throws IOException {
- String userInfo = calculateUserInfo(address);
- if (userInfo == null) {
- return;
+ private void downloadInternal( URI address, File destination )
+ throws Exception
+ {
+ OutputStream out = null;
+ URLConnection conn;
+ InputStream in = null;
+ try
+ {
+ URL url = address.toURL();
+ out = new BufferedOutputStream( new FileOutputStream( destination ) );
+ conn = url.openConnection();
+ addBasicAuthentication( address, conn );
+ final String userAgentValue = calculateUserAgent();
+ conn.setRequestProperty( "User-Agent", userAgentValue );
+ in = conn.getInputStream();
+ byte[] buffer = new byte[BUFFER_SIZE];
+ int numRead;
+ long progressCounter = 0;
+ while ( ( numRead = in.read( buffer ) ) != -1 )
+ {
+ progressCounter += numRead;
+ if ( progressCounter / PROGRESS_CHUNK > 0 )
+ {
+ Logger.info( "." );
+ progressCounter = progressCounter - PROGRESS_CHUNK;
+ }
+ out.write( buffer, 0, numRead );
+ }
+ }
+ finally
+ {
+ Logger.info( "" );
+ if ( in != null )
+ {
+ in.close();
+ }
+ if ( out != null )
+ {
+ out.close();
+ }
+ }
}
- if (!"https".equals(address.getScheme())) {
- Logger.warn("WARNING Using HTTP Basic Authentication over an insecure connection to download the Maven distribution. Please consider using HTTPS.");
+
+ private void addBasicAuthentication( URI address, URLConnection connection )
+ throws IOException
+ {
+ String userInfo = calculateUserInfo( address );
+ if ( userInfo == null )
+ {
+ return;
+ }
+ if ( !"https".equals( address.getScheme() ) )
+ {
+ Logger.warn( "WARNING Using HTTP Basic Authentication over an insecure connection"
+ + " to download the Maven distribution. Please consider using HTTPS." );
+ }
+ connection.setRequestProperty( "Authorization", "Basic " + base64Encode( userInfo ) );
}
- connection.setRequestProperty("Authorization", "Basic " + base64Encode(userInfo));
- }
- /**
- * Base64 encode user info for HTTP Basic Authentication.
- *
- * Try to use {@literal java.util.Base64} encoder which is available starting with Java 8.
- * Fallback to {@literal javax.xml.bind.DatatypeConverter} from JAXB which is available starting with Java 6 but is not anymore in Java 9.
- * Fortunately, both of these two Base64 encoders implement the right Base64 flavor, the one that does not split the output in multiple lines.
+ /**
+ * Base64 encode user info for HTTP Basic Authentication. Try to use {@literal java.util.Base64} encoder which is
+ * available starting with Java 8. Fallback to {@literal javax.xml.bind.DatatypeConverter} from JAXB which is
+ * available starting with Java 6 but is not anymore in Java 9. Fortunately, both of these two Base64 encoders
+ * implement the right Base64 flavor, the one that does not split the output in multiple lines.
*
* @param userInfo user info
* @return Base64 encoded user info
* @throws RuntimeException if no public Base64 encoder is available on this JVM
*/
- private String base64Encode(String userInfo) {
- ClassLoader loader = getClass().getClassLoader();
- try {
- Method getEncoderMethod = loader.loadClass("java.util.Base64").getMethod("getEncoder");
- Method encodeMethod = loader.loadClass("java.util.Base64$Encoder").getMethod("encodeToString", byte[].class);
- Object encoder = getEncoderMethod.invoke(null);
- return (String) encodeMethod.invoke(encoder, new Object[]{userInfo.getBytes("UTF-8")});
- } catch (Exception java7OrEarlier) {
- try {
- Method encodeMethod = loader.loadClass("javax.xml.bind.DatatypeConverter").getMethod("printBase64Binary", byte[].class);
- return (String) encodeMethod.invoke(null, new Object[]{userInfo.getBytes("UTF-8")});
- } catch (Exception java5OrEarlier) {
- throw new RuntimeException("Downloading Maven distributions with HTTP Basic Authentication is not supported on your JVM.", java5OrEarlier);
- }
- }
- }
-
- private String calculateUserInfo(URI uri) {
- String username = System.getenv(MVNW_USERNAME);
- String password = System.getenv(MVNW_PASSWORD);
- if (username != null && password != null) {
- return username + ':' + password;
+ private String base64Encode( String userInfo )
+ {
+ ClassLoader loader = getClass().getClassLoader();
+ try
+ {
+ Method getEncoderMethod = loader.loadClass( "java.util.Base64" ).getMethod( "getEncoder" );
+ Method encodeMethod =
+ loader.loadClass( "java.util.Base64$Encoder" ).getMethod( "encodeToString", byte[].class );
+ Object encoder = getEncoderMethod.invoke( null );
+ return (String) encodeMethod.invoke( encoder, new Object[] { userInfo.getBytes( "UTF-8" ) } );
+ }
+ catch ( Exception java7OrEarlier )
+ {
+ try
+ {
+ Method encodeMethod =
+ loader.loadClass( "javax.xml.bind.DatatypeConverter" ).getMethod( "printBase64Binary",
+ byte[].class );
+ return (String) encodeMethod.invoke( null, new Object[] { userInfo.getBytes( "UTF-8" ) } );
+ }
+ catch ( Exception java5OrEarlier )
+ {
+ throw new RuntimeException(
+ "Downloading Maven distributions with HTTP Basic Authentication is not supported on your JVM.",
+ java5OrEarlier );
+ }
+ }
+ }
+
+ private String calculateUserInfo( URI uri )
+ {
+ String username = System.getenv( MVNW_USERNAME );
+ String password = System.getenv( MVNW_PASSWORD );
+ if ( username != null && password != null )
+ {
+ return username + ':' + password;
+ }
+ return uri.getUserInfo();
+ }
+
+ private String calculateUserAgent()
+ {
+ String appVersion = applicationVersion;
+
+ String javaVendor = System.getProperty( "java.vendor" );
+ String javaVersion = System.getProperty( "java.version" );
+ String javaVendorVersion = System.getProperty( "java.vm.version" );
+ String osName = System.getProperty( "os.name" );
+ String osVersion = System.getProperty( "os.version" );
+ String osArch = System.getProperty( "os.arch" );
+ return String.format( "%s/%s (%s;%s;%s) (%s;%s;%s)", applicationName, appVersion, osName, osVersion, osArch,
+ javaVendor, javaVersion, javaVendorVersion );
}
- return uri.getUserInfo();
-}
- private String calculateUserAgent() {
- String appVersion = applicationVersion;
-
- String javaVendor = System.getProperty("java.vendor");
- String javaVersion = System.getProperty("java.version");
- String javaVendorVersion = System.getProperty("java.vm.version");
- String osName = System.getProperty("os.name");
- String osVersion = System.getProperty("os.version");
- String osArch = System.getProperty("os.arch");
- return String.format("%s/%s (%s;%s;%s) (%s;%s;%s)", applicationName, appVersion, osName, osVersion, osArch, javaVendor, javaVersion, javaVendorVersion);
- }
-
- private static class SystemPropertiesProxyAuthenticator extends Authenticator {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(System.getProperty("http.proxyUser"), System.getProperty("http.proxyPassword", "").toCharArray());
+ private static class SystemPropertiesProxyAuthenticator
+ extends Authenticator
+ {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication()
+ {
+ return new PasswordAuthentication( System.getProperty( "http.proxyUser" ),
+ System.getProperty( "http.proxyPassword", "" ).toCharArray() );
+ }
}
- }
}
diff --git a/src/main/java/org/apache/maven/wrapper/Downloader.java b/src/main/java/org/apache/maven/wrapper/Downloader.java
index f25e242..c61931d 100644
--- a/src/main/java/org/apache/maven/wrapper/Downloader.java
+++ b/src/main/java/org/apache/maven/wrapper/Downloader.java
@@ -1,19 +1,23 @@
+package org.apache.maven.wrapper;
+
/*
- * Copyright 2007-present the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper;
import java.io.File;
import java.net.URI;
@@ -21,6 +25,8 @@ import java.net.URI;
/**
* @author Hans Dockter
*/
-public interface Downloader {
- void download(URI address, File destination) throws Exception;
+public interface Downloader
+{
+ void download( URI address, File destination )
+ throws Exception;
}
diff --git a/src/main/java/org/apache/maven/wrapper/Installer.java b/src/main/java/org/apache/maven/wrapper/Installer.java
index 7c1acc3..dab1839 100644
--- a/src/main/java/org/apache/maven/wrapper/Installer.java
+++ b/src/main/java/org/apache/maven/wrapper/Installer.java
@@ -1,19 +1,23 @@
+package org.apache.maven.wrapper;
+
/*
- * Copyright 2007-present the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
@@ -36,164 +40,210 @@ import java.util.zip.ZipFile;
/**
* @author Hans Dockter
*/
-public class Installer {
- public static final String DEFAULT_DISTRIBUTION_PATH = "wrapper/dists";
-
- private final Downloader download;
-
- private final PathAssembler pathAssembler;
-
- public Installer(Downloader download, PathAssembler pathAssembler) {
- this.download = download;
- this.pathAssembler = pathAssembler;
- }
-
- public File createDist(WrapperConfiguration configuration) throws Exception {
- URI distributionUrl;
- String mvnwRepoUrl = System.getenv(MavenWrapperMain.MVNW_REPOURL);
- if (mvnwRepoUrl != null && !mvnwRepoUrl.isEmpty()) {
- distributionUrl = new URI(mvnwRepoUrl + "/" + MavenWrapperMain.MVN_PATH);
- Logger.info("Detected MVNW_REPOURL environment variable " + mvnwRepoUrl);
- } else {
- distributionUrl = configuration.getDistribution();
- }
- Logger.info("Downloading Maven binary from " + distributionUrl);
- boolean alwaysDownload = configuration.isAlwaysDownload();
- boolean alwaysUnpack = configuration.isAlwaysUnpack();
-
- PathAssembler.LocalDistribution localDistribution = pathAssembler.getDistribution(configuration);
-
- File localZipFile = localDistribution.getZipFile();
- boolean downloaded = false;
- if (alwaysDownload || !localZipFile.exists()) {
- File tmpZipFile = new File(localZipFile.getParentFile(), localZipFile.getName() + ".part");
- tmpZipFile.delete();
- Logger.info("Downloading " + distributionUrl);
- download.download(distributionUrl, tmpZipFile);
- tmpZipFile.renameTo(localZipFile);
- downloaded = true;
- }
+public class Installer
+{
+ public static final String DEFAULT_DISTRIBUTION_PATH = "wrapper/dists";
- File distDir = localDistribution.getDistributionDir();
- List<File> dirs = listDirs(distDir);
-
- if (downloaded || alwaysUnpack || dirs.isEmpty()) {
- for (File dir : dirs) {
- Logger.info("Deleting directory " + dir.getAbsolutePath());
- deleteDir(dir);
- }
- Logger.info("Unzipping " + localZipFile.getAbsolutePath() + " to " + distDir.getAbsolutePath());
- unzip(localZipFile, distDir);
- dirs = listDirs(distDir);
- if (dirs.isEmpty()) {
- throw new RuntimeException(String.format("Maven distribution '%s' does not contain any directories. Expected to find exactly 1 directory.", distributionUrl));
- }
- setExecutablePermissions(dirs.get(0));
- }
- if (dirs.size() != 1) {
- throw new RuntimeException(String.format("Maven distribution '%s' contains too many directories. Expected to find exactly 1 directory.", distributionUrl));
+ private final Downloader download;
+
+ private final PathAssembler pathAssembler;
+
+ public Installer( Downloader download, PathAssembler pathAssembler )
+ {
+ this.download = download;
+ this.pathAssembler = pathAssembler;
}
- return dirs.get(0);
- }
-
- private List<File> listDirs(File distDir) {
- List<File> dirs = new ArrayList<File>();
- if (distDir.exists()) {
- for (File file : distDir.listFiles()) {
- if (file.isDirectory()) {
- dirs.add(file);
+
+ public File createDist( WrapperConfiguration configuration )
+ throws Exception
+ {
+ URI distributionUrl;
+ String mvnwRepoUrl = System.getenv( MavenWrapperMain.MVNW_REPOURL );
+ if ( mvnwRepoUrl != null && !mvnwRepoUrl.isEmpty() )
+ {
+ distributionUrl = new URI( mvnwRepoUrl + "/" + MavenWrapperMain.MVN_PATH );
+ Logger.info( "Detected MVNW_REPOURL environment variable " + mvnwRepoUrl );
+ }
+ else
+ {
+ distributionUrl = configuration.getDistribution();
+ }
+ Logger.info( "Downloading Maven binary from " + distributionUrl );
+ boolean alwaysDownload = configuration.isAlwaysDownload();
+ boolean alwaysUnpack = configuration.isAlwaysUnpack();
+
+ PathAssembler.LocalDistribution localDistribution = pathAssembler.getDistribution( configuration );
+
+ File localZipFile = localDistribution.getZipFile();
+ boolean downloaded = false;
+ if ( alwaysDownload || !localZipFile.exists() )
+ {
+ File tmpZipFile = new File( localZipFile.getParentFile(), localZipFile.getName() + ".part" );
+ tmpZipFile.delete();
+ Logger.info( "Downloading " + distributionUrl );
+ download.download( distributionUrl, tmpZipFile );
+ tmpZipFile.renameTo( localZipFile );
+ downloaded = true;
}
- }
- }
- return dirs;
- }
- private void setExecutablePermissions(File mavenHome) {
- if (isWindows()) {
- return;
- }
- File mavenCommand = new File(mavenHome, "bin/mvn");
- String errorMessage = null;
- try {
- ProcessBuilder pb = new ProcessBuilder("chmod", "755", mavenCommand.getCanonicalPath());
- Process p = pb.start();
- if (p.waitFor() == 0) {
- Logger.info("Set executable permissions for: " + mavenCommand.getAbsolutePath());
- } else {
- BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream()));
- Formatter stdout = new Formatter();
- String line;
- while ((line = is.readLine()) != null) {
- stdout.format("%s%n", line);
+ File distDir = localDistribution.getDistributionDir();
+ List<File> dirs = listDirs( distDir );
+
+ if ( downloaded || alwaysUnpack || dirs.isEmpty() )
+ {
+ for ( File dir : dirs )
+ {
+ Logger.info( "Deleting directory " + dir.getAbsolutePath() );
+ deleteDir( dir );
+ }
+ Logger.info( "Unzipping " + localZipFile.getAbsolutePath() + " to " + distDir.getAbsolutePath() );
+ unzip( localZipFile, distDir );
+ dirs = listDirs( distDir );
+ if ( dirs.isEmpty() )
+ {
+ throw new RuntimeException( String.format(
+ "Maven distribution '%s' does not contain any directories. Expected to find exactly 1 directory.",
+ distributionUrl ) );
+ }
+ setExecutablePermissions( dirs.get( 0 ) );
+ }
+ if ( dirs.size() != 1 )
+ {
+ throw new RuntimeException( String.format(
+ "Maven distribution '%s' contains too many directories. Expected to find exactly 1 directory.",
+ distributionUrl ) );
}
- errorMessage = stdout.toString();
- }
- } catch (IOException e) {
- errorMessage = e.getMessage();
- } catch (InterruptedException e) {
- errorMessage = e.getMessage();
+ return dirs.get( 0 );
}
- if (errorMessage != null) {
- Logger.warn("Could not set executable permissions for: " + mavenCommand.getAbsolutePath());
- Logger.warn("Please do this manually if you want to use maven.");
+
+ private List<File> listDirs( File distDir )
+ {
+ List<File> dirs = new ArrayList<File>();
+ if ( distDir.exists() )
+ {
+ for ( File file : distDir.listFiles() )
+ {
+ if ( file.isDirectory() )
+ {
+ dirs.add( file );
+ }
+ }
+ }
+ return dirs;
}
- }
- private boolean isWindows() {
- String osName = System.getProperty("os.name").toLowerCase(Locale.US);
- if (osName.indexOf("windows") > -1) {
- return true;
+ private void setExecutablePermissions( File mavenHome )
+ {
+ if ( isWindows() )
+ {
+ return;
+ }
+ File mavenCommand = new File( mavenHome, "bin/mvn" );
+ String errorMessage = null;
+ try
+ {
+ ProcessBuilder pb = new ProcessBuilder( "chmod", "755", mavenCommand.getCanonicalPath() );
+ Process p = pb.start();
+ if ( p.waitFor() == 0 )
+ {
+ Logger.info( "Set executable permissions for: " + mavenCommand.getAbsolutePath() );
+ }
+ else
+ {
+ BufferedReader is = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
+ Formatter stdout = new Formatter();
+ String line;
+ while ( ( line = is.readLine() ) != null )
+ {
+ stdout.format( "%s%n", line );
+ }
+ errorMessage = stdout.toString();
+ }
+ }
+ catch ( IOException e )
+ {
+ errorMessage = e.getMessage();
+ }
+ catch ( InterruptedException e )
+ {
+ errorMessage = e.getMessage();
+ }
+ if ( errorMessage != null )
+ {
+ Logger.warn( "Could not set executable permissions for: " + mavenCommand.getAbsolutePath() );
+ Logger.warn( "Please do this manually if you want to use maven." );
+ }
}
- return false;
- }
-
- private boolean deleteDir(File dir) {
- if (dir.isDirectory()) {
- String[] children = dir.list();
- for (int i = 0; i < children.length; i++) {
- boolean success = deleteDir(new File(dir, children[i]));
- if (!success) {
- return false;
+
+ private boolean isWindows()
+ {
+ String osName = System.getProperty( "os.name" ).toLowerCase( Locale.US );
+ if ( osName.indexOf( "windows" ) > -1 )
+ {
+ return true;
}
- }
+ return false;
}
- // The directory is now empty so delete it
- return dir.delete();
- }
+ private boolean deleteDir( File dir )
+ {
+ if ( dir.isDirectory() )
+ {
+ String[] children = dir.list();
+ for ( int i = 0; i < children.length; i++ )
+ {
+ boolean success = deleteDir( new File( dir, children[i] ) );
+ if ( !success )
+ {
+ return false;
+ }
+ }
+ }
+
+ // The directory is now empty so delete it
+ return dir.delete();
+ }
- public void unzip(File zip, File dest) throws IOException {
- Enumeration entries;
- ZipFile zipFile;
+ public void unzip( File zip, File dest )
+ throws IOException
+ {
+ Enumeration entries;
+ ZipFile zipFile;
- zipFile = new ZipFile(zip);
+ zipFile = new ZipFile( zip );
- entries = zipFile.entries();
+ entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry entry = (ZipEntry) entries.nextElement();
+ while ( entries.hasMoreElements() )
+ {
+ ZipEntry entry = (ZipEntry) entries.nextElement();
- if (entry.isDirectory()) {
- (new File(dest, entry.getName())).mkdirs();
- continue;
- }
+ if ( entry.isDirectory() )
+ {
+ ( new File( dest, entry.getName() ) ).mkdirs();
+ continue;
+ }
- new File(dest, entry.getName()).getParentFile().mkdirs();
- copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(new File(dest, entry.getName()))));
+ new File( dest, entry.getName() ).getParentFile().mkdirs();
+ copyInputStream( zipFile.getInputStream( entry ),
+ new BufferedOutputStream( new FileOutputStream( new File( dest, entry.getName() ) ) ) );
+ }
+ zipFile.close();
}
- zipFile.close();
- }
- public void copyInputStream(InputStream in, OutputStream out) throws IOException {
- byte[] buffer = new byte[1024];
- int len;
+ public void copyInputStream( InputStream in, OutputStream out )
+ throws IOException
+ {
+ byte[] buffer = new byte[1024];
+ int len;
- while ((len = in.read(buffer)) >= 0) {
- out.write(buffer, 0, len);
- }
+ while ( ( len = in.read( buffer ) ) >= 0 )
+ {
+ out.write( buffer, 0, len );
+ }
- in.close();
- out.close();
- }
+ in.close();
+ out.close();
+ }
}
diff --git a/src/main/java/org/apache/maven/wrapper/Logger.java b/src/main/java/org/apache/maven/wrapper/Logger.java
index 12ebbdc..e02daee 100644
--- a/src/main/java/org/apache/maven/wrapper/Logger.java
+++ b/src/main/java/org/apache/maven/wrapper/Logger.java
@@ -1,33 +1,41 @@
+package org.apache.maven.wrapper;
+
/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper;
/**
* @author <a href="mailto:konstantin.sobolev@gmail.com">Konstantin Sobolev</a>
*/
-public class Logger {
- private static final boolean VERBOSE = "true".equalsIgnoreCase(System.getenv(MavenWrapperMain.MVNW_VERBOSE));
+public class Logger
+{
+ private static final boolean VERBOSE = "true".equalsIgnoreCase( System.getenv( MavenWrapperMain.MVNW_VERBOSE ) );
- public static void info(String msg) {
- if (VERBOSE) {
- System.out.println(msg);
+ public static void info( String msg )
+ {
+ if ( VERBOSE )
+ {
+ System.out.println( msg );
+ }
}
- }
- public static void warn(String msg) {
- System.out.println(msg);
- }
+ public static void warn( String msg )
+ {
+ System.out.println( msg );
+ }
}
diff --git a/src/main/java/org/apache/maven/wrapper/MavenWrapperMain.java b/src/main/java/org/apache/maven/wrapper/MavenWrapperMain.java
index 84ebb43..13f5daf 100644
--- a/src/main/java/org/apache/maven/wrapper/MavenWrapperMain.java
+++ b/src/main/java/org/apache/maven/wrapper/MavenWrapperMain.java
@@ -1,19 +1,23 @@
+package org.apache.maven.wrapper;
+
/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper;
import java.io.File;
import java.io.InputStream;
@@ -28,103 +32,142 @@ import org.apache.maven.wrapper.cli.SystemPropertiesCommandLineConverter;
/**
* @author Hans Dockter
*/
-public class MavenWrapperMain {
- public static final String DEFAULT_MAVEN_USER_HOME = System.getProperty("user.home") + "/.m2";
-
- public static final String MAVEN_USER_HOME_PROPERTY_KEY = "maven.user.home";
-
- public static final String MAVEN_USER_HOME_ENV_KEY = "MAVEN_USER_HOME";
-
- public static final String MVNW_VERBOSE = "MVNW_VERBOSE";
- public static final String MVNW_USERNAME = "MVNW_USERNAME";
- public static final String MVNW_PASSWORD = "MVNW_PASSWORD";
- public static final String MVNW_REPOURL = "MVNW_REPOURL";
-
- public static final String MVN_VERSION = "3.6.3";
- public static final String MVN_PATH =
- "org/apache/maven/apache-maven/" + MVN_VERSION + "/apache-maven-"+ MVN_VERSION + "-bin.zip";
-
- public static void main(String[] args) throws Exception {
- File wrapperJar = wrapperJar();
- File propertiesFile = wrapperProperties(wrapperJar);
- File rootDir = rootDir(wrapperJar);
-
- String wrapperVersion = wrapperVersion();
- Logger.info("Takari Maven Wrapper " + wrapperVersion);
-
- Properties systemProperties = System.getProperties();
- systemProperties.putAll(parseSystemPropertiesFromArgs(args));
-
- addSystemProperties(rootDir);
-
- WrapperExecutor wrapperExecutor = WrapperExecutor.forWrapperPropertiesFile(propertiesFile, System.out);
- wrapperExecutor.execute(args, new Installer(new DefaultDownloader("mvnw", wrapperVersion), new PathAssembler(mavenUserHome())), new BootstrapMainStarter());
- }
-
- private static Map<String, String> parseSystemPropertiesFromArgs(String[] args) {
- SystemPropertiesCommandLineConverter converter = new SystemPropertiesCommandLineConverter();
- CommandLineParser commandLineParser = new CommandLineParser();
- converter.configure(commandLineParser);
- commandLineParser.allowUnknownOptions();
- return converter.convert(commandLineParser.parse(args));
- }
-
- private static void addSystemProperties(File rootDir) {
- System.getProperties().putAll(SystemPropertiesHandler.getSystemProperties(new File(mavenUserHome(), "maven.properties")));
- System.getProperties().putAll(SystemPropertiesHandler.getSystemProperties(new File(rootDir, "maven.properties")));
- }
-
- private static File rootDir(File wrapperJar) {
- return wrapperJar.getParentFile().getParentFile().getParentFile();
- }
-
- private static File wrapperProperties(File wrapperJar) {
- return new File(wrapperJar.getParent(), wrapperJar.getName().replaceFirst("\\.jar$", ".properties"));
- }
-
- private static File wrapperJar() {
- URI location;
- try {
- location = MavenWrapperMain.class.getProtectionDomain().getCodeSource().getLocation().toURI();
- } catch (URISyntaxException e) {
- throw new RuntimeException(e);
+public class MavenWrapperMain
+{
+ public static final String DEFAULT_MAVEN_USER_HOME = System.getProperty( "user.home" ) + "/.m2";
+
+ public static final String MAVEN_USER_HOME_PROPERTY_KEY = "maven.user.home";
+
+ public static final String MAVEN_USER_HOME_ENV_KEY = "MAVEN_USER_HOME";
+
+ public static final String MVNW_VERBOSE = "MVNW_VERBOSE";
+
+ public static final String MVNW_USERNAME = "MVNW_USERNAME";
+
+ public static final String MVNW_PASSWORD = "MVNW_PASSWORD";
+
+ public static final String MVNW_REPOURL = "MVNW_REPOURL";
+
+ public static final String MVN_VERSION = "3.6.3";
+
+ public static final String MVN_PATH =
+ "org/apache/maven/apache-maven/" + MVN_VERSION + "/apache-maven-" + MVN_VERSION + "-bin.zip";
+
+ public static void main( String[] args )
+ throws Exception
+ {
+ File wrapperJar = wrapperJar();
+ File propertiesFile = wrapperProperties( wrapperJar );
+ File rootDir = rootDir( wrapperJar );
+
+ String wrapperVersion = wrapperVersion();
+ Logger.info( "Takari Maven Wrapper " + wrapperVersion );
+
+ Properties systemProperties = System.getProperties();
+ systemProperties.putAll( parseSystemPropertiesFromArgs( args ) );
+
+ addSystemProperties( rootDir );
+
+ WrapperExecutor wrapperExecutor = WrapperExecutor.forWrapperPropertiesFile( propertiesFile, System.out );
+ wrapperExecutor.execute( args, new Installer( new DefaultDownloader( "mvnw", wrapperVersion ),
+ new PathAssembler( mavenUserHome() ) ),
+ new BootstrapMainStarter() );
}
- if (!location.getScheme().equals("file")) {
- throw new RuntimeException(String.format("Cannot determine classpath for wrapper Jar from codebase '%s'.", location));
+
+ private static Map<String, String> parseSystemPropertiesFromArgs( String[] args )
+ {
+ SystemPropertiesCommandLineConverter converter = new SystemPropertiesCommandLineConverter();
+ CommandLineParser commandLineParser = new CommandLineParser();
+ converter.configure( commandLineParser );
+ commandLineParser.allowUnknownOptions();
+ return converter.convert( commandLineParser.parse( args ) );
}
- return new File(location.getPath());
- }
-
- static String wrapperVersion() {
- try {
- InputStream resourceAsStream = MavenWrapperMain.class.getResourceAsStream("/META-INF/maven/io.takari/maven-wrapper/pom.properties");
- if (resourceAsStream == null) {
- throw new RuntimeException("No maven properties found.");
- }
- Properties mavenProperties = new Properties();
- try {
- mavenProperties.load(resourceAsStream);
- String version = mavenProperties.getProperty("version");
- if (version == null) {
- throw new RuntimeException("No version number specified in build receipt resource.");
+
+ private static void addSystemProperties( File rootDir )
+ {
+ System.getProperties().putAll( SystemPropertiesHandler.getSystemProperties( new File( mavenUserHome(),
+ "maven.properties" ) ) );
+ System.getProperties().putAll( SystemPropertiesHandler.getSystemProperties( new File( rootDir,
+ "maven.properties" ) ) );
+ }
+
+ private static File rootDir( File wrapperJar )
+ {
+ return wrapperJar.getParentFile().getParentFile().getParentFile();
+ }
+
+ private static File wrapperProperties( File wrapperJar )
+ {
+ return new File( wrapperJar.getParent(), wrapperJar.getName().replaceFirst( "\\.jar$", ".properties" ) );
+ }
+
+ private static File wrapperJar()
+ {
+ URI location;
+ try
+ {
+ location = MavenWrapperMain.class.getProtectionDomain().getCodeSource().getLocation().toURI();
+ }
+ catch ( URISyntaxException e )
+ {
+ throw new RuntimeException( e );
+ }
+ if ( !location.getScheme().equals( "file" ) )
+ {
+ throw new RuntimeException( String.format( "Cannot determine classpath for wrapper Jar from codebase '%s'.",
+ location ) );
}
- return version;
- } finally {
- resourceAsStream.close();
- }
- } catch (Exception e) {
- throw new RuntimeException("Could not determine wrapper version.", e);
+ return new File( location.getPath() );
}
- }
-
- private static File mavenUserHome() {
- String mavenUserHome = System.getProperty(MAVEN_USER_HOME_PROPERTY_KEY);
- if (mavenUserHome != null) {
- return new File(mavenUserHome);
- } else if ((mavenUserHome = System.getenv(MAVEN_USER_HOME_ENV_KEY)) != null) {
- return new File(mavenUserHome);
- } else {
- return new File(DEFAULT_MAVEN_USER_HOME);
+
+ static String wrapperVersion()
+ {
+ try
+ {
+ InputStream resourceAsStream =
+ MavenWrapperMain.class.getResourceAsStream( "/META-INF/maven/io.takari/maven-wrapper/pom.properties" );
+ if ( resourceAsStream == null )
+ {
+ throw new RuntimeException( "No maven properties found." );
+ }
+ Properties mavenProperties = new Properties();
+ try
+ {
+ mavenProperties.load( resourceAsStream );
+ String version = mavenProperties.getProperty( "version" );
+ if ( version == null )
+ {
+ throw new RuntimeException( "No version number specified in build receipt resource." );
+ }
+ return version;
+ }
+ finally
+ {
+ resourceAsStream.close();
+ }
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Could not determine wrapper version.", e );
+ }
+ }
+
+ private static File mavenUserHome()
+ {
+ String mavenUserHome = System.getProperty( MAVEN_USER_HOME_PROPERTY_KEY );
+ if ( mavenUserHome != null )
+ {
+ return new File( mavenUserHome );
+ }
+
+ mavenUserHome = System.getenv( MAVEN_USER_HOME_ENV_KEY );
+ if ( mavenUserHome != null )
+ {
+ return new File( mavenUserHome );
+ }
+ else
+ {
+ return new File( DEFAULT_MAVEN_USER_HOME );
+ }
}
- }
}
diff --git a/src/main/java/org/apache/maven/wrapper/PathAssembler.java b/src/main/java/org/apache/maven/wrapper/PathAssembler.java
index 4f862bd..bb2111e 100644
--- a/src/main/java/org/apache/maven/wrapper/PathAssembler.java
+++ b/src/main/java/org/apache/maven/wrapper/PathAssembler.java
@@ -1,19 +1,23 @@
+package org.apache.maven.wrapper;
+
/*
- * Copyright 2007-present the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper;
import java.io.File;
import java.math.BigInteger;
@@ -23,97 +27,125 @@ import java.security.MessageDigest;
/**
* @author Hans Dockter
*/
-public class PathAssembler {
- public static final String MAVEN_USER_HOME_STRING = "MAVEN_USER_HOME";
-
- public static final String PROJECT_STRING = "PROJECT";
-
- private File mavenUserHome;
-
- public PathAssembler() {
- }
-
- public PathAssembler(File mavenUserHome) {
- this.mavenUserHome = mavenUserHome;
- }
-
- /**
- * Determines the local locations for the distribution to use given the supplied configuration.
- */
- public LocalDistribution getDistribution(WrapperConfiguration configuration) {
- String baseName = getDistName(configuration.getDistribution());
- String distName = removeExtension(baseName);
- String rootDirName = rootDirName(distName, configuration);
- File distDir = new File(getBaseDir(configuration.getDistributionBase()), configuration.getDistributionPath() + "/" + rootDirName);
- File distZip = new File(getBaseDir(configuration.getZipBase()), configuration.getZipPath() + "/" + rootDirName + "/" + baseName);
- return new LocalDistribution(distDir, distZip);
- }
-
- private String rootDirName(String distName, WrapperConfiguration configuration) {
- String urlHash = getMd5Hash(configuration.getDistribution().toString());
- return String.format("%s/%s", distName, urlHash);
- }
-
- private String getMd5Hash(String string) {
- try {
- MessageDigest messageDigest = MessageDigest.getInstance("MD5");
- byte[] bytes = string.getBytes();
- messageDigest.update(bytes);
- return new BigInteger(1, messageDigest.digest()).toString(32);
- } catch (Exception e) {
- throw new RuntimeException("Could not hash input string.", e);
+public class PathAssembler
+{
+ public static final String MAVEN_USER_HOME_STRING = "MAVEN_USER_HOME";
+
+ public static final String PROJECT_STRING = "PROJECT";
+
+ private File mavenUserHome;
+
+ public PathAssembler()
+ {
}
- }
- private String removeExtension(String name) {
- int p = name.lastIndexOf(".");
- if (p < 0) {
- return name;
+ public PathAssembler( File mavenUserHome )
+ {
+ this.mavenUserHome = mavenUserHome;
}
- return name.substring(0, p);
- }
-
- private String getDistName(URI distUrl) {
- String path = distUrl.getPath();
- int p = path.lastIndexOf("/");
- if (p < 0) {
- return path;
+
+ /**
+ * Determines the local locations for the distribution to use given the supplied configuration.
+ */
+ public LocalDistribution getDistribution( WrapperConfiguration configuration )
+ {
+ String baseName = getDistName( configuration.getDistribution() );
+ String distName = removeExtension( baseName );
+ String rootDirName = rootDirName( distName, configuration );
+ File distDir = new File( getBaseDir( configuration.getDistributionBase() ),
+ configuration.getDistributionPath() + "/" + rootDirName );
+ File distZip = new File( getBaseDir( configuration.getZipBase() ),
+ configuration.getZipPath() + "/" + rootDirName + "/" + baseName );
+ return new LocalDistribution( distDir, distZip );
}
- return path.substring(p + 1);
- }
-
- private File getBaseDir(String base) {
- if (base.equals(MAVEN_USER_HOME_STRING)) {
- return mavenUserHome;
- } else if (base.equals(PROJECT_STRING)) {
- return new File(System.getProperty("user.dir"));
- } else {
- throw new RuntimeException("Base: " + base + " is unknown");
+
+ private String rootDirName( String distName, WrapperConfiguration configuration )
+ {
+ String urlHash = getMd5Hash( configuration.getDistribution().toString() );
+ return String.format( "%s/%s", distName, urlHash );
}
- }
- public class LocalDistribution {
- private final File distZip;
+ private String getMd5Hash( String string )
+ {
+ try
+ {
+ MessageDigest messageDigest = MessageDigest.getInstance( "MD5" );
+ byte[] bytes = string.getBytes();
+ messageDigest.update( bytes );
+ return new BigInteger( 1, messageDigest.digest() ).toString( 32 );
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Could not hash input string.", e );
+ }
+ }
- private final File distDir;
+ private String removeExtension( String name )
+ {
+ int p = name.lastIndexOf( "." );
+ if ( p < 0 )
+ {
+ return name;
+ }
+ return name.substring( 0, p );
+ }
- public LocalDistribution(File distDir, File distZip) {
- this.distDir = distDir;
- this.distZip = distZip;
+ private String getDistName( URI distUrl )
+ {
+ String path = distUrl.getPath();
+ int p = path.lastIndexOf( "/" );
+ if ( p < 0 )
+ {
+ return path;
+ }
+ return path.substring( p + 1 );
}
- /**
- * Returns the location to install the distribution into.
- */
- public File getDistributionDir() {
- return distDir;
+ private File getBaseDir( String base )
+ {
+ if ( base.equals( MAVEN_USER_HOME_STRING ) )
+ {
+ return mavenUserHome;
+ }
+ else if ( base.equals( PROJECT_STRING ) )
+ {
+ return new File( System.getProperty( "user.dir" ) );
+ }
+ else
+ {
+ throw new RuntimeException( "Base: " + base + " is unknown" );
+ }
}
/**
- * Returns the location to install the distribution ZIP file to.
+ * The Local Distribution
*/
- public File getZipFile() {
- return distZip;
+ public class LocalDistribution
+ {
+ private final File distZip;
+
+ private final File distDir;
+
+ public LocalDistribution( File distDir, File distZip )
+ {
+ this.distDir = distDir;
+ this.distZip = distZip;
+ }
+
+ /**
+ * Returns the location to install the distribution into.
+ */
+ public File getDistributionDir()
+ {
+ return distDir;
+ }
+
+ /**
+ * Returns the location to install the distribution ZIP file to.
+ */
+ public File getZipFile()
+ {
+ return distZip;
+ }
}
- }
}
diff --git a/src/main/java/org/apache/maven/wrapper/SystemPropertiesHandler.java b/src/main/java/org/apache/maven/wrapper/SystemPropertiesHandler.java
index 8638a8a..abdc546 100644
--- a/src/main/java/org/apache/maven/wrapper/SystemPropertiesHandler.java
+++ b/src/main/java/org/apache/maven/wrapper/SystemPropertiesHandler.java
@@ -1,19 +1,23 @@
+package org.apache.maven.wrapper;
+
/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper;
import java.io.File;
import java.io.FileInputStream;
@@ -27,35 +31,47 @@ import java.util.regex.Pattern;
/**
* @author Hans Dockter
*/
-public class SystemPropertiesHandler {
+public class SystemPropertiesHandler
+{
- public static Map<String, String> getSystemProperties(File propertiesFile) {
- Map<String, String> propertyMap = new HashMap<String, String>();
- if (!propertiesFile.isFile()) {
- return propertyMap;
- }
- Properties properties = new Properties();
- try {
- FileInputStream inStream = new FileInputStream(propertiesFile);
- try {
- properties.load(inStream);
- } finally {
- inStream.close();
- }
- } catch (IOException e) {
- throw new RuntimeException("Error when loading properties file=" + propertiesFile, e);
- }
+ public static Map<String, String> getSystemProperties( File propertiesFile )
+ {
+ Map<String, String> propertyMap = new HashMap<String, String>();
+ if ( !propertiesFile.isFile() )
+ {
+ return propertyMap;
+ }
+ Properties properties = new Properties();
+ try
+ {
+ FileInputStream inStream = new FileInputStream( propertiesFile );
+ try
+ {
+ properties.load( inStream );
+ }
+ finally
+ {
+ inStream.close();
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( "Error when loading properties file=" + propertiesFile, e );
+ }
- Pattern pattern = Pattern.compile("systemProp\\.(.*)");
- for (Object argument : properties.keySet()) {
- Matcher matcher = pattern.matcher(argument.toString());
- if (matcher.find()) {
- String key = matcher.group(1);
- if (key.length() > 0) {
- propertyMap.put(key, properties.get(argument).toString());
+ Pattern pattern = Pattern.compile( "systemProp\\.(.*)" );
+ for ( Object argument : properties.keySet() )
+ {
+ Matcher matcher = pattern.matcher( argument.toString() );
+ if ( matcher.find() )
+ {
+ String key = matcher.group( 1 );
+ if ( key.length() > 0 )
+ {
+ propertyMap.put( key, properties.get( argument ).toString() );
+ }
+ }
}
- }
+ return propertyMap;
}
- return propertyMap;
- }
}
diff --git a/src/main/java/org/apache/maven/wrapper/WrapperConfiguration.java b/src/main/java/org/apache/maven/wrapper/WrapperConfiguration.java
index 8d76c91..54a49c0 100644
--- a/src/main/java/org/apache/maven/wrapper/WrapperConfiguration.java
+++ b/src/main/java/org/apache/maven/wrapper/WrapperConfiguration.java
@@ -1,94 +1,116 @@
+package org.apache.maven.wrapper;
+
/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper;
import java.net.URI;
-public class WrapperConfiguration {
- public static final String ALWAYS_UNPACK_ENV = "MAVEN_WRAPPER_ALWAYS_UNPACK";
+/**
+ * The Wrapper Configuration
+ */
+public class WrapperConfiguration
+{
+ public static final String ALWAYS_UNPACK_ENV = "MAVEN_WRAPPER_ALWAYS_UNPACK";
- public static final String ALWAYS_DOWNLOAD_ENV = "MAVEN_WRAPPER_ALWAYS_DOWNLOAD";
+ public static final String ALWAYS_DOWNLOAD_ENV = "MAVEN_WRAPPER_ALWAYS_DOWNLOAD";
- private boolean alwaysUnpack = Boolean.parseBoolean(System.getenv(ALWAYS_UNPACK_ENV));
+ private boolean alwaysUnpack = Boolean.parseBoolean( System.getenv( ALWAYS_UNPACK_ENV ) );
- private boolean alwaysDownload = Boolean.parseBoolean(System.getenv(ALWAYS_DOWNLOAD_ENV));
+ private boolean alwaysDownload = Boolean.parseBoolean( System.getenv( ALWAYS_DOWNLOAD_ENV ) );
- private URI distribution;
+ private URI distribution;
- private String distributionBase = PathAssembler.MAVEN_USER_HOME_STRING;
+ private String distributionBase = PathAssembler.MAVEN_USER_HOME_STRING;
- private String distributionPath = Installer.DEFAULT_DISTRIBUTION_PATH;
+ private String distributionPath = Installer.DEFAULT_DISTRIBUTION_PATH;
- private String zipBase = PathAssembler.MAVEN_USER_HOME_STRING;
+ private String zipBase = PathAssembler.MAVEN_USER_HOME_STRING;
- private String zipPath = Installer.DEFAULT_DISTRIBUTION_PATH;
+ private String zipPath = Installer.DEFAULT_DISTRIBUTION_PATH;
- public boolean isAlwaysDownload() {
- return alwaysDownload;
- }
+ public boolean isAlwaysDownload()
+ {
+ return alwaysDownload;
+ }
- public void setAlwaysDownload(boolean alwaysDownload) {
- this.alwaysDownload = alwaysDownload;
- }
+ public void setAlwaysDownload( boolean alwaysDownload )
+ {
+ this.alwaysDownload = alwaysDownload;
+ }
- public boolean isAlwaysUnpack() {
- return alwaysUnpack;
- }
+ public boolean isAlwaysUnpack()
+ {
+ return alwaysUnpack;
+ }
- public void setAlwaysUnpack(boolean alwaysUnpack) {
- this.alwaysUnpack = alwaysUnpack;
- }
+ public void setAlwaysUnpack( boolean alwaysUnpack )
+ {
+ this.alwaysUnpack = alwaysUnpack;
+ }
- public URI getDistribution() {
- return distribution;
- }
+ public URI getDistribution()
+ {
+ return distribution;
+ }
- public void setDistribution(URI distribution) {
- this.distribution = distribution;
- }
+ public void setDistribution( URI distribution )
+ {
+ this.distribution = distribution;
+ }
- public String getDistributionBase() {
- return distributionBase;
- }
+ public String getDistributionBase()
+ {
+ return distributionBase;
+ }
- public void setDistributionBase(String distributionBase) {
- this.distributionBase = distributionBase;
- }
+ public void setDistributionBase( String distributionBase )
+ {
+ this.distributionBase = distributionBase;
+ }
- public String getDistributionPath() {
- return distributionPath;
- }
+ public String getDistributionPath()
+ {
+ return distributionPath;
+ }
- public void setDistributionPath(String distributionPath) {
- this.distributionPath = distributionPath;
- }
+ public void setDistributionPath( String distributionPath )
+ {
+ this.distributionPath = distributionPath;
+ }
- public String getZipBase() {
- return zipBase;
- }
+ public String getZipBase()
+ {
+ return zipBase;
+ }
- public void setZipBase(String zipBase) {
- this.zipBase = zipBase;
- }
+ public void setZipBase( String zipBase )
+ {
+ this.zipBase = zipBase;
+ }
- public String getZipPath() {
- return zipPath;
- }
+ public String getZipPath()
+ {
+ return zipPath;
+ }
- public void setZipPath(String zipPath) {
- this.zipPath = zipPath;
- }
+ public void setZipPath( String zipPath )
+ {
+ this.zipPath = zipPath;
+ }
}
diff --git a/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java b/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java
index 31de402..8484e57 100644
--- a/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java
+++ b/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java
@@ -1,19 +1,23 @@
+package org.apache.maven.wrapper;
+
/*
- * Copyright 2007-present the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper;
import java.io.File;
import java.io.FileInputStream;
@@ -26,118 +30,154 @@ import java.util.Properties;
/**
* @author Hans Dockter
*/
-public class WrapperExecutor {
- public static final String DISTRIBUTION_URL_PROPERTY = "distributionUrl";
+public class WrapperExecutor
+{
+ public static final String DISTRIBUTION_URL_PROPERTY = "distributionUrl";
- public static final String DISTRIBUTION_BASE_PROPERTY = "distributionBase";
+ public static final String DISTRIBUTION_BASE_PROPERTY = "distributionBase";
- public static final String ZIP_STORE_BASE_PROPERTY = "zipStoreBase";
+ public static final String ZIP_STORE_BASE_PROPERTY = "zipStoreBase";
- public static final String DISTRIBUTION_PATH_PROPERTY = "distributionPath";
+ public static final String DISTRIBUTION_PATH_PROPERTY = "distributionPath";
- public static final String ZIP_STORE_PATH_PROPERTY = "zipStorePath";
+ public static final String ZIP_STORE_PATH_PROPERTY = "zipStorePath";
- private final Properties properties;
+ private final Properties properties;
- private final File propertiesFile;
+ private final File propertiesFile;
- private final Appendable warningOutput;
+ private final Appendable warningOutput;
- private final WrapperConfiguration config = new WrapperConfiguration();
+ private final WrapperConfiguration config = new WrapperConfiguration();
+
+ public static WrapperExecutor forProjectDirectory( File projectDir, Appendable warningOutput )
+ {
+ return new WrapperExecutor( new File( projectDir, "maven/wrapper/maven-wrapper.properties" ), new Properties(),
+ warningOutput );
+ }
+
+ public static WrapperExecutor forWrapperPropertiesFile( File propertiesFile, Appendable warningOutput )
+ {
+ if ( !propertiesFile.exists() )
+ {
+ throw new RuntimeException( String.format( "Wrapper properties file '%s' does not exist.",
+ propertiesFile ) );
+ }
+ return new WrapperExecutor( propertiesFile, new Properties(), warningOutput );
+ }
- public static WrapperExecutor forProjectDirectory(File projectDir, Appendable warningOutput) {
- return new WrapperExecutor(new File(projectDir, "maven/wrapper/maven-wrapper.properties"), new Properties(), warningOutput);
- }
+ WrapperExecutor( File propertiesFile, Properties properties, Appendable warningOutput )
+ {
+ this.properties = properties;
+ this.propertiesFile = propertiesFile;
+ this.warningOutput = warningOutput;
+ if ( propertiesFile.exists() )
+ {
+ try
+ {
+ loadProperties( propertiesFile, properties );
+ config.setDistribution( prepareDistributionUri() );
+ config.setDistributionBase( getProperty( DISTRIBUTION_BASE_PROPERTY, config.getDistributionBase() ) );
+ config.setDistributionPath( getProperty( DISTRIBUTION_PATH_PROPERTY, config.getDistributionPath() ) );
+ config.setZipBase( getProperty( ZIP_STORE_BASE_PROPERTY, config.getZipBase() ) );
+ config.setZipPath( getProperty( ZIP_STORE_PATH_PROPERTY, config.getZipPath() ) );
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( String.format( "Could not load wrapper properties from '%s'.",
+ propertiesFile ),
+ e );
+ }
+ }
+ }
- public static WrapperExecutor forWrapperPropertiesFile(File propertiesFile, Appendable warningOutput) {
- if (!propertiesFile.exists()) {
- throw new RuntimeException(String.format("Wrapper properties file '%s' does not exist.", propertiesFile));
+ private URI prepareDistributionUri()
+ throws URISyntaxException
+ {
+ URI source = readDistroUrl();
+ if ( source.getScheme() == null )
+ {
+ // no scheme means someone passed a relative url. In our context only file relative urls make sense.
+ return new File( propertiesFile.getParentFile(), source.getSchemeSpecificPart() ).toURI();
+ }
+ else
+ {
+ return source;
+ }
}
- return new WrapperExecutor(propertiesFile, new Properties(), warningOutput);
- }
-
- WrapperExecutor(File propertiesFile, Properties properties, Appendable warningOutput) {
- this.properties = properties;
- this.propertiesFile = propertiesFile;
- this.warningOutput = warningOutput;
- if (propertiesFile.exists()) {
- try {
- loadProperties(propertiesFile, properties);
- config.setDistribution(prepareDistributionUri());
- config.setDistributionBase(getProperty(DISTRIBUTION_BASE_PROPERTY, config.getDistributionBase()));
- config.setDistributionPath(getProperty(DISTRIBUTION_PATH_PROPERTY, config.getDistributionPath()));
- config.setZipBase(getProperty(ZIP_STORE_BASE_PROPERTY, config.getZipBase()));
- config.setZipPath(getProperty(ZIP_STORE_PATH_PROPERTY, config.getZipPath()));
- } catch (Exception e) {
- throw new RuntimeException(String.format("Could not load wrapper properties from '%s'.", propertiesFile), e);
- }
+
+ private URI readDistroUrl()
+ throws URISyntaxException
+ {
+ if ( properties.getProperty( DISTRIBUTION_URL_PROPERTY ) != null )
+ {
+ return new URI( getProperty( DISTRIBUTION_URL_PROPERTY ) );
+ }
+
+ reportMissingProperty( DISTRIBUTION_URL_PROPERTY );
+ return null; // previous line will fail
}
- }
-
- private URI prepareDistributionUri() throws URISyntaxException {
- URI source = readDistroUrl();
- if (source.getScheme() == null) {
- // no scheme means someone passed a relative url. In our context only file relative urls make sense.
- return new File(propertiesFile.getParentFile(), source.getSchemeSpecificPart()).toURI();
- } else {
- return source;
+
+ private static void loadProperties( File propertiesFile, Properties properties )
+ throws IOException
+ {
+ InputStream inStream = new FileInputStream( propertiesFile );
+ try
+ {
+ properties.load( inStream );
+ }
+ finally
+ {
+ inStream.close();
+ }
}
- }
- private URI readDistroUrl() throws URISyntaxException {
- if (properties.getProperty(DISTRIBUTION_URL_PROPERTY) != null) {
- return new URI(getProperty(DISTRIBUTION_URL_PROPERTY));
+ /**
+ * Returns the distribution which this wrapper will use. Returns null if no wrapper meta-data was found in the
+ * specified project directory.
+ */
+ public URI getDistribution()
+ {
+ return config.getDistribution();
}
- reportMissingProperty(DISTRIBUTION_URL_PROPERTY);
- return null; // previous line will fail
- }
+ /**
+ * Returns the configuration for this wrapper.
+ */
+ public WrapperConfiguration getConfiguration()
+ {
+ return config;
+ }
- private static void loadProperties(File propertiesFile, Properties properties) throws IOException {
- InputStream inStream = new FileInputStream(propertiesFile);
- try {
- properties.load(inStream);
- } finally {
- inStream.close();
+ public void execute( String[] args, Installer install, BootstrapMainStarter bootstrapMainStarter )
+ throws Exception
+ {
+ File mavenHome = install.createDist( config );
+ bootstrapMainStarter.start( args, mavenHome );
}
- }
-
- /**
- * Returns the distribution which this wrapper will use. Returns null if no wrapper meta-data was found in the
- * specified project directory.
- */
- public URI getDistribution() {
- return config.getDistribution();
- }
-
- /**
- * Returns the configuration for this wrapper.
- */
- public WrapperConfiguration getConfiguration() {
- return config;
- }
-
- public void execute(String[] args, Installer install, BootstrapMainStarter bootstrapMainStarter) throws Exception {
- File mavenHome = install.createDist(config);
- bootstrapMainStarter.start(args, mavenHome);
- }
-
- private String getProperty(String propertyName) {
- return getProperty(propertyName, null);
- }
-
- private String getProperty(String propertyName, String defaultValue) {
- String value = properties.getProperty(propertyName);
- if (value != null) {
- return value;
+
+ private String getProperty( String propertyName )
+ {
+ return getProperty( propertyName, null );
}
- if (defaultValue != null) {
- return defaultValue;
+
+ private String getProperty( String propertyName, String defaultValue )
+ {
+ String value = properties.getProperty( propertyName );
+ if ( value != null )
+ {
+ return value;
+ }
+ if ( defaultValue != null )
+ {
+ return defaultValue;
+ }
+ return reportMissingProperty( propertyName );
}
- return reportMissingProperty(propertyName);
- }
- private String reportMissingProperty(String propertyName) {
- throw new RuntimeException(String.format("No value with key '%s' specified in wrapper properties file '%s'.", propertyName, propertiesFile));
- }
+ private String reportMissingProperty( String propertyName )
+ {
+ throw new RuntimeException( String.format( "No value with key '%s' specified in wrapper properties file '%s'.",
+ propertyName, propertiesFile ) );
+ }
}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/AbstractCommandLineConverter.java b/src/main/java/org/apache/maven/wrapper/cli/AbstractCommandLineConverter.java
index aa8880f..f33c017 100644
--- a/src/main/java/org/apache/maven/wrapper/cli/AbstractCommandLineConverter.java
+++ b/src/main/java/org/apache/maven/wrapper/cli/AbstractCommandLineConverter.java
@@ -1,36 +1,53 @@
+package org.apache.maven.wrapper.cli;
+
/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper.cli;
-public abstract class AbstractCommandLineConverter<T> implements CommandLineConverter<T> {
- public T convert(Iterable<String> args) throws CommandLineArgumentException {
- CommandLineParser parser = new CommandLineParser();
- configure(parser);
- return convert(parser.parse(args));
- }
+/**
+ * The Abstract CommandLine Converter
+ *
+ * @param <T>
+ */
+public abstract class AbstractCommandLineConverter<T>
+ implements CommandLineConverter<T>
+{
+ public T convert( Iterable<String> args )
+ throws CommandLineArgumentException
+ {
+ CommandLineParser parser = new CommandLineParser();
+ configure( parser );
+ return convert( parser.parse( args ) );
+ }
- public T convert(ParsedCommandLine args) throws CommandLineArgumentException {
- return convert(args, newInstance());
- }
+ public T convert( ParsedCommandLine args )
+ throws CommandLineArgumentException
+ {
+ return convert( args, newInstance() );
+ }
- public T convert(Iterable<String> args, T target) throws CommandLineArgumentException {
- CommandLineParser parser = new CommandLineParser();
- configure(parser);
- return convert(parser.parse(args), target);
- }
+ public T convert( Iterable<String> args, T target )
+ throws CommandLineArgumentException
+ {
+ CommandLineParser parser = new CommandLineParser();
+ configure( parser );
+ return convert( parser.parse( args ), target );
+ }
- protected abstract T newInstance();
+ protected abstract T newInstance();
}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/AbstractPropertiesCommandLineConverter.java b/src/main/java/org/apache/maven/wrapper/cli/AbstractPropertiesCommandLineConverter.java
index 3800c0e..455fd27 100644
--- a/src/main/java/org/apache/maven/wrapper/cli/AbstractPropertiesCommandLineConverter.java
+++ b/src/main/java/org/apache/maven/wrapper/cli/AbstractPropertiesCommandLineConverter.java
@@ -1,50 +1,66 @@
+package org.apache.maven.wrapper.cli;
+
/*
- * Copyright 2007-present the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper.cli;
-
import java.util.HashMap;
import java.util.Map;
-public abstract class AbstractPropertiesCommandLineConverter extends AbstractCommandLineConverter<Map<String, String>> {
- protected abstract String getPropertyOption();
+/**
+ * The Abstract Properties CommandLine Converter
+ */
+public abstract class AbstractPropertiesCommandLineConverter
+ extends AbstractCommandLineConverter<Map<String, String>>
+{
+ protected abstract String getPropertyOption();
- protected abstract String getPropertyOptionDetailed();
+ protected abstract String getPropertyOptionDetailed();
- protected abstract String getPropertyOptionDescription();
+ protected abstract String getPropertyOptionDescription();
- public void configure(CommandLineParser parser) {
- CommandLineOption option = parser.option(getPropertyOption(), getPropertyOptionDetailed());
- option = option.hasArguments();
- option.hasDescription(getPropertyOptionDescription());
- }
+ public void configure( CommandLineParser parser )
+ {
+ CommandLineOption option = parser.option( getPropertyOption(), getPropertyOptionDetailed() );
+ option = option.hasArguments();
+ option.hasDescription( getPropertyOptionDescription() );
+ }
- protected Map<String, String> newInstance() {
- return new HashMap<String, String>();
- }
+ protected Map<String, String> newInstance()
+ {
+ return new HashMap<String, String>();
+ }
- public Map<String, String> convert(ParsedCommandLine options, Map<String, String> properties) throws CommandLineArgumentException {
- for (String keyValueExpression : options.option(getPropertyOption()).getValues()) {
- int pos = keyValueExpression.indexOf("=");
- if (pos < 0) {
- properties.put(keyValueExpression, "");
- } else {
- properties.put(keyValueExpression.substring(0, pos), keyValueExpression.substring(pos + 1));
- }
+ public Map<String, String> convert( ParsedCommandLine options, Map<String, String> properties )
+ throws CommandLineArgumentException
+ {
+ for ( String keyValueExpression : options.option( getPropertyOption() ).getValues() )
+ {
+ int pos = keyValueExpression.indexOf( "=" );
+ if ( pos < 0 )
+ {
+ properties.put( keyValueExpression, "" );
+ }
+ else
+ {
+ properties.put( keyValueExpression.substring( 0, pos ), keyValueExpression.substring( pos + 1 ) );
+ }
+ }
+ return properties;
}
- return properties;
- }
}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/CommandLineArgumentException.java b/src/main/java/org/apache/maven/wrapper/cli/CommandLineArgumentException.java
index 31721dc..3363349 100644
--- a/src/main/java/org/apache/maven/wrapper/cli/CommandLineArgumentException.java
+++ b/src/main/java/org/apache/maven/wrapper/cli/CommandLineArgumentException.java
@@ -1,31 +1,39 @@
+package org.apache.maven.wrapper.cli;
+
/*
- * Copyright 2007-present the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper.cli;
/**
* A {@code CommandLineArgumentException} is thrown when command-line arguments cannot be parsed.
*
* @author Hans Dockter
*/
-public class CommandLineArgumentException extends RuntimeException {
- public CommandLineArgumentException(String message) {
- super(message);
- }
+public class CommandLineArgumentException
+ extends RuntimeException
+{
+ public CommandLineArgumentException( String message )
+ {
+ super( message );
+ }
- public CommandLineArgumentException(String message, Throwable cause) {
- super(message, cause);
- }
+ public CommandLineArgumentException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/CommandLineConverter.java b/src/main/java/org/apache/maven/wrapper/cli/CommandLineConverter.java
index bb4e936..fe7fbdf 100644
--- a/src/main/java/org/apache/maven/wrapper/cli/CommandLineConverter.java
+++ b/src/main/java/org/apache/maven/wrapper/cli/CommandLineConverter.java
@@ -1,31 +1,41 @@
+package org.apache.maven.wrapper.cli;
+
/*
- * Copyright 2007-present the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper.cli;
/**
* @author Hans Dockter
+ * @param <T>
*/
-public interface CommandLineConverter<T> {
- T convert(Iterable<String> args) throws CommandLineArgumentException;
+public interface CommandLineConverter<T>
+{
+ T convert( Iterable<String> args )
+ throws CommandLineArgumentException;
- T convert(Iterable<String> args, T target) throws CommandLineArgumentException;
+ T convert( Iterable<String> args, T target )
+ throws CommandLineArgumentException;
- T convert(ParsedCommandLine args) throws CommandLineArgumentException;
+ T convert( ParsedCommandLine args )
+ throws CommandLineArgumentException;
- T convert(ParsedCommandLine args, T target) throws CommandLineArgumentException;
+ T convert( ParsedCommandLine args, T target )
+ throws CommandLineArgumentException;
- void configure(CommandLineParser parser);
+ void configure( CommandLineParser parser );
}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/CommandLineOption.java b/src/main/java/org/apache/maven/wrapper/cli/CommandLineOption.java
index d8fdcb5..0a6dc21 100644
--- a/src/main/java/org/apache/maven/wrapper/cli/CommandLineOption.java
+++ b/src/main/java/org/apache/maven/wrapper/cli/CommandLineOption.java
@@ -1,112 +1,140 @@
+package org.apache.maven.wrapper.cli;
+
/*
- * Copyright 2007-present the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper.cli;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-public class CommandLineOption {
- private final Set<String> options = new HashSet<String>();
+/**
+ * The CommandLine Option
+ *
+ */
+public class CommandLineOption
+{
+ private final Set<String> options = new HashSet<String>();
+
+ private Class<?> argumentType = Void.TYPE;
+
+ private String description;
+
+ private String subcommand;
+
+ private String deprecationWarning;
+
+ private boolean incubating;
+
+ public CommandLineOption( Iterable<String> options )
+ {
+ for ( String option : options )
+ {
+ this.options.add( option );
+ }
+ }
+
+ public Set<String> getOptions()
+ {
+ return options;
+ }
- private Class<?> argumentType = Void.TYPE;
+ public CommandLineOption hasArgument()
+ {
+ argumentType = String.class;
+ return this;
+ }
- private String description;
+ public CommandLineOption hasArguments()
+ {
+ argumentType = List.class;
+ return this;
+ }
- private String subcommand;
+ public String getSubcommand()
+ {
+ return subcommand;
+ }
- private String deprecationWarning;
+ public CommandLineOption mapsToSubcommand( String command )
+ {
+ this.subcommand = command;
+ return this;
+ }
- private boolean incubating;
+ public String getDescription()
+ {
+ StringBuilder result = new StringBuilder();
+ if ( description != null )
+ {
+ result.append( description );
+ }
+ if ( deprecationWarning != null )
+ {
+ if ( result.length() > 0 )
+ {
+ result.append( ' ' );
+ }
+ result.append( "[deprecated - " );
+ result.append( deprecationWarning );
+ result.append( "]" );
+ }
+ if ( incubating )
+ {
+ if ( result.length() > 0 )
+ {
+ result.append( ' ' );
+ }
+ result.append( "[incubating]" );
+ }
+ return result.toString();
+ }
- public CommandLineOption(Iterable<String> options) {
- for (String option : options) {
- this.options.add(option);
+ public CommandLineOption hasDescription( String description )
+ {
+ this.description = description;
+ return this;
}
- }
-
- public Set<String> getOptions() {
- return options;
- }
-
- public CommandLineOption hasArgument() {
- argumentType = String.class;
- return this;
- }
-
- public CommandLineOption hasArguments() {
- argumentType = List.class;
- return this;
- }
-
- public String getSubcommand() {
- return subcommand;
- }
-
- public CommandLineOption mapsToSubcommand(String command) {
- this.subcommand = command;
- return this;
- }
-
- public String getDescription() {
- StringBuilder result = new StringBuilder();
- if (description != null) {
- result.append(description);
+
+ public boolean getAllowsArguments()
+ {
+ return argumentType != Void.TYPE;
}
- if (deprecationWarning != null) {
- if (result.length() > 0) {
- result.append(' ');
- }
- result.append("[deprecated - ");
- result.append(deprecationWarning);
- result.append("]");
+
+ public boolean getAllowsMultipleArguments()
+ {
+ return argumentType == List.class;
+ }
+
+ public CommandLineOption deprecated( String deprecationWarning )
+ {
+ this.deprecationWarning = deprecationWarning;
+ return this;
}
- if (incubating) {
- if (result.length() > 0) {
- result.append(' ');
- }
- result.append("[incubating]");
+
+ public CommandLineOption incubating()
+ {
+ incubating = true;
+ return this;
+ }
+
+ public String getDeprecationWarning()
+ {
+ return deprecationWarning;
}
- return result.toString();
- }
-
- public CommandLineOption hasDescription(String description) {
- this.description = description;
- return this;
- }
-
- public boolean getAllowsArguments() {
- return argumentType != Void.TYPE;
- }
-
- public boolean getAllowsMultipleArguments() {
- return argumentType == List.class;
- }
-
- public CommandLineOption deprecated(String deprecationWarning) {
- this.deprecationWarning = deprecationWarning;
- return this;
- }
-
- public CommandLineOption incubating() {
- incubating = true;
- return this;
- }
-
- public String getDeprecationWarning() {
- return deprecationWarning;
- }
}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/CommandLineParser.java b/src/main/java/org/apache/maven/wrapper/cli/CommandLineParser.java
index ac74701..65ebc75 100644
--- a/src/main/java/org/apache/maven/wrapper/cli/CommandLineParser.java
+++ b/src/main/java/org/apache/maven/wrapper/cli/CommandLineParser.java
@@ -1,19 +1,23 @@
+package org.apache.maven.wrapper.cli;
+
/*
- * Copyright 2007-present the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper.cli;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
@@ -32,6 +36,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+//CHECKSTYLE_OFF: LineLength
/**
* <p>
* A command-line parser which supports a command/sub-command style command-line interface. Supports the following
@@ -55,478 +60,617 @@ import java.util.TreeSet;
* time. Use {@link ParsedCommandLine#getExtraArguments()} to obtain the non-option command-line arguments.</li>
* </ul>
*/
-public class CommandLineParser {
- private Map<String, CommandLineOption> optionsByString = new HashMap<String, CommandLineOption>();
-
- private boolean allowMixedOptions;
-
- private boolean allowUnknownOptions;
-
- private final PrintWriter deprecationPrinter;
-
- public CommandLineParser() {
- this(new OutputStreamWriter(System.out));
- }
-
- public CommandLineParser(Writer deprecationPrinter) {
- this.deprecationPrinter = new PrintWriter(deprecationPrinter);
- }
-
- /**
- * Parses the given command-line.
- *
- * @param commandLine The command-line.
- * @return The parsed command line.
- * @throws org.apache.maven.wrapper.cli.CommandLineArgumentException On parse failure.
- */
- public ParsedCommandLine parse(String... commandLine) throws CommandLineArgumentException {
- return parse(Arrays.asList(commandLine));
- }
-
- /**
- * Parses the given command-line.
- *
- * @param commandLine The command-line.
- * @return The parsed command line.
- * @throws org.apache.maven.wrapper.cli.CommandLineArgumentException On parse failure.
- */
- public ParsedCommandLine parse(Iterable<String> commandLine) throws CommandLineArgumentException {
- ParsedCommandLine parsedCommandLine = new ParsedCommandLine(new HashSet<CommandLineOption>(optionsByString.values()));
- ParserState parseState = new BeforeFirstSubCommand(parsedCommandLine);
- for (String arg : commandLine) {
- if (parseState.maybeStartOption(arg)) {
- if (arg.equals("--")) {
- parseState = new AfterOptions(parsedCommandLine);
- } else if (arg.matches("--[^=]+")) {
- OptionParserState parsedOption = parseState.onStartOption(arg, arg.substring(2));
- parseState = parsedOption.onStartNextArg();
- } else if (arg.matches("--[^=]+=.*")) {
- int endArg = arg.indexOf('=');
- OptionParserState parsedOption = parseState.onStartOption(arg, arg.substring(2, endArg));
- parseState = parsedOption.onArgument(arg.substring(endArg + 1));
- } else if (arg.matches("-[^=]=.*")) {
- OptionParserState parsedOption = parseState.onStartOption(arg, arg.substring(1, 2));
- parseState = parsedOption.onArgument(arg.substring(3));
- } else {
- assert arg.matches("-[^-].*");
- String option = arg.substring(1);
- if (optionsByString.containsKey(option)) {
- OptionParserState parsedOption = parseState.onStartOption(arg, option);
- parseState = parsedOption.onStartNextArg();
- } else {
- String option1 = arg.substring(1, 2);
- OptionParserState parsedOption;
- if (optionsByString.containsKey(option1)) {
- parsedOption = parseState.onStartOption("-" + option1, option1);
- if (parsedOption.getHasArgument()) {
- parseState = parsedOption.onArgument(arg.substring(2));
- } else {
- parseState = parsedOption.onComplete();
- for (int i = 2; i < arg.length(); i++) {
- String optionStr = arg.substring(i, i + 1);
- parsedOption = parseState.onStartOption("-" + optionStr, optionStr);
- parseState = parsedOption.onComplete();
+//CHECKSTYLE_ON: LineLength
+public class CommandLineParser
+{
+ private Map<String, CommandLineOption> optionsByString = new HashMap<String, CommandLineOption>();
+
+ private boolean allowMixedOptions;
+
+ private boolean allowUnknownOptions;
+
+ private final PrintWriter deprecationPrinter;
+
+ public CommandLineParser()
+ {
+ this( new OutputStreamWriter( System.out ) );
+ }
+
+ public CommandLineParser( Writer deprecationPrinter )
+ {
+ this.deprecationPrinter = new PrintWriter( deprecationPrinter );
+ }
+
+ /**
+ * Parses the given command-line.
+ *
+ * @param commandLine The command-line.
+ * @return The parsed command line.
+ * @throws org.apache.maven.wrapper.cli.CommandLineArgumentException On parse failure.
+ */
+ public ParsedCommandLine parse( String... commandLine )
+ throws CommandLineArgumentException
+ {
+ return parse( Arrays.asList( commandLine ) );
+ }
+
+ /**
+ * Parses the given command-line.
+ *
+ * @param commandLine The command-line.
+ * @return The parsed command line.
+ * @throws org.apache.maven.wrapper.cli.CommandLineArgumentException On parse failure.
+ */
+ public ParsedCommandLine parse( Iterable<String> commandLine )
+ throws CommandLineArgumentException
+ {
+ ParsedCommandLine parsedCommandLine =
+ new ParsedCommandLine( new HashSet<CommandLineOption>( optionsByString.values() ) );
+ ParserState parseState = new BeforeFirstSubCommand( parsedCommandLine );
+ for ( String arg : commandLine )
+ {
+ if ( parseState.maybeStartOption( arg ) )
+ {
+ if ( arg.equals( "--" ) )
+ {
+ parseState = new AfterOptions( parsedCommandLine );
+ }
+ else if ( arg.matches( "--[^=]+" ) )
+ {
+ OptionParserState parsedOption = parseState.onStartOption( arg, arg.substring( 2 ) );
+ parseState = parsedOption.onStartNextArg();
+ }
+ else if ( arg.matches( "--[^=]+=.*" ) )
+ {
+ int endArg = arg.indexOf( '=' );
+ OptionParserState parsedOption = parseState.onStartOption( arg, arg.substring( 2, endArg ) );
+ parseState = parsedOption.onArgument( arg.substring( endArg + 1 ) );
+ }
+ else if ( arg.matches( "-[^=]=.*" ) )
+ {
+ OptionParserState parsedOption = parseState.onStartOption( arg, arg.substring( 1, 2 ) );
+ parseState = parsedOption.onArgument( arg.substring( 3 ) );
}
- }
- } else {
- if (allowUnknownOptions) {
- // if we are allowing unknowns, just pass through the whole arg
- parsedOption = parseState.onStartOption(arg, option);
- parseState = parsedOption.onComplete();
- } else {
- // We are going to throw a CommandLineArgumentException below, but want the message
- // to reflect that we didn't recognise the first char (i.e. the option specifier)
- parsedOption = parseState.onStartOption("-" + option1, option1);
- parseState = parsedOption.onComplete();
- }
+ else
+ {
+ assert arg.matches( "-[^-].*" );
+ String option = arg.substring( 1 );
+ if ( optionsByString.containsKey( option ) )
+ {
+ OptionParserState parsedOption = parseState.onStartOption( arg, option );
+ parseState = parsedOption.onStartNextArg();
+ }
+ else
+ {
+ String option1 = arg.substring( 1, 2 );
+ OptionParserState parsedOption;
+ if ( optionsByString.containsKey( option1 ) )
+ {
+ parsedOption = parseState.onStartOption( "-" + option1, option1 );
+ if ( parsedOption.getHasArgument() )
+ {
+ parseState = parsedOption.onArgument( arg.substring( 2 ) );
+ }
+ else
+ {
+ parseState = parsedOption.onComplete();
+ for ( int i = 2; i < arg.length(); i++ )
+ {
+ String optionStr = arg.substring( i, i + 1 );
+ parsedOption = parseState.onStartOption( "-" + optionStr, optionStr );
+ parseState = parsedOption.onComplete();
+ }
+ }
+ }
+ else
+ {
+ if ( allowUnknownOptions )
+ {
+ // if we are allowing unknowns, just pass through the whole arg
+ parsedOption = parseState.onStartOption( arg, option );
+ parseState = parsedOption.onComplete();
+ }
+ else
+ {
+ // We are going to throw a CommandLineArgumentException below, but want the message
+ // to reflect that we didn't recognise the first char (i.e. the option specifier)
+ parsedOption = parseState.onStartOption( "-" + option1, option1 );
+ parseState = parsedOption.onComplete();
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ parseState = parseState.onNonOption( arg );
}
- }
}
- } else {
- parseState = parseState.onNonOption(arg);
- }
- }
- parseState.onCommandLineEnd();
- return parsedCommandLine;
- }
-
- public CommandLineParser allowMixedSubcommandsAndOptions() {
- allowMixedOptions = true;
- return this;
- }
-
- public CommandLineParser allowUnknownOptions() {
- allowUnknownOptions = true;
- return this;
- }
-
- /**
- * Prints a usage message to the given stream.
- *
- * @param out The output stream to write to.
- */
- public void printUsage(Appendable out) {
- Formatter formatter = new Formatter(out);
- Set<CommandLineOption> orderedOptions = new TreeSet<CommandLineOption>(new OptionComparator());
- orderedOptions.addAll(optionsByString.values());
- Map<String, String> lines = new LinkedHashMap<String, String>();
- for (CommandLineOption option : orderedOptions) {
- Set<String> orderedOptionStrings = new TreeSet<String>(new OptionStringComparator());
- orderedOptionStrings.addAll(option.getOptions());
- List<String> prefixedStrings = new ArrayList<String>();
- for (String optionString : orderedOptionStrings) {
- if (optionString.length() == 1) {
- prefixedStrings.add("-" + optionString);
- } else {
- prefixedStrings.add("--" + optionString);
- }
- }
-
- String key = join(prefixedStrings, ", ");
- String value = option.getDescription();
- if (value == null || value.length() == 0) {
- value = "";
- }
-
- lines.put(key, value);
- }
- int max = 0;
- for (String optionStr : lines.keySet()) {
- max = Math.max(max, optionStr.length());
- }
- for (Map.Entry<String, String> entry : lines.entrySet()) {
- if (entry.getValue().length() == 0) {
- formatter.format("%s%n", entry.getKey());
- } else {
- formatter.format("%-" + max + "s %s%n", entry.getKey(), entry.getValue());
- }
- }
- formatter.flush();
- }
+ parseState.onCommandLineEnd();
+ return parsedCommandLine;
+ }
+
+ public CommandLineParser allowMixedSubcommandsAndOptions()
+ {
+ allowMixedOptions = true;
+ return this;
+ }
+
+ public CommandLineParser allowUnknownOptions()
+ {
+ allowUnknownOptions = true;
+ return this;
+ }
+
+ /**
+ * Prints a usage message to the given stream.
+ *
+ * @param out The output stream to write to.
+ */
+ public void printUsage( Appendable out )
+ {
+ Formatter formatter = new Formatter( out );
+ Set<CommandLineOption> orderedOptions = new TreeSet<CommandLineOption>( new OptionComparator() );
+ orderedOptions.addAll( optionsByString.values() );
+ Map<String, String> lines = new LinkedHashMap<String, String>();
+ for ( CommandLineOption option : orderedOptions )
+ {
+ Set<String> orderedOptionStrings = new TreeSet<String>( new OptionStringComparator() );
+ orderedOptionStrings.addAll( option.getOptions() );
+ List<String> prefixedStrings = new ArrayList<String>();
+ for ( String optionString : orderedOptionStrings )
+ {
+ if ( optionString.length() == 1 )
+ {
+ prefixedStrings.add( "-" + optionString );
+ }
+ else
+ {
+ prefixedStrings.add( "--" + optionString );
+ }
+ }
- private static String join(Collection<?> things, String separator) {
- StringBuffer buffer = new StringBuffer();
- boolean first = true;
+ String key = join( prefixedStrings, ", " );
+ String value = option.getDescription();
+ if ( value == null || value.length() == 0 )
+ {
+ value = "";
+ }
- if (separator == null) {
- separator = "";
+ lines.put( key, value );
+ }
+ int max = 0;
+ for ( String optionStr : lines.keySet() )
+ {
+ max = Math.max( max, optionStr.length() );
+ }
+ for ( Map.Entry<String, String> entry : lines.entrySet() )
+ {
+ if ( entry.getValue().length() == 0 )
+ {
+ formatter.format( "%s%n", entry.getKey() );
+ }
+ else
+ {
+ formatter.format( "%-" + max + "s %s%n", entry.getKey(), entry.getValue() );
+ }
+ }
+ formatter.flush();
}
- for (Object thing : things) {
- if (!first) {
- buffer.append(separator);
- }
- buffer.append(thing.toString());
- first = false;
- }
- return buffer.toString();
- }
-
- /**
- * Defines a new option. By default, the option takes no arguments and has no description.
- *
- * @param options The options values.
- * @return The option, which can be further configured.
- */
- public CommandLineOption option(String... options) {
- for (String option : options) {
- if (optionsByString.containsKey(option)) {
- throw new IllegalArgumentException(String.format("Option '%s' is already defined.", option));
- }
- if (option.startsWith("-")) {
- throw new IllegalArgumentException(String.format("Cannot add option '%s' as an option cannot start with '-'.", option));
- }
- }
- CommandLineOption option = new CommandLineOption(Arrays.asList(options));
- for (String optionStr : option.getOptions()) {
- this.optionsByString.put(optionStr, option);
+ private static String join( Collection<?> things, String separator )
+ {
+ StringBuffer buffer = new StringBuffer();
+ boolean first = true;
+
+ if ( separator == null )
+ {
+ separator = "";
+ }
+
+ for ( Object thing : things )
+ {
+ if ( !first )
+ {
+ buffer.append( separator );
+ }
+ buffer.append( thing.toString() );
+ first = false;
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Defines a new option. By default, the option takes no arguments and has no description.
+ *
+ * @param options The options values.
+ * @return The option, which can be further configured.
+ */
+ public CommandLineOption option( String... options )
+ {
+ for ( String option : options )
+ {
+ if ( optionsByString.containsKey( option ) )
+ {
+ throw new IllegalArgumentException( String.format( "Option '%s' is already defined.", option ) );
+ }
+ if ( option.startsWith( "-" ) )
+ {
+ throw new IllegalArgumentException(
+ String.format( "Can't add option '%s' as an option cannot start with '-'.", option ) );
+ }
+ }
+ CommandLineOption option = new CommandLineOption( Arrays.asList( options ) );
+ for ( String optionStr : option.getOptions() )
+ {
+ this.optionsByString.put( optionStr, option );
+ }
+ return option;
}
- return option;
- }
- private static class OptionString {
- private final String arg;
+ private static class OptionString
+ {
+ private final String arg;
- private final String option;
+ private final String option;
- private OptionString(String arg, String option) {
- this.arg = arg;
- this.option = option;
- }
+ private OptionString( String arg, String option )
+ {
+ this.arg = arg;
+ this.option = option;
+ }
- public String getDisplayName() {
- return arg.startsWith("--") ? "--" + option : "-" + option;
- }
+ public String getDisplayName()
+ {
+ return arg.startsWith( "--" ) ? "--" + option : "-" + option;
+ }
- @Override
- public String toString() {
- return getDisplayName();
+ @Override
+ public String toString()
+ {
+ return getDisplayName();
+ }
}
- }
- private static abstract class ParserState {
- public abstract boolean maybeStartOption(String arg);
+ private abstract static class ParserState
+ {
+ public abstract boolean maybeStartOption( String arg );
- boolean isOption(String arg) {
- return arg.matches("-.+");
- }
+ boolean isOption( String arg )
+ {
+ return arg.matches( "-.+" );
+ }
- public abstract OptionParserState onStartOption(String arg, String option);
+ public abstract OptionParserState onStartOption( String arg, String option );
- public abstract ParserState onNonOption(String arg);
+ public abstract ParserState onNonOption( String arg );
- public void onCommandLineEnd() {
+ public void onCommandLineEnd()
+ {
+ }
}
- }
- private abstract class OptionAwareParserState extends ParserState {
- protected final ParsedCommandLine commandLine;
+ private abstract class OptionAwareParserState
+ extends ParserState
+ {
+ protected final ParsedCommandLine commandLine;
- protected OptionAwareParserState(ParsedCommandLine commandLine) {
- this.commandLine = commandLine;
- }
+ protected OptionAwareParserState( ParsedCommandLine commandLine )
+ {
+ this.commandLine = commandLine;
+ }
- @Override
- public boolean maybeStartOption(String arg) {
- return isOption(arg);
- }
+ @Override
+ public boolean maybeStartOption( String arg )
+ {
+ return isOption( arg );
+ }
- @Override
- public ParserState onNonOption(String arg) {
- commandLine.addExtraValue(arg);
- return allowMixedOptions ? new AfterFirstSubCommand(commandLine) : new AfterOptions(commandLine);
+ @Override
+ public ParserState onNonOption( String arg )
+ {
+ commandLine.addExtraValue( arg );
+ return allowMixedOptions ? new AfterFirstSubCommand( commandLine ) : new AfterOptions( commandLine );
+ }
}
- }
- private class BeforeFirstSubCommand extends OptionAwareParserState {
- private BeforeFirstSubCommand(ParsedCommandLine commandLine) {
- super(commandLine);
- }
+ private class BeforeFirstSubCommand
+ extends OptionAwareParserState
+ {
+ private BeforeFirstSubCommand( ParsedCommandLine commandLine )
+ {
+ super( commandLine );
+ }
- @Override
- public OptionParserState onStartOption(String arg, String option) {
- OptionString optionString = new OptionString(arg, option);
- CommandLineOption commandLineOption = optionsByString.get(option);
- if (commandLineOption == null) {
- if (allowUnknownOptions) {
- return new UnknownOptionParserState(arg, commandLine, this);
- } else {
- throw new CommandLineArgumentException(String.format("Unknown command-line option '%s'.", optionString));
- }
- }
- return new KnownOptionParserState(optionString, commandLineOption, commandLine, this);
+ @Override
+ public OptionParserState onStartOption( String arg, String option )
+ {
+ OptionString optionString = new OptionString( arg, option );
+ CommandLineOption commandLineOption = optionsByString.get( option );
+ if ( commandLineOption == null )
+ {
+ if ( allowUnknownOptions )
+ {
+ return new UnknownOptionParserState( arg, commandLine, this );
+ }
+ else
+ {
+ throw new CommandLineArgumentException( String.format( "Unknown command-line option '%s'.",
+ optionString ) );
+ }
+ }
+ return new KnownOptionParserState( optionString, commandLineOption, commandLine, this );
+ }
}
- }
- private class AfterFirstSubCommand extends OptionAwareParserState {
- private AfterFirstSubCommand(ParsedCommandLine commandLine) {
- super(commandLine);
- }
+ private class AfterFirstSubCommand
+ extends OptionAwareParserState
+ {
+ private AfterFirstSubCommand( ParsedCommandLine commandLine )
+ {
+ super( commandLine );
+ }
- @Override
- public OptionParserState onStartOption(String arg, String option) {
- CommandLineOption commandLineOption = optionsByString.get(option);
- if (commandLineOption == null) {
- return new UnknownOptionParserState(arg, commandLine, this);
- }
- return new KnownOptionParserState(new OptionString(arg, option), commandLineOption, commandLine, this);
+ @Override
+ public OptionParserState onStartOption( String arg, String option )
+ {
+ CommandLineOption commandLineOption = optionsByString.get( option );
+ if ( commandLineOption == null )
+ {
+ return new UnknownOptionParserState( arg, commandLine, this );
+ }
+ return new KnownOptionParserState( new OptionString( arg, option ), commandLineOption, commandLine, this );
+ }
}
- }
- private static class AfterOptions extends ParserState {
- private final ParsedCommandLine commandLine;
+ private static class AfterOptions
+ extends ParserState
+ {
+ private final ParsedCommandLine commandLine;
- private AfterOptions(ParsedCommandLine commandLine) {
- this.commandLine = commandLine;
- }
+ private AfterOptions( ParsedCommandLine commandLine )
+ {
+ this.commandLine = commandLine;
+ }
- @Override
- public boolean maybeStartOption(String arg) {
- return false;
- }
+ @Override
+ public boolean maybeStartOption( String arg )
+ {
+ return false;
+ }
- @Override
- public OptionParserState onStartOption(String arg, String option) {
- return new UnknownOptionParserState(arg, commandLine, this);
- }
+ @Override
+ public OptionParserState onStartOption( String arg, String option )
+ {
+ return new UnknownOptionParserState( arg, commandLine, this );
+ }
- @Override
- public ParserState onNonOption(String arg) {
- commandLine.addExtraValue(arg);
- return this;
+ @Override
+ public ParserState onNonOption( String arg )
+ {
+ commandLine.addExtraValue( arg );
+ return this;
+ }
}
- }
- private static class MissingOptionArgState extends ParserState {
- private final OptionParserState option;
+ private static class MissingOptionArgState
+ extends ParserState
+ {
+ private final OptionParserState option;
- private MissingOptionArgState(OptionParserState option) {
- this.option = option;
- }
+ private MissingOptionArgState( OptionParserState option )
+ {
+ this.option = option;
+ }
- @Override
- public boolean maybeStartOption(String arg) {
- return isOption(arg);
- }
+ @Override
+ public boolean maybeStartOption( String arg )
+ {
+ return isOption( arg );
+ }
- @Override
- public OptionParserState onStartOption(String arg, String option) {
- return this.option.onComplete().onStartOption(arg, option);
- }
+ @Override
+ public OptionParserState onStartOption( String arg, String option )
+ {
+ return this.option.onComplete().onStartOption( arg, option );
+ }
+
+ @Override
+ public ParserState onNonOption( String arg )
+ {
+ return option.onArgument( arg );
+ }
- @Override
- public ParserState onNonOption(String arg) {
- return option.onArgument(arg);
+ @Override
+ public void onCommandLineEnd()
+ {
+ option.onComplete();
+ }
}
- @Override
- public void onCommandLineEnd() {
- option.onComplete();
+ private abstract static class OptionParserState
+ {
+ public abstract ParserState onStartNextArg();
+
+ public abstract ParserState onArgument( String argument );
+
+ public abstract boolean getHasArgument();
+
+ public abstract ParserState onComplete();
}
- }
- private static abstract class OptionParserState {
- public abstract ParserState onStartNextArg();
+ private class KnownOptionParserState
+ extends OptionParserState
+ {
+ private final OptionString optionString;
- public abstract ParserState onArgument(String argument);
+ private final CommandLineOption option;
- public abstract boolean getHasArgument();
+ private final ParsedCommandLine commandLine;
- public abstract ParserState onComplete();
- }
+ private final ParserState state;
- private class KnownOptionParserState extends OptionParserState {
- private final OptionString optionString;
+ private final List<String> values = new ArrayList<String>();
- private final CommandLineOption option;
+ private KnownOptionParserState( OptionString optionString, CommandLineOption option,
+ ParsedCommandLine commandLine, ParserState state )
+ {
+ this.optionString = optionString;
+ this.option = option;
+ this.commandLine = commandLine;
+ this.state = state;
+ }
- private final ParsedCommandLine commandLine;
+ @Override
+ public ParserState onArgument( String argument )
+ {
+ if ( !getHasArgument() )
+ {
+ throw new CommandLineArgumentException(
+ String.format( "Command-line option '%s' does not take an argument.", optionString ) );
+ }
+ if ( argument.length() == 0 )
+ {
+ throw new CommandLineArgumentException(
+ String.format( "An empty argument was provided for command-line option '%s'.", optionString ) );
+ }
+ values.add( argument );
+ return onComplete();
+ }
- private final ParserState state;
+ @Override
+ public ParserState onStartNextArg()
+ {
+ if ( option.getAllowsArguments() && values.isEmpty() )
+ {
+ return new MissingOptionArgState( this );
+ }
+ return onComplete();
+ }
- private final List<String> values = new ArrayList<String>();
+ @Override
+ public boolean getHasArgument()
+ {
+ return option.getAllowsArguments();
+ }
- private KnownOptionParserState(OptionString optionString, CommandLineOption option, ParsedCommandLine commandLine, ParserState state) {
- this.optionString = optionString;
- this.option = option;
- this.commandLine = commandLine;
- this.state = state;
- }
+ @Override
+ public ParserState onComplete()
+ {
+ if ( getHasArgument() && values.isEmpty() )
+ {
+ throw new CommandLineArgumentException(
+ String.format( "No argument was provided for command-line option '%s'.", optionString ) );
+ }
- @Override
- public ParserState onArgument(String argument) {
- if (!getHasArgument()) {
- throw new CommandLineArgumentException(String.format("Command-line option '%s' does not take an argument.", optionString));
- }
- if (argument.length() == 0) {
- throw new CommandLineArgumentException(String.format("An empty argument was provided for command-line option '%s'.", optionString));
- }
- values.add(argument);
- return onComplete();
- }
+ ParsedCommandLineOption parsedOption = commandLine.addOption( optionString.option, option );
+ if ( values.size() + parsedOption.getValues().size() > 1 && !option.getAllowsMultipleArguments() )
+ {
+ throw new CommandLineArgumentException(
+ String.format( "Multiple arguments were provided for command-line option '%s'.", optionString ) );
+ }
+ for ( String value : values )
+ {
+ parsedOption.addArgument( value );
+ }
+ if ( option.getDeprecationWarning() != null )
+ {
+ deprecationPrinter.println( "The " + optionString + " option is deprecated - "
+ + option.getDeprecationWarning() );
+ }
+ if ( option.getSubcommand() != null )
+ {
+ return state.onNonOption( option.getSubcommand() );
+ }
- @Override
- public ParserState onStartNextArg() {
- if (option.getAllowsArguments() && values.isEmpty()) {
- return new MissingOptionArgState(this);
- }
- return onComplete();
+ return state;
+ }
}
- @Override
- public boolean getHasArgument() {
- return option.getAllowsArguments();
- }
+ private static class UnknownOptionParserState
+ extends OptionParserState
+ {
+ private final ParserState state;
- @Override
- public ParserState onComplete() {
- if (getHasArgument() && values.isEmpty()) {
- throw new CommandLineArgumentException(String.format("No argument was provided for command-line option '%s'.", optionString));
- }
-
- ParsedCommandLineOption parsedOption = commandLine.addOption(optionString.option, option);
- if (values.size() + parsedOption.getValues().size() > 1 && !option.getAllowsMultipleArguments()) {
- throw new CommandLineArgumentException(String.format("Multiple arguments were provided for command-line option '%s'.", optionString));
- }
- for (String value : values) {
- parsedOption.addArgument(value);
- }
- if (option.getDeprecationWarning() != null) {
- deprecationPrinter.println("The " + optionString + " option is deprecated - " + option.getDeprecationWarning());
- }
- if (option.getSubcommand() != null) {
- return state.onNonOption(option.getSubcommand());
- }
-
- return state;
- }
- }
+ private final String arg;
- private static class UnknownOptionParserState extends OptionParserState {
- private final ParserState state;
+ private final ParsedCommandLine commandLine;
- private final String arg;
+ private UnknownOptionParserState( String arg, ParsedCommandLine commandLine, ParserState state )
+ {
+ this.arg = arg;
+ this.commandLine = commandLine;
+ this.state = state;
+ }
- private final ParsedCommandLine commandLine;
+ @Override
+ public boolean getHasArgument()
+ {
+ return true;
+ }
- private UnknownOptionParserState(String arg, ParsedCommandLine commandLine, ParserState state) {
- this.arg = arg;
- this.commandLine = commandLine;
- this.state = state;
- }
+ @Override
+ public ParserState onStartNextArg()
+ {
+ return onComplete();
+ }
- @Override
- public boolean getHasArgument() {
- return true;
- }
+ @Override
+ public ParserState onArgument( String argument )
+ {
+ return onComplete();
+ }
- @Override
- public ParserState onStartNextArg() {
- return onComplete();
+ @Override
+ public ParserState onComplete()
+ {
+ commandLine.addExtraValue( arg );
+ return state;
+ }
}
- @Override
- public ParserState onArgument(String argument) {
- return onComplete();
+ private static final class OptionComparator
+ implements Comparator<CommandLineOption>
+ {
+ public int compare( CommandLineOption option1, CommandLineOption option2 )
+ {
+ String min1 = Collections.min( option1.getOptions(), new OptionStringComparator() );
+ String min2 = Collections.min( option2.getOptions(), new OptionStringComparator() );
+ return new CaseInsensitiveStringComparator().compare( min1, min2 );
+ }
}
- @Override
- public ParserState onComplete() {
- commandLine.addExtraValue(arg);
- return state;
+ private static final class CaseInsensitiveStringComparator
+ implements Comparator<String>
+ {
+ public int compare( String option1, String option2 )
+ {
+ int diff = option1.compareToIgnoreCase( option2 );
+ if ( diff != 0 )
+ {
+ return diff;
+ }
+ return option1.compareTo( option2 );
+ }
}
- }
- private static final class OptionComparator implements Comparator<CommandLineOption> {
- public int compare(CommandLineOption option1, CommandLineOption option2) {
- String min1 = Collections.min(option1.getOptions(), new OptionStringComparator());
- String min2 = Collections.min(option2.getOptions(), new OptionStringComparator());
- return new CaseInsensitiveStringComparator().compare(min1, min2);
- }
- }
-
- private static final class CaseInsensitiveStringComparator implements Comparator<String> {
- public int compare(String option1, String option2) {
- int diff = option1.compareToIgnoreCase(option2);
- if (diff != 0) {
- return diff;
- }
- return option1.compareTo(option2);
- }
- }
-
- private static final class OptionStringComparator implements Comparator<String> {
- public int compare(String option1, String option2) {
- boolean short1 = option1.length() == 1;
- boolean short2 = option2.length() == 1;
- if (short1 && !short2) {
- return -1;
- }
- if (!short1 && short2) {
- return 1;
- }
- return new CaseInsensitiveStringComparator().compare(option1, option2);
+ private static final class OptionStringComparator
+ implements Comparator<String>
+ {
+ public int compare( String option1, String option2 )
+ {
+ boolean short1 = option1.length() == 1;
+ boolean short2 = option2.length() == 1;
+ if ( short1 && !short2 )
+ {
+ return -1;
+ }
+ if ( !short1 && short2 )
+ {
+ return 1;
+ }
+ return new CaseInsensitiveStringComparator().compare( option1, option2 );
+ }
}
- }
}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLine.java b/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLine.java
index 8936e79..833da3d 100644
--- a/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLine.java
+++ b/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLine.java
@@ -1,19 +1,23 @@
+package org.apache.maven.wrapper.cli;
+
/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper.cli;
import java.util.ArrayList;
import java.util.Collection;
@@ -23,93 +27,114 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-public class ParsedCommandLine {
- private final Map<String, ParsedCommandLineOption> optionsByString = new HashMap<String, ParsedCommandLineOption>();
+/**
+ * The Parsed Command Line
+ */
+public class ParsedCommandLine
+{
+ private final Map<String, ParsedCommandLineOption> optionsByString = new HashMap<String, ParsedCommandLineOption>();
- private final Set<String> presentOptions = new HashSet<String>();
+ private final Set<String> presentOptions = new HashSet<String>();
- private final List<String> extraArguments = new ArrayList<String>();
+ private final List<String> extraArguments = new ArrayList<String>();
- ParsedCommandLine(Iterable<CommandLineOption> options) {
- for (CommandLineOption option : options) {
- ParsedCommandLineOption parsedOption = new ParsedCommandLineOption();
- for (String optionStr : option.getOptions()) {
- optionsByString.put(optionStr, parsedOption);
- }
+ ParsedCommandLine( Iterable<CommandLineOption> options )
+ {
+ for ( CommandLineOption option : options )
+ {
+ ParsedCommandLineOption parsedOption = new ParsedCommandLineOption();
+ for ( String optionStr : option.getOptions() )
+ {
+ optionsByString.put( optionStr, parsedOption );
+ }
+ }
}
- }
- @Override
- public String toString() {
- return String.format("options: %s, extraArguments: %s", quoteAndJoin(presentOptions), quoteAndJoin(extraArguments));
- }
+ @Override
+ public String toString()
+ {
+ return String.format( "options: %s, extraArguments: %s", quoteAndJoin( presentOptions ),
+ quoteAndJoin( extraArguments ) );
+ }
- private String quoteAndJoin(Iterable<String> strings) {
- StringBuilder output = new StringBuilder();
- boolean isFirst = true;
- for (String string : strings) {
- if (!isFirst) {
- output.append(", ");
- }
- output.append("'");
- output.append(string);
- output.append("'");
- isFirst = false;
+ private String quoteAndJoin( Iterable<String> strings )
+ {
+ StringBuilder output = new StringBuilder();
+ boolean isFirst = true;
+ for ( String string : strings )
+ {
+ if ( !isFirst )
+ {
+ output.append( ", " );
+ }
+ output.append( "'" );
+ output.append( string );
+ output.append( "'" );
+ isFirst = false;
+ }
+ return output.toString();
}
- return output.toString();
- }
- /**
- * Returns true if the given option is present in this command-line.
- *
- * @param option The option, without the '-' or '--' prefix.
- * @return true if the option is present.
- */
- public boolean hasOption(String option) {
- option(option);
- return presentOptions.contains(option);
- }
+ /**
+ * Returns true if the given option is present in this command-line.
+ *
+ * @param option The option, without the '-' or '--' prefix.
+ * @return true if the option is present.
+ */
+ public boolean hasOption( String option )
+ {
+ option( option );
+ return presentOptions.contains( option );
+ }
- /**
- * See also {@link #hasOption}.
- *
- * @param logLevelOptions the options to check
- * @return true if any of the passed options is present
- */
- public boolean hasAnyOption(Collection<String> logLevelOptions) {
- for (String option : logLevelOptions) {
- if (hasOption(option)) {
- return true;
- }
+ /**
+ * See also {@link #hasOption}.
+ *
+ * @param logLevelOptions the options to check
+ * @return true if any of the passed options is present
+ */
+ public boolean hasAnyOption( Collection<String> logLevelOptions )
+ {
+ for ( String option : logLevelOptions )
+ {
+ if ( hasOption( option ) )
+ {
+ return true;
+ }
+ }
+ return false;
}
- return false;
- }
- /**
- * Returns the value of the given option.
- *
- * @param option The option, without the '-' or '--' prefix.
- * @return The option. never returns null.
- */
- public ParsedCommandLineOption option(String option) {
- ParsedCommandLineOption parsedOption = optionsByString.get(option);
- if (parsedOption == null) {
- throw new IllegalArgumentException(String.format("Option '%s' not defined.", option));
+ /**
+ * Returns the value of the given option.
+ *
+ * @param option The option, without the '-' or '--' prefix.
+ * @return The option. never returns null.
+ */
+ public ParsedCommandLineOption option( String option )
+ {
+ ParsedCommandLineOption parsedOption = optionsByString.get( option );
+ if ( parsedOption == null )
+ {
+ throw new IllegalArgumentException( String.format( "Option '%s' not defined.", option ) );
+ }
+ return parsedOption;
}
- return parsedOption;
- }
- public List<String> getExtraArguments() {
- return extraArguments;
- }
+ public List<String> getExtraArguments()
+ {
+ return extraArguments;
+ }
- void addExtraValue(String value) {
- extraArguments.add(value);
- }
+ void addExtraValue( String value )
+ {
+ extraArguments.add( value );
+ }
- ParsedCommandLineOption addOption(String optionStr, CommandLineOption option) {
- ParsedCommandLineOption parsedOption = optionsByString.get(optionStr);
- presentOptions.addAll(option.getOptions());
- return parsedOption;
- }
+ ParsedCommandLineOption addOption( String optionStr, CommandLineOption option )
+ {
+ ParsedCommandLineOption parsedOption = optionsByString.get( optionStr );
+ presentOptions.addAll( option.getOptions() );
+ return parsedOption;
+ }
}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLineOption.java b/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLineOption.java
index 022d495..d75acc0 100644
--- a/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLineOption.java
+++ b/src/main/java/org/apache/maven/wrapper/cli/ParsedCommandLineOption.java
@@ -1,45 +1,59 @@
+package org.apache.maven.wrapper.cli;
+
/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper.cli;
import java.util.ArrayList;
import java.util.List;
-public class ParsedCommandLineOption {
- private final List<String> values = new ArrayList<String>();
+/**
+ * The Parsed Command Line Option
+ */
+public class ParsedCommandLineOption
+{
+ private final List<String> values = new ArrayList<String>();
- public String getValue() {
- if (!hasValue()) {
- throw new IllegalStateException("Option does not have any value.");
+ public String getValue()
+ {
+ if ( !hasValue() )
+ {
+ throw new IllegalStateException( "Option does not have any value." );
+ }
+ if ( values.size() > 1 )
+ {
+ throw new IllegalStateException( "Option has multiple values." );
+ }
+ return values.get( 0 );
}
- if (values.size() > 1) {
- throw new IllegalStateException("Option has multiple values.");
- }
- return values.get(0);
- }
- public List<String> getValues() {
- return values;
- }
+ public List<String> getValues()
+ {
+ return values;
+ }
- public void addArgument(String argument) {
- values.add(argument);
- }
+ public void addArgument( String argument )
+ {
+ values.add( argument );
+ }
- public boolean hasValue() {
- return !values.isEmpty();
- }
+ public boolean hasValue()
+ {
+ return !values.isEmpty();
+ }
}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/ProjectPropertiesCommandLineConverter.java b/src/main/java/org/apache/maven/wrapper/cli/ProjectPropertiesCommandLineConverter.java
index ae90665..eaa5b11 100644
--- a/src/main/java/org/apache/maven/wrapper/cli/ProjectPropertiesCommandLineConverter.java
+++ b/src/main/java/org/apache/maven/wrapper/cli/ProjectPropertiesCommandLineConverter.java
@@ -1,35 +1,46 @@
+package org.apache.maven.wrapper.cli;
+
/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper.cli;
-
-public class ProjectPropertiesCommandLineConverter extends AbstractPropertiesCommandLineConverter {
+/**
+ * The Project Properties CommandLine Converter
+ */
+public class ProjectPropertiesCommandLineConverter
+ extends AbstractPropertiesCommandLineConverter
+{
- @Override
- protected String getPropertyOption() {
- return "P";
- }
+ @Override
+ protected String getPropertyOption()
+ {
+ return "P";
+ }
- @Override
- protected String getPropertyOptionDetailed() {
- return "project-prop";
- }
+ @Override
+ protected String getPropertyOptionDetailed()
+ {
+ return "project-prop";
+ }
- @Override
- protected String getPropertyOptionDescription() {
- return "Set project property for the build script (e.g. -Pmyprop=myvalue).";
- }
+ @Override
+ protected String getPropertyOptionDescription()
+ {
+ return "Set project property for the build script (e.g. -Pmyprop=myvalue).";
+ }
}
diff --git a/src/main/java/org/apache/maven/wrapper/cli/SystemPropertiesCommandLineConverter.java b/src/main/java/org/apache/maven/wrapper/cli/SystemPropertiesCommandLineConverter.java
index 4cd03b4..6a1fca5 100644
--- a/src/main/java/org/apache/maven/wrapper/cli/SystemPropertiesCommandLineConverter.java
+++ b/src/main/java/org/apache/maven/wrapper/cli/SystemPropertiesCommandLineConverter.java
@@ -1,34 +1,46 @@
+package org.apache.maven.wrapper.cli;
+
/*
- * Copyright 2007-present the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.maven.wrapper.cli;
-public class SystemPropertiesCommandLineConverter extends AbstractPropertiesCommandLineConverter {
+/**
+ * The System Properties Command Line Converter
+ */
+public class SystemPropertiesCommandLineConverter
+ extends AbstractPropertiesCommandLineConverter
+{
- @Override
- protected String getPropertyOption() {
- return "D";
- }
+ @Override
+ protected String getPropertyOption()
+ {
+ return "D";
+ }
- @Override
- protected String getPropertyOptionDetailed() {
- return "system-prop";
- }
+ @Override
+ protected String getPropertyOptionDetailed()
+ {
+ return "system-prop";
+ }
- @Override
- protected String getPropertyOptionDescription() {
- return "Set system property of the JVM (e.g. -Dmyprop=myvalue).";
- }
+ @Override
+ protected String getPropertyOptionDescription()
+ {
+ return "Set system property of the JVM (e.g. -Dmyprop=myvalue).";
+ }
}
\ No newline at end of file
diff --git a/src/main/provisio/wrapper.xml b/src/main/provisio/wrapper.xml
deleted file mode 100644
index b0e7b10..0000000
--- a/src/main/provisio/wrapper.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<runtime>
- <archive name="${project.artifactId}-${project.version}.tar.gz" />
-
- <artifactSet to="/.mvn/wrapper">
- <artifact ref="projectArtifact" as="maven-wrapper.jar"/>
- </artifactSet>
-
- <fileSet to="/">
- <directory path="${basedir}">
- <include>mvnw</include>
- <include>mvnw.cmd</include>
- <include>.mvn/**</include>
- <exclude>**/*.jar</exclude>
- </directory>
- </fileSet>
-</runtime>
diff --git a/src/test/java/org/apache/maven/wrapper/DownloaderTest.java b/src/test/java/org/apache/maven/wrapper/DownloaderTest.java
index c3fa682..2f72e0c 100644
--- a/src/test/java/org/apache/maven/wrapper/DownloaderTest.java
+++ b/src/test/java/org/apache/maven/wrapper/DownloaderTest.java
@@ -1,5 +1,24 @@
package org.apache.maven.wrapper;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
import static org.junit.Assert.assertEquals;
import java.io.File;
diff --git a/src/test/java/org/apache/maven/wrapper/InstallerTest.java b/src/test/java/org/apache/maven/wrapper/InstallerTest.java
index 95b289a..b25599b 100644
--- a/src/test/java/org/apache/maven/wrapper/InstallerTest.java
+++ b/src/test/java/org/apache/maven/wrapper/InstallerTest.java
@@ -1,5 +1,24 @@
package org.apache.maven.wrapper;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
diff --git a/src/test/java/org/apache/maven/wrapper/SystemPropertiesHandlerTest.java b/src/test/java/org/apache/maven/wrapper/SystemPropertiesHandlerTest.java
index e650d57..df8c5b9 100644
--- a/src/test/java/org/apache/maven/wrapper/SystemPropertiesHandlerTest.java
+++ b/src/test/java/org/apache/maven/wrapper/SystemPropertiesHandlerTest.java
@@ -1,5 +1,24 @@
package org.apache.maven.wrapper;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
diff --git a/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java b/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java
index 439f68e..2c151a0 100644
--- a/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java
+++ b/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java
@@ -1,5 +1,24 @@
package org.apache.maven.wrapper;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
diff --git a/src/test/resources/org/apache/maven/wrapper/wrapper.properties b/src/test/resources/org/apache/maven/wrapper/wrapper.properties
index 6ff45e7..94970a2 100644
--- a/src/test/resources/org/apache/maven/wrapper/wrapper.properties
+++ b/src/test/resources/org/apache/maven/wrapper/wrapper.properties
@@ -1,3 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
distributionUrl=http://server/test/maven.zip
distributionBase=testDistBase
zipStoreBase=testZipBase