mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-22 00:59:34 +01:00
Corrected duplicate code identified by CPD
Former-commit-id: 223a20b4a61a69a6dd0714e1683633dd73eb4302
This commit is contained in:
@@ -17,9 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck.maven;
|
package org.owasp.dependencycheck.maven;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
@@ -28,10 +26,7 @@ import org.apache.maven.plugin.MojoFailureException;
|
|||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||||
import org.owasp.dependencycheck.data.nexus.MavenArtifact;
|
|
||||||
import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
|
import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
|
||||||
import org.owasp.dependencycheck.dependency.Confidence;
|
|
||||||
import org.owasp.dependencycheck.dependency.Dependency;
|
|
||||||
import org.owasp.dependencycheck.utils.Settings;
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,6 +71,7 @@ public class CheckMojo extends BaseDependencyCheckMojo {
|
|||||||
* @throws MojoExecutionException thrown if there is an exception executing the goal
|
* @throws MojoExecutionException thrown if there is an exception executing the goal
|
||||||
* @throws MojoFailureException thrown if dependency-check is configured to fail the build
|
* @throws MojoFailureException thrown if dependency-check is configured to fail the build
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void runCheck() throws MojoExecutionException, MojoFailureException {
|
public void runCheck() throws MojoExecutionException, MojoFailureException {
|
||||||
final Engine engine;
|
final Engine engine;
|
||||||
try {
|
try {
|
||||||
@@ -84,27 +80,7 @@ public class CheckMojo extends BaseDependencyCheckMojo {
|
|||||||
Logger.getLogger(CheckMojo.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(CheckMojo.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
throw new MojoExecutionException("An exception occured connecting to the local database. Please see the log file for more details.", ex);
|
throw new MojoExecutionException("An exception occured connecting to the local database. Please see the log file for more details.", ex);
|
||||||
}
|
}
|
||||||
|
scanArtifacts(getProject(), engine);
|
||||||
final Set<Artifact> artifacts = getProject().getArtifacts();
|
|
||||||
for (Artifact a : artifacts) {
|
|
||||||
if (excludeFromScan(a)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final List<Dependency> deps = engine.scan(a.getFile().getAbsoluteFile());
|
|
||||||
if (deps != null) {
|
|
||||||
if (deps.size() == 1) {
|
|
||||||
final Dependency d = deps.get(0);
|
|
||||||
if (d != null) {
|
|
||||||
final MavenArtifact ma = new MavenArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion());
|
|
||||||
d.addAsEvidence("pom", ma, Confidence.HIGHEST);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
final String msg = String.format("More then 1 dependency was identified in first pass scan of '%s:%s:%s'",
|
|
||||||
a.getGroupId(), a.getArtifactId(), a.getVersion());
|
|
||||||
LOGGER.info(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (engine.getDependencies().isEmpty()) {
|
if (engine.getDependencies().isEmpty()) {
|
||||||
LOGGER.info("No dependencies were identified that could be analyzed by dependency-check");
|
LOGGER.info("No dependencies were identified that could be analyzed by dependency-check");
|
||||||
} else {
|
} else {
|
||||||
@@ -114,7 +90,6 @@ public class CheckMojo extends BaseDependencyCheckMojo {
|
|||||||
showSummary(engine.getDependencies());
|
showSummary(engine.getDependencies());
|
||||||
checkForFailure(engine.getDependencies());
|
checkForFailure(engine.getDependencies());
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.cleanup();
|
engine.cleanup();
|
||||||
Settings.cleanup();
|
Settings.cleanup();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user