Skip to content

Commit

Permalink
feat: add java spotless code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
JudeNiroshan committed Apr 4, 2024
1 parent 5b1848f commit 4046d82
Show file tree
Hide file tree
Showing 60 changed files with 10,447 additions and 10,176 deletions.
15 changes: 15 additions & 0 deletions license-header
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright © 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
35 changes: 35 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,41 @@ limitations under the License.]]>
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<configuration>
<formats>
<format>
<includes><include>src/*</include></includes>
<trimTrailingWhitespace/>
<endWithNewline/>
<indent>
<tabs>true</tabs>
<spacesPerTab>4</spacesPerTab>
</indent>
</format>
</formats>
<java>
<palantirJavaFormat>
<version>2.39.0</version> <!-- optional -->
<style>PALANTIR</style> <!-- or AOSP/GOOGLE (optional) -->
</palantirJavaFormat>
<licenseHeader>
<file>${project.basedir}/license-header</file> -->
</licenseHeader>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
160 changes: 80 additions & 80 deletions src/main/java/com/redhat/exhort/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,100 +15,100 @@
*/
package com.redhat.exhort;

import com.redhat.exhort.api.AnalysisReport;
import com.redhat.exhort.image.ImageRef;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;

import com.redhat.exhort.api.AnalysisReport;
import com.redhat.exhort.image.ImageRef;

/** 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 {
final public byte[] html;
final public 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);
/** 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);
}
}

@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;
/**
* 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;
}
76 changes: 39 additions & 37 deletions src/main/java/com/redhat/exhort/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,56 @@
*/
package com.redhat.exhort;

import java.io.IOException;
import java.nio.file.Path;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.exhort.tools.Ecosystem;
import java.io.IOException;
import java.nio.file.Path;

/**
* 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;
public Content(byte[] buffer, String type){
this.buffer = buffer;
this.type = 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;
}
}
}

/** The ecosystem of this provider, i.e. maven. */
public final Ecosystem.Type ecosystem;
protected final ObjectMapper objectMapper = new ObjectMapper();
/** The ecosystem of this provider, i.e. maven. */
public final Ecosystem.Type ecosystem;

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 4046d82

Please sign in to comment.