Skip to content

Commit

Permalink
Activate Spotless via Maven property rather than file (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Apr 19, 2023
1 parent 85afa37 commit 5654d97
Show file tree
Hide file tree
Showing 31 changed files with 439 additions and 425 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ See [Incrementals](https://github.com/jenkinsci/incrementals-tools) for details.
## Formatting

To opt in to code formatting of your Java sources and Maven POM with Spotless,
create a `.mvn_exec_spotless` file at the root of your repository and remove
any existing Spotless configuration from your POM.
define the `spotless.check.skip` property to `false` and remove any existing
Spotless configuration from your POM.

To format existing code, run:

Expand Down
72 changes: 37 additions & 35 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
-->
<spotbugs.omitVisitors>FindReturnRef</spotbugs.omitVisitors>

<!-- Set to false to enable Spotless -->
<spotless.check.skip>true</spotless.check.skip>

<!-- Whether to skip tests during release phase (they are executed in the prepare phase). -->
<release.skipTests>true</release.skipTests>
<!-- By default we do not create *-tests.jar. Set to false to allow other plugins to depend on test utilities in yours, using <classifier>tests</classifier>. -->
Expand Down Expand Up @@ -687,6 +690,37 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<configuration>
<java>
<endWithNewline />
<importOrder />
<indent>
<spaces>true</spaces>
</indent>
<palantirJavaFormat />
<removeUnusedImports />
<trimTrailingWhitespace />
</java>
<pom>
<sortPom>
<expandEmptyElements>false</expandEmptyElements>
<sortDependencies>scope,groupId,artifactId</sortDependencies>
<sortDependencyExclusions>groupId,artifactId</sortDependencyExclusions>
<spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
</sortPom>
</pom>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
</plugin>
Expand Down Expand Up @@ -1427,41 +1461,9 @@
<exists>.mvn_exec_spotless</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<configuration>
<java>
<endWithNewline />
<importOrder />
<indent>
<spaces>true</spaces>
</indent>
<palantirJavaFormat />
<removeUnusedImports />
<trimTrailingWhitespace />
</java>
<pom>
<sortPom>
<expandEmptyElements>false</expandEmptyElements>
<sortDependencies>scope,groupId,artifactId</sortDependencies>
<sortDependencyExclusions>groupId,artifactId</sortDependencyExclusions>
<spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
</sortPom>
</pom>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<spotless.check.skip>false</spotless.check.skip>
</properties>
</profile>

<profile>
Expand Down
55 changes: 27 additions & 28 deletions src/it/benchmark/pom.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>@project.version@</version>
<relativePath/>
</parent>
<groupId>org.jenkins-ci.plugins.its</groupId>
<artifactId>benchmark-it</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<jenkins.version>2.361.4</jenkins.version>
</properties>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>@project.version@</version>
<relativePath />
</parent>
<groupId>org.jenkins-ci.plugins.its</groupId>
<artifactId>benchmark-it</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<jenkins.version>2.361.4</jenkins.version>
</properties>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
62 changes: 30 additions & 32 deletions src/it/benchmark/src/test/java/benchmark/BenchmarkRunner.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
package benchmark;

import jenkins.benchmark.jmh.BenchmarkFinder;
import org.junit.Test;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.ChainedOptionsBuilder;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

public class BenchmarkRunner {
@Test
public void runThis() throws Exception {
// number of iterations is kept to a minimum just to verify that the benchmarks work without spending extra
// time during builds.
ChainedOptionsBuilder optionsBuilder =
new OptionsBuilder()
.forks(1)
.warmupIterations(1)
.warmupBatchSize(1)
.measurementIterations(1)
.measurementBatchSize(1)
.shouldFailOnError(true)
.result("jmh-report.json")
.timeUnit(TimeUnit.MICROSECONDS)
.resultFormat(ResultFormatType.JSON);
BenchmarkFinder finder = new BenchmarkFinder(getClass());
finder.findBenchmarks(optionsBuilder);
new Runner(optionsBuilder.build()).run();
}
}
package benchmark;

import java.util.concurrent.TimeUnit;
import jenkins.benchmark.jmh.BenchmarkFinder;
import org.junit.Test;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.ChainedOptionsBuilder;
import org.openjdk.jmh.runner.options.OptionsBuilder;

public class BenchmarkRunner {
@Test
public void runThis() throws Exception {
// number of iterations is kept to a minimum just to verify that the benchmarks work without spending extra
// time during builds.
ChainedOptionsBuilder optionsBuilder = new OptionsBuilder()
.forks(1)
.warmupIterations(1)
.warmupBatchSize(1)
.measurementIterations(1)
.measurementBatchSize(1)
.shouldFailOnError(true)
.result("jmh-report.json")
.timeUnit(TimeUnit.MICROSECONDS)
.resultFormat(ResultFormatType.JSON);
BenchmarkFinder finder = new BenchmarkFinder(getClass());
finder.findBenchmarks(optionsBuilder);
new Runner(optionsBuilder.build()).run();
}
}
34 changes: 16 additions & 18 deletions src/it/benchmark/src/test/java/benchmark/SampleBenchmark.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package benchmark;

import jenkins.benchmark.jmh.JmhBenchmark;
import jenkins.benchmark.jmh.JmhBenchmarkState;
import org.openjdk.jmh.annotations.Benchmark;

import java.io.IOException;

@JmhBenchmark
public class SampleBenchmark {
public static class MyState extends JmhBenchmarkState {
}

@Benchmark
public void benchmark(MyState state) throws IOException {
state.getJenkins().setSystemMessage("Hello world");
}
}
package benchmark;

import java.io.IOException;
import jenkins.benchmark.jmh.JmhBenchmark;
import jenkins.benchmark.jmh.JmhBenchmarkState;
import org.openjdk.jmh.annotations.Benchmark;

@JmhBenchmark
public class SampleBenchmark {
public static class MyState extends JmhBenchmarkState {}

@Benchmark
public void benchmark(MyState state) throws IOException {
state.getJenkins().setSystemMessage("Hello world");
}
}
35 changes: 17 additions & 18 deletions src/it/beta-fail/downstream/pom.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins.its</groupId>
<artifactId>beta-fail</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>org.jenkins-ci.plugins.its.beta-fail</groupId>
<artifactId>downstream</artifactId>
<packaging>hpi</packaging>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.its.beta-fail</groupId>
<artifactId>upstream</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins.its</groupId>
<artifactId>beta-fail</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>org.jenkins-ci.plugins.its.beta-fail</groupId>
<artifactId>downstream</artifactId>
<packaging>hpi</packaging>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.its.beta-fail</groupId>
<artifactId>upstream</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package downstream;

import upstream.Api;

public class Caller {
static {
Api.experimental();
Expand Down
66 changes: 33 additions & 33 deletions src/it/beta-fail/pom.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>@project.version@</version>
<relativePath/>
</parent>
<groupId>org.jenkins-ci.plugins.its</groupId>
<artifactId>beta-fail</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<jenkins.version>2.361.4</jenkins.version>
<maven-hpi-plugin.disabledTestInjection>true</maven-hpi-plugin.disabledTestInjection>
</properties>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<modules>
<module>upstream</module>
<module>downstream</module>
</modules>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>@project.version@</version>
<relativePath />
</parent>
<groupId>org.jenkins-ci.plugins.its</groupId>
<artifactId>beta-fail</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>upstream</module>
<module>downstream</module>
</modules>
<properties>
<jenkins.version>2.361.4</jenkins.version>
<spotless.check.skip>false</spotless.check.skip>
<maven-hpi-plugin.disabledTestInjection>true</maven-hpi-plugin.disabledTestInjection>
</properties>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
2 changes: 1 addition & 1 deletion src/it/beta-fail/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
assert new File(basedir, 'build.log').text.replaceAll(/\e\[[\d;]*[^\d;]/, '').contains('[ERROR] downstream/Caller:5 upstream/Api.experimental()V is still in beta')
assert new File(basedir, 'build.log').text.replaceAll(/\e\[[\d;]*[^\d;]/, '').contains('[ERROR] downstream/Caller:7 upstream/Api.experimental()V is still in beta')

return true

0 comments on commit 5654d97

Please sign in to comment.