Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the new artifacts hashing algorithm #1280

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

shs96c
Copy link
Collaborator

@shs96c shs96c commented Nov 7, 2024

No description provided.

@shs96c shs96c requested review from jin and cheister as code owners November 7, 2024 18:01
@shs96c shs96c force-pushed the new-artifacts-hash branch from 4bf9b05 to 1526bbe Compare November 13, 2024 15:45
@shs96c shs96c force-pushed the new-artifacts-hash branch 2 times, most recently from 375945f to c0b40e3 Compare November 25, 2024 13:48
@shs96c shs96c force-pushed the new-artifacts-hash branch from c0b40e3 to 26571a7 Compare December 2, 2024 15:34
@@ -57,17 +57,30 @@ def unpack_coordinates(coords):
def _is_version_number(part):
return part[0].isdigit()

def _unpack_if_necssary(coords):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo error

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed.

@@ -45,7 +45,7 @@ public void shouldRenderAggregatingJarsAsJarWithNullShasum() {
Set.of(),
new TreeMap<>());

Map<String, Object> rendered = new V2LockFile(repos, Set.of(aggregator), Set.of()).render();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please name -1 as a constant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

import java.util.TreeSet;
import java.util.stream.Collectors;

public class ArtifactsHash {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: final, javadoc

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also added copyright notice.

for (DependencyInfo info : infos) {
StringBuilder line = new StringBuilder();
line.append(info.getCoordinates().toString())
.append(" | ")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: name this separator

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// utility class
}

public static int calculateArtifactsHash(Collection<DependencyInfo> infos) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this format/spec need to be versioned?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so: we're working on the DependencyInfo at this point, and we can reconstruct that from either lock file format.

}

groupId = Objects.requireNonNull(parts[0]);
artifactId = Objects.requireNonNull(parts[1]);

boolean isGradle =
coordinates.contains("@")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can non-gradle coordinates contain @?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, a non-gradle coordinate can contain an @ character, but the Maven folks recommend against it: https://maven.apache.org/guides/mini/guide-naming-conventions.html

I've never seen one in the wild, and I think it's reasonable to tell people to use the Gradle format if it's something they really need.

}

groupId = Objects.requireNonNull(parts[0]);
artifactId = Objects.requireNonNull(parts[1]);

boolean isGradle =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document this constructor formally on what formats are accepted. It's getting a bit harder to understand this code, and AFAIUC, we are trying to use this to canonicalize the format, so some documentation will be useful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I have added a little white-lie about how we handle a:b:c, but I'll create a follow up PR to make that true.

artifacts = _get_artifacts(lock_file_contents)

for artifact in artifacts:
line = "%s | %s | " % (to_external_form(artifact["coordinates"]), artifact["sha256"] if artifact["sha256"] else "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to mention that the format should also be updated in tandem with ArtifactsHash.java.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also added a very similar comment to ArtifactsHash.java

@jin
Copy link
Collaborator

jin commented Dec 5, 2024

Also please update the PR description with more details on why this is happening.

@shs96c shs96c force-pushed the new-artifacts-hash branch from 47b1557 to 2df9618 Compare December 18, 2024 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants