Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
a9f80db
#131: Support for tool dependencies
aBega2000 Nov 20, 2023
41d23ef
Merge branch 'main' of https://github.com/aBega2000/IDEasy into featu…
aBega2000 Nov 20, 2023
96f807f
Changes after review
aBega2000 Nov 22, 2023
ecd1df3
Update ToolCommandlet.java
aBega2000 Nov 22, 2023
b222aa5
#131: Changes after reviews
aBega2000 Nov 27, 2023
6080c80
Merge branch 'feature/131-support-for-tool-dependecies' of https://gi…
aBega2000 Nov 27, 2023
f7ff2c2
#131: Changes after review
aBega2000 Dec 1, 2023
e44d547
#131: Changes after review
aBega2000 Dec 13, 2023
4a6c8e9
Merge branch 'devonfw:main' into feature/131-support-for-tool-depende…
aBega2000 Dec 13, 2023
2805f0c
Merge branch 'feature/131-support-for-tool-dependecies' of https://gi…
aBega2000 Dec 13, 2023
67c5c9c
Small Change
aBega2000 Dec 13, 2023
cc8c0cb
#131: Changes after review
aBega2000 Dec 14, 2023
ed0b0f3
Merge branch 'feature/131-support-for-tool-dependecies' of https://gi…
aBega2000 Dec 14, 2023
18884c2
Merge branch 'main' into feature/131-support-for-tool-dependecies
jan-vcapgemini Jan 8, 2024
f2ed771
Merge branch 'devonfw:main' into feature/131-support-for-tool-depende…
aBega2000 Jan 8, 2024
32e4bd1
#131: Changes after review and according to VersionRange with boundar…
aBega2000 Jan 10, 2024
48e3437
Merge branch 'main' into feature/131-support-for-tool-dependecies
aBega2000 Jan 17, 2024
a3d82b9
Merge branch 'main' into feature/131-support-for-tool-dependecies
hohwille Jan 19, 2024
21781f2
#131: Resolved Conflicts
aBega2000 Feb 1, 2024
e4ad57b
Merge commit '43272714a125e23e8b47d4501a16b722cde17ab2' into feature/…
aBega2000 Feb 1, 2024
b9846f8
Merge branch 'feature/131-support-for-tool-dependecies' of https://gi…
aBega2000 Feb 1, 2024
52840dc
Merge branch 'main' of https://github.com/aBega2000/IDEasy into featu…
aBega2000 Feb 1, 2024
fbcbf31
#131: Changes after review
aBega2000 Feb 7, 2024
0a9b2b5
Merge branch 'main' into feature/131-support-for-tool-dependecies
aBega2000 Mar 7, 2024
8f04879
Merge branch 'devonfw:main' into feature/131-support-for-tool-depende…
aBega2000 Mar 12, 2024
c9cbe8d
#36: Tool Commandlet for Tomcat
aBega2000 Mar 17, 2024
21ea541
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Mar 17, 2024
2dc8b65
#36: Adding the software java folder
aBega2000 Mar 17, 2024
584c5f4
Update DependencyJson.java
hohwille Mar 19, 2024
f554f4d
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Mar 19, 2024
19badd0
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Mar 21, 2024
eb150c6
#36: changes after review
aBega2000 Mar 21, 2024
51479cf
Change in imports
aBega2000 Mar 21, 2024
4c0865b
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Apr 7, 2024
c35281b
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Apr 9, 2024
d5430eb
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Apr 9, 2024
de64024
#36: Added Mac testing
aBega2000 Apr 9, 2024
a9c30dd
#36: Changes after Review
aBega2000 Apr 10, 2024
a0be0a6
#36: Added port printing for information
aBega2000 Apr 11, 2024
c14bdd0
Solved confilcts
aBega2000 Apr 16, 2024
2145ed6
Merge branch 'main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Apr 16, 2024
75fa5fb
#36: Added more tests
aBega2000 Apr 17, 2024
28c2b83
#36: changes after error
aBega2000 Apr 17, 2024
c57392c
#36: added missing folder
aBega2000 Apr 17, 2024
cd43176
Update dependencies.json
aBega2000 Apr 18, 2024
1d6aca2
#36: Changed tests for running tomcat
aBega2000 Apr 19, 2024
f604d23
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Apr 19, 2024
d4e35fc
#36: Changes after review
aBega2000 Apr 25, 2024
dce9f15
changed line ending
aBega2000 Apr 29, 2024
7a808ec
Merge branch 'main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Apr 29, 2024
2c7abd4
#36: Changes after review
aBega2000 May 1, 2024
711e930
Update TomcatTest.java
aBega2000 May 1, 2024
d2833ab
#36: Changed the dependency env variables logic
aBega2000 May 1, 2024
ac94cd5
Merge branch 'feature/36-tool-commandlet-for-tomcat' of https://githu…
aBega2000 May 1, 2024
fa81af9
#36: Small change in LocalToolCommandlet
aBega2000 May 1, 2024
b456ece
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 May 1, 2024
1959b73
#36: Small changes in LocalToolCommandlet
aBega2000 May 2, 2024
065f60c
Merge branch 'feature/36-tool-commandlet-for-tomcat' of https://githu…
aBega2000 May 2, 2024
8a9e631
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 May 7, 2024
050101e
#36: Added functionalities
aBega2000 May 15, 2024
02ac6f3
#36: Name change
aBega2000 May 15, 2024
f384758
#36: Change for tests
aBega2000 May 16, 2024
1f0ba63
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 May 16, 2024
7bb7c9b
#36: Error case fixed
aBega2000 May 16, 2024
2ba9328
#36: Added functionaliy and JavaDocs
aBega2000 May 20, 2024
9344a04
#36: Changed JavaDoc
aBega2000 May 22, 2024
e2e562d
Merge branch 'main' into feature/36-tool-commandlet-for-tomcat
aBega2000 May 22, 2024
de3ab62
#36: Changes to Help.properites
aBega2000 May 22, 2024
dcb1d4c
#36: Fixed test error
aBega2000 May 22, 2024
0a26abe
#36: Added installation before running
aBega2000 May 23, 2024
758a3a2
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 May 23, 2024
1ec1585
Merge branch 'main' into feature/36-tool-commandlet-for-tomcat
aBega2000 May 29, 2024
c501587
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Jun 17, 2024
499136d
Merge branch 'main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Jun 27, 2024
6a294cd
Updated Help.properties
aBega2000 Jul 2, 2024
42f7a0c
Merge branch 'devonfw:main' into feature/36-tool-commandlet-for-tomcat
aBega2000 Jul 2, 2024
5e97f88
Merge branch 'main' into feature/36-tool-commandlet-for-tomcat
hohwille Jul 3, 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 @@ -29,6 +29,7 @@
import com.devonfw.tools.ide.tool.quarkus.Quarkus;
import com.devonfw.tools.ide.tool.sonar.Sonar;
import com.devonfw.tools.ide.tool.terraform.Terraform;
import com.devonfw.tools.ide.tool.tomcat.Tomcat;
import com.devonfw.tools.ide.tool.vscode.Vscode;

