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: extract node install mojo
- Loading branch information
Showing
8 changed files
with
84 additions
and
114 deletions.
There are no files selected for viewing
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
68 changes: 68 additions & 0 deletions
68
...rc/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AbstractInstallNodeMojo.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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.github.eirslett.maven.plugins.frontend.mojo; | ||
|
||
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory; | ||
import com.github.eirslett.maven.plugins.frontend.lib.NodeVersionDetector; | ||
import com.github.eirslett.maven.plugins.frontend.lib.NodeVersionHelper; | ||
import org.apache.maven.lifecycle.LifecycleExecutionException; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static com.github.eirslett.maven.plugins.frontend.lib.NodeVersionHelper.getDownloadableVersion; | ||
import static java.util.Objects.isNull; | ||
|
||
public abstract class AbstractInstallNodeMojo extends AbstractFrontendMojo { | ||
|
||
protected static final Logger logger = LoggerFactory.getLogger(AbstractInstallNodeMojo.class); | ||
|
||
/** | ||
* Where to download Node.js binary from. Defaults to https://nodejs.org/dist/ | ||
*/ | ||
@Parameter(property = "nodeDownloadRoot", required = false) | ||
protected String nodeDownloadRoot; | ||
|
||
/** | ||
* The version of Node.js to install. IMPORTANT! Most Node.js version names start with 'v', for example 'v0.10.18' | ||
* If using with node version manager (enabled by default), nodeVersion parameter will be ignored | ||
*/ | ||
@Parameter(property = "nodeVersion", defaultValue = "", required = false) | ||
protected String nodeVersion; | ||
|
||
/** | ||
* The path to the file that contains the Node version to use | ||
*/ | ||
@Parameter(property = "nodeVersionFile", defaultValue = "", required = false) | ||
protected String nodeVersionFile; | ||
|
||
@Override | ||
protected void execute(FrontendPluginFactory factory) throws Exception { | ||
verifyAndResolveNodeVersion(factory); | ||
executeWithVerifiedNodeVersion(factory); | ||
} | ||
|
||
protected abstract void executeWithVerifiedNodeVersion(FrontendPluginFactory factory) throws Exception; | ||
|
||
private void verifyAndResolveNodeVersion(FrontendPluginFactory factory) throws Exception { | ||
if (factory.isVersionManagerAvailable()) { | ||
if (this.nodeVersion != null && !this.nodeVersion.isEmpty()) { | ||
logger.warn("`nodeVersion` has been configured to {} but will be ignored when installing with node version manager." + | ||
" Version Manager will load the version from their version file (e.g. .nvmrc, .tool-versions)", this.nodeVersion); | ||
} | ||
} | ||
|
||
String nodeVersion = NodeVersionDetector.getNodeVersion(this.workingDirectory, this.nodeVersion, this.nodeVersionFile); | ||
|
||
if (isNull(nodeVersion)) { | ||
throw new LifecycleExecutionException("Node version could not be detected from a file and was not set"); | ||
} | ||
|
||
if (!NodeVersionHelper.validateVersion(nodeVersion)) { | ||
throw new LifecycleExecutionException("Node version (" + nodeVersion + ") is not valid. If you think it actually is, raise an issue"); | ||
} | ||
|
||
String validNodeVersion = getDownloadableVersion(nodeVersion); | ||
logger.info("Resolved Node version: {}", validNodeVersion); | ||
|
||
this.nodeVersion = validNodeVersion; | ||
} | ||
} |
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
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
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