Skip to content

Commit

Permalink
[fix] fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Magnus Viernickel <magnus.viernickel@wire.com>
  • Loading branch information
MangoIV committed Mar 18, 2024
1 parent 1e00857 commit 965fbc3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@
<scope>compile</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.brotli/dec -->
<dependency>
<groupId>org.brotli</groupId>
<artifactId>dec</artifactId>
<version>0.1.2</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
Expand Down Expand Up @@ -410,7 +417,6 @@
<version>2.35.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.http.client.utils.URIBuilder;
import org.brotli.dec.BrotliInputStream;

Check notice on line 28 in src/main/java/org/dependencytrack/tasks/repositories/NixpkgsMetaAnalyzer.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/java/org/dependencytrack/tasks/repositories/NixpkgsMetaAnalyzer.java#L28

Unused import - org.brotli.dec.BrotliInputStream.
import org.dependencytrack.exception.MetaAnalyzerException;
import org.dependencytrack.model.Component;
import org.dependencytrack.model.RepositoryType;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.stream.Collectors;

Check notice on line 40 in src/main/java/org/dependencytrack/tasks/repositories/NixpkgsMetaAnalyzer.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/java/org/dependencytrack/tasks/repositories/NixpkgsMetaAnalyzer.java#L40

Unused import - java.util.stream.Collectors.

public class NixpkgsMetaAnalyzer extends AbstractMetaAnalyzer {
private static final Logger LOGGER = Logger.getLogger(NixpkgsMetaAnalyzer.class);
Expand All @@ -51,20 +55,17 @@ private NixpkgsMetaAnalyzer() {
try (final CloseableHttpClient client = HttpClients.createDefault()) {
try (final CloseableHttpResponse packagesResponse = processHttpRequest5(client)) {
if (packagesResponse != null && packagesResponse.getCode() == HttpStatus.SC_OK) {
final var entity = packagesResponse.getEntity();
if (entity != null) {
// TODO(mangoiv): is this the fastest way we can do this?
final var entityString = EntityUtils.toString(entity);
final var packages = new JSONObject(entityString).getJSONObject("packages").toMap().values();
packages.forEach(pkg -> {
// FUTUREWORK(mangoiv): there are potentially packages with the same pname
if (pkg instanceof HashMap jsonPkg) {
final var pname = jsonPkg.get("pname");
final var version = jsonPkg.get("version");
newLatestVersion.putIfAbsent((String) pname, (String) version);
}
});
}
var reader = new BufferedReader(new InputStreamReader(packagesResponse.getEntity().getContent()));
var packages = new JSONObject(new JSONTokener(reader)).getJSONObject("packages").toMap().values();
packages.forEach(pkg -> {
// FUTUREWORK(mangoiv): there are potentially packages with the same pname
if (pkg instanceof HashMap jsonPkg) {
final var pname = jsonPkg.get("pname");
final var version = jsonPkg.get("version");
newLatestVersion.putIfAbsent((String) pname, (String) version);
}
});


}
}
Expand Down

0 comments on commit 965fbc3

Please sign in to comment.