import java.util.Collection;
Expand Down Expand Up @@ -92,6 +93,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Quarkus(context));
add(new Kotlinc(context));
add(new KotlincNative(context));
add(new Tomcat(context));
add(new Vscode(context));
add(new Azure(context));
add(new Aws(context));
Expand Down
136 changes: 136 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/Dependency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package com.devonfw.tools.ide.tool;

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;

import java.io.BufferedReader;
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;

/**
* Class to represent the functionality of installing the dependencies when a tool is being installed.
*/
public class Dependency {

private final IdeContext context;

private final String tool;

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

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

/**
* The constructor.
*
* @param context the {@link IdeContext}.
* @param tool the tool of the context
*/
public Dependency(IdeContext context, String tool) {

this.context = context;
this.tool = tool;
}

/**
* Method to get the dependency json file path
*
* @param toolEdition the edition of the tool.
* @return the {@link Path} of the dependency.json file
*/
public Path getDependencyJsonPath(String toolEdition) {

Path toolPath = this.context.getUrlsPath().resolve(tool).resolve(toolEdition);
return toolPath.resolve(DEPENDENCY_FILENAME);
}

/**
* Method to read the Json file
*
* @param version of the main tool to be installed.
* @param toolEdition of the main tool, so that the correct folder can be checked to find the dependency json file
* @return the {@link List} of {@link DependencyInfo} to be installed
*/
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);
}
}

