You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vk...@apache.org on 2020/12/29 00:22:48 UTC

[ignite-3] branch main updated: IGNITE-13921 - Use CLI tool location folder for ignite-bin and ignite-work

This is an automated email from the ASF dual-hosted git repository.

vkulichenko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 7f3ae46  IGNITE-13921 - Use CLI tool location folder for ignite-bin and ignite-work
7f3ae46 is described below

commit 7f3ae46f608f3bbf6373b74ec0810b13e377c8ee
Author: Valentin Kulichenko <va...@gmail.com>
AuthorDate: Mon Dec 28 16:22:04 2020 -0800

    IGNITE-13921 - Use CLI tool location folder for ignite-bin and ignite-work
---
 .../ignite/cli/builtins/SystemPathResolver.java      | 20 +++++++++++++++++++-
 .../ignite/cli/builtins/init/InitIgniteCommand.java  |  7 +++++--
 .../cli/builtins/init/InitIgniteCommandTest.java     |  2 ++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/modules/cli/src/main/java/org/apache/ignite/cli/builtins/SystemPathResolver.java b/modules/cli/src/main/java/org/apache/ignite/cli/builtins/SystemPathResolver.java
index 28f085e..66e29f7 100644
--- a/modules/cli/src/main/java/org/apache/ignite/cli/builtins/SystemPathResolver.java
+++ b/modules/cli/src/main/java/org/apache/ignite/cli/builtins/SystemPathResolver.java
@@ -17,24 +17,42 @@
 
 package org.apache.ignite.cli.builtins;
 
+import java.io.File;
+import java.net.URISyntaxException;
 import java.nio.file.Path;
 import javax.inject.Singleton;
 import io.micronaut.core.annotation.Introspected;
+import org.apache.ignite.cli.IgniteCLIException;
+import org.apache.ignite.cli.IgniteCliApp;
 
 public interface SystemPathResolver {
 
     Path osHomeDirectoryPath();
 
+    Path toolHomeDirectoryPath();
+
     /**
      *
      */
     @Singleton
     @Introspected
     class DefaultPathResolver implements SystemPathResolver {
-
         @Override public Path osHomeDirectoryPath() {
             return Path.of(System.getProperty("user.home"));
         }
 
+        @Override public Path toolHomeDirectoryPath() {
+            try {
+                var file = new File(IgniteCliApp.class.getProtectionDomain().getCodeSource().getLocation().toURI());
+
+                while (!file.isDirectory())
+                    file = file.getParentFile();
+
+                return file.toPath();
+            }
+            catch (URISyntaxException e) {
+                throw new IgniteCLIException("Failed to resolve the CLI tool home directory.", e);
+            }
+        }
     }
 }
diff --git a/modules/cli/src/main/java/org/apache/ignite/cli/builtins/init/InitIgniteCommand.java b/modules/cli/src/main/java/org/apache/ignite/cli/builtins/init/InitIgniteCommand.java
index a88199a..1971742 100644
--- a/modules/cli/src/main/java/org/apache/ignite/cli/builtins/init/InitIgniteCommand.java
+++ b/modules/cli/src/main/java/org/apache/ignite/cli/builtins/init/InitIgniteCommand.java
@@ -105,9 +105,12 @@ public class InitIgniteCommand {
         File newCfgFile = newCfgPath.toFile();
         try {
             newCfgFile.createNewFile();
-            Path binDir = pathResolver.osHomeDirectoryPath().resolve("ignite").resolve("bin");
-            Path workDir = pathResolver.osHomeDirectoryPath().resolve("ignite").resolve("work");
+
+            Path binDir = pathResolver.toolHomeDirectoryPath().resolve("ignite-bin");
+            Path workDir = pathResolver.toolHomeDirectoryPath().resolve("ignite-work");
+
             fillNewConfigFile(newCfgFile, binDir, workDir);
+
             return newCfgFile;
         }
         catch (IOException e) {
diff --git a/modules/cli/src/test/java/org/apache/ignite/cli/builtins/init/InitIgniteCommandTest.java b/modules/cli/src/test/java/org/apache/ignite/cli/builtins/init/InitIgniteCommandTest.java
index ceddc40..37ac59c 100644
--- a/modules/cli/src/test/java/org/apache/ignite/cli/builtins/init/InitIgniteCommandTest.java
+++ b/modules/cli/src/test/java/org/apache/ignite/cli/builtins/init/InitIgniteCommandTest.java
@@ -59,6 +59,7 @@ public class InitIgniteCommandTest {
     @Test
     void init() throws IOException {
         when(pathResolver.osHomeDirectoryPath()).thenReturn(homeDir);
+        when(pathResolver.toolHomeDirectoryPath()).thenReturn(currentDir);
 
         when(mavenArtifactResolver.resolve(any(), any(), any(), any(), any()))
             .thenReturn(new ResolveResult(Arrays.asList()));
@@ -73,6 +74,7 @@ public class InitIgniteCommandTest {
     @Test
     void reinit() throws IOException {
         when(pathResolver.osHomeDirectoryPath()).thenReturn(homeDir);
+        when(pathResolver.toolHomeDirectoryPath()).thenReturn(currentDir);
 
         when(mavenArtifactResolver.resolve(any(), any(), any(), any(), any()))
             .thenReturn(new ResolveResult(Collections.emptyList()));