Skip to content

Commit

Permalink
Merge pull request #151 from RedHatInsights/classpath_report_to_api
Browse files Browse the repository at this point in the history
DRAFT: Refactor to move Classpath Jar reports into the API module
  • Loading branch information
kittylyst authored Nov 15, 2023
2 parents 2de64f3 + f62808e commit 41e8906
Show file tree
Hide file tree
Showing 34 changed files with 77 additions and 45 deletions.
20 changes: 16 additions & 4 deletions STYLE.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
# Code style guide

Note: this is a set of recommendations, not requirements.
NOTE: The commit messages and need to run the formatter are requirements, whereas the code style points are a set of recommendations.

## Formatting

Before you commit, make sure to run the Spotless formatter:

$ mvn spotless:apply
$ mvn spotless:apply

We adhere to [Semantic Versioning](https://semver.org/) and reinforce this practice with [Conventional Commits](https://www.conventionalcommits.org/)

In its simplest form, a commit message should be structured as follows:

```
<type>[optional scope]: <description>
```

with the type being one of a number of types: `build`, `ci`, `chore`, `docs`, `feat`, `fix`, `perf`, `refactor`, `revert`, `style`, `test`.

If the change introduces a breaking change (which will necessitate a major version bump), then the commit message should be suffixed with `!`.

## Java constructors vs factory methods

- Prefer plain constructors to _factory_ static methods (e.g., `new ABC()` over `ABC.create()` / `ABC.of()`).
- Do use factory methods when:
- some initialization logic cannot be expressed from a constructor, or it becomes inelegant,
- hiding a concrete implementation behind an interface (e.g., `val vertx = Vertx.vertx();`).
- some initialization logic cannot be expressed from a constructor, or it becomes inelegant,
- hiding a concrete implementation behind an interface (e.g., `val vertx = Vertx.vertx();`).

## Getters and setters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.redhat.insights.http.InsightsHttpClient;
import com.redhat.insights.jars.JarInfo;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsReport;
import com.redhat.insights.reports.UpdateReportImpl;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import static com.redhat.insights.InsightsErrorCode.ERROR_WRITING_FILE;

import com.redhat.insights.InsightsException;
import com.redhat.insights.InsightsReport;
import com.redhat.insights.config.InsightsConfiguration;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsReport;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static com.redhat.insights.InsightsErrorCode.ERROR_GZIP_FILE;

import com.redhat.insights.InsightsException;
import com.redhat.insights.InsightsReport;
import com.redhat.insights.reports.InsightsReport;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import static com.redhat.insights.InsightsErrorCode.ERROR_CLIENT_FAILED;

import com.redhat.insights.InsightsException;
import com.redhat.insights.InsightsReport;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsReport;
import java.util.Arrays;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ public ClasspathJarInfoSubreport(InsightsLogger logger) {

@Override
public void generateReport() {
JarAnalyzer analyzer = new JarAnalyzer(logger, true);
String cwd = System.getProperty(USER_DIR);
String cpRaw = System.getProperty(CLASSPATH_ENV);
String[] entries = splitClassPathElements(cpRaw, File.pathSeparator);

jarInfos.clear();
for (String entry : splitClassPathElements(cpRaw, File.pathSeparator)) {
if (entries.length == 0) {
logger.warning("No classpath entries found");
} else {
addEntries(entries);
}
}

private void addEntries(String[] entries) {
JarAnalyzer analyzer = new JarAnalyzer(logger, true);
String cwd = System.getProperty(USER_DIR);

for (String entry : entries) {
logger.debug(entry);
try {
if (!entry.startsWith(File.separator)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.redhat.insights.InsightsException;
import com.redhat.insights.InsightsSubreport;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsSubreport;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.redhat.insights.InsightsSubreport;
import com.redhat.insights.reports.InsightsSubreport;
import java.io.IOException;

public class JarInfoSubreportSerializer extends JsonSerializer<InsightsSubreport> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* Copyright (C) Red Hat 2022-2023 */
package com.redhat.insights;
package com.redhat.insights.reports;

import com.fasterxml.jackson.databind.JsonSerializer;
import com.redhat.insights.Filtering;
import com.redhat.insights.config.InsightsConfiguration;
import com.redhat.insights.logging.InsightsLogger;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* Copyright (C) Red Hat 2022-2023 */
package com.redhat.insights.core.app;
package com.redhat.insights.reports;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.redhat.insights.InsightsSubreport;
import java.io.IOException;

/** A generic Java application {@link InsightsSubreport} JSON serializer implementation. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* Copyright (C) Red Hat 2022-2023 */
package com.redhat.insights.core.app;
package com.redhat.insights.reports;

import com.fasterxml.jackson.databind.JsonSerializer;
import com.redhat.insights.InsightsSubreport;

/** A generic Java application {@link InsightsSubreport} implementation. */
public final class AppInsightsSubreport implements InsightsSubreport {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* Copyright (C) Red Hat 2022-2023 */
package com.redhat.insights;
package com.redhat.insights.reports;

import static com.redhat.insights.InsightsErrorCode.ERROR_SERIALIZING_TO_JSON;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.insights.Filtering;
import com.redhat.insights.InsightsException;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (C) Red Hat 2022-2023 */
package com.redhat.insights;
package com.redhat.insights.reports;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (C) Red Hat 2022-2023 */
package com.redhat.insights;
package com.redhat.insights.reports;

import com.fasterxml.jackson.databind.JsonSerializer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (C) Red Hat 2023 */
package com.redhat.insights;
package com.redhat.insights.reports;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* Copyright (C) Red Hat 2023 */
package com.redhat.insights;
package com.redhat.insights.reports;

import com.fasterxml.jackson.databind.JsonSerializer;
import com.redhat.insights.Filtering;
import com.redhat.insights.jars.JarInfo;
import com.redhat.insights.jars.JarInfoSubreport;
import com.redhat.insights.logging.InsightsLogger;
Expand Down
2 changes: 2 additions & 0 deletions api/src/test/java/com/redhat/insights/AbstractReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.redhat.insights.jars.JarInfoSubreport;
import com.redhat.insights.jars.JarInfoSubreportSerializer;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsReport;
import com.redhat.insights.reports.InsightsReportSerializer;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.redhat.insights.doubles.NoopInsightsLogger;
import com.redhat.insights.http.InsightsHttpClient;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsReport;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
Expand Down
2 changes: 2 additions & 0 deletions api/src/test/java/com/redhat/insights/TestTopLevelReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.redhat.insights.jars.ClasspathJarInfoSubreport;
import com.redhat.insights.jars.JarInfo;
import com.redhat.insights.jars.JarInfoSubreport;
import com.redhat.insights.reports.InsightsReport;
import com.redhat.insights.reports.InsightsSubreport;
import java.io.IOException;
import java.util.*;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.redhat.insights.jars.JarInfo;
import com.redhat.insights.reports.UpdateReportImpl;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package com.redhat.insights.doubles;

import com.fasterxml.jackson.databind.JsonSerializer;
import com.redhat.insights.InsightsSubreport;
import com.redhat.insights.reports.InsightsSubreport;

/** A generic Java application {@link InsightsSubreport} implementation. */
public final class DummyInsightsSubreport implements InsightsSubreport {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Copyright (C) Red Hat 2022-2023 */
package com.redhat.insights.doubles;

import com.redhat.insights.AbstractTopLevelReportBase;
import com.redhat.insights.InsightsSubreport;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.AbstractTopLevelReportBase;
import com.redhat.insights.reports.InsightsSubreport;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Copyright (C) Red Hat 2023 */
package com.redhat.insights.doubles;

import com.redhat.insights.InsightsReport;
import com.redhat.insights.http.InsightsHttpClient;
import com.redhat.insights.reports.InsightsReport;

public final class NoopInsightsHttpClient implements InsightsHttpClient {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Copyright (C) Red Hat 2023 */
package com.redhat.insights.doubles;

import com.redhat.insights.InsightsReport;
import com.redhat.insights.http.InsightsHttpClient;
import com.redhat.insights.reports.InsightsReport;

/**
* Fake http client, which will store content of report sent. Designed to test @link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import static org.mockito.Mockito.when;

import com.redhat.insights.InsightsException;
import com.redhat.insights.InsightsReport;
import com.redhat.insights.config.InsightsConfiguration;
import com.redhat.insights.doubles.NoopInsightsLogger;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsReport;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import static org.mockito.Mockito.*;

import com.redhat.insights.InsightsException;
import com.redhat.insights.InsightsReport;
import com.redhat.insights.config.InsightsConfiguration;
import com.redhat.insights.doubles.DummyTopLevelReport;
import com.redhat.insights.doubles.NoopInsightsLogger;
import com.redhat.insights.doubles.StoringInsightsHttpClient;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsReport;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.redhat.insights.InsightsException;
import com.redhat.insights.InsightsReport;
import com.redhat.insights.InsightsReportController;
import com.redhat.insights.InsightsSubreport;
import com.redhat.insights.config.InsightsConfiguration;
import com.redhat.insights.doubles.*;
import com.redhat.insights.jars.ClasspathJarInfoSubreport;
import com.redhat.insights.jars.JarInfo;
import com.redhat.insights.jars.JarInfoSubreport;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsReport;
import com.redhat.insights.reports.InsightsSubreport;
import java.io.IOException;
import java.time.Duration;
import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import static com.redhat.insights.InsightsErrorCode.*;

import com.redhat.insights.InsightsException;
import com.redhat.insights.InsightsReport;
import com.redhat.insights.config.InsightsConfiguration;
import com.redhat.insights.http.InsightsHttpClient;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsReport;
import java.io.File;
import java.net.InetSocketAddress;
import java.net.ProxySelector;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* Copyright (C) Red Hat 2022-2023 */
package com.redhat.insights.core.app;
package com.redhat.insights.core.reports;

import com.redhat.insights.InsightsSubreport;
import com.redhat.insights.config.InsightsConfiguration;
import com.redhat.insights.core.TopLevelReportBaseImpl;
import com.redhat.insights.jars.ClasspathJarInfoSubreport;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.AppInsightsSubreport;
import com.redhat.insights.reports.InsightsSubreport;
import java.util.Map;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* Copyright (C) Red Hat 2022-2023 */
package com.redhat.insights.core;
package com.redhat.insights.core.reports;

import com.redhat.insights.AbstractTopLevelReportBase;
import com.redhat.insights.InsightsSubreport;
import com.redhat.insights.config.InsightsConfiguration;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.AbstractTopLevelReportBase;
import com.redhat.insights.reports.InsightsSubreport;
import java.util.*;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import com.redhat.insights.core.app.AppTopLevelReport;
import com.redhat.insights.core.httpclient.HttpResponseBase;
import com.redhat.insights.core.httpclient.MockInsightsJdkHttpClient;
import com.redhat.insights.core.reports.AppTopLevelReport;
import com.redhat.insights.doubles.MockInsightsConfiguration;
import com.redhat.insights.doubles.NoopInsightsLogger;
import com.redhat.insights.tls.PEMSupport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import static org.junit.jupiter.api.Assertions.*;

import com.redhat.insights.config.EnvAndSysPropsInsightsConfiguration;
import com.redhat.insights.core.app.AppInsightsSubreport;
import com.redhat.insights.core.app.AppTopLevelReport;
import com.redhat.insights.core.reports.AppTopLevelReport;
import com.redhat.insights.jars.ClasspathJarInfoSubreport;
import com.redhat.insights.jars.JarInfo;
import com.redhat.insights.logging.PrintLogger;
import com.redhat.insights.reports.AppInsightsSubreport;
import java.util.Map;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import com.redhat.insights.InsightsReport;
import com.redhat.insights.config.InsightsConfiguration;
import com.redhat.insights.core.app.AppTopLevelReport;
import com.redhat.insights.core.reports.AppTopLevelReport;
import com.redhat.insights.doubles.DummyTopLevelReport;
import com.redhat.insights.doubles.MockInsightsConfiguration;
import com.redhat.insights.doubles.NoopInsightsLogger;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsReport;
import com.redhat.insights.tls.PEMSupport;
import java.io.File;
import java.io.IOException;
Expand Down
Loading

0 comments on commit 41e8906

Please sign in to comment.