/**
* Method to search the List of versions available in the ide and find the right version to install
*
* @param dependencyFound the {@link DependencyInfo} of the dependency that was found that needs to be installed
* @return {@link VersionIdentifier} of the dependency that is to be installed
*/
public VersionIdentifier findDependencyVersionToInstall(DependencyInfo dependencyFound) {

String dependencyEdition = this.context.getVariables().getToolEdition(dependencyFound.getTool());

List<VersionIdentifier> versions = this.context.getUrls().getSortedVersions(dependencyFound.getTool(), dependencyEdition);

for (VersionIdentifier vi : versions) {
if (dependencyFound.getVersionRange().contains(vi)) {
return vi;
}
}
return null;
}

/**
* Method to check if in the repository of the dependency there is a Version greater or equal to the version range to be installed, and to return the path of
* this version if it exists
*
* @param dependencyRepositoryPath the {@link Path} of the dependency repository
* @param dependencyVersionRangeFound the {@link VersionRange} of the dependency version to be installed
* @return the {@link Path} of such version if it exists in repository already, an empty Path
*/
public Path versionExistsInRepository(Path dependencyRepositoryPath, VersionRange dependencyVersionRangeFound) {

try (Stream<Path> versions = Files.list(dependencyRepositoryPath)) {
Iterator<Path> versionsIterator = versions.iterator();
while (versionsIterator.hasNext()) {
VersionIdentifier versionFound = VersionIdentifier.of(versionsIterator.next().getFileName().toString());
if (dependencyVersionRangeFound.contains(versionFound)) {
assert versionFound != null;
return dependencyRepositoryPath.resolve(versionFound.toString());
}
}
} catch (IOException e) {
throw new IllegalStateException("Failed to iterate through " + dependencyRepositoryPath, e);
}
return Path.of("");
}

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

for (Map.Entry<VersionRange, List<DependencyInfo>> map : dependencies.entrySet()) {

VersionRange foundToolVersionRange = map.getKey();

if (foundToolVersionRange.contains(toolVersionToCheck)) {
return map.getValue();
}
}
return null;
}
}
145 changes: 145 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,33 @@
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.ProcessContext;
import com.devonfw.tools.ide.process.ProcessErrorHandling;
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.repo.ToolRepository;
import com.devonfw.tools.ide.step.Step;
import com.devonfw.tools.ide.url.model.file.dependencyJson.DependencyInfo;
import com.devonfw.tools.ide.version.VersionIdentifier;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

