diff --git a/.gitignore b/.gitignore index 8539942..3d02b83 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea/ build .gradle +/bin/ diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..1a0819e --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +java temurin-11.0.20+8 diff --git a/.travis.yml b/.travis.yml index 19c6239..164288b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,8 @@ cache: - '$HOME/.gradle/wrapper/' script: - - ./gradlew -is check +- test/bin/smoketest || travis_terminate 1 +- ./gradlew -is check before_deploy: - | diff --git a/build.gradle b/build.gradle index f88dc74..9a535cc 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,12 @@ def versionLikeRegexp = /^\d+\.\d+.*/ def travisVersionOK = travisVersion && (travisVersion ==~ versionLikeRegexp) paramVersion = paramVersion ?: (travisVersionOK ? travisVersion : defVersion) +if (findProperty('snapshot') != null) { + paramVersion += '-SNAPSHOT' +} + +println "version:$paramVersion" + version = paramVersion group = paramGroupId @@ -49,8 +55,9 @@ repositories { dependencies { gradleApi() localGroovy() - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2' + testImplementation(enforcedPlatform("org.junit:junit-bom:5.10.0")) // JUnit 5 BOM + testImplementation("org.junit.jupiter:junit-jupiter") + implementation 'com.appland:appmap-agent:[1.3, 2.0)' implementation 'commons-lang:commons-lang:2.6' implementation 'com.google.guava:guava:30.1.1-jre' diff --git a/src/main/java/com/appland/appmap/gradle/AgentCommandLineLoader.java b/src/main/java/com/appland/appmap/gradle/AgentCommandLineLoader.java index 79a69bb..0fbf60f 100644 --- a/src/main/java/com/appland/appmap/gradle/AgentCommandLineLoader.java +++ b/src/main/java/com/appland/appmap/gradle/AgentCommandLineLoader.java @@ -2,19 +2,22 @@ import static java.lang.String.format; -import com.google.common.base.Joiner; import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import org.apache.commons.lang.StringEscapeUtils; import org.gradle.api.GradleException; import org.gradle.api.Named; +import org.gradle.api.file.RegularFileProperty; import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logging; import org.gradle.api.tasks.Internal; import org.gradle.process.CommandLineArgumentProvider; import org.gradle.util.RelativePathUtil; +import com.google.common.base.Joiner; + /** * This class is the actual responsible of building the JVM args to run the AppMap Agent. */ @@ -51,6 +54,8 @@ public String getName() { */ @Internal public List getAsJvmArg() { + RegularFileProperty configFile = appmap.getConfigFile(); + if (!appmap.isConfigFileValid()) { appmap.setSkip(true); throw new GradleException("Configuration file must exist and be readable: " @@ -69,7 +74,7 @@ public List getAsJvmArg() { List argumentLn = new ArrayList<>(); argumentLn.add(javaAgentArg); - if ( appmap.getConfigFile().isPresent() ) { + if (configFile != null && configFile.isPresent()) { argumentLn.add("-Dappmap.config.file=" + appmap.getConfigFilePath()); } argumentLn.add("-Dappmap.output.directory=" + appmap.getOutputDirectoryPath()); diff --git a/src/main/java/com/appland/appmap/gradle/AppMapPlugin.java b/src/main/java/com/appland/appmap/gradle/AppMapPlugin.java index 896a81c..415d8f0 100644 --- a/src/main/java/com/appland/appmap/gradle/AppMapPlugin.java +++ b/src/main/java/com/appland/appmap/gradle/AppMapPlugin.java @@ -26,10 +26,9 @@ public void apply(Project project) { config.setTransitive(true); config.setDescription("AppMap agent to generate app map data."); config.defaultDependencies(dependencies -> - dependencies.add( - project.getDependencies().create("com.appland:appmap-agent:" + DEFAULT_AGENT_VERSION) - ) - ); + dependencies.add( + project.getDependencies().create( + "com.appland:appmap-agent:" + findProperty("appmapAgentVersion", DEFAULT_AGENT_VERSION)))); AppMapPluginExtension extension = project.getExtensions() .create(PLUGIN_EXTENSION_NAME, AppMapPluginExtension.class, project, config); //extension.setAgentVersion(DEFAULT_AGENT_VERSION);*/ @@ -54,44 +53,41 @@ private void addAppMapGradleTasks(AppMapPluginExtension extension) { * @param extension holds the config parameters for the plugin. */ private void addAppMapTasks(AppMapPluginExtension extension) { - project.getTasks().register( - "appmap", - AppMapTask.class, - prepareAgentTask -> { - prepareAgentTask.doFirst( - new ValidateConfigAction(extension.getConfigFile().getAsFile()) - ); - prepareAgentTask.doLast(new LoadAppMapAgentAction(project, extension)); - prepareAgentTask.setGroup(LifecycleBasePlugin.BUILD_GROUP); - prepareAgentTask.setDescription( - String.format("Injects AppMap Agent JVM settings to the 'test' task") - ); - }); + project.getTasks().register( + "appmap", + AppMapTask.class, + prepareAgentTask -> { + prepareAgentTask.doFirst( + new ValidateConfigAction(extension.getConfigFile())); + prepareAgentTask.doLast(new LoadAppMapAgentAction(project, extension)); + prepareAgentTask.setGroup(LifecycleBasePlugin.BUILD_GROUP); + prepareAgentTask.setDescription( + String.format("Injects AppMap Agent JVM settings to the 'test' task")); + }); - project.getTasks().register( - "appmap-validate-config", - validateConfigTask -> { - validateConfigTask.doFirst( - new ValidateConfigAction(extension.getConfigFile().getAsFile()) - ); - validateConfigTask.setGroup(LifecycleBasePlugin.BUILD_GROUP); - validateConfigTask.setDescription( - String.format("Validates the AppMap Agent configuration") - ); - } - ); + project.getTasks().register( + "appmap-validate-config", + validateConfigTask -> { + validateConfigTask.doFirst( + new ValidateConfigAction(extension.getConfigFile())); + validateConfigTask.setGroup(LifecycleBasePlugin.BUILD_GROUP); + validateConfigTask.setDescription( + String.format("Validates the AppMap Agent configuration")); + }); project.getTasks().register( - "appmap-print-jar-path", - agentJarPathTask -> { - agentJarPathTask.doFirst( - new PrintJarPathAction(extension) - ); - agentJarPathTask.setGroup(LifecycleBasePlugin.BUILD_GROUP); - agentJarPathTask.setDescription( - String.format("Prints the file path of the AppMap Agent JAR") - ); - } - ); + "appmap-print-jar-path", + agentJarPathTask -> { + agentJarPathTask.doFirst( + new PrintJarPathAction(extension)); + agentJarPathTask.setGroup(LifecycleBasePlugin.BUILD_GROUP); + agentJarPathTask.setDescription( + String.format("Prints the file path of the AppMap Agent JAR")); + }); + } + + String findProperty(String name, String defaultValue) { + String value = (String) project.findProperty(name); + return value != null ? value : defaultValue; } } diff --git a/src/main/java/com/appland/appmap/gradle/AppMapPluginExtension.java b/src/main/java/com/appland/appmap/gradle/AppMapPluginExtension.java index 6e73168..b5e3d8e 100644 --- a/src/main/java/com/appland/appmap/gradle/AppMapPluginExtension.java +++ b/src/main/java/com/appland/appmap/gradle/AppMapPluginExtension.java @@ -6,8 +6,12 @@ import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; +import org.gradle.api.file.Directory; import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.file.ProjectLayout; +import org.gradle.api.file.RegularFile; import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.model.ObjectFactory; import org.gradle.api.tasks.Input; /** @@ -29,21 +33,24 @@ public class AppMapPluginExtension { private int eventValueSize = 1024; /** - * Constructor method, receives the project, configuration and fork options, read and provide the + * Constructor method, receives the project, configuration and fork options, + * read and provide the * rest of the configuration to the AppMapPlugin class. * - * @param project Actual project object representation. + * @param project Actual project object representation. * @param agentConf Holder of the project configuration. */ public AppMapPluginExtension(Project project, Configuration agentConf) { this.project = project; this.agentConf = agentConf; - this.configFile = project.getObjects().fileProperty() - .value(project.getLayout().getProjectDirectory().file("appmap.yml")); this.outputDirectory = project.getObjects().directoryProperty() .value(project.getLayout().getBuildDirectory().dir(DEFAULT_OUTPUT_DIRECTORY).get()); - this.debugFile = project.getObjects().fileProperty() - .value(project.getLayout().getBuildDirectory().file("appmap/agent.log").get()); + ProjectLayout projectLayout = project.getLayout(); + Directory projectDirectory = projectLayout.getProjectDirectory(); + ObjectFactory projectObjects = project.getObjects(); + this.configFile = projectObjects.fileProperty(); + this.debugFile = projectObjects.fileProperty() + .value(projectLayout.getBuildDirectory().file("appmap/agent.log").get()); logger.info("AppMap Plugin Initialized."); } @@ -117,10 +124,16 @@ public boolean isSkip() { } public boolean isConfigFileValid() { - return AppMapPluginExtension.isConfigFileValid(configFile.get().getAsFile()); + return AppMapPluginExtension.isConfigFileValid(configFile.getOrNull()); } - public static boolean isConfigFileValid(File configFile) { + public static boolean isConfigFileValid(RegularFile configFileProperty) { + if (configFileProperty == null) { + // If there's no config file specified, let the agent deal with it. + return true; + } + + File configFile = configFileProperty.getAsFile(); return configFile.exists() && Files.isReadable(configFile.toPath()); } } diff --git a/src/main/java/com/appland/appmap/gradle/ValidateConfigAction.java b/src/main/java/com/appland/appmap/gradle/ValidateConfigAction.java index 43b9aef..fb467f0 100644 --- a/src/main/java/com/appland/appmap/gradle/ValidateConfigAction.java +++ b/src/main/java/com/appland/appmap/gradle/ValidateConfigAction.java @@ -1,10 +1,10 @@ package com.appland.appmap.gradle; -import java.io.File; - import org.gradle.api.Action; import org.gradle.api.GradleException; import org.gradle.api.Task; +import org.gradle.api.file.RegularFile; +import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.Provider; /** @@ -12,22 +12,22 @@ */ public class ValidateConfigAction implements Action { - private final Provider configFile; + private final Provider configFile; - public ValidateConfigAction(Provider configFile) { - this.configFile = configFile; + public ValidateConfigAction(RegularFileProperty regularFileProperty) { + this.configFile = regularFileProperty; } @Override public void execute(Task task) { if (!isConfigFileValid()) { throw new GradleException( - "Config file " + configFile.get().getPath() + " not found or not readable." + "Config file " + configFile.get().getAsFile().getPath() + " not found or not readable." ); } } protected boolean isConfigFileValid() { - return AppMapPluginExtension.isConfigFileValid(configFile.get()); + return AppMapPluginExtension.isConfigFileValid(configFile.getOrNull()); } } diff --git a/src/test/java/com/appland/appmap/gradle/AppMapPluginFunctionalTest.java b/src/test/java/com/appland/appmap/gradle/AppMapPluginFunctionalTest.java index 1344ba0..9aabef7 100644 --- a/src/test/java/com/appland/appmap/gradle/AppMapPluginFunctionalTest.java +++ b/src/test/java/com/appland/appmap/gradle/AppMapPluginFunctionalTest.java @@ -1,23 +1,27 @@ package com.appland.appmap.gradle; -import org.gradle.testkit.runner.BuildResult; -import org.gradle.testkit.runner.GradleRunner; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; +import static org.gradle.testkit.runner.TaskOutcome.FAILED; +import static org.gradle.testkit.runner.TaskOutcome.NO_SOURCE; +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; -import static org.gradle.testkit.runner.TaskOutcome.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.gradle.testkit.runner.BuildResult; +import org.gradle.testkit.runner.GradleRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class AppMapPluginFunctionalTest { - @TempDir File testProjectDir; + @TempDir + File testProjectDir; private File settingsFile; private File buildFile; private File appmapConfigFile; @@ -30,25 +34,10 @@ public void setup() { } @Test - public void testValidateConfigGoalFailsOnNonExistentFile() throws IOException { - writeFile(settingsFile, SETTINGS_GRADLE_CONTENT); - writeFile(buildFile, BUILD_FILE_CONTENT); - - BuildResult result = GradleRunner.create() - .withProjectDir(testProjectDir) - .withArguments("appmap-validate-config") - .withPluginClasspath() - .buildAndFail(); - - assertTrue(result.getOutput().contains("not found or not readable.")); - assertEquals(FAILED, result.task(":appmap-validate-config").getOutcome()); - } - - @Test - public void testValidateConfigGoalSucceed() throws IOException { + public void testValidateConfigGoalSucceedsOnNonExistentFile() throws IOException { writeFile(settingsFile, SETTINGS_GRADLE_CONTENT); - writeFile(buildFile, BUILD_FILE_CONTENT); - writeFile(appmapConfigFile, APPMAP_CONFIGFILE_CONTENT); + String buildFileContent = String.format(BUILD_FILE_CONTENT, ""); + writeFile(buildFile, buildFileContent); BuildResult result = GradleRunner.create() .withProjectDir(testProjectDir) @@ -60,38 +49,71 @@ public void testValidateConfigGoalSucceed() throws IOException { assertEquals(SUCCESS, result.task(":appmap-validate-config").getOutcome()); } - @Test - public void testAppMapGoalSucceed() throws IOException { - writeFile(settingsFile, SETTINGS_GRADLE_CONTENT); - writeFile(buildFile, BUILD_FILE_CONTENT); - writeFile(appmapConfigFile, APPMAP_CONFIGFILE_CONTENT); + @Nested + class withConfigSpecified { + @BeforeEach + void writeFiles() throws IOException { + writeFile(settingsFile, SETTINGS_GRADLE_CONTENT); + writeFile(buildFile, String.format(BUILD_FILE_CONTENT, "configFile = file(\"$projectDir/appmap.yml\")\n")); + } - BuildResult result = GradleRunner.create() - .withProjectDir(testProjectDir) - .withArguments("appmap") - .withPluginClasspath() - .build(); + @Test + public void testValidateConfigGoalFailsOnNonExistentFile() throws IOException { + BuildResult result = GradleRunner.create() + .withProjectDir(testProjectDir) + .withArguments("appmap-validate-config") + .withPluginClasspath() + .buildAndFail(); - assertTrue(result.getOutput().contains("BUILD SUCCESSFUL")); - assertEquals(NO_SOURCE, result.task(":appmap").getOutcome()); - } + assertTrue(result.getOutput().contains("not found or not readable.")); + assertEquals(FAILED, result.task(":appmap-validate-config").getOutcome()); + } - @Test - public void testAppMapJarPath() throws IOException { - writeFile(settingsFile, SETTINGS_GRADLE_CONTENT); - writeFile(buildFile, BUILD_FILE_CONTENT); - writeFile(appmapConfigFile, APPMAP_CONFIGFILE_CONTENT); + @Nested + class withConfigPresent { + @BeforeEach + void writeConfig() throws IOException { + writeFile(appmapConfigFile, APPMAP_CONFIGFILE_CONTENT); + } - BuildResult result = GradleRunner.create() - .withProjectDir(testProjectDir) - .withArguments("appmap-print-jar-path") - .withPluginClasspath() - .build(); + @Test + public void testValidateConfigGoalSucceed() throws IOException { + BuildResult result = GradleRunner.create() + .withProjectDir(testProjectDir) + .withArguments("appmap-validate-config") + .withPluginClasspath() + .build(); - assertTrue(result.getOutput().contains("BUILD SUCCESSFUL")); - assertTrue(result.getOutput().contains("java.home=")); - assertTrue(result.getOutput().contains("com.appland:appmap-agent.jar.path=")); - assertEquals(SUCCESS, result.task(":appmap-print-jar-path").getOutcome()); + assertTrue(result.getOutput().contains("BUILD SUCCESSFUL")); + assertEquals(SUCCESS, result.task(":appmap-validate-config").getOutcome()); + } + + @Test + public void testAppMapGoalSucceed() throws IOException { + BuildResult result = GradleRunner.create() + .withProjectDir(testProjectDir) + .withArguments("appmap") + .withPluginClasspath() + .build(); + + assertTrue(result.getOutput().contains("BUILD SUCCESSFUL")); + assertEquals(NO_SOURCE, result.task(":appmap").getOutcome()); + } + + @Test + public void testAppMapJarPath() throws IOException { + BuildResult result = GradleRunner.create() + .withProjectDir(testProjectDir) + .withArguments("appmap-print-jar-path") + .withPluginClasspath() + .build(); + + assertTrue(result.getOutput().contains("BUILD SUCCESSFUL")); + assertTrue(result.getOutput().contains("java.home=")); + assertTrue(result.getOutput().contains("com.appland:appmap-agent.jar.path=")); + assertEquals(SUCCESS, result.task(":appmap-print-jar-path").getOutcome()); + } + } } private void writeFile(File destination, String content) throws IOException { @@ -120,7 +142,7 @@ private void writeFile(File destination, String content) throws IOException { "}\n" + "\n" + "appmap {\n" + - " configFile = file(\"$projectDir/appmap.yml\")\n" + + " %s" + " outputDirectory = file(\"$projectDir/build/appmap\")\n" + " skip = false\n" + " debug = \"info\"\n" + diff --git a/test/bin/smoketest b/test/bin/smoketest new file mode 100755 index 0000000..0dceb69 --- /dev/null +++ b/test/bin/smoketest @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -ex -o pipefail + +version=$(./gradlew -q clean check publishToMavenLocal -Psnapshot | awk '/^version:/ {print $2}' FS=:) + +cd test/fixture +appmapDir=app/build/appmap +rm -rf $appmapDir +./gradlew -PappmapGradleVersion=$version ${appmapAgentVersion+-PappmapAgentVersion=$appmapAgentVersion} clean appmap test + +appmap=$appmapDir/junit/com_example_AppTest_shouldAnswerWithTrue.appmap.json +test -f $appmap +events=$(jq '.events | length' $appmap) +test $events -eq 4 diff --git a/test/fixture/.gitattributes b/test/fixture/.gitattributes new file mode 100644 index 0000000..097f9f9 --- /dev/null +++ b/test/fixture/.gitattributes @@ -0,0 +1,9 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# Linux start script should use lf +/gradlew text eol=lf + +# These are Windows script files and should use crlf +*.bat text eol=crlf + diff --git a/test/fixture/.gitignore b/test/fixture/.gitignore new file mode 100644 index 0000000..1b6985c --- /dev/null +++ b/test/fixture/.gitignore @@ -0,0 +1,5 @@ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/test/fixture/app/.gitignore b/test/fixture/app/.gitignore new file mode 100644 index 0000000..bdba1df --- /dev/null +++ b/test/fixture/app/.gitignore @@ -0,0 +1,2 @@ +/appmap.yml +/tmp diff --git a/test/fixture/app/build.gradle b/test/fixture/app/build.gradle new file mode 100644 index 0000000..a40b786 --- /dev/null +++ b/test/fixture/app/build.gradle @@ -0,0 +1,39 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This generated file contains a sample Java application project to get you started. + * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle + * User Manual available at https://docs.gradle.org/8.1.1/userguide/building_java_projects.html + */ + +plugins { + // Apply the application plugin to add support for building a CLI application in Java. + id 'application' + id 'com.appland.appmap' version "${appmapGradleVersion}" +} + +repositories { + // Use Maven Central for resolving dependencies. + mavenLocal() + mavenCentral() +} + +dependencies { + // Use JUnit Jupiter for testing. + testImplementation 'junit:junit:4.13.2' + + // This dependency is used by the application. + implementation 'com.google.guava:guava:31.1-jre' +} + +// Apply a specific Java toolchain to ease working on different environments. +java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } +} + +application { + // Define the main class for the application. + mainClass = 'com.example.App' +} diff --git a/test/fixture/app/gradle.properties b/test/fixture/app/gradle.properties new file mode 100644 index 0000000..7f24b1b --- /dev/null +++ b/test/fixture/app/gradle.properties @@ -0,0 +1 @@ +appmapGradleVersion = [1,2) \ No newline at end of file diff --git a/test/fixture/app/src/main/java/com/example/App.java b/test/fixture/app/src/main/java/com/example/App.java new file mode 100644 index 0000000..a87bd57 --- /dev/null +++ b/test/fixture/app/src/main/java/com/example/App.java @@ -0,0 +1,15 @@ +package com.example; + +/** + * Hello world! + * + */ +public class App { + public static void main(String[] args) { + new App().sayHello(); + } + + public void sayHello() { + System.out.println("Hello World!"); + } +} diff --git a/test/fixture/app/src/test/java/com/example/AppTest.java b/test/fixture/app/src/test/java/com/example/AppTest.java new file mode 100644 index 0000000..00eb379 --- /dev/null +++ b/test/fixture/app/src/test/java/com/example/AppTest.java @@ -0,0 +1,18 @@ +package com.example; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest { + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() { + new App().sayHello(); + } +} diff --git a/test/fixture/gradle/wrapper/gradle-wrapper.jar b/test/fixture/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..c1962a7 Binary files /dev/null and b/test/fixture/gradle/wrapper/gradle-wrapper.jar differ diff --git a/test/fixture/gradle/wrapper/gradle-wrapper.properties b/test/fixture/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..37aef8d --- /dev/null +++ b/test/fixture/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/test/fixture/gradlew b/test/fixture/gradlew new file mode 100755 index 0000000..aeb74cb --- /dev/null +++ b/test/fixture/gradlew @@ -0,0 +1,245 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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 POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-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 + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/test/fixture/gradlew.bat b/test/fixture/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/test/fixture/gradlew.bat @@ -0,0 +1,92 @@ +@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 +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +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="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/test/fixture/settings.gradle b/test/fixture/settings.gradle new file mode 100644 index 0000000..45f8cbf --- /dev/null +++ b/test/fixture/settings.gradle @@ -0,0 +1,25 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * The settings file is used to specify which projects to include in your build. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user manual at https://docs.gradle.org/8.1.1/userguide/multi_project_builds.html + */ +pluginManagement { + repositories { + mavenLocal() + mavenCentral() + maven { + url "https://plugins.gradle.org/m2/" + } + } +} + +plugins { + // Apply the foojay-resolver plugin to allow automatic download of JDKs + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' +} + +rootProject.name = 'app' +include('app')