Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#439: refactor tool dependencies and tomcat #515

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
91af92c
#439: Refactored and improved Tool-Dependencies and Tomcat
aBega2000 Aug 5, 2024
49b2735
Merge branch 'main' into feature/439-refactor-tool-dependencies-and-t…
aBega2000 Aug 5, 2024
eff8cbe
#439: Small Changes
aBega2000 Aug 5, 2024
c5286e7
#439: small change in Tomcat Test
aBega2000 Aug 5, 2024
8513f9f
Merge branch 'main' into feature/439-refactor-tool-dependencies-and-t…
jan-vcapgemini Aug 7, 2024
7deee94
#439: Changes after review
aBega2000 Aug 9, 2024
b83ee76
Merge branch 'main' into feature/439-refactor-tool-dependencies-and-t…
aBega2000 Aug 12, 2024
35a321e
#439: Refactoring Changes
aBega2000 Aug 12, 2024
9e02570
#439: Small changes
aBega2000 Aug 12, 2024
0e336ee
#439: Small changes after review
aBega2000 Aug 13, 2024
b054c5a
Merge branch 'devonfw:main' into feature/439-refactor-tool-dependenci…
aBega2000 Aug 13, 2024
c92a690
Merge branch 'main' into feature/439-refactor-tool-dependencies-and-t…
jan-vcapgemini Aug 13, 2024
7c223e5
#439: Changes after review
aBega2000 Aug 13, 2024
2767ed6
Merge branch 'feature/439-refactor-tool-dependencies-and-tomcat' of h…
aBega2000 Aug 13, 2024
ff19243
#439: small change in tomcat.java
aBega2000 Aug 13, 2024
4592bfd
#439: Refactored Dependency.java class
aBega2000 Aug 13, 2024
6778f31
#439: Changes after Review
aBega2000 Aug 14, 2024
426a593
Merge branch 'devonfw:main' into feature/439-refactor-tool-dependenci…
aBega2000 Aug 14, 2024
f26581d
#439: refactored runTool() method
aBega2000 Aug 15, 2024
862eb2f
Merge branch 'feature/439-refactor-tool-dependencies-and-tomcat' of h…
aBega2000 Aug 15, 2024
5c644e8
#439: Added JavaDoc
aBega2000 Aug 16, 2024
5a2ca3e
Merge branch 'main' into feature/439-refactor-tool-dependencies-and-t…
hohwille Aug 19, 2024
abccad7
Merge branch 'main' into feature/439-refactor-tool-dependencies-and-t…
hohwille Aug 22, 2024
3ee6595
Merge branch 'devonfw:main' into feature/439-refactor-tool-dependenci…
aBega2000 Aug 23, 2024
a77c8d1
#439: Changes after Review
aBega2000 Aug 23, 2024
16be639
#439: Changes After Review
aBega2000 Aug 26, 2024
452db88
Merge branch 'main' into feature/439-refactor-tool-dependencies-and-t…
hohwille Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void updateSoftware() {

// update/install the toolCommandlets
for (ToolCommandlet toolCommandlet : toolCommandlets) {
toolCommandlet.install(false);
toolCommandlet.install(null, false);
hohwille marked this conversation as resolved.
Show resolved Hide resolved
}
step.success();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void run() {
if (versionIdentifier != null) {
commandlet.setVersion(versionIdentifier, false);
}
commandlet.install(false);
commandlet.install(null, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private static String getTool(Path path, Path ideRoot) {

private Path findBinaryInOrder(Path path, String tool) {

List<String> extensionPriority = List.of("");
List<String> extensionPriority = List.of("", ".sh");
hohwille marked this conversation as resolved.
Show resolved Hide resolved
if (SystemInfoImpl.INSTANCE.isWindows()) {
extensionPriority = EXTENSION_PRIORITY;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.devonfw.tools.ide.process;

public interface EnvironmentContext {
jan-vcapgemini marked this conversation as resolved.
Show resolved Hide resolved

EnvironmentContext withEnvVar(String key, String value);
hohwille marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Wrapper for {@link ProcessBuilder} to simplify its usage and avoid common mistakes and pitfalls.
*/
public interface ProcessContext {
public interface ProcessContext extends EnvironmentContext {

/**
* @param handling the desired {@link ProcessErrorHandling}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.devonfw.tools.ide.tool;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.process.EnvironmentContext;
import com.devonfw.tools.ide.repo.CustomTool;
import com.devonfw.tools.ide.version.VersionIdentifier;


public class CustomToolCommandlet extends LocalToolCommandlet {

private CustomTool customTool;
Expand All @@ -16,15 +16,15 @@ public CustomToolCommandlet(IdeContext context, CustomTool customTool) {
}

@Override
public ToolInstallation installTool(VersionIdentifier version) {
public ToolInstallation installTool(EnvironmentContext environmentContext, VersionIdentifier version) {
hohwille marked this conversation as resolved.
Show resolved Hide resolved

return installTool(version, this.customTool.getEdition());
return installTool(environmentContext, version, this.customTool.getEdition());
}

@Override
public ToolInstallation installTool(VersionIdentifier version, String edition) {
public ToolInstallation installTool(EnvironmentContext environmentContext, VersionIdentifier version, String edition) {

return installTool(version, edition, this.context.getCustomToolRepository());
return installTool(environmentContext, version, edition, this.context.getCustomToolRepository());
}

@Override
Expand Down
53 changes: 24 additions & 29 deletions cli/src/main/java/com/devonfw/tools/ide/tool/Dependency.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package com.devonfw.tools.ide.tool;

import java.io.BufferedReader;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.url.model.file.UrlDependencyFile;
import com.devonfw.tools.ide.url.model.file.dependencyJson.DependencyInfo;
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
import com.devonfw.tools.ide.url.model.folder.UrlRepository;
import com.devonfw.tools.ide.url.model.folder.UrlTool;
import com.devonfw.tools.ide.version.VersionIdentifier;
import com.devonfw.tools.ide.version.VersionRange;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.json.mapping.JsonMapping;
import com.devonfw.tools.ide.url.model.file.dependencyJson.DependencyInfo;
import com.devonfw.tools.ide.version.VersionIdentifier;
import com.devonfw.tools.ide.version.VersionRange;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Class to represent the functionality of installing the dependencies when a tool is being installed.
*/
Expand All @@ -27,10 +26,6 @@ public class Dependency {

private final String tool;

private static final String DEPENDENCY_FILENAME = "dependencies.json";

private static final ObjectMapper MAPPER = JsonMapping.create();

/**
* The constructor.
*
Expand All @@ -49,10 +44,17 @@ public Dependency(IdeContext context, String tool) {
* @param toolEdition the edition of the tool.
* @return the {@link Path} of the dependency.json file
*/
public Path getDependencyJsonPath(String toolEdition) {
public boolean existsDependencyJsonPath(String toolEdition) {

Path toolPath = this.context.getUrlsPath().resolve(this.tool).resolve(toolEdition);
return toolPath.resolve(DEPENDENCY_FILENAME);
return Files.exists(getDependencyUrlEdition(toolEdition).getDependencyFile().getPath());
hohwille marked this conversation as resolved.
Show resolved Hide resolved
}

private UrlEdition getDependencyUrlEdition(String toolEdition) {

UrlRepository urlRepository = new UrlRepository(this.context.getUrlsPath());
UrlTool urlTool = new UrlTool(urlRepository, tool);
UrlEdition urlEdition = new UrlEdition(urlTool, toolEdition);
return urlEdition;
hohwille marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -64,16 +66,9 @@ public Path getDependencyJsonPath(String toolEdition) {
*/
public List<DependencyInfo> readJson(VersionIdentifier version, String toolEdition) {

Path dependencyJsonPath = getDependencyJsonPath(toolEdition);

try (BufferedReader reader = Files.newBufferedReader(dependencyJsonPath)) {
TypeReference<HashMap<VersionRange, List<DependencyInfo>>> typeRef = new TypeReference<>() {
};
Map<VersionRange, List<DependencyInfo>> dependencyJson = MAPPER.readValue(reader, typeRef);
return findDependenciesFromJson(dependencyJson, version);
} catch (IOException e) {
throw new RuntimeException(e);
}
UrlDependencyFile urlDependencyFile = getDependencyUrlEdition(toolEdition).getDependencyFile();
Map<VersionRange, List<DependencyInfo>> dependencyMap = urlDependencyFile.getDependencyMap();
return findDependenciesFromJson(dependencyMap, version);
}

/**
Expand Down Expand Up @@ -121,9 +116,9 @@ public Path versionExistsInRepository(Path dependencyRepositoryPath, VersionRang
return Path.of("");
}

private List<DependencyInfo> findDependenciesFromJson(Map<VersionRange, List<DependencyInfo>> dependencies, VersionIdentifier toolVersionToCheck) {
private List<DependencyInfo> findDependenciesFromJson(Map<VersionRange, List<DependencyInfo>> dependencyMap, VersionIdentifier toolVersionToCheck) {

for (Map.Entry<VersionRange, List<DependencyInfo>> map : dependencies.entrySet()) {
for (Map.Entry<VersionRange, List<DependencyInfo>> map : dependencyMap.entrySet()) {
hohwille marked this conversation as resolved.
Show resolved Hide resolved

VersionRange foundToolVersionRange = map.getKey();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.process.EnvironmentContext;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.process.ProcessErrorHandling;
import com.devonfw.tools.ide.repo.ToolRepository;
Expand Down Expand Up @@ -104,7 +105,7 @@ protected boolean isExtract() {
}

@Override
protected boolean doInstall(boolean silent) {
protected boolean doInstall(EnvironmentContext environmentContext, boolean silent) {

Path binaryPath = this.context.getPath().findBinary(Path.of(getBinaryName()));
// if force mode is enabled, go through with the installation even if the tool is already installed
Expand Down
Loading
Loading