Skip to content

Commit 50b78ee

Browse files
committed
build: configure test Maven through the pipeline
Prepare an isolated Maven user home for Tycho tests so embedded m2e reads the CFS settings through Maven standard discovery, without changing Java sources. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac225268-483d-4498-a08f-fe79a87d4d2e
1 parent 5bf84de commit 50b78ee

6 files changed

Lines changed: 30 additions & 28 deletions

File tree

.azure-pipelines/maven-cfs-variables.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ variables:
3030
# MAVEN_ARGS to every invocation, so build scripts keep calling `mvnw` with no extra
3131
# flags of their own. Supported by Maven 3.9 and newer, which is what the wrapper here
3232
# pins.
33-
- name: JAVA_TEST_MAVEN_USER_SETTINGS
34-
value: $(Build.SourcesDirectory)/.azure-pipelines/cfs-settings.xml
35-
- name: MAVEN_ARGS
36-
value: -s $(JAVA_TEST_MAVEN_USER_SETTINGS)
37-
33+
#
3834
# Path two: plugin tests import sample Maven projects through JDT LS's embedded m2e.
39-
# That Maven client runs inside the test JVM and does not read MAVEN_ARGS.
40-
# AbstractProjectsManagerBasedTest maps JAVA_TEST_MAVEN_USER_SETTINGS to m2e's user
41-
# settings before any project is imported.
35+
# That Maven client runs inside Tycho's test JVM and does not read MAVEN_ARGS. Give
36+
# the test JVM an isolated user.home whose .m2/settings.xml is prepared by
37+
# maven-cfs.yml. m2e then discovers the CFS mirror through Maven's standard settings
38+
# lookup, with no test or product source changes.
39+
- name: JAVA_TEST_MAVEN_USER_HOME
40+
value: $(Agent.TempDirectory)/java-test-maven-home-$(Build.BuildId)
41+
- name: MAVEN_ARGS
42+
value: >-
43+
-s $(Build.SourcesDirectory)/.azure-pipelines/cfs-settings.xml
44+
-Dtycho.testArgLine=-Duser.home=$(JAVA_TEST_MAVEN_USER_HOME)
4245
4346
# Path three: the Maven distribution itself. The wrapper downloads it from
4447
# distributionUrl before Maven exists, so settings.xml cannot influence that request.

.azure-pipelines/maven-cfs.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Prepares Maven's standard user settings location for Maven clients running inside
2+
# the Tycho test JVM. The outer Maven process uses MAVEN_ARGS, but embedded m2e does
3+
# not see those command-line arguments and resolves settings from user.home instead.
4+
steps:
5+
- task: PowerShell@2
6+
displayName: Configure Maven test importer
7+
inputs:
8+
targetType: inline
9+
pwsh: true
10+
script: |-
11+
$m2Directory = Join-Path '$(JAVA_TEST_MAVEN_USER_HOME)' '.m2'
12+
New-Item -ItemType Directory -Path $m2Directory -Force | Out-Null
13+
Copy-Item `
14+
-LiteralPath '$(Build.SourcesDirectory)/.azure-pipelines/cfs-settings.xml' `
15+
-Destination (Join-Path $m2Directory 'settings.xml') `
16+
-Force

.azure-pipelines/vscode-java-test-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ extends:
5656
displayName: npm install
5757
- script: npm run lint
5858
displayName: npm run lint
59+
- template: /.azure-pipelines/maven-cfs.yml@self
5960
- script: npm run build-plugin
6061
displayName: npm run build-plugin
6162
# System.AccessToken is a secret, and Azure Pipelines does not export secret

.azure-pipelines/vscode-java-test-nightly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ extends:
7272
displayName: npm install
7373
- script: npm run lint
7474
displayName: npm run lint
75+
- template: /.azure-pipelines/maven-cfs.yml@self
7576
- script: npm run build-plugin
7677
displayName: npm run build-plugin
7778
# System.AccessToken is a secret, and Azure Pipelines does not export secret

.azure-pipelines/vscode-java-test-rc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ extends:
6767
displayName: npm install
6868
- script: npm run lint
6969
displayName: npm run lint
70+
- template: /.azure-pipelines/maven-cfs.yml@self
7071
- script: npm run build-plugin
7172
displayName: npm run build-plugin
7273
# System.AccessToken is a secret, and Azure Pipelines does not export secret

java-extension/com.microsoft.java.test.plugin.test/src/com/microsoft/java/test/plugin/AbstractProjectsManagerBasedTest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
4949
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
5050
import org.eclipse.jdt.ls.core.internal.preferences.StandardPreferenceManager;
51-
import org.eclipse.m2e.core.MavenPlugin;
5251
import org.junit.After;
5352
import org.junit.Before;
5453
import org.mockito.Mock;
@@ -61,7 +60,6 @@
6160
public abstract class AbstractProjectsManagerBasedTest {
6261

6362
public static final String TEST_PROJECT_NAME = "TestProject";
64-
private static final String MAVEN_USER_SETTINGS_ENV = "JAVA_TEST_MAVEN_USER_SETTINGS";
6563

6664
protected StandardProjectsManager projectsManager;
6765
@Mock
@@ -79,30 +77,12 @@ public void initProjectManager() throws Exception {
7977
preferenceManager = mock(StandardPreferenceManager.class);
8078
}
8179
initPreferenceManager(true);
82-
configureMavenUserSettings(preferences);
8380

8481
oldPreferenceManager = JavaLanguageServerPlugin.getPreferencesManager();
8582
JavaLanguageServerPlugin.setPreferencesManager(preferenceManager);
8683
projectsManager = new StandardProjectsManager(preferenceManager);
8784
}
8885

89-
private void configureMavenUserSettings(Preferences preferences) throws CoreException, IOException {
90-
String settingsPath = System.getenv(MAVEN_USER_SETTINGS_ENV);
91-
if (StringUtils.isBlank(settingsPath)) {
92-
return;
93-
}
94-
95-
File settingsFile = new File(settingsPath);
96-
if (!settingsFile.isFile()) {
97-
throw new IOException("Maven user settings file does not exist: " + settingsPath);
98-
}
99-
100-
String canonicalPath = settingsFile.getCanonicalPath();
101-
preferences.setMavenUserSettings(canonicalPath);
102-
// The preference manager is mocked in these tests, so apply the setting to m2e directly.
103-
MavenPlugin.getMavenConfiguration().setUserSettingsFile(canonicalPath);
104-
}
105-
10686
protected void initPreferences(Preferences preferences) throws IOException {
10787
preferences.setRootPaths(Collections.singleton(new Path(getWorkingProjectDirectory().getAbsolutePath())));
10888
preferences.setCodeGenerationTemplateGenerateComments(true);

0 commit comments

Comments
 (0)