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

Sonar cloud fixes for 9.5 #1077

Merged
merged 5 commits into from
Mar 21, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.*;
import java.util.regex.Pattern;

import com.synopsys.integration.detectable.detectables.projectinspector.ProjectInspectorParser;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -202,6 +201,10 @@ private void populateGraphDependencies(ExcludedIncludedWildcardFilter scopeFilte
dependencyParentStack.push(dependency);
}
}
addShadedDependenciesToGraph(dependency);
}

private void addShadedDependenciesToGraph(ScopedDependency dependency) {
if(!shadedDependenciesConverted.isEmpty() && shadedDependenciesConverted.containsKey(dependency.getExternalId())) {
for(Dependency childDependency: shadedDependenciesConverted.get(dependency.getExternalId())) {
currentGraph.addParentWithChild(dependency, childDependency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private DependencyGraph buildGraphForProject(
if (shouldInclude(entryName, entry.getVersion())) {
LazyId id = generateComponentDependencyId(entryName, entry.getVersion());
graphBuilder.setDependencyInfo(id, entryName, entry.getVersion(), generateComponentExternalId(entryName, entry.getVersion()));
ExternalIdDependencyGraphBuilder.LazyDependencyInfo parentInfo = graphBuilder.checkAndHandleMissingExternalId(lazyBuilderHandler, id);
LazyExternalIdDependencyGraphBuilder.LazyDependencyInfo parentInfo = graphBuilder.checkAndHandleMissingExternalId(lazyBuilderHandler, id);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependency parent = new Dependency(parentInfo.getName(), parentInfo.getVersion(), parentInfo.getExternalId(), null);
mutableDependencyGraph.addDirectDependency(parent);
collectYarnDependencies(lazyBuilderHandler, graphBuilder, mutableDependencyGraph, yarnLockResult, entry, resolvedEntryIdVersionMap, parent);
Expand All @@ -158,35 +158,43 @@ private void collectYarnDependencies(
) throws MissingExternalIdException {
for (YarnLockDependency dependency : entry.getDependencies()) {
if (!isWorkspace(yarnLockResult.getWorkspaceData(), dependency)) {
Map<String, String> idVersionMap = resolvedEntryIdVersionMap.get(dependency.getName());
String dependencyVersion;
if (idVersionMap != null) {
dependencyVersion = idVersionMap.get(dependency.getVersion());
if (dependencyVersion == null) {
if (idVersionMap.values().isEmpty()) {
logger.warn("Dependency {} with version definition {} not found in the Yarn map entries {}", dependency.getName(), dependency.getVersion(), idVersionMap.toString());
dependencyVersion = dependency.getVersion();
} else {
// 1. Choose first version.
dependencyVersion = (String) idVersionMap.values().toArray()[0];
}
// 2. Try to auto-resolve to one of the versions.
}
} else {
dependencyVersion = dependency.getVersion();
}
String dependencyVersion = getDependencyVersion(resolvedEntryIdVersionMap, dependency);
LazyId stringDependencyId = generateComponentDependencyId(dependency.getName(), dependencyVersion);
if (yarnDependencyTypeFilter.shouldInclude(YarnDependencyType.NON_PRODUCTION) || !dependency.isOptional()) {
graphBuilder.setDependencyInfo(stringDependencyId, dependency.getName(), dependencyVersion, generateComponentExternalId(dependency.getName(), dependencyVersion));
//graphBuilder.addChildWithParent(stringDependencyId, id);
LazyDependencyInfo childInfo = graphBuilder.checkAndHandleMissingExternalId(lazyBuilderHandler, stringDependencyId);
Dependency child = new Dependency(childInfo.getName(), childInfo.getVersion(), childInfo.getExternalId(), null);
mutableDependencyGraph.addChildWithParent(child, parent);
includeNonProductionOrOptionalIfNeeded(dependency, dependencyVersion, parent,lazyBuilderHandler, graphBuilder, mutableDependencyGraph, stringDependencyId);
}
}
}

private String getDependencyVersion(Map<String, Map<String, String>> resolvedEntryIdVersionMap, YarnLockDependency dependency) {
Map<String, String> idVersionMap = resolvedEntryIdVersionMap.get(dependency.getName());
String dependencyVersion;
if (idVersionMap != null) {
dependencyVersion = idVersionMap.get(dependency.getVersion());
if (dependencyVersion == null) {
if (idVersionMap.values().isEmpty()) {
logger.warn("Dependency {} with version definition {} not found in the Yarn map entries {}", dependency.getName(), dependency.getVersion(), idVersionMap.toString());
dependencyVersion = dependency.getVersion();
} else {
logger.trace("Excluding optional dependency: {}", stringDependencyId);
// 1. Choose first version.
dependencyVersion = (String) idVersionMap.values().toArray()[0];
}
// 2. Try to auto-resolve to one of the versions.
}
} else {
dependencyVersion = dependency.getVersion();
}
return dependencyVersion;
}

private void includeNonProductionOrOptionalIfNeeded(YarnLockDependency dependency, String dependencyVersion, Dependency parent, LazyBuilderMissingExternalIdHandler lazyBuilderHandler, ExternalIdDependencyGraphBuilder graphBuilder, BasicDependencyGraph mutableDependencyGraph, LazyId stringDependencyId) throws MissingExternalIdException {
if (yarnDependencyTypeFilter.shouldInclude(YarnDependencyType.NON_PRODUCTION) || !dependency.isOptional()) {
graphBuilder.setDependencyInfo(stringDependencyId, dependency.getName(), dependencyVersion, generateComponentExternalId(dependency.getName(), dependencyVersion));
LazyDependencyInfo childInfo = graphBuilder.checkAndHandleMissingExternalId(lazyBuilderHandler, stringDependencyId);
Dependency child = new Dependency(childInfo.getName(), childInfo.getVersion(), childInfo.getExternalId(), null);
mutableDependencyGraph.addChildWithParent(child, parent);

} else {
logger.trace("Excluding optional dependency: {}", stringDependencyId);
}
}

Expand Down