Skip to content

Commit

Permalink
feat: use Google java spotless formatter
Browse files Browse the repository at this point in the history
Signed-off-by: Jude Niroshan <[email protected]>
  • Loading branch information
JudeNiroshan authored and zvigrinberg committed Apr 19, 2024
1 parent a3d5f72 commit ac49ad9
Show file tree
Hide file tree
Showing 64 changed files with 11,104 additions and 10,246 deletions.
10 changes: 6 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,15 @@ limitations under the License.]]>
</format>
</formats>
<java>
<palantirJavaFormat>
<version>2.39.0</version> <!-- optional -->
<style>PALANTIR</style> <!-- or AOSP/GOOGLE (optional) -->
</palantirJavaFormat>
<googleJavaFormat>
<style>GOOGLE</style> <!-- or AOSP (optional) -->
<reflowLongStrings>true</reflowLongStrings> <!-- optional -->
</googleJavaFormat>
<licenseHeader>
<file>${project.basedir}/license-header</file> -->
</licenseHeader>
<removeUnusedImports />
<formatAnnotations />
</java>
</configuration>
<executions>
Expand Down
160 changes: 81 additions & 79 deletions src/main/java/com/redhat/exhort/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,91 +24,93 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;

/** The Api interface is used for contracting API implementations. **/
/** The Api interface is used for contracting API implementations. * */
public interface Api {

public static final String CYCLONEDX_MEDIA_TYPE = "application/vnd.cyclonedx+json";
public static final String CYCLONEDX_MEDIA_TYPE = "application/vnd.cyclonedx+json";

enum MediaType {
APPLICATION_JSON,
TEXT_HTML,
MULTIPART_MIXED;
enum MediaType {
APPLICATION_JSON,
TEXT_HTML,
MULTIPART_MIXED;

@Override
public String toString() {
return this.name().toLowerCase().replace("_", "/");
}
@Override
public String toString() {
return this.name().toLowerCase().replace("_", "/");
}
}

/** POJO class used for aggregating multipart/mixed analysis requests. */
class MixedReport {
public final byte[] html;
public final AnalysisReport json;

public MixedReport(final byte[] html, final AnalysisReport json) {
this.html = html;
this.json = json;
}

public MixedReport() {
this.html = new byte[0];
this.json = new AnalysisReport();
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
var that = (MixedReport) o;
return Arrays.equals(this.html, that.html) && Objects.equals(this.json, that.json);
}

@Override
public int hashCode() {
return 31 * Objects.hash(json) + Arrays.hashCode(html);
}
/** POJO class used for aggregating multipart/mixed analysis requests. */
class MixedReport {
public final byte[] html;
public final AnalysisReport json;

public MixedReport(final byte[] html, final AnalysisReport json) {
this.html = html;
this.json = json;
}

public MixedReport() {
this.html = new byte[0];
this.json = new AnalysisReport();
}

/**
* Use for creating a stack analysis HTML report for a given manifest file.
*
* @param manifestFile the path for the manifest file
* @return a mixed reports for both HTML and JSON wrapped in a CompletableFuture
* @throws IOException when failed to load the manifest file
*/
CompletableFuture<MixedReport> stackAnalysisMixed(String manifestFile) throws IOException;

/**
* Use for creating a stack analysis HTML report for a given manifest file.
*
* @param manifestFile the path for the manifest file
* @return the HTML report as a String wrapped in a CompletableFuture
* @throws IOException when failed to load the manifest file
*/
CompletableFuture<byte[]> stackAnalysisHtml(String manifestFile) throws IOException;

/**
* Use for creating a stack analysis deserialized Json report for a given manifest file.
*
* @param manifestFile the path for the manifest file
* @return the deserialized Json report as an AnalysisReport wrapped in a CompletableFuture
* @throws IOException when failed to load the manifest file
*/
CompletableFuture<AnalysisReport> stackAnalysis(String manifestFile) throws IOException;

/**
* Use for creating a component analysis deserialized Json report for a given type and content.
*
* @param manifestType the type of the manifest, i.e. {@code pom.xml}
* @param manifestContent a byte array of the manifest's content
* @return the deserialized Json report as an AnalysisReport wrapped in a CompletableFuture
* @throws IOException when failed to load the manifest content
*/
CompletableFuture<AnalysisReport> componentAnalysis(String manifestType, byte[] manifestContent) throws IOException;

CompletableFuture<AnalysisReport> componentAnalysis(String manifestFile) throws IOException;

CompletableFuture<Map<ImageRef, AnalysisReport>> imageAnalysis(Set<ImageRef> imageRefs) throws IOException;

CompletableFuture<byte[]> imageAnalysisHtml(Set<ImageRef> imageRefs) throws IOException;
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
var that = (MixedReport) o;
return Arrays.equals(this.html, that.html) && Objects.equals(this.json, that.json);
}

@Override
public int hashCode() {
return 31 * Objects.hash(json) + Arrays.hashCode(html);
}
}

/**
* Use for creating a stack analysis HTML report for a given manifest file.
*
* @param manifestFile the path for the manifest file
* @return a mixed reports for both HTML and JSON wrapped in a CompletableFuture
* @throws IOException when failed to load the manifest file
*/
CompletableFuture<MixedReport> stackAnalysisMixed(String manifestFile) throws IOException;

/**
* Use for creating a stack analysis HTML report for a given manifest file.
*
* @param manifestFile the path for the manifest file
* @return the HTML report as a String wrapped in a CompletableFuture
* @throws IOException when failed to load the manifest file
*/
CompletableFuture<byte[]> stackAnalysisHtml(String manifestFile) throws IOException;

/**
* Use for creating a stack analysis deserialized Json report for a given manifest file.
*
* @param manifestFile the path for the manifest file
* @return the deserialized Json report as an AnalysisReport wrapped in a CompletableFuture
* @throws IOException when failed to load the manifest file
*/
CompletableFuture<AnalysisReport> stackAnalysis(String manifestFile) throws IOException;

/**
* Use for creating a component analysis deserialized Json report for a given type and content.
*
* @param manifestType the type of the manifest, i.e. {@code pom.xml}
* @param manifestContent a byte array of the manifest's content
* @return the deserialized Json report as an AnalysisReport wrapped in a CompletableFuture
* @throws IOException when failed to load the manifest content
*/
CompletableFuture<AnalysisReport> componentAnalysis(String manifestType, byte[] manifestContent)
throws IOException;

CompletableFuture<AnalysisReport> componentAnalysis(String manifestFile) throws IOException;

CompletableFuture<Map<ImageRef, AnalysisReport>> imageAnalysis(Set<ImageRef> imageRefs)
throws IOException;

CompletableFuture<byte[]> imageAnalysisHtml(Set<ImageRef> imageRefs) throws IOException;
}
74 changes: 37 additions & 37 deletions src/main/java/com/redhat/exhort/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,50 @@
import java.nio.file.Path;

/**
* The Provider abstraction is used for contracting providers providing a {@link Content}
* per manifest type for constructing backend requests.
**/
* The Provider abstraction is used for contracting providers providing a {@link Content} per
* manifest type for constructing backend requests.
*/
public abstract class Provider {
/**
* Content is used to aggregate a content buffer and a content type.
* These will be used to construct the backend API request.
**/
public static class Content {
public final byte[] buffer;
public final String type;
/**
* Content is used to aggregate a content buffer and a content type. These will be used to
* construct the backend API request.
*/
public static class Content {
public final byte[] buffer;
public final String type;

public Content(byte[] buffer, String type) {
this.buffer = buffer;
this.type = type;
}
public Content(byte[] buffer, String type) {
this.buffer = buffer;
this.type = type;
}
}

/** The ecosystem of this provider, i.e. maven. */
public final Ecosystem.Type ecosystem;
/** The ecosystem of this provider, i.e. maven. */
public final Ecosystem.Type ecosystem;

protected final ObjectMapper objectMapper = new ObjectMapper();
protected final ObjectMapper objectMapper = new ObjectMapper();

protected Provider(Ecosystem.Type ecosystem) {
this.ecosystem = ecosystem;
}
protected Provider(Ecosystem.Type ecosystem) {
this.ecosystem = ecosystem;
}

/**
* Use for providing content for a stack analysis request.
*
* @param manifestPath the Path for the manifest file
* @return A Content record aggregating the body content and content type
* @throws IOException when failed to load the manifest file
*/
public abstract Content provideStack(Path manifestPath) throws IOException;
/**
* Use for providing content for a stack analysis request.
*
* @param manifestPath the Path for the manifest file
* @return A Content record aggregating the body content and content type
* @throws IOException when failed to load the manifest file
*/
public abstract Content provideStack(Path manifestPath) throws IOException;

/**
* Use for providing content for a component analysis request.
*
* @param manifestContent the content of the manifest file
* @return A Content record aggregating the body content and content type
* @throws IOException when failed to load the manifest content
*/
public abstract Content provideComponent(byte[] manifestContent) throws IOException;
/**
* Use for providing content for a component analysis request.
*
* @param manifestContent the content of the manifest file
* @return A Content record aggregating the body content and content type
* @throws IOException when failed to load the manifest content
*/
public abstract Content provideComponent(byte[] manifestContent) throws IOException;

public abstract Content provideComponent(Path manifestPath) throws IOException;
public abstract Content provideComponent(Path manifestPath) throws IOException;
}
Loading

0 comments on commit ac49ad9

Please sign in to comment.