Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable automatic source code formatting #5

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,29 @@ concurrency:
cancel-in-progress: true

jobs:
build-:
format-check:
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'maven'
- name: Validate Formatting
run: |
mvn -B -ntp validate -Pformat-check
build:
needs: format-check
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest ]
java: ['11', '17', '21']
java: ['17', '21']

steps:
- uses: actions/checkout@v4
Expand All @@ -40,9 +56,34 @@ jobs:
distribution: 'temurin'
cache: 'maven'
- name: Build with Maven Java ${{ matrix.java }}
run: mvn -B clean verify
run: mvn -B -ntp clean verify
- uses: actions/upload-artifact@v4
if: failure()
with:
name: surefire-reports-${{ matrix.os }}-${{ matrix.java }}
path: '**/surefire-reports/*'
test-java11:
needs: format-check
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest ]

steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: |
11
17
distribution: 'temurin'
cache: 'maven'
- name: Build with Maven Java ${{ matrix.java }}
run: mvn -B -ntp clean verify '-Djava11.home="${{env.JAVA_HOME_11_X64}}"'
- uses: actions/upload-artifact@v4
if: failure()
with:
name: surefire-reports-${{ matrix.os }}-${{ matrix.java }}
path: '**/surefire-reports/*'
path: '**/surefire-reports/*'
103 changes: 103 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,20 @@

<!-- Properties -->
<properties>
<maven.compile.release>11</maven.compile.release>
<jdk.min.version>17</jdk.min.version>

<!-- Dependency versions -->
<version.arquillian_core>1.8.0.Final</version.arquillian_core>
<version.testcontainers>1.19.8</version.testcontainers>

<!-- Plugin versions -->
<version.formatter.maven.plugin>2.23.0</version.formatter.maven.plugin>
<version.impsort.maven.plugin>1.11.0</version.impsort.maven.plugin>

<!-- Configuration properties -->
<skipFormatting>false</skipFormatting>
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -124,7 +136,98 @@
<localCheckout>true</localCheckout>
</configuration>
</plugin>
<!-- Enable auto-formatting of source files -->
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>${version.formatter.maven.plugin}</version>
<dependencies>
<dependency>
<groupId>org.wildfly.tools</groupId>
<artifactId>ide-config</artifactId>
<version>1.0.4.Final</version>
</dependency>
</dependencies>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache</cachedir>
<configFile>eclipse-code-formatter.xml</configFile>
<configXmlFile>wildfly-xml.properties</configXmlFile>
<lineEnding>LF</lineEnding>
<includeResources>true</includeResources>
<removeTrailingWhitespace>true</removeTrailingWhitespace>
<skip>${skipFormatting}</skip>
</configuration>
<executions>
<execution>
<id>format</id>
<goals>
<goal>format</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>${version.impsort.maven.plugin}</version>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache</cachedir>
<groups>java.,javax.,jakarta.,org.,com.</groups>
<staticGroups>*</staticGroups>
<skip>${skipFormatting}</skip>
<removeUnused>true</removeUnused>
</configuration>
<executions>
<execution>
<id>sort-imports</id>
<goals>
<goal>sort</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>format-check</id>
<build>
<plugins>
<!-- Validate formatting -->
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<executions>
<execution>
<id>validate-format</id>
<phase>validate</phase>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<executions>
<execution>
<id>check-import-sort</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Target({ ElementType.TYPE })
public @interface TestContainer {
Class<? extends GenericContainer<?>> value();

boolean failIfNoDocker() default true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import java.lang.annotation.Annotation;

import org.jboss.arquillian.container.test.impl.enricher.resource.OperatesOnDeploymentAwareProvider;
import org.jboss.arquillian.core.api.Instance;
import org.jboss.arquillian.core.api.annotation.Inject;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.arquillian.test.spi.annotation.ClassScoped;
import org.jboss.arquillian.container.test.impl.enricher.resource.OperatesOnDeploymentAwareProvider;
import org.testcontainers.containers.GenericContainer;

public class TestContainerProvider extends OperatesOnDeploymentAwareProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.lang.reflect.Constructor;

import com.github.dockerjava.api.DockerClient;
import org.jboss.arquillian.core.api.InstanceProducer;
import org.jboss.arquillian.core.api.annotation.Inject;
import org.jboss.arquillian.core.api.annotation.Observes;
Expand All @@ -29,6 +28,8 @@
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.GenericContainer;

import com.github.dockerjava.api.DockerClient;

public class TestContainersObserver {
@Inject
@ClassScoped
Expand All @@ -45,7 +46,7 @@ public void createContainer(@Observes(precedence = 500) BeforeClass beforeClass)
final GenericContainer<?> container = clazz.getConstructor().newInstance();
container.start();
containerWrapper.set(container);
} catch (Exception e) { //Clean up
} catch (Exception e) { // Clean up
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -74,7 +75,7 @@ private void checkForDocker(boolean failIfNoDocker) {
}

private boolean isDockerAvailable() {
try(DockerClient client = DockerClientFactory.instance().client()) {
try (DockerClient client = DockerClientFactory.instance().client()) {
return true;
} catch (Throwable ex) {
return false;
Expand Down