Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
moved verification of the bazel executable (running the bazel version…
Browse files Browse the repository at this point in the history
… command) to BazelExecutableFinder
  • Loading branch information
Steve Billings committed Jan 16, 2019
1 parent 9a319c8 commit 0e5973c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public MavenExecutableFinder mavenExecutableFinder() {

@Bean
public BazelExecutableFinder bazelExecutableFinder() {
return new BazelExecutableFinder(executableFinder, detectConfiguration);
return new BazelExecutableFinder(executableRunner, executableFinder, detectConfiguration);
}

@Bean
Expand Down Expand Up @@ -479,7 +479,7 @@ public BitbakeListTasksParser bitbakeListTasksParser() {
@Bean
@Scope(scopeName = BeanDefinition.SCOPE_PROTOTYPE)
public BazelDetector bazelDetector(final DetectorEnvironment environment) {
return new BazelDetector(environment, executableRunner, bazelExtractor(), bazelExecutableFinder(), detectConfiguration);
return new BazelDetector(environment, bazelExtractor(), bazelExecutableFinder(), detectConfiguration);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
public BazelDetector createBazelDetector(final DetectorEnvironment environment) {
return beanFactory.getBean(BazelDetector.class, environment);
}

public DockerDetector createDockerDetector(final DetectorEnvironment environment) {
return beanFactory.getBean(DockerDetector.class, environment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,24 @@
import com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority;
import com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment;
import com.blackducksoftware.integration.hub.detect.tool.SimpleToolDetector;
import com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput;
import com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner;
import com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException;
import com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction;
import com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorResult;
import com.blackducksoftware.integration.hub.detect.workflow.search.result.ExecutableNotFoundDetectorResult;
import com.blackducksoftware.integration.hub.detect.workflow.search.result.PassedDetectorResult;
import com.blackducksoftware.integration.hub.detect.workflow.search.result.PropertyInsufficientDetectorResult;

public class BazelDetector extends SimpleToolDetector {
private static final String BAZEL_VERSION_SUBCOMMAND = "version";
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final DetectorEnvironment environment;
private final BazelExtractor bazelExtractor;
private final ExecutableRunner executableRunner;
private final BazelExecutableFinder bazelExecutableFinder;
private String bazelExe;
private final DetectConfiguration detectConfiguration;

public BazelDetector(final DetectorEnvironment environment, final ExecutableRunner executableRunner, final BazelExtractor bazelExtractor,
public BazelDetector(final DetectorEnvironment environment, final BazelExtractor bazelExtractor,
BazelExecutableFinder bazelExecutableFinder, final DetectConfiguration detectConfiguration) {
super(DetectTool.BAZEL);
this.environment = environment;
this.executableRunner = executableRunner;
this.bazelExtractor = bazelExtractor;
this.bazelExecutableFinder = bazelExecutableFinder;
this.detectConfiguration = detectConfiguration;
Expand All @@ -74,13 +68,8 @@ public DetectorResult applicable() {
@Override
public DetectorResult extractable() {
bazelExe = bazelExecutableFinder.findBazel(environment);
final ExecutableOutput bazelQueryDepsRecursiveOutput;
try {
bazelQueryDepsRecursiveOutput = executableRunner.executeQuietly(environment.getDirectory(), bazelExe, BAZEL_VERSION_SUBCOMMAND);
int returnCode = bazelQueryDepsRecursiveOutput.getReturnCode();
logger.trace(String.format("Bazel version returned %d; output: %s", returnCode, bazelQueryDepsRecursiveOutput.getStandardOutput()));
} catch (ExecutableRunnerException e) {
logger.debug(String.format("Bazel version threw exception: %s", e.getMessage()));
if (bazelExe == null) {
logger.debug("Bazel command not found");
return new ExecutableNotFoundDetectorResult("bazel");
}
return new PassedDetectorResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@
import com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment;
import com.blackducksoftware.integration.hub.detect.type.ExecutableType;
import com.blackducksoftware.integration.hub.detect.util.executable.ExecutableFinder;
import com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput;
import com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner;
import com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException;

public class BazelExecutableFinder {
private final Logger logger = LoggerFactory.getLogger(this.getClass());

private static final String BAZEL_VERSION_SUBCOMMAND = "version";
private final ExecutableRunner executableRunner;
private final ExecutableFinder executableFinder;
private final DetectConfiguration detectConfiguration;

private boolean hasLookedForSystemBazel = false;
private String resolvedBazel = null;

public BazelExecutableFinder(final ExecutableFinder executableFinder, final DetectConfiguration detectConfiguration) {
public BazelExecutableFinder(final ExecutableRunner executableRunner, final ExecutableFinder executableFinder, final DetectConfiguration detectConfiguration) {
this.executableRunner = executableRunner;
this.executableFinder = executableFinder;
this.detectConfiguration = detectConfiguration;
}
Expand All @@ -53,6 +58,16 @@ public String findBazel(final DetectorEnvironment environment) {
resolvedBazel = executableFinder.getExecutablePathOrOverride(ExecutableType.BAZEL, true, environment.getDirectory(), userProvidedBazelPath);
hasLookedForSystemBazel = true;
}

final ExecutableOutput bazelQueryDepsRecursiveOutput;
try {
bazelQueryDepsRecursiveOutput = executableRunner.executeQuietly(environment.getDirectory(), resolvedBazel, BAZEL_VERSION_SUBCOMMAND);
int returnCode = bazelQueryDepsRecursiveOutput.getReturnCode();
logger.trace(String.format("Bazel version returned %d; output: %s", returnCode, bazelQueryDepsRecursiveOutput.getStandardOutput()));
} catch (ExecutableRunnerException e) {
logger.debug(String.format("Bazel version threw exception: %s", e.getMessage()));
resolvedBazel = null;
}
return resolvedBazel;
}
}

0 comments on commit 0e5973c

Please sign in to comment.