gnodet-bot commented on code in PR #13602: URL: https://github.com/apache/maven/pull/13602#discussion_r4522309631
########## impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenDiDiagnosticsTest.java: ########## @@ -0,0 +1,123 @@ +/* + * 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.cling.invoker.mvn; + +import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import org.apache.maven.api.cli.Invoker; +import org.apache.maven.api.cli.Parser; +import org.apache.maven.api.cli.ParserRequest; +import org.apache.maven.api.services.MessageBuilder; +import org.apache.maven.cling.invoker.ProtoLookup; +import org.apache.maven.impl.DefaultMessageBuilder; +import org.apache.maven.impl.DefaultMessageBuilderFactory; +import org.codehaus.plexus.classworlds.ClassWorld; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.api.parallel.ResourceLock; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.parallel.Resources.SYSTEM_OUT; +import static org.junit.jupiter.api.parallel.Resources.SYSTEM_PROPERTIES; + +@ResourceLock(SYSTEM_OUT) +@ResourceLock(SYSTEM_PROPERTIES) +class MavenDiDiagnosticsTest extends MavenInvokerTestSupport { + @Test + void embeddedInvocationsStyleEarlyDiagnosticsWithTheirOwnFactory(@TempDir Path directory) throws Exception { + Files.writeString(directory.resolve("pom.xml"), """ + <project> + <modelVersion>4.0.0</modelVersion> + <groupId>test</groupId> + <artifactId>di-diagnostics</artifactId> + <version>1</version> + </project> + """); + Files.createDirectories(directory.resolve(".mvn")); + Path userHome = Files.createDirectory(directory.resolve("home")); + String property = "maven.di.debug"; Review Comment: 💡 **Use `Constants.MAVEN_DI_DEBUG` instead of the string literal** `maven-cli` already depends on `maven-api-core` (other classes in the module import `org.apache.maven.api.Constants`). Now that `Constants.MAVEN_DI_DEBUG` exists, using the literal here defeats its purpose — a future rename or typo diverges silently. ```suggestion String property = Constants.MAVEN_DI_DEBUG; ``` Also add `import org.apache.maven.api.Constants;` to the imports. ########## impl/maven-core/src/test/java/org/apache/maven/internal/impl/SisuDiDiagnosticsTest.java: ########## @@ -0,0 +1,292 @@ +/* + * 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.impl; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +import com.google.inject.AbstractModule; +import com.google.inject.CreationException; +import com.google.inject.Guice; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.di.Named; +import org.apache.maven.api.services.MessageBuilder; +import org.apache.maven.api.services.MessageBuilderFactory; +import org.apache.maven.di.Injector; +import org.apache.maven.di.Key; +import org.apache.maven.di.impl.InjectorImpl; +import org.apache.maven.impl.DefaultMessageBuilder; +import org.apache.maven.impl.DefaultMessageBuilderFactory; +import org.codehaus.plexus.DefaultContainerConfiguration; +import org.codehaus.plexus.DefaultPlexusContainer; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.eclipse.sisu.inject.BeanLocator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.api.parallel.ResourceLock; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.parallel.Resources.SYSTEM_OUT; +import static org.junit.jupiter.api.parallel.Resources.SYSTEM_PROPERTIES; + +@ResourceLock(SYSTEM_PROPERTIES) +@ResourceLock(SYSTEM_OUT) +class SisuDiDiagnosticsTest { + private static final String MAVEN_DI_DEBUG = "maven.di.debug"; Review Comment: 💡 **Use `Constants.MAVEN_DI_DEBUG` instead of a local constant** `maven-core` depends on `maven-api-core`. Now that `Constants.MAVEN_DI_DEBUG` is part of the public API, keeping a private duplicate here defeats its purpose. ```suggestion private static final String MAVEN_DI_DEBUG = Constants.MAVEN_DI_DEBUG; ``` Or simply remove the field and use `Constants.MAVEN_DI_DEBUG` directly at each usage site. Either way, add `import org.apache.maven.api.Constants;` to the imports. -- 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]
