Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into ps_notification_key_gen
  • Loading branch information
ekerwin committed May 9, 2018
2 parents 759c8c5 + ff3f218 commit 95915ba
Show file tree
Hide file tree
Showing 23 changed files with 499 additions and 352 deletions.
20 changes: 11 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ buildscript {
}
plugins { id 'groovy' }

version = '31.1.0-SNAPSHOT'
version = '32.0.0-SNAPSHOT'

apply plugin: 'com.blackducksoftware.integration.library'

repositories {
mavenLocal()
}

dependencies {
compile 'com.blackducksoftware.integration:hub-common-rest:8.2.2'
compile 'com.blackducksoftware.integration:hub-common-rest:9.0.1'
compile 'com.blackducksoftware.integration:hub-common-api:4.6.0.1'
compile 'com.blackducksoftware.integration:hub-common-reporting:4.1.0'
compile 'com.blackducksoftware.integration:integration-bdio:13.0.0'
compile 'com.blackducksoftware.integration:phone-home-client:0.9.1'

compile 'joda-time:joda-time:2.9.6'
compile 'com.blackducksoftware.integration:hub-common-reporting:5.0.0'
compile 'com.blackducksoftware.integration:integration-bdio:14.0.0'
compile 'com.blackducksoftware.integration:phone-home-client:0.12.0'

testCompile 'org.codehaus.groovy:groovy-all:2.4.12'
testCompile 'org.mockito:mockito-core:2.13.0'
testCompile 'org.codehaus.groovy:groovy-all:2.4.15'
testCompile 'org.mockito:mockito-core:2.18.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
import com.blackducksoftware.integration.hub.rest.RestConnection;
import com.blackducksoftware.integration.hub.service.model.RequestFactory;
import com.blackducksoftware.integration.log.IntLogger;
import com.blackducksoftware.integration.util.CIEnvironmentVariables;
import com.blackducksoftware.integration.util.HostNameHelper;
import com.blackducksoftware.integration.util.IntEnvironmentVariables;

public class CLIDownloadUtility {
private final IntLogger logger;
Expand All @@ -68,17 +69,13 @@ public CLIDownloadUtility(final IntLogger logger, final RestConnection restConne
this.restConnection = restConnection;
}

public void performInstallation(final File directoryToInstallTo, final CIEnvironmentVariables ciEnvironmentVariables, final String hubUrl, final String hubVersion, final String localHostName)
public void performInstallation(final File directoryToInstallTo, final IntEnvironmentVariables intEnvironmentVariables, final String hubUrl, final String hubVersion)
throws HubIntegrationException, EncryptionException {
if (StringUtils.isBlank(localHostName)) {
throw new IllegalArgumentException("You must provided the hostName of the machine this is running on.");
}

final CLILocation cliLocation = new CLILocation(this.logger, directoryToInstallTo);
final String cliDownloadUrl = cliLocation.getCLIDownloadUrl(this.logger, hubUrl);
if (StringUtils.isNotBlank(cliDownloadUrl)) {
try {
customInstall(cliLocation, ciEnvironmentVariables, new URL(cliDownloadUrl), hubVersion, localHostName);
customInstall(cliLocation, intEnvironmentVariables, new URL(cliDownloadUrl), hubVersion);
} catch (final MalformedURLException e) {
throw new HubIntegrationException(String.format("The cli could not be downloaded from %s: %s", cliDownloadUrl, e.getMessage()), e);
}
Expand All @@ -87,8 +84,7 @@ public void performInstallation(final File directoryToInstallTo, final CIEnviron
}
}

public void customInstall(final CLILocation cliLocation, final CIEnvironmentVariables ciEnvironmentVariables, final URL cliDownloadUrl, final String hubVersion, final String localHostName)
throws HubIntegrationException, EncryptionException {
public void customInstall(final CLILocation cliLocation, final IntEnvironmentVariables intEnvironmentVariables, final URL cliDownloadUrl, final String hubVersion) throws HubIntegrationException, EncryptionException {
final String directoryToInstallTo;
try {
directoryToInstallTo = cliLocation.getCanonicalPath();
Expand Down Expand Up @@ -164,14 +160,15 @@ public void customInstall(final CLILocation cliLocation, final CIEnvironmentVari
this.logger.debug("Updating the Hub CLI.");
hubVersionFile.setLastModified(lastModifiedLong);

final String localHostName = HostNameHelper.getMyHostName();
this.logger.info("Unpacking " + cliDownloadUrl.toString() + " to " + directoryToInstallTo + " on " + localHostName);

try (InputStream cliStream = response.getContent()) {
long byteCount = 0;
try (CountingInputStream cis = new CountingInputStream(cliStream)) {
byteCount = cis.getByteCount();
unzip(cliInstallDirectory, cis, this.logger);
updateJreSecurity(this.logger, cliLocation, ciEnvironmentVariables);
updateJreSecurity(this.logger, cliLocation, intEnvironmentVariables);
} catch (final IOException e) {
throw new HubIntegrationException(String.format("Failed to unpack %s (%d bytes read of total %d)", cliDownloadUrl, byteCount, response.getContentLength()), e);
}
Expand All @@ -187,7 +184,7 @@ public void customInstall(final CLILocation cliLocation, final CIEnvironmentVari
}
}

private void updateJreSecurity(final IntLogger logger, final CLILocation cliLocation, final CIEnvironmentVariables ciEnvironmentVariables) throws IOException {
private void updateJreSecurity(final IntLogger logger, final CLILocation cliLocation, final IntEnvironmentVariables intEnvironmentVariables) throws IOException {
final File securityDirectory = cliLocation.getJreSecurityDirectory();
if (securityDirectory == null || !securityDirectory.isDirectory()) {
// the cli might not have the jre included
Expand All @@ -196,9 +193,9 @@ private void updateJreSecurity(final IntLogger logger, final CLILocation cliLoca
return;
}
File trustStoreFile = null;
if (ciEnvironmentVariables.containsKey(CIEnvironmentVariables.BDS_CACERTS_OVERRIDE)) {
logger.trace("Found the variable : " + CIEnvironmentVariables.BDS_CACERTS_OVERRIDE + ", using value : " + ciEnvironmentVariables.getValue(CIEnvironmentVariables.BDS_CACERTS_OVERRIDE));
final String trustStorePath = ciEnvironmentVariables.getValue(CIEnvironmentVariables.BDS_CACERTS_OVERRIDE);
if (intEnvironmentVariables.containsKey(IntEnvironmentVariables.BDS_CACERTS_OVERRIDE)) {
logger.trace("Found the variable : " + IntEnvironmentVariables.BDS_CACERTS_OVERRIDE + ", using value : " + intEnvironmentVariables.getValue(IntEnvironmentVariables.BDS_CACERTS_OVERRIDE));
final String trustStorePath = intEnvironmentVariables.getValue(IntEnvironmentVariables.BDS_CACERTS_OVERRIDE);
trustStoreFile = new File(trustStorePath);
} else {
final CertificateHandler certificateHandler = new CertificateHandler(logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -40,10 +43,6 @@
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.blackducksoftware.integration.exception.EncryptionException;
import com.blackducksoftware.integration.exception.IntegrationException;
Expand All @@ -57,7 +56,7 @@
import com.blackducksoftware.integration.hub.service.model.ScannerSplitStream;
import com.blackducksoftware.integration.hub.service.model.StreamRedirectThread;
import com.blackducksoftware.integration.log.IntLogger;
import com.blackducksoftware.integration.util.CIEnvironmentVariables;
import com.blackducksoftware.integration.util.IntEnvironmentVariables;
import com.google.gson.Gson;

public class SimpleScanUtility {
Expand All @@ -66,20 +65,20 @@ public class SimpleScanUtility {
private final Gson gson;
private final IntLogger logger;
private final HubServerConfig hubServerConfig;
private final CIEnvironmentVariables ciEnvironmentVariables;
private final IntEnvironmentVariables intEnvironmentVariables;
private final HubScanConfig hubScanConfig;
private final String project;
private final String version;
private final List<String> cmd = new ArrayList<>();

private File logDirectory;

public SimpleScanUtility(final IntLogger logger, final Gson gson, final HubServerConfig hubServerConfig, final CIEnvironmentVariables ciEnvironmentVariables, final HubScanConfig hubScanConfig,
public SimpleScanUtility(final IntLogger logger, final Gson gson, final HubServerConfig hubServerConfig, final IntEnvironmentVariables intEnvironmentVariables, final HubScanConfig hubScanConfig,
final String project, final String version) {
this.gson = gson;
this.logger = logger;
this.hubServerConfig = hubServerConfig;
this.ciEnvironmentVariables = ciEnvironmentVariables;
this.intEnvironmentVariables = intEnvironmentVariables;
this.hubScanConfig = hubScanConfig;
this.project = project;
this.version = version;
Expand Down Expand Up @@ -269,7 +268,7 @@ private void executeScan() throws IllegalArgumentException, EncryptionException,
}
processBuilder.environment().put("BD_HUB_NO_PROMPT", "true");

final String bdioEnvVar = ciEnvironmentVariables.getValue("BD_HUB_DECLARED_COMPONENTS");
final String bdioEnvVar = intEnvironmentVariables.getValue("BD_HUB_DECLARED_COMPONENTS");
if (StringUtils.isNotBlank(bdioEnvVar)) {
processBuilder.environment().put("BD_HUB_DECLARED_COMPONENTS", bdioEnvVar);
}
Expand Down Expand Up @@ -348,8 +347,8 @@ public List<ScanSummaryView> getScanSummaryItems() {
* This method can be overridden to provide a more appropriate directory name for the logs of a specific scan execution.
*/
public String getSpecificScanExecutionLogDirectory() {
final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd_HH-mm-ss-SSS").withZoneUTC();
final String timeString = DateTime.now().withZone(DateTimeZone.UTC).toString(dateTimeFormatter);
final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss-SSS").withZone(ZoneOffset.UTC);
final String timeString = Instant.now().atZone(ZoneOffset.UTC).format(dateTimeFormatter);
return timeString;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.blackducksoftware.integration.hub.request.Request;
import com.blackducksoftware.integration.hub.request.Response;
import com.blackducksoftware.integration.hub.rest.HttpMethod;
import com.blackducksoftware.integration.hub.service.model.HubQuery;
import com.blackducksoftware.integration.hub.service.model.RequestFactory;

public class CodeLocationService extends DataService {
Expand Down Expand Up @@ -133,7 +134,8 @@ public void deleteCodeLocation(final String codeLocationViewUrl) throws Integrat

public CodeLocationView getCodeLocationByName(final String codeLocationName) throws IntegrationException {
if (StringUtils.isNotBlank(codeLocationName)) {
final Request.Builder requestBuilder = RequestFactory.createCommonGetRequestBuilder().addQueryParameter("q", "name:" + codeLocationName);
final HubQuery hubQuery = new HubQuery("name:" + codeLocationName);
final Request.Builder requestBuilder = RequestFactory.createCommonGetRequestBuilder(hubQuery);
final List<CodeLocationView> codeLocations = hubService.getAllResponses(ApiDiscovery.CODELOCATIONS_LINK_RESPONSE, requestBuilder);
for (final CodeLocationView codeLocation : codeLocations) {
if (codeLocationName.equals(codeLocation.name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.blackducksoftware.integration.hub.exception.HubIntegrationException;
import com.blackducksoftware.integration.hub.request.Request;
import com.blackducksoftware.integration.hub.service.model.HubMediaTypes;
import com.blackducksoftware.integration.hub.service.model.HubQuery;
import com.blackducksoftware.integration.hub.service.model.RequestFactory;

public class ComponentService extends DataService {
Expand Down Expand Up @@ -77,9 +78,9 @@ public ComponentSearchResultView getExactComponentMatch(final ExternalId externa
public List<ComponentSearchResultView> getAllComponents(final ExternalId externalId) throws IntegrationException {
final String forge = externalId.forge.getName();
final String hubOriginId = externalId.createHubOriginId();
final String componentQuery = String.format("id:%s|%s", forge, hubOriginId);
final HubQuery hubQuery = new HubQuery(String.format("id:%s|%s", forge, hubOriginId));

final Request.Builder requestBuilder = new Request.Builder().addQueryParameter("q", componentQuery);
final Request.Builder requestBuilder = RequestFactory.createCommonGetRequestBuilder(hubQuery);
final List<ComponentSearchResultView> allComponents = hubService.getAllResponses(ApiDiscovery.COMPONENTS_LINK_RESPONSE, requestBuilder);
return allComponents;
}
Expand Down

This file was deleted.

Loading

0 comments on commit 95915ba

Please sign in to comment.