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

#25: implement tool commandlet for intellij #297

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
13a2b75
#25: implemented install and plugins
ndemirca Feb 23, 2024
b8292b6
Merge branch 'main' into feature/25-Implement-ToolCommandlet-for-Inte…
ndemirca Mar 7, 2024
bcf0e4b
added first windows unittests for intellij
ndemirca Mar 8, 2024
1194c04
tested intellij installation
ndemirca Mar 8, 2024
2213057
adapted test data for intellij commandlet
ndemirca Mar 13, 2024
4329115
Adapted intellij tests
ndemirca Mar 13, 2024
b1f7e9c
Merge branch 'main' into feature/25-Implement-ToolCommandlet-for-Inte…
ndemirca Apr 17, 2024
a1ae18a
adjusted test data
ndemirca Apr 17, 2024
3402cc7
changed test data for mac
ndemirca Apr 17, 2024
2d39454
fixed intellij Unittests
ndemirca Apr 17, 2024
0bd0b42
expanden intellij tool commandlet
ndemirca Apr 17, 2024
1599acb
added javadoc
ndemirca Apr 18, 2024
2dbd602
Merge branch 'main' into feature/25-Implement-ToolCommandlet-for-Inte…
ndemirca Apr 23, 2024
c4ae3cf
added improvements to intellij and optimized tests
ndemirca Apr 23, 2024
e26ce93
cleaned up test data
ndemirca Apr 23, 2024
7b63574
imroved tests
ndemirca Apr 23, 2024
93265c9
fixed mac implementation
ndemirca Apr 24, 2024
dd5b979
added file mode to extractDmg to fix a bug
ndemirca Apr 24, 2024
ab2bedd
improved mac implementation
ndemirca Apr 24, 2024
5f5b2a9
refactoring
ndemirca Apr 24, 2024
a87dde9
adapted tests
ndemirca Apr 24, 2024
ca10f69
fixed unittests for mac
ndemirca Apr 25, 2024
6e46659
fixed unittest
ndemirca Apr 25, 2024
053faed
Merge branch 'main' into feature/25-Implement-ToolCommandlet-for-Inte…
ndemirca Apr 25, 2024
35012f0
small improvements
ndemirca Apr 25, 2024
b9af487
moved open into bin folder
ndemirca Apr 25, 2024
13c526f
Merge branch 'main' into feature/25-Implement-ToolCommandlet-for-Inte…
ndemirca Apr 29, 2024
c9af2b5
fix git merge conflict leftover
ndemirca Apr 29, 2024
7733bfc
Merge branch 'feature/25-Implement-ToolCommandlet-for-Intellij' of ht…
ndemirca Apr 29, 2024
4bbb95b
fixed gitattributes
ndemirca Apr 29, 2024
2c8820a
Merge branch 'main' into feature/25-Implement-ToolCommandlet-for-Inte…
ndemirca Apr 30, 2024
9ed18b4
added gitkeep into gitignore
ndemirca Apr 30, 2024
789f5c7
restover from uninstall commandlet
ndemirca Apr 30, 2024
5463998
refactoring
ndemirca Apr 30, 2024
a3cb929
added CR improvements
ndemirca Apr 30, 2024
1c25fb4
added improvements
ndemirca May 3, 2024
02ce32c
added line endings
ndemirca May 7, 2024
1589f88
Merge branch 'main' into feature/25-Implement-ToolCommandlet-for-Inte…
ndemirca May 7, 2024
9f5d2f7
fixed mac implementation
ndemirca May 7, 2024
1664414
fixed and cleaned up tests
ndemirca May 8, 2024
548357d
manipulated jmc test file
ndemirca May 8, 2024
35c7d63
reverted test step for jmc tests
ndemirca May 8, 2024
480a472
added node_modules into gittignore
ndemirca May 8, 2024
408b8e7
Merge branch 'main' into feature/25-Implement-ToolCommandlet-for-Inte…
ndemirca May 8, 2024
30e4048
Merge branch 'main' into feature/25-Implement-ToolCommandlet-for-Inte…
ndemirca May 17, 2024
20e8710
fixed copy bug in extractdmg
ndemirca May 23, 2024
a45b108
changed binarypath for mac
ndemirca May 27, 2024
bf7fa79
fixed copy method within extractdmg
ndemirca May 27, 2024
26e902f
adapted mac binary path
ndemirca May 27, 2024
3382e54
#347: fixed copy
jan-vcapgemini May 27, 2024
40eb875
Merge branch 'feature/347-Change-copy-method' into feature/25-Impleme…
ndemirca May 27, 2024
30062f3
fixed copy leftover and refactoring
ndemirca May 28, 2024
ad6f549
reverted refactoring
ndemirca May 28, 2024
63793c8
fixed mac tests
ndemirca May 28, 2024
9ca87e3
Merge branch 'main' into feature/25-Implement-ToolCommandlet-for-Inte…
hohwille Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
*.tgz binary
*.tar binary
*.bz2 binary
*.gz binary
*.gz binary

