Skip to content

Commit

Permalink
Merge pull request #22 from rnc/FORMAT
Browse files Browse the repository at this point in the history
Switch to spotless and PNC formatting
  • Loading branch information
rnc authored Jan 24, 2025
2 parents 116970d + 3d6c00e commit 306ed1a
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 193 deletions.
127 changes: 24 additions & 103 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@
<quarkus.platform.version>3.17.3</quarkus.platform.version>

<lombok.version>1.18.32</lombok.version>
<formatter-maven-plugin.version>2.24.1</formatter-maven-plugin.version>
<impsort-maven-plugin.version>1.12.0</impsort-maven-plugin.version>

<format.skip>false</format.skip>
</properties>

<!-- Other PNC code doesn't deploy to Sonatype Snapshots -->
Expand Down Expand Up @@ -184,37 +180,36 @@
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>${formatter-maven-plugin.version}</version>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.44.2</version>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-ide-config</artifactId>
<version>${quarkus.platform.version}</version>
<groupId>org.jboss.pnc</groupId>
<artifactId>ide-config</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache/formatter-maven-plugin-${formatter-maven-plugin.version}</cachedir>
<configFile>eclipse-format.xml</configFile>
<lineEnding>LF</lineEnding>
<skip>${format.skip}</skip>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>${impsort-maven-plugin.version}</version>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache/impsort-maven-plugin-${impsort-maven-plugin.version}</cachedir>
<groups>java.,javax.,jakarta.,org.,com.</groups>
<staticGroups>*</staticGroups>
<lineEnding>LF</lineEnding>
<skip>${format.skip}</skip>
<removeUnused>true</removeUnused>
<java>
<removeUnusedImports/>
<importOrder>
<order>java,javax,jakarta,org,com</order>
</importOrder>
<eclipse>
<file>java-formatter.xml</file>
</eclipse>
<lineEndings>UNIX</lineEndings>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>apply</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -241,79 +236,5 @@
<quarkus.native.enabled>true</quarkus.native.enabled>
</properties>
</profile>
<profile>
<id>format</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>!validate-format</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<executions>
<execution>
<id>sort-imports</id>
<goals>
<goal>sort</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>validate</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>validate-format</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<executions>
<execution>
<id>check-imports</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
5 changes: 2 additions & 3 deletions src/main/docker/Dockerfile.all-in-one
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
FROM registry.access.redhat.com/ubi8/openjdk-21@sha256:3f712e2b11fea22b81636747175d68830b5cba527c2dff9172d143b9acc5612e AS builder

USER root
USER 0
RUN microdnf --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install -y git

USER 185
WORKDIR /work
COPY ./ .

RUN mvn -V -B package -DskipTests
RUN git config --global --add safe.directory /work && mvn -e -V -B package -Dmaven.test.skip=true

FROM registry.access.redhat.com/ubi8/openjdk-21-runtime@sha256:418b3b6f9bc41ba969a6c7a20b06831131e30d6b4140e29a9453c6a4f08f8c21
WORKDIR /work/
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/org/jboss/pnc/konfluxtooling/EntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import picocli.CommandLine;

