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 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
13 changes: 5 additions & 8 deletions src/main/java/com/jfrog/ide/idea/scan/ScanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.jfrog.ide.common.utils.Utils;
import com.jfrog.ide.idea.log.Logger;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;

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

/**
Expand All @@ -22,22 +21,20 @@
public class ScanUtils {
/**
* This method gets a set of modules from IDEA, and searches for projects to be scanned.
* It appends the root path of each module it finds into a set.
*
* @param scannersMap - current scanners
* @param project - the project
* @param project - the project
* @return local scan paths
*/
static Set<Path> createScanPaths(Map<Integer, ScannerBase> scannersMap, Project project) {
final Set<Path> paths = Sets.newHashSet();
public static Set<Path> createScanPaths(Project project) {
Set<Path> paths = Sets.newHashSet();
paths.add(com.jfrog.ide.idea.utils.Utils.getProjectBasePath(project));
for (Module module : ModuleManager.getInstance(project).getModules()) {
VirtualFile modulePath = ProjectUtil.guessModuleDir(module);
if (modulePath != null) {
paths.add(modulePath.toNioPath());
}
}
scannersMap.values().stream().map(ScannerBase::getProjectPaths).flatMap(Collection::stream).forEach(paths::add);
paths = Utils.consolidatePaths(paths);
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 @@ -3,14 +3,16 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.intellij.openapi.project.Project;
import com.jfrog.ide.idea.configuration.GlobalSettings;
import com.jfrog.ide.idea.scan.ScanUtils;
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 +24,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 = ScanUtils.createScanPaths(project);
applicationsConfig.modules = new ArrayList<>();
applicationsConfig.modules.add(defualtModuleConfig);

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

return applicationsConfig;
}

}
Loading