Skip to content

Commit

Permalink
# This is a combination of 25 commits.
Browse files Browse the repository at this point in the history
# 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
Show file tree
Hide file tree
Showing 46 changed files with 1,926 additions and 152 deletions.
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
stack: jdk 8
stack: jdk 8, node 8
skip_tags: true
environment:
matrix:
Expand All @@ -16,7 +16,7 @@ environment:
secure: Xf371RQAxCTMn/S7NdmV8g==

test_script:
- sh: ./gradlew clean test
- cmd: gradlew.bat clean test
- sh: ./gradlew clean test
- cmd: gradlew.bat clean test

build: off
22 changes: 22 additions & 0 deletions build-info-api/src/main/java/org/jfrog/build/api/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@

import com.thoughtworks.xstream.annotations.XStreamAlias;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.jfrog.build.api.BuildBean.MODULE;

Expand Down Expand Up @@ -113,6 +118,23 @@ public void setExcludedArtifacts(List<Artifact> excludedArtifacts) {
this.excludedArtifacts = excludedArtifacts;
}

/**
* Append other module to this module
*
* @param other Module to append
*/
public void append(Module other) {
artifacts = appendBuildFileLists(artifacts, other.getArtifacts());
excludedArtifacts = appendBuildFileLists(excludedArtifacts, other.getExcludedArtifacts());
dependencies = appendBuildFileLists(dependencies, other.getDependencies());
}

private <T extends BaseBuildBean> List<T> appendBuildFileLists(List<T> a, List<T> b) {
return Stream.of(Optional.ofNullable(a).orElseGet(Collections::emptyList), Optional.ofNullable(b).orElseGet(Collections::emptyList))
.flatMap(Collection::stream)
.collect(Collectors.toList());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.collect.Lists;
import org.jfrog.build.api.Dependency;

import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
Expand Down Expand Up @@ -90,6 +91,20 @@ public DependencyBuilder scopes(Set<String> scopes) {
return this;
}

/**
* Adds the given scope to the scopes set
*
* @param scope Dependency scope list
* @return Builder instance
*/
public DependencyBuilder addScope(String scope) {
if (scopes == null) {
scopes = new HashSet<>();
}
scopes.add(scope);
return this;
}

/**
* Sets the SHA1 checksum of the dependency
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jfrog.build.extractor.producerConsumer;
package org.jfrog.build.api.producerConsumer;

/**
* Interface for defining a ProducerConsumerExecutor suitable item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
*
* @author Tomer Cohen
*/
public class GradleBuildInfoExtractor implements BuildInfoExtractor<Project, Build> {
public class GradleBuildInfoExtractor implements BuildInfoExtractor<Project> {
private static final Logger log = Logging.getLogger(GradleBuildInfoExtractor.class);

private static final String SHA1 = "sha1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
* @author Noam Y. Tenne
*/
@Component(role = BuildInfoRecorder.class)
public class BuildInfoRecorder extends AbstractExecutionListener implements BuildInfoExtractor<ExecutionEvent, Build> {
public class BuildInfoRecorder extends AbstractExecutionListener implements BuildInfoExtractor<ExecutionEvent> {

@Requirement
private Logger logger;
Expand Down
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();
}
}
Loading

0 comments on commit 208d8ea

Please sign in to comment.