Skip to content

Commit e583ae0

Browse files
committed
fix some issues with installing external software (hopefully for real this time...)
1 parent 25c69b7 commit e583ae0

File tree

66 files changed

+892
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+892
-141
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/dtsx/astra/cli/commands/db/cqlsh/CqlshPathCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public <T> T throwNoInstallationFound() {
6969
Please install @!cqlsh!@ by running any cqlsh command through @!${cli.name}!@.
7070
7171
@|faint,italic Note that the CLI does not recognize cqlsh installations done outside of astra.|@
72-
""".formatted(ctx.home().getDir()), List.of(
72+
""".formatted(ctx.home().root()), List.of(
7373
new Hint("Example command to install cqlsh (no --if-exists flag):", "${cli.name} db cqlsh path")
7474
));
7575
}

src/main/java/com/dtsx/astra/cli/commands/db/dsbulk/DbDsbulkPathCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public <T> T throwNoInstallationFound() {
6969
Please install @!dsbulk!@ by running any dsbulk command through @!${cli.name}!@.
7070
7171
@|faint,italic Note that the CLI does not recognize dsbulk installations done outside of astra.|@
72-
""".formatted(ctx.home().getDir()), List.of(
72+
""".formatted(ctx.home().root()), List.of(
7373
new Hint("Example command to install dsbulk (no --if-exists flag):", "${cli.name} db dsbulk path")
7474
));
7575
}

src/main/java/com/dtsx/astra/cli/commands/streaming/pulsar/StreamingPulsarPathCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public <T> T throwNoInstallationFound() {
7070
Please install @!pulsar!@ by running any pulsar command through @!${cli.name}!@.
7171
7272
@|faint,italic Note that the CLI does not recognize pulsar installations done outside of astra.|@
73-
""".formatted(ctx.home().getDir()), List.of(
73+
""".formatted(ctx.home().root()), List.of(
7474
new Hint("Example command to install pulsar:", "${cli.name} streaming pulsar version")
7575
));
7676
}

src/main/java/com/dtsx/astra/cli/core/completions/CompletionsCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public final void removeFromCache(String completion) {
103103
}
104104

105105
protected static Path defaultCacheDir(CliContext ctx) {
106-
return ctx.home().dirs().useCompletionsCache();
106+
return ctx.home().dirs.completionsCache.use();
107107
}
108108

109109
@SneakyThrows

src/main/java/com/dtsx/astra/cli/core/config/AstraHome.java

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,81 @@
22

33
import com.dtsx.astra.cli.core.CliContext;
44
import com.dtsx.astra.cli.core.datatypes.Thunk;
5-
import com.dtsx.astra.cli.core.models.Version;
65
import com.dtsx.astra.cli.utils.FileUtils;
7-
import lombok.val;
86

97
import java.nio.file.Files;
108
import java.nio.file.Path;
9+
import java.util.Optional;
1110
import java.util.function.Supplier;
1211

