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

Scan all available roots when no configuration file can be found by JAS scanners #435

Merged
merged 6 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 2 additions & 4 deletions src/main/java/com/jfrog/ide/idea/scan/ScanManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@
import static com.jfrog.ide.common.utils.XrayConnectionUtils.createXrayClientBuilder;

public class ScanManager {
private final int SCAN_TIMEOUT_MINUTES = 60;
private final Project project;
private final ScannerFactory factory;
private final SourceCodeScannerManager sourceCodeScannerManager;
private Map<Integer, ScannerBase> scanners = Maps.newHashMap();
private ExecutorService executor;


private ScanManager(@NotNull Project project) {
this.project = project;
factory = new ScannerFactory(project);
Expand Down Expand Up @@ -97,8 +95,8 @@ public void startScan() {
scanner.asyncScanAndUpdateResults();
}
executor.shutdown();
if (!executor.awaitTermination(SCAN_TIMEOUT_MINUTES, TimeUnit.MINUTES)) {
logError(Logger.getInstance(), "Scan timeout of " + SCAN_TIMEOUT_MINUTES + " minutes elapsed. The scan is being canceled.", true);
if (!executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES)) {
Copy link
Member

Choose a reason for hiding this comment

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

I disagree with that approach. In a developer environment, it's better to end the scan after a few minutes. Plus, users don't get any feedback or indication about the ongoing scan during this prolonged period. But ultimately, it's up to you to decide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will remove the timeout, add more logging, and add progress bars to enhance the user experience as discussed on Zoom

logError(Logger.getInstance(), "Scan timeout elapsed. The scan is being canceled.", true);
}
// Cache tree only if no errors occurred during scan.
if (scanners.values().stream().anyMatch(ScannerBase::isScanErrorOccurred)) {
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/jfrog/ide/idea/scan/ScanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

/**
Expand All @@ -28,7 +26,7 @@ public class ScanUtils {
* @param project - the project
Or-Geva marked this conversation as resolved.
Show resolved Hide resolved
* @return local scan paths
*/
static Set<Path> createScanPaths(Map<Integer, ScannerBase> scannersMap, Project project) {
public static Set<Path> createScanPaths(Project project) {
final Set<Path> paths = Sets.newHashSet();
paths.add(com.jfrog.ide.idea.utils.Utils.getProjectBasePath(project));
for (Module module : ModuleManager.getInstance(project).getModules()) {
Expand All @@ -37,7 +35,6 @@ static Set<Path> createScanPaths(Map<Integer, ScannerBase> scannersMap, Project
paths.add(modulePath.toNioPath());
}
}
scannersMap.values().stream().map(ScannerBase::getProjectPaths).flatMap(Collection::stream).forEach(paths::add);
Logger.getInstance().debug("Scanning projects in the following paths: " + paths);
return paths;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/jfrog/ide/idea/scan/ScannerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -45,7 +46,8 @@ public Map<Integer, ScannerBase> refreshScanners(Map<Integer, ScannerBase> oldSc
Map<Integer, ScannerBase> scanners = Maps.newHashMap();
refreshMavenScanner(scanners, oldScanners, executor, scanLogic);
refreshPypiScanners(scanners, oldScanners, executor, scanLogic);
Set<Path> scanPaths = createScanPaths(oldScanners, project);
Set<Path> scanPaths = createScanPaths(project);
oldScanners.values().stream().map(ScannerBase::getProjectPaths).flatMap(Collection::stream).forEach(scanPaths::add);
refreshGenericScanners(scanners, oldScanners, scanPaths, executor, scanLogic);
return scanners;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import static com.jfrog.ide.idea.scan.SourceCodeScannerManager.convertToSkippedFolders;
import static com.jfrog.ide.idea.utils.Utils.getProjectBasePath;

@Getter
@NoArgsConstructor
Expand All @@ -22,15 +23,16 @@ public class JFrogApplicationsConfig {

public static JFrogApplicationsConfig createApplicationConfigWithDefaultModule(Project project) {
JFrogApplicationsConfig applicationsConfig = new JFrogApplicationsConfig();

ModuleConfig defualtModuleConfig = new ModuleConfig();
defualtModuleConfig.setSourceRoot(getProjectBasePath(project).toAbsolutePath().toString());
defualtModuleConfig.setExcludePatterns(convertToSkippedFolders(GlobalSettings.getInstance().getServerConfig().getExcludedPaths()));

Set<Path> paths = com.jfrog.ide.idea.scan.ScanUtils.createScanPaths(project);
Or-Geva marked this conversation as resolved.
Show resolved Hide resolved
applicationsConfig.modules = new ArrayList<>();
applicationsConfig.modules.add(defualtModuleConfig);

for (Path path : paths) {
Or-Geva marked this conversation as resolved.
Show resolved Hide resolved
ModuleConfig defualtModuleConfig = new ModuleConfig();
Or-Geva marked this conversation as resolved.
Show resolved Hide resolved
defualtModuleConfig.setSourceRoot(path.toString());
defualtModuleConfig.setExcludePatterns(convertToSkippedFolders(GlobalSettings.getInstance().getServerConfig().getExcludedPaths()));
applicationsConfig.modules.add(defualtModuleConfig);
}

return applicationsConfig;
}

}
Loading