Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ target/
.idea/*
*.iml
.DS_Store
.gradle/
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class RuleEntryParams {
private final String analysisMode;
private final ArrayList<String> includedPaths;
private final boolean includeOpenSourceLibraries;
private final String mavenLocalRepoPath;
private final String mavenIndexPath;

public RuleEntryParams(final String commandId, final List<Object> arguments) {
@SuppressWarnings("unchecked")
Expand All @@ -27,11 +29,14 @@ public RuleEntryParams(final String commandId, final List<Object> arguments) {
this.projectName = (String) obj.get("project");
this.query = (String) obj.get("query");
this.location = Integer.parseInt((String) obj.get("location"));
this.annotationQuery = AnnotationQuery.fromMap(this.query, (Map<String, Object>) obj.get("annotationQuery"), location);
this.annotationQuery = AnnotationQuery.fromMap(this.query, (Map<String, Object>) obj.get("annotationQuery"),
location);
this.analysisMode = (String) obj.get("analysisMode");
this.includedPaths = (ArrayList<String>) obj.get("includedPaths");
Boolean includeOpenSourceLibs = (Boolean) obj.get("includeOpenSourceLibraries");
this.includeOpenSourceLibraries = (includeOpenSourceLibs != null) ? includeOpenSourceLibs : false;
this.mavenLocalRepoPath = (String) obj.get("mavenLocalRepo");
this.mavenIndexPath = (String) obj.get("mavenIndexPath");
}

public String getProjectName() {
Expand Down Expand Up @@ -61,4 +66,12 @@ public ArrayList<String> getIncludedPaths() {
public Boolean getIncludeOpenSourceLibraries() {
return includeOpenSourceLibraries;
}

public String getMavenLocalRepoPath() {
return mavenLocalRepoPath;
}

public String getMavenIndexPath() {
return mavenIndexPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import io.konveyor.tackle.core.internal.query.AnnotationQuery;
import io.konveyor.tackle.core.internal.util.OpenSourceFilteredSearchScope;
import io.konveyor.tackle.core.internal.util.OpenSourceLibraryExclusionManager;

public class SampleDelegateCommandHandler implements IDelegateCommandHandler {

Expand All @@ -37,19 +38,19 @@ public class SampleDelegateCommandHandler implements IDelegateCommandHandler {

private static final String FullAnalysisMode = "full";
private static final String sourceOnlyAnalysisMode = "source-only";


@Override
public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor progress) throws Exception {
switch (commandId) {
case COMMAND_ID:
return "Hello World";
case RULE_ENTRY_COMMAND_ID:
logInfo("Here we get the arguments for rule entry: "+arguments);
logInfo("Here we get the arguments for rule entry: " + arguments);
RuleEntryParams params = new RuleEntryParams(commandId, arguments);
return search(params.getProjectName(), params.getIncludedPaths(), params.getQuery(),
params.getAnnotationQuery(), params.getLocation(), params.getAnalysisMode(),
params.getIncludeOpenSourceLibraries(), progress);
params.getAnnotationQuery(), params.getLocation(), params.getAnalysisMode(),
params.getIncludeOpenSourceLibraries(), params.getMavenLocalRepoPath(),
params.getMavenIndexPath(), progress);
default:
throw new UnsupportedOperationException(format("Unsupported command '%s'!", commandId));
}
Expand All @@ -59,7 +60,7 @@ private static void waitForJavaSourceDownloads() {
JobHelpers.waitForInitializeJobs();
JobHelpers.waitForBuildJobs(JobHelpers.MAX_TIME_MILLIS);
JobHelpers.waitForDownloadSourcesJobs(JobHelpers.MAX_TIME_MILLIS);

}

// mapLocationToSearchPatternLocation will create the correct search pattern or throw an error if one can not be built.
Expand Down Expand Up @@ -189,7 +190,8 @@ private static SearchPattern getPatternSingleQuery(int location, String query) t
throw new Exception("unable to create search pattern");
}

private static List<SymbolInformation> search(String projectName, ArrayList<String> includedPaths, String query, AnnotationQuery annotationQuery, int location, String analsysisMode, boolean includeOpenSourceLibraries, IProgressMonitor monitor) throws Exception {
private static List<SymbolInformation> search(String projectName, ArrayList<String> includedPaths, String query, AnnotationQuery annotationQuery, int location, String analysisMode,
boolean includeOpenSourceLibraries, String mavenLocalRepoPath, String mavenIndexPath, IProgressMonitor monitor) throws Exception {
IJavaProject[] targetProjects;
IJavaProject project = ProjectUtils.getJavaProject(projectName);
if (project != null) {
Expand All @@ -202,7 +204,7 @@ private static List<SymbolInformation> search(String projectName, ArrayList<Stri

// For Partial results, we are going to filter out based on a list in the engine
int s = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS | IJavaSearchScope.APPLICATION_LIBRARIES;
if (analsysisMode.equals(sourceOnlyAnalysisMode)) {
if (analysisMode.equals(sourceOnlyAnalysisMode)) {
logInfo("KONVEYOR_LOG: source-only analysis mode only scoping to Sources");
s = IJavaSearchScope.SOURCES;
} else {
Expand Down Expand Up @@ -293,7 +295,8 @@ private static List<SymbolInformation> search(String projectName, ArrayList<Stri

// Use a filtered scope when open source libraries are not included
if (!includeOpenSourceLibraries) {
scope = new OpenSourceFilteredSearchScope(scope);
scope = new OpenSourceFilteredSearchScope(scope,
OpenSourceLibraryExclusionManager.getInstance(mavenLocalRepoPath, mavenIndexPath));
}
logInfo("scope: " + scope);

Expand All @@ -320,7 +323,7 @@ private static List<SymbolInformation> search(String projectName, ArrayList<Stri
try {
searchEngine.search(pattern, participents, scope, requestor, monitor);
} catch (Exception e) {
//TODO: handle exception
// TODO: handle exception
logInfo("KONVEYOR_LOG: unable to get search " + e.toString().replace("\n", " "));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logInfo;

import java.util.Arrays;

Expand All @@ -14,9 +15,9 @@ public class OpenSourceFilteredSearchScope implements IJavaSearchScope {
private final IJavaSearchScope scope;
private final OpenSourceLibraryExclusionManager exclusionManager;

public OpenSourceFilteredSearchScope(IJavaSearchScope scope) {
public OpenSourceFilteredSearchScope(IJavaSearchScope scope, OpenSourceLibraryExclusionManager instance) {
this.scope = scope;
this.exclusionManager = OpenSourceLibraryExclusionManager.getInstance();
this.exclusionManager = instance;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,53 @@ public class OpenSourceLibraryExclusionManager {

private final List<Pattern> exclusionPatterns = new ArrayList<>();
private final ConcurrentHashMap<String, Boolean> exclusionCache = new ConcurrentHashMap<>();
private final String mavenLocalRepoPath;
private final String mavenIndexPath;

private OpenSourceLibraryExclusionManager() {
private OpenSourceLibraryExclusionManager(String mavenLocalRepoPath, String mavenIndexPath) {
this.mavenLocalRepoPath = mavenLocalRepoPath;
this.mavenIndexPath = mavenIndexPath;
loadExclusionPatterns();
}

public static OpenSourceLibraryExclusionManager getInstance() {
public static OpenSourceLibraryExclusionManager getInstance(String mavenLocalRepoPath, String mavenIndexPath) {
if (instance == null) {
synchronized (OpenSourceLibraryExclusionManager.class) {
if (instance == null) {
instance = new OpenSourceLibraryExclusionManager();
instance = new OpenSourceLibraryExclusionManager(mavenLocalRepoPath, mavenIndexPath);
}
}
}
return instance;
}

private String normalizePath(String path) {
if (path == null) {
return "";
}
String normalized = path.replace('\\', '/');
normalized = normalized.replaceAll("^[A-Za-z]:/", "");
normalized = normalized.replace('/', '.').replace(':', '.');
normalized = normalized.replaceAll("^\\.*", ".");
return normalized;
}

private void loadExclusionPatterns() {
try (BufferedReader reader = new BufferedReader(new FileReader(MAVEN_INDEX_FILE, StandardCharsets.UTF_8))) {
String normalizedRepoPath = this.normalizePath(this.mavenLocalRepoPath);
String mavenIndexPath = MAVEN_INDEX_FILE;
if (this.mavenIndexPath != null) {
mavenIndexPath = this.mavenIndexPath;
}
logInfo("OpenSourceLibraryExclusionManager: using maven index path " + mavenIndexPath);
logInfo("OpenSourceLibraryExclusionManager: using base query pattern " + normalizedRepoPath + ".*");
try (BufferedReader reader = new BufferedReader(new FileReader(mavenIndexPath, StandardCharsets.UTF_8))) {
List<String> patterns = reader.lines()
.filter(line -> !line.trim().isEmpty())
.collect(Collectors.toList());

for (String patternStr : patterns) {
try {
String prefix = ".*";
String prefix = normalizedRepoPath + ".*";
exclusionPatterns.add(Pattern.compile(prefix + patternStr));
} catch (Exception e) {
logInfo("Invalid exclusion pattern: " + patternStr);
Expand Down
Loading