Skip to content

Commit

Permalink
Show error status when the project is not created (#2059)
Browse files Browse the repository at this point in the history
Signed-off-by: Shi Chen <[email protected]>
  • Loading branch information
CsCherrYY authored May 4, 2022
1 parent 03aa9ab commit c64c32c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
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));
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) {
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());
}

}

0 comments on commit c64c32c

Please sign in to comment.