diff options
3 files changed, 35 insertions, 15 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java index 96d9ff973..c02dc4925 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2016 IBM Corporation and others. + * Copyright (c) 2007, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,9 +15,14 @@ package org.eclipse.equinox.spi.p2.publisher; import java.io.File; +import java.io.IOException; import java.util.*; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.metadata.ArtifactKey; import org.eclipse.equinox.internal.p2.metadata.BasicVersion; +import org.eclipse.equinox.internal.p2.publisher.Activator; import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumProducer; import org.eclipse.equinox.p2.metadata.*; import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription; @@ -106,11 +111,17 @@ public class PublisherHelper { if (pathOnDisk != null) { descriptor.setProperty(IArtifactDescriptor.ARTIFACT_SIZE, Long.toString(pathOnDisk.length())); descriptor.setProperty(IArtifactDescriptor.DOWNLOAD_SIZE, Long.toString(pathOnDisk.length())); - } - if (info == null || (info.getArtifactOptions() & IPublisherInfo.A_NO_MD5) == 0) { - String md5 = ChecksumProducer.computeMD5(pathOnDisk); - if (md5 != null) - descriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, md5); + if (info == null || (info.getArtifactOptions() & IPublisherInfo.A_NO_MD5) == 0) { + try { + String md5 = ChecksumProducer.computeMD5(pathOnDisk); + if (md5 != null) + descriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, md5); + } catch (IOException e) { + // don't care if failed to compute checksum + // TODO provide message? + LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "", e)); + } + } } } return result; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java index 8932e357c..fbd0cb0bf 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2015 IBM Corporation and others. + * Copyright (c) 2009, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,10 +13,12 @@ package org.eclipse.equinox.p2.internal.repository.tools; import java.io.File; +import java.io.IOException; import java.net.URI; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository; +import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumProducer; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.metadata.IArtifactKey; @@ -118,9 +120,15 @@ public class RecreateRepositoryApplication extends AbstractApplication { newDescriptor.setProperty(IArtifactDescriptor.ARTIFACT_SIZE, size); newDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_SIZE, size); - String md5 = ChecksumProducer.computeMD5(artifactFile); - if (md5 != null) - newDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, md5); + try { + String md5 = ChecksumProducer.computeMD5(artifactFile); + if (md5 != null) + newDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, md5); + } catch (IOException e) { + // don't care if failed to compute checksum + // TODO provide message? + LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "", e)); + } File temp = new File(artifactFile.getParentFile(), artifactFile.getName() + ".pack.gz"); //$NON-NLS-1$ if (temp.exists()) { diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java index 4296a53fa..fc8cabec6 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java @@ -18,9 +18,12 @@ import java.security.NoSuchAlgorithmException; public class ChecksumProducer { - public static String computeMD5(File file) { - if (file == null || file.isDirectory() || !file.exists()) - return null; + /** + * @param file should not be <code>null</code> + * @return MD5 checksum of the file or <code>null</code> in case of NoSuchAlgorithmException + * @throws IOException + */ + public static String computeMD5(File file) throws IOException { InputStream fis = null; try { MessageDigest md5Checker = MessageDigest.getInstance("MD5"); //$NON-NLS-1$ @@ -41,8 +44,6 @@ public class ChecksumProducer { return buf.toString(); } catch (NoSuchAlgorithmException e) { return null; - } catch (IOException e) { - return null; } finally { if (fis != null) try { |