Skip to content

Commit

Permalink
fix: Dependency ID fixed FIXED (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniotarricone authored May 30, 2023
1 parent f3882ae commit 72273f5
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 97 deletions.
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>it.pagopa.maven</groupId>
<artifactId>depcheck</artifactId>
<version>1.0.4</version>
<version>1.0.7-RC</version>
<packaging>maven-plugin</packaging>

<description>This Maven plugin generates and verifies sha256 of project dependencies</description>
Expand All @@ -23,19 +23,21 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven-plugin-plugin.version>3.8.1</maven-plugin-plugin.version>
<jacoco-maven-plugin.version>0.8.10</jacoco-maven-plugin.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.8.1</version>
<version>${maven-plugin-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<version>${jacoco-maven-plugin.version}</version>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ protected List<Dependency> retrieveDependencies(MavenProject specProject) {
try {
String sha256 = "";
if (a.getFile() == null) {
getLog().warn(String.format("SHA-256 of %s:%s:%s cannot be computed.", a.getGroupId(), a.getArtifactId(), a.getVersion()));
getLog().warn(String.format("SHA-256 of %s cannot be computed.", a.getId()));
} else {
sha256 = Sha256.calculate(a.getFile());
}

Dependency dependency = new Dependency(a.getArtifactId(), a.getGroupId(), a.getVersion(), sha256);
Dependency dependency = new Dependency(a.getId(), a.getArtifactId(), a.getGroupId(), a.getVersion(), sha256);
getLog().info(dependency.toString());
return dependency;
} catch (NoSuchAlgorithmException | IOException e) {
getLog().error(String.format("Error calculating SHA-256 %s:%s:%s.", a.getGroupId(), a.getArtifactId(), a.getVersion()));
getLog().error(String.format("Error calculating SHA-256 %s.", a.getId()));
getLog().error(e);
throw new RuntimeException(e);
}
Expand Down
34 changes: 20 additions & 14 deletions src/main/java/it/pagopa/maven/depcheck/bean/Dependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
* @author Antonio Tarricone
*/
public class Dependency implements Comparable<Dependency> {
/*
*
*/
private String id;

/*
*
*/
Expand Down Expand Up @@ -37,12 +42,14 @@ public Dependency() {
}

/**
* @param id
* @param artifactId
* @param groupId
* @param version
* @param sha256
*/
public Dependency(String artifactId, String groupId, String version, String sha256) {
public Dependency(String id, String artifactId, String groupId, String version, String sha256) {
this.id = id;
this.artifactId = artifactId;
this.groupId = groupId;
this.version = version;
Expand All @@ -57,24 +64,20 @@ public String getSha256() {
}

/**
*
* @return
*/
public String getId() {
return new StringBuilder(groupId)
.append(":")
.append(artifactId)
.append(":")
.append(version)
.toString();
return id;
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return new StringBuilder("Dependency [artifactId=")
return new StringBuilder("Dependency [id=")
.append(id)
.append(", artifactId=")
.append(artifactId)
.append(", groupId=")
.append(groupId)
Expand All @@ -91,13 +94,16 @@ public String toString() {
*/
@Override
public int compareTo(Dependency o) {
int c = groupId.compareTo(o.groupId);
int c = id.compareTo(o.id);
if (c == 0) {
c = artifactId.compareTo(o.artifactId);
c = groupId.compareTo(o.groupId);
if (c == 0) {
c = version.compareTo(o.version);
c = artifactId.compareTo(o.artifactId);
if (c == 0) {
c = sha256.compareTo(o.sha256);
c = version.compareTo(o.version);
if (c == 0) {
c = sha256.compareTo(o.sha256);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import java.io.FileReader;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.stubs.ArtifactStub;
import org.apache.maven.project.MavenProject;

import com.google.gson.GsonBuilder;
Expand All @@ -29,13 +27,15 @@ public class DependenciesDataGeneratorMojoTest extends AbstractMojoTestCase {
* @throws Exception
*/
public void testWoParentWoPluginsHashOk() throws Exception {
Artifact artifact1 = new ArtifactStub();
MyArtifactStub artifact1 = new MyArtifactStub();
artifact1.setId("art_1");
artifact1.setArtifactId("artifact_1");
artifact1.setFile(getTestFile("src/test/resources/unit-test/artifact_1.txt"));
artifact1.setGroupId("group_1");
artifact1.setVersion("version_1");

Artifact artifact2 = new ArtifactStub();
MyArtifactStub artifact2 = new MyArtifactStub();
artifact2.setId("art_2");
artifact2.setArtifactId("artifact_2");
artifact2.setFile(getTestFile("src/test/resources/unit-test/artifact_2.txt"));
artifact2.setGroupId("group_2");
Expand Down Expand Up @@ -79,25 +79,29 @@ public void testWoParentWoPluginsHashOk() throws Exception {
* @throws Exception
*/
public void testWoParentWPluginsHashOk() throws Exception {
Artifact artifact1 = new ArtifactStub();
MyArtifactStub artifact1 = new MyArtifactStub();
artifact1.setId("art_1");
artifact1.setArtifactId("artifact_1");
artifact1.setFile(getTestFile("src/test/resources/unit-test/artifact_1.txt"));
artifact1.setGroupId("group_1");
artifact1.setVersion("version_1");

Artifact artifact2 = new ArtifactStub();
MyArtifactStub artifact2 = new MyArtifactStub();
artifact2.setId("art_2");
artifact2.setArtifactId("artifact_2");
artifact2.setFile(getTestFile("src/test/resources/unit-test/artifact_2.txt"));
artifact2.setGroupId("group_2");
artifact2.setVersion("version_2");

Artifact artifact3 = new ArtifactStub();
MyArtifactStub artifact3 = new MyArtifactStub();
artifact3.setId("art_3");
artifact3.setArtifactId("artifact_3");
artifact3.setFile(getTestFile("src/test/resources/unit-test/artifact_3.txt"));
artifact3.setGroupId("group_3");
artifact3.setVersion("version_3");

Artifact artifact4 = new ArtifactStub();
MyArtifactStub artifact4 = new MyArtifactStub();
artifact4.setId("art_4");
artifact4.setArtifactId("artifact_4");
artifact4.setFile(getTestFile("src/test/resources/unit-test/artifact_4.txt"));
artifact4.setGroupId("group_4");
Expand Down Expand Up @@ -141,37 +145,43 @@ public void testWoParentWPluginsHashOk() throws Exception {
* @throws Exception
*/
public void testWParentWPluginsHashOk() throws Exception {
Artifact artifact1 = new ArtifactStub();
MyArtifactStub artifact1 = new MyArtifactStub();
artifact1.setId("art_1");
artifact1.setArtifactId("artifact_1");
artifact1.setFile(getTestFile("src/test/resources/unit-test/artifact_1.txt"));
artifact1.setGroupId("group_1");
artifact1.setVersion("version_1");

Artifact artifact2 = new ArtifactStub();
MyArtifactStub artifact2 = new MyArtifactStub();
artifact2.setId("art_2");
artifact2.setArtifactId("artifact_2");
artifact2.setFile(getTestFile("src/test/resources/unit-test/artifact_2.txt"));
artifact2.setGroupId("group_2");
artifact2.setVersion("version_2");

Artifact artifact3 = new ArtifactStub();
MyArtifactStub artifact3 = new MyArtifactStub();
artifact3.setId("art_3");
artifact3.setArtifactId("artifact_3");
artifact3.setFile(getTestFile("src/test/resources/unit-test/artifact_3.txt"));
artifact3.setGroupId("group_3");
artifact3.setVersion("version_3");

Artifact artifact4 = new ArtifactStub();
MyArtifactStub artifact4 = new MyArtifactStub();
artifact4.setId("art_4");
artifact4.setArtifactId("artifact_4");
artifact4.setFile(getTestFile("src/test/resources/unit-test/artifact_4.txt"));
artifact4.setGroupId("group_4");
artifact4.setVersion("version_4");

Artifact artifact5 = new ArtifactStub();
MyArtifactStub artifact5 = new MyArtifactStub();
artifact5.setId("art_5");
artifact5.setArtifactId("artifact_5");
artifact5.setFile(getTestFile("src/test/resources/unit-test/artifact_5.txt"));
artifact5.setGroupId("group_5");
artifact5.setVersion("version_5");

Artifact artifact6 = new ArtifactStub();
MyArtifactStub artifact6 = new MyArtifactStub();
artifact6.setId("art_6");
artifact6.setArtifactId("artifact_6");
artifact6.setFile(getTestFile("src/test/resources/unit-test/artifact_6.txt"));
artifact6.setGroupId("group_6");
Expand Down
Loading

0 comments on commit 72273f5

Please sign in to comment.