You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/10/22 11:20:21 UTC
(maven) branch feature/logging-foundation updated: fix: drop BuildEnvironment – superseded by BuildInvocation from master
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch feature/logging-foundation
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/feature/logging-foundation by this push:
new 7132ad5346 fix: drop BuildEnvironment – superseded by BuildInvocation from master
7132ad5346 is described below
commit 7132ad5346320227b18e78253ac468d290e33b1f
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Oct 22 11:20:12 2026 +0000
fix: drop BuildEnvironment – superseded by BuildInvocation from master
---
.../org/apache/maven/api/BuildEnvironment.java | 203 ---------------------
.../internal/build/DefaultBuildEnvironment.java | 170 -----------------
2 files changed, 373 deletions(-)
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/BuildEnvironment.java b/api/maven-api-core/src/main/java/org/apache/maven/api/BuildEnvironment.java
deleted file mode 100644
index 37d6dc596a..0000000000
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/BuildEnvironment.java
+++ /dev/null
@@ -1,203 +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.api;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.maven.api.annotations.Experimental;
-import org.apache.maven.api.annotations.Immutable;
-import org.apache.maven.api.annotations.Nonnull;
-
-/**
- * Describes the invocation context of a Maven build: the flags, properties, and
- * environment settings that were active when the build started.
- *
- * <p>An instance is available via {@link Session#buildEnvironment()} during the build,
- * and is also recorded in the structured build report for post-mortem analysis and
- * reproducibility.
- *
- * <h2>What is captured</h2>
- * <ul>
- * <li>Goals and lifecycle phases requested ({@link #goals()})</li>
- * <li>User properties passed via {@code -Dkey=value} ({@link #userProperties()}),
- * with sensitive keys redacted — see {@link #userProperties()} for the denylist</li>
- * <li>A curated subset of system properties relevant to reproducibility
- * ({@link #systemInfo()}): OS name/arch/version, Java vendor and VM name/version,
- * Maven home, and available processors</li>
- * <li>Local repository path ({@link #localRepository()})</li>
- * <li>Explicitly activated or deactivated profiles ({@link #activeProfiles()})</li>
- * <li>Selected projects ({@link #selectedProjects()}) and resume-from
- * ({@link #resumeFrom()})</li>
- * <li>Reactor failure behavior ({@link #reactorFailureBehavior()})</li>
- * <li>Offline mode ({@link #offline()}) and snapshot update policy
- * ({@link #updateSnapshots()})</li>
- * <li>Degree of concurrency ({@link #threads()})</li>
- * <li>Transfer-progress suppression ({@link #noTransferProgress()}) and batch mode ({@link #batchMode()})</li>
- * </ul>
- *
- * <h2>What is not yet captured</h2>
- * <p>The following information is not currently available through the Maven 4 API
- * and therefore cannot be recorded here. It may be added in future versions as
- * the API evolves:
- * <ul>
- * <li><b>Raw command-line arguments</b> ({@code args[]}): the CLI bootstrap layer
- * does not surface these through {@code MavenExecutionRequest} or the session</li>
- * <li><b>Implicitly activated profiles</b>: profiles activated by OS, JDK, or
- * property conditions rather than by explicit {@code -P} flag; computing
- * these requires per-project activation and is not available at session level</li>
- * </ul>
- *
- * @since 4.1.0
- * @see Session#buildEnvironment()
- */
-@Experimental
-@Immutable
-public interface BuildEnvironment {
-
- /**
- * The goals or lifecycle phases that were requested on the command line.
- *
- * @return the requested goals/phases, never {@code null}
- */
- @Nonnull
- List<String> goals();
-
- /**
- * User properties passed via {@code -Dkey=value} on the command line or via
- * {@code --define}.
- *
- * <p>Sensitive keys are redacted and replaced with {@code "***"}. A key is
- * considered sensitive if its lower-case form contains any of:
- * {@code password}, {@code passwd}, {@code secret}, {@code token},
- * {@code apikey}, {@code api_key}, {@code credential}, {@code passphrase}.
- *
- * @return the user properties, never {@code null}; values of sensitive keys
- * are replaced with {@code "***"}
- */
- @Nonnull
- Map<String, String> userProperties();
-
- /**
- * A curated subset of system properties capturing platform and JVM identity,
- * relevant for build reproducibility analysis.
- *
- * <p>The following keys are included when present:
- * {@code os.name}, {@code os.arch}, {@code os.version},
- * {@code java.vendor}, {@code java.vm.name}, {@code java.vm.version},
- * {@code maven.home}, {@code user.home}, {@code user.name},
- * and {@code available.processors} (from {@code Runtime.getRuntime()}).
- *
- * <p>The full {@code System.getProperties()} map is intentionally not captured:
- * it is large, mostly irrelevant, and may contain sensitive values.
- *
- * @return the curated system info map, never {@code null}
- */
- @Nonnull
- Map<String, String> systemInfo();
-
- /**
- * The path to the local repository used for this build.
- *
- * @return the local repository path string, never {@code null}
- */
- @Nonnull
- String localRepository();
-
- /**
- * Profiles explicitly activated ({@code -P profileId}) or deactivated
- * ({@code -P !profileId}) on the command line.
- *
- * <p>This list reflects only explicit {@code -P} selections. Profiles activated
- * implicitly by OS, JDK, or property conditions are not included here — see
- * the class-level javadoc for details.
- *
- * @return the explicitly selected profiles, never {@code null}; may be empty
- */
- @Nonnull
- List<String> activeProfiles();
-
- /**
- * Projects explicitly selected via {@code -pl} / {@code --projects}.
- *
- * @return the selected project selectors (e.g. {@code ":my-module"}),
- * never {@code null}; empty for a full reactor build
- */
- @Nonnull
- List<String> selectedProjects();
-
- /**
- * The project to resume from, as specified via {@code -rf} / {@code --resume-from}.
- *
- * @return the resume-from selector, or {@code null} if not specified
- */
- String resumeFrom();
-
- /**
- * The reactor failure behavior, corresponding to the {@code -ff} / {@code -fae} /
- * {@code -fn} flags.
- *
- * <p>Possible values (matching {@code MavenExecutionRequest} constants):
- * <ul>
- * <li>{@code "FAIL_FAST"} — stop at first failure ({@code -ff}, default)</li>
- * <li>{@code "FAIL_AT_END"} — build all, report failures at end ({@code -fae})</li>
- * <li>{@code "FAIL_NEVER"} — always exit with success ({@code -fn})</li>
- * </ul>
- *
- * @return the failure behavior string, never {@code null}
- */
- @Nonnull
- String reactorFailureBehavior();
-
- /**
- * Whether the build was invoked in offline mode ({@code -o} / {@code --offline}).
- *
- * @return {@code true} if offline mode was active
- */
- boolean offline();
-
- /**
- * Whether snapshot updates were forced ({@code -U} / {@code --update-snapshots}).
- *
- * @return {@code true} if snapshot updates were forced
- */
- boolean updateSnapshots();
-
- /**
- * Whether transfer progress output was suppressed ({@code --no-transfer-progress} / {@code -ntp}).
- *
- * @return {@code true} if transfer progress was disabled
- */
- boolean noTransferProgress();
-
- /**
- * Whether the build was invoked in non-interactive (batch) mode ({@code --batch-mode} / {@code -B}).
- * Equivalent to {@code !isInteractiveMode()} on {@code MavenExecutionRequest}.
- *
- * @return {@code true} if batch mode was active
- */
- boolean batchMode();
-
- /**
- * The degree of concurrency ({@code -T} flag), or {@code 1} for sequential builds.
- *
- * @return the thread count
- */
- int threads();
-}
diff --git a/impl/maven-core/src/main/java/org/apache/maven/internal/build/DefaultBuildEnvironment.java b/impl/maven-core/src/main/java/org/apache/maven/internal/build/DefaultBuildEnvironment.java
deleted file mode 100644
index 69e1d2fb09..0000000000
--- a/impl/maven-core/src/main/java/org/apache/maven/internal/build/DefaultBuildEnvironment.java
+++ /dev/null
@@ -1,170 +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.internal.build;
-
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-import org.apache.maven.api.BuildEnvironment;
-import org.apache.maven.execution.MavenSession;
-
-/**
- * Internal immutable implementation of {@link BuildEnvironment}.
- *
- * @param goals requested goals/phases
- * @param userProperties user properties with sensitive values redacted
- * @param systemInfo curated system properties for reproducibility
- * @param localRepository local repository path
- * @param activeProfiles explicitly activated profiles
- * @param selectedProjects projects selected via {@code -pl}
- * @param resumeFrom resume-from selector, or {@code null}
- * @param reactorFailureBehavior reactor failure behavior
- * @param offline whether offline mode was active
- * @param updateSnapshots whether snapshot updates were forced
- * @param noTransferProgress whether transfer progress was suppressed
- * @param batchMode whether batch mode was active
- * @param threads degree of concurrency
- */
-public record DefaultBuildEnvironment(
- List<String> goals,
- Map<String, String> userProperties,
- Map<String, String> systemInfo,
- String localRepository,
- List<String> activeProfiles,
- List<String> selectedProjects,
- String resumeFrom,
- String reactorFailureBehavior,
- boolean offline,
- boolean updateSnapshots,
- boolean noTransferProgress,
- boolean batchMode,
- int threads)
- implements BuildEnvironment {
-
- private static final Set<String> SENSITIVE_KEY_FRAGMENTS =
- Set.of("password", "passwd", "secret", "token", "apikey", "api_key", "credential", "passphrase");
-
- @Override
- public List<String> goals() {
- return List.copyOf(goals);
- }
-
- @Override
- public Map<String, String> userProperties() {
- return Map.copyOf(userProperties);
- }
-
- @Override
- public Map<String, String> systemInfo() {
- return Map.copyOf(systemInfo);
- }
-
- @Override
- public List<String> activeProfiles() {
- return List.copyOf(activeProfiles);
- }
-
- @Override
- public List<String> selectedProjects() {
- return List.copyOf(selectedProjects);
- }
-
- /**
- * Creates a {@link BuildEnvironment} snapshot from the current session state.
- *
- * @param session the Maven session
- * @return a new immutable build environment instance
- */
- public static BuildEnvironment from(MavenSession session) {
- var request = session.getRequest();
-
- List<String> goals = request.getGoals() != null ? List.copyOf(request.getGoals()) : List.of();
-
- Map<String, String> userProps = new LinkedHashMap<>();
- if (request.getUserProperties() != null) {
- request.getUserProperties().forEach((k, v) -> {
- String key = String.valueOf(k);
- String value = isSensitiveKey(key) ? "***" : String.valueOf(v);
- userProps.put(key, value);
- });
- }
-
- Map<String, String> sysInfo = new TreeMap<>();
- addSystemProp(sysInfo, "os.name");
- addSystemProp(sysInfo, "os.arch");
- addSystemProp(sysInfo, "os.version");
- addSystemProp(sysInfo, "java.vendor");
- addSystemProp(sysInfo, "java.vm.name");
- addSystemProp(sysInfo, "java.vm.version");
- addSystemProp(sysInfo, "maven.home");
- addSystemProp(sysInfo, "user.home");
- addSystemProp(sysInfo, "user.name");
- sysInfo.put("available.processors", String.valueOf(Runtime.getRuntime().availableProcessors()));
-
- String localRepo = request.getLocalRepositoryPath() != null
- ? request.getLocalRepositoryPath().getAbsolutePath()
- : "";
-
- List<String> activeProfiles =
- request.getActiveProfiles() != null ? List.copyOf(request.getActiveProfiles()) : List.of();
-
- List<String> selectedProjects =
- request.getSelectedProjects() != null ? List.copyOf(request.getSelectedProjects()) : List.of();
-
- String resumeFrom = request.getResumeFrom();
-
- String failureBehavior =
- request.getReactorFailureBehavior() != null ? request.getReactorFailureBehavior() : "FAIL_FAST";
-
- return new DefaultBuildEnvironment(
- goals,
- userProps,
- sysInfo,
- localRepo,
- activeProfiles,
- selectedProjects,
- resumeFrom,
- failureBehavior,
- request.isOffline(),
- request.isUpdateSnapshots(),
- request.isNoTransferProgress(),
- !request.isInteractiveMode(),
- request.getDegreeOfConcurrency());
- }
-
- private static boolean isSensitiveKey(String key) {
- String lower = key.toLowerCase(java.util.Locale.ROOT);
- for (String fragment : SENSITIVE_KEY_FRAGMENTS) {
- if (lower.contains(fragment)) {
- return true;
- }
- }
- return false;
- }
-
- private static void addSystemProp(Map<String, String> map, String key) {
- String value = System.getProperty(key);
- if (value != null) {
- map.put(key, value);
- }
- }
-}