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

Show error status when the project is not created #2059

Merged
merged 3 commits into from
May 4, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.codehaus.plexus.util.DirectoryScanner;
import org.eclipse.buildship.core.internal.configuration.GradleProjectNature;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -546,27 +545,15 @@ public static int getMaxProjectProblemSeverity() {
if (ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName())) {
continue;
}

try {
maxSeverity = Math.max(maxSeverity, project.findMaxProblemSeverity(null, true, IResource.DEPTH_ZERO));
if (ProjectUtils.isMavenProject(project)) {
IFile configFile = project.getFile(MavenProjectImporter.POM_FILE);
if (configFile.exists()) {
maxSeverity = Math.max(maxSeverity, configFile.findMaxProblemSeverity(null, true, IResource.DEPTH_ZERO));
}
} else if (ProjectUtils.isGradleProject(project)) {
List<String> gradleConfigs = Arrays.asList(
GradleProjectImporter.BUILD_GRADLE_DESCRIPTOR,
GradleProjectImporter.BUILD_GRADLE_KTS_DESCRIPTOR,
GradleProjectImporter.SETTINGS_GRADLE_DESCRIPTOR,
GradleProjectImporter.SETTINGS_GRADLE_KTS_DESCRIPTOR
);

for (String fileName : gradleConfigs) {
IFile configFile = project.getFile(fileName);
if (configFile.exists()) {
maxSeverity = Math.max(maxSeverity, configFile.findMaxProblemSeverity(null, true, IResource.DEPTH_ZERO));
}
List<IMarker> markers = ResourceUtils.findMarkers(project, IMarker.SEVERITY_ERROR, IMarker.SEVERITY_WARNING);
List<IMarker> buildFileMarkers = markers.stream().filter(marker -> isBuildFileMarker(marker, project)).collect(Collectors.toList());
for (IMarker marker : buildFileMarkers) {
maxSeverity = Math.max(maxSeverity, marker.getAttribute(IMarker.SEVERITY, 0));
jdneo marked this conversation as resolved.
Show resolved Hide resolved
if (maxSeverity == IMarker.SEVERITY_ERROR) {
break;
}
}
} catch (CoreException e) {
Expand All @@ -581,4 +568,21 @@ public static int getMaxProjectProblemSeverity() {
return maxSeverity;
}

private static boolean isBuildFileMarker(IMarker marker, IProject project) {
jdneo marked this conversation as resolved.
Show resolved Hide resolved
IResource resource = marker.getResource();
if (!resource.exists()) {
return false;
}
String lastSegment = resource.getFullPath().lastSegment();
if (ProjectUtils.isMavenProject(project)) {
return lastSegment.equals(MavenProjectImporter.POM_FILE);
} else if (ProjectUtils.isGradleProject(project)) {
return lastSegment.equals(GradleProjectImporter.BUILD_GRADLE_DESCRIPTOR) ||
lastSegment.equals(GradleProjectImporter.BUILD_GRADLE_KTS_DESCRIPTOR) ||
lastSegment.equals(GradleProjectImporter.SETTINGS_GRADLE_DESCRIPTOR) ||
lastSegment.equals(GradleProjectImporter.SETTINGS_GRADLE_KTS_DESCRIPTOR);
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
// id 'java'
}

repositories {
mavenCentral()
}

dependencies {
testImplementation(platform('org.junit:junit-bom:5.7.1'))
testImplementation('org.junit.jupiter:junit-jupiter')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = 'invalid-subproject'
include 'invalid'
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ public void testGetProjectSeverityWhenConfigFileNotExists() throws Exception {
ProjectUtils.getMaxProjectProblemSeverity();
}

@Test
public void testGetMaxProjectProblemSeverityForSubProject() throws Exception {
importProjects("gradle/invalid-subproject");
assertEquals(IMarker.SEVERITY_ERROR, ProjectUtils.getMaxProjectProblemSeverity());
}

}