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

[JENKINS-66326] Prepare SCM Sync Configuration for core Guava upgrade #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
package hudson.plugins.scm_sync_configuration.utils;

import com.google.common.io.ByteStreams;
import com.google.common.io.Files;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum;

/**
* @author fcamblor
* Utility class allowing to provide easy access to jenkins files checksums
*/
public class Checksums {

private static final int BUF_SIZE = 0x1000; // 4K

public static boolean fileAndByteArrayContentAreEqual(File file, byte[] content) throws IOException {
if(!file.exists()){
return content == null || content.length == 0;
}

long fileChecksum;
CheckedInputStream in = null;
try {
in = new CheckedInputStream(new FileInputStream(file), createChecksum());
byte[] buffer = new byte[BUF_SIZE];
while (in.read(buffer, 0, buffer.length) >= 0) {
// keep updating checksum
}
fileChecksum = in.getChecksum().getValue();
} finally {
if (in != null) {
in.close();
}
}

Checksum checksum = createChecksum();
long fileChecksum = Files.getChecksum(file, checksum);
long contentChecksum = ByteStreams.getChecksum(ByteStreams.newInputStreamSupplier(content), checksum);
checksum.update(content, 0, content.length);
long contentChecksum = checksum.getValue();

return fileChecksum == contentChecksum;
}

Expand Down