This commit is contained in:
aboyko
2022-11-11 17:11:12 -05:00
2 changed files with 27 additions and 10 deletions

View File

@@ -11,6 +11,9 @@
package org.springframework.ide.vscode.commons.java;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Predicate;
import java.util.regex.Matcher;
@@ -171,4 +174,16 @@ public class SpringProjectUtil {
return true;
};
}
public static File getFile(IJavaProject project, String fileName) throws Exception {
Path projectPath = new File(project.getLocationUri()).toPath();
if (Files.isDirectory(projectPath, new LinkOption[] {LinkOption.NOFOLLOW_LINKS})) {
List<Path>results = Files.walk(projectPath).filter(Files::isRegularFile)
.filter(file -> file.toFile().getName().equals(fileName)).collect(Collectors.toList());
if (results != null && !results.isEmpty()) {
return results.get(0).toFile();
}
}
return null;
}
}

View File

@@ -22,8 +22,8 @@ import org.springframework.ide.vscode.commons.java.Version;
public abstract class BootDiagnosticProvider {
public static final String BOOT_VERSION_VALIDATION_CODE = "BOOT_VERSION_VALIDATION_CODE";;
public static final String BOOT_VERSION_VALIDATION_CODE = "BOOT_VERSION_VALIDATION_CODE";
private static final String[] BUILD_FILES = new String[] {"pom.xml", "build.gradle", "build.gradle.kts"};
/**
*
@@ -35,13 +35,16 @@ public abstract class BootDiagnosticProvider {
abstract SpringProjectDiagnostic getDiagnostic(IJavaProject javaProject, SpringDependencyInfo info, Generations generations) throws Exception;
protected URI getBuildFileUri(IJavaProject javaProject) throws Exception {
// TODO: add gradle support here
return getPomUri(javaProject);
}
private URI getPomUri(IJavaProject project) throws Exception {
return new URI(project.getLocationUri().toString() + "/pom.xml");
File file = null;
for (String fileName : BUILD_FILES) {
file = SpringProjectUtil.getFile(javaProject, fileName);
if (file != null) {
return file.toURI();
}
}
return null;
}
protected File getSpringBootDependency(IJavaProject project) {
@@ -52,5 +55,4 @@ public abstract class BootDiagnosticProvider {
protected Version getVersion(Generation generation) throws Exception {
return SpringProjectUtil.getVersionFromGeneration(generation.getName());
}
}