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

#20: Implement ToolCommandlet for GCViewer #151

Merged
merged 17 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -11,6 +11,7 @@
import com.devonfw.tools.ide.property.Property;
import com.devonfw.tools.ide.tool.az.Azure;
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.gradle.Gradle;
import com.devonfw.tools.ide.tool.helm.Helm;
Expand Down Expand Up @@ -64,6 +65,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Java(context));
add(new Node(context));
add(new Mvn(context));
add(new GcViewer(context));
add(new Gradle(context));
add(new Eclipse(context));
add(new Terraform(context));
Expand Down
12 changes: 11 additions & 1 deletion cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,17 @@ protected void extract(Path file, Path targetDir) {
fileAccess.delete(tmpDir);
} else {
this.context.trace("Extraction is disabled for '{}' hence just moving the downloaded file {}.", getName(), file);
fileAccess.move(file, targetDir);

if (Files.isDirectory(file)) {
fileAccess.move(file, targetDir);
} else {
try {
Files.createDirectories(targetDir);
} catch (IOException e) {
throw new IllegalStateException("Failed to create folder " + targetDir);
}
fileAccess.move(file, targetDir.resolve(file.getFileName()));
}
}
}

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

import java.util.Set;

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

/**
* {@link ToolCommandlet} for GcViewer.
*/
public class GcViewer extends LocalToolCommandlet {

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

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

@Override
protected boolean isExtract() {

return false;
}

@Override
public void run() {

install(true);
ProcessContext pc = this.context.newProcess();
pc.directory(getToolPath());
pc.executable("java");
pc.addArg("-jar");
pc.addArg("gcviewer-" + getInstalledVersion() + ".jar");
pc.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public static String getExtension(String path) {
lastSlash = 0;
}
int lastDot = path.lastIndexOf('.');

// workaround for sourceforge urls ending with /download like
// https://sourceforge.net/projects/gcviewer/files/gcviewer-1.36.jar/download
if (path.startsWith("https://") && path.contains("sourceforge") && path.endsWith("download")) {
return path.substring(lastDot + 1, lastSlash);
}

if (lastDot < lastSlash) {
return null;
}
Expand Down
Loading