Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Configure spotless plugin and enable code formatting (#276)
Browse files Browse the repository at this point in the history
* Configure spotless plugin and enable code formatting

* Remove checkstyle and @ignore flaky tests
  • Loading branch information
jotok committed Mar 25, 2021
1 parent f7b430b commit 3e6b8ec
Show file tree
Hide file tree
Showing 12 changed files with 396 additions and 257 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Java CI
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

jobs:
build_rca_pkg:
Expand All @@ -22,6 +22,10 @@ jobs:
uses: actions/checkout@v2
with:
path: ./tmp/pa
# fetch the main branch to make it available for spotless ratcheting
- name: Fetch 'main' branch
working-directory: ./tmp/pa
run: git fetch --depth=1 origin main
- name: Set up JDK 1.12
uses: actions/setup-java@v1
with:
Expand Down
32 changes: 18 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ plugins {
id 'java'
id 'nebula.ospackage' version "8.3.0"
id 'com.github.spotbugs' version '4.6.0'
id 'checkstyle'
id 'jacoco'
id 'com.diffplug.spotless' version '5.8.2'
id 'com.diffplug.spotless' version '5.11.0'
}

spotbugsMain {
Expand Down Expand Up @@ -71,13 +70,23 @@ ext {
projectSubstitutions = [:]
licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')
gitDefaultBranch = 'main'
}

apply plugin: 'com.diffplug.spotless'

spotless {
java {
// only apply formatting rules to updated files
ratchetFrom "origin/${gitDefaultBranch}"

licenseHeaderFile(file('license-header'))
googleJavaFormat().aosp()
importOrder()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()

// add support for spotless:off and spotless:on tags to exclude sections of code
toggleOffOn()
}
}

Expand All @@ -88,6 +97,8 @@ test {

licenseHeaders.enabled = false
validateNebulaPom.enabled = false


loggerUsageCheck.enabled = false

esplugin {
Expand Down Expand Up @@ -188,13 +199,8 @@ jacocoTestCoverageVerification {
// to run coverage verification during the build (and fail when appropriate)
check.dependsOn jacocoTestCoverageVerification

checkstyle {
toolVersion = '8.24'
configFile file("checkstyle/checkstyle.xml")
}

checkstyleMain.ignoreFailures = true
checkstyleTest.ignoreFailures = true
checkstyleMain.enabled = false
checkstyleTest.enabled = false

dependencies {
if (JavaVersion.current() <= JavaVersion.VERSION_1_8) {
Expand All @@ -209,7 +215,6 @@ dependencies {

configurations.all {
resolutionStrategy {
force "com.puppycrawl.tools:checkstyle:${project.checkstyle.toolVersion}"
force 'com.fasterxml.jackson.core:jackson-databind:2.10.5.1'
force 'com.fasterxml.jackson.core:jackson-core:2.10.5'
force 'com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.10.5'
Expand Down Expand Up @@ -263,8 +268,6 @@ dependencies {
force = 'true'
}
testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'

checkstyle "com.puppycrawl.tools:checkstyle:${project.checkstyle.toolVersion}"
}

dependencyLicenses {
Expand Down Expand Up @@ -300,6 +303,7 @@ task cloneGitRepo(type: GitClone) {
rcaDir = Paths.get(getProject().getBuildDir().toString(), "performance-analyzer-rca").toString()
def destination = file(rcaDir)
uri = "https://github.com/opendistro-for-elasticsearch/performance-analyzer-rca.git"
branch = gitDefaultBranch
destinationPath = destination
bare = false
enabled = !destination.exists() // to clone only once
Expand Down
1 change: 0 additions & 1 deletion licenses/bcpkix-jdk15on-1.66.jar.sha1

This file was deleted.

1 change: 0 additions & 1 deletion licenses/bcprov-jdk15on-1.66.jar.sha1

This file was deleted.

1 change: 0 additions & 1 deletion licenses/jackson-annotations-2.10.4.jar.sha1

This file was deleted.

1 change: 0 additions & 1 deletion licenses/jackson-databind-2.10.4.jar.sha1

This file was deleted.

2 changes: 1 addition & 1 deletion licenses/performanceanalyzer-rca-1.13.jar.sha1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0ca252df95b9c0743d7b29452c7637504d5ba50f
0d0d568122db55b2a11cf5d0f562d754e2bcf898

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,31 @@

package com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors;

import static org.junit.Assert.assertEquals;

import com.amazon.opendistro.elasticsearch.performanceanalyzer.CustomMetricsLocationTestBase;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.MetricsConfiguration;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.PerformanceAnalyzerMetrics;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader_writer_shared.Event;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import org.junit.Ignore;
import org.junit.Test;

public class AdmissionControlMetricsCollectorTests extends CustomMetricsLocationTestBase {

@Ignore
@Test
public void admissionControlMetricsCollector() {
MetricsConfiguration.CONFIG_MAP.put(AdmissionControlMetricsCollector.class, MetricsConfiguration.cdefault);
AdmissionControlMetricsCollector admissionControlMetricsCollector = new AdmissionControlMetricsCollector();
MetricsConfiguration.CONFIG_MAP.put(
AdmissionControlMetricsCollector.class, MetricsConfiguration.cdefault);
AdmissionControlMetricsCollector admissionControlMetricsCollector =
new AdmissionControlMetricsCollector();

long startTimeInMills = System.currentTimeMillis();
admissionControlMetricsCollector.saveMetricValues("testMetric", startTimeInMills);

List<Event> metrics = new ArrayList<>();
List<Event> metrics = new ArrayList<>();
PerformanceAnalyzerMetrics.metricQueue.drainTo(metrics);
assertEquals(1, metrics.size());
assertEquals("testMetric", metrics.get(0).value);
Expand Down
Loading

0 comments on commit 3e6b8ec

Please sign in to comment.