Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no longer checks for build receipt resource, skips Install and Download #4

Merged
merged 7 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pick one of the below options:
* `groovyw` and/or `groovyw.bat` should live next to their Gradle variants in the root of a project
* Download a zip file from the Releases tab, extract, place the files accordingly into a local workspace
* Build your own by cloning this repo and running `gradlew jar` to get a fresh `groovy-wrapper.jar` of your own
* You can run `gradlew prep` to both build and place the jar under `gradle/wrapper` where it can be tested with `groovyw test`
* You can run `gradlew prep` to both build and place the jar under `gradle/wrapper` where it can be tested with `groovyw Test`
* For convenience a built version is already maintained there for easy testing

## Gradle
Expand Down
6 changes: 0 additions & 6 deletions Test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,4 @@ class Test extends GroovyTestCase {
def ivyHome = report.getIvyHomeURL()
assertTrue(ivyHome.contains("apache.org"))
}

void testCLI() {
def cli = new CliBuilder(usage: 'Usage')
def expected = 'Usage'
assertToString(cli.usage, expected)
}
}
Binary file modified gradle/wrapper/groovy-wrapper.jar
Binary file not shown.
57 changes: 35 additions & 22 deletions groovyw
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 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
#
# https://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.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -33,11 +49,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -66,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar:$APP_HOME/gradle/wrapper/groovy-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand All @@ -138,35 +156,30 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GroovyWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
20 changes: 20 additions & 0 deletions groovyw.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -13,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

Expand Down Expand Up @@ -65,6 +84,7 @@ set CMD_LINE_ARGS=%*

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar;%APP_HOME%\gradle\wrapper\groovy-wrapper.jar;


@rem Execute Groovy via the Gradle Wrapper
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GroovyWrapperMain %CMD_LINE_ARGS%

Expand Down
49 changes: 27 additions & 22 deletions src/main/java/org/gradle/wrapper/GroovyBootstrapMainStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.gradle.wrapper;

import java.io.Closeable;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
Expand All @@ -24,31 +23,37 @@
public class GroovyBootstrapMainStarter extends BootstrapMainStarter {
@Override
public void start(String[] args, File gradleHome) throws Exception {
File groovyJar = findJar("groovy-all", gradleHome, "lib");
File ivyJar = findJar("ivy", gradleHome, "lib/plugins");
File cliJar = findJar("commons-cli", gradleHome, "lib/plugins");
File junitJar = findJar("junit", gradleHome, "lib/plugins");
URLClassLoader contextClassLoader = new URLClassLoader(new URL[]{
groovyJar.toURI().toURL()
,ivyJar.toURI().toURL()
,cliJar.toURI().toURL()
,junitJar.toURI().toURL()
}, ClassLoader.getSystemClassLoader().getParent());
Thread.currentThread().setContextClassLoader(contextClassLoader);
Class<?> mainClass = contextClassLoader.loadClass("groovy.ui.GroovyMain");
Method mainMethod = mainClass.getMethod("main", String[].class);
mainMethod.invoke(null, new Object[]{args});
if (contextClassLoader instanceof Closeable) {
((Closeable) contextClassLoader).close();
final URL[] urls = {
findJar("groovy-all", gradleHome, "lib"),
findJar("ivy", gradleHome, "lib/plugins"),
findJar("junit", gradleHome, "lib/plugins")
};
try (URLClassLoader contextClassLoader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader().getParent())) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
Class<?> mainClass = contextClassLoader.loadClass("groovy.ui.GroovyMain");
Method mainMethod = mainClass.getMethod("main", String[].class);
mainMethod.invoke(null, new Object[]{args});
}
}

