-
Notifications
You must be signed in to change notification settings - Fork 877
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial bun integration * fixing integration tests * fixing integration tests * fixing integration tests * adding invoker properties * bun install * fix log output * update bun integration test to version 1.0.10
- Loading branch information
Showing
16 changed files
with
686 additions
and
0 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
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 @@ | ||
node_modules |
1 change: 1 addition & 0 deletions
1
frontend-maven-plugin/src/it/bun-integration/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 |
---|---|---|
@@ -0,0 +1 @@ | ||
invoker.os.family = !windows, unix, mac |
13 changes: 13 additions & 0 deletions
13
frontend-maven-plugin/src/it/bun-integration/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 @@ | ||
{ | ||
"name": "example", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"classnames": "^2.3.2" | ||
}, | ||
"scripts": { | ||
"prebuild": "npm install" | ||
} | ||
} |
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,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.github.eirslett</groupId> | ||
<artifactId>example</artifactId> | ||
<version>0</version> | ||
<packaging>pom</packaging> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.eirslett</groupId> | ||
<artifactId>frontend-maven-plugin</artifactId> | ||
<!-- NB! Set <version> to the latest released version of frontend-maven-plugin, like in README.md --> | ||
<version>@project.version@</version> | ||
|
||
<configuration> | ||
<installDirectory>target</installDirectory> | ||
</configuration> | ||
|
||
<executions> | ||
|
||
<execution> | ||
<id>install bun runtime</id> | ||
<goals> | ||
<goal>install-bun</goal> | ||
</goals> | ||
<configuration> | ||
<bunVersion>v1.0.10</bunVersion> | ||
</configuration> | ||
</execution> | ||
|
||
<execution> | ||
<id>bun install</id> | ||
<goals> | ||
<goal>bun</goal> | ||
</goals> | ||
<!-- Optional configuration which provides for running any npm command --> | ||
<configuration> | ||
<arguments>install</arguments> | ||
</configuration> | ||
</execution> | ||
|
||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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,7 @@ | ||
assert new File(basedir, 'target/bun').exists(): "Bun was not installed in the custom install directory"; | ||
|
||
import org.codehaus.plexus.util.FileUtils; | ||
|
||
String buildLog = FileUtils.fileRead(new File(basedir, 'build.log')); | ||
|
||
assert buildLog.contains('BUILD SUCCESS'): 'build was not successful' |
84 changes: 84 additions & 0 deletions
84
...d-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/BunMojo.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,84 @@ | ||
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.ProxyConfig; | ||
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException; | ||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.settings.crypto.SettingsDecrypter; | ||
import org.sonatype.plexus.build.incremental.BuildContext; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
|
||
@Mojo(name = "bun", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true) | ||
public final class BunMojo extends AbstractFrontendMojo { | ||
|
||
private static final String NPM_REGISTRY_URL = "npmRegistryURL"; | ||
|
||
/** | ||
* bun arguments. Default is "install". | ||
*/ | ||
@Parameter(defaultValue = "", property = "frontend.bun.arguments", required = false) | ||
private String arguments; | ||
|
||
@Parameter(property = "frontend.bun.bunInheritsProxyConfigFromMaven", required = false, | ||
defaultValue = "true") | ||
private boolean bunInheritsProxyConfigFromMaven; | ||
|
||
/** | ||
* Registry override, passed as the registry option during npm install if set. | ||
*/ | ||
@Parameter(property = NPM_REGISTRY_URL, required = false, defaultValue = "") | ||
private String npmRegistryURL; | ||
|
||
@Parameter(property = "session", defaultValue = "${session}", readonly = true) | ||
private MavenSession session; | ||
|
||
@Component | ||
private BuildContext buildContext; | ||
|
||
@Component(role = SettingsDecrypter.class) | ||
private SettingsDecrypter decrypter; | ||
|
||
/** | ||
* Skips execution of this mojo. | ||
*/ | ||
@Parameter(property = "skip.bun", defaultValue = "${skip.bun}") | ||
private boolean skip; | ||
|
||
@Override | ||
protected boolean skipExecution() { | ||
return this.skip; | ||
} | ||
|
||
@Override | ||
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException { | ||
File packageJson = new File(this.workingDirectory, "package.json"); | ||
if (this.buildContext == null || this.buildContext.hasDelta(packageJson) | ||
|| !this.buildContext.isIncremental()) { | ||
ProxyConfig proxyConfig = getProxyConfig(); | ||
factory.getBunRunner(proxyConfig, getRegistryUrl()).execute(this.arguments, | ||
this.environmentVariables); | ||
} else { | ||
getLog().info("Skipping bun install as package.json unchanged"); | ||
} | ||
} | ||
|
||
private ProxyConfig getProxyConfig() { | ||
if (this.bunInheritsProxyConfigFromMaven) { | ||
return MojoUtils.getProxyConfig(this.session, this.decrypter); | ||
} else { | ||
getLog().info("bun not inheriting proxy config from Maven"); | ||
return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList()); | ||
} | ||
} | ||
|
||
private String getRegistryUrl() { | ||
// check to see if overridden via `-D`, otherwise fallback to pom value | ||
return System.getProperty(NPM_REGISTRY_URL, this.npmRegistryURL); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallBunMojo.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,59 @@ | ||
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.InstallationException; | ||
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig; | ||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.settings.Server; | ||
import org.apache.maven.settings.crypto.SettingsDecrypter; | ||
|
||
@Mojo(name = "install-bun", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true) | ||
public final class InstallBunMojo extends AbstractFrontendMojo { | ||
|
||
/** | ||
* The version of Bun to install. IMPORTANT! Most Bun version names start with 'v', for example | ||
* 'v1.0.0' | ||
*/ | ||
@Parameter(property = "bunVersion", required = true) | ||
private String bunVersion; | ||
|
||
/** | ||
* Server Id for download username and password | ||
*/ | ||
@Parameter(property = "serverId", defaultValue = "") | ||
private String serverId; | ||
|
||
@Parameter(property = "session", defaultValue = "${session}", readonly = true) | ||
private MavenSession session; | ||
|
||
/** | ||
* Skips execution of this mojo. | ||
*/ | ||
@Parameter(property = "skip.installbun", alias = "skip.installbun", defaultValue = "${skip.installbun}") | ||
private boolean skip; | ||
|
||
@Component(role = SettingsDecrypter.class) | ||
private SettingsDecrypter decrypter; | ||
|
||
@Override | ||
protected boolean skipExecution() { | ||
return this.skip; | ||
} | ||
|
||
@Override | ||
public void execute(FrontendPluginFactory factory) throws InstallationException { | ||
ProxyConfig proxyConfig = MojoUtils.getProxyConfig(this.session, this.decrypter); | ||
Server server = MojoUtils.decryptServer(this.serverId, this.session, this.decrypter); | ||
if (null != server) { | ||
factory.getBunInstaller(proxyConfig).setBunVersion(this.bunVersion).setUserName(server.getUsername()) | ||
.setPassword(server.getPassword()).install(); | ||
} else { | ||
factory.getBunInstaller(proxyConfig).setBunVersion(this.bunVersion).install(); | ||
} | ||
} | ||
|
||
} |
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
31 changes: 31 additions & 0 deletions
31
...plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/BunExecutor.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,31 @@ | ||
package com.github.eirslett.maven.plugins.frontend.lib; | ||
|
||
import org.slf4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
final class BunExecutor { | ||
private final ProcessExecutor executor; | ||
|
||
public BunExecutor(BunExecutorConfig config, List<String> arguments, Map<String, String> additionalEnvironment) { | ||
final String bun = config.getBunPath().getAbsolutePath(); | ||
List<String> localPaths = new ArrayList<String>(); | ||
localPaths.add(config.getBunPath().getParent()); | ||
this.executor = new ProcessExecutor( | ||
config.getWorkingDirectory(), | ||
localPaths, | ||
Utils.prepend(bun, arguments), | ||
config.getPlatform(), | ||
additionalEnvironment); | ||
} | ||
|
||
public String executeAndGetResult(final Logger logger) throws ProcessExecutionException { | ||
return executor.executeAndGetResult(logger); | ||
} | ||
|
||
public int executeAndRedirectOutput(final Logger logger) throws ProcessExecutionException { | ||
return executor.executeAndRedirectOutput(logger); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/BunExecutorConfig.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,46 @@ | ||
package com.github.eirslett.maven.plugins.frontend.lib; | ||
|
||
import java.io.File; | ||
|
||
public interface BunExecutorConfig { | ||
|
||
File getNodePath(); | ||
|
||
File getBunPath(); | ||
|
||
File getWorkingDirectory(); | ||
|
||
Platform getPlatform(); | ||
} | ||
|
||
final class InstallBunExecutorConfig implements BunExecutorConfig { | ||
|
||
private File nodePath; | ||
|
||
private final InstallConfig installConfig; | ||
|
||
public InstallBunExecutorConfig(InstallConfig installConfig) { | ||
this.installConfig = installConfig; | ||
nodePath = new InstallNodeExecutorConfig(installConfig).getNodePath(); | ||
} | ||
|
||
@Override | ||
public File getNodePath() { | ||
return nodePath; | ||
} | ||
|
||
@Override | ||
public File getBunPath() { | ||
return new File(installConfig.getInstallDirectory() + BunInstaller.INSTALL_PATH); | ||
} | ||
|
||
@Override | ||
public File getWorkingDirectory() { | ||
return installConfig.getWorkingDirectory(); | ||
} | ||
|
||
@Override | ||
public Platform getPlatform() { | ||
return installConfig.getPlatform(); | ||
} | ||
} |
Oops, something went wrong.