From 15910e5ebce1e88092322178567e11fa1e6da56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Mon, 4 Nov 2024 09:27:22 +0100 Subject: [PATCH] #727: allow fallback to edition independent dependencies.json (#728) --- .../tools/ide/context/AbstractIdeContext.java | 20 ++----- .../tools/ide/repo/DefaultToolRepository.java | 16 +++++- .../tools/ide/tool/LocalToolCommandlet.java | 6 +- .../ide/url/model/file/UrlDependencyFile.java | 6 +- .../url/model/file/json/ToolDependencies.java | 9 +++ .../folder/AbstractUrlToolOrEdition.java | 35 ++++++++++++ .../ide/url/model/folder/UrlEdition.java | 19 +------ .../tools/ide/url/model/folder/UrlTool.java | 4 +- .../ide/context/AbstractIdeTestContext.java | 55 ++++++++++-------- .../tools/ide/context/IdeSlf4jContext.java | 9 +++ .../tools/ide/context/IdeTestContextMock.java | 10 +++- .../tools/ide/tool/eclipse/EclipseTest.java | 2 +- .../tools/ide/tool/intellij/IntellijTest.java | 2 +- .../ide/url/model/AbstractUrlModelTest.java | 38 +++++++++++++ .../ide/url/model/file/UrlStatusFileTest.java | 7 +-- .../model/file/json/ToolDependenciesTest.java | 57 +++++++++++++++++++ .../test/resources/urls/mvn/dependencies.json | 14 +++++ .../resources/urls/tomcat/dependencies.json | 8 +++ .../urls/tomcat/tomcat/dependencies.json | 50 ++++++++++++++++ 19 files changed, 290 insertions(+), 77 deletions(-) create mode 100644 cli/src/main/java/com/devonfw/tools/ide/url/model/folder/AbstractUrlToolOrEdition.java create mode 100644 cli/src/test/java/com/devonfw/tools/ide/url/model/AbstractUrlModelTest.java create mode 100644 cli/src/test/java/com/devonfw/tools/ide/url/model/file/json/ToolDependenciesTest.java create mode 100644 cli/src/test/resources/urls/mvn/dependencies.json create mode 100644 cli/src/test/resources/urls/tomcat/dependencies.json create mode 100644 cli/src/test/resources/urls/tomcat/tomcat/dependencies.json diff --git a/cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java b/cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java index 7a679a8c0..9fde2bbf9 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java +++ b/cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java @@ -82,7 +82,7 @@ public abstract class AbstractIdeContext implements IdeContext { private String workspaceName; - private Path urlsPath; + protected Path urlsPath; private Path tempPath; @@ -94,7 +94,7 @@ public abstract class AbstractIdeContext implements IdeContext { private Path toolRepositoryPath; - private Path userHome; + protected Path userHome; private Path userHomeIde; @@ -110,19 +110,19 @@ public abstract class AbstractIdeContext implements IdeContext { private final CommandletManager commandletManager; - private ToolRepository defaultToolRepository; + protected ToolRepository defaultToolRepository; private CustomToolRepository customToolRepository; private DirectoryMerger workspaceMerger; - private UrlMetadata urlMetadata; + protected UrlMetadata urlMetadata; - private Path defaultExecutionDirectory; + protected Path defaultExecutionDirectory; private StepImpl currentStep; - private Boolean online; + protected Boolean online; /** * The constructor. @@ -366,14 +366,6 @@ public ToolRepository getDefaultToolRepository() { return this.defaultToolRepository; } - /** - * @param defaultToolRepository the new value of {@link #getDefaultToolRepository()}. - */ - protected void setDefaultToolRepository(ToolRepository defaultToolRepository) { - - this.defaultToolRepository = defaultToolRepository; - } - @Override public CustomToolRepository getCustomToolRepository() { diff --git a/cli/src/main/java/com/devonfw/tools/ide/repo/DefaultToolRepository.java b/cli/src/main/java/com/devonfw/tools/ide/repo/DefaultToolRepository.java index c26c1fdef..00ffde30b 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/repo/DefaultToolRepository.java +++ b/cli/src/main/java/com/devonfw/tools/ide/repo/DefaultToolRepository.java @@ -5,10 +5,12 @@ import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.os.SystemInfo; import com.devonfw.tools.ide.url.model.UrlMetadata; -import com.devonfw.tools.ide.url.model.file.UrlDependencyFile; import com.devonfw.tools.ide.url.model.file.UrlDownloadFile; import com.devonfw.tools.ide.url.model.file.UrlDownloadFileMetadata; +import com.devonfw.tools.ide.url.model.file.json.ToolDependencies; import com.devonfw.tools.ide.url.model.file.json.ToolDependency; +import com.devonfw.tools.ide.url.model.folder.UrlEdition; +import com.devonfw.tools.ide.url.model.folder.UrlTool; import com.devonfw.tools.ide.url.model.folder.UrlVersion; import com.devonfw.tools.ide.version.GenericVersionRange; import com.devonfw.tools.ide.version.VersionIdentifier; @@ -55,7 +57,15 @@ protected UrlDownloadFileMetadata getMetadata(String tool, String edition, Versi @Override public Collection findDependencies(String tool, String edition, VersionIdentifier version) { - UrlDependencyFile dependencyFile = this.context.getUrls().getEdition(tool, edition).getDependencyFile(); - return dependencyFile.getDependencies().findDependencies(version, this.context); + UrlEdition urlEdition = this.context.getUrls().getEdition(tool, edition); + ToolDependencies dependencies = urlEdition.getDependencyFile().getDependencies(); + if (dependencies == ToolDependencies.getEmpty()) { + UrlTool urlTool = urlEdition.getParent(); + dependencies = urlTool.getDependencyFile().getDependencies(); + } + if (dependencies != ToolDependencies.getEmpty()) { + this.context.trace("Found dependencies in {}", dependencies); + } + return dependencies.findDependencies(version, this.context); } } diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java index 99f0b842d..009ef5187 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java @@ -12,7 +12,6 @@ import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.io.FileAccess; import com.devonfw.tools.ide.io.FileCopyMode; -import com.devonfw.tools.ide.log.IdeLogLevel; import com.devonfw.tools.ide.process.EnvironmentContext; import com.devonfw.tools.ide.repo.ToolRepository; import com.devonfw.tools.ide.step.Step; @@ -118,8 +117,9 @@ public final boolean install(boolean silent, EnvironmentContext environmentConte } private boolean toolAlreadyInstalled(boolean silent, VersionIdentifier installedVersion, Step step) { - IdeLogLevel level = silent ? IdeLogLevel.DEBUG : IdeLogLevel.INFO; - this.context.level(level).log("Version {} of tool {} is already installed", installedVersion, getToolWithEdition()); + if (!silent) { + this.context.info("Version {} of tool {} is already installed", installedVersion, getToolWithEdition()); + } postInstall(false); step.success(); return false; diff --git a/cli/src/main/java/com/devonfw/tools/ide/url/model/file/UrlDependencyFile.java b/cli/src/main/java/com/devonfw/tools/ide/url/model/file/UrlDependencyFile.java index 60d1e7666..84f3bb9b9 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/url/model/file/UrlDependencyFile.java +++ b/cli/src/main/java/com/devonfw/tools/ide/url/model/file/UrlDependencyFile.java @@ -1,12 +1,12 @@ package com.devonfw.tools.ide.url.model.file; import com.devonfw.tools.ide.url.model.file.json.ToolDependencies; -import com.devonfw.tools.ide.url.model.folder.UrlEdition; +import com.devonfw.tools.ide.url.model.folder.AbstractUrlToolOrEdition; /** * {@link UrlFile} for the "dependency.json" file. */ -public class UrlDependencyFile extends AbstractUrlFile { +public class UrlDependencyFile extends AbstractUrlFile> { public static final String DEPENDENCY_JSON = "dependencies.json"; @@ -18,7 +18,7 @@ public class UrlDependencyFile extends AbstractUrlFile { * * @param parent the {@link #getParent() parent folder}. */ - public UrlDependencyFile(UrlEdition parent) { + public UrlDependencyFile(AbstractUrlToolOrEdition parent) { super(parent, DEPENDENCY_JSON); } diff --git a/cli/src/main/java/com/devonfw/tools/ide/url/model/file/json/ToolDependencies.java b/cli/src/main/java/com/devonfw/tools/ide/url/model/file/json/ToolDependencies.java index 0b22ae6d1..92600ed96 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/url/model/file/json/ToolDependencies.java +++ b/cli/src/main/java/com/devonfw/tools/ide/url/model/file/json/ToolDependencies.java @@ -55,6 +55,15 @@ public List findDependencies(VersionIdentifier version, IdeLogge return Collections.emptyList(); } + @Override + public String toString() { + + if (this == EMPTY) { + return "[empty]"; + } + return this.path.toString(); + } + /** * @param file the {@link Path} to the JSON file to load. * @return the loaded {@link ToolDependencies} or the {@link #getEmpty() empty instance} if given {@link Path} does not exist. diff --git a/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/AbstractUrlToolOrEdition.java b/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/AbstractUrlToolOrEdition.java new file mode 100644 index 000000000..dff1230d3 --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/AbstractUrlToolOrEdition.java @@ -0,0 +1,35 @@ +package com.devonfw.tools.ide.url.model.folder; + +import com.devonfw.tools.ide.url.model.AbstractUrlFolderWithParent; +import com.devonfw.tools.ide.url.model.UrlArtifactWithParent; +import com.devonfw.tools.ide.url.model.file.UrlDependencyFile; + +public abstract class AbstractUrlToolOrEdition

