Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DotNet 3 #176

Merged
merged 18 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
public class NugetInspectorArguments {
private static final Logger logger = LoggerFactory.getLogger(NugetInspectorArguments.class);

//At the time of righting, both inspectors (exe and dotnet) use the same arguments so a shared static method is provided.
//At the time of writing, both inspectors (exe and dotnet) use the same arguments so a shared static method is provided.
//If they diverge the options object protects the argument conversion so each inspector can convert as they see fit.
public static List<String> fromInspectorOptions(final NugetInspectorOptions nugetInspectorOptions, final File sourcePath, final File outputDirectory) throws IOException {
final List<String> options = new ArrayList<>(Arrays.asList(
public static List<String> fromInspectorOptions(NugetInspectorOptions nugetInspectorOptions, File sourcePath, File outputDirectory) throws IOException {
List<String> options = new ArrayList<>(Arrays.asList(
"--target_path=" + sourcePath.getCanonicalPath(),
"--output_directory=" + outputDirectory.getCanonicalPath(),
"--ignore_failure=" + nugetInspectorOptions.isIgnoreFailures()));
Expand All @@ -50,9 +50,9 @@ public static List<String> fromInspectorOptions(final NugetInspectorOptions nuge
nugetInspectorOptions.getIncludedModules()
.ifPresent(arg -> options.add("--included_modules=" + arg));

final List<String> nugetPackagesRepo = nugetInspectorOptions.getPackagesRepoUrl();
List<String> nugetPackagesRepo = nugetInspectorOptions.getPackagesRepoUrl();
if (nugetPackagesRepo != null && nugetPackagesRepo.size() > 0) {
final String packagesRepos = String.join(",", nugetPackagesRepo);
String packagesRepos = String.join(",", nugetPackagesRepo);
options.add("--packages_repo_url=" + packagesRepos);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
import com.synopsys.integration.detect.tool.detector.inspectors.nuget.NugetInspectorLocator;
import com.synopsys.integration.detect.tool.detector.inspectors.nuget.NugetLocatorOptions;
import com.synopsys.integration.detect.tool.detector.inspectors.nuget.OnlineNugetInspectorLocator;
import com.synopsys.integration.detect.tool.detector.inspectors.nuget.runtime.DotNetRuntimeFinder;
import com.synopsys.integration.detect.tool.detector.inspectors.nuget.runtime.DotNetRuntimeManager;
import com.synopsys.integration.detect.tool.detector.inspectors.nuget.runtime.DotNetRuntimeParser;
import com.synopsys.integration.detect.tool.signaturescanner.BlackDuckSignatureScanner;
import com.synopsys.integration.detect.tool.signaturescanner.BlackDuckSignatureScannerOptions;
import com.synopsys.integration.detect.workflow.ArtifactResolver;
Expand Down Expand Up @@ -218,7 +221,11 @@ public NugetInspectorResolver nugetInspectorResolver() {
final NugetInspectorInstaller installer = new NugetInspectorInstaller(artifactResolver());
locator = new OnlineNugetInspectorLocator(installer, directoryManager, installerOptions.getNugetInspectorVersion().orElse(null));
}
return new LocatorNugetInspectorResolver(detectExecutableResolver(), executableRunner(), detectInfo, fullFileFinder(), installerOptions.getNugetInspectorName(), installerOptions.getPackagesRepoUrl(), locator);

final ExecutableRunner executableRunner = executableRunner();
final DotNetRuntimeFinder runtimeFinder = new DotNetRuntimeFinder(executableRunner, new File("."));
final DotNetRuntimeManager dotNetRuntimeManager = new DotNetRuntimeManager(runtimeFinder, new DotNetRuntimeParser());
return new LocatorNugetInspectorResolver(detectExecutableResolver(), executableRunner, detectInfo, fullFileFinder(), installerOptions.getNugetInspectorName(), installerOptions.getPackagesRepoUrl(), locator, dotNetRuntimeManager);
}

@Bean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.synopsys.integration.rest.proxy.ProxyInfo;

public class ConnectionDetails {
private final ProxyInfo proxyInformation; // Not nuzll because of NO_PROXY_INFO value.
private final ProxyInfo proxyInformation; // Not null because of NO_PROXY_INFO value.
private final List<Pattern> ignoredProxyHostPatterns;
private final Long timeout;
private final Boolean alwaysTrust;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,39 @@
package com.synopsys.integration.detect.tool.detector.inspectors.nuget;

import java.io.File;
import java.util.Optional;

import com.synopsys.integration.detect.workflow.airgap.AirGapInspectorPaths;
import com.synopsys.integration.detectable.detectable.exception.DetectableException;

public class AirgapNugetInspectorLocator implements NugetInspectorLocator {
public static final String INSPECTOR_DIR_DOTNET3 = "nuget_dotnet3";
public static final String INSPECTOR_DIR_DOTNET = "nuget_dotnet";
public static final String INSPECTOR_DIR_CLASSIC = "nuget_classic";

private final AirGapInspectorPaths airGapInspectorPaths;

public AirgapNugetInspectorLocator(final AirGapInspectorPaths airGapInspectorPaths) {
this.airGapInspectorPaths = airGapInspectorPaths;
}

@Override
public File locateExeInspector() {
final Optional<File> nugetAirGapPath = airGapInspectorPaths.getNugetInspectorAirGapFile();
return new File(nugetAirGapPath.get(), "nuget_classic"); // TODO: Why is there no ifPresent() check?
public File locateDotnet3Inspector() throws DetectableException {
return locateInspector(INSPECTOR_DIR_DOTNET3);
}

@Override
public File locateDotnetInspector() throws DetectableException {
return locateInspector(INSPECTOR_DIR_DOTNET);
}

@Override
public File locateDotnetInspector() {
final Optional<File> nugetAirGapPath = airGapInspectorPaths.getNugetInspectorAirGapFile();
return new File(nugetAirGapPath.get(), "nuget_dotnet"); // TODO: Why is there no ifPresent() check?
public File locateExeInspector() throws DetectableException {
return locateInspector(INSPECTOR_DIR_CLASSIC);
}

private File locateInspector(final String childName) throws DetectableException {
return airGapInspectorPaths.getNugetInspectorAirGapFile()
.map(nugetAirGapPath -> new File(nugetAirGapPath, childName))
.orElseThrow(() -> new DetectableException("Could not get the nuget air gap path"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@

import java.io.File;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.synopsys.integration.detect.DetectInfo;
import com.synopsys.integration.detect.tool.detector.impl.DetectExecutableResolver;
import com.synopsys.integration.detect.tool.detector.inspectors.nuget.runtime.DotNetRuntimeManager;
import com.synopsys.integration.detect.type.OperatingSystemType;
import com.synopsys.integration.detectable.detectable.exception.DetectableException;
import com.synopsys.integration.detectable.detectable.executable.ExecutableRunner;
Expand All @@ -50,20 +51,23 @@ public class LocatorNugetInspectorResolver implements NugetInspectorResolver {
private final FileFinder fileFinder;
private final String nugetInspectorName;
private final List<String> packagesRepoUrl;
private final NugetInspectorLocator nugetInspectorLocator;
private final DotNetRuntimeManager dotNetRuntimeManager;

private boolean hasResolvedInspector;
private NugetInspector resolvedNugetInspector;
private final NugetInspectorLocator nugetInspectorLocator;

public LocatorNugetInspectorResolver(final DetectExecutableResolver executableResolver, final ExecutableRunner executableRunner, final DetectInfo detectInfo,
final FileFinder fileFinder, final String nugetInspectorName, final List<String> packagesRepoUrl, final NugetInspectorLocator nugetInspectorLocator) {
final FileFinder fileFinder, final String nugetInspectorName, final List<String> packagesRepoUrl, final NugetInspectorLocator nugetInspectorLocator,
final DotNetRuntimeManager dotNetRuntimeManager) {
this.executableResolver = executableResolver;
this.executableRunner = executableRunner;
this.detectInfo = detectInfo;
this.fileFinder = fileFinder;
this.nugetInspectorName = nugetInspectorName;
this.packagesRepoUrl = packagesRepoUrl;
this.nugetInspectorLocator = nugetInspectorLocator;
this.dotNetRuntimeManager = dotNetRuntimeManager;
}

@Override
Expand Down Expand Up @@ -97,43 +101,44 @@ private NugetInspector install() throws IntegrationException {
}

if (useDotnet) {
final File dotnetFolder = nugetInspectorLocator.locateDotnetInspector();
return findDotnetCoreInspector(dotnetFolder, dotnetExecutable);
final File dotnetFolder;
if (dotNetRuntimeManager.isRuntimeAvailable(3, 1)) {
dotnetFolder = nugetInspectorLocator.locateDotnet3Inspector();
return findDotnetCoreInspector(dotnetFolder, dotnetExecutable, "NugetDotnet3Inspector.dll");
} else {
dotnetFolder = nugetInspectorLocator.locateDotnetInspector();
return findDotnetCoreInspector(dotnetFolder, dotnetExecutable, "BlackduckNugetInspector.dll");
}
} else {
final File classicFolder = nugetInspectorLocator.locateExeInspector();
return findExeInspector(classicFolder);
}
}

private DotNetCoreNugetInspector findDotnetCoreInspector(final File nupkgFolder, final File dotnetExecutable) throws DetectableException {
//new inspector
final String dotnetInspectorName = "BlackduckNugetInspector.dll";
logger.debug("Searching for: " + dotnetInspectorName);
final File toolsFolder = new File(nupkgFolder, "tools");
final Optional<File> foundExe = fileFinder.findFiles(toolsFolder, dotnetInspectorName, 3).stream().findFirst();
if (foundExe.isPresent() && foundExe.get().exists()) {
final String inspectorExe = foundExe.get().getAbsolutePath();
logger.debug("Found nuget inspector: " + inspectorExe);
return new DotNetCoreNugetInspector(dotnetExecutable, inspectorExe, executableRunner);
} else {
throw new DetectableException("Unable to find nuget inspector, looking for " + dotnetInspectorName + " in " + toolsFolder.toString());
}
private NugetInspector findDotnetCoreInspector(final File nupkgFolder, final File dotnetExecutable, final String dotnetInspectorName) throws DetectableException {
final Function<String, NugetInspector> constructor = (String exePath) -> new DotNetCoreNugetInspector(dotnetExecutable, exePath, executableRunner);
return findInspector(nupkgFolder, dotnetInspectorName, constructor);
}

private ExeNugetInspector findExeInspector(final File nupkgFolder) throws DetectableException {
//original inspector
//original inspector
private NugetInspector findExeInspector(final File nupkgFolder) throws DetectableException {
final String exeName = nugetInspectorName + ".exe";
logger.debug("Searching for: " + exeName);
final Function<String, NugetInspector> constructor = (String exePath) -> new ExeNugetInspector(executableRunner, exePath);
return findInspector(nupkgFolder, exeName, constructor);
}

private NugetInspector findInspector(final File nupkgFolder, final String inspectorName, final Function<String, NugetInspector> inspectorInitializer) throws DetectableException {
logger.debug("Searching for: " + inspectorName);
final File toolsFolder = new File(nupkgFolder, "tools");
logger.debug("Searching in: " + toolsFolder.getAbsolutePath());
final Optional<File> foundExe = fileFinder.findFiles(toolsFolder, exeName, 3).stream().findFirst();
if (foundExe.isPresent() && foundExe.get().exists()) {
final String inspectorExe = foundExe.get().getAbsolutePath();
logger.debug("Found nuget inspector: " + inspectorExe);
return new ExeNugetInspector(executableRunner, inspectorExe);
} else {
throw new DetectableException("Unable to find nuget inspector named '" + exeName + "' in " + toolsFolder.getAbsolutePath());
}
final File foundExecutable = fileFinder.findFiles(toolsFolder, inspectorName, 3)
.stream()
.findFirst()
.filter(File::exists)
.orElseThrow(() -> new DetectableException(String.format("Unable to find nuget inspector, looking for %s in %s", inspectorName, toolsFolder.toString())));
final String inspectorExecutable = foundExecutable.getAbsolutePath();
logger.debug("Found nuget inspector: {}", inspectorExecutable);
return inspectorInitializer.apply(inspectorExecutable);
}

private boolean isWindows(final DetectInfo detectInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Optional;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.synopsys.integration.detect.exception.DetectUserFriendlyException;
import com.synopsys.integration.detect.util.DetectZipUtil;
import com.synopsys.integration.detect.workflow.ArtifactResolver;
import com.synopsys.integration.detect.workflow.ArtifactoryConstants;
Expand All @@ -46,31 +46,31 @@ public NugetInspectorInstaller(final ArtifactResolver artifactResolver) {
this.artifactResolver = artifactResolver;
}

public File installDotNet(final File destination, final Optional<String> overrideVersion) throws DetectableException {
try {
logger.debug("Will attempt to resolve the dotnet inspector version.");
final String source = artifactResolver.resolveArtifactLocation(ArtifactoryConstants.ARTIFACTORY_URL, ArtifactoryConstants.NUGET_INSPECTOR_REPO, ArtifactoryConstants.NUGET_INSPECTOR_PROPERTY,
overrideVersion.orElse(""),
ArtifactoryConstants.NUGET_INSPECTOR_VERSION_OVERRIDE);
return installFromSource(destination, source);
} catch (final Exception e) {
throw new DetectableException("Unable to install the nuget inspector from Artifactory.", e);
}
public File installDotNet3(final File destination, @Nullable final String overrideVersion) throws DetectableException {
logger.debug("Will attempt to resolve the dotnet3 inspector version.");
return installInspector(destination, overrideVersion, ArtifactoryConstants.NUGET_DOTNET3_INSPECTOR_REPO, ArtifactoryConstants.NUGET_DOTNET3_INSPECTOR_PROPERTY, ArtifactoryConstants.NUGET_DOTNET3_INSPECTOR_VERSION_OVERRIDE);
}

public File installDotNet(final File destination, @Nullable final String overrideVersion) throws DetectableException {
logger.debug("Will attempt to resolve the dotnet inspector version.");
return installInspector(destination, overrideVersion, ArtifactoryConstants.NUGET_INSPECTOR_REPO, ArtifactoryConstants.NUGET_INSPECTOR_PROPERTY, ArtifactoryConstants.NUGET_INSPECTOR_VERSION_OVERRIDE);
}

public File installExeInspector(final File destination, @Nullable final String overrideVersion) throws DetectableException {
logger.debug("Will attempt to resolve the classic inspector version.");
return installInspector(destination, overrideVersion, ArtifactoryConstants.CLASSIC_NUGET_INSPECTOR_REPO, ArtifactoryConstants.CLASSIC_NUGET_INSPECTOR_PROPERTY, ArtifactoryConstants.CLASSIC_NUGET_INSPECTOR_VERSION_OVERRIDE);
}

public File installExeInspector(final File destination, final Optional<String> overrideVersion) throws DetectableException {
private File installInspector(final File destination, @Nullable final String overrideVersion, final String inspectorRepo, final String inspectorProperty, final String inspectorVersionOverride) throws DetectableException {
try {
logger.debug("Will attempt to resolve the classic inspector version.");
final String source = artifactResolver.resolveArtifactLocation(ArtifactoryConstants.ARTIFACTORY_URL, ArtifactoryConstants.CLASSIC_NUGET_INSPECTOR_REPO, ArtifactoryConstants.CLASSIC_NUGET_INSPECTOR_PROPERTY,
overrideVersion.orElse(""),
ArtifactoryConstants.CLASSIC_NUGET_INSPECTOR_VERSION_OVERRIDE);
final String source = artifactResolver.resolveArtifactLocation(ArtifactoryConstants.ARTIFACTORY_URL, inspectorRepo, inspectorProperty, StringUtils.defaultString(overrideVersion), inspectorVersionOverride);
return installFromSource(destination, source);
} catch (final Exception e) {
throw new DetectableException("Unable to install the nuget inspector from Artifactory.", e);
}
}

private File installFromSource(final File dest, final String source) throws IntegrationException, IOException, DetectUserFriendlyException {
private File installFromSource(final File dest, final String source) throws IntegrationException, IOException {
logger.debug("Resolved the nuget inspector url: " + source);
final String nupkgName = artifactResolver.parseFileName(source);
logger.debug("Parsed artifact name: " + nupkgName);
Expand All @@ -83,10 +83,9 @@ private File installFromSource(final File dest, final String source) throws Inte
logger.debug("Extracting nuget inspector.");
DetectZipUtil.unzip(nupkgFile, inspectorFolder, Charset.defaultCharset());
FileUtils.deleteQuietly(nupkgFile);
return inspectorFolder;
} else {
logger.debug("Inspector is already downloaded, folder exists.");
return inspectorFolder;
}
return inspectorFolder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.synopsys.integration.detectable.detectable.exception.DetectableException;

public interface NugetInspectorLocator {
File locateDotnet3Inspector() throws DetectableException;

File locateDotnetInspector() throws DetectableException;

File locateExeInspector() throws DetectableException;
Expand Down