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

Commit

Permalink
Merge fc1038a into ceb7284
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Billings committed Jan 16, 2019
2 parents ceb7284 + fc1038a commit 994b5f6
Show file tree
Hide file tree
Showing 53 changed files with 2,431 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public enum DetectTool {
SIGNATURE_SCAN,
BINARY_SCAN,
POLARIS,
DOCKER;

DOCKER,
BAZEL;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.blackducksoftware.integration.hub.detect.configuration;

import static com.blackducksoftware.integration.hub.detect.configuration.DetectProperty.PropertyConstants.GROUP_BAZEL;
import static com.blackducksoftware.integration.hub.detect.configuration.DetectProperty.PropertyConstants.GROUP_BITBAKE;
import static com.blackducksoftware.integration.hub.detect.configuration.DetectProperty.PropertyConstants.GROUP_BLACKDUCK_CONFIGURATION;
import static com.blackducksoftware.integration.hub.detect.configuration.DetectProperty.PropertyConstants.GROUP_BOMTOOL;
Expand Down Expand Up @@ -281,8 +282,8 @@ public enum DetectProperty {

@HelpGroup(primary = GROUP_PATHS, additional = { GROUP_BOMTOOL, SEARCH_GROUP_SEARCH })
@HelpDescription("The tool priority for project name and version. The first tool in this list that provides a project name and version will be used.")
@AcceptableValues(value = { "DETECTOR", "DOCKER" }, caseSensitive = true, strict = true, isCommaSeparatedList = true)
DETECT_PROJECT_TOOL("detect.project.tool", "5.0.0", PropertyType.STRING, PropertyAuthority.None, "DETECTOR,DOCKER"),
@AcceptableValues(value = { "DETECTOR", "DOCKER", "BAZEL" }, caseSensitive = true, strict = true, isCommaSeparatedList = true)
DETECT_PROJECT_TOOL("detect.project.tool", "5.0.0", PropertyType.STRING, PropertyAuthority.None, "DOCKER,DETECTOR,BAZEL"),

@HelpGroup(primary = GROUP_PATHS, additional = { GROUP_BOMTOOL, SEARCH_GROUP_SEARCH })
@HelpDescription("The tools detect should allow in a comma-separated list. Included and not excluded tools will be allowed to run if all criteria of the tool is met. Exclusion rules always win.")
Expand All @@ -291,7 +292,7 @@ public enum DetectProperty {

@HelpGroup(primary = GROUP_PATHS, additional = { GROUP_BOMTOOL, SEARCH_GROUP_SEARCH })
@HelpDescription("The tools detect should not allow in a comma-separated list. Excluded tools will not be run even if all criteria for the tool is met. Exclusion rules always win.")
@AcceptableValues(value = { "DETECTOR", "DOCKER", "SIGNATURE_SCAN", "BINARY_SCAN", "POLARIS", "NONE", "ALL" }, caseSensitive = true, strict = false, isCommaSeparatedList = true)
@AcceptableValues(value = { "BAZEL", "DETECTOR", "DOCKER", "SIGNATURE_SCAN", "BINARY_SCAN", "POLARIS", "NONE", "ALL" }, caseSensitive = true, strict = false, isCommaSeparatedList = true)
DETECT_TOOLS_EXCLUDED("detect.tools.excluded", "5.0.0", PropertyType.STRING, PropertyAuthority.None),

@Deprecated
Expand Down Expand Up @@ -541,6 +542,18 @@ public enum DetectProperty {
@HelpDescription("The names of the module to include")
DETECT_MAVEN_INCLUDED_MODULES("detect.maven.included.modules", "3.0.0", PropertyType.STRING, PropertyAuthority.None),

@HelpGroup(primary = GROUP_BAZEL)
@HelpDescription("The path of the Bazel executable")
DETECT_BAZEL_PATH("detect.bazel.path", "5.2.0", PropertyType.STRING, PropertyAuthority.None),

@HelpGroup(primary = GROUP_BAZEL)
@HelpDescription("The bazel target (e.g. //foo:foolib) to collect dependencies for. For detect to run bazel this property must be set.")
DETECT_BAZEL_TARGET("detect.bazel.target", "5.2.0", PropertyType.STRING, PropertyAuthority.None),

@HelpGroup(primary = GROUP_BAZEL)
@HelpDescription("The path to a file containing a list of BazelExternalIdExtractionXPathRule objects in json (to override the default behavior)")
DETECT_BAZEL_ADVANCED_RULES_PATH("detect.bazel.advanced.rules.path", "5.2.0", PropertyType.STRING, PropertyAuthority.None),

@Deprecated
@DetectDeprecation(description = "In the future, detect will no longer need a nuget executable as it will download the inspector from Artifactory exclusively.", failInVersion = DetectMajorVersion.SIX, removeInVersion = DetectMajorVersion.SEVEN)
@HelpGroup(primary = GROUP_NUGET)
Expand Down Expand Up @@ -961,6 +974,7 @@ public final class PropertyConstants {
public static final String GROUP_SIGNATURE_SCANNER = "signature scanner";
public static final String GROUP_YARN = "yarn";
public static final String GROUP_POLARIS = "polaris";
public static final String GROUP_BAZEL = "bazel";

@Deprecated
public static final String SEARCH_GROUP_HUB = "hub";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public enum ExecutableType {
PYTHON3,
REBAR3,
YARN,
JAVA;
JAVA,
BAZEL;

private String executableName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@
import com.blackducksoftware.integration.hub.detect.detector.yarn.YarnLockDetector;
import com.blackducksoftware.integration.hub.detect.detector.yarn.YarnLockExtractor;
import com.blackducksoftware.integration.hub.detect.detector.yarn.YarnLockParser;
import com.blackducksoftware.integration.hub.detect.tool.bazel.BazelCodeLocationBuilder;
import com.blackducksoftware.integration.hub.detect.tool.bazel.BazelDetector;
import com.blackducksoftware.integration.hub.detect.tool.bazel.BazelExecutableFinder;
import com.blackducksoftware.integration.hub.detect.tool.bazel.BazelExternalIdExtractionFullRuleJsonProcessor;
import com.blackducksoftware.integration.hub.detect.tool.bazel.BazelExternalIdExtractionSimpleRules;
import com.blackducksoftware.integration.hub.detect.tool.bazel.BazelExtractor;
import com.blackducksoftware.integration.hub.detect.tool.bazel.BazelQueryXmlOutputParser;
import com.blackducksoftware.integration.hub.detect.tool.bazel.XPathParser;
import com.blackducksoftware.integration.hub.detect.util.executable.CacheableExecutableFinder;
import com.blackducksoftware.integration.hub.detect.util.executable.ExecutableFinder;
import com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner;
Expand Down Expand Up @@ -202,6 +210,15 @@ public CodeLocationAssembler codeLocationAssembler() {
return new CodeLocationAssembler(externalIdFactory);
}

@Bean
public BazelExtractor bazelExtractor() {
BazelQueryXmlOutputParser parser = new BazelQueryXmlOutputParser(new XPathParser());
BazelExternalIdExtractionSimpleRules rules = new BazelExternalIdExtractionSimpleRules(detectConfiguration.getProperty(DetectProperty.DETECT_BAZEL_TARGET, PropertyAuthority.None));
BazelCodeLocationBuilder codeLocationGenerator = new BazelCodeLocationBuilder(externalIdFactory);
BazelExternalIdExtractionFullRuleJsonProcessor bazelExternalIdExtractionFullRuleJsonProcessor = new BazelExternalIdExtractionFullRuleJsonProcessor(gson);
return new BazelExtractor(detectConfiguration, executableRunner, parser, rules, codeLocationGenerator, bazelExternalIdExtractionFullRuleJsonProcessor);
}

@Bean
public ClangExtractor clangExtractor() {
return new ClangExtractor(detectConfiguration, executableRunner, gson, detectFileFinder, directoryManager, clangDependenciesListFileParser(), codeLocationAssembler());
Expand Down Expand Up @@ -325,6 +342,11 @@ public MavenExecutableFinder mavenExecutableFinder() {
return new MavenExecutableFinder(executableFinder, detectConfiguration);
}

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

@Bean
public NpmCliParser npmCliDependencyFinder() {
return new NpmCliParser(externalIdFactory);
Expand Down Expand Up @@ -459,6 +481,13 @@ public BitbakeListTasksParser bitbakeListTasksParser() {
//Should be scoped to Prototype so a new Detector is created every time one is needed.
//Should only be accessed through the DetectorFactory.


@Bean
@Scope(scopeName = BeanDefinition.SCOPE_PROTOTYPE)
public BazelDetector bazelDetector(final DetectorEnvironment environment) {
return new BazelDetector(environment, bazelExtractor(), bazelExecutableFinder(), detectConfiguration);
}

@Bean
@Scope(scopeName = BeanDefinition.SCOPE_PROTOTYPE)
public BitbakeDetector bitbakeBomTool(final DetectorEnvironment environment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockDetector;
import com.blackducksoftware.integration.hub.detect.detector.sbt.SbtResolutionCacheDetector;
import com.blackducksoftware.integration.hub.detect.detector.yarn.YarnLockDetector;
import com.blackducksoftware.integration.hub.detect.tool.bazel.BazelDetector;
import com.blackducksoftware.integration.hub.detect.tool.docker.DockerDetector;

public class DetectorFactory implements BeanFactoryAware {

Expand All @@ -63,6 +65,14 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}

public BazelDetector createBazelDetector(final DetectorEnvironment environment) {
return beanFactory.getBean(BazelDetector.class, environment);
}

public DockerDetector createDockerDetector(final DetectorEnvironment environment) {
return beanFactory.getBean(DockerDetector.class, environment);
}

public BitbakeDetector createBitbakeBomTool(final DetectorEnvironment environment) {
return beanFactory.getBean(BitbakeDetector.class, environment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.blackducksoftware.integration.hub.detect.lifecycle.run;

import java.util.Collections;
import java.util.Optional;

import org.slf4j.Logger;
Expand All @@ -35,15 +36,16 @@
import com.blackducksoftware.integration.hub.detect.configuration.DetectConfigurationFactory;
import com.blackducksoftware.integration.hub.detect.configuration.DetectProperty;
import com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority;
import com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment;
import com.blackducksoftware.integration.hub.detect.detector.DetectorFactory;
import com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException;
import com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType;
import com.blackducksoftware.integration.hub.detect.lifecycle.DetectContext;
import com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest;
import com.blackducksoftware.integration.hub.detect.tool.ToolRunner;
import com.blackducksoftware.integration.hub.detect.tool.binaryscanner.BlackDuckBinaryScannerTool;
import com.blackducksoftware.integration.hub.detect.tool.detector.DetectorTool;
import com.blackducksoftware.integration.hub.detect.tool.detector.DetectorToolResult;
import com.blackducksoftware.integration.hub.detect.tool.docker.DockerTool;
import com.blackducksoftware.integration.hub.detect.tool.docker.DockerToolResult;
import com.blackducksoftware.integration.hub.detect.tool.polaris.PolarisTool;
import com.blackducksoftware.integration.hub.detect.tool.signaturescanner.BlackDuckSignatureScannerOptions;
import com.blackducksoftware.integration.hub.detect.tool.signaturescanner.BlackDuckSignatureScannerTool;
Expand Down Expand Up @@ -110,27 +112,30 @@ public RunResult run() throws DetectUserFriendlyException, InterruptedException,

final RunResult runResult = new RunResult();
final RunOptions runOptions = detectConfigurationFactory.createRunOptions();

final DetectToolFilter detectToolFilter = runOptions.getDetectToolFilter();

DetectorEnvironment detectorEnvironment = new DetectorEnvironment(directoryManager.getSourceDirectory(), Collections.emptySet(), 0, null, false);
DetectorFactory detectorFactory = detectContext.getBean(DetectorFactory.class);
logger.info(ReportConstants.RUN_SEPARATOR);
if (detectToolFilter.shouldInclude(DetectTool.DOCKER)) {
logger.info("Will include the docker tool.");
final DockerTool dockerTool = new DockerTool(detectContext);

final DockerToolResult dockerToolResult = dockerTool.run();
runResult.addToolNameVersionIfPresent(DetectTool.DOCKER, dockerToolResult.dockerProjectNameVersion);
runResult.addDetectCodeLocations(dockerToolResult.dockerCodeLocations);
runResult.addDockerFile(dockerToolResult.dockerTar);

if (dockerToolResult.resultType == DockerToolResult.DockerToolResultType.FAILURE) {
eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_GENERAL_ERROR, dockerToolResult.errorMessage));
}
ToolRunner toolRunner = new ToolRunner(eventSystem, detectorFactory.createDockerDetector(detectorEnvironment));
toolRunner.run(runResult);
logger.info("Docker actions finished.");
} else {
logger.info("Docker tool will not be run.");
}

logger.info(ReportConstants.RUN_SEPARATOR);
if (detectToolFilter.shouldInclude(DetectTool.BAZEL)) {
logger.info("Will include the bazel tool.");
ToolRunner toolRunner = new ToolRunner(eventSystem, detectorFactory.createBazelDetector(detectorEnvironment));
toolRunner.run(runResult);
logger.info("Bazel actions finished.");
} else {
logger.info("Bazel tool will not be run.");
}

logger.info(ReportConstants.RUN_SEPARATOR);
if (detectToolFilter.shouldInclude(DetectTool.DETECTOR)) {
logger.info("Will include the detector tool.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* hub-detect
*
* Copyright (C) 2019 Black Duck Software, Inc.
* http://www.blackducksoftware.com/
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.blackducksoftware.integration.hub.detect.tool;

import com.blackducksoftware.integration.hub.detect.DetectTool;
import com.blackducksoftware.integration.hub.detect.detector.DetectorException;
import com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction;
import com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorResult;

public abstract class SimpleToolDetector {
private final DetectTool toolEnum;

public SimpleToolDetector(final DetectTool toolEnum) {
this.toolEnum = toolEnum;
}
public DetectTool getToolEnum() {
return toolEnum;
}
public abstract DetectorResult applicable();
public abstract DetectorResult extractable() throws DetectorException;
public abstract Extraction extract();
}
Loading

0 comments on commit 994b5f6

Please sign in to comment.