private File findJar(String fragment, File gradleHome, String subdir) {
for (File file : new File(gradleHome, subdir).listFiles()) {
if (file.getName().matches(fragment + "-.*\\.jar")) {
return file;
private URL findJar(String fragment, File gradleHome, String subdir) {
final File gradleSubdir = new File(gradleHome, subdir);
final File[] files = gradleSubdir.listFiles((d, name) ->
name.startsWith(fragment + "-") && name.endsWith(".jar")
);
if (files == null) {
throw new RuntimeException(String.format("Could not locate the JAR for %s; no such directory '%s'.",
fragment, gradleSubdir));
} else if (files.length == 0) {
throw new RuntimeException(String.format("Could not locate the JAR for %s in Gradle distribution '%s'.",
fragment, gradleHome));
} else {
try {
return files[0].toURI().toURL();
} catch (java.net.MalformedURLException e) {
// This is so unlikely, let's keep it out of the signature.
throw new RuntimeException(e.getMessage(),e);
}
}
throw new RuntimeException(String.format("Could not locate the JAR for " + fragment + " in Gradle distribution '%s'.", gradleHome));
}
}
49 changes: 16 additions & 33 deletions src/main/java/org/gradle/wrapper/GroovyWrapperMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.gradle.cli.SystemPropertiesCommandLineConverter;

import java.io.File;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
Expand Down Expand Up @@ -55,13 +54,23 @@ public static void main(String[] args) throws Exception {

addSystemProperties(gradleUserHome, rootDir);

Logger logger = logger(options);
WrapperConfiguration config = WrapperExecutor.forWrapperPropertiesFile(propertiesFile).getConfiguration();
PathAssembler.LocalDistribution localDist = new PathAssembler(gradleUserHome).getDistribution(config);
File gradleHome = getAndVerifyDistributionRoot(localDist.getDistributionDir());

WrapperExecutor wrapperExecutor = WrapperExecutor.forWrapperPropertiesFile(propertiesFile);
wrapperExecutor.execute(
args,
new Install(logger, new Download(logger, "gradlew", wrapperVersion()), new PathAssembler(gradleUserHome)),
Comment on lines -60 to -63
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I axed all this Install and Download invocation, but if you want to keep the download-and-install functionality, you leave this in and just replace that wrapperVersion() with org.gradle.wrapper.Download.UNKNOWN_VERSION: https://github.com/gradle/gradle/blob/00862b8160a09051e8226736314afd16e7f418f7/subprojects/wrapper/src/main/java/org/gradle/wrapper/Download.java#L24

aka "0"

new GroovyBootstrapMainStarter());
new GroovyBootstrapMainStarter().start(args, gradleHome);
}

static File getAndVerifyDistributionRoot(File distDir) {
// Extracted from org.gradle.wrapper.Install.getAndVerifyDistributionRoot
Comment on lines +64 to +65
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then if you keep that Install invocation, there's no reason to have this duplicate copy of this method brought over from the Install class.

java.io.File[] dirs = distDir.listFiles(File::isDirectory);
assert dirs != null: "directory does not exist: " + distDir;
if (dirs.length != 1) {
throw new RuntimeException(String.format("Gradle distribution '%s' contains %d directories. " +
"Expected to find exactly 1 directory.", distDir, dirs.length));
} else {
return dirs[0];
}
}

private static void addSystemProperties(File gradleHome, File rootDir) {
Expand Down Expand Up @@ -90,36 +99,10 @@ private static File wrapperJar() {
return new File(location.getPath());
}

static String wrapperVersion() {
try {
InputStream resourceAsStream = GradleWrapperMain.class.getResourceAsStream("/build-receipt.properties");
if (resourceAsStream == null) {
throw new RuntimeException("No build receipt resource found.");
}
Properties buildReceipt = new Properties();
try {
buildReceipt.load(resourceAsStream);
String versionNumber = buildReceipt.getProperty("versionNumber");
if (versionNumber == null) {
throw new RuntimeException("No version number specified in build receipt resource.");
}
return versionNumber;
} finally {
resourceAsStream.close();
}
} catch (Exception e) {
throw new RuntimeException("Could not determine wrapper version.", e);
}
}

private static File gradleUserHome(ParsedCommandLine options) {
if (options.hasOption(GRADLE_USER_HOME_OPTION)) {
return new File(options.option(GRADLE_USER_HOME_OPTION).getValue());
}
return GradleUserHomeLookup.gradleUserHome();
}

private static Logger logger(ParsedCommandLine options) {
return new Logger(options.hasOption(GRADLE_QUIET_OPTION));
}
}