From 5763fc69db9b2664bb0ba3ca508d3d31e53e4590 Mon Sep 17 00:00:00 2001
From: treilhes
Date: Tue, 13 Feb 2024 01:48:37 +0100
Subject: [PATCH] Propagate surefire and failsafe plugin configurations to
launch config
---
RELEASE_NOTES.md | 11 +
.../argumentsAreSet/pom.xml | 42 ++
...UnitTestLaunchConfigConfigurationTest.java | 319 +++++++++++++
org.eclipse.m2e.jdt/META-INF/MANIFEST.MF | 2 +-
.../AbstractJavaProjectConfigurator.java | 2 +
.../m2e/jdt/internal/UnitTestSupport.java | 435 ++++++++++++++++++
.../MavenLaunchConfigurationListener.java | 2 +
7 files changed, 812 insertions(+), 1 deletion(-)
create mode 100644 org.eclipse.m2e.jdt.tests/projects/surefireFailsafeToTestLaunchSettings/argumentsAreSet/pom.xml
create mode 100644 org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/UnitTestLaunchConfigConfigurationTest.java
create mode 100644 org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/UnitTestSupport.java
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index f738659511..34f5977c4d 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -8,6 +8,17 @@
Updated the embedded Maven from version 3.9.7 to 3.9.9; [Maven 3.9.9 Release Notes](https://maven.apache.org/docs/3.9.9/release-notes.html).
+### Surefire/Failsafe plugin configuration propagated to Junit/TestNG launch configuration
+
+The following arguments are supported:
+``,
+``,
+``,
+``,
+``,
+
+Configuration is propagated on unit test launch configuration creation and also when executing `maven > update project`
+
## 2.6.1
* 📅 Release Date: 04th June 2024
diff --git a/org.eclipse.m2e.jdt.tests/projects/surefireFailsafeToTestLaunchSettings/argumentsAreSet/pom.xml b/org.eclipse.m2e.jdt.tests/projects/surefireFailsafeToTestLaunchSettings/argumentsAreSet/pom.xml
new file mode 100644
index 0000000000..de4208e439
--- /dev/null
+++ b/org.eclipse.m2e.jdt.tests/projects/surefireFailsafeToTestLaunchSettings/argumentsAreSet/pom.xml
@@ -0,0 +1,42 @@
+
+
+ 4.0.0
+ foo.bar
+ demo-test-config
+ 0.0.1-SNAPSHOT
+
+
+ org.codehaus.mojo:properties-maven-plugin:read-project-properties
+
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+
+
+
+
+ integration-test
+
+
+
+
+
+
+
+
diff --git a/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/UnitTestLaunchConfigConfigurationTest.java b/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/UnitTestLaunchConfigConfigurationTest.java
new file mode 100644
index 0000000000..e3f24fcc82
--- /dev/null
+++ b/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/UnitTestLaunchConfigConfigurationTest.java
@@ -0,0 +1,319 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Pascal Treilhes
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+
+package org.eclipse.m2e.jdt.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.preferences.MavenConfigurationImpl;
+import org.eclipse.m2e.jdt.internal.UnitTestSupport;
+import org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider;
+import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@SuppressWarnings("restriction")
+@RunWith(Parameterized.class)
+public class UnitTestLaunchConfigConfigurationTest extends AbstractMavenProjectTestCase {
+
+ private static final String REPLACED_SUREFIRE_POM_STRING = "";
+ private static final String REPLACED_FAILSAFE_POM_STRING = "";
+ private static final String ROOT_PATH = "/projects/surefireFailsafeToTestLaunchSettings";
+ private static ILaunchManager LAUNCH_MANAGER = DebugPlugin.getDefault().getLaunchManager();
+
+ private static final String SUREFIRE_ARGS_SET = """
+
+
+ --argLineItem=surefireArgLineValue
+
+
+ surefireProp1Value
+
+
+ surefireEnvironmentVariables1Value
+
+
+ """;
+ private static final String FAILSAFE_ARGS_SET = """
+
+
+ --argLineItem=failsafeArgLineValue
+
+
+ failsafeProp1Value
+
+
+ failsafeEnvironmentVariables1Value
+
+
+ """;
+
+ // Define the parameters to be used in the test
+ @Parameters
+ public static Collection