Skip to content

Commit ab27c97

Browse files
author
Vincent Potucek
committed
[rewrite] Add RemoveUnusedPrivateMethods
Signed-off-by: Vincent Potucek <[email protected]>
1 parent 476d3d1 commit ab27c97

File tree

51 files changed

+69
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+69
-316
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set +e
4+
5+
./gradlew rewriteDryRun -Dorg.gradle.jvmargs=-Xmx8G \
6+
--configure-on-demand \
7+
--console plain \
8+
--max-workers=1 \
9+
-Pqa --profile
10+
11+
gradle_return_code=$?
12+
13+
set -e
14+
15+
exit $gradle_return_code

build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import org.sonar.build.BlackBoxTest
33

44
import static org.gradle.api.JavaVersion.VERSION_17
55

6-
plugins {
7-
// Ordered alphabetically
6+
plugins { // natural order
87
id 'com.github.hierynomus.license' version '0.16.1'
9-
id "com.github.hierynomus.license-report" version "0.16.1" apply false
10-
id 'com.gradleup.shadow' version '8.3.6' apply false
8+
id 'com.github.hierynomus.license-report' version '0.16.1' apply false
119
id 'com.google.protobuf' version '0.8.19' apply false
10+
id 'com.gradleup.shadow' version '8.3.6' apply false
1211
id 'com.jfrog.artifactory' version '6.0.2'
13-
id "de.undercouch.download" version "5.6.0" apply false
12+
id 'de.undercouch.download' version '5.6.0' apply false
1413
id 'io.spring.dependency-management' version '1.1.7'
15-
id "org.cyclonedx.bom" version "2.3.1" apply false
14+
id 'org.cyclonedx.bom' version '2.3.1' apply false
15+
id 'org.openrewrite.rewrite' version '7.19.0' apply false
1616
id 'org.sonarqube' version '7.0.0.6105'
1717
}
1818

@@ -200,7 +200,10 @@ allprojects {
200200
}
201201
}
202202

