Skip to content

Commit

Permalink
refactor: Common static analysis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
2 people authored and app committed Dec 6, 2023
1 parent 4a886c4 commit c182da7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ public G.CompilationUnit visitCompilationUnit(G.CompilationUnit cu, ExecutionCon
}
SourceFile s = (SourceFile) tree;
if(s.getSourcePath().endsWith("build.gradle") && !s.getMarkers().findFirst(GradleProject.class).isPresent()) {
if(s.getMarkers().getMarkers().stream().anyMatch(marker -> marker.getClass().getName().equals("org.openrewrite.gradle.marker.GradleProject"))) {
if(s.getMarkers().getMarkers().stream().anyMatch(marker -> "org.openrewrite.gradle.marker.GradleProject".equals(marker.getClass().getName()))) {
s = Markup.error(s, new IllegalStateException(
s.getSourcePath() + " has a GradleProject marker, but it is loaded by a different classloader than the recipe."));
} else {
s = Markup.warn(s, new IllegalStateException(
s.getSourcePath() + " is a Gradle build file, but it is missing a GradleProject marker."));
}
} else if(s.getSourcePath().endsWith("pom.xml") && !s.getMarkers().findFirst(MavenResolutionResult.class).isPresent()) {
if(s.getMarkers().getMarkers().stream().anyMatch(marker -> marker.getClass().getName().equals("org.openrewrite.maven.tree.MavenResolutionResult"))) {
if(s.getMarkers().getMarkers().stream().anyMatch(marker -> "org.openrewrite.maven.tree.MavenResolutionResult".equals(marker.getClass().getName()))) {
s = Markup.error(s, new IllegalStateException(
s.getSourcePath() + " has a MavenResolutionResult marker, but it is loaded by a different classloader than the recipe."));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ private AddDependency addDependency(String gav, String onlyIfUsing, @Nullable St
return new AddDependency(
gavParts[0],
gavParts[1],
(gavParts.length < 3) ? null : gavParts[2],
gavParts.length < 3 ? null : gavParts[2],
null,
onlyIfUsing,
(gavParts.length < 4) ? null : gavParts[3],
gavParts.length < 4 ? null : gavParts[3],
null,
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ void basic() {
.dataTable(DependencyListReport.Row.class, rows -> {
assertThat(rows).isNotEmpty();
assertThat(rows)
.filteredOn(it -> it.getBuildTool().equals("Maven") && it.getDependencyArtifactId().equals("rewrite-core"))
.filteredOn(it -> "Maven".equals(it.getBuildTool()) && "rewrite-core".equals(it.getDependencyArtifactId()))
.hasSize(1);
assertThat(rows)
.filteredOn(it -> it.getBuildTool().equals("Gradle") && it.getDependencyArtifactId().equals("rewrite-core"))
.filteredOn(it -> "Gradle".equals(it.getBuildTool()) && "rewrite-core".equals(it.getDependencyArtifactId()))
.hasSize(1);
}),
//language=groovy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void gradle() {
assertThat(rows).contains(
new RepositoryAccessibilityReport.Row("https://plugins.gradle.org/m2", "", "", 200, "", ""));
assertThat(rows)
.filteredOn(row -> row.getUri().equals("https://nonexistent.moderne.io/maven2") && row.getPingHttpCode() == null).hasSize(1);
.filteredOn(row -> "https://nonexistent.moderne.io/maven2".equals(row.getUri()) && row.getPingHttpCode() == null).hasSize(1);
}),
//language=groovy
buildGradle("""
Expand Down

0 comments on commit c182da7

Please sign in to comment.