Skip to content
This repository has been archived by the owner on Nov 30, 2017. It is now read-only.

Commit

Permalink
Merge pull request #19 from blackducksoftware/feature_includedConfigu…
Browse files Browse the repository at this point in the history
…rations

Add includedConfigurations property to the gradle tasks
  • Loading branch information
psantos1113 committed Dec 12, 2016
2 parents 5119b3e + 28fbcc0 commit 6f83870
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class DependencyGatherer {

final Map<String, DependencyNode> visitedMap = new HashMap<>();

final String includedConfigurations;

public DependencyGatherer(String includedConfigurations) {
this.includedConfigurations = includedConfigurations;
}

public DependencyNode getFullyPopulatedRootNode(Project project, String hubProjectName, String hubProjectVersion) {
logger.info("creating the dependency graph");
final String groupId = project.getGroup().toString();
Expand All @@ -59,7 +65,7 @@ public DependencyNode getFullyPopulatedRootNode(Project project, String hubProje
}

private void getProjectDependencies(final Project project, final List<DependencyNode> children) {
final ScopesHelper scopesHelper = new ScopesHelper(project);
final ScopesHelper scopesHelper = new ScopesHelper(project, includedConfigurations);
final Set<Configuration> configurations = project.getConfigurations();
for (final Configuration configuration : configurations) {
final String configName = configuration.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,36 @@ public class PluginHelper {
private final Logger logger = LoggerFactory.getLogger(PluginHelper.class);

public void createFlatDependencyList(Project project, final String hubProjectName, final String hubProjectVersion,
final File outputDirectory) throws IOException {
final DependencyGatherer dependencyGatherer = new DependencyGatherer();
DependencyNode rootNode = dependencyGatherer.getFullyPopulatedRootNode(project, hubProjectName, hubProjectVersion);
final File outputDirectory, final String includedConfigurations) throws IOException {
final DependencyGatherer dependencyGatherer = new DependencyGatherer(includedConfigurations);
final DependencyNode rootNode = dependencyGatherer.getFullyPopulatedRootNode(project, hubProjectName, hubProjectVersion);

final FlatDependencyListWriter flatDependencyListWriter = new FlatDependencyListWriter();
flatDependencyListWriter.write(outputDirectory, hubProjectName, rootNode);
}

public void createHubOutput(Project project, final String hubProjectName, final String hubProjectVersion,
final File outputDirectory) throws IOException {
final DependencyGatherer dependencyGatherer = new DependencyGatherer();
DependencyNode rootNode = dependencyGatherer.getFullyPopulatedRootNode(project, hubProjectName, hubProjectVersion);
final File outputDirectory, final String includedConfigurations) throws IOException {
final DependencyGatherer dependencyGatherer = new DependencyGatherer(includedConfigurations);
final DependencyNode rootNode = dependencyGatherer.getFullyPopulatedRootNode(project, hubProjectName, hubProjectVersion);

final BdioDependencyWriter bdioDependencyWriter = new BdioDependencyWriter();
bdioDependencyWriter.write(outputDirectory, hubProjectName, rootNode);
}

public void deployHubOutput(final Slf4jIntLogger logger, final HubServicesFactory services,
final File outputDirectory, final String hubProjectName) throws IOException, ResourceDoesNotExistException, URISyntaxException, BDRestException {
String filename = BdioDependencyWriter.getFilename(hubProjectName);
final String filename = BdioDependencyWriter.getFilename(hubProjectName);
final File file = new File(outputDirectory, filename);
BomImportRestService bomImportRestService = services.createBomImportRestService();
final BomImportRestService bomImportRestService = services.createBomImportRestService();
bomImportRestService.importBomFile(file, Constants.BDIO_FILE_MEDIA_TYPE);

logger.info(String.format(Constants.UPLOAD_FILE_MESSAGE, file, bomImportRestService.getRestConnection().getBaseUrl()));
}

public void waitForHub(final HubServicesFactory services, final String hubProjectName,
final String hubProjectVersion, final long scanStartedTimeout, final long scanFinishedTimeout) {
ScanStatusDataService scanStatusDataService = services.createScanStatusDataService();
final ScanStatusDataService scanStatusDataService = services.createScanStatusDataService();
try {
scanStatusDataService.assertBomImportScanStartedThenFinished(hubProjectName, hubProjectVersion,
scanStartedTimeout * 1000, scanFinishedTimeout * 1000, new Slf4jIntLogger(logger));
Expand All @@ -94,14 +94,14 @@ public void createRiskReport(final Slf4jIntLogger logger, final HubServicesFacto
final File outputDirectory, String projectName, String projectVersionName)
throws IOException, BDRestException, URISyntaxException, HubIntegrationException, InterruptedException, UnexpectedHubResponseException,
ProjectDoesNotExistException {
RiskReportDataService reportDataService = services.createRiskReportDataService(logger);
final RiskReportDataService reportDataService = services.createRiskReportDataService(logger);
reportDataService.createRiskReport(outputDirectory, projectName, projectVersionName);
}

public PolicyStatusItem checkPolicies(final HubServicesFactory services, final String hubProjectName,
final String hubProjectVersion) throws IOException, URISyntaxException, BDRestException, ProjectDoesNotExistException, HubIntegrationException,
MissingUUIDException, UnexpectedHubResponseException {
PolicyStatusDataService policyStatusDataService = services.createPolicyStatusDataService();
final PolicyStatusDataService policyStatusDataService = services.createPolicyStatusDataService();
final PolicyStatusItem policyStatusItem = policyStatusDataService
.getPolicyStatusForProjectAndVersion(hubProjectName, hubProjectVersion);
return policyStatusItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ public class ScopesHelper {

private final Map<String, Boolean> shouldIncludeScopeMap = new HashMap<>();

public ScopesHelper(final Project project) {
private final String includedConfigurations;

public ScopesHelper(final Project project, String includedConfigurations) {
this.project = project;
this.includedConfigurations = includedConfigurations;
populateRequestedScopes();
populateAllAvailableScopes();
populateShouldIncludeScopeMap();
Expand Down Expand Up @@ -89,7 +92,14 @@ private void populateAllAvailableScopes() {
}

private void populateRequestedScopes() {
final String requestedScopesString = System.getProperty(INCLUDED_CONFIGURATIONS_PROPERTY);
// using the system property is deprecated but for customers that may set it check for it.
String requestedScopesString = System.getProperty(INCLUDED_CONFIGURATIONS_PROPERTY);
// let the task property override the system property since the system property existed
// beforehand
if (includedConfigurations != null && includedConfigurations.trim().length() > 0) {
requestedScopesString = includedConfigurations;
}

if (requestedScopesString != null && requestedScopesString.trim().length() > 0) {
requestedScopes = new HashSet<>();
if (requestedScopesString.contains(",")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void performTask() {
logger.info(String.format(CREATE_FLAT_DEPENDENCY_LIST_STARTING, getFlatFilename()));

try {
PLUGIN_HELPER.createFlatDependencyList(getProject(), getHubProjectName(), getHubVersionName(), getOutputDirectory());
PLUGIN_HELPER.createFlatDependencyList(getProject(), getHubProjectName(), getHubVersionName(), getOutputDirectory(), getIncludedConfigurations());
} catch (final IOException e) {
throw new GradleException(String.format(CREATE_FLAT_DEPENDENCY_LIST_ERROR, e.getMessage()), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void performTask() {
logger.info(String.format(CREATE_HUB_OUTPUT_STARTING, getBdioFilename()));

try {
PLUGIN_HELPER.createHubOutput(getProject(), getHubProjectName(), getHubVersionName(), getOutputDirectory());
PLUGIN_HELPER.createHubOutput(getProject(), getHubProjectName(), getHubVersionName(), getOutputDirectory(), getIncludedConfigurations());
} catch (final IOException e) {
throw new GradleException(String.format(CREATE_HUB_OUTPUT_ERROR, e.getMessage()), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public void performTask() {
logger.info(String.format(DEPLOY_HUB_OUTPUT_AND_CHECK_POLICIES_STARTING, getBdioFilename()));

try {
PLUGIN_HELPER.createHubOutput(getProject(), getHubProjectName(), getHubVersionName(), getOutputDirectory());
PLUGIN_HELPER.createHubOutput(getProject(), getHubProjectName(), getHubVersionName(), getOutputDirectory(), getIncludedConfigurations());
} catch (final IOException e) {
throw new GradleException(String.format(CREATE_HUB_OUTPUT_ERROR, e.getMessage()), e);
}

final HubServerConfig hubServerConfig = getHubServerConfigBuilder().build();
final RestConnection restConnection;
Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
final Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
HubServicesFactory services;
try {
restConnection = new CredentialsRestConnection(hubServerConfig);
Expand All @@ -78,7 +78,7 @@ public void performTask() {
PLUGIN_HELPER.waitForHub(services, getHubProjectName(), getHubVersionName(), getHubScanStartedTimeout(),
getHubScanFinishedTimeout());
if (getCreateHubReport()) {
File reportOutput = new File(getOutputDirectory(), "report");
final File reportOutput = new File(getOutputDirectory(), "report");
try {
PLUGIN_HELPER.createRiskReport(intLogger, services, reportOutput, getHubProjectName(), getHubVersionName());
} catch (IllegalArgumentException | URISyntaxException | BDRestException | IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public void performTask() {
logger.info(String.format(DEPLOY_HUB_OUTPUT_STARTING, getBdioFilename()));

try {
PLUGIN_HELPER.createHubOutput(getProject(), getHubProjectName(), getHubVersionName(), getOutputDirectory());
PLUGIN_HELPER.createHubOutput(getProject(), getHubProjectName(), getHubVersionName(), getOutputDirectory(), getIncludedConfigurations());
} catch (final IOException e) {
throw new GradleException(String.format(CREATE_HUB_OUTPUT_ERROR, e.getMessage()), e);
}

final HubServerConfig hubServerConfig = getHubServerConfigBuilder().build();
Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
final Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
RestConnection restConnection;
HubServicesFactory services;
try {
Expand All @@ -69,7 +69,7 @@ public void performTask() {
if (getCreateHubReport()) {
PLUGIN_HELPER.waitForHub(services, getHubProjectName(), getHubVersionName(), getHubScanStartedTimeout(),
getHubScanFinishedTimeout());
File reportOutput = new File(getOutputDirectory(), "report");
final File reportOutput = new File(getOutputDirectory(), "report");
try {
PLUGIN_HELPER.createRiskReport(intLogger, services, reportOutput, getHubProjectName(), getHubVersionName());
} catch (IllegalArgumentException | URISyntaxException | BDRestException | IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ public abstract class HubTask extends DefaultTask {

private File outputDirectory;

private String includedConfigurations = "compile";

public HubTask() {
File buildDir = null == getProject().getRootProject() ? getProject().getBuildDir() : getProject().getRootProject().getBuildDir();
final File buildDir = null == getProject().getRootProject() ? getProject().getBuildDir() : getProject().getRootProject().getBuildDir();
outputDirectory = new File(buildDir, "blackduck");
}

Expand Down Expand Up @@ -267,4 +269,11 @@ public void setHubScanFinishedTimeout(long hubScanFinishedTimeout) {
this.hubScanFinishedTimeout = hubScanFinishedTimeout;
}

public String getIncludedConfigurations() {
return includedConfigurations;
}

public void setIncludedConfigurations(String includedConfigurations) {
this.includedConfigurations = includedConfigurations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ public void canApplyPluginToProject() {
assertNotNull(task);
assertTrue(task instanceof CreateHubOutputTask);
}

}

0 comments on commit 6f83870

Please sign in to comment.