Skip to content

Commit 4046d82

Browse files
committed
feat: add java spotless code formatter
1 parent 5b1848f commit 4046d82

File tree

60 files changed

+10447
-10176
lines changed

Some content is hidden

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

60 files changed

+10447
-10176
lines changed

license-header

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright © 2023 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/

pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,41 @@ limitations under the License.]]>
685685
</execution>
686686
</executions>
687687
</plugin>
688+
689+
<plugin>
690+
<groupId>com.diffplug.spotless</groupId>
691+
<artifactId>spotless-maven-plugin</artifactId>
692+
<configuration>
693+
<formats>
694+
<format>
695+
<includes><include>src/*</include></includes>
696+
<trimTrailingWhitespace/>
697+
<endWithNewline/>
698+
<indent>
699+
<tabs>true</tabs>
700+
<spacesPerTab>4</spacesPerTab>
701+
</indent>
702+
</format>
703+
</formats>
704+
<java>
705+
<palantirJavaFormat>
706+
<version>2.39.0</version> <!-- optional -->
707+
<style>PALANTIR</style> <!-- or AOSP/GOOGLE (optional) -->
708+
</palantirJavaFormat>
709+
<licenseHeader>
710+
<file>${project.basedir}/license-header</file> -->
711+
</licenseHeader>
712+
</java>
713+
</configuration>
714+
<executions>
715+
<execution>
716+
<goals>
717+
<goal>check</goal>
718+
</goals>
719+
<phase>process-sources</phase>
720+
</execution>
721+
</executions>
722+
</plugin>
688723
</plugins>
689724
</build>
690725

src/main/java/com/redhat/exhort/Api.java

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -15,100 +15,100 @@
1515
*/
1616
package com.redhat.exhort;
1717

18+
import com.redhat.exhort.api.AnalysisReport;
19+
import com.redhat.exhort.image.ImageRef;
1820
import java.io.IOException;
1921
import java.util.Arrays;
2022
import java.util.Map;
2123
import java.util.Objects;
2224
import java.util.Set;
2325
import java.util.concurrent.CompletableFuture;
2426

