io.github.pmckeown.dependencytrack.finding.FindingsAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dependency-track-maven-plugin Show documentation
Show all versions of dependency-track-maven-plugin Show documentation
Maven plugin to integrate with a Dependency Track server to submit dependency manifests and gather project metrics.
package io.github.pmckeown.dependencytrack.finding;
import io.github.pmckeown.dependencytrack.DependencyTrackException;
import io.github.pmckeown.dependencytrack.Response;
import io.github.pmckeown.dependencytrack.project.Project;
import io.github.pmckeown.util.Logger;
import kong.unirest.UnirestException;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@Singleton
public class FindingsAction {
private FindingsClient findingClient;
private Logger logger;
@Inject
public FindingsAction(FindingsClient findingClient, Logger logger) {
this.findingClient = findingClient;
this.logger = logger;
}
List getFindings(Project project) throws DependencyTrackException {
logger.info("Getting findings for project %s-%s", project.getName(), project.getVersion());
try {
Response> response = findingClient.getFindingsForProject(project);
Optional> body = response.getBody();
if (response.isSuccess()) {
if (body.isPresent()) {
return body.get();
} else {
logger.info("No findings available for project %s-%s", project.getName(),
project.getVersion());
return Collections.emptyList();
}
} else {
throw new DependencyTrackException("Error received from server");
}
} catch (UnirestException ex) {
logger.error(ex.getMessage());
throw new DependencyTrackException(ex.getMessage());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy