diff --git a/.github/workflows/early-access.yaml b/.github/workflows/early-access.yaml index b8b1010a6..3c2f5962d 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 2da20e0c7..3ea1fe7d3 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/agent/pom.xml b/agent/pom.xml index 0f50ca8b7..636fff2a9 100644 --- a/agent/pom.xml +++ b/agent/pom.xml @@ -22,7 +22,7 @@ org.apache.maven.daemon mvnd - 1.0-m9-SNAPSHOT + 2.0-SNAPSHOT mvnd-agent diff --git a/build-plugin/pom.xml b/build-plugin/pom.xml index 6ad3dd464..62a145a22 100644 --- a/build-plugin/pom.xml +++ b/build-plugin/pom.xml @@ -22,7 +22,7 @@ org.apache.maven.daemon mvnd - 1.0-m9-SNAPSHOT + 2.0-SNAPSHOT mvnd-build-maven-plugin diff --git a/build/publish-on-homebrew.sh b/build/publish-on-homebrew.sh index 20f416bd8..f6a2444ca 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 "gnodet@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 c9363f50c..0fc36be13 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 148002ba2..1d93c468b 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 8726746c9..1a9f0d375 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -22,7 +22,7 @@ org.apache.maven.daemon mvnd - 1.0-m9-SNAPSHOT + 2.0-SNAPSHOT mvnd-client @@ -31,7 +31,6 @@ Maven Daemon - Client - 11 true @@ -80,28 +79,6 @@ - - org.apache.maven.plugins - maven-enforcer-plugin - - - enforce-bytecode-version - - enforce - - - - - ${maven.compiler.release} - - org.graalvm.nativeimage:svm - - - - - - - org.codehaus.mojo buildnumber-maven-plugin diff --git a/common/pom.xml b/common/pom.xml index be2244477..5df322ca5 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -22,7 +22,7 @@ org.apache.maven.daemon mvnd - 1.0-m9-SNAPSHOT + 2.0-SNAPSHOT mvnd-common diff --git a/daemon-m39/pom.xml b/daemon-m39/pom.xml deleted file mode 100644 index 2990eec0b..000000000 --- a/daemon-m39/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - 4.0.0 - - org.apache.maven.daemon - mvnd - 1.0-m9-SNAPSHOT - - - mvnd-daemon-m39 - - jar - Maven Daemon - Daemon 3.9.x specifics - - - - org.apache.maven - maven-core - ${maven3.version} - - - org.apache.maven - maven-embedder - ${maven3.version} - - - org.apache.maven.daemon - mvnd-daemon - - - - - - - org.eclipse.sisu - sisu-maven-plugin - - - - - 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 142e1fa8c..000000000 --- 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 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 arguments, - String workingDirectory, - String projectDirectory, - Map 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 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 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