Skip to content

Commit 830c11f

Browse files
authored
#20: Implement ToolCommandlet for GCViewer (#151)
1 parent ae37714 commit 830c11f

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.devonfw.tools.ide.property.Property;
1212
import com.devonfw.tools.ide.tool.az.Azure;
1313
import com.devonfw.tools.ide.tool.eclipse.Eclipse;
14+
import com.devonfw.tools.ide.tool.gcviewer.GcViewer;
1415
import com.devonfw.tools.ide.tool.gh.Gh;
1516
import com.devonfw.tools.ide.tool.gradle.Gradle;
1617
import com.devonfw.tools.ide.tool.helm.Helm;
@@ -64,6 +65,7 @@ public CommandletManagerImpl(IdeContext context) {
6465
add(new Java(context));
6566
add(new Node(context));
6667
add(new Mvn(context));
68+
add(new GcViewer(context));
6769
add(new Gradle(context));
6870
add(new Eclipse(context));
6971
add(new Terraform(context));

cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,17 @@ protected void extract(Path file, Path targetDir) {
271271
fileAccess.delete(tmpDir);
272272
} else {
273273
this.context.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", getName(), file);
274-
fileAccess.move(file, targetDir);
274+
275+
if (Files.isDirectory(file)) {
276+
fileAccess.move(file, targetDir);
277+
} else {
278+
try {
279+
Files.createDirectories(targetDir);
280+
} catch (IOException e) {
281+
throw new IllegalStateException("Failed to create folder " + targetDir);
282+
}
283+
fileAccess.move(file, targetDir.resolve(file.getFileName()));
284+
}
275285
}
276286
}
277287

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.devonfw.tools.ide.tool.gcviewer;
2+
3+
import java.util.Set;
4+
5+
import com.devonfw.tools.ide.common.Tag;
6+
import com.devonfw.tools.ide.context.IdeContext;
7+
import com.devonfw.tools.ide.process.ProcessContext;
8+
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
9+
import com.devonfw.tools.ide.tool.ToolCommandlet;
10+
11+
/**
12+
* {@link ToolCommandlet} for GcViewer.
13+
*/
14+
public class GcViewer extends LocalToolCommandlet {
15+
16+
/**
17+
* The constructor.
18+
*
19+
* @param context the {@link IdeContext}.
20+
*/
21+
public GcViewer(IdeContext context) {
22+
23+
super(context, "gcviewer", Set.of(Tag.JAVA));
24+
}
25+
26+
@Override
27+
protected boolean isExtract() {
28+
29+
return false;
30+
}
31+
32+
@Override
33+
public void run() {
34+
35+
install(true);
36+
ProcessContext pc = this.context.newProcess();
37+
pc.directory(getToolPath());
38+
pc.executable("java");
39+
pc.addArg("-jar");
40+
pc.addArg("gcviewer-" + getInstalledVersion() + ".jar");
41+
pc.run();
42+
}
43+
}

cli/src/main/java/com/devonfw/tools/ide/util/FilenameUtil.java

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public static String getExtension(String path) {
2828
lastSlash = 0;
2929
}
3030
int lastDot = path.lastIndexOf('.');
31+
32+
// workaround for sourceforge urls ending with /download like
33+
// https://sourceforge.net/projects/gcviewer/files/gcviewer-1.36.jar/download
34+
if (path.startsWith("https://") && path.contains("sourceforge") && path.endsWith("download")) {
35+
return path.substring(lastDot + 1, lastSlash);
36+
}
37+
3138
if (lastDot < lastSlash) {
3239
return null;
3340
}

0 commit comments

Comments
 (0)