Skip to content

Commit

Permalink
fix(detectable): Delegate creation of proxyInfo to ConnectionDetails …
Browse files Browse the repository at this point in the history
…in DetectDetectableFactory
  • Loading branch information
crowleySynopsys committed Feb 25, 2020
1 parent c4cc8bd commit 55a940d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 28 deletions.
Expand Up @@ -38,6 +38,7 @@
import com.synopsys.integration.detectable.detectable.result.FilesNotFoundDetectableResult;
import com.synopsys.integration.detectable.detectable.result.InspectorNotFoundDetectableResult;
import com.synopsys.integration.detectable.detectable.result.PassedDetectableResult;
import com.synopsys.integration.rest.proxy.ProxyInfo;

@DetectableInfo(language = "various", forge = "Maven Central", requirementsMarkdown = "File: build.gradle or build.gradle.kts.<br/><br/>Executable: gradlew or gradle.")
public class GradleDetectable extends Detectable {
Expand All @@ -49,18 +50,20 @@ public class GradleDetectable extends Detectable {
private final GradleInspectorResolver gradleInspectorResolver;
private final GradleInspectorExtractor gradleInspectorExtractor;
private final GradleInspectorOptions gradleInspectorOptions;
private final ProxyInfo proxyInfo;

private File gradleExe;
private File gradleInspector;

public GradleDetectable(final DetectableEnvironment environment, final FileFinder fileFinder, final GradleResolver gradleResolver, final GradleInspectorResolver gradleInspectorResolver,
final GradleInspectorExtractor gradleInspectorExtractor, final GradleInspectorOptions gradleInspectorOptions) {
final GradleInspectorExtractor gradleInspectorExtractor, final GradleInspectorOptions gradleInspectorOptions, final ProxyInfo proxyInfo) {
super(environment);
this.fileFinder = fileFinder;
this.gradleResolver = gradleResolver;
this.gradleInspectorResolver = gradleInspectorResolver;
this.gradleInspectorExtractor = gradleInspectorExtractor;
this.gradleInspectorOptions = gradleInspectorOptions;
this.proxyInfo = proxyInfo;
}

@Override
Expand Down Expand Up @@ -96,6 +99,6 @@ public DetectableResult extractable() throws DetectableException {
@Override
public Extraction extract(final ExtractionEnvironment extractionEnvironment) {
String gradleCommand = gradleInspectorOptions.getGradleBuildCommand().orElse(""); // TODO: Nullable.
return gradleInspectorExtractor.extract(environment.getDirectory(), gradleExe, gradleCommand, gradleInspectorOptions.getproxyInfo(), gradleInspector, extractionEnvironment.getOutputDirectory());
return gradleInspectorExtractor.extract(environment.getDirectory(), gradleExe, gradleCommand, proxyInfo, gradleInspector, extractionEnvironment.getOutputDirectory());
}
}
Expand Up @@ -194,6 +194,7 @@
import com.synopsys.integration.detectable.detectables.yarn.YarnLockExtractor;
import com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser;
import com.synopsys.integration.detectable.detectables.yarn.parse.YarnTransformer;
import com.synopsys.integration.rest.proxy.ProxyInfo;

/*
Entry point for creating detectables using most
Expand Down Expand Up @@ -279,8 +280,10 @@ public GoGradleDetectable createGoGradleDetectable(final DetectableEnvironment e
return new GoGradleDetectable(environment, fileFinder, goGradleExtractor());
}

public GradleDetectable createGradleDetectable(final DetectableEnvironment environment, final GradleInspectorOptions gradleInspectorOptions, final GradleInspectorResolver gradleInspectorResolver, final GradleResolver gradleResolver) {
return new GradleDetectable(environment, fileFinder, gradleResolver, gradleInspectorResolver, gradleInspectorExtractor(), gradleInspectorOptions);
public GradleDetectable createGradleDetectable(final DetectableEnvironment environment, final GradleInspectorOptions gradleInspectorOptions, final GradleInspectorResolver gradleInspectorResolver, final GradleResolver gradleResolver,
final
ProxyInfo proxyInfo) {
return new GradleDetectable(environment, fileFinder, gradleResolver, gradleInspectorResolver, gradleInspectorExtractor(), gradleInspectorOptions, proxyInfo);
}

public GradleParseDetectable createGradleParseDetectable(final DetectableEnvironment environment) {
Expand Down Expand Up @@ -339,7 +342,8 @@ public PipenvDetectable createPipenvDetectable(final DetectableEnvironment envir
return new PipenvDetectable(environment, pipenvDetectableOptions, fileFinder, pythonResolver, pipenvResolver, pipenvExtractor());
}

public PipInspectorDetectable createPipInspectorDetectable(final DetectableEnvironment environment, final PipInspectorDetectableOptions pipInspectorDetectableOptions, final PipInspectorResolver pipInspectorResolver, final PythonResolver pythonResolver,
public PipInspectorDetectable createPipInspectorDetectable(final DetectableEnvironment environment, final PipInspectorDetectableOptions pipInspectorDetectableOptions, final PipInspectorResolver pipInspectorResolver,
final PythonResolver pythonResolver,
final PipResolver pipResolver) {
return new PipInspectorDetectable(environment, fileFinder, pythonResolver, pipResolver, pipInspectorResolver, pipInspectorExtractor(), pipInspectorDetectableOptions);
}
Expand Down
Expand Up @@ -35,6 +35,7 @@
import com.synopsys.integration.detectable.detectables.gradle.inspection.GradleInspectorOptions;
import com.synopsys.integration.detectable.util.MockDetectableEnvironment;
import com.synopsys.integration.detectable.util.MockFileFinder;
import com.synopsys.integration.rest.proxy.ProxyInfo;

public class GradleInspectorDetectableTest {
@Test
Expand All @@ -44,11 +45,12 @@ public void testApplicable() {
final GradleInspectorResolver gradleInspectorResolver = null;
final GradleInspectorExtractor gradleInspectorExtractor = null;
final GradleInspectorOptions gradleInspectorOptions = null;
final ProxyInfo proxyInfo = null;

final DetectableEnvironment environment = MockDetectableEnvironment.empty();
final FileFinder fileFinder = MockFileFinder.withFileNamed("build.gradle");

final GradleDetectable detectable = new GradleDetectable(environment, fileFinder, gradleResolver, gradleInspectorResolver, gradleInspectorExtractor, gradleInspectorOptions);
final GradleDetectable detectable = new GradleDetectable(environment, fileFinder, gradleResolver, gradleInspectorResolver, gradleInspectorExtractor, gradleInspectorOptions, proxyInfo);

assertTrue(detectable.applicable().getPassed());
}
Expand Down
Expand Up @@ -232,7 +232,8 @@ public DetectableFactory detectableFactory() {

@Bean()
public DetectDetectableFactory detectDetectableFactory() {
return new DetectDetectableFactory(detectableFactory(), detectableOptionFactory, detectExecutableResolver(), dockerInspectorResolver(), gradleInspectorResolver(), nugetInspectorResolver(), pipInspectorResolver());
return new DetectDetectableFactory(detectableFactory(), detectableOptionFactory, detectExecutableResolver(), dockerInspectorResolver(), gradleInspectorResolver(), nugetInspectorResolver(), pipInspectorResolver(),
detectConfigurationFactory.createConnectionDetails());
}

//#endregion Detectables
Expand Down
Empty file.
Expand Up @@ -48,8 +48,6 @@ import com.synopsys.integration.detectable.detectables.pip.PipenvDetectableOptio
import com.synopsys.integration.detectable.detectables.rubygems.gemspec.GemspecParseDetectableOptions
import com.synopsys.integration.detectable.detectables.sbt.SbtResolutionCacheDetectableOptions
import com.synopsys.integration.detectable.detectables.yarn.YarnLockOptions
import com.synopsys.integration.rest.credentials.CredentialsBuilder
import com.synopsys.integration.rest.proxy.ProxyInfoBuilder
import org.apache.commons.lang3.StringUtils
import org.slf4j.LoggerFactory
import java.util.*
Expand Down Expand Up @@ -119,26 +117,13 @@ class DetectableOptionFactory(private val detectConfiguration: PropertyConfigura
customRepository = configuredGradleInspectorRepositoryUrl
}

//Get proxy information
val proxyHost = detectConfiguration.getValue(DetectProperties.BLACKDUCK_PROXY_HOST)
val proxyPort = detectConfiguration.getValue(DetectProperties.BLACKDUCK_PROXY_PORT)
val proxyUsername = detectConfiguration.getValue(DetectProperties.BLACKDUCK_PROXY_USERNAME)
val proxyPassword = detectConfiguration.getValue(DetectProperties.BLACKDUCK_PROXY_PASSWORD)
val proxyCredentials = CredentialsBuilder()
proxyCredentials.setUsernameAndPassword(proxyUsername.get(), proxyPassword.get())
val proxyNtmlDomain = detectConfiguration.getValue(DetectProperties.BLACKDUCK_PROXY_NTLM_DOMAIN)
val proxyNtmlWorkspace = detectConfiguration.getValue(DetectProperties.BLACKDUCK_PROXY_NTLM_WORKSTATION)
val proxyInfo = ProxyInfoBuilder()
proxyInfo.setHost(proxyHost.get())
proxyInfo.setPort(proxyPort.get().toInt())
proxyInfo.setCredentials(proxyCredentials.build())
proxyInfo.setNtlmDomain(proxyNtmlDomain.get())
proxyInfo.setNtlmWorkstation(proxyNtmlWorkspace.get())
val detectConfigurationFactory = DetectConfigurationFactory(detectConfiguration, pathResolver)
val proxyInfo = detectConfigurationFactory.createBlackDuckProxyInfo()

val onlineInspectorVersion = detectConfiguration.getValue(DetectProperties.DETECT_GRADLE_INSPECTOR_VERSION).orElse(null)
val scriptOptions = GradleInspectorScriptOptions(excludedProjectNames, includedProjectNames, excludedConfigurationNames, includedConfigurationNames, customRepository, onlineInspectorVersion)
val gradleBuildCommand = detectConfiguration.getValue(DetectProperties.DETECT_GRADLE_BUILD_COMMAND).orElse(null)
return GradleInspectorOptions(gradleBuildCommand, scriptOptions, proxyInfo.build())
return GradleInspectorOptions(gradleBuildCommand, scriptOptions, proxyInfo)
}

fun createMavenCliOptions(): MavenCliExtractorOptions {
Expand Down
Expand Up @@ -265,7 +265,7 @@ private void printAppropriateHelp(final List<Property> properties, final DetectA
private void printHelpJsonDocument(final List<Property> properties, final DetectInfo detectInfo, final Gson gson) {
final DetectorRuleFactory ruleFactory = new DetectorRuleFactory();
// TODO: Is there a better way to build a fake set of rules?
final DetectDetectableFactory mockFactory = new DetectDetectableFactory(null, null, null, null, null, null, null);
final DetectDetectableFactory mockFactory = new DetectDetectableFactory(null, null, null, null, null, null, null, null);
final DetectorRuleSet build = ruleFactory.createRules(mockFactory, false);
final DetectorRuleSet buildless = ruleFactory.createRules(mockFactory, true);
final List<HelpJsonDetector> buildDetectors = build.getOrderedDetectorRules().stream().map(detectorRule -> convertDetectorRule(detectorRule, build)).collect(Collectors.toList());
Expand Down
Expand Up @@ -22,6 +22,7 @@
*/
package com.synopsys.integration.detect.tool.detector.impl;

import com.synopsys.integration.detect.configuration.ConnectionDetails;
import com.synopsys.integration.detect.configuration.DetectableOptionFactory;
import com.synopsys.integration.detectable.DetectableEnvironment;
import com.synopsys.integration.detectable.detectable.inspector.GradleInspectorResolver;
Expand Down Expand Up @@ -75,17 +76,19 @@ public class DetectDetectableFactory {
private final GradleInspectorResolver gradleInspectorResolver;
private final NugetInspectorResolver nugetInspectorResolver;
private final PipInspectorResolver pipInspectorResolver;
private final ConnectionDetails connectionDetails;

public DetectDetectableFactory(final DetectableFactory detectableFactory, final DetectableOptionFactory detectableOptionFactory, final DetectExecutableResolver detectExecutableResolver,
final DockerInspectorResolver dockerInspectorResolver, final GradleInspectorResolver gradleInspectorResolver, final NugetInspectorResolver nugetInspectorResolver,
final PipInspectorResolver pipInspectorResolver) {
final PipInspectorResolver pipInspectorResolver, final ConnectionDetails connectionDetails) {
this.detectableFactory = detectableFactory;
this.detectableOptionFactory = detectableOptionFactory;
this.detectExecutableResolver = detectExecutableResolver;
this.dockerInspectorResolver = dockerInspectorResolver;
this.gradleInspectorResolver = gradleInspectorResolver;
this.nugetInspectorResolver = nugetInspectorResolver;
this.pipInspectorResolver = pipInspectorResolver;
this.connectionDetails = connectionDetails;
}

public DockerDetectable createDockerDetectable(final DetectableEnvironment environment) {
Expand Down Expand Up @@ -149,7 +152,7 @@ public GoGradleDetectable createGoGradleDetectable(final DetectableEnvironment e
}

public GradleDetectable createGradleDetectable(final DetectableEnvironment environment) {
return detectableFactory.createGradleDetectable(environment, detectableOptionFactory.createGradleInspectorOptions(), gradleInspectorResolver, detectExecutableResolver);
return detectableFactory.createGradleDetectable(environment, detectableOptionFactory.createGradleInspectorOptions(), gradleInspectorResolver, detectExecutableResolver, connectionDetails.getProxyInformation());
}

public GradleParseDetectable createGradleParseDetectable(final DetectableEnvironment environment) {
Expand Down

0 comments on commit 55a940d

Please sign in to comment.