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

[tycho-4.0.x] Fix NPE in MavenChecksumAdvice #3757

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,51 @@
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;

public class MavenChecksumAdvice implements IPropertyAdvice {
//We use a fixed list here of default supported ones, actually one can provide a ChecksumAlgorithmFactory to extend the default algorithms
Map<String, String> mavenExtensions = Map.of(//
".md5", "download.checksum.md5", //
".sha1", "download.checksum.sha-1", //
".sha256", "download.checksum.sha-256", //
".sha512", "download.checksum.sha-512" //
);
// We use a fixed list here of default supported ones, actually one can provide
// a ChecksumAlgorithmFactory to extend the default algorithms
Map<String, String> mavenExtensions = Map.of(//
".md5", "download.checksum.md5", //
".sha1", "download.checksum.sha-1", //
".sha256", "download.checksum.sha-256", //
".sha512", "download.checksum.sha-512" //
);

private File artifactFile;
private File artifactFile;

public MavenChecksumAdvice(File artifactFile) {
this.artifactFile = artifactFile;
}
public MavenChecksumAdvice(File artifactFile) {
this.artifactFile = artifactFile;
}

@Override
public Map<String, String> getInstallableUnitProperties(InstallableUnitDescription iu) {
return Collections.emptyMap();
}
@Override
public Map<String, String> getInstallableUnitProperties(InstallableUnitDescription iu) {
return Collections.emptyMap();
}

@Override
public Map<String, String> getArtifactProperties(IInstallableUnit iu, IArtifactDescriptor descriptor) {
if (descriptor instanceof ArtifactDescriptor artifactDescriptor) {
// Workaround bug Bug 539672
String baseName = artifactFile.getName();
for (var entry : mavenExtensions.entrySet()) {
File file = new File(artifactFile.getParentFile(), baseName + entry.getKey());
if (file.isFile()) {
try {
String checksum = Files.readString(file.toPath(), StandardCharsets.US_ASCII).strip();
artifactDescriptor.setProperty(entry.getValue(), checksum);
} catch (IOException e) {
//can't use the checksum then...
}
}
}
}
return null;
}
@Override
public Map<String, String> getArtifactProperties(IInstallableUnit iu, IArtifactDescriptor descriptor) {
if (artifactFile != null) {
if (descriptor instanceof ArtifactDescriptor artifactDescriptor) {
// Workaround bug Bug 539672
String baseName = artifactFile.getName();
for (var entry : mavenExtensions.entrySet()) {
File file = new File(artifactFile.getParentFile(), baseName + entry.getKey());
if (file.isFile()) {
try {
String checksum = Files.readString(file.toPath(), StandardCharsets.US_ASCII).strip();
artifactDescriptor.setProperty(entry.getValue(), checksum);
} catch (IOException e) {
// can't use the checksum then...
}
}
}
}
}
return null;
}

@Override
public boolean isApplicable(String configSpec, boolean includeDefault, String id, Version version) {
return true;
}
@Override
public boolean isApplicable(String configSpec, boolean includeDefault, String id, Version version) {
return true;
}

}
Loading