Copilot commented on code in PR #531:
URL: https://github.com/apache/maven-ear-plugin/pull/531#discussion_r3596627386
##########
src/main/java/org/apache/maven/plugins/ear/EarMojo.java:
##########
@@ -560,9 +560,12 @@ private static File buildDestinationFile(File buildDir,
String uri) {
* @return the EAR file to generate
*/
private static File getEarFile(String basedir, String finalName, String
classifier) {
- if (classifier == null) {
+ if (classifier != null) {
+ classifier = classifier.trim();
+ }
+ if (classifier == null || classifier.isEmpty()) {
classifier = "";
Review Comment:
`getEarFile(...)` trims the classifier only for filename construction, but
the caller (`execute()`) still uses the untrimmed `classifier` field later to
decide whether to `attachArtifact(...)`. With a whitespace-only classifier, the
output file becomes unclassified (`finalName.ear`), but the build will still
attach an artifact with a whitespace classifier and will skip setting the main
project artifact file. Consider normalizing the classifier once (trim + treat
empty as null) in `execute()` and use that normalized value both for
`getEarFile(...)` and for the attach-vs-main-artifact decision.
##########
src/test/java/org/apache/maven/plugins/ear/EarMojoTest.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.plugins.ear;
+
+import java.io.File;
+import java.lang.reflect.Method;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class EarMojoTest {
+
+ private static File invokeGetEarFile(String basedir, String finalName,
String classifier) throws Exception {
+ Method method = EarMojo.class.getDeclaredMethod("getEarFile",
String.class, String.class, String.class);
+ method.setAccessible(true);
+ return (File) method.invoke(null, basedir, finalName, classifier);
+ }
+
+ @Test
+ void testGetEarFileWithNullClassifier() throws Exception {
+ File result = invokeGetEarFile("/tmp", "myapp", null);
+ assertEquals(new File("/tmp", "myapp.ear"), result);
Review Comment:
Hard-coding `/tmp` makes this unit test non-portable (e.g., Windows runners)
and can be brittle in hermetic CI. Prefer using the platform temp directory
(`java.io.tmpdir`) or a JUnit `@TempDir`.
##########
src/test/java/org/apache/maven/plugins/ear/EarMojoTest.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.plugins.ear;
+
+import java.io.File;
+import java.lang.reflect.Method;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class EarMojoTest {
+
+ private static File invokeGetEarFile(String basedir, String finalName,
String classifier) throws Exception {
+ Method method = EarMojo.class.getDeclaredMethod("getEarFile",
String.class, String.class, String.class);
+ method.setAccessible(true);
+ return (File) method.invoke(null, basedir, finalName, classifier);
+ }
+
+ @Test
+ void testGetEarFileWithNullClassifier() throws Exception {
+ File result = invokeGetEarFile("/tmp", "myapp", null);
+ assertEquals(new File("/tmp", "myapp.ear"), result);
+ }
+
+ @Test
+ void testGetEarFileWithClassifier() throws Exception {
+ File result = invokeGetEarFile("/tmp", "myapp", "sources");
+ assertEquals(new File("/tmp", "myapp-sources.ear"), result);
+ }
+
+ @Test
+ void testGetEarFileWithDashPrefixedClassifier() throws Exception {
+ File result = invokeGetEarFile("/tmp", "myapp", "-sources");
+ assertEquals(new File("/tmp", "myapp-sources.ear"), result);
+ }
+
+ @Test
+ void testGetEarFileWithWhitespaceOnlyClassifier() throws Exception {
+ File result = invokeGetEarFile("/tmp", "myapp", " ");
+ assertEquals(new File("/tmp", "myapp.ear"), result);
+ assertFalse(
+ result.getAbsolutePath().contains(" "),
+ "EAR filename should not contain spaces from whitespace-only
classifier");
Review Comment:
This test hard-codes `/tmp` (non-portable) and checks
`result.getAbsolutePath().contains(" ")`, which can fail if the temp directory
path itself contains spaces. Use the platform temp directory and assert on the
filename (`getName()`) instead of the absolute path.
##########
src/test/java/org/apache/maven/plugins/ear/EarMojoTest.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.plugins.ear;
+
+import java.io.File;
+import java.lang.reflect.Method;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class EarMojoTest {
+
+ private static File invokeGetEarFile(String basedir, String finalName,
String classifier) throws Exception {
+ Method method = EarMojo.class.getDeclaredMethod("getEarFile",
String.class, String.class, String.class);
+ method.setAccessible(true);
+ return (File) method.invoke(null, basedir, finalName, classifier);
+ }
+
+ @Test
+ void testGetEarFileWithNullClassifier() throws Exception {
+ File result = invokeGetEarFile("/tmp", "myapp", null);
+ assertEquals(new File("/tmp", "myapp.ear"), result);
+ }
+
+ @Test
+ void testGetEarFileWithClassifier() throws Exception {
+ File result = invokeGetEarFile("/tmp", "myapp", "sources");
+ assertEquals(new File("/tmp", "myapp-sources.ear"), result);
Review Comment:
Hard-coding `/tmp` makes this unit test non-portable (e.g., Windows runners)
and can be brittle in hermetic CI. Prefer using the platform temp directory
(`java.io.tmpdir`) or a JUnit `@TempDir`.
##########
src/test/java/org/apache/maven/plugins/ear/EarMojoTest.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.plugins.ear;
+
+import java.io.File;
+import java.lang.reflect.Method;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class EarMojoTest {
+
+ private static File invokeGetEarFile(String basedir, String finalName,
String classifier) throws Exception {
+ Method method = EarMojo.class.getDeclaredMethod("getEarFile",
String.class, String.class, String.class);
+ method.setAccessible(true);
+ return (File) method.invoke(null, basedir, finalName, classifier);
+ }
+
+ @Test
+ void testGetEarFileWithNullClassifier() throws Exception {
+ File result = invokeGetEarFile("/tmp", "myapp", null);
+ assertEquals(new File("/tmp", "myapp.ear"), result);
+ }
+
+ @Test
+ void testGetEarFileWithClassifier() throws Exception {
+ File result = invokeGetEarFile("/tmp", "myapp", "sources");
+ assertEquals(new File("/tmp", "myapp-sources.ear"), result);
+ }
+
+ @Test
+ void testGetEarFileWithDashPrefixedClassifier() throws Exception {
+ File result = invokeGetEarFile("/tmp", "myapp", "-sources");
+ assertEquals(new File("/tmp", "myapp-sources.ear"), result);
Review Comment:
Hard-coding `/tmp` makes this unit test non-portable (e.g., Windows runners)
and can be brittle in hermetic CI. Prefer using the platform temp directory
(`java.io.tmpdir`) or a JUnit `@TempDir`.
--
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]