-
Notifications
You must be signed in to change notification settings - Fork 70
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
+334
−90
Merged
DotNet 3 #176
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a8d1717
feat(nuget): Begin implementing support for dotnet 3.1 runtime
8bf0ca5
feat(nuget): Add semantic version parsing for dotnet runtimes and log…
71e8082
feat(nuget): Make version parsing more generic
54d35c2
Add artifactory constants for dotnet3
971dcc6
feat(nuget): Create additional abstraction for redundant nuget code a…
e7d2ae7
Merge branch 'master' into gk_support_dotnet_3
4b58ca7
fix: resolve sonar code smells
fc0d762
refactor(nuget): Split dotnet runtime finding and runtime verifying i…
9284bef
fix: Resolve several issues discovered in code review
71449bc
fix: Replace regex functionality with java code
4bb964f
refactor: Replace POC of dotnet runtime regex alternative with less v…
b2c90ba
refactor: Clean up dotnet runtime parsing logic
fe6b978
Merge branch 'gk_support_dotnet_3_no_regex' into gk_support_dotnet_3
63f520d
Merge branch 'master' into gk_support_dotnet_3
fcd5c3f
refactor: Make method name plural
5cde737
chore: Add copyright header to new files
3bf080b
fix: Add finals to local variables based on project preference
f50c14e
Merge branch 'master' into gk_support_dotnet_3
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,12 +25,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; | ||||||||||||
|
@@ -50,20 +52,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) { | ||||||||||||
public LocatorNugetInspectorResolver(DetectExecutableResolver executableResolver, ExecutableRunner executableRunner, DetectInfo detectInfo, | ||||||||||||
FileFinder fileFinder, String nugetInspectorName, List<String> packagesRepoUrl, NugetInspectorLocator nugetInspectorLocator, | ||||||||||||
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 | ||||||||||||
|
@@ -75,14 +80,14 @@ public NugetInspector resolveNugetInspector() throws DetectableException { | |||||||||||
} | ||||||||||||
|
||||||||||||
return resolvedNugetInspector; | ||||||||||||
} catch (final Exception e) { | ||||||||||||
} catch (Exception e) { | ||||||||||||
throw new DetectableException(e); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
private NugetInspector install() throws IntegrationException { | ||||||||||||
//dotnet | ||||||||||||
final File dotnetExecutable = executableResolver.resolveDotNet(); | ||||||||||||
File dotnetExecutable = executableResolver.resolveDotNet(); | ||||||||||||
|
||||||||||||
boolean useDotnet = true; | ||||||||||||
if (shouldForceExeInspector(detectInfo)) { | ||||||||||||
|
@@ -97,61 +102,62 @@ private NugetInspector install() throws IntegrationException { | |||||||||||
} | ||||||||||||
|
||||||||||||
if (useDotnet) { | ||||||||||||
final File dotnetFolder = nugetInspectorLocator.locateDotnetInspector(); | ||||||||||||
return findDotnetCoreInspector(dotnetFolder, dotnetExecutable); | ||||||||||||
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(); | ||||||||||||
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(File nupkgFolder, File dotnetExecutable, String dotnetInspectorName) throws DetectableException { | ||||||||||||
Function<String, NugetInspector> constructor = (String exePath) -> new DotNetCoreNugetInspector(dotnetExecutable, exePath, executableRunner); | ||||||||||||
return findInspector(nupkgFolder, dotnetInspectorName, constructor); | ||||||||||||
} | ||||||||||||
|
||||||||||||
//original inspector | ||||||||||||
private NugetInspector findExeInspector(File nupkgFolder) throws DetectableException { | ||||||||||||
String exeName = nugetInspectorName + ".exe"; | ||||||||||||
Function<String, NugetInspector> constructor = (String exePath) -> new ExeNugetInspector(executableRunner, exePath); | ||||||||||||
return findInspector(nupkgFolder, exeName, constructor); | ||||||||||||
} | ||||||||||||
|
||||||||||||
private ExeNugetInspector findExeInspector(final File nupkgFolder) throws DetectableException { | ||||||||||||
//original inspector | ||||||||||||
final String exeName = nugetInspectorName + ".exe"; | ||||||||||||
logger.debug("Searching for: " + exeName); | ||||||||||||
final File toolsFolder = new File(nupkgFolder, "tools"); | ||||||||||||
private NugetInspector findInspector(File nupkgFolder, String inspectorName, Function<String, NugetInspector> inspectorInitializer) throws DetectableException { | ||||||||||||
logger.debug("Searching for: " + inspectorName); | ||||||||||||
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); | ||||||||||||
Optional<File> foundExecutable = fileFinder.findFiles(toolsFolder, inspectorName, 3).stream().findFirst(); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need the if/else if we do the filtering in the Stream. |
||||||||||||
if (foundExecutable.isPresent() && foundExecutable.get().exists()) { | ||||||||||||
String inspectorExecutable = foundExecutable.get().getAbsolutePath(); | ||||||||||||
logger.debug("Found nuget inspector: {}", inspectorExecutable); | ||||||||||||
return inspectorInitializer.apply(inspectorExecutable); | ||||||||||||
} else { | ||||||||||||
throw new DetectableException("Unable to find nuget inspector named '" + exeName + "' in " + toolsFolder.getAbsolutePath()); | ||||||||||||
throw new DetectableException(String.format("Unable to find nuget inspector, looking for %s in %s", inspectorName, toolsFolder.toString())); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
private boolean isWindows(final DetectInfo detectInfo) { | ||||||||||||
private boolean isWindows(DetectInfo detectInfo) { | ||||||||||||
return detectInfo.getCurrentOs() == OperatingSystemType.WINDOWS; | ||||||||||||
} | ||||||||||||
|
||||||||||||
private boolean isNotWindows(final DetectInfo detectInfo) { | ||||||||||||
private boolean isNotWindows(DetectInfo detectInfo) { | ||||||||||||
return !isWindows(detectInfo); | ||||||||||||
} | ||||||||||||
|
||||||||||||
private boolean shouldForceExeInspector(final DetectInfo detectInfo) { | ||||||||||||
private boolean shouldForceExeInspector(DetectInfo detectInfo) { | ||||||||||||
if (isNotWindows(detectInfo)) { | ||||||||||||
return false; | ||||||||||||
} | ||||||||||||
|
||||||||||||
//if customers have overridden the repo url's and include a v2 api, we must use the old nuget inspector (exe inspector) until 5.0.0 of detect. | ||||||||||||
//TODO: Remove in 7.0.0 | ||||||||||||
for (final String source : packagesRepoUrl) { | ||||||||||||
for (String source : packagesRepoUrl) { | ||||||||||||
if (source.contains("v2")) { | ||||||||||||
logger.warn("You are using Version 2 of the Nuget Api. Please update to version 3. Support for 2 is deprecated."); | ||||||||||||
return true; | ||||||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in love with removing all the finals, but since we don't have an official rule on it, it's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My save actions are configured based on the Engineer Onboarding on Confluence, but if you guys have a different preference in Detect, I can update the settings for the project accordingly. I assumed the finals were just left over from when we still had that convention mandated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you could add them back for now that would be great.