Skip to content

Commit

Permalink
#22: implement tool commandlet graalvm (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceHeu authored Apr 25, 2024
1 parent e0e6f35 commit d2bfec2
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.devonfw.tools.ide.tool.eclipse.Eclipse;
import com.devonfw.tools.ide.tool.gcviewer.GcViewer;
import com.devonfw.tools.ide.tool.gh.Gh;
import com.devonfw.tools.ide.tool.graalvm.GraalVm;
import com.devonfw.tools.ide.tool.gradle.Gradle;
import com.devonfw.tools.ide.tool.helm.Helm;
import com.devonfw.tools.ide.tool.jasypt.Jasypt;
Expand Down Expand Up @@ -95,6 +96,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Jasypt(context));
add(new Docker(context));
add(new Sonar(context));
add(new GraalVm(context));
}

private void add(Commandlet commandlet) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.devonfw.tools.ide.commandlet;

import com.devonfw.tools.ide.context.AbstractIdeContext;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.property.StringProperty;
Expand All @@ -14,7 +13,6 @@ public class CreateCommandlet extends AbstractUpdateCommandlet {

public final StringProperty newProject;


/**
* The constructor.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.devonfw.tools.ide.commandlet;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.StringProperty;

/**
* {@link Commandlet} to update settings, software and repositories
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
package com.devonfw.tools.ide.context;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
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.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

import com.devonfw.tools.ide.cli.CliAbortException;
import com.devonfw.tools.ide.cli.CliArgument;
import com.devonfw.tools.ide.cli.CliArguments;
Expand Down Expand Up @@ -50,6 +36,20 @@
import com.devonfw.tools.ide.step.StepImpl;
import com.devonfw.tools.ide.url.model.UrlMetadata;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
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.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

/**
* Abstract base implementation of {@link IdeContext}.
*/
Expand All @@ -69,6 +69,8 @@ public abstract class AbstractIdeContext implements IdeContext {

private Path softwarePath;

private Path softwareExtraPath;

private Path softwareRepositoryPath;

private Path pluginsPath;
Expand Down Expand Up @@ -235,12 +237,14 @@ public void setCwd(Path userDir, String workspace, Path ideHome) {
this.confPath = null;
this.settingsPath = null;
this.softwarePath = null;
this.softwareExtraPath = null;
this.pluginsPath = null;
} else {
this.workspacePath = this.ideHome.resolve(FOLDER_WORKSPACES).resolve(this.workspaceName);
this.confPath = this.ideHome.resolve(FOLDER_CONF);
this.settingsPath = this.ideHome.resolve(FOLDER_SETTINGS);
this.softwarePath = this.ideHome.resolve(FOLDER_SOFTWARE);
this.softwareExtraPath = this.softwarePath.resolve(FOLDER_EXTRA);
this.pluginsPath = this.ideHome.resolve(FOLDER_PLUGINS);
}
if (isTest()) {
Expand Down Expand Up @@ -459,6 +463,12 @@ public Path getSoftwarePath() {
return this.softwarePath;
}

@Override
public Path getSoftwareExtraPath() {

return this.softwareExtraPath;
}

@Override
public Path getSoftwareRepositoryPath() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public interface IdeContext extends IdeLogger {
/** The name of the app folder inside a MacOS app. */
String FOLDER_APP = "app";

/** The name of the extra folder inside the software folder */
String FOLDER_EXTRA = "extra";

/**
* The name of the {@link #getPluginsPath() plugins folder} and also the plugins folder inside the IDE folders of {@link #getSettingsPath() settings} (e.g.
* settings/eclipse/plugins).
Expand Down Expand Up @@ -311,6 +314,12 @@ default void requireOnline(String purpose) {
*/
Path getSoftwarePath();

/**
* @return the {@link Path} to the extra folder inside software folder inside {@link #getIdeHome() IDE_HOME}. All tools for that IDE instance will be linked
* here from the {@link #getSoftwareRepositoryPath() software repository} as sub-folder named after the according tool.
*/
Path getSoftwareExtraPath();

/**
* @return the {@link Path} to the global software repository. This is the central directory where the tools are extracted physically on the local disc. Those
* are shared among all IDE instances (see {@link #getIdeHome() IDE_HOME}) via symbolic links (see {@link #getSoftwarePath()}). Therefore this repository
Expand Down
111 changes: 55 additions & 56 deletions cli/src/main/java/com/devonfw/tools/ide/log/IdeSubLogger.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
package com.devonfw.tools.ide.log;

/**
* Interface for a logger to {@link #log(String) log a message} on a specific {@link #getLevel() log-level}.
*/
public interface IdeSubLogger {

/**
* @param message the message to log.
*/
default void log(String message) {

log(null, message);
}

/**
* @param error the {@link Throwable} that was catched and should be logged or {@code null} for no error.
* @param message the message to log.
* @param args the dynamic arguments to fill in.
* @return the message headline that was logged.
*/
default String log(String message, Object... args) {

return log(null, message, args);
}

/**
* @param error the {@link Throwable} that was catched and should be logged or {@code null} for no error.
* @param message the message to log.
* @return the message headline that was logged.
*/
default String log(Throwable error, String message) {

return log(error, message, (Object[]) null);
}

/**
* @param error the {@link Throwable} that was catched and should be logged or {@code null} for no error.
* @param message the message to log.
* @param args the dynamic arguments to fill in.
* @return the message headline that was logged.
*/
String log(Throwable error, String message, Object... args);

/**
* @return {@code true} if this logger is enabled, {@code false} otherwise (this logger does nothing and all
* {@link #log(String) logged messages} with be ignored).
*/
boolean isEnabled();

/**
* @return the {@link IdeLogLevel} of this logger.
*/
IdeLogLevel getLevel();

}
package com.devonfw.tools.ide.log;

/**
* Interface for a logger to {@link #log(String) log a message} on a specific {@link #getLevel() log-level}.
*/
public interface IdeSubLogger {

/**
* @param message the message to log.
*/
default void log(String message) {

log(null, message);
}

/**
* @param message the message to log.
* @param args the dynamic arguments to fill in.
* @return the message headline that was logged.
*/
default String log(String message, Object... args) {

return log(null, message, args);
}

/**
* @param error the {@link Throwable} that was catched and should be logged or {@code null} for no error.
* @param message the message to log.
* @return the message headline that was logged.
*/
default String log(Throwable error, String message) {

return log(error, message, (Object[]) null);
}

/**
* @param error the {@link Throwable} that was catched and should be logged or {@code null} for no error.
* @param message the message to log.
* @param args the dynamic arguments to fill in.
* @return the message headline that was logged.
*/
String log(Throwable error, String message, Object... args);

/**
* @return {@code true} if this logger is enabled, {@code false} otherwise (this logger does nothing and all {@link #log(String) logged messages} with be
* ignored).
*/
boolean isEnabled();

/**
* @return the {@link IdeLogLevel} of this logger.
*/
IdeLogLevel getLevel();

}
3 changes: 1 addition & 2 deletions cli/src/main/java/com/devonfw/tools/ide/step/StepImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ private void end(Boolean newSuccess, Throwable error, boolean suppress, String m
if (!firstCallOfEnd) {
assert (this.duration > 0);
if (newSuccess != null) {
this.context.warning("Step '{}' already ended with {} and now ended again with {}.", this.name, this.success,
newSuccess);
this.context.warning("Step '{}' already ended with {} and now ended again with {}.", this.name, this.success, newSuccess);
} else {
return;
}
Expand Down
54 changes: 54 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/graalvm/GraalVm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.devonfw.tools.ide.tool.graalvm;

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;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.version.VersionIdentifier;

import java.nio.file.Path;
import java.util.Set;

/**
* {@link LocalToolCommandlet} for <a href="https://www.graalvm.org/">GraalVM</a>, an advanced JDK with ahead-of-time Native Image compilation.
*/
public class GraalVm extends LocalToolCommandlet {

/**
* The constructor.
*
* @param context the {@link IdeContext}.
*/
public GraalVm(IdeContext context) {

super(context, "graalvm", Set.of(Tag.JAVA, Tag.RUNTIME));
}

@Override
public Path getToolPath() {

return this.context.getSoftwareExtraPath().resolve(getName());
}

@Override
public VersionIdentifier getInstalledVersion() {

return super.getInstalledVersion(getToolPath());
}

@Override
protected String getBinaryName() {

return getToolPath().resolve(IdeContext.FOLDER_BIN).resolve("java").toString();
}

@Override
public void postInstall() {

EnvironmentVariables envVars = this.context.getVariables().getByType(EnvironmentVariablesType.CONF);
envVars.set("GRAALVM_HOME", getToolPath().toString(), true);
envVars.save();
super.postInstall();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public interface IdeVariables {
VariableDefinitionString DOCKER_EDITION = new VariableDefinitionString("DOCKER_EDITION", null, c -> "rancher");

/** {@link VariableDefinition} for {@link com.devonfw.tools.ide.context.IdeContext#getWorkspaceName() WORKSPACE}. */
VariableDefinitionString GRAALVM_EDITION = new VariableDefinitionString("GRAALVM_EDITION", null, c -> "community");

/** {@link VariableDefinition} for options of jasypt */
VariableDefinitionString JASYPT_OPTS = new VariableDefinitionString("JASYPT_OPTS", null,
Expand All @@ -59,7 +58,7 @@ public interface IdeVariables {

/** A {@link Collection} with all pre-defined {@link VariableDefinition}s. */
Collection<VariableDefinition<?>> VARIABLES = List.of(PATH, HOME, WORKSPACE_PATH, IDE_HOME, IDE_ROOT, WORKSPACE, IDE_TOOLS, CREATE_START_SCRIPTS,
IDE_MIN_VERSION, MVN_VERSION, DOCKER_EDITION, GRAALVM_EDITION, JASYPT_OPTS, MAVEN_ARGS, PROJECT_NAME);
IDE_MIN_VERSION, MVN_VERSION, DOCKER_EDITION, JASYPT_OPTS, MAVEN_ARGS, PROJECT_NAME);

/**
* @param name the name of the requested {@link VariableDefinition}.
Expand Down
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cmd-gh=Tool commandlet for GitHub CLI.
cmd-repository=setup the pre-configured git repository.
cmd-create=create a new IDEasy project.
cmd-gradle=Tool commandlet for Gradle (Build-Tool).
cmd-graalvm=Tool commandlet for GraalVm.
cmd-helm=Tool commandlet for Helm (Kubernetes Package Manager).
cmd-help=Prints this help.
cmd-install=Install the selected tool.
Expand Down
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cmd-vscode=Werkzeug Kommando für Visual Studio Code (IDE).
cmd-cobigen=Werkzeug Kommando für Cobigen.
cmd-jasypt=Werkzeug Kommando für Jasypt.
cmd-sonar=Werkzeug Kommando für SonarQube.
cmd-graalvm=Werkzeug Kommando für GraalVm.
cmd-docker=Werkzeug Kommando für Docker.
cmd-gcviewer=Werkzeug Kommando für GC Viewer.
val-args=Die Kommandozeilen-Argumente zur Übergabe an das Werkzeug.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.devonfw.tools.ide.tool.graalvm;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import org.junit.jupiter.api.Test;

/**
* Integration test of {@link GraalVm}.
*/
public class GraalVmTest extends AbstractIdeContextTest {

private static final String PROJECT_GRAALVM = "graalvm";

@Test
public void testGraalVmInstallInDirectoryExtra() {

// arrange
IdeTestContext context = newContext(PROJECT_GRAALVM);

GraalVm commandlet = new GraalVm(context);

// act
commandlet.install();

// assert
assertThat(context.getSoftwareExtraPath().resolve("graalvm/bin/HelloWorld.txt")).exists();
assertThat(context.getSoftwareExtraPath().resolve("graalvm/.ide.software.version")).exists().hasContent("22.3.3");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# here the GRAALVM_HOME variable should be added by the test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GRAALVM_VERSION=22.3.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the workspace of graalvm test case
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!

0 comments on commit d2bfec2

Please sign in to comment.