, C extends UrlArtifactWithParent> extends AbstractUrlFolderWithParent { + + private UrlDependencyFile dependencyFile; + + /** + * The constructor. + * + * @param parent the {@link #getParent() parent folder}. + * @param name the {@link #getName() filename}. + */ + public AbstractUrlToolOrEdition(P parent, String name) { + + super(parent, name); + } + + + /** + * @return the {@link UrlDependencyFile} of this {@link UrlEdition}. Will be lazily initialized on the first call of this method. If the file exists, it will + * be loaded, otherwise it will be empty and only created on save if data was added. + */ + public UrlDependencyFile getDependencyFile() { + + if (this.dependencyFile == null) { + this.dependencyFile = new UrlDependencyFile(this); + this.dependencyFile.load(false); + } + return dependencyFile; + } +} diff --git a/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/UrlEdition.java b/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/UrlEdition.java index 86eb0573b..3776a5eb7 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/UrlEdition.java +++ b/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/UrlEdition.java @@ -1,19 +1,15 @@ package com.devonfw.tools.ide.url.model.folder; -import com.devonfw.tools.ide.url.model.AbstractUrlFolderWithParent; -import com.devonfw.tools.ide.url.model.file.UrlDependencyFile; import com.devonfw.tools.ide.url.model.file.UrlSecurityFile; /** * An {@link UrlFolder} representing the actual edition of a {@link UrlTool}. The default edition may have the same {@link #getName() name} as the * {@link UrlTool} itself. However, tools like "intellij" may have editions like "community" or "ultimate". */ -public class UrlEdition extends AbstractUrlFolderWithParent { +public class UrlEdition extends AbstractUrlToolOrEdition { private UrlSecurityFile securityFile; - private UrlDependencyFile dependencyFile; - /** * The constructor. * @@ -49,19 +45,6 @@ public UrlSecurityFile getSecurityFile() { return this.securityFile; } - /** - * @return the {@link UrlDependencyFile} of this {@link UrlEdition}. Will be lazily initialized on the first call of this method. If the file exists, it will - * be loaded, otherwise it will be empty and only created on save if data was added. - */ - public UrlDependencyFile getDependencyFile() { - - if (this.dependencyFile == null) { - this.dependencyFile = new UrlDependencyFile(this); - this.dependencyFile.load(false); - } - return dependencyFile; - } - @Override public void save() { diff --git a/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/UrlTool.java b/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/UrlTool.java index 04d9b7dc3..af7e67fd0 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/UrlTool.java +++ b/cli/src/main/java/com/devonfw/tools/ide/url/model/folder/UrlTool.java @@ -1,11 +1,9 @@ package com.devonfw.tools.ide.url.model.folder; -import com.devonfw.tools.ide.url.model.AbstractUrlFolderWithParent; - /** * An {@link UrlFolder} representing the actual software tool like "docker" or "vscode". */ -public class UrlTool extends AbstractUrlFolderWithParent { +public class UrlTool extends AbstractUrlToolOrEdition { /** * The constructor. diff --git a/cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeTestContext.java b/cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeTestContext.java index 184b02a1a..7fff3da92 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeTestContext.java +++ b/cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeTestContext.java @@ -16,6 +16,7 @@ import com.devonfw.tools.ide.os.SystemInfo; import com.devonfw.tools.ide.process.ProcessContext; import com.devonfw.tools.ide.repo.ToolRepository; +import com.devonfw.tools.ide.url.model.UrlMetadata; import com.devonfw.tools.ide.variable.IdeVariables; /** @@ -31,10 +32,6 @@ public class AbstractIdeTestContext extends AbstractIdeContext { private SystemInfo systemInfo; - private Path dummyUserHome; - - private Boolean online; - private ProcessContext mockContext; /** @@ -58,6 +55,22 @@ public boolean isTest() { return true; } + /** + * @return {@code true} if mutable, {@code false} otherwise. + * @see IdeTestContextMock + */ + protected boolean isMutable() { + + return true; + } + + private void requireMutable() { + + if (!isMutable()) { + throw new IllegalStateException(getClass().getSimpleName() + " is immutable!"); + } + } + @Override protected String readLine() { @@ -68,6 +81,7 @@ protected String readLine() { } public void setAnswers(String... answers) { + requireMutable(); this.answers = answers; this.answerIndex = 0; } @@ -114,20 +128,12 @@ protected SystemPath computeSystemPath() { return new SystemPath(this, envPath); } - @Override - public boolean isOnline() { - - if (this.online != null) { - return this.online.booleanValue(); - } - return super.isOnline(); - } - /** * @param online the mocked {@link #isOnline()} result. */ public void setOnline(Boolean online) { + requireMutable(); this.online = online; } @@ -145,6 +151,7 @@ public ProcessContext newProcess() { */ public void setProcessContext(ProcessContext mockContext) { + requireMutable(); this.mockContext = mockContext; } @@ -160,6 +167,7 @@ public SystemInfo getSystemInfo() { */ public void setSystemInfo(SystemInfo systemInfo) { + requireMutable(); this.systemInfo = systemInfo; } @@ -168,25 +176,24 @@ public void setSystemInfo(SystemInfo systemInfo) { */ public void setUserHome(Path dummyUserHome) { - this.dummyUserHome = dummyUserHome; + requireMutable(); + this.userHome = dummyUserHome; } /** - * @return a dummy UserHome path to avoid global path access in a commandlet test. The defined {@link #dummyUserHome} will be returned if it is not - * {@code null}, else see implementation {@link #AbstractIdeContext}. + * @param urlsPath the mocked {@link #getUrlsPath() urls path}. */ - @Override - public Path getUserHome() { + public void setUrlsPath(Path urlsPath) { - if (this.dummyUserHome != null) { - return this.dummyUserHome; - } - return super.getUserHome(); + this.urlsPath = urlsPath; + this.urlMetadata = new UrlMetadata(this); } - @Override + /** + * @param defaultToolRepository the new value of {@link #getDefaultToolRepository()}. + */ public void setDefaultToolRepository(ToolRepository defaultToolRepository) { - super.setDefaultToolRepository(defaultToolRepository); + this.defaultToolRepository = defaultToolRepository; } } diff --git a/cli/src/test/java/com/devonfw/tools/ide/context/IdeSlf4jContext.java b/cli/src/test/java/com/devonfw/tools/ide/context/IdeSlf4jContext.java index 34e8d3043..e9282653e 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/context/IdeSlf4jContext.java +++ b/cli/src/test/java/com/devonfw/tools/ide/context/IdeSlf4jContext.java @@ -10,6 +10,15 @@ */ public class IdeSlf4jContext extends AbstractIdeTestContext { + private static final Path PATH_MOCK = Path.of("/"); + + /** + * The constructor. + */ + public IdeSlf4jContext() { + this(PATH_MOCK); + } + /** * The constructor. * diff --git a/cli/src/test/java/com/devonfw/tools/ide/context/IdeTestContextMock.java b/cli/src/test/java/com/devonfw/tools/ide/context/IdeTestContextMock.java index 994a40a74..75c92e682 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/context/IdeTestContextMock.java +++ b/cli/src/test/java/com/devonfw/tools/ide/context/IdeTestContextMock.java @@ -1,7 +1,5 @@ package com.devonfw.tools.ide.context; -import java.nio.file.Path; - /** * Mock instance of {@link com.devonfw.tools.ide.context.IdeContext}. * @@ -13,7 +11,13 @@ public class IdeTestContextMock extends IdeSlf4jContext { private IdeTestContextMock() { - super(Path.of("/")); + super(); + } + + @Override + protected boolean isMutable() { + + return false; } /** diff --git a/cli/src/test/java/com/devonfw/tools/ide/tool/eclipse/EclipseTest.java b/cli/src/test/java/com/devonfw/tools/ide/tool/eclipse/EclipseTest.java index a52017f33..d71e85038 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/tool/eclipse/EclipseTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/tool/eclipse/EclipseTest.java @@ -52,7 +52,7 @@ public void testEclipse(String os) throws IOException { //if tool already installed eclipse.install(); - assertThat(context).logAtDebug().hasMessage("Version 2024-09 of tool eclipse is already installed"); + assertThat(context).logAtDebug().hasMessageContaining("Version 2024-09 of tool eclipse is already installed"); } } diff --git a/cli/src/test/java/com/devonfw/tools/ide/tool/intellij/IntellijTest.java b/cli/src/test/java/com/devonfw/tools/ide/tool/intellij/IntellijTest.java index 7b59af64f..c57b4cd30 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/tool/intellij/IntellijTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/tool/intellij/IntellijTest.java @@ -55,7 +55,7 @@ public void testIntellijInstall(String os, WireMockRuntimeInfo wmRuntimeInfo) th //if tool already installed commandlet.install(); - assertThat(this.context).logAtDebug().hasMessage("Version 2023.3.3 of tool intellij is already installed"); + assertThat(this.context).logAtDebug().hasMessageContaining("Version 2023.3.3 of tool intellij is already installed"); } /** diff --git a/cli/src/test/java/com/devonfw/tools/ide/url/model/AbstractUrlModelTest.java b/cli/src/test/java/com/devonfw/tools/ide/url/model/AbstractUrlModelTest.java new file mode 100644 index 000000000..1928fb5a7 --- /dev/null +++ b/cli/src/test/java/com/devonfw/tools/ide/url/model/AbstractUrlModelTest.java @@ -0,0 +1,38 @@ +package com.devonfw.tools.ide.url.model; + +import java.nio.file.Path; + +import org.assertj.core.api.Assertions; + +import com.devonfw.tools.ide.context.AbstractIdeTestContext; +import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.context.IdeSlf4jContext; +import com.devonfw.tools.ide.url.model.folder.UrlRepository; + +/** + * Abstract class for all tests of {@link UrlArtifact}s and {@link UrlRepository}. + */ +public class AbstractUrlModelTest extends Assertions { + + /** {@link Path} to {@link com.devonfw.tools.ide.url.model.folder.UrlRepository} with test-data. */ + protected static final Path URLS_PATH = Path.of("src/test/resources/urls"); + + /** + * @return a new instance of {@link UrlRepository} for testing. + */ + protected UrlRepository newRepo() { + + return UrlRepository.load(URLS_PATH); + } + + /** + * @return a new instance of {@link IdeContext} for testing with urls test-data. + */ + protected IdeContext newContext() { + + AbstractIdeTestContext context = new IdeSlf4jContext(Path.of("")); + context.setUrlsPath(URLS_PATH); + return context; + } + +} diff --git a/cli/src/test/java/com/devonfw/tools/ide/url/model/file/UrlStatusFileTest.java b/cli/src/test/java/com/devonfw/tools/ide/url/model/file/UrlStatusFileTest.java index 168860e2a..fa785e79c 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/url/model/file/UrlStatusFileTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/url/model/file/UrlStatusFileTest.java @@ -1,11 +1,10 @@ package com.devonfw.tools.ide.url.model.file; -import java.nio.file.Path; import java.time.Instant; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import com.devonfw.tools.ide.url.model.AbstractUrlModelTest; import com.devonfw.tools.ide.url.model.file.json.StatusJson; import com.devonfw.tools.ide.url.model.file.json.UrlStatus; import com.devonfw.tools.ide.url.model.file.json.UrlStatusState; @@ -17,7 +16,7 @@ /** * Test of {@link UrlStatusFile}. */ -public class UrlStatusFileTest extends Assertions { +public class UrlStatusFileTest extends AbstractUrlModelTest { /** * Test of {@link UrlStatusFile#getStatusJson()}. @@ -26,7 +25,7 @@ public class UrlStatusFileTest extends Assertions { public void testReadJson() { // given - UrlRepository repo = UrlRepository.load(Path.of("src/test/resources/urls")); + UrlRepository repo = newRepo(); UrlTool tool = repo.getChild("docker"); UrlEdition edition = tool.getChild("rancher"); UrlVersion version = edition.getChild("1.6.2"); diff --git a/cli/src/test/java/com/devonfw/tools/ide/url/model/file/json/ToolDependenciesTest.java b/cli/src/test/java/com/devonfw/tools/ide/url/model/file/json/ToolDependenciesTest.java new file mode 100644 index 000000000..fd7ba382f --- /dev/null +++ b/cli/src/test/java/com/devonfw/tools/ide/url/model/file/json/ToolDependenciesTest.java @@ -0,0 +1,57 @@ +package com.devonfw.tools.ide.url.model.file.json; + +import java.util.Collection; + +import org.junit.jupiter.api.Test; + +import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.url.model.AbstractUrlModelTest; +import com.devonfw.tools.ide.url.model.folder.AbstractUrlToolOrEdition; +import com.devonfw.tools.ide.version.VersionIdentifier; +import com.devonfw.tools.ide.version.VersionRange; + +/** + * Test of {@link com.devonfw.tools.ide.url.model.file.json.ToolDependencies} and {@link AbstractUrlToolOrEdition#getDependencyFile()}. + */ +public class ToolDependenciesTest extends AbstractUrlModelTest { + + + @Test + public void testEditionSpecific() { + + // arrange + IdeContext context = newContext(); + + // act + Collection dependencies = context.getDefaultToolRepository().findDependencies("tomcat", "tomcat", VersionIdentifier.of("11.0.0")); + + // assert + assertThat(dependencies).containsExactly(new ToolDependency("java", VersionRange.of("[17,)"))); + } + + @Test + public void testEditionFallback() { + + // arrange + IdeContext context = newContext(); + + // act + Collection dependencies = context.getDefaultToolRepository().findDependencies("tomcat", "undefined", VersionIdentifier.of("11.0.0")); + + // assert + assertThat(dependencies).containsExactly(new ToolDependency("this-is-the-wrong-file-only-for-testing", VersionRange.of("[1.0,2.0]"))); + } + + @Test + public void testEditionUnspecific() { + + // arrange + IdeContext context = newContext(); + + // act + Collection dependencies = context.getDefaultToolRepository().findDependencies("mvn", "undefined", VersionIdentifier.of("3.9.0")); + + // assert + assertThat(dependencies).containsExactly(new ToolDependency("java", VersionRange.of("[8,)"))); + } +} diff --git a/cli/src/test/resources/urls/mvn/dependencies.json b/cli/src/test/resources/urls/mvn/dependencies.json new file mode 100644 index 000000000..a735640e0 --- /dev/null +++ b/cli/src/test/resources/urls/mvn/dependencies.json @@ -0,0 +1,14 @@ +{ + "[4.0,)": [ + { + "tool": "java", + "versionRange": "[17,)" + } + ], + "[3.0,4.0)": [ + { + "tool": "java", + "versionRange": "[8,)" + } + ] +} diff --git a/cli/src/test/resources/urls/tomcat/dependencies.json b/cli/src/test/resources/urls/tomcat/dependencies.json new file mode 100644 index 000000000..219d347d3 --- /dev/null +++ b/cli/src/test/resources/urls/tomcat/dependencies.json @@ -0,0 +1,8 @@ +{ + "[1.0,99.0)": [ + { + "tool": "this-is-the-wrong-file-only-for-testing", + "versionRange": "[1.0,2.0]" + } + ] +} diff --git a/cli/src/test/resources/urls/tomcat/tomcat/dependencies.json b/cli/src/test/resources/urls/tomcat/tomcat/dependencies.json new file mode 100644 index 000000000..06cb6e947 --- /dev/null +++ b/cli/src/test/resources/urls/tomcat/tomcat/dependencies.json @@ -0,0 +1,50 @@ +{ + "[11.0.0,)": [ + { + "tool": "java", + "versionRange": "[17,)" + } + ], + "[10.1,11.0.0)": [ + { + "tool": "java", + "versionRange": "[11,)" + } + ], + "[10.0,10.1)": [ + { + "tool": "java", + "versionRange": "[8,11)" + } + ], + "[9.0,10.0)": [ + { + "tool": "java", + "versionRange": "[8,11)" + } + ], + "[8.5,9.0)": [ + { + "tool": "java", + "versionRange": "[7,8)" + } + ], + "[8.0,8.5)": [ + { + "tool": "java", + "versionRange": "[7,8)" + } + ], + "[7.0,8.0)": [ + { + "tool": "java", + "versionRange": "[7,8)" + } + ], + "[6.0,7.0)": [ + { + "tool": "java", + "versionRange": "[5,7)" + } + ] +}