/**
* {@link ToolCommandlet} that is installed locally into the IDE.
*/
public abstract class LocalToolCommandlet extends ToolCommandlet {

protected HashMap<String, String> dependenciesEnvVariableNames = null;

protected HashMap<String, String> dependenciesEnvVariablePaths = new HashMap<>();

private final Dependency dependency = new Dependency(this.context, this.tool);

/**
* The constructor.
*
Expand Down Expand Up @@ -133,6 +145,13 @@ public ToolInstallation installInRepo(VersionIdentifier version, String edition)
public ToolInstallation installInRepo(VersionIdentifier version, String edition, ToolRepository toolRepository) {

VersionIdentifier resolvedVersion = toolRepository.resolveVersion(this.tool, edition, version);

if (Files.exists(this.dependency.getDependencyJsonPath(getEdition()))) {
installDependencies(resolvedVersion);
} else {
this.context.trace("No Dependencies file found");
}

Path toolPath = this.context.getSoftwareRepositoryPath().resolve(toolRepository.getId()).resolve(this.tool).resolve(edition)
.resolve(resolvedVersion.toString());
Path toolVersionFile = toolPath.resolve(IdeContext.FILE_SOFTWARE_VERSION);
Expand Down Expand Up @@ -283,4 +302,130 @@ private ToolInstallation createToolInstallation(Path rootDir, VersionIdentifier
return createToolInstallation(rootDir, resolvedVersion, toolVersionFile, false);
}

@Override
public void runTool(ProcessMode processMode, VersionIdentifier toolVersion, String... args) {

Path binaryPath;
Path toolPath = Path.of(getBinaryName());
if (toolVersion == null) {
install(true);
binaryPath = toolPath;
} else {
throw new UnsupportedOperationException("Not yet implemented!");
}

if (Files.exists(this.dependency.getDependencyJsonPath(getEdition()))) {
setDependencyRepository(getInstalledVersion());
} else {
this.context.trace("No Dependencies file found");
}

ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING).executable(binaryPath).addArgs(args);

for (String key : this.dependenciesEnvVariablePaths.keySet()) {

String dependencyPath = this.dependenciesEnvVariablePaths.get(key);
pc = pc.withEnvVar(key, dependencyPath);
}

pc.run(processMode);
}

private void installDependencies(VersionIdentifier version) {

List<DependencyInfo> dependencies = this.dependency.readJson(version, getEdition());

for (DependencyInfo dependencyInfo : dependencies) {

String dependencyName = dependencyInfo.getTool();
VersionIdentifier dependencyVersionToInstall = this.dependency.findDependencyVersionToInstall(dependencyInfo);
if (dependencyVersionToInstall == null) {
continue;
}

ToolCommandlet dependencyTool = this.context.getCommandletManager().getToolCommandlet(dependencyName);
Path dependencyRepository = getDependencySoftwareRepository(dependencyName, dependencyTool.getEdition());

if (!Files.exists(dependencyRepository)) {
installDependencyInRepo(dependencyName, dependencyTool, dependencyVersionToInstall);
} else {
Path versionExistingInRepository = this.dependency.versionExistsInRepository(dependencyRepository, dependencyInfo.getVersionRange());
if (versionExistingInRepository.equals(Path.of(""))) {
installDependencyInRepo(dependencyName, dependencyTool, dependencyVersionToInstall);
} else {
this.context.info("Necessary version of the dependency {} is already installed in repository", dependencyName);
}
}
}
}

private void installDependencyInRepo(String dependencyName, ToolCommandlet dependencyTool, VersionIdentifier dependencyVersionToInstall) {

this.context.info("The version {} of the dependency {} is being installed", dependencyVersionToInstall, dependencyName);
LocalToolCommandlet dependencyLocal = (LocalToolCommandlet) dependencyTool;
dependencyLocal.installInRepo(dependencyVersionToInstall);
this.context.info("The version {} of the dependency {} was successfully installed", dependencyVersionToInstall, dependencyName);
}

protected void setDependencyRepository(VersionIdentifier version) {

List<DependencyInfo> dependencies = this.dependency.readJson(version, getEdition());

for (DependencyInfo dependencyInfo : dependencies) {
String dependencyName = dependencyInfo.getTool();
VersionIdentifier dependencyVersionToInstall = this.dependency.findDependencyVersionToInstall(dependencyInfo);
if (dependencyVersionToInstall == null) {
continue;
}

ToolCommandlet dependencyTool = this.context.getCommandletManager().getToolCommandlet(dependencyName);
Path dependencyRepository = getDependencySoftwareRepository(dependencyName, dependencyTool.getEdition());
Path versionExistingInRepository = this.dependency.versionExistsInRepository(dependencyRepository, dependencyInfo.getVersionRange());
Path dependencyPath;

if (versionExistingInRepository.equals(Path.of(""))) {
dependencyPath = dependencyRepository.resolve(dependencyVersionToInstall.toString());
} else {
dependencyPath = dependencyRepository.resolve(versionExistingInRepository);
}
setDependencyEnvironmentPath(getDependencyEnvironmentName(dependencyName), dependencyPath);
}
}

private void setDependencyEnvironmentPath(String dependencyEnvironmentName, Path dependencyPath) {

this.dependenciesEnvVariablePaths.put(dependencyEnvironmentName, dependencyPath.toString());

}

/**
* Method to return the list of the environment variable name for the dependencies. If necessary, it should be overridden in the specific tool
*
* @return the {@link HashMap} with the dependency name mapped to the env variable, for example ( java: JAVA_HOME )
*/

protected HashMap<String, String> listOfDependencyEnvVariableNames() {

return dependenciesEnvVariableNames;
}

private String getDependencyEnvironmentName(String dependencyName) {

HashMap<String, String> envVariableName = listOfDependencyEnvVariableNames();

if (envVariableName != null) {
return envVariableName.get(dependencyName);
}

return dependencyName.toUpperCase() + "_HOME";
}

private Path getDependencySoftwareRepository(String dependencyName, String dependencyEdition) {

String defaultToolRepositoryId = this.context.getDefaultToolRepository().getId();
Path dependencyRepository = this.context.getSoftwareRepositoryPath().resolve(defaultToolRepositoryId).resolve(dependencyName).resolve(dependencyEdition);

return dependencyRepository;
}

}
Loading