# special handling for test files
cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/windows/bin/studio64.exe text
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.devonfw.tools.ide.tool.gh.Gh;
import com.devonfw.tools.ide.tool.gradle.Gradle;
import com.devonfw.tools.ide.tool.helm.Helm;
import com.devonfw.tools.ide.tool.intellij.Intellij;
import com.devonfw.tools.ide.tool.jasypt.Jasypt;
import com.devonfw.tools.ide.tool.java.Java;
import com.devonfw.tools.ide.tool.jmc.Jmc;
Expand Down Expand Up @@ -92,6 +93,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Aws(context));
add(new Cobigen(context));
add(new Jmc(context));
add(new Intellij(context));
add(new Jasypt(context));
add(new Docker(context));
add(new Sonar(context));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
package com.devonfw.tools.ide.tool.intellij;

import java.util.Set;

import com.devonfw.tools.ide.cli.CliArgument;
import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
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.process.ProcessResult;
import com.devonfw.tools.ide.step.Step;
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
import com.devonfw.tools.ide.tool.ide.PluginDescriptor;
import com.devonfw.tools.ide.tool.java.Java;

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

/**
* {@link IdeToolCommandlet} for <a href="https://www.jetbrains.com/idea/">IntelliJ</a>.
*/
public class Intellij extends IdeToolCommandlet {

private static final String IDEA = "idea";

private static final String IDEA64_EXE = IDEA + "64.exe";

private static final String IDEA_BASH_SCRIPT = IDEA + ".sh";

/**
* The constructor.
*
Expand All @@ -23,6 +37,60 @@ public Intellij(IdeContext context) {
super(context, "intellij", Set.of(Tag.INTELLIJ));
}

@Override
protected void runIde(String... args) {
ndemirca marked this conversation as resolved.
Show resolved Hide resolved

install(true);

Step stepRun = this.context.newStep("Running IntelliJ");
try {
ProcessResult result;
if (this.context.getSystemInfo().isWindows()) {
result = runIntelliJ(ProcessMode.BACKGROUND, CliArgument.prepend(args, this.context.getWorkspacePath().toString()));
} else {
result = runIntelliJ(ProcessMode.BACKGROUND, CliArgument.prepend(args, "open", "-na", this.context.getWorkspacePath().toString()));
}
if (result.isSuccessful()) {
stepRun.success("Running IntelliJ successfully.");
} else {
stepRun.isFailure();
}
} catch (Exception e) {
stepRun.error(e, "Failed to run IntelliJ.");
} finally {
stepRun.end();
}
}

/**
* Runs IntelliJ application.
*
* @param processMode - the {@link ProcessMode}.
* @param args the individual arguments to pass to IntelliJ.
* @return the {@link ProcessResult}.
*/
protected ProcessResult runIntelliJ(ProcessMode processMode, String... args) {

Path toolPath;
if (this.context.getSystemInfo().isWindows()) {
toolPath = getToolBinPath().resolve(IDEA64_EXE);
} else {
toolPath = getToolBinPath().resolve(IDEA_BASH_SCRIPT);
if (!Files.exists(toolPath)) {
toolPath = getToolPath().resolve(IDEA_BASH_SCRIPT);
}
}

ProcessContext pc = this.context.newProcess();
if (processMode == ProcessMode.DEFAULT_CAPTURE) {
pc.errorHandling(ProcessErrorHandling.ERROR);
}
pc.executable(toolPath);
pc.addArgs(args);

return pc.run(processMode);
}

@Override
public boolean install(boolean silent) {

Expand All @@ -33,8 +101,5 @@ public boolean install(boolean silent) {
@Override
public void installPlugin(PluginDescriptor plugin) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not implemented so this PR does not entirely close #25. If you do something like this on purpose, then create a new issue for IntelliJ plugin support and leave a comment here like TODO https://github.com/devonfw/IDEasy/issues/«id». Otherwise we still end up in the same situation that we have currently that some comandlets seem to be present but are incomplete and if we have no issue about the problem, we might forget about it and currently merging this PR would automatically close #25.

// TODO Auto-generated method stub

}

}
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 @@ -17,6 +17,7 @@ cmd-gradle=Tool commandlet for Gradle (Build-Tool).
cmd-helm=Tool commandlet for Helm (Kubernetes Package Manager).
cmd-help=Prints this help.
cmd-install=Install the selected tool.
cmd-intellij=Tool commandlet for IntelliJ (IDE)
cmd-update=update settings, software and repositories.
cmd-java=Tool commandlet for Java (OpenJDK).
cmd-jmc=Tool commandlet for JDK Mission Control.
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 @@ -16,6 +16,7 @@ cmd-gradle=Werkzeug Kommando für Gradle (Build-Tool).
cmd-helm=Werkzeug Kommando für Helm (Kubernetes Package Manager).
cmd-help=Zeigt diese Hilfe an.
cmd-install=Installiert das selektierte Werkzeug.
cmd-intellij=Werkzeug Kommando für Intellij (IDE)
cmd-update=Updatet die Settings, Software und Repositories.
cmd-create=Erstellt ein neues IDEasy Projekt.
cmd-java=Werkzeug Kommando für Java (OpenJDK).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.devonfw.tools.ide.tool.intellij;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.os.SystemInfoMock;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Integration test of {@link Intellij}.
*/
public class IntellijTest extends AbstractIdeContextTest {

private static final String PROJECT_INTELLIJ = "intellij";

private final IdeTestContext context = newContext(PROJECT_INTELLIJ);

/**
* Tests if the {@link Intellij} can be installed properly.
*
* @param os String of the OS to use.
*/
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
public void testIntellijInstall(String os) {

// arrange
SystemInfo systemInfo = SystemInfoMock.of(os);
context.setSystemInfo(systemInfo);
Intellij commandlet = new Intellij(context);

// act
commandlet.install();

// assert
checkInstallation(context);

//if tool already installed
commandlet.install();
assertLogMessage(context, IdeLogLevel.DEBUG, "Version 2023.3.3 of tool intellij is already installed");
}

/**
* Tests if {@link Intellij IntelliJ IDE} can be run.
*
* @param os String of the OS to use.
*/
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
public void testIntellijRun(String os) {
// arrange
SystemInfo systemInfo = SystemInfoMock.of(os);
context.setSystemInfo(systemInfo);
Intellij commandlet = new Intellij(context);

// act
commandlet.run();

// assert
SystemInfo currentSystemInfo = context.getSystemInfo();
if (currentSystemInfo.isMac()) {
assertLogMessage(context, IdeLogLevel.INFO, "intellij mac open -na " + context.getWorkspacePath());
} else if (currentSystemInfo.isLinux()) {
assertLogMessage(context, IdeLogLevel.INFO, "intellij linux open -na " + context.getWorkspacePath());
} else if (currentSystemInfo.isWindows()) {
assertLogMessage(context, IdeLogLevel.INFO, "intellij windows " + context.getWorkspacePath());
}
assertLogMessage(context, IdeLogLevel.SUCCESS, "Running IntelliJ successfully.");
checkInstallation(context);
}

private void checkInstallation(IdeTestContext context) {

assertThat(context.getSoftwarePath().resolve("intellij/.ide.software.version")).exists().hasContent("2023.3.3");
assertLogMessage(context, IdeLogLevel.SUCCESS, "Successfully installed java in version 17.0.10_7");
assertLogMessage(context, IdeLogLevel.SUCCESS, "Successfully installed intellij in version 2023.3.3");
}
}
25 changes: 14 additions & 11 deletions cli/src/test/java/com/devonfw/tools/ide/tool/npm/NpmTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package com.devonfw.tools.ide.tool.npm;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.os.SystemInfoMock;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Integration test of {@link Npm}.
*/
public class NpmTest extends AbstractIdeContextTest {

private static final String PROJECT_NPM = "npm";

/**
* Tests if the {@link Npm} install works correctly across all three operating systems.
*
* @param os Operating system
*/
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
public void testNpmInstall(String os) {
Expand All @@ -33,14 +40,10 @@ public void testNpmInstall(String os) {
private void checkInstallation(IdeTestContext context) {

if (context.getSystemInfo().isWindows()) {
assertThat(context.getSoftwarePath().resolve("node/npm")).exists()
.hasContent("#!/bin/bash\n" + "echo \"npmbin $*\"");
assertThat(context.getSoftwarePath().resolve("node/npm.cmd")).exists()
.hasContent("@echo off\n" + "echo npmcmdbin %*");
assertThat(context.getSoftwarePath().resolve("node/npx")).exists()
.hasContent("#!/bin/bash\n" + "echo \"npxbin $*\"");
assertThat(context.getSoftwarePath().resolve("node/npx.cmd")).exists()
.hasContent("@echo off\n" + "echo npxcmdbin %*");
assertThat(context.getSoftwarePath().resolve("node/npm")).exists().hasContent("#!/bin/bash\n" + "echo \"npmbin $*\"");
assertThat(context.getSoftwarePath().resolve("node/npm.cmd")).exists().hasContent("@echo off\n" + "echo npmcmdbin %*");
assertThat(context.getSoftwarePath().resolve("node/npx")).exists().hasContent("#!/bin/bash\n" + "echo \"npxbin $*\"");
assertThat(context.getSoftwarePath().resolve("node/npx.cmd")).exists().hasContent("@echo off\n" + "echo npxcmdbin %*");
}

assertThat(context.getSoftwarePath().resolve("npm/.ide.software.version")).exists().hasContent("9.9.2");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JAVA_VERSION=17.0.10_7
INTELLIJ_VERSION=2023.3.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "intellij linux $*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "intellij mac $*"
ndemirca marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "intellij windows $*"