Skip to content

Commit

Permalink
Fix PluginFingerprint for plugin with dependencies
Browse files Browse the repository at this point in the history
Fixes #1073
  • Loading branch information
tisoft committed Jan 7, 2022
1 parent 59051ff commit c2df929
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 DiffPlug
* Copyright 2021-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,9 +17,12 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Objects;

import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;

Expand Down Expand Up @@ -77,6 +80,10 @@ public String toString() {
}

private static byte[] digest(Plugin plugin, Iterable<Formatter> formatters) {
List<Dependency> dependencies = plugin.getDependencies();
// dependencies can be an unserializable org.apache.maven.model.merge.ModelMerger$MergingList
// replace it with a serializable ArrayList
plugin.setDependencies(new ArrayList<>(dependencies));
try (ObjectDigestOutputStream out = ObjectDigestOutputStream.create()) {
out.writeObject(plugin);
for (Formatter formatter : formatters) {
Expand All @@ -86,6 +93,9 @@ private static byte[] digest(Plugin plugin, Iterable<Formatter> formatters) {
return out.digest();
} catch (IOException e) {
throw new UncheckedIOException("Unable to serialize plugin " + plugin, e);
} finally {
// reset the original list
plugin.setDependencies(dependencies);
}
}
}

0 comments on commit c2df929

Please sign in to comment.