Skip to content

Commit 473aeb5

Browse files
authored
refactor: remove duplicate DependencyAggregator from JavaMavenProvider (#389)
refactor: remove duplicate DependencyAggregator from JavaMavenProvider
1 parent 82256ac commit 473aeb5

File tree

2 files changed

+10
-74
lines changed

2 files changed

+10
-74
lines changed

src/main/java/io/github/guacsec/trustifyda/providers/BaseJavaProvider.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ PackageURL toPurl() {
196196
}
197197
}
198198

199+
/** Creates a PackageURL without version for coordinate-based matching. */
200+
PackageURL toPurlWithoutVersion() {
201+
try {
202+
return new PackageURL(
203+
Ecosystem.Type.MAVEN.getType(), groupId, artifactId, null, null, null);
204+
} catch (MalformedPackageURLException e) {
205+
throw new IllegalArgumentException("Unable to parse PackageURL", e);
206+
}
207+
}
208+
199209
@Override
200210
public boolean equals(Object o) {
201211
if (this == o) return true;

src/main/java/io/github/guacsec/trustifyda/providers/JavaMavenProvider.java

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static io.github.guacsec.trustifyda.impl.ExhortApi.debugLoggingIsNeeded;
2020

21-
import com.github.packageurl.MalformedPackageURLException;
2221
import com.github.packageurl.PackageURL;
2322
import io.github.guacsec.trustifyda.Api;
2423
import io.github.guacsec.trustifyda.Provider;
@@ -40,7 +39,6 @@
4039
import java.util.List;
4140
import java.util.Map;
4241
import java.util.Objects;
43-
import java.util.TreeMap;
4442
import java.util.logging.Level;
4543
import java.util.logging.Logger;
4644
import java.util.stream.Collectors;
@@ -431,78 +429,6 @@ private List<String> buildMvnCommandArgs(String... baseArgs) {
431429
return args;
432430
}
433431

434-
// NOTE if we want to include "scope" tags in ignore,
435-
// add property here and a case in the start-element-switch in the getIgnored method
436-
437-
/** Aggregator class for aggregating Dependency data over stream iterations, * */
438-
private static final class DependencyAggregator {
439-
private String scope = "*";
440-
private String groupId;
441-
private String artifactId;
442-
private String version;
443-
boolean ignored = false;
444-
445-
/**
446-
* Get the string representation of the dependency to use as excludes
447-
*
448-
* @return an exclude string for the dependency:tree plugin, i.e. group-id:artifact-id:*:version
449-
*/
450-
@Override
451-
public String toString() {
452-
// NOTE if you add scope, don't forget to replace the * with its value
453-
return String.format("%s:%s:%s:%s", groupId, artifactId, scope, version);
454-
}
455-
456-
public boolean isValid() {
457-
return Objects.nonNull(groupId) && Objects.nonNull(artifactId) && Objects.nonNull(version);
458-
}
459-
460-
public boolean isTestDependency() {
461-
return scope.trim().equals("test");
462-
}
463-
464-
public PackageURL toPurl() {
465-
try {
466-
return new PackageURL(
467-
Type.MAVEN.getType(),
468-
groupId,
469-
artifactId,
470-
version,
471-
this.scope.equals("*") ? null : new TreeMap<>(Map.of("scope", this.scope)),
472-
null);
473-
} catch (MalformedPackageURLException e) {
474-
throw new IllegalArgumentException("Unable to parse PackageURL", e);
475-
}
476-
}
477-
478-
/** Creates a PackageURL without version for coordinate-based matching. */
479-
public PackageURL toPurlWithoutVersion() {
480-
try {
481-
return new PackageURL(Type.MAVEN.getType(), groupId, artifactId, null, null, null);
482-
} catch (MalformedPackageURLException e) {
483-
throw new IllegalArgumentException("Unable to parse PackageURL", e);
484-
}
485-
}
486-
487-
@Override
488-
public boolean equals(Object o) {
489-
if (this == o) return true;
490-
if (!(o instanceof DependencyAggregator)) return false;
491-
var that = (DependencyAggregator) o;
492-
// NOTE we do not compare the ignored field
493-
// This is required for comparing pom.xml with effective_pom.xml as the latter doesn't
494-
// contain comments indicating ignore
495-
return Objects.equals(this.groupId, that.groupId)
496-
&& Objects.equals(this.artifactId, that.artifactId)
497-
&& Objects.equals(this.version, that.version);
498-
}
499-
500-
@Override
501-
public int hashCode() {
502-
return Objects.hash(groupId, artifactId, version);
503-
}
504-
}
505-
506432
private String selectMvnRuntime(final Path manifestPath) {
507433
boolean preferWrapper = Operations.getWrapperPreference(MVN);
508434
if (preferWrapper && manifestPath != null) {

0 commit comments

Comments
 (0)