gnodet-bot commented on code in PR #13546: URL: https://github.com/apache/maven/pull/13546#discussion_r4316452454
########## its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11759SiteLifecycleDisabledTest.java: ########## @@ -0,0 +1,62 @@ +/* + * 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.it; + +import java.io.File; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * Integration test for <a href="https://github.com/apache/maven/issues/11759">gh-11759</a>: + * verifies that setting {@code -Dmaven.site.lifecycle.disabled=true} via {@code MAVEN_OPTS} + * removes the {@code site} lifecycle so that invoking the {@code site} phase fails with + * "Unknown lifecycle phase". + */ +class MavenITgh11759SiteLifecycleDisabledTest extends AbstractMavenIntegrationTestCase { + + MavenITgh11759SiteLifecycleDisabledTest() { + super("[4.0.0-rc-3,)"); Review Comment: ❌ **Compile error (4th cycle)** — `AbstractMavenIntegrationTestCase` has only a no-arg constructor (`protected AbstractMavenIntegrationTestCase() {}`). There is no `String` constructor. The `super("[4.0.0-rc-3,)")` call does not compile. Remove the constructor override entirely — the default constructor is sufficient since version range filtering is not needed here: ```suggestion class MavenITgh11759SiteLifecycleDisabledTest extends AbstractMavenIntegrationTestCase { ``` ########## its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11759SiteLifecycleDisabledTest.java: ########## @@ -0,0 +1,62 @@ +/* + * 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.it; + +import java.io.File; Review Comment: ⚠️ **Wrong import (4th cycle)** — `extractResources()` returns `java.nio.file.Path`, not `java.io.File`. Replace: ```suggestion import java.nio.file.Path; ``` ########## api/maven-api-core/src/main/java/org/apache/maven/api/Constants.java: ########## @@ -888,5 +888,22 @@ public final class Constants { @Config(type = "java.lang.Boolean", defaultValue = "false", source = Config.Source.SYSTEM_PROPERTIES) public static final String MAVEN_TEMPFILE_KEEP = "maven.tempfile.keep"; + /** + * System property to disable the {@code site} lifecycle. + * When set to {@code true} via {@code -Dmaven.site.lifecycle.disabled=true}, the {@code site} + * lifecycle is excluded from the default lifecycles, so Maven will not resolve or bind the + * {@code maven-site-plugin} unless it is explicitly configured in the POM. + * This is a JVM system property only (read via {@link Boolean#getBoolean(String)}); + * it is not resolved through Maven's property mechanism (pom.xml, profiles, settings.xml). + * + * @since 4.0.0 Review Comment: ⚠️ **Wrong `@since` tag (4th cycle)** — this constant is introduced in this PR which targets `master` (Maven 4.1.0). The tag must be `@since 4.1.0`, not `@since 4.0.0`. ```suggestion * @since 4.1.0 ``` ########## its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11759SiteLifecycleDisabledTest.java: ########## @@ -0,0 +1,62 @@ +/* + * 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.it; + +import java.io.File; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * Integration test for <a href="https://github.com/apache/maven/issues/11759">gh-11759</a>: + * verifies that setting {@code -Dmaven.site.lifecycle.disabled=true} via {@code MAVEN_OPTS} + * removes the {@code site} lifecycle so that invoking the {@code site} phase fails with + * "Unknown lifecycle phase". + */ +class MavenITgh11759SiteLifecycleDisabledTest extends AbstractMavenIntegrationTestCase { + + MavenITgh11759SiteLifecycleDisabledTest() { + super("[4.0.0-rc-3,)"); + } + + /** + * Verifies that with {@code maven.site.lifecycle.disabled=true} the site lifecycle + * is absent and invoking the {@code site} phase causes a build failure. + */ + @Test + void testSiteLifecycleDisabledViaSystemProperty() throws Exception { + File testDir = extractResources("/gh-11759-site-lifecycle-disabled"); Review Comment: ❌ **Compile error (4th cycle)** — `extractResources()` returns `Path`, not `File`. Also, `newVerifier(Path, String)` takes a `Path` directly — no need to call `.toAbsolutePath()`: ```suggestion Path testDir = extractResources("/gh-11759-site-lifecycle-disabled"); Verifier verifier = newVerifier(testDir, null); ``` ########## impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLifecycleRegistryTest.java: ########## @@ -18,14 +18,40 @@ */ package org.apache.maven.internal.impl; +import java.util.List; + +import org.apache.maven.api.Constants; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; class DefaultLifecycleRegistryTest { @Test void returnsNullImplementationVersionWhenClassHasNoPackage() { assertNull(DefaultLifecycleRegistry.getImplementationVersion(int.class)); } + + /** + * Verifies that the site-lifecycle filtering constant reads from the correct system property. + * The actual site-disabled path requires a forked JVM with the property set at startup + * (static final field), so we verify correctness of the property name used. + */ + @Test + void siteDisabledPropertyNameMatchesConstant() throws Exception { + java.lang.reflect.Field field = DefaultLifecycleRegistry.class.getDeclaredField("SITE_DISABLED"); Review Comment: 💡 **Reflection on private field is fragile** — `getDeclaredField("SITE_DISABLED")` couples the test to the private implementation detail of `DefaultLifecycleRegistry`. If the field is renamed or removed, this test fails with a cryptic `NoSuchFieldException` rather than a meaningful assertion. A simpler and more robust approach: set the system property before constructing the registry and verify the site lifecycle is filtered: ```java @Test void siteDisabledPropertyNameMatchesConstant() { System.clearProperty(Constants.MAVEN_SITE_LIFECYCLE_DISABLED); DefaultLifecycleRegistry registry = new DefaultLifecycleRegistry(List.of()); assertTrue(registry.lookup("site").isPresent(), "site lifecycle present when property not set"); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