25-
import com.redhat.exhort.api.AnalysisReport;
26-
import com.redhat.exhort.image.ImageRef;
27-
2827
/** The Api interface is used for contracting API implementations. **/
2928
public interface Api {
3029

31-
public static final String CYCLONEDX_MEDIA_TYPE = "application/vnd.cyclonedx+json";
30+
public static final String CYCLONEDX_MEDIA_TYPE = "application/vnd.cyclonedx+json";
3231

33-
enum MediaType {
34-
APPLICATION_JSON,
35-
TEXT_HTML,
36-
MULTIPART_MIXED;
32+
enum MediaType {
33+
APPLICATION_JSON,
34+
TEXT_HTML,
35+
MULTIPART_MIXED;
3736

38-
@Override
39-
public String toString() {
40-
return this.name().toLowerCase().replace("_", "/");
37+
@Override
38+
public String toString() {
39+
return this.name().toLowerCase().replace("_", "/");
40+
}
4141
}
42-
}
4342

44-
/** POJO class used for aggregating multipart/mixed analysis requests. */
45-
class MixedReport {
46-
final public byte[] html;
47-
final public AnalysisReport json;
48-
49-
public MixedReport(final byte[] html, final AnalysisReport json) {
50-
this.html = html;
51-
this.json = json;
52-
}
53-
public MixedReport()
54-
{
55-
this.html = new byte[0];
56-
this.json = new AnalysisReport();
57-
}
58-
@Override
59-
public boolean equals(final Object o) {
60-
if (this == o) return true;
61-
if (o == null || this.getClass() != o.getClass()) return false;
62-
var that = (MixedReport) o;
63-
return Arrays.equals(this.html, that.html) && Objects.equals(this.json, that.json);
43+
/** POJO class used for aggregating multipart/mixed analysis requests. */
44+
class MixedReport {
45+
public final byte[] html;
46+
public final AnalysisReport json;
47+
48+
public MixedReport(final byte[] html, final AnalysisReport json) {
49+
this.html = html;
50+
this.json = json;
51+
}
52+
53+
public MixedReport() {
54+
this.html = new byte[0];
55+
this.json = new AnalysisReport();
56+
}
57+
58+
@Override
59+
public boolean equals(final Object o) {
60+
if (this == o) return true;
61+
if (o == null || this.getClass() != o.getClass()) return false;
62+
var that = (MixedReport) o;
63+
return Arrays.equals(this.html, that.html) && Objects.equals(this.json, that.json);
64+
}
65+
66+
@Override
67+
public int hashCode() {
68+
return 31 * Objects.hash(json) + Arrays.hashCode(html);
69+
}
6470
}
6571

66-
@Override
67-
public int hashCode() {
68-
return 31 * Objects.hash(json) + Arrays.hashCode(html);
69-
}
70-
}
71-
72-
/**
73-
* Use for creating a stack analysis HTML report for a given manifest file.
74-
*
75-
* @param manifestFile the path for the manifest file
76-
* @return a mixed reports for both HTML and JSON wrapped in a CompletableFuture
77-
* @throws IOException when failed to load the manifest file
78-
*/
79-
CompletableFuture<MixedReport> stackAnalysisMixed(String manifestFile) throws IOException;
80-
81-
/**
82-
* Use for creating a stack analysis HTML report for a given manifest file.
83-
*
84-
* @param manifestFile the path for the manifest file
85-
* @return the HTML report as a String wrapped in a CompletableFuture
86-
* @throws IOException when failed to load the manifest file
87-
*/
88-
CompletableFuture<byte[]> stackAnalysisHtml(String manifestFile) throws IOException;
89-
90-
/**
91-
* Use for creating a stack analysis deserialized Json report for a given manifest file.
92-
*
93-
* @param manifestFile the path for the manifest file
94-
* @return the deserialized Json report as an AnalysisReport wrapped in a CompletableFuture
95-
* @throws IOException when failed to load the manifest file
96-
*/
97-
CompletableFuture<AnalysisReport> stackAnalysis(String manifestFile) throws IOException;
98-
99-
/**
100-
* Use for creating a component analysis deserialized Json report for a given type and content.
101-
*
102-
* @param manifestType the type of the manifest, i.e. {@code pom.xml}
103-
* @param manifestContent a byte array of the manifest's content
104-
* @return the deserialized Json report as an AnalysisReport wrapped in a CompletableFuture
105-
* @throws IOException when failed to load the manifest content
106-
*/
107-
CompletableFuture<AnalysisReport> componentAnalysis(String manifestType, byte[] manifestContent) throws IOException;
108-
109-
CompletableFuture<AnalysisReport> componentAnalysis(String manifestFile) throws IOException;
110-
111-
CompletableFuture<Map<ImageRef, AnalysisReport>> imageAnalysis(Set<ImageRef> imageRefs) throws IOException;
112-
113-
CompletableFuture<byte[]> imageAnalysisHtml(Set<ImageRef> imageRefs) throws IOException;
72+
/**
73+
* Use for creating a stack analysis HTML report for a given manifest file.
74+
*
75+
* @param manifestFile the path for the manifest file
76+
* @return a mixed reports for both HTML and JSON wrapped in a CompletableFuture
77+
* @throws IOException when failed to load the manifest file
78+
*/
79+
CompletableFuture<MixedReport> stackAnalysisMixed(String manifestFile) throws IOException;
80+
81+
/**
82+
* Use for creating a stack analysis HTML report for a given manifest file.
83+
*
84+
* @param manifestFile the path for the manifest file
85+
* @return the HTML report as a String wrapped in a CompletableFuture
86+
* @throws IOException when failed to load the manifest file
87+
*/
88+
CompletableFuture<byte[]> stackAnalysisHtml(String manifestFile) throws IOException;
89+
90+
/**
91+
* Use for creating a stack analysis deserialized Json report for a given manifest file.
92+
*
93+
* @param manifestFile the path for the manifest file
94+
* @return the deserialized Json report as an AnalysisReport wrapped in a CompletableFuture
95+
* @throws IOException when failed to load the manifest file
96+
*/
97+
CompletableFuture<AnalysisReport> stackAnalysis(String manifestFile) throws IOException;
98+
99+
/**
100+
* Use for creating a component analysis deserialized Json report for a given type and content.
101+
*
102+
* @param manifestType the type of the manifest, i.e. {@code pom.xml}
103+
* @param manifestContent a byte array of the manifest's content
104+
* @return the deserialized Json report as an AnalysisReport wrapped in a CompletableFuture
105+
* @throws IOException when failed to load the manifest content
106+
*/
107+
CompletableFuture<AnalysisReport> componentAnalysis(String manifestType, byte[] manifestContent) throws IOException;
108+
109+
CompletableFuture<AnalysisReport> componentAnalysis(String manifestFile) throws IOException;
110+
111+
CompletableFuture<Map<ImageRef, AnalysisReport>> imageAnalysis(Set<ImageRef> imageRefs) throws IOException;
112+
113+
CompletableFuture<byte[]> imageAnalysisHtml(Set<ImageRef> imageRefs) throws IOException;
114114
}

src/main/java/com/redhat/exhort/Provider.java

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,56 @@
1515
*/
1616
package com.redhat.exhort;
1717

18-
import java.io.IOException;
19-
import java.nio.file.Path;
20-
2118
import com.fasterxml.jackson.databind.ObjectMapper;
2219
import com.redhat.exhort.tools.Ecosystem;
20+
import java.io.IOException;
21+
import java.nio.file.Path;
2322

2423
/**
2524
* The Provider abstraction is used for contracting providers providing a {@link Content}
2625
* per manifest type for constructing backend requests.
2726
**/
2827
public abstract class Provider {
29-
/**
30-
* Content is used to aggregate a content buffer and a content type.
31-
* These will be used to construct the backend API request.
32-
**/
33-
public static class Content {
34-
public final byte[] buffer;
35-
public final String type;
36-
public Content(byte[] buffer, String type){
37-
this.buffer = buffer;
38-
this.type = type;
28+
/**
29+
* Content is used to aggregate a content buffer and a content type.
30+
* These will be used to construct the backend API request.
31+
**/
32+
public static class Content {
33+
public final byte[] buffer;
34+
public final String type;
35+
36+
public Content(byte[] buffer, String type) {
37+
this.buffer = buffer;
38+
this.type = type;
39+
}
3940
}
40-
}
4141

42-
/** The ecosystem of this provider, i.e. maven. */
43-
public final Ecosystem.Type ecosystem;
44-
protected final ObjectMapper objectMapper = new ObjectMapper();
42+
/** The ecosystem of this provider, i.e. maven. */
43+
public final Ecosystem.Type ecosystem;
44+
45+
protected final ObjectMapper objectMapper = new ObjectMapper();
46+
47+
protected Provider(Ecosystem.Type ecosystem) {
48+
this.ecosystem = ecosystem;
49+
}
4550

46-
protected Provider(Ecosystem.Type ecosystem) {
47-
this.ecosystem = ecosystem;
48-
}
51+
/**
52+
* Use for providing content for a stack analysis request.
53+
*
54+
* @param manifestPath the Path for the manifest file
55+
* @return A Content record aggregating the body content and content type
56+
* @throws IOException when failed to load the manifest file
57+
*/
58+
public abstract Content provideStack(Path manifestPath) throws IOException;
4959

50-
/**
51-
* Use for providing content for a stack analysis request.
52-
*
53-
* @param manifestPath the Path for the manifest file
54-
* @return A Content record aggregating the body content and content type
55-
* @throws IOException when failed to load the manifest file
56-
*/
57-
public abstract Content provideStack(Path manifestPath) throws IOException;
60+
/**
61+
* Use for providing content for a component analysis request.
62+
*
63+
* @param manifestContent the content of the manifest file
64+
* @return A Content record aggregating the body content and content type
65+
* @throws IOException when failed to load the manifest content
66+
*/
67+
public abstract Content provideComponent(byte[] manifestContent) throws IOException;
5868

59-
/**
60-
* Use for providing content for a component analysis request.
61-
*
62-
* @param manifestContent the content of the manifest file
63-
* @return A Content record aggregating the body content and content type
64-
* @throws IOException when failed to load the manifest content
65-
*/
66-
public abstract Content provideComponent(byte[] manifestContent) throws IOException;
67-
public abstract Content provideComponent(Path manifestPath) throws IOException;
69+
public abstract Content provideComponent(Path manifestPath) throws IOException;
6870
}

0 commit comments

Comments
 (0)