Skip to content
Open
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
@@ -1,4 +1,4 @@
package com.github.clementherve.intellijjavadependencyupdaterplugin.util;
package com.github.clementherve.intellijjavadependencyupdaterplugin.buildfile;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
Expand All @@ -12,7 +12,7 @@
import java.util.ArrayList;
import java.util.List;

public class FindBuildGradleFilesUtil {
public class BuildFileLocator {
public static List<VirtualFile> findBuildGradleFilesInCurrentProject(Project project) {
return ApplicationManager.getApplication().runReadAction((Computable<List<VirtualFile>>) () -> {
List<VirtualFile> files = new ArrayList<>();
Expand All @@ -22,13 +22,13 @@ public static List<VirtualFile> findBuildGradleFilesInCurrentProject(Project pro
VfsUtilCore.visitChildrenRecursively(baseDir, new VirtualFileVisitor<Void>() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
// Skip common directories
// Skip common big directories
if (file.isDirectory()) {
String name = file.getName();
return !name.startsWith(".") && !name.equals("build") && !name.equals("node_modules") && !name.equals("target");
}

if (SupportedFilesUtil.isSupportedFile(file.getName())) {
if (SupportedBuildFile.isSupportedFile(file.getName())) {
files.add(file);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.clementherve.intellijjavadependencyupdaterplugin.psi;
package com.github.clementherve.intellijjavadependencyupdaterplugin.buildfile;

import com.github.clementherve.intellijjavadependencyupdaterplugin.model.DependencyInfo;
import com.github.clementherve.intellijjavadependencyupdaterplugin.dependency.Dependency;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;

Expand All @@ -9,7 +9,7 @@
/**
* Interface for parsing dependency declarations from Gradle build files.
*/
public interface DependencyParser {
public interface BuildFileParser {

/**
* Parses all dependency declarations from a PSI file.
Expand All @@ -18,7 +18,7 @@ public interface DependencyParser {
* @return a list of dependency information objects
*/
@NotNull
List<DependencyInfo> parseDependencies(@NotNull PsiFile psiFile);
List<Dependency> parseDependencies(@NotNull PsiFile psiFile);

/**
* Checks if this parser can handle the given file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.github.clementherve.intellijjavadependencyupdaterplugin.psi;
package com.github.clementherve.intellijjavadependencyupdaterplugin.buildfile;

import com.github.clementherve.intellijjavadependencyupdaterplugin.buildfile.gradle.GradleBuildFileParser;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Factory for creating appropriate dependency parsers based on file type.
*/
public class DependencyParserFactory {
public class BuildFileParserFactory {

/**
* Gets the appropriate parser for the given file.
Expand All @@ -16,11 +17,11 @@ public class DependencyParserFactory {
* @return a parser instance, or null if no parser is available for this file type
*/
@Nullable
public static DependencyParser getParser(@NotNull PsiFile file) {
public static BuildFileParser getParser(@NotNull PsiFile file) {
String fileName = file.getName();

if ("build.gradle".equals(fileName)) {
return new GradlePsiParser();
return new GradleBuildFileParser();
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.clementherve.intellijjavadependencyupdaterplugin.util;
package com.github.clementherve.intellijjavadependencyupdaterplugin.buildfile;

public class SupportedFilesUtil {
public class SupportedBuildFile {
private static final String SUPPORTED_FILE = "build.gradle";

public static boolean isSupportedFile(String fileName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.github.clementherve.intellijjavadependencyupdaterplugin.buildfile.gradle;

import com.github.clementherve.intellijjavadependencyupdaterplugin.buildfile.BuildFileParser;
import com.github.clementherve.intellijjavadependencyupdaterplugin.buildfile.SupportedBuildFile;
import com.github.clementherve.intellijjavadependencyupdaterplugin.dependency.Dependency;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;

import java.util.ArrayList;
import java.util.List;

/**
* Parses dependency and plugin declarations from Groovy build.gradle files by walking every
* method call and delegating each to the dependency and plugin extractors.
*/
public class GradleBuildFileParser implements BuildFileParser {

private static final Logger LOGGER = Logger.getInstance(GradleBuildFileParser.class);

@Override
public boolean canParse(@NotNull PsiFile psiFile) {
return SupportedBuildFile.isSupportedFile(psiFile.getName());
}

@NotNull
@Override
public List<Dependency> parseDependencies(@NotNull PsiFile psiFile) {
List<Dependency> dependencies = new ArrayList<>();

for (GrMethodCall methodCall : PsiTreeUtil.findChildrenOfType(psiFile, GrMethodCall.class)) {
try {
Dependency dependency = GradleDependencyExtractor.extract(methodCall, psiFile);
if (dependency != null) {
dependencies.add(dependency);
}

Dependency plugin = GradlePluginExtractor.extract(methodCall);
if (plugin != null) {
dependencies.add(plugin);
}
} catch (ProcessCanceledException exception) {
// Rethrow - this is a control flow exception, not an error
throw exception;
} catch (Exception exception) {
LOGGER.debug("Failed to parse dependency from method call", exception);
}
}

return dependencies;
}
}
Loading