redactUserInfo(String url) {
72 | if (!url.startsWith("http")) {
73 | return Optional.of(url);
74 | }
75 |
76 | try {
77 | URI uri = new URI(url);
78 | URI redactedUri = new URI(
79 | uri.getScheme(),
80 | uri.getUserInfo() == null || uri.getUserInfo().isEmpty() ? null : "******",
81 | uri.getHost(),
82 | uri.getPort(),
83 | uri.getRawPath(),
84 | uri.getRawQuery(),
85 | uri.getRawFragment());
86 | return Optional.of(redactedUri.toString());
87 | } catch (URISyntaxException e) {
88 | return Optional.empty();
89 | }
90 | }
91 |
92 | static Properties readPropertiesFile(String name) {
93 | try (InputStream input = new FileInputStream(name)) {
94 | Properties properties = new Properties();
95 | properties.load(input);
96 | return properties;
97 | } catch (IOException e) {
98 | throw new RuntimeException(e);
99 | }
100 | }
101 |
102 | static boolean execAndCheckSuccess(String... args) {
103 | Runtime runtime = Runtime.getRuntime();
104 | Process process = null;
105 | try {
106 | process = runtime.exec(args);
107 | boolean finished = process.waitFor(10, TimeUnit.SECONDS);
108 | return finished && process.exitValue() == 0;
109 | } catch (IOException | InterruptedException ignored) {
110 | return false;
111 | } finally {
112 | if (process != null) {
113 | process.destroyForcibly();
114 | }
115 | }
116 | }
117 |
118 | static String execAndGetStdOut(String... args) {
119 | Runtime runtime = Runtime.getRuntime();
120 | Process process;
121 | try {
122 | process = runtime.exec(args);
123 | } catch (IOException e) {
124 | throw new RuntimeException(e);
125 | }
126 |
127 | try (Reader standard = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.defaultCharset()))) {
128 | try (Reader error = new BufferedReader(new InputStreamReader(process.getErrorStream(), Charset.defaultCharset()))) {
129 | String standardText = readFully(standard);
130 | String ignore = readFully(error);
131 |
132 | boolean finished = process.waitFor(10, TimeUnit.SECONDS);
133 | return finished && process.exitValue() == 0 ? trimAtEnd(standardText) : null;
134 | }
135 | } catch (IOException | InterruptedException e) {
136 | throw new RuntimeException(e);
137 | } finally {
138 | process.destroyForcibly();
139 | }
140 | }
141 |
142 | /**
143 | * Construct a repo {@link URI} from a git URL in the format of
144 | * git://github.com/acme-inc/my-project.git. If the URL cannot be parsed, {@link Optional#empty()} is
145 | * returned.
146 | *
147 | * The scheme can be any of git://, https://, or ssh.
148 | */
149 | static Optional toWebRepoUri(String gitRepoUri) {
150 | Matcher matcher = GIT_REPO_URI_PATTERN.matcher(gitRepoUri);
151 | if (matcher.matches()) {
152 | String scheme = "https";
153 | String host = matcher.group(1);
154 | String path = matcher.group(2).startsWith("/") ? matcher.group(2) : "/" + matcher.group(2);
155 | return toUri(scheme, host, path);
156 | } else {
157 | return Optional.empty();
158 | }
159 | }
160 |
161 | static Optional toUri(String scheme, String host, String path) {
162 | try {
163 | return Optional.of(new URI(scheme, host, path, null));
164 | } catch (URISyntaxException e) {
165 | return Optional.empty();
166 | }
167 | }
168 |
169 | private static String readFully(Reader reader) throws IOException {
170 | StringBuilder sb = new StringBuilder();
171 | char[] buf = new char[1024];
172 | int nRead;
173 | while ((nRead = reader.read(buf)) != -1) {
174 | sb.append(buf, 0, nRead);
175 | }
176 | return sb.toString();
177 | }
178 |
179 | private static String trimAtEnd(String str) {
180 | return ('x' + str).trim().substring(1);
181 | }
182 |
183 | private Utils() {
184 | }
185 |
186 | }
187 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | <# : batch portion
2 | @REM ----------------------------------------------------------------------------
3 | @REM Licensed to the Apache Software Foundation (ASF) under one
4 | @REM or more contributor license agreements. See the NOTICE file
5 | @REM distributed with this work for additional information
6 | @REM regarding copyright ownership. The ASF licenses this file
7 | @REM to you under the Apache License, Version 2.0 (the
8 | @REM "License"); you may not use this file except in compliance
9 | @REM with the License. You may obtain a copy of the License at
10 | @REM
11 | @REM http://www.apache.org/licenses/LICENSE-2.0
12 | @REM
13 | @REM Unless required by applicable law or agreed to in writing,
14 | @REM software distributed under the License is distributed on an
15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | @REM KIND, either express or implied. See the License for the
17 | @REM specific language governing permissions and limitations
18 | @REM under the License.
19 | @REM ----------------------------------------------------------------------------
20 |
21 | @REM ----------------------------------------------------------------------------
22 | @REM Apache Maven Wrapper startup batch script, version 3.3.4
23 | @REM
24 | @REM Optional ENV vars
25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution
26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
28 | @REM ----------------------------------------------------------------------------
29 |
30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
31 | @SET __MVNW_CMD__=
32 | @SET __MVNW_ERROR__=
33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
34 | @SET PSModulePath=
35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
37 | )
38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
39 | @SET __MVNW_PSMODULEP_SAVE=
40 | @SET __MVNW_ARG0_NAME__=
41 | @SET MVNW_USERNAME=
42 | @SET MVNW_PASSWORD=
43 | @IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*)
44 | @echo Cannot start maven from wrapper >&2 && exit /b 1
45 | @GOTO :EOF
46 | : end batch / begin powershell #>
47 |
48 | $ErrorActionPreference = "Stop"
49 | if ($env:MVNW_VERBOSE -eq "true") {
50 | $VerbosePreference = "Continue"
51 | }
52 |
53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
55 | if (!$distributionUrl) {
56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
57 | }
58 |
59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
60 | "maven-mvnd-*" {
61 | $USE_MVND = $true
62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
63 | $MVN_CMD = "mvnd.cmd"
64 | break
65 | }
66 | default {
67 | $USE_MVND = $false
68 | $MVN_CMD = $script -replace '^mvnw','mvn'
69 | break
70 | }
71 | }
72 |
73 | # apply MVNW_REPOURL and calculate MAVEN_HOME
74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
75 | if ($env:MVNW_REPOURL) {
76 | $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" }
77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')"
78 | }
79 | $distributionUrlName = $distributionUrl -replace '^.*/',''
80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
81 |
82 | $MAVEN_M2_PATH = "$HOME/.m2"
83 | if ($env:MAVEN_USER_HOME) {
84 | $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME"
85 | }
86 |
87 | if (-not (Test-Path -Path $MAVEN_M2_PATH)) {
88 | New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null
89 | }
90 |
91 | $MAVEN_WRAPPER_DISTS = $null
92 | if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) {
93 | $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
94 | } else {
95 | $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
96 | }
97 |
98 | $MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"
99 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
100 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
101 |
102 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
103 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
104 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
105 | exit $?
106 | }
107 |
108 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
109 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
110 | }
111 |
112 | # prepare tmp dir
113 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
114 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
115 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
116 | trap {
117 | if ($TMP_DOWNLOAD_DIR.Exists) {
118 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
119 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
120 | }
121 | }
122 |
123 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
124 |
125 | # Download and Install Apache Maven
126 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
127 | Write-Verbose "Downloading from: $distributionUrl"
128 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
129 |
130 | $webclient = New-Object System.Net.WebClient
131 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
132 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
133 | }
134 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
135 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
136 |
137 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
138 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
139 | if ($distributionSha256Sum) {
140 | if ($USE_MVND) {
141 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
142 | }
143 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
144 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
145 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
146 | }
147 | }
148 |
149 | # unzip and move
150 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
151 |
152 | # Find the actual extracted directory name (handles snapshots where filename != directory name)
153 | $actualDistributionDir = ""
154 |
155 | # First try the expected directory name (for regular distributions)
156 | $expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain"
157 | $expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD"
158 | if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) {
159 | $actualDistributionDir = $distributionUrlNameMain
160 | }
161 |
162 | # If not found, search for any directory with the Maven executable (for snapshots)
163 | if (!$actualDistributionDir) {
164 | Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object {
165 | $testPath = Join-Path $_.FullName "bin/$MVN_CMD"
166 | if (Test-Path -Path $testPath -PathType Leaf) {
167 | $actualDistributionDir = $_.Name
168 | }
169 | }
170 | }
171 |
172 | if (!$actualDistributionDir) {
173 | Write-Error "Could not find Maven distribution directory in extracted archive"
174 | }
175 |
176 | Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir"
177 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null
178 | try {
179 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
180 | } catch {
181 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
182 | Write-Error "fail to move MAVEN_HOME"
183 | }
184 | } finally {
185 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
186 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
187 | }
188 |
189 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
190 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | > _This repository is maintained by the Develocity Solutions team, as one of several publicly available repositories:_
2 | > - _[Android Cache Fix Gradle Plugin][android-cache-fix-plugin]_
3 | > - _[Common Custom User Data Gradle Plugin][ccud-gradle-plugin]_
4 | > - _[Common Custom User Data Maven Extension][ccud-maven-extension] (this repository)_
5 | > - _[Develocity Build Configuration Samples][develocity-build-config-samples]_
6 | > - _[Develocity Build Validation Scripts][develocity-build-validation-scripts]_
7 | > - _[Develocity Open Source Projects][develocity-oss-projects]_
8 | > - _[Quarkus Build Caching Extension][quarkus-build-caching-extension]_
9 |
10 | # Common Custom User Data Maven Extension
11 |
12 | [](https://github.com/gradle/common-custom-user-data-maven-extension/actions/workflows/build-verification.yml)
13 | [](https://search.maven.org/artifact/com.gradle/common-custom-user-data-maven-extension)
14 | [](https://ge.solutions-team.gradle.com/scans)
15 |
16 | The Common Custom User Data Maven extension for Develocity enhances published build scans
17 | by adding a set of tags, links and custom values that have proven to be useful for many projects building with Develocity.
18 |
19 | You can leverage this extension for your project in one of two ways:
20 | 1. [Apply the published extension](#applying-the-published-extension) directly in your `.mvn/extensions.xml` and immediately benefit from enhanced build scans
21 | 2. Copy this repository and [develop a customized version of the extension](#developing-a-customized-version-of-the-extension) to standardize Develocity usage across multiple projects
22 |
23 | ## Applying the published extension
24 |
25 | The Common Custom User Data Maven extension is available in [Maven Central](https://search.maven.org/artifact/com.gradle/common-custom-user-data-maven-extension). This extension
26 | requires the [Develocity Maven extension](https://search.maven.org/artifact/com.gradle/develocity-maven-extension) to also be applied in your build in order to have
27 | an effect.
28 |
29 | In order for the Common Custom User Data Maven extension to become active, you need to register it in the `.mvn/extensions.xml` file in your root project. The `extensions.xml` file
30 | is the same file where you have already declared the Develocity Maven extension.
31 |
32 | See [here](.mvn/extensions.xml) for an example.
33 |
34 | ### Version compatibility
35 |
36 | This table details the version compatibility of the Common Custom User Data Maven extension with the Develocity Maven extension.
37 |
38 | | Common Custom User Data Maven extension versions | Develocity Maven extension versions |
39 | | ------------------------------------------------ | ------------------------------------------ |
40 | | `1.8+` | `1.11+` |
41 | | `1.7` - `1.7.3` | `1.10.1+` |
42 | | `1.3` - `1.6` | `1.6.5+` |
43 | | `1.0` - `1.2` | `1.0+` |
44 |
45 | The above chart captures the minimum compatible versions. For the best experience with the Develocity Maven extension 1.21 or higher, we recommend using the Common Custom User Data Maven extension 2.0 or higher.
46 |
47 | ## Captured data
48 |
49 | The additional tags, links and custom values captured by this extension include:
50 | - A tag representing the operating system
51 | - A tag representing how the build was invoked, be that from your IDE (IDEA, Eclipse) or from the command-line
52 | - A tag representing builds run on CI, together with a set of tags, links and custom values specific to the CI server running the build
53 | - For Git repositories, information on the commit id, branch name, status, and whether the checkout is dirty or not
54 |
55 | See [CustomBuildScanEnhancements.java](./src/main/java/com/gradle/CustomBuildScanEnhancements.java) for details on what data is
56 | captured and under which conditions.
57 |
58 | ## Capturing additional tags, links and values in your build scans
59 |
60 | You can apply additional configuration beyond what is contributed by the Common Custom User Data Maven extension by default.
61 | The extension evaluates Groovy scripts from two locations:
62 |
63 | 1. Any `*.groovy` files in the `custom-user-data` directory, located within the [Develocity storage directory](https://docs.gradle.com/develocity/maven/current/maven-extension/#anatomy-of-the-develocity-directory), `${user.home}/.m2/.develocity` by default
64 | 2. A `.mvn/develocity-custom-user-data.groovy` or `.mvn/gradle-enterprise-custom-user-data.groovy` in your root project
65 |
66 | All matching files are evaluated with the following bindings:
67 |
68 | - `develocity/gradleEnterprise` (type: [DevelocityAdapter](https://github.com/gradle/develocity-agent-adapters/blob/main/develocity-maven-extension-adapters/src/compatibilityApi/java/com/gradle/develocity/agent/maven/adapters/DevelocityAdapter.java)): _configure Develocity_
69 | - `buildScan` (type: [BuildScanApiAdapter](https://github.com/gradle/develocity-agent-adapters/blob/main/develocity-maven-extension-adapters/src/compatibilityApi/java/com/gradle/develocity/agent/maven/adapters/BuildScanApiAdapter.java)): _configure build scan publishing and enhance build scans_
70 | - `buildCache` (type: [BuildCacheApiAdapter](https://github.com/gradle/develocity-agent-adapters/blob/main/develocity-maven-extension-adapters/src/compatibilityApi/java/com/gradle/develocity/agent/maven/adapters/BuildCacheApiAdapter.java)): _configure build cache_
71 | - `log` (type: [`Logger`](http://www.slf4j.org/apidocs/org/slf4j/Logger.html)): _write to the build log_
72 | - `project` (type: [`MavenProject`](https://maven.apache.org/ref/current/maven-core/apidocs/org/apache/maven/project/MavenProject.html)): _the top-level Maven project_
73 | - `session` (type: [`MavenSession`](https://maven.apache.org/ref/current/maven-core/apidocs/org/apache/maven/execution/MavenSession.html)): _the Maven session_
74 |
75 | The Groovy scripts are evaluated in the exact order listed above, with the scripts in the `custom-user-data` directory being executed in alphabetical order.
76 |
77 | See [here](.mvn/develocity-custom-user-data.groovy) for an example.
78 |
79 | ## Developing a customized version of the extension
80 |
81 | For more flexibility, we recommend creating a copy of this repository so that you may develop a customized version of the extension and publish it internally for your projects to consume.
82 |
83 | This approach has a number of benefits:
84 | - Tailor the build scan enhancements to exactly the set of tags, links and custom values you require
85 | - Standardize the configuration for connecting to Develocity and the remote build cache in your organization, removing the need for each project to specify this configuration
86 |
87 | If your customized extension provides all required Develocity configuration, then a consumer project will get all the benefits of Develocity simply by applying the extension. The
88 | project sources provide a good template to get started with your own extension.
89 |
90 | Refer to the [Javadoc](https://docs.gradle.com/enterprise/maven-extension/api/) for more details on the key types available for use.
91 |
92 | ## Changelog
93 |
94 | Refer to the [release history](https://github.com/gradle/common-custom-user-data-maven-extension/releases) to see detailed changes on the versions.
95 |
96 | ## Breaking API changes
97 |
98 | When updating to the Common Custom User Data Maven extension 2.0, please take care of the following.
99 |
100 | 1. Rename the `.mvn/gradle-enterprise-custom-user-data.groovy` to `.mvn/develocity-custom-user-data.groovy`.
101 | 2. Use `BuildScanApiAdapter` instead of `BuildScanApi`. See the example below:
102 |
103 | `gradle-enterprise-custom-user-data.groovy`
104 | ```
105 | import com.gradle.maven.extension.api.scan.BuildScanApi
106 |
107 | buildScan.executeOnce('top-level-project') { BuildScanApi buildScanApi -> }
108 | ```
109 | `develocity-custom-user-data.groovy`
110 | ```
111 | import com.gradle.develocity.agent.maven.adapters.BuildScanApiAdapter
112 |
113 | buildScan.executeOnce('top-level-project') { BuildScanApiAdapter buildScanApi -> }
114 | ```
115 |
116 | ## Learn more
117 |
118 | Visit our website to learn more about [Develocity][develocity].
119 |
120 | ## License
121 |
122 | The Develocity Common Custom User Data Maven extension is open-source software released under the [Apache 2.0 License][apache-license].
123 |
124 | [android-cache-fix-plugin]: https://github.com/gradle/android-cache-fix-gradle-plugin
125 | [ccud-gradle-plugin]: https://github.com/gradle/common-custom-user-data-gradle-plugin
126 | [ccud-maven-extension]: https://github.com/gradle/common-custom-user-data-maven-extension
127 | [develocity-build-config-samples]: https://github.com/gradle/develocity-build-config-samples
128 | [develocity-build-validation-scripts]: https://github.com/gradle/develocity-build-validation-scripts
129 | [develocity-oss-projects]: https://github.com/gradle/develocity-oss-projects
130 | [quarkus-build-caching-extension]: https://github.com/gradle/quarkus-build-caching-extension
131 | [develocity]: https://gradle.com/develocity
132 | [apache-license]: https://www.apache.org/licenses/LICENSE-2.0.html
133 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | com.gradle
5 | common-custom-user-data-maven-extension
6 | 2.1.1-SNAPSHOT
7 | jar
8 |
9 | Develocity Common Custom User Data Maven Extension
10 | A Maven extension to capture common custom user data used for Maven Build Scans in Develocity
11 | https://github.com/gradle/common-custom-user-data-maven-extension
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 | scm:git:https://github.com/gradle/common-custom-user-data-maven-extension.git
19 | https://github.com/gradle/common-custom-user-data-maven-extension
20 | HEAD
21 |
22 |
23 |
24 |
25 | Apache-2.0
26 | https://www.apache.org/licenses/LICENSE-2.0.txt
27 |
28 |
29 |
30 |
31 |
32 | Documentation
33 | https://docs.gradle.com
34 |
35 |
36 |
37 |
38 |
39 | The Gradle team
40 | Gradle Inc.
41 | https://gradle.com
42 |
43 |
44 |
45 |
46 |
47 | org.apache.maven
48 | maven-core
49 | 3.9.12
50 | provided
51 |
52 |
53 |
54 | com.gradle
55 | gradle-enterprise-maven-extension
56 | 1.20.1
57 | provided
58 |
59 |
60 |
61 | com.gradle
62 | develocity-maven-extension
63 | 2.3
64 | provided
65 |
66 |
67 | com.gradle
68 | develocity-maven-extension-adapters
69 | 1.0
70 |
71 |
72 | org.apache.groovy
73 | groovy
74 | 4.0.29
75 |
76 |
77 | org.apache.ivy
78 | ivy
79 | 2.5.3
80 |
81 |
82 | org.junit.jupiter
83 | junit-jupiter
84 | 6.0.1
85 | test
86 |
87 |
88 |
89 |
90 |
91 |
92 | org.apache.maven.plugins
93 | maven-compiler-plugin
94 | 3.14.1
95 |
96 | 8
97 |
98 |
99 | org.eclipse.sisu
100 | org.eclipse.sisu.inject
101 | 0.3.5
102 |
103 |
104 |
105 |
106 |
107 | org.apache.maven.plugins
108 | maven-surefire-plugin
109 | 3.5.4
110 |
111 |
112 | org.apache.maven.plugins
113 | maven-shade-plugin
114 | 3.6.1
115 |
116 |
117 |
118 | com.gradle:develocity-maven-extension-adapters
119 |
120 | META-INF/MANIFEST.MF
121 |
122 |
123 |
124 | org.codehaus.groovy:groovy
125 |
126 | META-INF/LICENSE
127 | META-INF/MANIFEST.MF
128 | META-INF/NOTICE
129 |
130 |
131 |
132 | org.apache.ivy:ivy
133 |
134 | META-INF/LICENSE
135 | META-INF/MANIFEST.MF
136 | META-INF/NOTICE
137 |
138 |
139 |
140 |
141 |
142 |
143 | package
144 |
145 | shade
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 | ${project.basedir}/src/main/resources
154 |
155 |
156 | ${project.basedir}/release/distribution
157 |
158 |
159 | ${project.basedir}
160 |
161 | LICENSE
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 | release
170 |
171 |
172 |
173 | org.apache.maven.plugins
174 | maven-release-plugin
175 | 3.3.1
176 |
177 | -Dscan=false
178 |
179 |
180 |
181 | org.apache.maven.plugins
182 | maven-source-plugin
183 | 3.4.0
184 |
185 |
186 | attach-sources
187 |
188 | jar-no-fork
189 |
190 |
191 |
192 |
193 |
194 | org.apache.maven.plugins
195 | maven-javadoc-plugin
196 | 3.12.0
197 |
198 |
199 | attach-javadocs
200 |
201 | jar
202 |
203 |
204 |
205 |
206 | 8
207 |
208 |
209 |
210 | org.apache.maven.plugins
211 | maven-site-plugin
212 | 3.21.0
213 |
214 | true
215 | true
216 |
217 |
218 |
219 | org.simplify4u.plugins
220 | sign-maven-plugin
221 | 1.1.0
222 |
223 |
224 | sign
225 |
226 | sign
227 |
228 |
229 |
230 |
231 | false
232 |
233 |
234 |
235 | org.sonatype.central
236 | central-publishing-maven-plugin
237 | 0.9.0
238 | true
239 |
240 | ossrh
241 | true
242 | published
243 | Common Custom User Data Maven Extension
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2024 Gradle Inc.
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Apache Maven Wrapper startup batch script, version 3.3.4
23 | #
24 | # Optional ENV vars
25 | # -----------------
26 | # JAVA_HOME - location of a JDK home dir, required when download maven via java source
27 | # MVNW_REPOURL - repo url base for downloading maven distribution
28 | # MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
29 | # MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
30 | # ----------------------------------------------------------------------------
31 |
32 | set -euf
33 | [ "${MVNW_VERBOSE-}" != debug ] || set -x
34 |
35 | # OS specific support.
36 | native_path() { printf %s\\n "$1"; }
37 | case "$(uname)" in
38 | CYGWIN* | MINGW*)
39 | [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
40 | native_path() { cygpath --path --windows "$1"; }
41 | ;;
42 | esac
43 |
44 | # set JAVACMD and JAVACCMD
45 | set_java_home() {
46 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
47 | if [ -n "${JAVA_HOME-}" ]; then
48 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then
49 | # IBM's JDK on AIX uses strange locations for the executables
50 | JAVACMD="$JAVA_HOME/jre/sh/java"
51 | JAVACCMD="$JAVA_HOME/jre/sh/javac"
52 | else
53 | JAVACMD="$JAVA_HOME/bin/java"
54 | JAVACCMD="$JAVA_HOME/bin/javac"
55 |
56 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
57 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
58 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
59 | return 1
60 | fi
61 | fi
62 | else
63 | JAVACMD="$(
64 | 'set' +e
65 | 'unset' -f command 2>/dev/null
66 | 'command' -v java
67 | )" || :
68 | JAVACCMD="$(
69 | 'set' +e
70 | 'unset' -f command 2>/dev/null
71 | 'command' -v javac
72 | )" || :
73 |
74 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
75 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
76 | return 1
77 | fi
78 | fi
79 | }
80 |
81 | # hash string like Java String::hashCode
82 | hash_string() {
83 | str="${1:-}" h=0
84 | while [ -n "$str" ]; do
85 | char="${str%"${str#?}"}"
86 | h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
87 | str="${str#?}"
88 | done
89 | printf %x\\n $h
90 | }
91 |
92 | verbose() { :; }
93 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
94 |
95 | die() {
96 | printf %s\\n "$1" >&2
97 | exit 1
98 | }
99 |
100 | trim() {
101 | # MWRAPPER-139:
102 | # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
103 | # Needed for removing poorly interpreted newline sequences when running in more
104 | # exotic environments such as mingw bash on Windows.
105 | printf "%s" "${1}" | tr -d '[:space:]'
106 | }
107 |
108 | scriptDir="$(dirname "$0")"
109 | scriptName="$(basename "$0")"
110 |
111 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
112 | while IFS="=" read -r key value; do
113 | case "${key-}" in
114 | distributionUrl) distributionUrl=$(trim "${value-}") ;;
115 | distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
116 | esac
117 | done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties"
118 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
119 |
120 | case "${distributionUrl##*/}" in
121 | maven-mvnd-*bin.*)
122 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
123 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
124 | *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
125 | :Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
126 | :Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
127 | :Linux*x86_64*) distributionPlatform=linux-amd64 ;;
128 | *)
129 | echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
130 | distributionPlatform=linux-amd64
131 | ;;
132 | esac
133 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
134 | ;;
135 | maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
136 | *) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
137 | esac
138 |
139 | # apply MVNW_REPOURL and calculate MAVEN_HOME
140 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
141 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
142 | distributionUrlName="${distributionUrl##*/}"
143 | distributionUrlNameMain="${distributionUrlName%.*}"
144 | distributionUrlNameMain="${distributionUrlNameMain%-bin}"
145 | MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
146 | MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
147 |
148 | exec_maven() {
149 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
150 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
151 | }
152 |
153 | if [ -d "$MAVEN_HOME" ]; then
154 | verbose "found existing MAVEN_HOME at $MAVEN_HOME"
155 | exec_maven "$@"
156 | fi
157 |
158 | case "${distributionUrl-}" in
159 | *?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
160 | *) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
161 | esac
162 |
163 | # prepare tmp dir
164 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
165 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
166 | trap clean HUP INT TERM EXIT
167 | else
168 | die "cannot create temp dir"
169 | fi
170 |
171 | mkdir -p -- "${MAVEN_HOME%/*}"
172 |
173 | # Download and Install Apache Maven
174 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
175 | verbose "Downloading from: $distributionUrl"
176 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
177 |
178 | # select .zip or .tar.gz
179 | if ! command -v unzip >/dev/null; then
180 | distributionUrl="${distributionUrl%.zip}.tar.gz"
181 | distributionUrlName="${distributionUrl##*/}"
182 | fi
183 |
184 | # verbose opt
185 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
186 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
187 |
188 | # normalize http auth
189 | case "${MVNW_PASSWORD:+has-password}" in
190 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
191 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
192 | esac
193 |
194 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
195 | verbose "Found wget ... using wget"
196 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
197 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
198 | verbose "Found curl ... using curl"
199 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
200 | elif set_java_home; then
201 | verbose "Falling back to use Java to download"
202 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
203 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
204 | cat >"$javaSource" <<-END
205 | public class Downloader extends java.net.Authenticator
206 | {
207 | protected java.net.PasswordAuthentication getPasswordAuthentication()
208 | {
209 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
210 | }
211 | public static void main( String[] args ) throws Exception
212 | {
213 | setDefault( new Downloader() );
214 | java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
215 | }
216 | }
217 | END
218 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java
219 | verbose " - Compiling Downloader.java ..."
220 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
221 | verbose " - Running Downloader.java ..."
222 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
223 | fi
224 |
225 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
226 | if [ -n "${distributionSha256Sum-}" ]; then
227 | distributionSha256Result=false
228 | if [ "$MVN_CMD" = mvnd.sh ]; then
229 | echo "Checksum validation is not supported for maven-mvnd." >&2
230 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
231 | exit 1
232 | elif command -v sha256sum >/dev/null; then
233 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then
234 | distributionSha256Result=true
235 | fi
236 | elif command -v shasum >/dev/null; then
237 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
238 | distributionSha256Result=true
239 | fi
240 | else
241 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
242 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
243 | exit 1
244 | fi
245 | if [ $distributionSha256Result = false ]; then
246 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
247 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
248 | exit 1
249 | fi
250 | fi
251 |
252 | # unzip and move
253 | if command -v unzip >/dev/null; then
254 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
255 | else
256 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
257 | fi
258 |
259 | # Find the actual extracted directory name (handles snapshots where filename != directory name)
260 | actualDistributionDir=""
261 |
262 | # First try the expected directory name (for regular distributions)
263 | if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then
264 | if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then
265 | actualDistributionDir="$distributionUrlNameMain"
266 | fi
267 | fi
268 |
269 | # If not found, search for any directory with the Maven executable (for snapshots)
270 | if [ -z "$actualDistributionDir" ]; then
271 | # enable globbing to iterate over items
272 | set +f
273 | for dir in "$TMP_DOWNLOAD_DIR"/*; do
274 | if [ -d "$dir" ]; then
275 | if [ -f "$dir/bin/$MVN_CMD" ]; then
276 | actualDistributionDir="$(basename "$dir")"
277 | break
278 | fi
279 | fi
280 | done
281 | set -f
282 | fi
283 |
284 | if [ -z "$actualDistributionDir" ]; then
285 | verbose "Contents of $TMP_DOWNLOAD_DIR:"
286 | verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
287 | die "Could not find Maven distribution directory in extracted archive"
288 | fi
289 |
290 | verbose "Found extracted Maven distribution directory: $actualDistributionDir"
291 | printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url"
292 | mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
293 |
294 | clean || :
295 | exec_maven "$@"
296 |
--------------------------------------------------------------------------------
/src/main/java/com/gradle/CustomBuildScanEnhancements.java:
--------------------------------------------------------------------------------
1 | package com.gradle;
2 |
3 | import com.gradle.develocity.agent.maven.adapters.BuildScanApiAdapter;
4 | import org.apache.maven.execution.MavenSession;
5 |
6 | import java.net.URI;
7 | import java.util.AbstractMap;
8 | import java.util.Arrays;
9 | import java.util.Comparator;
10 | import java.util.HashMap;
11 | import java.util.LinkedHashMap;
12 | import java.util.Map;
13 | import java.util.Optional;
14 | import java.util.Properties;
15 | import java.util.function.Consumer;
16 | import java.util.function.Function;
17 | import java.util.function.Supplier;
18 | import java.util.stream.Stream;
19 |
20 | import static com.gradle.CiUtils.isAzurePipelines;
21 | import static com.gradle.CiUtils.isBamboo;
22 | import static com.gradle.CiUtils.isBitrise;
23 | import static com.gradle.CiUtils.isBuildkite;
24 | import static com.gradle.CiUtils.isCi;
25 | import static com.gradle.CiUtils.isCircleCI;
26 | import static com.gradle.CiUtils.isGitHubActions;
27 | import static com.gradle.CiUtils.isGitLab;
28 | import static com.gradle.CiUtils.isGoCD;
29 | import static com.gradle.CiUtils.isHudson;
30 | import static com.gradle.CiUtils.isJenkins;
31 | import static com.gradle.CiUtils.isTeamCity;
32 | import static com.gradle.CiUtils.isTravis;
33 | import static com.gradle.Utils.appendIfMissing;
34 | import static com.gradle.Utils.envVariable;
35 | import static com.gradle.Utils.execAndCheckSuccess;
36 | import static com.gradle.Utils.execAndGetStdOut;
37 | import static com.gradle.Utils.isNotEmpty;
38 | import static com.gradle.Utils.projectProperty;
39 | import static com.gradle.Utils.readPropertiesFile;
40 | import static com.gradle.Utils.redactUserInfo;
41 | import static com.gradle.Utils.sysProperty;
42 | import static com.gradle.Utils.toWebRepoUri;
43 | import static com.gradle.Utils.urlEncode;
44 |
45 | /**
46 | * Adds a standard set of useful tags, links and custom values to all build scans published.
47 | */
48 | final class CustomBuildScanEnhancements {
49 |
50 | private static final String SYSTEM_PROP_IDEA_VENDOR_NAME = "idea.vendor.name";
51 | private static final String SYSTEM_PROP_IDEA_VERSION = "idea.version";
52 | private static final String SYSTEM_PROP_ECLIPSE_BUILD_ID = "eclipse.buildId";
53 | private static final String SYSTEM_PROP_IDEA_SYNC_ACTIVE = "idea.sync.active";
54 | private static final String ENV_VAR_VSCODE_PID = "VSCODE_PID";
55 | private static final String ENV_VAR_VSCODE_INJECTION = "VSCODE_INJECTION";
56 |
57 | private final BuildScanApiAdapter buildScan;
58 | private final MavenSession mavenSession;
59 |
60 | CustomBuildScanEnhancements(BuildScanApiAdapter buildScan, MavenSession mavenSession) {
61 | this.buildScan = buildScan;
62 | this.mavenSession = mavenSession;
63 | }
64 |
65 | void apply() {
66 | captureOs();
67 | captureIde();
68 | captureCiOrLocal();
69 | captureCiMetadata();
70 | captureGitMetadata();
71 | captureSkipTestsFlags();
72 | }
73 |
74 | private void captureOs() {
75 | sysProperty("os.name").ifPresent(buildScan::tag);
76 | }
77 |
78 | private void captureIde() {
79 | if (!isCi()) {
80 | Map> ideProperties = new HashMap<>();
81 | ideProperties.put(SYSTEM_PROP_IDEA_VENDOR_NAME, sysProperty(SYSTEM_PROP_IDEA_VENDOR_NAME));
82 | ideProperties.put(SYSTEM_PROP_IDEA_VERSION, sysProperty(SYSTEM_PROP_IDEA_VERSION));
83 | ideProperties.put(SYSTEM_PROP_ECLIPSE_BUILD_ID, sysProperty(SYSTEM_PROP_ECLIPSE_BUILD_ID));
84 | ideProperties.put(SYSTEM_PROP_IDEA_SYNC_ACTIVE, sysProperty(SYSTEM_PROP_IDEA_SYNC_ACTIVE));
85 | ideProperties.put(ENV_VAR_VSCODE_PID, envVariable(ENV_VAR_VSCODE_PID));
86 | ideProperties.put(ENV_VAR_VSCODE_INJECTION, envVariable(ENV_VAR_VSCODE_INJECTION));
87 |
88 | new CaptureIdeMetadataAction(buildScan, ideProperties).execute();
89 | }
90 | }
91 |
92 | private static final class CaptureIdeMetadataAction {
93 |
94 | private final BuildScanApiAdapter buildScan;
95 | private final Map> props;
96 |
97 | private CaptureIdeMetadataAction(BuildScanApiAdapter buildScan, Map> props) {
98 | this.buildScan = buildScan;
99 | this.props = props;
100 | }
101 |
102 | private void execute() {
103 | if (props.get(SYSTEM_PROP_IDEA_VENDOR_NAME).isPresent()) {
104 | String ideaVendorNameValue = props.get(SYSTEM_PROP_IDEA_VENDOR_NAME).get();
105 | if ("JetBrains".equals(ideaVendorNameValue)) {
106 | tagIde("IntelliJ IDEA", props.get(SYSTEM_PROP_IDEA_VERSION).orElse(""));
107 | }
108 | } else if (props.get(SYSTEM_PROP_IDEA_VERSION).isPresent()) {
109 | // this case should be handled by the ideaVendorName condition but keeping it for compatibility reason (ideaVendorName started with 2020.1)
110 | tagIde("IntelliJ IDEA", props.get(SYSTEM_PROP_IDEA_VERSION).get());
111 | } else if (props.get(SYSTEM_PROP_ECLIPSE_BUILD_ID).isPresent()) {
112 | tagIde("Eclipse", props.get(SYSTEM_PROP_ECLIPSE_BUILD_ID).get());
113 | } else if (props.get(ENV_VAR_VSCODE_PID).isPresent() || props.get(ENV_VAR_VSCODE_INJECTION).isPresent()) {
114 | tagIde("VS Code", "");
115 | } else {
116 | buildScan.tag("Cmd Line");
117 | }
118 |
119 | if (props.get(SYSTEM_PROP_IDEA_SYNC_ACTIVE).isPresent()) {
120 | buildScan.tag("IDE sync");
121 | }
122 | }
123 |
124 | private void tagIde(String ideLabel, String version) {
125 | buildScan.tag(ideLabel);
126 | if (!version.isEmpty()) {
127 | buildScan.value(ideLabel + " version", version);
128 | }
129 | }
130 |
131 | }
132 |
133 | private void captureCiOrLocal() {
134 | buildScan.tag(isCi() ? "CI" : "LOCAL");
135 | }
136 |
137 | private void captureCiMetadata() {
138 | if (isCi()) {
139 | new CaptureCiMetadataAction(buildScan).execute();
140 | }
141 | }
142 |
143 | private static final class CaptureCiMetadataAction {
144 | private final BuildScanApiAdapter buildScan;
145 |
146 | public CaptureCiMetadataAction(BuildScanApiAdapter buildScan) {
147 | this.buildScan = buildScan;
148 | }
149 |
150 | private void execute() {
151 | if (isJenkins() || isHudson()) {
152 | String ciProvider = isJenkins() ? "Jenkins" : "Hudson";
153 | String controllerUrlEnvVar = isJenkins() ? "JENKINS_URL" : "HUDSON_URL";
154 |
155 | Optional buildUrl = envVariable("BUILD_URL");
156 | Optional buildNumber = envVariable("BUILD_NUMBER");
157 | Optional nodeName = envVariable("NODE_NAME");
158 | Optional jobName = envVariable("JOB_NAME");
159 | Optional stageName = envVariable("STAGE_NAME");
160 | Optional controllerUrl = envVariable(controllerUrlEnvVar);
161 |
162 | buildScan.value("CI provider", ciProvider);
163 | buildUrl.ifPresent(url ->
164 | buildScan.link(isJenkins() ? "Jenkins build" : "Hudson build", url));
165 | buildNumber.ifPresent(value ->
166 | buildScan.value("CI build number", value));
167 | nodeName.ifPresent(value ->
168 | addCustomValueAndSearchLink(buildScan, "CI node", value));
169 | jobName.ifPresent(value ->
170 | addCustomValueAndSearchLink(buildScan, "CI job", value));
171 | stageName.ifPresent(value ->
172 | addCustomValueAndSearchLink(buildScan, "CI stage", value));
173 | controllerUrl.ifPresent(value ->
174 | buildScan.value("CI controller", value));
175 |
176 | jobName.ifPresent(j -> buildNumber.ifPresent(b -> {
177 | Map params = new LinkedHashMap<>();
178 | params.put("CI job", j);
179 | params.put("CI build number", b);
180 | addSearchLink(buildScan, "CI pipeline", params);
181 | }));
182 | }
183 |
184 | if (isTeamCity()) {
185 | buildScan.value("CI provider", "TeamCity");
186 | Optional teamcityBuildPropertiesFile = envVariable("TEAMCITY_BUILD_PROPERTIES_FILE");
187 | if (teamcityBuildPropertiesFile.isPresent()) {
188 | Properties buildProperties = readPropertiesFile(teamcityBuildPropertiesFile.get());
189 |
190 | String teamCityBuildId = buildProperties.getProperty("teamcity.build.id");
191 | if (isNotEmpty(teamCityBuildId)) {
192 | String teamcityConfigFile = buildProperties.getProperty("teamcity.configuration.properties.file");
193 | if (isNotEmpty(teamcityConfigFile)) {
194 | Properties configProperties = readPropertiesFile(teamcityConfigFile);
195 |
196 | String teamCityServerUrl = configProperties.getProperty("teamcity.serverUrl");
197 | if (isNotEmpty(teamCityServerUrl)) {
198 | String buildUrl = appendIfMissing(teamCityServerUrl, "/") + "viewLog.html?buildId=" + urlEncode(teamCityBuildId);
199 | buildScan.link("TeamCity build", buildUrl);
200 | }
201 | }
202 | }
203 |
204 | String teamCityBuildNumber = buildProperties.getProperty("build.number");
205 | if (isNotEmpty(teamCityBuildNumber)) {
206 | buildScan.value("CI build number", teamCityBuildNumber);
207 | }
208 | String teamCityBuildTypeId = buildProperties.getProperty("teamcity.buildType.id");
209 | if (isNotEmpty(teamCityBuildTypeId)) {
210 | addCustomValueAndSearchLink(buildScan, "CI build config", teamCityBuildTypeId);
211 | }
212 | String teamCityAgentName = buildProperties.getProperty("agent.name");
213 | if (isNotEmpty(teamCityAgentName)) {
214 | addCustomValueAndSearchLink(buildScan, "CI agent", teamCityAgentName);
215 | }
216 | }
217 | }
218 |
219 | if (isCircleCI()) {
220 | buildScan.value("CI provider", "CircleCI");
221 | envVariable("CIRCLE_BUILD_URL").ifPresent(url ->
222 | buildScan.link("CircleCI build", url));
223 | envVariable("CIRCLE_BUILD_NUM").ifPresent(value ->
224 | buildScan.value("CI build number", value));
225 | envVariable("CIRCLE_JOB").ifPresent(value ->
226 | addCustomValueAndSearchLink(buildScan, "CI job", value));
227 | envVariable("CIRCLE_WORKFLOW_ID").ifPresent(value ->
228 | addCustomValueAndSearchLink(buildScan, "CI workflow", value));
229 | }
230 |
231 | if (isBamboo()) {
232 | buildScan.value("CI provider", "Bamboo");
233 | envVariable("bamboo_resultsUrl").ifPresent(url ->
234 | buildScan.link("Bamboo build", url));
235 | envVariable("bamboo_buildNumber").ifPresent(value ->
236 | buildScan.value("CI build number", value));
237 | envVariable("bamboo_planName").ifPresent(value ->
238 | addCustomValueAndSearchLink(buildScan, "CI plan", value));
239 | envVariable("bamboo_buildPlanName").ifPresent(value ->
240 | addCustomValueAndSearchLink(buildScan, "CI build plan", value));
241 | envVariable("bamboo_agentId").ifPresent(value ->
242 | addCustomValueAndSearchLink(buildScan, "CI agent", value));
243 | }
244 |
245 | if (isGitHubActions()) {
246 | buildScan.value("CI provider", "GitHub Actions");
247 |
248 | Optional workflow = envVariable("GITHUB_WORKFLOW");
249 | Optional jobId = envVariable("GITHUB_JOB");
250 | Optional actionNameOrStepId = envVariable("GITHUB_ACTION");
251 | Optional runId = envVariable("GITHUB_RUN_ID");
252 | Optional runAttempt = envVariable("GITHUB_RUN_ATTEMPT");
253 | Optional runNumber = envVariable("GITHUB_RUN_NUMBER");
254 | Optional headRef = envVariable("GITHUB_HEAD_REF").filter(value -> !value.isEmpty());
255 | Optional serverUrl = envVariable("GITHUB_SERVER_URL");
256 | Optional gitRepository = envVariable("GITHUB_REPOSITORY");
257 |
258 | workflow.ifPresent(value ->
259 | addCustomValueAndSearchLink(buildScan, "CI workflow", value));
260 | jobId.ifPresent(value ->
261 | addCustomValueAndSearchLink(buildScan, "CI job", value));
262 | actionNameOrStepId.ifPresent(value ->
263 | addCustomValueAndSearchLink(buildScan, "CI step", value));
264 |
265 | runId.ifPresent(value ->
266 | buildScan.value("CI run", value));
267 | runAttempt.ifPresent(value ->
268 | buildScan.value("CI run attempt", value));
269 | runNumber.ifPresent(value ->
270 | buildScan.value("CI run number", value));
271 | headRef.ifPresent(value ->
272 | buildScan.value("PR branch", value));
273 |
274 | if (serverUrl.isPresent() && gitRepository.isPresent() && runId.isPresent()) {
275 | StringBuilder githubActionsBuild = new StringBuilder(serverUrl.get())
276 | .append("/").append(gitRepository.get())
277 | .append("/actions/runs/").append(runId.get());
278 | runAttempt.ifPresent(value -> githubActionsBuild.append("/attempts/").append(value));
279 | buildScan.link("GitHub Actions build", githubActionsBuild.toString());
280 | }
281 |
282 | if (runId.isPresent()) {
283 | Map params = new HashMap<>();
284 | params.put("CI run", runId.get());
285 | runAttempt.ifPresent(value -> params.put("CI run attempt", value));
286 | addSearchLink(buildScan, "CI run", params);
287 | }
288 | }
289 |
290 | if (isGitLab()) {
291 | buildScan.value("CI provider", "GitLab");
292 | envVariable("CI_JOB_URL").ifPresent(url ->
293 | buildScan.link("GitLab build", url));
294 | envVariable("CI_PIPELINE_URL").ifPresent(url ->
295 | buildScan.link("GitLab pipeline", url));
296 | envVariable("CI_JOB_NAME").ifPresent(value ->
297 | addCustomValueAndSearchLink(buildScan, "CI job", value));
298 | envVariable("CI_JOB_STAGE").ifPresent(value ->
299 | addCustomValueAndSearchLink(buildScan, "CI stage", value));
300 | }
301 |
302 | if (isTravis()) {
303 | buildScan.value("CI provider", "Travis");
304 | envVariable("TRAVIS_BUILD_WEB_URL").ifPresent(url ->
305 | buildScan.link("Travis build", url));
306 | envVariable("TRAVIS_BUILD_NUMBER").ifPresent(value ->
307 | buildScan.value("CI build number", value));
308 | envVariable("TRAVIS_JOB_NAME").ifPresent(value ->
309 | addCustomValueAndSearchLink(buildScan, "CI job", value));
310 | envVariable("TRAVIS_EVENT_TYPE").ifPresent(buildScan::tag);
311 | }
312 |
313 | if (isBitrise()) {
314 | buildScan.value("CI provider", "Bitrise");
315 | envVariable("BITRISE_BUILD_URL").ifPresent(url ->
316 | buildScan.link("Bitrise build", url));
317 | envVariable("BITRISE_BUILD_NUMBER").ifPresent(value ->
318 | buildScan.value("CI build number", value));
319 | }
320 |
321 | if (isGoCD()) {
322 | buildScan.value("CI provider", "GoCD");
323 | Optional pipelineName = envVariable("GO_PIPELINE_NAME");
324 | Optional pipelineNumber = envVariable("GO_PIPELINE_COUNTER");
325 | Optional stageName = envVariable("GO_STAGE_NAME");
326 | Optional stageNumber = envVariable("GO_STAGE_COUNTER");
327 | Optional jobName = envVariable("GO_JOB_NAME");
328 | Optional goServerUrl = envVariable("GO_SERVER_URL");
329 | if (Stream.of(pipelineName, pipelineNumber, stageName, stageNumber, jobName, goServerUrl).allMatch(Optional::isPresent)) {
330 | //noinspection OptionalGetWithoutIsPresent
331 | String buildUrl = String.format("%s/tab/build/detail/%s/%s/%s/%s/%s",
332 | goServerUrl.get(), pipelineName.get(),
333 | pipelineNumber.get(), stageName.get(), stageNumber.get(), jobName.get());
334 | buildScan.link("GoCD build", buildUrl);
335 | } else if (goServerUrl.isPresent()) {
336 | buildScan.link("GoCD", goServerUrl.get());
337 | }
338 | pipelineName.ifPresent(value ->
339 | addCustomValueAndSearchLink(buildScan, "CI pipeline", value));
340 | jobName.ifPresent(value ->
341 | addCustomValueAndSearchLink(buildScan, "CI job", value));
342 | stageName.ifPresent(value ->
343 | addCustomValueAndSearchLink(buildScan, "CI stage", value));
344 | }
345 |
346 | if (isAzurePipelines()) {
347 | buildScan.value("CI provider", "Azure Pipelines");
348 | Optional azureServerUrl = envVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI");
349 | Optional azureProject = envVariable("SYSTEM_TEAMPROJECT");
350 | Optional buildId = envVariable("BUILD_BUILDID");
351 | if (Stream.of(azureServerUrl, azureProject, buildId).allMatch(Optional::isPresent)) {
352 | //noinspection OptionalGetWithoutIsPresent
353 | String buildUrl = String.format("%s%s/_build/results?buildId=%s",
354 | azureServerUrl.get(), azureProject.get(), buildId.get());
355 | buildScan.link("Azure Pipelines build", buildUrl);
356 | } else if (azureServerUrl.isPresent()) {
357 | buildScan.link("Azure Pipelines", azureServerUrl.get());
358 | }
359 |
360 | buildId.ifPresent(value ->
361 | buildScan.value("CI build number", value));
362 | }
363 |
364 | if (isBuildkite()) {
365 | buildScan.value("CI provider", "Buildkite");
366 | envVariable("BUILDKITE_BUILD_URL").ifPresent(url ->
367 | buildScan.link("Buildkite build", url));
368 | envVariable("BUILDKITE_COMMAND").ifPresent(command ->
369 | addCustomValueAndSearchLink(buildScan, "CI command", command));
370 | envVariable("BUILDKITE_BUILD_ID").ifPresent(id ->
371 | buildScan.value("CI build ID", id));
372 |
373 | Optional buildkitePrRepo = envVariable("BUILDKITE_PULL_REQUEST_REPO");
374 | Optional buildkitePrNumber = envVariable("BUILDKITE_PULL_REQUEST");
375 | if (buildkitePrRepo.isPresent() && buildkitePrNumber.isPresent()) {
376 | // Create a GitHub link with the pr number and full repo url
377 | String prNumber = buildkitePrNumber.get();
378 | toWebRepoUri(buildkitePrRepo.get()).ifPresent(url ->
379 | buildScan.link("PR source", url + "/pull/" + prNumber));
380 | }
381 | }
382 | }
383 | }
384 |
385 | private void captureGitMetadata() {
386 | // Run expensive computation in background
387 | buildScan.background(new CaptureGitMetadataAction());
388 | }
389 |
390 | private static final class CaptureGitMetadataAction implements Consumer {
391 |
392 | @Override
393 | public void accept(BuildScanApiAdapter buildScan) {
394 | if (!isGitInstalled()) {
395 | return;
396 | }
397 |
398 | String gitRepo = execAndGetStdOut("git", "config", "--get", "remote.origin.url");
399 | String gitCommitId = execAndGetStdOut("git", "rev-parse", "--verify", "HEAD");
400 | String gitCommitShortId = execAndGetStdOut("git", "rev-parse", "--short=8", "--verify", "HEAD");
401 | String gitBranchName = getGitBranchName(() -> execAndGetStdOut("git", "rev-parse", "--abbrev-ref", "HEAD"));
402 | String gitStatus = execAndGetStdOut("git", "status", "--porcelain");
403 |
404 | if (isNotEmpty(gitRepo)) {
405 | redactUserInfo(gitRepo).ifPresent(redactedGitRepo -> buildScan.value("Git repository", redactedGitRepo));
406 | }
407 | if (isNotEmpty(gitCommitId)) {
408 | buildScan.value("Git commit id", gitCommitId);
409 | }
410 | if (isNotEmpty(gitCommitShortId)) {
411 | addCustomValueAndSearchLink(buildScan, "Git commit id", "Git commit id short", gitCommitShortId);
412 | }
413 | if (isNotEmpty(gitBranchName)) {
414 | buildScan.tag(gitBranchName);
415 | buildScan.value("Git branch", gitBranchName);
416 | }
417 | if (isNotEmpty(gitStatus)) {
418 | buildScan.tag("Dirty");
419 | buildScan.value("Git status", gitStatus);
420 | }
421 |
422 | Optional gitHubUrl = envVariable("GITHUB_SERVER_URL");
423 | Optional gitRepository = envVariable("GITHUB_REPOSITORY");
424 | if (gitHubUrl.isPresent() && gitRepository.isPresent() && isNotEmpty(gitCommitId)) {
425 | buildScan.link("GitHub source", gitHubUrl.get() + "/" + gitRepository.get() + "/tree/" + gitCommitId);
426 | } else if (isNotEmpty(gitRepo) && isNotEmpty(gitCommitId)) {
427 | Optional webRepoUri = toWebRepoUri(gitRepo);
428 | webRepoUri.ifPresent(uri -> {
429 | if (uri.getHost().contains("github")) {
430 | buildScan.link("GitHub source", uri + "/tree/" + gitCommitId);
431 | } else if (uri.getHost().contains("gitlab")) {
432 | buildScan.link("GitLab source", uri + "/-/commit/" + gitCommitId);
433 | }
434 | });
435 | }
436 | }
437 |
438 | private boolean isGitInstalled() {
439 | return execAndCheckSuccess("git", "--version");
440 | }
441 |
442 | private String getGitBranchName(Supplier gitCommand) {
443 | if (isJenkins() || isHudson()) {
444 | Optional branch = envVariable("BRANCH_NAME");
445 | if (branch.isPresent()) {
446 | return branch.get();
447 | }
448 |
449 | Optional gitBranch = envVariable("GIT_BRANCH");
450 | if (gitBranch.isPresent()) {
451 | Optional localBranch = getLocalBranch(gitBranch.get());
452 | if (localBranch.isPresent()) {
453 | return localBranch.get();
454 | }
455 | }
456 | } else if (isGitLab()) {
457 | Optional branch = envVariable("CI_COMMIT_REF_NAME");
458 | if (branch.isPresent()) {
459 | return branch.get();
460 | }
461 | } else if (isAzurePipelines()) {
462 | Optional branch = envVariable("BUILD_SOURCEBRANCH");
463 | if (branch.isPresent()) {
464 | return branch.get();
465 | }
466 | } else if (isGitHubActions()) {
467 | Optional branch = envVariable("GITHUB_REF_NAME");
468 | if (branch.isPresent()) {
469 | return branch.get();
470 | }
471 | }
472 | return gitCommand.get();
473 | }
474 |
475 | private static Optional getLocalBranch(String remoteBranch) {
476 | // This finds the longest matching remote name. This is because, for example, a local git clone could have
477 | // two remotes named `origin` and `origin/two`. In this scenario, we would want a remote branch of
478 | // `origin/two/main` to match to the `origin/two` remote, not to `origin`
479 | Function> findLongestMatchingRemote = remotes -> Arrays.stream(remotes.split("\\R"))
480 | .filter(remote -> remoteBranch.startsWith(remote + "/"))
481 | .max(Comparator.comparingInt(String::length));
482 |
483 | return Optional.ofNullable(execAndGetStdOut("git", "remote"))
484 | .filter(Utils::isNotEmpty)
485 | .flatMap(findLongestMatchingRemote)
486 | .map(remote -> remoteBranch.replaceFirst("^" + remote + "/", ""));
487 | }
488 | }
489 |
490 | private void captureSkipTestsFlags() {
491 | addCustomValueWhenProjectPropertyResolvesToTrue("skipITs");
492 | addCustomValueWhenProjectPropertyResolvesToTrue("skipTests");
493 | addCustomValueWhenProjectPropertyResolvesToTrue("maven.test.skip");
494 | }
495 |
496 | private void addCustomValueWhenProjectPropertyResolvesToTrue(String property) {
497 | projectProperty(mavenSession, property).ifPresent(value -> {
498 | if (value.isEmpty() || Boolean.valueOf(value).equals(Boolean.TRUE)) {
499 | buildScan.value("switches." + property, "On");
500 | }
501 | });
502 | }
503 |
504 | private static void addCustomValueAndSearchLink(BuildScanApiAdapter buildScan, String name, String value) {
505 | addCustomValueAndSearchLink(buildScan, name, name, value);
506 | }
507 |
508 | private static void addCustomValueAndSearchLink(BuildScanApiAdapter buildScan, String linkLabel, String name, String value) {
509 | // Set custom values immediately, but do not add custom links until 'buildFinished' since
510 | // creating customs links requires the server url to be fully configured
511 | buildScan.value(name, value);
512 | buildScan.buildFinished(result -> addSearchLink(buildScan, linkLabel, name, value));
513 | }
514 |
515 | private static void addSearchLink(BuildScanApiAdapter buildScan, String linkLabel, Map values) {
516 | // the parameters for a link querying multiple custom values look like:
517 | // search.names=name1,name2&search.values=value1,value2
518 | // this reduction groups all names and all values together in order to properly generate the query
519 | values.entrySet().stream()
520 | .sorted(Map.Entry.comparingByKey()) // results in a deterministic order of link parameters
521 | .reduce((a, b) -> new AbstractMap.SimpleEntry<>(a.getKey() + "," + b.getKey(), a.getValue() + "," + b.getValue()))
522 | .ifPresent(x -> buildScan.buildFinished(result -> addSearchLink(buildScan, linkLabel, x.getKey(), x.getValue())));
523 | }
524 |
525 | private static void addSearchLink(BuildScanApiAdapter buildScan, String linkLabel, String name, String value) {
526 | String server = buildScan.getServer();
527 | if (server != null) {
528 | String searchParams = "search.names=" + urlEncode(name) + "&search.values=" + urlEncode(value);
529 | String url = appendIfMissing(server, "/") + "scans?" + searchParams + "#selection.buildScanB=" + urlEncode("{SCAN_ID}");
530 | buildScan.link(linkLabel + " build scans", url);
531 | }
532 | }
533 |
534 | }
--------------------------------------------------------------------------------