From c30452abfa703e1d94229939e423e3bfe4222f39 Mon Sep 17 00:00:00 2001 From: yyin Date: Thu, 5 Dec 2024 09:48:54 +0800 Subject: [PATCH] fix(QTDI-763) issue to enable Tacokit (#945) * fix(QTDI-835) issue to enable Tacokit --------- Co-authored-by: Emmanuel GALLOIS --- .../MavenRepositoryDefaultResolver.java | 10 +++++- .../service/MavenRepositoryResolverTest.java | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/service/MavenRepositoryDefaultResolver.java b/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/service/MavenRepositoryDefaultResolver.java index aecfadb7df767..c397d61e0b0e6 100644 --- a/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/service/MavenRepositoryDefaultResolver.java +++ b/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/service/MavenRepositoryDefaultResolver.java @@ -15,6 +15,7 @@ */ package org.talend.sdk.component.runtime.manager.service; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -79,7 +80,14 @@ private Path fromStudioConfiguration() { // check if we are in the studio process if so just grab the studio config final String m2Repo = System.getProperty(STUDIO_MVN_REPOSITORY); if (!"global".equals(m2Repo)) { - return handler.get(Paths.get(System.getProperty("osgi.configuration.area", ""), M2_REPOSITORY).toString()); + final String osgi = System.getProperty("osgi.configuration.area", ""); + try { + return osgi != null && osgi.startsWith("file") ? handler.get(Paths.get(new URI(osgi)).toString()) + : handler.get(Paths.get(osgi, M2_REPOSITORY).toString()); + } catch (java.net.URISyntaxException e) { + log.debug("[fromStudioConfiguration] Could not get m2 from studio config." + e.getMessage()); + return null; + } } log.debug("[fromStudioConfiguration] Could not get m2 from studio config."); return null; diff --git a/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/service/MavenRepositoryResolverTest.java b/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/service/MavenRepositoryResolverTest.java index afd4f2e1a862a..edb0af05c274c 100644 --- a/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/service/MavenRepositoryResolverTest.java +++ b/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/service/MavenRepositoryResolverTest.java @@ -170,6 +170,40 @@ void discoverFromSettingsWindowsPath() { System.clearProperty(TALEND_COMPONENT_MANAGER_M2_SETTINGS); } + @Test + void discoverFromWindowsPathWithFile() { + System.setProperty("osgi.configuration.area", "file:/C:/Users/Talend-Studio-CICD_TEST/configuration/"); + System.setProperty(STUDIO_MVN_REPOSITORY, "studio"); + final Path m2 = resolver.discover(); + assertNotNull(m2); + System.clearProperty("osgi.configuration.area"); + System.clearProperty(STUDIO_MVN_REPOSITORY); + } + + @Test + void discoverFromWindowsPathWithoutFile() { + System.setProperty("osgi.configuration.area", "C:/Users/Talend-Studio-CICD_TEST/configuration/"); + final Path m3 = resolver.discover(); + assertNotNull(m3); + System.clearProperty("osgi.configuration.area"); + } + + @Test + void discoverFromWindowsPathWrongURI() { + System.setProperty("osgi.configuration.area", "file://example .com"); + final Path m4 = resolver.discover(); + assertNotNull(m4); + System.clearProperty("osgi.configuration.area"); + } + + @Test + void discoverFromWindowsPathGlobal() { + System.setProperty(STUDIO_MVN_REPOSITORY, "global"); + final Path m5 = resolver.discover(); + assertNotNull(m5); + System.clearProperty(STUDIO_MVN_REPOSITORY); + } + @Test void discoverFromSettingsTildePath() { setSettingsProperty("settings/settings-tilde.xml");