Skip to content

Commit

Permalink
Merge branch 'main' into feature/131-support-for-tool-dependecies
Browse files Browse the repository at this point in the history
  • Loading branch information
aBega2000 authored Jan 17, 2024
2 parents 32e4bd1 + e82a1a0 commit 48e3437
Show file tree
Hide file tree
Showing 34 changed files with 1,050 additions and 317 deletions.
564 changes: 564 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/common/Tag.java

Large diffs are not rendered by default.

59 changes: 4 additions & 55 deletions cli/src/main/java/com/devonfw/tools/ide/common/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,14 @@
import java.util.Set;

/**
* TODO hohwille This type ...
*
* Interface for an object that {@link #getTags() has} {@link Tag}s.
*/
public interface Tags {

/** {@link #getTags() Tag} for Java and JVM related tools. */
String TAG_JAVA = "java";

/** {@link #getTags() Tag} for build tools. */
String TAG_BUILD = "build";

/** {@link #getTags() Tag} for quality assurance (QA) tools. */
String TAG_QA = "qa";

/** {@link #getTags() Tag} for artificial intelligence (AI) and machine learning (ML) tools. */
String TAG_AI = "ai";

/** {@link #getTags() Tag} for documentation tools. */
String TAG_DOCUMENTATION = "doc";

/** {@link #getTags() Tag} for tools supporting AsciiDoc. */
String TAG_ASCIIDOC = "adoc";

/** {@link #getTags() Tag} for angular related tools. */
String TAG_ANGULAR = "angular";

/** {@link #getTags() Tag} for TypeScript related tools. */
String TAG_TYPE_SCRIPT = "ts";

/** {@link #getTags() Tag} for generic tools that increase productivity. */
String TAG_PRODUCTIVITY = "productivity";

/** {@link #getTags() Tag} for DotNet related tools. */
String TAG_DOT_NET = ".net";

/** {@link #getTags() Tag} for Python related tools. */
String TAG_PYTHON = "python";

/** {@link #getTags() Tag} for tools that actually represent an IDE (Integrated Development Environment). */
String TAG_IDE = "ide";

/** {@link #getTags() Tag} for tools providing a runtime environment (the core of a programming language). */
String TAG_RUNTIME = "runtime";

/**
* {@link #getTags() Tag} for cloud tools (e.g. CLI to manage infrastructure in the cloud). This is not limited to the
* hyper-scalers but also used for other platforms providing automation like openshift or even github.
* @return a {@link Set} with the tags classifying this object. E.g. for mvn (maven) the tags {@link Tag#JAVA java}
* and {@link Tag#BUILD build} could be associated.
*/
String TAG_CLOUD = "cloud";
Set<Tag> getTags();

/** {@link #getTags() Tag} for infrastructure-as-code (IAC) tools. */
String TAG_IAC = "iac";

/** {@link #getTags() Tag} for frameworks. */
String TAG_FRAMEWORK = "framework";

/**
* @return a {@link Set} with the tags classifying this object. E.g. for mvn (maven) the tags {@link #TAG_JAVA java}
* and {@link #TAG_BUILD build} could be associated.
*/
Set<String> getTags();
}
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public void gitPullOrClone(Path target, String gitRepoUrl) {
if (!gitRepoUrl.startsWith("http")) {
throw new IllegalArgumentException("Invalid git URL '" + gitRepoUrl + "'!");
}
ProcessContext pc = newProcess().directory(target).executable("git");
ProcessContext pc = newProcess().directory(target).executable("git").withEnvVar("GIT_TERMINAL_PROMPT", "0");
if (Files.isDirectory(target.resolve(".git"))) {
ProcessResult result = pc.addArg("remote").run(true);
List<String> remotes = result.getOut();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ default ProcessContext addArgs(List<?>... args) {
return this;
}

/**
* Sets or overrides the specified environment variable only for the planned {@link #run() process execution}. Please
* note that the environment variables are initialized when the {@link ProcessContext} is created. This method
* explicitly set an additional or overrides an existing environment and will have effect for each {@link #run()
* process execution} invoked from this {@link ProcessContext} instance. Be aware of such side-effects when reusing
* the same {@link ProcessContext} to {@link #run() run} multiple commands.
*
* @param key the name of the environment variable (E.g. "PATH").
* @param value the value of the environment variable.
* @return this {@link ProcessContext} for fluent API calls.
*/
ProcessContext withEnvVar(String key, String value);

/**
* Runs the previously configured {@link #executable(Path) command} with the configured {@link #addArgs(String...)
* arguments}. Will reset the {@link #addArgs(String...) arguments} but not the {@link #executable(Path) command} for
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.devonfw.tools.ide.process;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -89,6 +89,13 @@ public ProcessContext addArg(String arg) {
return this;
}

@Override
public ProcessContext withEnvVar(String key, String value) {

this.processBuilder.environment().put(key, value);
return this;
}

@Override
public ProcessResult run(boolean capture) {

Expand Down Expand Up @@ -195,7 +202,7 @@ private String createCommandMessage(String suffix) {
String message = sb.toString();
return message;
}

private boolean hasSheBang(Path file) {

try (InputStream in = Files.newInputStream(file)) {
Expand All @@ -211,15 +218,16 @@ private boolean hasSheBang(Path file) {
}

private String findBashOnWindows() {

// Check if Git Bash exists in the default location
Path defaultPath = Paths.get("C:\\Program Files\\Git\\bin\\bash.exe");
if (Files.exists(defaultPath)) {
return defaultPath.toString();
}

// If not found in the default location, try the registry query
String[] bashVariants = {"GitForWindows", "Cygwin\\setup"};
String[] registryKeys = {"HKEY_LOCAL_MACHINE","HKEY_CURRENT_USER"};
String[] bashVariants = { "GitForWindows", "Cygwin\\setup" };
String[] registryKeys = { "HKEY_LOCAL_MACHINE", "HKEY_CURRENT_USER" };
String regQueryResult;
for (String bashVariant : bashVariants) {
for (String registryKey : registryKeys) {
Expand Down Expand Up @@ -256,9 +264,8 @@ private String findBashOnWindows() {
}
}
}
//no bash found
// no bash found
throw new IllegalStateException("Could not find Bash. Please install Git for Windows and rerun.");
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devonfw.tools.ide.tool;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.process.ProcessContext;
Expand All @@ -24,7 +25,7 @@ public abstract class GlobalToolCommandlet extends ToolCommandlet {
* @param tags the {@link #getTags() tags} classifying the tool. Should be created via {@link Set#of(Object) Set.of}
* method.
*/
public GlobalToolCommandlet(IdeContext context, String tool, Set<String> tags) {
public GlobalToolCommandlet(IdeContext context, String tool, Set<Tag> tags) {

super(context, tool, tags);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package com.devonfw.tools.ide.tool;

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

import com.devonfw.tools.ide.commandlet.Commandlet;
import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.io.FileCopyMode;
Expand All @@ -13,17 +25,6 @@
import com.devonfw.tools.ide.version.VersionRange;
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.nio.file.StandardOpenOption;
import java.util.Set;
import java.util.List;
import java.util.Map;
import java.util.Iterator;
import java.util.stream.Stream;

/**
* {@link ToolCommandlet} that is installed locally into the IDE.
*/
Expand All @@ -41,7 +42,7 @@ public abstract class LocalToolCommandlet extends ToolCommandlet {
* @param tags the {@link #getTags() tags} classifying the tool. Should be created via {@link Set#of(Object) Set.of}
* method.
*/
public LocalToolCommandlet(IdeContext context, String tool, Set<String> tags) {
public LocalToolCommandlet(IdeContext context, String tool, Set<Tag> tags) {

super(context, tool, tags);
}
Expand Down Expand Up @@ -99,7 +100,7 @@ protected boolean doInstall(boolean silent) {
if (installedVersion == null) {
this.context.success("Successfully installed {} in version {}", this.tool, resolvedVersion);
} else {
this.context.success("Successfully installed {} in version {} replacing previous version {]", this.tool,
this.context.success("Successfully installed {} in version {} replacing previous version {}", this.tool,
resolvedVersion, installedVersion);
}
postInstall();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.devonfw.tools.ide.cli.CliException;
import com.devonfw.tools.ide.commandlet.Commandlet;
import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.common.Tags;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
Expand All @@ -31,7 +32,7 @@ public abstract class ToolCommandlet extends Commandlet implements Tags {
/** @see #getName() */
protected final String tool;

private final Set<String> tags;
private final Set<Tag> tags;

/** The commandline arguments to pass to the tool. */
public final StringListProperty arguments;
Expand All @@ -46,7 +47,7 @@ public abstract class ToolCommandlet extends Commandlet implements Tags {
* @param tags the {@link #getTags() tags} classifying the tool. Should be created via {@link Set#of(Object) Set.of}
* method.
*/
public ToolCommandlet(IdeContext context, String tool, Set<String> tags) {
public ToolCommandlet(IdeContext context, String tool, Set<Tag> tags) {

super(context);
this.tool = tool;
Expand All @@ -73,7 +74,7 @@ protected String getBinaryName() {
}

@Override
public final Set<String> getTags() {
public final Set<Tag> getTags() {

return this.tags;
}
Expand Down
5 changes: 3 additions & 2 deletions cli/src/main/java/com/devonfw/tools/ide/tool/az/Azure.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.file.Paths;
import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
Expand All @@ -22,7 +23,7 @@ public class Azure extends LocalToolCommandlet {
*/
public Azure(IdeContext context) {

super(context, "az", Set.of(TAG_CLOUD));
super(context, "az", Set.of(Tag.CLOUD));
}

@Override
Expand All @@ -34,6 +35,6 @@ public void postInstall() {
EnvironmentVariables typeVariables = variables.getByType(EnvironmentVariablesType.CONF);
typeVariables.set("AZURE_CONFIG_DIR", this.context.getConfPath().resolve(".azure").toString(), true);
typeVariables.save();
this.context.getFileAccess().symlink(Paths.get("wbin"), this.getToolPath().resolve("bin"));
this.context.getFileAccess().symlink(Paths.get("wbin"), getToolPath().resolve("bin"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.devonfw.tools.ide.cli.CliArgument;
import com.devonfw.tools.ide.cli.CliException;
import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.process.ProcessContext;
Expand All @@ -32,7 +33,7 @@ public class Eclipse extends IdeToolCommandlet {
*/
public Eclipse(IdeContext context) {

super(context, "eclipse", Set.of(TAG_JAVA, TAG_IDE));
super(context, "eclipse", Set.of(Tag.ECLIPSE));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.devonfw.tools.ide.tool.eclipse;

/**
* {@link EclipseUrlUpdater} for "jee" (C++) edition of Eclipse.
*/
public class EclipseJeeUrlUpdater extends EclipseUrlUpdater {
@Override
protected String getEdition() {

return "jee";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected Pattern getVersionPattern() {
@Override
protected String mapVersion(String version) {

// TODO remove this hack and get versiosn from reliable API
// TODO remove this hack and get versions from reliable API
return super.mapVersion(version.replace(" ", "-"));
}

Expand Down
3 changes: 2 additions & 1 deletion cli/src/main/java/com/devonfw/tools/ide/tool/gh/Gh.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;
Expand All @@ -18,7 +19,7 @@ public class Gh extends LocalToolCommandlet {
*/
public Gh(IdeContext context) {

super(context, "gh", Set.of(TAG_CLOUD));
super(context, "gh", Set.of(Tag.CLOUD));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;
Expand All @@ -19,7 +20,7 @@ public class Gradle extends LocalToolCommandlet {
*/
public Gradle(IdeContext context) {

super(context, "gradle", Set.of(TAG_JAVA, TAG_BUILD));
super(context, "gradle", Set.of(Tag.JAVA, Tag.BUILD));
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions cli/src/main/java/com/devonfw/tools/ide/tool/helm/Helm.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.devonfw.tools.ide.tool.helm;

import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;

import java.util.Set;

/**
* {@link ToolCommandlet} for <a href="https://helm.sh/">Helm</a>, the package manager for Kubernetes.
*/
Expand All @@ -17,7 +18,7 @@ public class Helm extends LocalToolCommandlet {
*/
public Helm(IdeContext context) {

super(context, "helm", Set.of(TAG_CLOUD));
super(context, "helm", Set.of(Tag.KUBERNETES));
}

}
Loading

0 comments on commit 48e3437

Please sign in to comment.