1312
public class AstraHome {
1413
private final Supplier<CliContext> ctxSupplier;
15-
private final Thunk<Path> dir;
16-
private final Thunk<Dirs> dirs;
14+
private Thunk<Path> dir;
1715

1816
public AstraHome(Supplier<CliContext> ctxSupplier) {
1917
this.ctxSupplier = ctxSupplier;
2018

2119
this.dir = new Thunk<>(() -> (
2220
ctx().path(ctx().properties().homeFolderLocations(ctx().isWindows()).preferred())
2321
));
24-
25-
this.dirs = new Thunk<>(Dirs::new);
2622
}
2723

28-
public String getDir() {
29-
return dir.toString();
24+
public String root() {
25+
return dir.get().toString();
3026
}
3127

32-
public Path useDir() {
33-
FileUtils.createDirIfNotExists(dir.get(), null);
34-
return dir.get();
35-
}
28+
public final UsablePath updateNotifierProperties = new Thunk<>(() -> {
29+
Path path = dir.get().resolve("upgrade-notifier.properties");
30+
FileUtils.createFileIfNotExists(path, null);
31+
return path;
32+
})::get;
3633

37-
public Dirs dirs() {
38-
return dirs.get();
39-
}
34+
public final AstraSubfolders dirs = new AstraSubfolders();
4035

41-
public class Dirs {
42-
private final Path SCB = dir.get().resolve("scb");
43-
private final Path COMPLETIONS_CACHE = dir.get().resolve("completions-cache");
44-
private final Path LOGS = dir.get().resolve("logs");
45-
private final Path CQLSH = dir.get().resolve("cqlsh-astra");
36+
public class AstraSubfolders {
37+
public final AstraSubfolder scb = new AstraSubfolder("scb");
38+
public final AstraSubfolder completionsCache = new AstraSubfolder("completions-cache");
39+
public final AstraSubfolder logs = new AstraSubfolder("logs");
4640

47-
public Path useScb() {
48-
FileUtils.createDirIfNotExists(SCB, null);
49-
return SCB;
41+
public AstraSubfolder cqlsh(String version) {
42+
return new AstraSubfolder("cqlsh-astra@v1", version);
5043
}
5144

52-
public Path useCompletionsCache() {
53-
FileUtils.createDirIfNotExists(COMPLETIONS_CACHE, null);
54-
return COMPLETIONS_CACHE;
45+
public AstraSubfolder dsbulk(String version) {
46+
return new AstraSubfolder("dsbulk@v1", version);
5547
}
5648

57-
public Path useLogs() {
58-
FileUtils.createDirIfNotExists(LOGS, null);
59-
return LOGS;
49+
public AstraSubfolder pulsar(String version) {
50+
return new AstraSubfolder("pulsar-shell@v1", version);
6051
}
52+
}
6153

62-
public Path useCqlsh(Version version) {
63-
val path = dir.get().resolve("cqlsh-astra").resolve(version.toString());
64-
FileUtils.createDirIfNotExists(path, null);
65-
return CQLSH;
66-
}
54+
public interface UsablePath {
55+
Path use();
56+
}
6757

68-
public Path useDsbulk(Version version) {
69-
val path = dir.get().resolve("dsbulk").resolve(version.toString());
70-
FileUtils.createDirIfNotExists(path, null);
71-
return path;
72-
}
58+
public class AstraSubfolder implements UsablePath {
59+
private final Supplier<Path> folder;
7360

74-
public Path usePulsar(Version version) {
75-
val path = dir.get().resolve("lunastreaming-shell").resolve(version.toString());
76-
FileUtils.createDirIfNotExists(path, null);
77-
return path;
61+
public AstraSubfolder(String... subfolder) {
62+
this.folder = new Thunk<>(() -> dir.get().resolve(ctx().fs().getPath("", subfolder)));
7863
}
7964

80-
public boolean cqlshExists(Version version) {
81-
val path = dir.get().resolve("cqlsh-astra").resolve(version.toString());
82-
return Files.exists(path);
65+
public boolean exists() {
66+
return Files.exists(folder.get());
8367
}
8468

85-
public boolean dsbulkExists(Version version) {
86-
val path = dir.get().resolve("dsbulk").resolve(version.toString());
87-
return Files.exists(path);
69+
public Optional<Path> useIfExists() {
70+
if (exists()) {
71+
return Optional.of(use());
72+
}
73+
return Optional.empty();
8874
}
8975

90-
public boolean pulsarExists(Version version) {
91-
val path = dir.get().resolve("lunastreaming-shell").resolve(version.toString());
92-
return Files.exists(path);
76+
@Override
77+
public Path use() {
78+
FileUtils.createDirIfNotExists(folder.get(), null);
79+
return folder.get();
9380
}
9481
}
9582

src/main/java/com/dtsx/astra/cli/core/models/Version.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.dtsx.astra.cli.core.CliContext;
44
import com.dtsx.astra.cli.core.datatypes.Either;
5+
import com.dtsx.astra.cli.core.exceptions.internal.cli.CongratsYouFoundABugException;
56
import com.dtsx.astra.cli.core.output.Highlightable;
67
import lombok.*;
78
import lombok.experimental.Accessors;
@@ -45,7 +46,7 @@ public static Either<String, Version> parse(String version) {
4546
}
4647

4748
public static Version mkUnsafe(String version) {
48-
return parse(version).getRight();
49+
return parse(version).getRight((_) -> new CongratsYouFoundABugException("Invalid version: " + version));
4950
}
5051

5152
public boolean isPreRelease() {

src/main/java/com/dtsx/astra/cli/core/output/AstraLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public AstraLogger(Level level, Supplier<CliContext> ctxSupplier, boolean should
6161
this.sessionLogFile = () -> {
6262
if (cachedLogFile.ref == null) {
6363
val timestamp = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss").format(Instant.now().atZone(ZoneId.systemDefault()));
64-
cachedLogFile.ref = ctx().home().dirs().useLogs().resolve(timestamp + ".astra.log");
64+
cachedLogFile.ref = ctx().home().dirs.logs.use().resolve(timestamp + ".astra.log");
6565
}
6666
return cachedLogFile.ref;
6767
};
@@ -191,7 +191,7 @@ public void dumpLogsToFile() {
191191
}
192192
logsDumped = true;
193193

194-
deleteOldLogs(ctx().home().dirs().useLogs());
194+
deleteOldLogs(ctx().home().dirs.logs.use());
195195

196196
try (var writer = Files.newBufferedWriter(sessionLogFile.get())) {
197197
for (val line : accumulated) {

src/main/java/com/dtsx/astra/cli/core/properties/CliProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ConstEnvVars {
2323

2424
record ExternalSoftware(
2525
String url,
26-
Version version
26+
String version // can't use Version here unfortunately b/c pulsar-shell doesn't use semver ._.
2727
) {}
2828

2929
enum PathLocationResolver { CUSTOM, XDG, HOME }

src/main/java/com/dtsx/astra/cli/core/properties/CliPropertiesImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ public static CliProperties mkAndLoadSysProps(CliEnvironment env, Function<CliPr
5555

5656
@Override
5757
public ExternalSoftware cqlsh() {
58-
return new ExternalSoftware(requireProperty("cqlsh.url"), Version.mkUnsafe(requireProperty("cqlsh.version")));
58+
return new ExternalSoftware(requireProperty("cqlsh.url"), requireProperty("cqlsh.version"));
5959
}
6060

6161
@Override
6262
public ExternalSoftware dsbulk() {
63-
return new ExternalSoftware(requireProperty("dsbulk.url"), Version.mkUnsafe(requireProperty("dsbulk.version")));
63+
return new ExternalSoftware(requireProperty("dsbulk.url"), requireProperty("dsbulk.version"));
6464
}
6565

6666
@Override
6767
public ExternalSoftware pulsar() {
68-
return new ExternalSoftware(requireProperty("pulsar-shell.url"), Version.mkUnsafe(requireProperty("pulsar-shell.version")));
68+
return new ExternalSoftware(requireProperty("pulsar-shell.url"), requireProperty("pulsar-shell.version"));
6969
}
7070

7171
@Override

0 commit comments

Comments
 (0)