Skip to content

Commit

Permalink
[[JENKINS-16301] Use a buffered input stream to get somewhat better p…
Browse files Browse the repository at this point in the history
…erformance also from Maven archiving.

Introducing Util.getDigestOf(File) as a convenience.
Originally-Committed-As: 11953750ab422bcec28d12a436867d0888313aaa
  • Loading branch information
jglick committed Jul 24, 2013
1 parent da7f61f commit db2b691
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/main/java/hudson/maven/ExecutedMojo.java
Expand Up @@ -30,7 +30,6 @@
import hudson.util.ReflectionUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -101,7 +100,7 @@ public ExecutedMojo(MojoInfo mojo, long duration) {
if (clazz!=null) {
File jarFile = Which.jarFile(clazz);
if (jarFile.isFile()) {
digest = Util.getDigestOf(new FileInputStream(jarFile));
digest = Util.getDigestOf(jarFile);
} else {
// Maybe mojo was loaded from a classes dir instead of from a jar (JENKINS-5044)
LOGGER.log(Level.WARNING, "Cannot calculate digest of mojo class, because mojo wasn't loaded from a jar, but from: "
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/hudson/maven/reporters/MavenArtifact.java
Expand Up @@ -48,7 +48,6 @@
import org.kohsuke.stapler.export.ExportedBean;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
Expand Down Expand Up @@ -119,7 +118,7 @@ public MavenArtifact(Artifact a) throws IOException {
this.classifier = a.getClassifier();
this.type = a.getType();
this.fileName = a.getFile().getName();
this.md5sum = Util.getDigestOf(new FileInputStream(a.getFile()));
this.md5sum = Util.getDigestOf(a.getFile());
String extension;
if(a.getArtifactHandler()!=null) // don't know if this can be null, but just to be defensive.
extension = a.getArtifactHandler().getExtension();
Expand Down
Expand Up @@ -33,7 +33,6 @@
import org.apache.maven.project.MavenProject;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -99,7 +98,7 @@ public boolean postBuild(MavenBuildProxy build, MavenProject pom, final BuildLis
if (pom.getFile() != null) {// goals like 'clean' runs without loading POM, apparently.
// record POM
final MavenArtifact pomArtifact = new MavenArtifact(
pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), null, "pom", pom.getFile().getName(), Util.getDigestOf(new FileInputStream(pom.getFile())));
pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), null, "pom", pom.getFile().getName(), Util.getDigestOf(pom.getFile()));

final String repositoryUrl = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getUrl());
final String repositoryId = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getId());
Expand Down

0 comments on commit db2b691

Please sign in to comment.