This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch mvnd-2.x in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git
commit 7a0d7ed2acb94ca76632941bfc77b4acdd17c510 Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Tue Apr 23 20:53:53 2024 +0200 Switch back to support only Maven 4.0.x --- .github/workflows/early-access.yaml | 12 +- .github/workflows/release.yaml | 102 +- build/publish-on-homebrew.sh | 15 +- build/publish-on-sdkman.sh | 36 +- build/release-candidate.sh | 2 +- client/pom.xml | 23 - daemon-m39/pom.xml | 59 - .../java/org/apache/maven/cli/DaemonMavenCli.java | 1563 -------------------- .../apache/maven/project/SnapshotModelCache.java | 48 - .../maven/project/SnapshotModelCacheFactory.java | 59 - .../InvalidatingPluginDescriptorCache.java | 134 -- .../mvnd/plugin/CachingPluginVersionResolver.java | 79 - daemon-m40/pom.xml | 59 - .../invalidating/InvalidatingPluginRealmCache.java | 121 -- .../InvalidatingRealmCacheEventSpy.java | 190 --- daemon/pom.xml | 6 +- .../java/org/apache/maven/cli/DaemonMavenCli.java | 0 .../apache/maven/project/SnapshotModelCache.java | 0 .../maven/project/SnapshotModelCacheFactory.java | 0 .../org/apache/maven/settings/SettingsUtilsV4.java | 0 .../InvalidatingPluginDescriptorCache.java | 0 .../invalidating/InvalidatingPluginRealmCache.java | 0 .../InvalidatingRealmCacheEventSpy.java | 0 .../mvnd/execution/BuildResumptionAnalyzer.java | 0 .../mvnd/execution/BuildResumptionData.java | 0 .../execution/BuildResumptionDataRepository.java | 0 .../BuildResumptionPersistenceException.java | 0 .../execution/DefaultBuildResumptionAnalyzer.java | 0 .../DefaultBuildResumptionDataRepository.java | 0 .../mvnd/plugin/CachingPluginVersionResolver.java | 0 dist-m39/src/main/provisio/maven-distro.xml | 96 -- dist-m40/pom.xml | 82 - {dist-m39 => dist}/pom.xml | 10 +- .../src/main/provisio/maven-distro.xml | 9 +- integration-tests/pom.xml | 57 +- logging/pom.xml | 2 +- .../logging/smart/LoggingExecutionListener.java | 2 - pom.xml | 49 +- 38 files changed, 76 insertions(+), 2739 deletions(-) diff --git a/.github/workflows/early-access.yaml b/.github/workflows/early-access.yaml index b8b1010a..3c2f5962 100644 --- a/.github/workflows/early-access.yaml +++ b/.github/workflows/early-access.yaml @@ -123,14 +123,8 @@ jobs: name: daemon-test-logs-${{ env.OS }} path: integration-tests/target/mvnd-tests/**/daemon*.log - - name: 'Upload m39 artifact' + - name: 'Upload artifact' uses: actions/upload-artifact@v4 with: - name: mvnd-m39-${{ env.OS }} - path: dist-m39/target/maven-mvnd-*.zip - - - name: 'Upload m40 artifact' - uses: actions/upload-artifact@v4 - with: - name: mvnd-m40-${{ env.OS }} - path: dist-m40/target/maven-mvnd-*.zip + name: mvnd-${{ env.OS }} + path: dist/target/maven-mvnd-*.zip diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2da20e0c..3ea1fe7d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -98,10 +98,8 @@ jobs: with: name: artifacts path: | - dist-m39/target/maven-mvnd-*.zip - dist-m39/target/maven-mvnd-*.tar.gz - dist-m40/target/maven-mvnd-*.zip - dist-m40/target/maven-mvnd-*.tar.gz + dist/target/maven-mvnd-*.zip + dist/target/maven-mvnd-*.tar.gz source: name: 'Build source distributions' @@ -201,123 +199,63 @@ jobs: asset_name: maven-mvnd-${{ env.VERSION }}-src.tar.gz asset_content_type: application/tar.gz - - name: Deploy maven-mvnd-m39-linux-amd64.zip + - name: Deploy maven-mvnd-linux-amd64.zip uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m39/target/maven-mvnd-${{ env.VERSION }}-m39-linux-amd64.zip - asset_name: maven-mvnd-${{ env.VERSION }}-m39-linux-amd64.zip + asset_path: artifacts/dist/target/maven-mvnd-${{ env.VERSION }}-linux-amd64.zip + asset_name: maven-mvnd-${{ env.VERSION }}-linux-amd64.zip asset_content_type: application/zip - - name: Deploy maven-mvnd-m39-linux-amd64.tar.gz + - name: Deploy maven-mvnd-linux-amd64.tar.gz uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m39/target/maven-mvnd-${{ env.VERSION }}-m39-linux-amd64.tar.gz - asset_name: maven-mvnd-${{ env.VERSION }}-m39-linux-amd64.tar.gz + asset_path: artifacts/dist/target/maven-mvnd-${{ env.VERSION }}-linux-amd64.tar.gz + asset_name: maven-mvnd-${{ env.VERSION }}-linux-amd64.tar.gz asset_content_type: application/x-gzip - - name: Deploy maven-mvnd-m39-darwin-amd64.zip + - name: Deploy maven-mvnd-darwin-amd64.zip uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m39/target/maven-mvnd-${{ env.VERSION }}-m39-darwin-amd64.zip - asset_name: maven-mvnd-${{ env.VERSION }}-m39-darwin-amd64.zip + asset_path: artifacts/dist/target/maven-mvnd-${{ env.VERSION }}-darwin-amd64.zip + asset_name: maven-mvnd-${{ env.VERSION }}-darwin-amd64.zip asset_content_type: application/zip - - name: Deploy maven-mvnd-m39-darwin-amd64.tar.gz + - name: Deploy maven-mvnd-darwin-amd64.tar.gz uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m39/target/maven-mvnd-${{ env.VERSION }}-m39-darwin-amd64.tar.gz - asset_name: maven-mvnd-${{ env.VERSION }}-m39-darwin-amd64.tar.gz + asset_path: artifacts/dist/target/maven-mvnd-${{ env.VERSION }}-darwin-amd64.tar.gz + asset_name: maven-mvnd-${{ env.VERSION }}-darwin-amd64.tar.gz asset_content_type: application/x-gzip - - name: Deploy maven-mvnd-m39-windows-amd64.zip + - name: Deploy maven-mvnd-windows-amd64.zip uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m39/target/maven-mvnd-${{ env.VERSION }}-m39-windows-amd64.zip - asset_name: maven-mvnd-${{ env.VERSION }}-m39-windows-amd64.zip + asset_path: artifacts/dist/target/maven-mvnd-${{ env.VERSION }}-windows-amd64.zip + asset_name: maven-mvnd-${{ env.VERSION }}-windows-amd64.zip asset_content_type: application/zip - - name: Deploy maven-mvnd-m39-windows-amd64.tar.gz + - name: Deploy maven-mvnd-windows-amd64.tar.gz uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m39/target/maven-mvnd-${{ env.VERSION }}-m39-windows-amd64.tar.gz - asset_name: maven-mvnd-${{ env.VERSION }}-m39-windows-amd64.tar.gz - asset_content_type: application/x-gzip - - - name: Deploy maven-mvnd-m40-linux-amd64.zip - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m40/target/maven-mvnd-${{ env.VERSION }}-m40-linux-amd64.zip - asset_name: maven-mvnd-${{ env.VERSION }}-m40-linux-amd64.zip - asset_content_type: application/zip - - - name: Deploy maven-mvnd-m40-linux-amd64.tar.gz - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m40/target/maven-mvnd-${{ env.VERSION }}-m40-linux-amd64.tar.gz - asset_name: maven-mvnd-${{ env.VERSION }}-m40-linux-amd64.tar.gz - asset_content_type: application/x-gzip - - - name: Deploy maven-mvnd-m40-darwin-amd64.zip - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m40/target/maven-mvnd-${{ env.VERSION }}-m40-darwin-amd64.zip - asset_name: maven-mvnd-${{ env.VERSION }}-m40-darwin-amd64.zip - asset_content_type: application/zip - - - name: Deploy maven-mvnd-m40-darwin-amd64.tar.gz - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m40/target/maven-mvnd-${{ env.VERSION }}-m40-darwin-amd64.tar.gz - asset_name: maven-mvnd-${{ env.VERSION }}-m40-darwin-amd64.tar.gz - asset_content_type: application/x-gzip - - - name: Deploy maven-mvnd-m40-windows-amd64.zip - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m40/target/maven-mvnd-${{ env.VERSION }}-m40-windows-amd64.zip - asset_name: maven-mvnd-${{ env.VERSION }}-m40-windows-amd64.zip - asset_content_type: application/zip - - - name: Deploy maven-mvnd-m40-windows-amd64.tar.gz - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/dist-m40/target/maven-mvnd-${{ env.VERSION }}-m40-windows-amd64.tar.gz - asset_name: maven-mvnd-${{ env.VERSION }}-m40-windows-amd64.tar.gz + asset_path: artifacts/dist/target/maven-mvnd-${{ env.VERSION }}-windows-amd64.tar.gz + asset_name: maven-mvnd-${{ env.VERSION }}-windows-amd64.tar.gz asset_content_type: application/x-gzip diff --git a/build/publish-on-homebrew.sh b/build/publish-on-homebrew.sh index 20f416bd..f6a2444c 100755 --- a/build/publish-on-homebrew.sh +++ b/build/publish-on-homebrew.sh @@ -17,7 +17,6 @@ set -e export VERSION=$1 -export QUALIFIER=m39 if [ "${VERSION}x" = "x" ] then @@ -29,15 +28,15 @@ rm -Rf target/releases/${VERSION} mkdir -p target/releases/${VERSION} pushd target/releases -darwinAmdZipUrl="https://downloads.apache.org/maven/mvnd/${VERSION}/maven-mvnd-${VERSION}-${QUALIFIER}-darwin-amd64.zip" +darwinAmdZipUrl="https://downloads.apache.org/maven/mvnd/${VERSION}/maven-mvnd-${VERSION}-darwin-amd64.zip" darwinAmdSha256="$(curl -L --silent "${darwinAmdZipUrl}.sha256")" -darwinArmZipUrl="https://downloads.apache.org/maven/mvnd/${VERSION}/maven-mvnd-${VERSION}-${QUALIFIER}-darwin-aarch64.zip" +darwinArmZipUrl="https://downloads.apache.org/maven/mvnd/${VERSION}/maven-mvnd-${VERSION}-darwin-aarch64.zip" darwinArmSha256="$(curl -L --silent "${darwinArmZipUrl}.sha256")" -linuxZipUrl="https://downloads.apache.org/maven/mvnd/${VERSION}/maven-mvnd-${VERSION}-${QUALIFIER}-linux-amd64.zip" +linuxZipUrl="https://downloads.apache.org/maven/mvnd/${VERSION}/maven-mvnd-${VERSION}-linux-amd64.zip" linuxSha256="$(curl -L --silent "${linuxZipUrl}.sha256")" echo "Updating Formula/mvnd.rb with" -echo "version: ${VERSION}-${QUALIFIER}" +echo "version: ${VERSION}" echo "darwin-amd-url: ${darwinAmdZipUrl}" echo "darwin-amd-sha256: ${darwinAmdSha256}" echo "darwin-arm-url: ${darwinArmZipUrl}" @@ -52,14 +51,14 @@ cd homebrew-mvnd perl -i -0pe 's|(on_macos do[\s\S\n]+on_intel do\n\s+url )\"([^\"]+)\"(\n\s+sha256 )\"([^\"]+)\"|$1\"'${darwinAmdZipUrl}'\"$3\"'${darwinAmdSha256}'\"|g' Formula/mvnd.rb perl -i -0pe 's|(on_macos do[\s\S\n]+on_arm do\n\s+url )\"([^\"]+)\"(\n\s+sha256 )\"([^\"]+)\"|$1\"'${darwinArmZipUrl}'\"$3\"'${darwinArmSha256}'\"|g' Formula/mvnd.rb perl -i -0pe 's|(on_linux do\n\s+url )\"([^\"]+)\"(\n\s+sha256 )\"([^\"]+)\"|$1\"'${linuxZipUrl}'\"$3\"'${linuxSha256}'\"|g' Formula/mvnd.rb -perl -i -0pe 's|(version )"([^\"]+)"|$1\"'${VERSION}-${QUALIFIER}'\"|g' Formula/mvnd.rb +perl -i -0pe 's|(version )"([^\"]+)"|$1\"'${VERSION}'\"|g' Formula/mvnd.rb if [ -n "$(git status --porcelain)" ]; then - echo "Committing release ${VERSION}-${QUALIFIER}" + echo "Committing release ${VERSION}" git config --global user.email "gno...@gmail.com" git config --global user.name "Guillaume Nodet" git add -A - git commit -m "Release ${VERSION}-${QUALIFIER}" + git commit -m "Release ${VERSION}" #git push origin master else echo "Nothing to commit" diff --git a/build/publish-on-sdkman.sh b/build/publish-on-sdkman.sh index c9363f50..0fc36be1 100755 --- a/build/publish-on-sdkman.sh +++ b/build/publish-on-sdkman.sh @@ -36,16 +36,15 @@ function publishRelease() { VERSION=$1 SDKMAN_PLATFORM=$2 MVND_PLATFORM=$3 - QUALIFIER=$4 - FILE="maven-mvnd-${VERSION}-${QUALIFIER}-${MVND_PLATFORM}.zip" + FILE="maven-mvnd-${VERSION}-${MVND_PLATFORM}.zip" URL="https://downloads.apache.org/maven/mvnd/${VERSION}/${FILE}" RESPONSE="$(curl -s -X POST \ -H "Consumer-Key: ${SDKMAN_CONSUMER_KEY}" \ -H "Consumer-Token: ${SDKMAN_CONSUMER_TOKEN}" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ - -d '{"candidate": "mvnd", "version": "'${VERSION}-${QUALIFIER}'", "platform" : "'${SDKMAN_PLATFORM}'", "url": "'${URL}'"}' \ + -d '{"candidate": "mvnd", "version": "'${VERSION}'", "platform" : "'${SDKMAN_PLATFORM}'", "url": "'${URL}'"}' \ https://vendors.sdkman.io/release)" node -pe " @@ -59,14 +58,10 @@ function publishRelease() { " "${RESPONSE}" } -publishRelease ${VERSION} LINUX_64 linux-amd64 m39 -publishRelease ${VERSION} MAC_OSX darwin-amd64 m39 -publishRelease ${VERSION} MAC_ARM64 darwin-aarch64 m39 -publishRelease ${VERSION} WINDOWS_64 windows-amd64 m39 -publishRelease ${VERSION} LINUX_64 linux-amd64 m40 -publishRelease ${VERSION} MAC_OSX darwin-amd64 m40 -publishRelease ${VERSION} MAC_ARM64 darwin-aarch64 m40 -publishRelease ${VERSION} WINDOWS_64 windows-amd64 m40 +publishRelease ${VERSION} LINUX_64 linux-amd64 +publishRelease ${VERSION} MAC_OSX darwin-amd64 +publishRelease ${VERSION} MAC_ARM64 darwin-aarch64 +publishRelease ${VERSION} WINDOWS_64 windows-amd64 echo "Setting ${VERSION} as a default" RESPONSE="$(curl -s -X PUT \ @@ -95,7 +90,7 @@ RESPONSE="$(curl -s -X POST \ -H "Consumer-Token: ${SDKMAN_CONSUMER_TOKEN}" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ - -d '{"candidate": "mvnd", "version": "'${VERSION}-m39'", "url": "'${RELEASE_URL}'"}' \ + -d '{"candidate": "mvnd", "version": "'${VERSION}'", "url": "'${RELEASE_URL}'"}' \ https://vendors.sdkman.io/announce/struct)" node -pe " @@ -108,20 +103,3 @@ node -pe " } " "${RESPONSE}" -RESPONSE="$(curl -s -X POST \ - -H "Consumer-Key: ${SDKMAN_CONSUMER_KEY}" \ - -H "Consumer-Token: ${SDKMAN_CONSUMER_TOKEN}" \ - -H "Content-Type: application/json" \ - -H "Accept: application/json" \ - -d '{"candidate": "mvnd", "version": "'${VERSION}-m40'", "url": "'${RELEASE_URL}'"}' \ - https://vendors.sdkman.io/announce/struct)" - -node -pe " - var json = JSON.parse(process.argv[1]); - if (json.status == 200 || json.status == 201) { - json.status + ' as expected from /announce/freeform'; - } else { - console.log('Unexpected status from /announce/freeform: ' + process.argv[1]); - process.exit(1); - } -" "${RESPONSE}" diff --git a/build/release-candidate.sh b/build/release-candidate.sh index 148002ba..1d93c468 100755 --- a/build/release-candidate.sh +++ b/build/release-candidate.sh @@ -48,7 +48,7 @@ gh api $downloadUrl > artifacts-${VERSION}.zip unzip artifacts-${VERSION}.zip -d ${VERSION} cd ${VERSION} -for dist in m39-darwin-amd64.zip m39-darwin-amd64.tar.gz m39-darwin-aarch64.zip m39-darwin-aarch64.tar.gz m39-linux-amd64.zip m39-linux-amd64.tar.gz m39-windows-amd64.zip m39-windows-amd64.tar.gz m40-darwin-amd64.zip m40-darwin-amd64.tar.gz m40-darwin-aarch64.zip m40-darwin-aarch64.tar.gz m40-linux-amd64.zip m40-linux-amd64.tar.gz m40-windows-amd64.zip m40-windows-amd64.tar.gz src.zip src.tar.gz +for dist in darwin-amd64.zip darwin-amd64.tar.gz darwin-aarch64.zip darwin-aarch64.tar.gz linux-amd64.zip linux-amd64.tar.gz windows-amd64.zip windows-amd64.tar.gz src.zip src.tar.gz do FILE=maven-mvnd-${VERSION}-${dist} # sha256 are used by homebrew which does not support sha512 atm diff --git a/client/pom.xml b/client/pom.xml index 8726746c..20822866 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -31,7 +31,6 @@ <name>Maven Daemon - Client</name> <properties> - <maven.compiler.release>11</maven.compiler.release> <graalvm-native-static-opt /> <graalvm-native-glibc-opt /> <patchelf.skip>true</patchelf.skip> @@ -80,28 +79,6 @@ </resource> </resources> <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-enforcer-plugin</artifactId> - <executions> - <execution> - <id>enforce-bytecode-version</id> - <goals> - <goal>enforce</goal> - </goals> - <configuration> - <rules> - <enforceBytecodeVersion> - <maxJdkVersion>${maven.compiler.release}</maxJdkVersion> - <excludes> - <exclude>org.graalvm.nativeimage:svm</exclude> - </excludes> - </enforceBytecodeVersion> - </rules> - </configuration> - </execution> - </executions> - </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> diff --git a/daemon-m39/pom.xml b/daemon-m39/pom.xml deleted file mode 100644 index 2990eec0..00000000 --- a/daemon-m39/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Copyright 2019 the original author or authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd</artifactId> - <version>1.0-m9-SNAPSHOT</version> - </parent> - - <artifactId>mvnd-daemon-m39</artifactId> - - <packaging>jar</packaging> - <name>Maven Daemon - Daemon 3.9.x specifics</name> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-core</artifactId> - <version>${maven3.version}</version> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-embedder</artifactId> - <version>${maven3.version}</version> - </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-daemon</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.eclipse.sisu</groupId> - <artifactId>sisu-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - -</project> diff --git a/daemon-m39/src/main/java/org/apache/maven/cli/DaemonMavenCli.java b/daemon-m39/src/main/java/org/apache/maven/cli/DaemonMavenCli.java deleted file mode 100644 index 142e1fa8..00000000 --- a/daemon-m39/src/main/java/org/apache/maven/cli/DaemonMavenCli.java +++ /dev/null @@ -1,1563 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.cli; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.ListIterator; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import com.google.inject.AbstractModule; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.ParseException; -import org.apache.commons.cli.UnrecognizedOptionException; -import org.apache.maven.InternalErrorException; -import org.apache.maven.Maven; -import org.apache.maven.building.FileSource; -import org.apache.maven.building.Problem; -import org.apache.maven.building.Source; -import org.apache.maven.cli.configuration.ConfigurationProcessor; -import org.apache.maven.cli.configuration.SettingsXmlConfigurationProcessor; -import org.apache.maven.cli.event.ExecutionEventLogger; -import org.apache.maven.cli.internal.BootstrapCoreExtensionManager; -import org.apache.maven.cli.internal.extension.model.CoreExtension; -import org.apache.maven.cli.logging.Slf4jConfiguration; -import org.apache.maven.cli.logging.Slf4jConfigurationFactory; -import org.apache.maven.cli.transfer.QuietMavenTransferListener; -import org.apache.maven.cli.transfer.Slf4jMavenTransferListener; -import org.apache.maven.eventspy.internal.EventSpyDispatcher; -import org.apache.maven.exception.DefaultExceptionHandler; -import org.apache.maven.exception.ExceptionHandler; -import org.apache.maven.exception.ExceptionSummary; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequestPopulationException; -import org.apache.maven.execution.MavenExecutionRequestPopulator; -import org.apache.maven.execution.MavenExecutionResult; -import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule; -import org.apache.maven.extension.internal.CoreExports; -import org.apache.maven.extension.internal.CoreExtensionEntry; -import org.apache.maven.lifecycle.LifecycleExecutionException; -import org.apache.maven.model.building.ModelProcessor; -import org.apache.maven.plugin.ExtensionRealmCache; -import org.apache.maven.plugin.PluginArtifactsCache; -import org.apache.maven.plugin.PluginRealmCache; -import org.apache.maven.plugin.version.PluginVersionResolver; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.artifact.ProjectArtifactsCache; -import org.apache.maven.properties.internal.SystemProperties; -import org.apache.maven.session.scope.internal.SessionScopeModule; -import org.apache.maven.shared.utils.logging.MessageBuilder; -import org.apache.maven.shared.utils.logging.MessageUtils; -import org.apache.maven.toolchain.building.DefaultToolchainsBuildingRequest; -import org.apache.maven.toolchain.building.ToolchainsBuilder; -import org.apache.maven.toolchain.building.ToolchainsBuildingResult; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.classworlds.ClassWorld; -import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.interpolation.AbstractValueSource; -import org.codehaus.plexus.interpolation.InterpolationException; -import org.codehaus.plexus.interpolation.StringSearchInterpolator; -import org.eclipse.aether.transfer.TransferListener; -import org.mvndaemon.mvnd.cache.invalidating.InvalidatingExtensionRealmCache; -import org.mvndaemon.mvnd.cache.invalidating.InvalidatingPluginArtifactsCache; -import org.mvndaemon.mvnd.cache.invalidating.InvalidatingPluginRealmCache; -import org.mvndaemon.mvnd.cache.invalidating.InvalidatingProjectArtifactsCache; -import org.mvndaemon.mvnd.cli.EnvHelper; -import org.mvndaemon.mvnd.common.Environment; -import org.mvndaemon.mvnd.common.Os; -import org.mvndaemon.mvnd.execution.BuildResumptionPersistenceException; -import org.mvndaemon.mvnd.execution.DefaultBuildResumptionAnalyzer; -import org.mvndaemon.mvnd.execution.DefaultBuildResumptionDataRepository; -import org.mvndaemon.mvnd.logging.internal.Slf4jLoggerManager; -import org.mvndaemon.mvnd.logging.smart.BuildEventListener; -import org.mvndaemon.mvnd.logging.smart.LoggingExecutionListener; -import org.mvndaemon.mvnd.logging.smart.LoggingOutputStream; -import org.mvndaemon.mvnd.plugin.CachingPluginVersionResolver; -import org.mvndaemon.mvnd.transfer.DaemonMavenTransferListener; -import org.slf4j.ILoggerFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.impl.MvndSimpleLogger; -import org.slf4j.spi.LocationAwareLogger; -import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher; -import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; - -import static java.util.Comparator.comparing; -import static org.apache.maven.shared.utils.logging.MessageUtils.buffer; - -/** - * File origin: - * https://github.com/apache/maven/blob/maven-3.6.2/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java - * - * @author Jason van Zyl - */ -public class DaemonMavenCli implements DaemonCli { - public static final String LOCAL_REPO_PROPERTY = "maven.repo.local"; - - public static final String MULTIMODULE_PROJECT_DIRECTORY = "maven.multiModuleProjectDirectory"; - - public static final String USER_HOME = System.getProperty("user.home"); - - public static final File USER_MAVEN_CONFIGURATION_HOME = new File(USER_HOME, ".m2"); - - public static final File DEFAULT_USER_TOOLCHAINS_FILE = new File(USER_MAVEN_CONFIGURATION_HOME, "toolchains.xml"); - - public static final File DEFAULT_GLOBAL_TOOLCHAINS_FILE = - new File(System.getProperty("maven.conf"), "toolchains.xml"); - - private static final String EXT_CLASS_PATH = "maven.ext.class.path"; - - private static final String DOT_MVN = ".mvn"; - - private static final String UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE = "Unable to find the root directory. Create a " - + DOT_MVN + " directory in the project root directory to identify it."; - - private static final String EXTENSIONS_FILENAME = DOT_MVN + "/extensions.xml"; - - private static final String MVN_MAVEN_CONFIG = DOT_MVN + "/maven.config"; - - public static final String STYLE_COLOR_PROPERTY = "style.color"; - - public static final String RESUME = "r"; - - public static final String RAW_STREAMS = "raw-streams"; - - private final Slf4jLoggerManager plexusLoggerManager; - - private final ILoggerFactory slf4jLoggerFactory; - - private final Logger slf4jLogger; - - private final ClassWorld classWorld; - - private final DefaultPlexusContainer container; - - private final EventSpyDispatcher eventSpyDispatcher; - - private final ModelProcessor modelProcessor; - - private final Maven maven; - - private final MavenExecutionRequestPopulator executionRequestPopulator; - - private final ToolchainsBuilder toolchainsBuilder; - - private final DefaultSecDispatcher dispatcher; - - private final Map<String, ConfigurationProcessor> configurationProcessors; - - private final LoggingExecutionListener executionListener; - - /** Non-volatile, assuming that it is accessed only from the main thread */ - private BuildEventListener buildEventListener = BuildEventListener.dummy(); - - public DaemonMavenCli() throws Exception { - slf4jLoggerFactory = LoggerFactory.getILoggerFactory(); - slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName()); - plexusLoggerManager = new Slf4jLoggerManager(); - - this.classWorld = ((ClassRealm) Thread.currentThread().getContextClassLoader()).getWorld(); - - container = container(); - - eventSpyDispatcher = container.lookup(EventSpyDispatcher.class); - maven = container.lookup(Maven.class); - executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class); - modelProcessor = createModelProcessor(container); - configurationProcessors = container.lookupMap(ConfigurationProcessor.class); - toolchainsBuilder = container.lookup(ToolchainsBuilder.class); - dispatcher = (DefaultSecDispatcher) container.lookup(SecDispatcher.class, "maven"); - executionListener = container.lookup(LoggingExecutionListener.class); - } - - public int main( - List<String> arguments, - String workingDirectory, - String projectDirectory, - Map<String, String> clientEnv, - BuildEventListener buildEventListener) - throws Exception { - this.buildEventListener = buildEventListener; - try { - CliRequest req = new CliRequest(null, null); - req.args = arguments.toArray(new String[0]); - req.workingDirectory = new File(workingDirectory).getCanonicalPath(); - req.multiModuleProjectDirectory = new File(projectDirectory); - return doMain(req, clientEnv); - } finally { - this.buildEventListener = BuildEventListener.dummy(); - } - } - - public int doMain(CliRequest cliRequest, Map<String, String> clientEnv) throws Exception { - Properties props = (Properties) System.getProperties().clone(); - ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(container.getContainerRealm()); - initialize(cliRequest); - environment(cliRequest.workingDirectory, clientEnv); - cli(cliRequest); - properties(cliRequest); - logging(cliRequest); - informativeCommands(cliRequest); - version(cliRequest); - container(cliRequest); - configure(cliRequest, eventSpyDispatcher, configurationProcessors); - toolchains(cliRequest); - populateRequest(cliRequest); - encryption(cliRequest); - return execute(cliRequest); - } catch (ExitException e) { - return e.exitCode; - } catch (UnrecognizedOptionException e) { - // pure user error, suppress stack trace - return 1; - } finally { - eventSpyDispatcher.close(); - System.setProperties(props); - Thread.currentThread().setContextClassLoader(tccl); - } - } - - void initialize(CliRequest cliRequest) throws ExitException { - cliRequest.classWorld = classWorld; - - if (cliRequest.workingDirectory == null) { - cliRequest.workingDirectory = System.getProperty("user.dir"); - } - - if (cliRequest.multiModuleProjectDirectory == null) { - String basedirProperty = System.getProperty(MULTIMODULE_PROJECT_DIRECTORY); - if (basedirProperty == null) { - System.err.format("-D%s system property is not set.", MULTIMODULE_PROJECT_DIRECTORY); - throw new ExitException(1); - } - File basedir = new File(basedirProperty); - try { - cliRequest.multiModuleProjectDirectory = basedir.getCanonicalFile(); - } catch (IOException e) { - cliRequest.multiModuleProjectDirectory = basedir.getAbsoluteFile(); - } - } - - // We need to locate the top level project which may be pointed at using - // the -f/--file option. However, the command line isn't parsed yet, so - // we need to iterate through the args to find it and act upon it. - Path topDirectory = Paths.get(cliRequest.workingDirectory); - boolean isAltFile = false; - for (String arg : cliRequest.args) { - if (isAltFile) { - // this is the argument following -f/--file - Path path = topDirectory.resolve(arg); - if (Files.isDirectory(path)) { - topDirectory = path; - } else if (Files.isRegularFile(path)) { - topDirectory = path.getParent(); - if (!Files.isDirectory(topDirectory)) { - System.err.println("Directory " + topDirectory - + " extracted from the -f/--file command-line argument " + arg + " does not exist"); - throw new ExitException(1); - } - } else { - System.err.println( - "POM file " + arg + " specified with the -f/--file command line argument does not exist"); - throw new ExitException(1); - } - break; - } else { - // Check if this is the -f/--file option - isAltFile = arg.equals(String.valueOf(CLIManager.ALTERNATE_POM_FILE)) || arg.equals("file"); - } - } - topDirectory = getCanonicalPath(topDirectory); - cliRequest.topDirectory = topDirectory; - // We're very early in the process and we don't have the container set up yet, - // so we on searchAcceptableRootDirectory method to find us acceptable directory. - // The method may return null if nothing acceptable found. - cliRequest.rootDirectory = searchAcceptableRootDirectory(topDirectory); - - // - // Make sure the Maven home directory is an absolute path to save us from confusion with say drive-relative - // Windows paths. - // - String mavenHome = System.getProperty("maven.home"); - - if (mavenHome != null) { - System.setProperty("maven.home", new File(mavenHome).getAbsolutePath()); - } - } - - protected boolean isAcceptableRootDirectory(Path path) { - return path != null && Files.isDirectory(path.resolve(DOT_MVN)); - } - - protected Path searchAcceptableRootDirectory(Path path) { - if (path == null) { - return null; - } - if (isAcceptableRootDirectory(path)) { - return path; - } - return searchAcceptableRootDirectory(path.getParent()); - } - - private static Path getCanonicalPath(Path path) { - try { - return path.toRealPath(); - } catch (IOException e) { - return getCanonicalPath(path.getParent()).resolve(path.getFileName()); - } - } - - void cli(CliRequest cliRequest) throws Exception { - CLIManager cliManager = newCLIManager(); - - CommandLine mavenConfig = null; - try { - File configFile = new File(cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG); - - if (configFile.isFile()) { - try (Stream<String> lines = Files.lines(configFile.toPath(), Charset.defaultCharset())) { - String[] args = lines.filter(arg -> !arg.isEmpty() && !arg.startsWith("#")) - .toArray(String[]::new); - mavenConfig = cliManager.parse(args); - List<?> unrecognized = mavenConfig.getArgList(); - if (!unrecognized.isEmpty()) { - // This file can only contain options, not args (goals or phases) - throw new ParseException("Unrecognized maven.config file entries: " + unrecognized); - } - } - } - } catch (ParseException e) { - buildEventListener.log("Unable to parse maven.config: " + e.getMessage()); - buildEventListener.log("Run 'mvnd --help' for available options."); - throw new ExitException(1); - } - - try { - if (mavenConfig == null) { - cliRequest.commandLine = cliManager.parse(cliRequest.args); - } else { - cliRequest.commandLine = cliMerge(cliManager.parse(cliRequest.args), mavenConfig); - } - } catch (ParseException e) { - buildEventListener.log("Unable to parse command line options: " + e.getMessage()); - buildEventListener.log("Run 'mvnd --help' for available options."); - throw new ExitException(1); - } - } - - private void informativeCommands(CliRequest cliRequest) throws Exception { - if (cliRequest.commandLine.hasOption(CLIManager.HELP)) { - buildEventListener.log(MvndHelpFormatter.displayHelp(newCLIManager())); - throw new ExitException(0); - } - - if (cliRequest.commandLine.hasOption(CLIManager.VERSION)) { - if (cliRequest.commandLine.hasOption(CLIManager.QUIET)) { - buildEventListener.log(CLIReportingUtils.showVersionMinimal()); - } else { - buildEventListener.log(CLIReportingUtils.showVersion()); - } - throw new ExitException(0); - } - } - - private CLIManager newCLIManager() { - CLIManager cliManager = new CLIManager(); - cliManager.options.addOption(Option.builder(RESUME) - .longOpt("resume") - .desc("Resume reactor from " - + "the last failed project, using the resume.properties file in the build directory") - .build()); - cliManager.options.addOption(Option.builder() - .longOpt(RAW_STREAMS) - .desc("Do not decorate output and error streams") - .build()); - return cliManager; - } - - private CommandLine cliMerge(CommandLine mavenArgs, CommandLine mavenConfig) { - CommandLine.Builder commandLineBuilder = new CommandLine.Builder(); - - // the args are easy, cli first then config file - for (String arg : mavenArgs.getArgs()) { - commandLineBuilder.addArg(arg); - } - for (String arg : mavenConfig.getArgs()) { - commandLineBuilder.addArg(arg); - } - - // now add all options, except for -D with cli first then config file - List<Option> setPropertyOptions = new ArrayList<>(); - for (Option opt : mavenArgs.getOptions()) { - if (String.valueOf(CLIManager.SET_SYSTEM_PROPERTY).equals(opt.getOpt())) { - setPropertyOptions.add(opt); - } else { - commandLineBuilder.addOption(opt); - } - } - for (Option opt : mavenConfig.getOptions()) { - commandLineBuilder.addOption(opt); - } - // finally add the CLI system properties - for (Option opt : setPropertyOptions) { - commandLineBuilder.addOption(opt); - } - return commandLineBuilder.build(); - } - - /** - * configure logging - */ - void logging(CliRequest cliRequest) { - // LOG LEVEL - cliRequest.debug = cliRequest.commandLine.hasOption(CLIManager.DEBUG); - cliRequest.quiet = !cliRequest.debug && cliRequest.commandLine.hasOption(CLIManager.QUIET); - cliRequest.showErrors = cliRequest.debug || cliRequest.commandLine.hasOption(CLIManager.ERRORS); - - Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory); - - if (cliRequest.debug) { - cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG); - slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG); - } else if (cliRequest.quiet) { - cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR); - slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR); - } - // else fall back to default log level specified in conf - // see https://issues.apache.org/jira/browse/MNG-2570 - - // LOG COLOR - String styleColor = cliRequest.getUserProperties().getProperty(STYLE_COLOR_PROPERTY, "auto"); - if ("always".equals(styleColor)) { - MessageUtils.setColorEnabled(true); - } else if ("never".equals(styleColor)) { - MessageUtils.setColorEnabled(false); - } else if (!"auto".equals(styleColor)) { - throw new IllegalArgumentException("Invalid color configuration option [" + styleColor - + "]. Supported values are (auto|always|never)."); - } else if (cliRequest.commandLine.hasOption(CLIManager.BATCH_MODE) - || cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) { - MessageUtils.setColorEnabled(false); - } - - // LOG STREAMS - if (cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) { - File logFile = new File(cliRequest.commandLine.getOptionValue(CLIManager.LOG_FILE)); - logFile = resolveFile(logFile, cliRequest.workingDirectory); - - // redirect stdout and stderr to file - try { - PrintStream ps = new PrintStream(new FileOutputStream(logFile), true); - System.setOut(ps); - System.setErr(ps); - } catch (FileNotFoundException e) { - // - // Ignore - // - } - } else if (!Environment.MVND_RAW_STREAMS - .asOptional() - .map(Boolean::parseBoolean) - .orElse(Boolean.FALSE)) { - MvndSimpleLogger stdout = (MvndSimpleLogger) slf4jLoggerFactory.getLogger("stdout"); - MvndSimpleLogger stderr = (MvndSimpleLogger) slf4jLoggerFactory.getLogger("stderr"); - stdout.setLogLevel(LocationAwareLogger.INFO_INT); - stderr.setLogLevel(LocationAwareLogger.INFO_INT); - System.setOut(new LoggingOutputStream(s -> stdout.info("[stdout] " + s)).printStream()); - System.setErr(new LoggingOutputStream(s -> stderr.warn("[stderr] " + s)).printStream()); - } - - slf4jConfiguration.activate(); - } - - private void version(CliRequest cliRequest) throws ExitException { - if (cliRequest.debug || cliRequest.commandLine.hasOption(CLIManager.SHOW_VERSION)) { - buildEventListener.log(CLIReportingUtils.showVersion()); - } - } - - private void commands(CliRequest cliRequest) { - if (cliRequest.showErrors) { - slf4jLogger.info("Error stacktraces are turned on."); - } - - if (MavenExecutionRequest.CHECKSUM_POLICY_WARN.equals(cliRequest.request.getGlobalChecksumPolicy())) { - slf4jLogger.info("Disabling strict checksum verification on all artifact downloads."); - } else if (MavenExecutionRequest.CHECKSUM_POLICY_FAIL.equals(cliRequest.request.getGlobalChecksumPolicy())) { - slf4jLogger.info("Enabling strict checksum verification on all artifact downloads."); - } - - if (slf4jLogger.isDebugEnabled()) { - slf4jLogger.debug("Message scheme: {}", (MessageUtils.isColorEnabled() ? "color" : "plain")); - if (MessageUtils.isColorEnabled()) { - MessageBuilder buff = MessageUtils.buffer(); - buff.a("Message styles: "); - buff.a(MessageUtils.level().debug("debug")).a(' '); - buff.a(MessageUtils.level().info("info")).a(' '); - buff.a(MessageUtils.level().warning("warning")).a(' '); - buff.a(MessageUtils.level().error("error")).a(' '); - - buff.success("success").a(' '); - buff.failure("failure").a(' '); - buff.strong("strong").a(' '); - buff.mojo("mojo").a(' '); - buff.project("project"); - slf4jLogger.debug(buff.toString()); - } - } - } - - // Needed to make this method package visible to make writing a unit test possible - // Maybe it's better to move some of those methods to separate class (SoC). - void properties(CliRequest cliRequest) throws ExitException { - try { - populateProperties(cliRequest, cliRequest.systemProperties, cliRequest.userProperties); - - StringSearchInterpolator interpolator = - createInterpolator(cliRequest, cliRequest.systemProperties, cliRequest.userProperties); - CommandLine.Builder commandLineBuilder = new CommandLine.Builder(); - for (Option option : cliRequest.commandLine.getOptions()) { - if (!String.valueOf(CLIManager.SET_USER_PROPERTY).equals(option.getOpt())) { - List<String> values = option.getValuesList(); - for (ListIterator<String> it = values.listIterator(); it.hasNext(); ) { - it.set(interpolator.interpolate(it.next())); - } - } - commandLineBuilder.addOption(option); - } - for (String arg : cliRequest.commandLine.getArgList()) { - commandLineBuilder.addArg(interpolator.interpolate(arg)); - } - cliRequest.commandLine = commandLineBuilder.build(); - } catch (InterpolationException e) { - String message = "ERROR: Could not interpolate properties and/or arguments: " + e.getMessage(); - System.err.println(message); - throw new ExitException(1); // user error - } catch (MavenCli.IllegalUseOfUndefinedProperty e) { - String message = "ERROR: Illegal use of undefined property: " + e.property; - System.err.println(message); - if (cliRequest.rootDirectory == null) { - System.err.println(); - System.err.println(UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE); - } - throw new ExitException(1); // user error - } - } - - protected static StringSearchInterpolator createInterpolator(CliRequest cliRequest, Properties... properties) { - StringSearchInterpolator interpolator = new StringSearchInterpolator(); - interpolator.addValueSource(new AbstractValueSource(false) { - @Override - public Object getValue(String expression) { - if ("session.topDirectory".equals(expression)) { - Path topDirectory = cliRequest.topDirectory; - if (topDirectory != null) { - return topDirectory.toString(); - } else { - throw new MavenCli.IllegalUseOfUndefinedProperty(expression); - } - } else if ("session.rootDirectory".equals(expression)) { - Path rootDirectory = cliRequest.rootDirectory; - if (rootDirectory != null) { - return rootDirectory.toString(); - } else { - throw new MavenCli.IllegalUseOfUndefinedProperty(expression); - } - } - return null; - } - }); - interpolator.addValueSource(new AbstractValueSource(false) { - @Override - public Object getValue(String expression) { - for (Properties props : properties) { - Object val = props.getProperty(expression); - if (val != null) { - return val; - } - } - return null; - } - }); - return interpolator; - } - - void container(CliRequest cliRequest) { - Map<String, Object> data = new HashMap<>(); - data.put("plexus", container); - data.put("workingDirectory", cliRequest.workingDirectory); - data.put("systemProperties", cliRequest.systemProperties); - data.put("userProperties", cliRequest.userProperties); - data.put("versionProperties", CLIReportingUtils.getBuildProperties()); - eventSpyDispatcher.init(() -> data); - } - - DefaultPlexusContainer container() throws Exception { - ClassRealm coreRealm = classWorld.getClassRealm("plexus.core"); - if (coreRealm == null) { - coreRealm = classWorld.getRealms().iterator().next(); - } - - List<File> extClassPath = Stream.of( - Environment.MVND_EXT_CLASSPATH.asString().split(",")) - .filter(s -> s != null && !s.isEmpty()) - .map(File::new) - .collect(Collectors.toList()); - - CoreExtensionEntry coreEntry = CoreExtensionEntry.discoverFrom(coreRealm); - - List<CoreExtension> extensions = Stream.of( - Environment.MVND_CORE_EXTENSIONS.asString().split(";")) - .filter(s -> s != null && !s.isEmpty()) - .map(s -> { - String[] parts = s.split(":"); - CoreExtension ce = new CoreExtension(); - ce.setGroupId(parts[0]); - ce.setArtifactId(parts[1]); - ce.setVersion(parts[2]); - return ce; - }) - .collect(Collectors.toList()); - List<CoreExtensionEntry> extensionsEntries = - loadCoreExtensions(extensions, coreRealm, coreEntry.getExportedArtifacts()); - ClassRealm containerRealm = setupContainerRealm(classWorld, coreRealm, extClassPath, extensionsEntries); - - ContainerConfiguration cc = new DefaultContainerConfiguration() - .setClassWorld(classWorld) - .setRealm(containerRealm) - .setClassPathScanning(PlexusConstants.SCANNING_INDEX) - .setAutoWiring(true) - .setJSR250Lifecycle(true) - .setName("maven"); - - Set<String> exportedArtifacts = new HashSet<>(coreEntry.getExportedArtifacts()); - Set<String> exportedPackages = new HashSet<>(coreEntry.getExportedPackages()); - for (CoreExtensionEntry extension : extensionsEntries) { - exportedArtifacts.addAll(extension.getExportedArtifacts()); - exportedPackages.addAll(extension.getExportedPackages()); - } - exportedPackages.add("org.codehaus.plexus.components.interactivity"); - exportedPackages.add("org.mvndaemon.mvnd.interactivity"); - exportedArtifacts.add("org.codehaus.plexus:plexus-interactivity-api"); - - final CoreExports exports = new CoreExports(containerRealm, exportedArtifacts, exportedPackages); - - final DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() { - @Override - protected void configure() { - bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory); - bind(CoreExports.class).toInstance(exports); - bind(ExtensionRealmCache.class).to(InvalidatingExtensionRealmCache.class); - bind(PluginArtifactsCache.class).to(InvalidatingPluginArtifactsCache.class); - bind(PluginRealmCache.class).to(InvalidatingPluginRealmCache.class); - bind(ProjectArtifactsCache.class).to(InvalidatingProjectArtifactsCache.class); - bind(PluginVersionResolver.class).to(CachingPluginVersionResolver.class); - } - }); - - // NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups - container.setLookupRealm(null); - Thread.currentThread().setContextClassLoader(container.getContainerRealm()); - - container.setLoggerManager(plexusLoggerManager); - - for (CoreExtensionEntry extension : extensionsEntries) { - container.discoverComponents( - extension.getClassRealm(), - new SessionScopeModule(container), - new MojoExecutionScopeModule(container)); - } - return container; - } - - private List<CoreExtensionEntry> loadCoreExtensions( - List<CoreExtension> extensions, ClassRealm containerRealm, Set<String> providedArtifacts) throws Exception { - if (extensions.isEmpty()) { - return Collections.emptyList(); - } - ContainerConfiguration cc = new DefaultContainerConfiguration() // - .setClassWorld(classWorld) // - .setRealm(containerRealm) // - .setClassPathScanning(PlexusConstants.SCANNING_INDEX) // - .setAutoWiring(true) // - .setJSR250Lifecycle(true) // - .setName("maven"); - - DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() { - @Override - protected void configure() { - bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory); - } - }); - MavenExecutionRequestPopulator executionRequestPopulator = null; - try { - CliRequest cliRequest = new CliRequest(new String[0], classWorld); - cliRequest.commandLine = new CommandLine.Builder().build(); - container.setLookupRealm(null); - container.setLoggerManager(plexusLoggerManager); - container.getLoggerManager().setThresholds(cliRequest.request.getLoggingLevel()); - Thread.currentThread().setContextClassLoader(container.getContainerRealm()); - executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class); - final Map<String, ConfigurationProcessor> configurationProcessors = - container.lookupMap(ConfigurationProcessor.class); - final EventSpyDispatcher eventSpyDispatcher = container.lookup(EventSpyDispatcher.class); - properties(cliRequest); - configure(cliRequest, eventSpyDispatcher, configurationProcessors); - LoggingExecutionListener executionListener = container.lookup(LoggingExecutionListener.class); - populateRequest( - cliRequest, - cliRequest.request, - slf4jLogger, - eventSpyDispatcher, - container.lookup(ModelProcessor.class), - createTransferListener(cliRequest), - buildEventListener, - executionListener); - executionRequestPopulator.populateDefaults(cliRequest.request); - BootstrapCoreExtensionManager resolver = container.lookup(BootstrapCoreExtensionManager.class); - return Collections.unmodifiableList( - resolver.loadCoreExtensions(cliRequest.request, providedArtifacts, extensions)); - } finally { - executionRequestPopulator = null; - container.dispose(); - } - } - - private ClassRealm setupContainerRealm( - ClassWorld classWorld, ClassRealm coreRealm, List<File> extClassPath, List<CoreExtensionEntry> extensions) - throws Exception { - if (!extClassPath.isEmpty() || !extensions.isEmpty()) { - ClassRealm extRealm = classWorld.newRealm("maven.ext", null); - extRealm.setParentRealm(coreRealm); - slf4jLogger.debug("Populating class realm {}", extRealm.getId()); - for (File file : extClassPath) { - - extRealm.addURL(file.toURI().toURL()); - } - for (CoreExtensionEntry entry : reverse(extensions)) { - Set<String> exportedPackages = entry.getExportedPackages(); - ClassRealm realm = entry.getClassRealm(); - for (String exportedPackage : exportedPackages) { - extRealm.importFrom(realm, exportedPackage); - } - if (exportedPackages.isEmpty()) { - // sisu uses realm imports to establish component visibility - extRealm.importFrom(realm, realm.getId()); - } - } - return extRealm; - } - return coreRealm; - } - - private static <T> List<T> reverse(List<T> list) { - List<T> copy = new ArrayList<>(list); - Collections.reverse(copy); - return copy; - } - - private List<File> parseExtClasspath(CliRequest cliRequest) { - String extClassPath = cliRequest.userProperties.getProperty(EXT_CLASS_PATH); - if (extClassPath == null) { - extClassPath = cliRequest.systemProperties.getProperty(EXT_CLASS_PATH); - } - - List<File> jars = new ArrayList<>(); - - if (extClassPath != null) { - for (String jar : extClassPath.split(File.pathSeparator)) { - File file = resolveFile(new File(jar), cliRequest.workingDirectory); - slf4jLogger.debug(" Included {}", file); - jars.add(file); - } - } - - return jars; - } - - // - // This should probably be a separate tool and not be baked into Maven. - // - private void encryption(CliRequest cliRequest) throws Exception { - if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_MASTER_PASSWORD)) { - throw new UnsupportedOperationException("Unsupported option: " + CLIManager.ENCRYPT_MASTER_PASSWORD); - } else if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_PASSWORD)) { - throw new UnsupportedOperationException("Unsupported option: " + CLIManager.ENCRYPT_PASSWORD); - } - } - - private void environment(String workingDir, Map<String, String> clientEnv) { - EnvHelper.environment(workingDir, clientEnv); - } - - private int execute(CliRequest cliRequest) throws MavenExecutionRequestPopulationException { - commands(cliRequest); - - MavenExecutionRequest request = executionRequestPopulator.populateDefaults(cliRequest.request); - - eventSpyDispatcher.onEvent(request); - - slf4jLogger.info(buffer().a("Processing build on daemon ") - .strong(Environment.MVND_ID.asString()) - .toString()); - - MavenExecutionResult result = maven.execute(request); - - LoggingOutputStream.forceFlush(System.out); - LoggingOutputStream.forceFlush(System.err); - - eventSpyDispatcher.onEvent(result); - - if (result.hasExceptions()) { - ExceptionHandler handler = new DefaultExceptionHandler(); - - Map<String, String> references = new LinkedHashMap<>(); - - List<MavenProject> failedProjects = new ArrayList<>(); - - for (Throwable exception : result.getExceptions()) { - ExceptionSummary summary = handler.handleException(exception); - - logSummary(summary, references, "", cliRequest.showErrors); - - if (exception instanceof LifecycleExecutionException) { - MavenProject project = ((LifecycleExecutionException) exception).getProject(); - if (project != null) { - failedProjects.add(project); - } - } - } - - slf4jLogger.error(""); - - if (!cliRequest.showErrors) { - slf4jLogger.error( - "To see the full stack trace of the errors, re-run Maven with the {} switch.", - buffer().strong("-e")); - } - if (!slf4jLogger.isDebugEnabled()) { - slf4jLogger.error( - "Re-run Maven using the {} switch to enable full debug logging.", buffer().strong("-X")); - } - - if (!references.isEmpty()) { - slf4jLogger.error(""); - slf4jLogger.error("For more information about the errors and possible solutions" - + ", please read the following articles:"); - - for (Entry<String, String> entry : references.entrySet()) { - slf4jLogger.error("{} {}", buffer().strong(entry.getValue()), entry.getKey()); - } - } - - boolean canResume = new DefaultBuildResumptionAnalyzer() - .determineBuildResumptionData(result) - .map(resumption -> { - try { - Path directory = - Paths.get(request.getBaseDirectory()).resolve("target"); - new DefaultBuildResumptionDataRepository().persistResumptionData(directory, resumption); - return true; - } catch (BuildResumptionPersistenceException e) { - slf4jLogger.warn("Could not persist build resumption data", e); - } - return false; - }) - .orElse(false); - - if (canResume) { - logBuildResumeHint("mvn <args> -r"); - } else if (!failedProjects.isEmpty()) { - List<MavenProject> sortedProjects = result.getTopologicallySortedProjects(); - - // Sort the failedProjects list in the topologically sorted order. - failedProjects.sort(comparing(sortedProjects::indexOf)); - - MavenProject firstFailedProject = failedProjects.get(0); - if (!firstFailedProject.equals(sortedProjects.get(0))) { - String resumeFromSelector = getResumeFromSelector(sortedProjects, firstFailedProject); - logBuildResumeHint("mvn <args> -rf " + resumeFromSelector); - } - } - - if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(cliRequest.request.getReactorFailureBehavior())) { - slf4jLogger.info("Build failures were ignored."); - - return 0; - } else { - return 1; - } - } else { - Path directory = Paths.get(request.getBaseDirectory()).resolve("target"); - new DefaultBuildResumptionDataRepository().removeResumptionData(directory); - return 0; - } - } - - private void logBuildResumeHint(String resumeBuildHint) { - slf4jLogger.error(""); - slf4jLogger.error("After correcting the problems, you can resume the build with the command"); - slf4jLogger.error(buffer().a(" ").strong(resumeBuildHint).toString()); - } - - /** - * A helper method to determine the value to resume the build with {@code -rf} taking into account the - * edge case where multiple modules in the reactor have the same artifactId. - * <p> - * {@code -rf :artifactId} will pick up the first module which matches, but when multiple modules in the - * reactor have the same artifactId, effective failed module might be later in build reactor. - * This means that developer will either have to type groupId or wait for build execution of all modules - * which were fine, but they are still before one which reported errors. - * <p> - * Then the returned value is {@code groupId:artifactId} when there is a name clash and - * {@code :artifactId} if there is no conflict. - * - * @param mavenProjects Maven projects which are part of build execution. - * @param failedProject Project which has failed. - * @return Value for -rf flag to resume build exactly from place where it failed ({@code :artifactId} in - * general and {@code groupId:artifactId} when there is a name clash). - */ - private String getResumeFromSelector(List<MavenProject> mavenProjects, MavenProject failedProject) { - for (MavenProject buildProject : mavenProjects) { - if (failedProject.getArtifactId().equals(buildProject.getArtifactId()) - && !failedProject.equals(buildProject)) { - return failedProject.getGroupId() + ":" + failedProject.getArtifactId(); - } - } - return ":" + failedProject.getArtifactId(); - } - - private void logSummary( - ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) { - String msg = summary.getMessage(); - - if (!summary.getReference().isEmpty()) { - String referenceKey = - references.computeIfAbsent(summary.getReference(), k -> "[Help " + (references.size() + 1) + "]"); - if (msg.indexOf('\n') < 0) { - msg += " -> " + buffer().strong(referenceKey); - } else { - msg += "\n-> " + buffer().strong(referenceKey); - } - } - - String[] lines = msg.split("(\r\n)|(\r)|(\n)"); - String currentColor = ""; - - for (int i = 0; i < lines.length; i++) { - // add eventual current color inherited from previous line - String line = currentColor + lines[i]; - - // look for last ANSI escape sequence to check if nextColor - Matcher matcher = LAST_ANSI_SEQUENCE.matcher(line); - String nextColor = ""; - if (matcher.find()) { - nextColor = matcher.group(1); - if (ANSI_RESET.equals(nextColor)) { - // last ANSI escape code is reset: no next color - nextColor = ""; - } - } - - // effective line, with indent and reset if end is colored - line = indent + line + ("".equals(nextColor) ? "" : ANSI_RESET); - - if ((i == lines.length - 1) && (showErrors || (summary.getException() instanceof InternalErrorException))) { - slf4jLogger.error(line, summary.getException()); - } else { - slf4jLogger.error(line); - } - - currentColor = nextColor; - } - - indent += " "; - - for (ExceptionSummary child : summary.getChildren()) { - logSummary(child, references, indent, showErrors); - } - } - - private static final Pattern LAST_ANSI_SEQUENCE = Pattern.compile("(\u001B\\[[;\\d]*[ -/]*[@-~])[^\u001B]*$"); - - private static final String ANSI_RESET = "\u001B\u005Bm"; - - private static void configure( - CliRequest cliRequest, - EventSpyDispatcher eventSpyDispatcher, - Map<String, ConfigurationProcessor> configurationProcessors) - throws Exception { - // - // This is not ideal but there are events specifically for configuration from the CLI which I don't - // believe are really valid but there are ITs which assert the right events are published so this - // needs to be supported so the EventSpyDispatcher needs to be put in the CliRequest so that - // it can be accessed by configuration processors. - // - cliRequest.request.setEventSpyDispatcher(eventSpyDispatcher); - - // - // We expect at most 2 implementations to be available. The SettingsXmlConfigurationProcessor implementation - // is always available in the core and likely always will be, but we may have another ConfigurationProcessor - // present supplied by the user. The rule is that we only allow the execution of one ConfigurationProcessor. - // If there is more than one then we execute the one supplied by the user, otherwise we execute the - // the default SettingsXmlConfigurationProcessor. - // - int userSuppliedConfigurationProcessorCount = configurationProcessors.size() - 1; - - if (userSuppliedConfigurationProcessorCount == 0) { - // - // Our settings.xml source is historically how we have configured Maven from the CLI so we are going to - // have to honour its existence forever. So let's run it. - // - configurationProcessors.get(SettingsXmlConfigurationProcessor.HINT).process(cliRequest); - } else if (userSuppliedConfigurationProcessorCount == 1) { - // - // Run the user supplied ConfigurationProcessor - // - for (Entry<String, ConfigurationProcessor> entry : configurationProcessors.entrySet()) { - String hint = entry.getKey(); - if (!hint.equals(SettingsXmlConfigurationProcessor.HINT)) { - ConfigurationProcessor configurationProcessor = entry.getValue(); - configurationProcessor.process(cliRequest); - } - } - } else if (userSuppliedConfigurationProcessorCount > 1) { - // - // There are too many ConfigurationProcessors so we don't know which one to run so report the error. - // - StringBuilder sb = new StringBuilder(String.format( - "\nThere can only be one user supplied ConfigurationProcessor, there are %s:\n\n", - userSuppliedConfigurationProcessorCount)); - for (Entry<String, ConfigurationProcessor> entry : configurationProcessors.entrySet()) { - String hint = entry.getKey(); - if (!hint.equals(SettingsXmlConfigurationProcessor.HINT)) { - ConfigurationProcessor configurationProcessor = entry.getValue(); - sb.append(String.format( - "%s\n", configurationProcessor.getClass().getName())); - } - } - sb.append("\n"); - throw new Exception(sb.toString()); - } - } - - void toolchains(CliRequest cliRequest) throws Exception { - File userToolchainsFile; - - if (cliRequest.commandLine.hasOption(CLIManager.ALTERNATE_USER_TOOLCHAINS)) { - userToolchainsFile = new File(cliRequest.commandLine.getOptionValue(CLIManager.ALTERNATE_USER_TOOLCHAINS)); - userToolchainsFile = resolveFile(userToolchainsFile, cliRequest.workingDirectory); - - if (!userToolchainsFile.isFile()) { - throw new FileNotFoundException( - "The specified user toolchains file does not exist: " + userToolchainsFile); - } - } else { - userToolchainsFile = DEFAULT_USER_TOOLCHAINS_FILE; - } - - File globalToolchainsFile; - - if (cliRequest.commandLine.hasOption(CLIManager.ALTERNATE_GLOBAL_TOOLCHAINS)) { - globalToolchainsFile = - new File(cliRequest.commandLine.getOptionValue(CLIManager.ALTERNATE_GLOBAL_TOOLCHAINS)); - globalToolchainsFile = resolveFile(globalToolchainsFile, cliRequest.workingDirectory); - - if (!globalToolchainsFile.isFile()) { - throw new FileNotFoundException( - "The specified global toolchains file does not exist: " + globalToolchainsFile); - } - } else { - globalToolchainsFile = DEFAULT_GLOBAL_TOOLCHAINS_FILE; - } - - cliRequest.request.setGlobalToolchainsFile(globalToolchainsFile); - cliRequest.request.setUserToolchainsFile(userToolchainsFile); - - DefaultToolchainsBuildingRequest toolchainsRequest = new DefaultToolchainsBuildingRequest(); - if (globalToolchainsFile.isFile()) { - toolchainsRequest.setGlobalToolchainsSource(new FileSource(globalToolchainsFile)); - } - if (userToolchainsFile.isFile()) { - toolchainsRequest.setUserToolchainsSource(new FileSource(userToolchainsFile)); - } - - eventSpyDispatcher.onEvent(toolchainsRequest); - - slf4jLogger.debug( - "Reading global toolchains from {}", - getLocation(toolchainsRequest.getGlobalToolchainsSource(), globalToolchainsFile)); - slf4jLogger.debug( - "Reading user toolchains from {}", - getLocation(toolchainsRequest.getUserToolchainsSource(), userToolchainsFile)); - - ToolchainsBuildingResult toolchainsResult = toolchainsBuilder.build(toolchainsRequest); - - eventSpyDispatcher.onEvent(toolchainsResult); - - executionRequestPopulator.populateFromToolchains(cliRequest.request, toolchainsResult.getEffectiveToolchains()); - - if (!toolchainsResult.getProblems().isEmpty() && slf4jLogger.isWarnEnabled()) { - slf4jLogger.warn(""); - slf4jLogger.warn("Some problems were encountered while building the effective toolchains"); - - for (Problem problem : toolchainsResult.getProblems()) { - slf4jLogger.warn("{} @ {}", problem.getMessage(), problem.getLocation()); - } - - slf4jLogger.warn(""); - } - } - - private Object getLocation(Source source, File defaultLocation) { - if (source != null) { - return source.getLocation(); - } - return defaultLocation; - } - - private void populateRequest(CliRequest cliRequest) { - populateRequest( - cliRequest, - cliRequest.request, - slf4jLogger, - eventSpyDispatcher, - modelProcessor, - createTransferListener(cliRequest), - buildEventListener, - executionListener); - } - - private static void populateRequest( - CliRequest cliRequest, - MavenExecutionRequest request, - Logger slf4jLogger, - EventSpyDispatcher eventSpyDispatcher, - ModelProcessor modelProcessor, - TransferListener transferListener, - BuildEventListener buildEventListener, - LoggingExecutionListener executionListener) { - CommandLine commandLine = cliRequest.commandLine; - String workingDirectory = cliRequest.workingDirectory; - boolean showErrors = cliRequest.showErrors; - - String[] deprecatedOptions = {"up", "npu", "cpu", "npr"}; - for (String deprecatedOption : deprecatedOptions) { - if (commandLine.hasOption(deprecatedOption)) { - slf4jLogger.warn( - "Command line option -{} is deprecated and will be removed in future Maven versions.", - deprecatedOption); - } - } - - // ---------------------------------------------------------------------- - // Now that we have everything that we need we will fire up plexus and - // bring the maven component to life for use. - // ---------------------------------------------------------------------- - - if (commandLine.hasOption(CLIManager.BATCH_MODE)) { - request.setInteractiveMode(false); - } - - boolean noSnapshotUpdates = false; - if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) { - noSnapshotUpdates = true; - } - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - List<String> goals = commandLine.getArgList(); - - boolean recursive = true; - - // this is the default behavior. - String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; - - if (commandLine.hasOption(CLIManager.NON_RECURSIVE)) { - recursive = false; - } - - if (commandLine.hasOption(CLIManager.FAIL_FAST)) { - reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; - } else if (commandLine.hasOption(CLIManager.FAIL_AT_END)) { - reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END; - } else if (commandLine.hasOption(CLIManager.FAIL_NEVER)) { - reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER; - } - - if (commandLine.hasOption(CLIManager.OFFLINE)) { - request.setOffline(true); - } - - boolean updateSnapshots = false; - - if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) { - updateSnapshots = true; - } - - String globalChecksumPolicy = null; - - if (commandLine.hasOption(CLIManager.CHECKSUM_FAILURE_POLICY)) { - globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL; - } else if (commandLine.hasOption(CLIManager.CHECKSUM_WARNING_POLICY)) { - globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN; - } - - File baseDirectory = new File(workingDirectory, "").getAbsoluteFile(); - - // ---------------------------------------------------------------------- - // Profile Activation - // ---------------------------------------------------------------------- - - List<String> activeProfiles = new ArrayList<>(); - - List<String> inactiveProfiles = new ArrayList<>(); - - if (commandLine.hasOption(CLIManager.ACTIVATE_PROFILES)) { - String[] profileOptionValues = commandLine.getOptionValues(CLIManager.ACTIVATE_PROFILES); - if (profileOptionValues != null) { - for (String profileOptionValue : profileOptionValues) { - StringTokenizer profileTokens = new StringTokenizer(profileOptionValue, ","); - - while (profileTokens.hasMoreTokens()) { - String profileAction = profileTokens.nextToken().trim(); - - if (profileAction.startsWith("-") || profileAction.startsWith("!")) { - inactiveProfiles.add(profileAction.substring(1)); - } else if (profileAction.startsWith("+")) { - activeProfiles.add(profileAction.substring(1)); - } else { - activeProfiles.add(profileAction); - } - } - } - } - } - - ExecutionEventLogger executionEventLogger = new ExecutionEventLogger(); - executionListener.init(eventSpyDispatcher.chainListener(executionEventLogger), buildEventListener); - - String alternatePomFile = null; - if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) { - alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE); - } - - request.setBaseDirectory(baseDirectory) - .setGoals(goals) - .setSystemProperties(cliRequest.systemProperties) - .setUserProperties(cliRequest.userProperties) - .setReactorFailureBehavior(reactorFailureBehaviour) // default: fail fast - .setRecursive(recursive) // default: true - .setShowErrors(showErrors) // default: false - .addActiveProfiles(activeProfiles) // optional - .addInactiveProfiles(inactiveProfiles) // optional - .setExecutionListener(executionListener) - .setTransferListener(transferListener) // default: batch mode which goes along with interactive - .setUpdateSnapshots(updateSnapshots) // default: false - .setNoSnapshotUpdates(noSnapshotUpdates) // default: false - .setGlobalChecksumPolicy(globalChecksumPolicy) // default: warn - .setMultiModuleProjectDirectory(cliRequest.getMultiModuleProjectDirectory()); - - if (alternatePomFile != null) { - File pom = resolveFile(new File(alternatePomFile), workingDirectory); - if (pom.isDirectory()) { - pom = new File(pom, "pom.xml"); - } - - request.setPom(pom); - } else if (modelProcessor != null) { - File pom = modelProcessor.locatePom(baseDirectory); - - if (pom.isFile()) { - request.setPom(pom); - } - } - - if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) { - request.setBaseDirectory(request.getPom().getParentFile()); - } - - if (commandLine.hasOption(RESUME)) { - new DefaultBuildResumptionDataRepository() - .applyResumptionData( - request, Paths.get(request.getBaseDirectory()).resolve("target")); - } - - if (commandLine.hasOption(CLIManager.RESUME_FROM)) { - request.setResumeFrom(commandLine.getOptionValue(CLIManager.RESUME_FROM)); - } - - if (commandLine.hasOption(CLIManager.PROJECT_LIST)) { - String[] projectOptionValues = commandLine.getOptionValues(CLIManager.PROJECT_LIST); - - List<String> inclProjects = new ArrayList<>(); - List<String> exclProjects = new ArrayList<>(); - - if (projectOptionValues != null) { - for (String projectOptionValue : projectOptionValues) { - StringTokenizer projectTokens = new StringTokenizer(projectOptionValue, ","); - - while (projectTokens.hasMoreTokens()) { - String projectAction = projectTokens.nextToken().trim(); - - if (projectAction.startsWith("-") || projectAction.startsWith("!")) { - exclProjects.add(projectAction.substring(1)); - } else if (projectAction.startsWith("+")) { - inclProjects.add(projectAction.substring(1)); - } else { - inclProjects.add(projectAction); - } - } - } - } - - request.setSelectedProjects(inclProjects); - request.setExcludedProjects(exclProjects); - } - - if (commandLine.hasOption(CLIManager.ALSO_MAKE) && !commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { - request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_UPSTREAM); - } else if (!commandLine.hasOption(CLIManager.ALSO_MAKE) - && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { - request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM); - } else if (commandLine.hasOption(CLIManager.ALSO_MAKE) - && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { - request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_BOTH); - } - - String localRepoProperty = request.getUserProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); - - if (localRepoProperty == null) { - localRepoProperty = request.getSystemProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); - } - - if (localRepoProperty != null) { - request.setLocalRepositoryPath(localRepoProperty); - } - - request.setCacheNotFound(true); - request.setCacheTransferError(false); - - // - // Builder, concurrency and parallelism - // - // We preserve the existing methods for builder selection which is to look for various inputs in the threading - // configuration. We don't have an easy way to allow a pluggable builder to provide its own configuration - // parameters but this is sufficient for now. Ultimately we want components like Builders to provide a way to - // extend the command line to accept its own configuration parameters. - // - final String threadConfiguration = - commandLine.hasOption(CLIManager.THREADS) ? commandLine.getOptionValue(CLIManager.THREADS) : null; - - if (threadConfiguration != null) { - // - // Default to the standard multithreaded builder - // - request.setBuilderId("multithreaded"); - - if (threadConfiguration.contains("C")) { - request.setDegreeOfConcurrency(calculateDegreeOfConcurrencyWithCoreMultiplier(threadConfiguration)); - } else { - request.setDegreeOfConcurrency(Integer.parseInt(threadConfiguration)); - } - } - - // - // Allow the builder to be overridden by the user if requested. The builders are now pluggable. - // - if (commandLine.hasOption(CLIManager.BUILDER)) { - request.setBuilderId(commandLine.getOptionValue(CLIManager.BUILDER)); - } - } - - static int calculateDegreeOfConcurrencyWithCoreMultiplier(String threadConfiguration) { - int procs = Runtime.getRuntime().availableProcessors(); - return (int) (Float.parseFloat(threadConfiguration.replace("C", "")) * procs); - } - - static File resolveFile(File file, String workingDirectory) { - if (file == null) { - return null; - } else if (file.isAbsolute()) { - return file; - } else if (file.getPath().startsWith(File.separator)) { - // drive-relative Windows path - return file.getAbsoluteFile(); - } else { - return new File(workingDirectory, file.getPath()).getAbsoluteFile(); - } - } - - // ---------------------------------------------------------------------- - // System properties handling - // ---------------------------------------------------------------------- - - static void populateProperties(CliRequest cliRequest, Properties systemProperties, Properties userProperties) - throws InterpolationException { - addEnvVars(systemProperties); - - // ---------------------------------------------------------------------- - // Options that are set on the command line become system properties - // and therefore are set in the session properties. System properties - // are most dominant. - // ---------------------------------------------------------------------- - - Properties cliProperties = new Properties(); - if (cliRequest.commandLine.hasOption(CLIManager.SET_SYSTEM_PROPERTY)) { - String[] defStrs = cliRequest.commandLine.getOptionValues(CLIManager.SET_SYSTEM_PROPERTY); - - if (defStrs != null) { - for (String defStr : defStrs) { - setCliProperty(defStr, cliProperties); - } - } - } - - SystemProperties.addSystemProperties(systemProperties); - - StringSearchInterpolator interpolator = createInterpolator(cliRequest, cliProperties, systemProperties); - for (Map.Entry<Object, Object> e : cliProperties.entrySet()) { - String name = (String) e.getKey(); - String value = interpolator.interpolate((String) e.getValue()); - userProperties.setProperty(name, value); - } - - // ---------------------------------------------------------------------- - // Properties containing info about the currently running version of Maven - // These override any corresponding properties set on the command line - // ---------------------------------------------------------------------- - - Properties buildProperties = CLIReportingUtils.getBuildProperties(); - - String mavenVersion = buildProperties.getProperty(CLIReportingUtils.BUILD_VERSION_PROPERTY); - systemProperties.setProperty("maven.version", mavenVersion); - - String mavenBuildVersion = CLIReportingUtils.createMavenVersionString(buildProperties); - systemProperties.setProperty("maven.build.version", mavenBuildVersion); - } - - public static void addEnvVars(Properties props) { - if (props != null) { - boolean caseSensitive = Os.current() == Os.WINDOWS; - for (Map.Entry<String, String> entry : System.getenv().entrySet()) { - String key = "env." - + (caseSensitive ? entry.getKey() : entry.getKey().toUpperCase(Locale.ENGLISH)); - props.setProperty(key, entry.getValue()); - } - } - } - - private static void setCliProperty(String property, Properties properties) { - String name; - - String value; - - int i = property.indexOf('='); - - if (i <= 0) { - name = property.trim(); - - value = "true"; - } else { - name = property.substring(0, i).trim(); - - value = property.substring(i + 1); - } - - properties.setProperty(name, value); - - // ---------------------------------------------------------------------- - // I'm leaving the setting of system properties here as not to break - // the SystemPropertyProfileActivator. This won't harm embedding. jvz. - // ---------------------------------------------------------------------- - - System.setProperty(name, value); - } - - static class ExitException extends Exception { - static final long serialVersionUID = 1L; - int exitCode; - - ExitException(int exitCode) { - this.exitCode = exitCode; - } - } - - // - // Customizations available via the CLI - // - - protected TransferListener createTransferListener(CliRequest cliRequest) { - if (cliRequest.quiet || cliRequest.commandLine.hasOption(CLIManager.NO_TRANSFER_PROGRESS)) { - return new QuietMavenTransferListener(); - } else if (cliRequest.request.isInteractiveMode() && !cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) { - // - // If we're logging to a file then we don't want the console transfer listener as it will spew - // download progress all over the place - // - return getConsoleTransferListener(); - } else { - return getBatchTransferListener(); - } - } - - protected TransferListener getConsoleTransferListener() { - return new DaemonMavenTransferListener(buildEventListener, new Slf4jMavenTransferListener()); - } - - protected TransferListener getBatchTransferListener() { - return new Slf4jMavenTransferListener(); - } - - protected ModelProcessor createModelProcessor(PlexusContainer container) throws ComponentLookupException { - return container.lookup(ModelProcessor.class); - } -} diff --git a/daemon-m39/src/main/java/org/apache/maven/project/SnapshotModelCache.java b/daemon-m39/src/main/java/org/apache/maven/project/SnapshotModelCache.java deleted file mode 100644 index 8d7d20ea..00000000 --- a/daemon-m39/src/main/java/org/apache/maven/project/SnapshotModelCache.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.project; - -import java.util.Objects; - -import org.apache.maven.model.building.ModelCache; - -public class SnapshotModelCache implements ModelCache { - - private final ModelCache globalCache; - private final ModelCache reactorCache; - - public SnapshotModelCache(ModelCache globalCache, ModelCache reactorCache) { - this.globalCache = Objects.requireNonNull(globalCache); - this.reactorCache = Objects.requireNonNull(reactorCache); - } - - @Override - public void put(String groupId, String artifactId, String version, String tag, Object data) { - getDelegate(version).put(groupId, artifactId, version, tag, data); - } - - @Override - public Object get(String groupId, String artifactId, String version, String tag) { - return getDelegate(version).get(groupId, artifactId, version, tag); - } - - private ModelCache getDelegate(String version) { - return version.contains("SNAPSHOT") || version.contains("${") ? reactorCache : globalCache; - } -} diff --git a/daemon-m39/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java b/daemon-m39/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java deleted file mode 100644 index abb49f50..00000000 --- a/daemon-m39/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.project; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.model.building.ModelCache; -import org.apache.maven.repository.internal.DefaultModelCacheFactory; -import org.apache.maven.repository.internal.ModelCacheFactory; -import org.eclipse.aether.DefaultRepositoryCache; -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.sisu.Priority; - -import static org.mvndaemon.mvnd.common.Environment.MVND_NO_MODEL_CACHE; - -@Singleton -@Named -@Priority(10) -public class SnapshotModelCacheFactory implements ModelCacheFactory { - - private final ModelCacheFactory factory; - private final ModelCache globalCache; - - @Inject - public SnapshotModelCacheFactory(DefaultModelCacheFactory factory) { - this.factory = factory; - DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(); - session.setCache(new DefaultRepositoryCache()); - this.globalCache = factory.createCache(session); - } - - @Override - public ModelCache createCache(RepositorySystemSession session) { - boolean noModelCache = - Boolean.parseBoolean(MVND_NO_MODEL_CACHE.asOptional().orElse(MVND_NO_MODEL_CACHE.getDefault())); - ModelCache reactorCache = factory.createCache(session); - ModelCache globalCache = noModelCache ? reactorCache : this.globalCache; - return new SnapshotModelCache(globalCache, reactorCache); - } -} diff --git a/daemon-m39/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginDescriptorCache.java b/daemon-m39/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginDescriptorCache.java deleted file mode 100644 index 0d8b924f..00000000 --- a/daemon-m39/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginDescriptorCache.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.mvndaemon.mvnd.cache.invalidating; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.DefaultPluginDescriptorCache; -import org.apache.maven.plugin.InvalidPluginDescriptorException; -import org.apache.maven.plugin.PluginDescriptorParsingException; -import org.apache.maven.plugin.PluginResolutionException; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.sisu.Priority; -import org.mvndaemon.mvnd.cache.Cache; -import org.mvndaemon.mvnd.cache.CacheFactory; -import org.mvndaemon.mvnd.cache.CacheRecord; - -@Singleton -@Named -@Priority(10) -public class InvalidatingPluginDescriptorCache extends DefaultPluginDescriptorCache { - - protected static class Record implements CacheRecord { - - private final PluginDescriptor descriptor; - - public Record(PluginDescriptor descriptor) { - this.descriptor = descriptor; - } - - @Override - public Stream<Path> getDependencyPaths() { - return Optional.ofNullable(descriptor.getArtifacts()).orElse(Collections.emptyList()).stream() - .map(artifact -> artifact.getFile().toPath()); - } - - @Override - public void invalidate() { - ClassRealm realm = descriptor.getClassRealm(); - if (realm == null) { - return; - } - try { - realm.getWorld().disposeRealm(realm.getId()); - } catch (NoSuchRealmException e) { - // ignore - } - } - } - - final Cache<Key, Record> cache; - - @Inject - public InvalidatingPluginDescriptorCache(CacheFactory cacheFactory) { - this.cache = cacheFactory.newCache(); - } - - @Override - public Key createKey(Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session) { - return super.createKey(plugin, repositories, session); - } - - @Override - public PluginDescriptor get(Key key) { - Record r = cache.get(key); - return r != null ? clone(r.descriptor) : null; - } - - @Override - public PluginDescriptor get(Key key, PluginDescriptorSupplier supplier) - throws PluginDescriptorParsingException, PluginResolutionException, InvalidPluginDescriptorException { - try { - Record r = cache.computeIfAbsent(key, k -> { - try { - return new Record(clone(supplier.load())); - } catch (PluginDescriptorParsingException - | PluginResolutionException - | InvalidPluginDescriptorException e) { - throw new RuntimeException(e); - } - }); - return clone(r.descriptor); - } catch (RuntimeException e) { - if (e.getCause() instanceof PluginDescriptorParsingException) { - throw (PluginDescriptorParsingException) e.getCause(); - } - if (e.getCause() instanceof PluginResolutionException) { - throw (PluginResolutionException) e.getCause(); - } - if (e.getCause() instanceof InvalidPluginDescriptorException) { - throw (InvalidPluginDescriptorException) e.getCause(); - } - throw e; - } - } - - @Override - public void put(Key key, PluginDescriptor descriptor) { - cache.put(key, new Record(clone(descriptor))); - } - - @Override - public void flush() { - cache.clear(); - } -} diff --git a/daemon-m39/src/main/java/org/mvndaemon/mvnd/plugin/CachingPluginVersionResolver.java b/daemon-m39/src/main/java/org/mvndaemon/mvnd/plugin/CachingPluginVersionResolver.java deleted file mode 100644 index 19c73f9b..00000000 --- a/daemon-m39/src/main/java/org/mvndaemon/mvnd/plugin/CachingPluginVersionResolver.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.mvndaemon.mvnd.plugin; - -import javax.inject.Named; -import javax.inject.Singleton; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.apache.maven.plugin.version.PluginVersionRequest; -import org.apache.maven.plugin.version.PluginVersionResolutionException; -import org.apache.maven.plugin.version.PluginVersionResolver; -import org.apache.maven.plugin.version.PluginVersionResult; -import org.apache.maven.plugin.version.internal.DefaultPluginVersionResolver; -import org.eclipse.aether.SessionData; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.sisu.Priority; -import org.eclipse.sisu.Typed; - -@Named -@Singleton -@Priority(10) -@Typed(PluginVersionResolver.class) -public class CachingPluginVersionResolver extends DefaultPluginVersionResolver { - - private static final Object CACHE_KEY = new Object(); - - @Override - public PluginVersionResult resolve(PluginVersionRequest request) throws PluginVersionResolutionException { - Map<String, PluginVersionResult> cache = - getCache(request.getRepositorySession().getData()); - String key = getKey(request); - PluginVersionResult result = cache.get(key); - if (result == null) { - result = super.resolve(request); - cache.putIfAbsent(key, result); - } - return result; - } - - @SuppressWarnings("unchecked") - private Map<String, PluginVersionResult> getCache(SessionData data) { - Map<String, PluginVersionResult> cache = (Map<String, PluginVersionResult>) data.get(CACHE_KEY); - while (cache == null) { - cache = new ConcurrentHashMap<>(256); - if (data.set(CACHE_KEY, null, cache)) { - break; - } - cache = (Map<String, PluginVersionResult>) data.get(CACHE_KEY); - } - return cache; - } - - private static String getKey(PluginVersionRequest request) { - return Stream.concat( - Stream.of(request.getGroupId(), request.getArtifactId()), - request.getRepositories().stream().map(RemoteRepository::getId)) - .collect(Collectors.joining(":")); - } -} diff --git a/daemon-m40/pom.xml b/daemon-m40/pom.xml deleted file mode 100644 index 490871a2..00000000 --- a/daemon-m40/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Copyright 2019 the original author or authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd</artifactId> - <version>1.0-m9-SNAPSHOT</version> - </parent> - - <artifactId>mvnd-daemon-m40</artifactId> - - <packaging>jar</packaging> - <name>Maven Daemon - Daemon 4.0.x specifics</name> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-core</artifactId> - <version>${maven4.version}</version> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-embedder</artifactId> - <version>${maven4.version}</version> - </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-daemon</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.eclipse.sisu</groupId> - <artifactId>sisu-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - -</project> diff --git a/daemon-m40/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginRealmCache.java b/daemon-m40/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginRealmCache.java deleted file mode 100644 index 805866e5..00000000 --- a/daemon-m40/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginRealmCache.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.mvndaemon.mvnd.cache.invalidating; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import java.nio.file.Path; -import java.util.List; -import java.util.stream.Stream; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.DefaultPluginRealmCache; -import org.apache.maven.plugin.PluginContainerException; -import org.apache.maven.plugin.PluginResolutionException; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; -import org.eclipse.sisu.Priority; -import org.mvndaemon.mvnd.cache.Cache; -import org.mvndaemon.mvnd.cache.CacheFactory; - -@Singleton -@Named -@Priority(10) -public class InvalidatingPluginRealmCache extends DefaultPluginRealmCache { - - protected static class Record implements org.mvndaemon.mvnd.cache.CacheRecord { - - final CacheRecord record; - - public Record(CacheRecord record) { - this.record = record; - } - - @Override - public Stream<Path> getDependencyPaths() { - return record.getArtifacts().stream() - .map(artifact -> artifact.getFile().toPath()); - } - - @Override - public void invalidate() { - ClassRealm realm = record.getRealm(); - try { - realm.getWorld().disposeRealm(realm.getId()); - } catch (NoSuchRealmException e) { - // ignore - } - } - } - - final Cache<Key, Record> cache; - - @Inject - public InvalidatingPluginRealmCache(CacheFactory cacheFactory) { - cache = cacheFactory.newCache(); - } - - @Override - public CacheRecord get(Key key) { - Record r = cache.get(key); - return r != null ? r.record : null; - } - - @Override - public CacheRecord get(Key key, PluginRealmSupplier supplier) - throws PluginResolutionException, PluginContainerException { - try { - Record r = cache.computeIfAbsent(key, k -> { - try { - return new Record(supplier.load()); - } catch (PluginResolutionException | PluginContainerException e) { - throw new RuntimeException(e); - } - }); - return r.record; - } catch (RuntimeException e) { - if (e.getCause() instanceof PluginResolutionException) { - throw (PluginResolutionException) e.getCause(); - } - if (e.getCause() instanceof PluginContainerException) { - throw (PluginContainerException) e.getCause(); - } - throw e; - } - } - - @Override - public CacheRecord put(Key key, ClassRealm pluginRealm, List<Artifact> pluginArtifacts) { - CacheRecord record = super.put(key, pluginRealm, pluginArtifacts); - super.cache.remove(key); - cache.put(key, new Record(record)); - return record; - } - - @Override - public void flush() { - cache.clear(); - } - - @Override - public void register(MavenProject project, Key key, CacheRecord record) {} -} diff --git a/daemon-m40/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingRealmCacheEventSpy.java b/daemon-m40/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingRealmCacheEventSpy.java deleted file mode 100644 index e69da0a0..00000000 --- a/daemon-m40/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingRealmCacheEventSpy.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.mvndaemon.mvnd.cache.invalidating; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.nio.file.PathMatcher; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.eventspy.AbstractEventSpy; -import org.apache.maven.eventspy.EventSpy; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionResult; -import org.apache.maven.project.MavenProject; -import org.eclipse.sisu.Typed; -import org.mvndaemon.mvnd.common.Environment; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Named -@Singleton -@Typed(EventSpy.class) -public class InvalidatingRealmCacheEventSpy extends AbstractEventSpy { - - private static final Logger LOG = LoggerFactory.getLogger(InvalidatingRealmCacheEventSpy.class); - - private final InvalidatingPluginRealmCache pluginCache; - private final InvalidatingExtensionRealmCache extensionCache; - private final InvalidatingProjectArtifactsCache projectArtifactsCache; - private Path multiModuleProjectDirectory; - private String pattern; - private PathMatcher matcher; - - @Inject - public InvalidatingRealmCacheEventSpy( - InvalidatingPluginRealmCache cache, - InvalidatingExtensionRealmCache extensionCache, - InvalidatingProjectArtifactsCache projectArtifactsCache) { - this.pluginCache = cache; - this.extensionCache = extensionCache; - this.projectArtifactsCache = projectArtifactsCache; - } - - @Override - public void onEvent(Object event) throws Exception { - try { - if (event instanceof MavenExecutionRequest) { - /* Store the multiModuleProjectDirectory path */ - multiModuleProjectDirectory = ((MavenExecutionRequest) event) - .getMultiModuleProjectDirectory() - .toPath(); - pattern = Environment.MVND_PLUGIN_REALM_EVICT_PATTERN - .asOptional() - .orElse(Environment.MVND_PLUGIN_REALM_EVICT_PATTERN.getDefault()); - if (!pattern.isEmpty()) { - String[] patterns = pattern.split(","); - List<PathMatcher> matchers = new ArrayList<>(); - for (String pattern : patterns) { - if (pattern.startsWith("mvn:")) { - String[] parts = pattern.substring("mvn:".length()).split(":"); - String groupId, artifactId, version; - if (parts.length >= 3) { - version = parts[2]; - } else { - version = "*"; - } - if (parts.length >= 2) { - groupId = parts[0]; - artifactId = parts[1]; - } else { - groupId = "*"; - artifactId = parts[0]; - } - pattern = "glob:**/" + ("*".equals(groupId) ? "" : groupId.replace('.', '/') + "/") - + artifactId + "/" + ("*".equals(version) ? "**" : version + "/**"); - } - matchers.add(getPathMatcher(pattern)); - } - if (matchers.size() == 1) { - matcher = matchers.iterator().next(); - } else { - matcher = path -> matchers.stream().anyMatch(f -> f.matches(path)); - } - } - } else if (event instanceof MavenExecutionResult) { - /* Evict the entries referring to jars under multiModuleProjectDirectory */ - pluginCache.cache.removeIf(this::shouldEvict); - extensionCache.cache.removeIf(this::shouldEvict); - MavenExecutionResult mer = (MavenExecutionResult) event; - List<MavenProject> projects = mer.getTopologicallySortedProjects(); - projectArtifactsCache.cache.removeIf( - (k, r) -> shouldEvict(projects, (InvalidatingProjectArtifactsCache.CacheKey) k, r)); - } - } catch (Exception e) { - LOG.warn("Could not notify CliPluginRealmCache", e); - } - } - - private boolean shouldEvict( - List<MavenProject> projects, - InvalidatingProjectArtifactsCache.CacheKey k, - InvalidatingProjectArtifactsCache.Record v) { - return projects.stream().anyMatch(p -> k.matches(p.getGroupId(), p.getArtifactId(), p.getVersion())); - } - - private boolean shouldEvict(InvalidatingPluginRealmCache.Key k, InvalidatingPluginRealmCache.Record v) { - try { - for (URL url : v.record.getRealm().getURLs()) { - if (url.getProtocol().equals("file")) { - final Path path = Paths.get(url.toURI()); - if (path.startsWith(multiModuleProjectDirectory)) { - LOG.debug( - "Removing PluginRealmCache entry {} because it refers to an artifact in the build tree {}", - k, - path); - return true; - } else if (matcher != null && matcher.matches(path)) { - LOG.debug( - "Removing PluginRealmCache entry {} because its components {} matches the eviction pattern '{}'", - k, - path, - pattern); - return true; - } - } - } - return false; - } catch (URISyntaxException e) { - return true; - } - } - - private boolean shouldEvict(InvalidatingExtensionRealmCache.Key k, InvalidatingExtensionRealmCache.Record v) { - try { - for (URL url : v.record.getRealm().getURLs()) { - if (url.getProtocol().equals("file")) { - final Path path = Paths.get(url.toURI()); - if (path.startsWith(multiModuleProjectDirectory)) { - LOG.debug( - "Removing ExtensionRealmCache entry {} because it refers to an artifact in the build tree {}", - k, - path); - return true; - } else if (matcher != null && matcher.matches(path)) { - LOG.debug( - "Removing ExtensionRealmCache entry {} because its components {} matches the eviction pattern '{}'", - k, - path, - pattern); - return true; - } - } - } - return false; - } catch (URISyntaxException e) { - return true; - } - } - - private static PathMatcher getPathMatcher(String pattern) { - if (!pattern.startsWith("glob:") && !pattern.startsWith("regex:")) { - pattern = "glob:" + pattern; - } - return FileSystems.getDefault().getPathMatcher(pattern); - } -} diff --git a/daemon/pom.xml b/daemon/pom.xml index 4901475a..4bff4949 100644 --- a/daemon/pom.xml +++ b/daemon/pom.xml @@ -32,7 +32,7 @@ <properties> <!-- If using release, sun.misc is not reachable (see SignalHelper) --> - <maven.compiler.release /> + <!-- <maven.compiler.release />--> </properties> <dependencies> @@ -54,6 +54,10 @@ <groupId>org.apache.maven.daemon</groupId> <artifactId>mvnd-logging</artifactId> </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-embedder</artifactId> diff --git a/daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java similarity index 100% rename from daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java rename to daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java diff --git a/daemon-m40/src/main/java/org/apache/maven/project/SnapshotModelCache.java b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java similarity index 100% rename from daemon-m40/src/main/java/org/apache/maven/project/SnapshotModelCache.java rename to daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java diff --git a/daemon-m40/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java similarity index 100% rename from daemon-m40/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java rename to daemon/src/main/java/org/apache/maven/project/SnapshotModelCacheFactory.java diff --git a/daemon-m40/src/main/java/org/apache/maven/settings/SettingsUtilsV4.java b/daemon/src/main/java/org/apache/maven/settings/SettingsUtilsV4.java similarity index 100% rename from daemon-m40/src/main/java/org/apache/maven/settings/SettingsUtilsV4.java rename to daemon/src/main/java/org/apache/maven/settings/SettingsUtilsV4.java diff --git a/daemon-m40/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginDescriptorCache.java b/daemon/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginDescriptorCache.java similarity index 100% rename from daemon-m40/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginDescriptorCache.java rename to daemon/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginDescriptorCache.java diff --git a/daemon-m39/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginRealmCache.java b/daemon/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginRealmCache.java similarity index 100% rename from daemon-m39/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginRealmCache.java rename to daemon/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingPluginRealmCache.java diff --git a/daemon-m39/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingRealmCacheEventSpy.java b/daemon/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingRealmCacheEventSpy.java similarity index 100% rename from daemon-m39/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingRealmCacheEventSpy.java rename to daemon/src/main/java/org/mvndaemon/mvnd/cache/invalidating/InvalidatingRealmCacheEventSpy.java diff --git a/daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionAnalyzer.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionAnalyzer.java similarity index 100% rename from daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionAnalyzer.java rename to daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionAnalyzer.java diff --git a/daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionData.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionData.java similarity index 100% rename from daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionData.java rename to daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionData.java diff --git a/daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionDataRepository.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionDataRepository.java similarity index 100% rename from daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionDataRepository.java rename to daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionDataRepository.java diff --git a/daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionPersistenceException.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionPersistenceException.java similarity index 100% rename from daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionPersistenceException.java rename to daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionPersistenceException.java diff --git a/daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionAnalyzer.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionAnalyzer.java similarity index 100% rename from daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionAnalyzer.java rename to daemon/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionAnalyzer.java diff --git a/daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionDataRepository.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionDataRepository.java similarity index 100% rename from daemon-m39/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionDataRepository.java rename to daemon/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionDataRepository.java diff --git a/daemon-m40/src/main/java/org/mvndaemon/mvnd/plugin/CachingPluginVersionResolver.java b/daemon/src/main/java/org/mvndaemon/mvnd/plugin/CachingPluginVersionResolver.java similarity index 100% rename from daemon-m40/src/main/java/org/mvndaemon/mvnd/plugin/CachingPluginVersionResolver.java rename to daemon/src/main/java/org/mvndaemon/mvnd/plugin/CachingPluginVersionResolver.java diff --git a/dist-m39/src/main/provisio/maven-distro.xml b/dist-m39/src/main/provisio/maven-distro.xml deleted file mode 100644 index caa8d6ed..00000000 --- a/dist-m39/src/main/provisio/maven-distro.xml +++ /dev/null @@ -1,96 +0,0 @@ -<!-- - - Copyright 2019-2021 the original author or authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<assembly> - - <artifactSet to="/mvn"> - <artifact id="org.apache.maven:apache-maven:tar.gz:bin:${maven3.version}"> - <unpack useRoot="false" - excludes="lib/maven-slf4j-*" /> - </artifact> - </artifactSet> - - <artifactSet to="/mvn/lib"> - <artifact id="org.apache.maven.daemon:mvnd-logging:${project.version}"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.slf4j:jul-to-slf4j"> - <exclusion id="*:*"/> - </artifact> - </artifactSet> - - <artifactSet to="/mvn/lib/mvnd"> - <artifact id="io.takari.maven:takari-smart-builder:${takari-smart-builder.version}"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.apache.maven.daemon:mvnd-daemon:${project.version}"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.apache.maven.daemon:mvnd-daemon-m39:${project.version}"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.apache.maven.daemon:mvnd-client:${project.version}"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.apache.maven.daemon:mvnd-common:${project.version}"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.apache.maven.daemon:mvnd-agent:${project.version}"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.apache.maven.daemon:mvnd-helper-agent:${project.version}"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.apache.maven.daemon:mvnd-native:${project.version}"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.codehaus.plexus:plexus-interactivity-api"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.jline:jline-terminal"> - <exclusion id="*:*"/> - </artifact> - <artifact id="org.jline:jline-terminal-jansi"> - <exclusion id="*:*"/> - </artifact> - </artifactSet> - - <fileSet to="/"> - <directory path="${basedir}/../dist/src/main/distro"/> - <directory path="${basedir}/.."> - <include>NOTICE.txt</include> - <include>LICENSE.txt</include> - <include>README.adoc</include> - </directory> - </fileSet> - <fileSet to="/bin"> - <directory path="${basedir}/../client/target"> - <include>mvnd</include> - <include>mvnd.exe</include> - </directory> - <directory path="${basedir}/../dist/src/main/resources"> - <include>platform-${os.detected.name}-${os.detected.arch}</include> - </directory> - </fileSet> - - <archive name="maven-mvnd-${project.version}-m39-${os.detected.name}-${os.detected.arch}.zip" - executable="**/bin/mvnd"/> - - <archive name="maven-mvnd-${project.version}-m39-${os.detected.name}-${os.detected.arch}.tar.gz" - executable="**/bin/mvnd"/> - -</assembly> diff --git a/dist-m40/pom.xml b/dist-m40/pom.xml deleted file mode 100644 index 5c154928..00000000 --- a/dist-m40/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Copyright 2019-2021 the original author or authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd</artifactId> - <version>1.0-m9-SNAPSHOT</version> - </parent> - - <artifactId>mvnd-dist-m40</artifactId> - - <packaging>pom</packaging> - <name>Maven Daemon - Distribution for 4.0.x</name> - - <properties> - <maven.compiler.target>11</maven.compiler.target> - <maven.compiler.source>11</maven.compiler.source> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-agent</artifactId> - </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-helper-agent</artifactId> - </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-client</artifactId> - </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-daemon</artifactId> - </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-daemon-m40</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>ca.vanzyl.provisio.maven.plugins</groupId> - <artifactId>provisio-maven-plugin</artifactId> - <executions> - <execution> - <id>maven-distro</id> - <goals> - <goal>provision</goal> - </goals> - <phase>package</phase> - <configuration> - <outputDirectory>${project.build.directory}/maven-mvnd-${project.version}-m40-${os.detected.name}-${os.detected.arch}</outputDirectory> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> diff --git a/dist-m39/pom.xml b/dist/pom.xml similarity index 88% rename from dist-m39/pom.xml rename to dist/pom.xml index 8627f5ae..0a4b5c54 100644 --- a/dist-m39/pom.xml +++ b/dist/pom.xml @@ -25,10 +25,10 @@ <version>1.0-m9-SNAPSHOT</version> </parent> - <artifactId>mvnd-dist-m39</artifactId> + <artifactId>mvnd-dist</artifactId> <packaging>pom</packaging> - <name>Maven Daemon - Distribution for 3.9.x</name> + <name>Maven Daemon - Distribution</name> <properties> <maven.compiler.target>11</maven.compiler.target> @@ -52,10 +52,6 @@ <groupId>org.apache.maven.daemon</groupId> <artifactId>mvnd-daemon</artifactId> </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-daemon-m39</artifactId> - </dependency> </dependencies> <build> @@ -71,7 +67,7 @@ </goals> <phase>package</phase> <configuration> - <outputDirectory>${project.build.directory}/maven-mvnd-${project.version}-m39-${os.detected.name}-${os.detected.arch}</outputDirectory> + <outputDirectory>${project.build.directory}/maven-mvnd-${project.version}-${os.detected.name}-${os.detected.arch}</outputDirectory> </configuration> </execution> </executions> diff --git a/dist-m40/src/main/provisio/maven-distro.xml b/dist/src/main/provisio/maven-distro.xml similarity index 90% rename from dist-m40/src/main/provisio/maven-distro.xml rename to dist/src/main/provisio/maven-distro.xml index 0faf498f..29e23b5f 100644 --- a/dist-m40/src/main/provisio/maven-distro.xml +++ b/dist/src/main/provisio/maven-distro.xml @@ -18,7 +18,7 @@ <assembly> <artifactSet to="/mvn"> - <artifact id="org.apache.maven:apache-maven:tar.gz:bin:${maven4.version}"> + <artifact id="org.apache.maven:apache-maven:tar.gz:bin:${maven.version}"> <unpack useRoot="false" excludes="lib/maven-slf4j-*,lib/plexus-utils-3.*" /> </artifact> @@ -43,9 +43,6 @@ <artifact id="org.apache.maven.daemon:mvnd-daemon:${project.version}"> <exclusion id="*:*"/> </artifact> - <artifact id="org.apache.maven.daemon:mvnd-daemon-m40:${project.version}"> - <exclusion id="*:*"/> - </artifact> <artifact id="org.apache.maven.daemon:mvnd-client:${project.version}"> <exclusion id="*:*"/> </artifact> @@ -90,10 +87,10 @@ </directory> </fileSet> - <archive name="maven-mvnd-${project.version}-m40-${os.detected.name}-${os.detected.arch}.zip" + <archive name="maven-mvnd-${project.version}-${os.detected.name}-${os.detected.arch}.zip" executable="**/bin/mvnd"/> - <archive name="maven-mvnd-${project.version}-m40-${os.detected.name}-${os.detected.arch}.tar.gz" + <archive name="maven-mvnd-${project.version}-${os.detected.name}-${os.detected.arch}.tar.gz" executable="**/bin/mvnd"/> </assembly> diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 12f20a9c..d37e7dce 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -32,8 +32,7 @@ <properties> <maven.compiler.target>11</maven.compiler.target> <maven.compiler.source>11</maven.compiler.source> - <mvnd.m39.home>${project.basedir}/../dist-m39/target/maven-mvnd-${project.version}-m39-${os.detected.name}-${os.detected.arch}</mvnd.m39.home> - <mvnd.m40.home>${project.basedir}/../dist-m40/target/maven-mvnd-${project.version}-m40-${os.detected.name}-${os.detected.arch}</mvnd.m40.home> + <mvnd.home>${project.basedir}/../dist/target/maven-mvnd-${project.version}-${os.detected.name}-${os.detected.arch}</mvnd.home> <preinstall.artifacts>org/apache/maven/surefire/surefire-providers/${surefire.version} org/apache/maven/surefire/surefire-junit-platform/${surefire.version} org/junit/platform/junit-platform-launcher/${junit-platform-launcher.version} @@ -58,19 +57,7 @@ </dependency> <dependency> <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-dist-m39</artifactId> - <type>pom</type> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-dist-m40</artifactId> + <artifactId>mvnd-dist</artifactId> <type>pom</type> <scope>test</scope> <exclusions> @@ -130,25 +117,7 @@ <phase>test</phase> <configuration> <systemPropertyVariables> - <mvnd.home>${mvnd.m39.home}</mvnd.home> - <project.version>${project.version}</project.version> - <mrm.repository.url>${mrm.repository.url}</mrm.repository.url> - <os.detected.name>${os.detected.name}</os.detected.name> - <os.detected.arch>${os.detected.arch}</os.detected.arch> - <mvnd.test.hostLocalMavenRepo>${settings.localRepository}</mvnd.test.hostLocalMavenRepo> - <preinstall.artifacts>${preinstall.artifacts}</preinstall.artifacts> - </systemPropertyVariables> - </configuration> - </execution> - <execution> - <id>mvn-40</id> - <goals> - <goal>test</goal> - </goals> - <phase>test</phase> - <configuration> - <systemPropertyVariables> - <mvnd.home>${mvnd.m40.home}</mvnd.home> + <mvnd.home>${mvnd.home}</mvnd.home> <project.version>${project.version}</project.version> <mrm.repository.url>${mrm.repository.url}</mrm.repository.url> <os.detected.name>${os.detected.name}</os.detected.name> @@ -235,25 +204,7 @@ <configuration> <systemPropertyVariables> <project.version>${project.version}</project.version> - <mvnd.home>${mvnd.m39.home}</mvnd.home> - <mrm.repository.url>${mrm.repository.url}</mrm.repository.url> - <os.detected.name>${os.detected.name}</os.detected.name> - <os.detected.arch>${os.detected.arch}</os.detected.arch> - <mvnd.test.hostLocalMavenRepo>${settings.localRepository}</mvnd.test.hostLocalMavenRepo> - <preinstall.artifacts>${preinstall.artifacts}</preinstall.artifacts> - </systemPropertyVariables> - </configuration> - </execution> - <execution> - <id>native-40</id> - <goals> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - <configuration> - <systemPropertyVariables> - <project.version>${project.version}</project.version> - <mvnd.home>${mvnd.m40.home}</mvnd.home> + <mvnd.home>${mvnd.home}</mvnd.home> <mrm.repository.url>${mrm.repository.url}</mrm.repository.url> <os.detected.name>${os.detected.name}</os.detected.name> <os.detected.arch>${os.detected.arch}</os.detected.arch> diff --git a/logging/pom.xml b/logging/pom.xml index acf3b3ea..f55888cd 100644 --- a/logging/pom.xml +++ b/logging/pom.xml @@ -76,7 +76,7 @@ <artifactItem> <groupId>org.apache.maven</groupId> <artifactId>maven-slf4j-wrapper</artifactId> - <version>${maven4.version}</version> + <version>${maven.version}</version> <classifier>sources</classifier> </artifactItem> <artifactItem> diff --git a/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/LoggingExecutionListener.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/LoggingExecutionListener.java index eccd2ba7..233796f9 100644 --- a/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/LoggingExecutionListener.java +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/LoggingExecutionListener.java @@ -29,11 +29,9 @@ import org.apache.maven.execution.ProjectExecutionEvent; import org.apache.maven.execution.ProjectExecutionListener; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.internal.ReactorBuildStatus; -import org.eclipse.sisu.Typed; @Singleton @Named -@Typed({LoggingExecutionListener.class, ExecutionListener.class, ProjectExecutionListener.class}) public class LoggingExecutionListener implements ExecutionListener, ProjectExecutionListener { private ExecutionListener delegate; diff --git a/pom.xml b/pom.xml index e7cf0800..cf6c617f 100644 --- a/pom.xml +++ b/pom.xml @@ -52,10 +52,7 @@ <module>client</module> <module>logging</module> <module>daemon</module> - <module>daemon-m39</module> - <module>daemon-m40</module> - <module>dist-m39</module> - <module>dist-m40</module> + <module>dist</module> <module>integration-tests</module> </modules> @@ -68,9 +65,8 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <maven.compiler.target>8</maven.compiler.target> - <maven.compiler.source>8</maven.compiler.source> - <maven-dist.required.jdk>8</maven-dist.required.jdk> + <maven.compiler.release>17</maven.compiler.release> + <maven-dist.required.jdk>17</maven-dist.required.jdk> <project.build.outputTimestamp>2023-10-26T05:45:19Z</project.build.outputTimestamp> <trimStackTrace>false</trimStackTrace> <project.github.repository>apache/maven-mvnd</project.github.repository> @@ -88,8 +84,6 @@ <jansi.version>2.4.1</jansi.version> <jline.version>3.25.1</jline.version> <maven.version>4.0.0-alpha-8</maven.version> - <maven3.version>3.9.6</maven3.version> - <maven4.version>${maven.version}</maven4.version> <!-- Keep in sync with Maven --> <maven.resolver.version>1.9.18</maven.resolver.version> <slf4j.version>1.7.36</slf4j.version> @@ -157,6 +151,11 @@ <artifactId>maven-model</artifactId> <version>${maven.version}</version> </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${maven.version}</version> + </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-embedder</artifactId> @@ -241,13 +240,7 @@ </dependency> <dependency> <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-dist-m39</artifactId> - <version>${project.version}</version> - <type>pom</type> - </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-dist-m40</artifactId> + <artifactId>mvnd-dist</artifactId> <version>${project.version}</version> <type>pom</type> </dependency> @@ -256,16 +249,6 @@ <artifactId>mvnd-daemon</artifactId> <version>${project.version}</version> </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-daemon-m39</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.maven.daemon</groupId> - <artifactId>mvnd-daemon-m40</artifactId> - <version>${project.version}</version> - </dependency> <dependency> <groupId>org.apache.maven.daemon</groupId> <artifactId>mvnd-helper-agent</artifactId> @@ -457,7 +440,7 @@ <artifactId>maven-enforcer-plugin</artifactId> <executions> <execution> - <id>enforce-maven-3</id> + <id>enforce-bytecode-version</id> <goals> <goal>enforce</goal> </goals> @@ -466,6 +449,18 @@ <requireMavenVersion> <version>3.5.4</version> </requireMavenVersion> + <requireJavaVersion> + <version>[17,)</version> + </requireJavaVersion> + <enforceBytecodeVersion> + <maxJdkVersion>${maven.compiler.release}</maxJdkVersion> + <ignoredScopes> + <ignoredScope>test</ignoredScope> + </ignoredScopes> + <excludes> + <exclude>org.jline:jline</exclude> + </excludes> + </enforceBytecodeVersion> </rules> <fail>true</fail> </configuration>