203+
apply from: 'gradle/rewrite.gradle'
204+
203205
apply plugin: 'org.sonarqube'
206+
204207
sonar {
205208
properties {
206209
property 'sonar.projectName', projectTitle

gradle/rewrite.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
apply plugin: 'org.openrewrite.rewrite'
10+
11+
rewrite {
12+
activeRecipe('org.opensearch.openrewrite.SanityCheck')
13+
exclusion('**package-info.java')
14+
setExportDatatables(true)
15+
setFailOnDryRunResults(true)
16+
}
17+
18+
dependencies {
19+
rewrite(platform('org.openrewrite.recipe:rewrite-recipe-bom:3.17.0'))
20+
rewrite('org.openrewrite.recipe:rewrite-migrate-java:3.20.0')
21+
rewrite('org.openrewrite.recipe:rewrite-java-security:3.19.2')
22+
rewrite('org.openrewrite.recipe:rewrite-rewrite:0.14.1')
23+
rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.20.0')
24+
rewrite('org.openrewrite.recipe:rewrite-third-party:0.30.0')
25+
}

rewrite.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
type: specs.openrewrite.org/v1beta/recipe
3+
name: org.opensearch.openrewrite.SanityCheck
4+
displayName: Apply all Java & Gradle best practices
5+
description: Comprehensive code quality recipe combining modernization, security, and best practices.
6+
tags:
7+
- java
8+
- gradle
9+
- static-analysis
10+
- cleanup
11+
recipeList:
12+
- org.openrewrite.gradle.EnableGradleBuildCache
13+
- org.openrewrite.gradle.EnableGradleParallelExecution
14+
- org.openrewrite.java.RemoveUnusedImports
15+
- org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods
16+
---

server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubRestClient.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,12 @@
2020
package org.sonar.auth.github;
2121

2222
import com.github.scribejava.core.model.OAuth2AccessToken;
23-
import com.github.scribejava.core.model.OAuthRequest;
24-
import com.github.scribejava.core.model.Response;
25-
import com.github.scribejava.core.model.Verb;
2623
import com.github.scribejava.core.oauth.OAuth20Service;
2724
import java.io.IOException;
28-
import java.net.HttpURLConnection;
2925
import java.util.List;
30-
import java.util.concurrent.ExecutionException;
3126
import org.slf4j.Logger;
3227
import org.slf4j.LoggerFactory;
3328

34-
import static java.lang.String.format;
3529
import static org.sonar.auth.OAuthRestClient.executePaginatedRequest;
3630
import static org.sonar.auth.OAuthRestClient.executeRequest;
3731

server/sonar-ce-common/src/it/java/org/sonar/ce/queue/CeQueueImplIT.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,6 @@ private CeTaskSubmit createTaskSubmit(String type, @Nullable Component component
634634
.build();
635635
}
636636

637-
private ComponentDto insertComponent(ComponentDto componentDto) {
638-
return db.components().insertComponent(componentDto);
639-
}
640-
641637
private UserDto insertUser(UserDto userDto) {
642638
db.getDbClient().userDao().insert(session, userDto);
643639
session.commit();

server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepIT.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
import com.tngtech.java.junit.dataprovider.UseDataProvider;
2525
import java.time.ZoneId;
2626
import java.time.ZonedDateTime;
27-
import java.util.ArrayList;
2827
import java.util.Arrays;
29-
import java.util.List;
3028
import java.util.Optional;
3129
import java.util.Random;
3230
import java.util.stream.Stream;
@@ -489,16 +487,6 @@ public static Object[][] anyValidLeakPeriodSettingValue() {
489487
};
490488
}
491489

492-
private List<SnapshotDto> createSnapshots(ComponentDto project) {
493-
ArrayList<SnapshotDto> list = new ArrayList<>();
494-
list.add(dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setLast(false))); // 2008-11-11
495-
list.add(dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setLast(false))); // 2008-11-12
496-
list.add(dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setLast(false))); // 2008-11-20
497-
list.add(dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setLast(false))); // 2008-11-22
498-
list.add(dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setLast(true))); // 2008-11-29
499-
return list;
500-
}
501-
502490
private long milisSinceEpoch(int year, int month, int day, int hour) {
503491
return ZonedDateTime.of(year, month, day, hour, 0, 0, 0, ZoneId.systemDefault())
504492
.toInstant().toEpochMilli();

server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepIT.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.sonar.ce.task.projectanalysis.step;
2121

2222
import java.util.Date;
23-
import javax.annotation.Nullable;
2423
import org.junit.Rule;
2524
import org.junit.Test;
2625
import org.sonar.api.utils.DateUtils;
@@ -35,13 +34,10 @@
3534
import org.sonar.ce.task.step.TestComputationStepContext;
3635
import org.sonar.db.DbClient;
3736
import org.sonar.db.DbTester;
38-
import org.sonar.db.component.BranchType;
3937
import org.sonar.db.component.ComponentDto;
4038
import org.sonar.db.component.SnapshotTesting;
4139

4240
import static org.assertj.core.api.Assertions.assertThatThrownBy;
43-
import static org.mockito.Mockito.mock;
44-
import static org.mockito.Mockito.when;
4541
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
4642

4743
public class ValidateProjectStepIT {
@@ -110,11 +106,4 @@ public void fail_when_project_key_is_invalid() {
110106
"Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.",
111107
"You should update the project key with the expected format.");
112108
}
113-
114-
private void setBranch(BranchType type, @Nullable String mergeBranchUuid) {
115-
Branch branch = mock(Branch.class);
116-
when(branch.getType()).thenReturn(type);
117-
when(branch.getReferenceBranchUuid()).thenReturn(mergeBranchUuid);
118-
analysisMetadataHolder.setBranch(branch);
119-
}
120109
}

server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -516,22 +516,6 @@ private void assertDtoIsView(ComponentDto dto) {
516516
assertThat(dto.getCreatedAt()).isEqualTo(now);
517517
}
518518

519-
/**
520-
* Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()}
521-
*/
522-
private void assertDtoIsApplication(ComponentDto dto) {
523-
assertThat(dto.name()).isEqualTo(VIEW_NAME);
524-
assertThat(dto.longName()).isEqualTo(VIEW_NAME);
525-
assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION);
526-
assertThat(dto.path()).isNull();
527-
assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
528-
assertThat(dto.branchUuid()).isEqualTo(VIEW_UUID);
529-
assertThat(dto.qualifier()).isEqualTo(ComponentQualifiers.APP);
530-
assertThat(dto.scope()).isEqualTo(ComponentScopes.PROJECT);
531-
assertThat(dto.getCopyComponentUuid()).isNull();
532-
assertThat(dto.getCreatedAt()).isEqualTo(now);
533-
}
534-
535519
/**
536520
* Assertions to verify the DTO created from {@link #createProjectView1Builder(ComponentDto, Long)}
537521
*/

server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/PostMeasuresComputationCheck.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.sonar.api.ExtensionPoint;
2323
import org.sonar.api.ce.ComputeEngineSide;
2424
import org.sonar.ce.common.scanner.ScannerReportReader;
25-
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
2625
import org.sonar.ce.task.projectanalysis.analysis.Branch;
2726
import org.sonar.ce.task.projectanalysis.component.Component;
2827

0 commit comments

Comments
 (0)