Skip to content

Commit

Permalink
Scan all available roots when no configuration file can be found by J…
Browse files Browse the repository at this point in the history
…AS scanners (#435)
  • Loading branch information
Or-Geva authored Nov 14, 2023
1 parent 7ea0046 commit 6f6d898
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
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) {
ModuleConfig defaultModuleConfig = new ModuleConfig();
defaultModuleConfig.setSourceRoot(path.toString());
defaultModuleConfig.setExcludePatterns(convertToSkippedFolders(GlobalSettings.getInstance().getServerConfig().getExcludedPaths()));
applicationsConfig.modules.add(defaultModuleConfig);
}

return applicationsConfig;
}

}

0 comments on commit 6f6d898

Please sign in to comment.