@TopCommand
@CommandLine.Command(mixinStandardHelpOptions = true, subcommands = {
CopyArtifactsCommand.class,
DeployCommand.class,
UploadLogCommand.class,
NotifyCommand.class,
PreprocessorCommand.class
})
@CommandLine.Command(
mixinStandardHelpOptions = true,
subcommands = {
CopyArtifactsCommand.class,
DeployCommand.class,
UploadLogCommand.class,
NotifyCommand.class,
PreprocessorCommand.class
})
public class EntryPoint {
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,19 @@ public void run() {
Log.warnf("Skipping POM %s with invalid version %s", fileName, version);
} else {
var packaging = project.getPackaging();
var gav = new Gav(project.getGroupId(), project.getArtifactId(), version, null, packaging, null,
null, null, false, null, false, null);
var gav = new Gav(
project.getGroupId(),
project.getArtifactId(),
version,
null,
packaging,
null,
null,
null,
false,
null,
false,
null);

var existingPath = pomFiles.get(gav);

Expand Down Expand Up @@ -106,14 +117,17 @@ public void run() {

var jarDestFile = Path.of(fullPath + ".jar");
var jarName = jarDestFile.getFileName().toString();
var files = jarFiles.stream().filter(jarPath -> jarPath.getFileName().toString().equals(jarName)).toList();
var files = jarFiles.stream()
.filter(jarPath -> jarPath.getFileName().toString().equals(jarName))
.toList();
var jarSourceFile = (Path) null;

if (!files.isEmpty()) {
jarSourceFile = files.get(0);
} else {
var unversionedJarName = jarName.replace("-" + gav.getVersion(), "");
files = jarFiles.stream().filter(jarPath -> jarPath.getFileName().toString().equals(unversionedJarName))
files = jarFiles.stream()
.filter(jarPath -> jarPath.getFileName().toString().equals(unversionedJarName))
.toList();

if (!files.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ public void run() {
}
}
// Maven Repo Deployment
MavenRepositoryDeployer deployer = new MavenRepositoryDeployer(mvnCtx, mvnUser, mvnPassword.orElse(""), mvnRepo,
serverId, deploymentPath);
MavenRepositoryDeployer deployer = new MavenRepositoryDeployer(
mvnCtx,
mvnUser,
mvnPassword.orElse(""),
mvnRepo,
serverId,
deploymentPath);
deployer.deploy();
} catch (Exception e) {
Log.error("Deployment failed", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ public class MavenRepositoryDeployer {

private final String serverId;

public MavenRepositoryDeployer(BootstrapMavenContext mvnCtx, String username, String password, String repository,
String serverId, Path artifacts)
public MavenRepositoryDeployer(
BootstrapMavenContext mvnCtx,
String username,
String password,
String repository,
String serverId,
Path artifacts)
throws BootstrapMavenException {
this.username = username;
this.password = password;
Expand All @@ -59,14 +64,17 @@ public MavenRepositoryDeployer(BootstrapMavenContext mvnCtx, String username, St
public void deploy()
throws IOException {
RemoteRepository result;
RemoteRepository initial = new RemoteRepository.Builder(serverId,
RemoteRepository initial = new RemoteRepository.Builder(
serverId,
"default",
repository).build();
RemoteRepository.Builder builder = new RemoteRepository.Builder(initial);

if (isNotEmpty(username)) {
builder.setAuthentication(new AuthenticationBuilder().addUsername(username)
.addPassword(password).build());
builder.setAuthentication(
new AuthenticationBuilder().addUsername(username)
.addPassword(password)
.build());
} else {
builder.setAuthentication(session.getAuthenticationSelector().getAuthentication(initial));
}
Expand All @@ -77,7 +85,8 @@ public void deploy()

Log.infof("Configured repository %s", result);

Files.walkFileTree(artifacts,
Files.walkFileTree(
artifacts,
new SimpleFileVisitor<>() {

@Override
Expand All @@ -91,11 +100,14 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
if (relative.getNameCount() <= 2) {
Log.errorf(
"Invalid repository format. Local directory is '%s' with relative path '%s' and not enough components to calculate groupId and artifactId",
artifacts, relative);
artifacts,
relative);
}
// If we're in org/foobar/artifact/1.0 then the group is two up and the artifact is one up.
String group = relative.getParent().getParent().toString().replace(File.separatorChar,
'.');
String group = relative.getParent()
.getParent()
.toString()
.replace(File.separatorChar, '.');
String artifact = relative.getParent().getFileName().toString();
String version = dir.getFileName().toString();
Log.info(
Expand All @@ -108,7 +120,9 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
for (var i : files) {
Matcher matcher = p.matcher(i.getFileName().toString());
if (matcher.matches()) {
Artifact jarArtifact = new DefaultArtifact(group, artifact,
Artifact jarArtifact = new DefaultArtifact(
group,
artifact,
matcher.group(2),
matcher.group(3),
version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,27 @@ public class UploadLogCommand implements Runnable {
@CommandLine.Option(names = "--max-retries")
int maxRetries = DEFAULT_MAX_RETRIES;

@CommandLine.Option(names = "--delay-seconds", description = "in case of retries this is the delay in seconds before next retry")
@CommandLine.Option(
names = "--delay-seconds",
description = "in case of retries this is the delay in seconds before next retry")
int delaySeconds = DEFAULT_DELAY_SECONDS;

@CommandLine.Option(names = "--process-context", description = "id of an long running operation (in this case the build-id is used)")
@CommandLine.Option(
names = "--process-context",
description = "id of an long running operation (in this case the build-id is used)")
String processContext;

@CommandLine.Option(names = "--process-context-variant", description = "in case there are subtasks or retries of individual steps this field can be used to add another ID")
@CommandLine.Option(
names = "--process-context-variant",
description = "in case there are subtasks or retries of individual steps this field can be used to add another ID")
String processContextVariant;

@CommandLine.Option(names = "--tmp", description = "temp build or not, used for a log clean-up")
String tmp = "false";

@CommandLine.Option(names = "--request-context", description = "an id of the initial (http) request that triggered this and potentially other processes")
@CommandLine.Option(
names = "--request-context",
description = "an id of the initial (http) request that triggered this and potentially other processes")
String requestContext;

public void run() {
Expand All @@ -62,8 +70,8 @@ public void run() {
var logFilePath = Path.of(logFile);
var file = logFilePath.toFile();
if (!file.exists()) {
throw new RuntimeException(String.format(
"No log file found at %s. Has the build been correctly done?", logFilePath));
throw new RuntimeException(
String.format("No log file found at %s. Has the build been correctly done?", logFilePath));
}
var md5 = getMD5(logFilePath);
uploadLogsToBifrost(file, md5);
Expand All @@ -80,7 +88,8 @@ private String getMD5(Path logFilePath) throws Exception {
}

private void uploadLogsToBifrost(File logFile, String md5) {
BifrostLogUploader logUploader = new BifrostLogUploader(URI.create(bifrostURL),
BifrostLogUploader logUploader = new BifrostLogUploader(
URI.create(bifrostURL),
maxRetries,
delaySeconds,
() -> accessToken.orElse(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ public void run() {
Request callback = objectMapper.readValue(context, Request.class);

Log.infof("Notification for build %s with status %s and callback %s", buildId, status, callback);
PipelineNotification notification = PipelineNotification.builder().buildId(buildId).status(status)
.completionCallback((Request) callback.getAttachment()).build();
PipelineNotification notification = PipelineNotification.builder()
.buildId(buildId)
.status(status)
.completionCallback((Request) callback.getAttachment())
.build();
String body = objectMapper.writeValueAsString(notification);

HttpRequest.Builder builder = HttpRequest.newBuilder()
Expand Down
Loading

0 comments on commit 306ed1a

Please sign in to comment.