forked from eirslett/frontend-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DCA11Y-1145: refactor: use shell only if node version manager require…
…s shell
- Loading branch information
Showing
9 changed files
with
329 additions
and
173 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
frontend-maven-plugin/src/it/node-version-manager/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# ignoring windows for now | ||
invoker.os.family=!windows,unix,mac | ||
invoker.environmentVariables.SHELL=bash | ||
invoker.environmentVariables.SHELL=bash | ||
invoker.environmentVariables.FNM_DIR=$HOME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 60 additions & 19 deletions
79
...ava/com/github/eirslett/maven/plugins/frontend/lib/version/manager/client/AsdfClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,94 @@ | ||
package com.github.eirslett.maven.plugins.frontend.lib.version.manager.client; | ||
|
||
import com.github.eirslett.maven.plugins.frontend.lib.version.manager.ShellExecutor; | ||
import com.github.eirslett.maven.plugins.frontend.lib.version.manager.CommandExecutor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
|
||
public class AsdfClient implements VersionManagerClient { | ||
final Logger logger = LoggerFactory.getLogger(getClass()); | ||
final ShellExecutor shellExecutor; | ||
final CommandExecutor commandExecutor; | ||
|
||
private static final String EXECUTABLE = "asdf"; | ||
|
||
public AsdfClient(ShellExecutor shellExecutor) { | ||
this.shellExecutor = shellExecutor; | ||
public AsdfClient(CommandExecutor commandExecutor) { | ||
this.commandExecutor = commandExecutor; | ||
} | ||
|
||
@Override | ||
public boolean isInstalled() { | ||
String version = shellExecutor.executeAndCatchErrors(Arrays.asList( | ||
EXECUTABLE, "--version" | ||
)); | ||
|
||
return version.matches("v\\d+\\.\\d+\\.\\d+-[0-9a-z]+"); | ||
String asdfDir = getAsdfDir(); | ||
logger.debug("Checking if ASDF installation directory exists: {}", asdfDir); | ||
return asdfDir != null; | ||
} | ||
|
||
@Override | ||
public void installNode() { | ||
|
||
shellExecutor.executeOrFail(Arrays.asList( | ||
EXECUTABLE, "plugin", "add", "nodejs" | ||
)); | ||
shellExecutor.executeOrFail(Arrays.asList( | ||
EXECUTABLE, "install", "nodejs" | ||
)); | ||
commandExecutor | ||
.withShell() | ||
.withSourced(getAsdfScript()) | ||
.executeOrFail(Arrays.asList( | ||
EXECUTABLE, "plugin", "add", "nodejs" | ||
)); | ||
commandExecutor | ||
.withShell() | ||
.withSourced(getAsdfScript()) | ||
.executeOrFail(Arrays.asList( | ||
EXECUTABLE, "install", "nodejs" | ||
)); | ||
} | ||
|
||
@Override | ||
public File getNodeExecutable() { | ||
return new File(shellExecutor.executeOrFail(Arrays.asList( | ||
EXECUTABLE, "which", "node" | ||
))); | ||
String nodePath = commandExecutor | ||
.withShell() | ||
.withSourced(getAsdfScript()) | ||
.executeOrFail(Arrays.asList( | ||
EXECUTABLE, "which", "node" | ||
)); | ||
return new File(nodePath); | ||
} | ||
|
||
@Override | ||
public File getNpmExecutable() { | ||
File nodeExec = getNodeExecutable(); | ||
return Paths.get(nodeExec.getParent(), "npm").toFile(); | ||
} | ||
|
||
private String getAsdfScript() { | ||
String asdfDir = getAsdfDir(); | ||
String asdfScript = Paths.get(asdfDir, "asdf.sh").toString(); | ||
|
||
return asdfScript; | ||
} | ||
|
||
private String getAsdfDir() { | ||
String asdfDir = System.getenv("ASDF_DIR"); | ||
if (asdfDir != null) { | ||
Path path = Paths.get(asdfDir); | ||
if (Files.exists(path)) { | ||
return path.toString(); | ||
} | ||
} | ||
|
||
String home = System.getenv("HOME"); | ||
if (home != null) { | ||
Path path = Paths.get(home, ".asdf"); | ||
if (Files.exists(path)) { | ||
return path.toString(); | ||
} | ||
|
||
path = Paths.get(home, ".local", "share", "asdf"); | ||
if (Files.exists(path)) { | ||
return path.toString(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.