forked from jfrog/build-info
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 25 commits.
# This is the 1st commit message: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#2: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#3: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#4: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#5: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#6: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#7: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#8: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#9: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#10: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#11: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#12: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#13: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#14: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#15: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#16: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#17: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#18: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#19: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#20: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#21: HAP-1044 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#22: BI-465 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#23: BI-465 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#24: BI-465 - Support for NPM in the Jenkins Artifactory Plugin # This is the commit message jfrog#25: BI-465 - Support for NPM in the Jenkins Artifactory Plugin
- Loading branch information
yahavi
committed
Dec 27, 2018
1 parent
d8d13c8
commit 208d8ea
Showing
46 changed files
with
1,926 additions
and
152 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
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
2 changes: 1 addition & 1 deletion
2
...roducerConsumer/ProducerConsumerItem.java → ...roducerConsumer/ProducerConsumerItem.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
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
89 changes: 89 additions & 0 deletions
89
build-info-extractor-npm/src/main/java/org/jfrog/build/extractor/npm/NpmDriver.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,89 @@ | ||
package org.jfrog.build.extractor.npm; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectReader; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.jfrog.build.extractor.executor.CommandExecutor; | ||
import org.jfrog.build.extractor.executor.CommandResults; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* @author Yahav Itzhak | ||
*/ | ||
public class NpmDriver implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private static ObjectReader jsonReader = new ObjectMapper().reader(); | ||
private CommandExecutor commandExecutor; | ||
|
||
public NpmDriver(String executablePath) { | ||
this.commandExecutor = new CommandExecutor(StringUtils.defaultIfEmpty(executablePath, "npm")); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public boolean isNpmInstalled() { | ||
try { | ||
version(new File("")); | ||
return true; | ||
} catch (IOException | InterruptedException e) { | ||
return false; | ||
} | ||
} | ||
|
||
public void install(File workingDirectory, List<String> extraArgs) throws IOException { | ||
try { | ||
runCommand(workingDirectory, new String[]{"i"}, extraArgs); | ||
} catch (IOException | InterruptedException e) { | ||
throw new IOException("npm install failed: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
public void pack(File workingDirectory, List<String> extraArgs) throws IOException { | ||
try { | ||
runCommand(workingDirectory, new String[]{"pack"}, extraArgs); | ||
} catch (IOException | InterruptedException e) { | ||
throw new IOException("npm pack failed: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
public JsonNode list(File workingDirectory, List<String> extraArgs) throws IOException { | ||
List<String> args = new ArrayList<>(); | ||
args.add("ls"); | ||
args.add("--json"); | ||
args.addAll(extraArgs); | ||
try { | ||
CommandResults npmCommandRes = commandExecutor.exeCommand(workingDirectory, args); | ||
String res = StringUtils.isBlank(npmCommandRes.getRes()) ? "{}" : npmCommandRes.getRes(); | ||
return jsonReader.readTree(res); | ||
} catch (IOException | InterruptedException e) { | ||
throw new IOException("npm ls failed", e); | ||
} | ||
} | ||
|
||
public String version(File workingDirectory) throws IOException, InterruptedException { | ||
return runCommand(workingDirectory, new String[]{"--version"}, Collections.emptyList()); | ||
} | ||
|
||
public String configList(File workingDirectory, List<String> extraArgs) throws IOException, InterruptedException { | ||
return runCommand(workingDirectory, new String[]{"c", "ls", "--json"}, extraArgs); | ||
} | ||
|
||
private String runCommand(File workingDirectory, String[] args, List<String> extraArgs) throws IOException, InterruptedException { | ||
List<String> finalArgs = Stream.concat(Arrays.stream(args), extraArgs.stream()).collect(Collectors.toList()); | ||
CommandResults npmCommandRes = commandExecutor.exeCommand(workingDirectory, finalArgs); | ||
if (!npmCommandRes.isOk()) { | ||
throw new IOException(npmCommandRes.getErr()); | ||
} | ||
return npmCommandRes.getRes(); | ||
} | ||
} |
Oops, something went wrong.