diff options
author | Christoph Läubrich | 2022-01-26 14:16:28 +0000 |
---|---|---|
committer | Mickael Istria | 2022-01-27 13:12:53 +0000 |
commit | ad48deb75e775535cf42a0f7c02f0c79406bf63b (patch) | |
tree | 589c88acea8a33d5e10fd7d4ee903e2094527a66 | |
parent | 983059c3b35e12411216c4a3f0f5087f90fcd45a (diff) | |
download | rt.equinox.p2-ad48deb75e775535cf42a0f7c02f0c79406bf63b.tar.gz rt.equinox.p2-ad48deb75e775535cf42a0f7c02f0c79406bf63b.tar.xz rt.equinox.p2-ad48deb75e775535cf42a0f7c02f0c79406bf63b.zip |
Bug 578394 - Add helper methods to PublisherHelper that are more
meaningful to get the bitflags form IPublisherInfo
- add helper methods to PublisherHelper
- adjust the test to give more meaningfull error messages
- let mockito call the default methods
- fix API description
Change-Id: I9d4b6b7d7ab826a0ab699d9514578cfb18f74f56
Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.p2/+/190041
Reviewed-by: Mickael Istria <mistria@redhat.com>
Tested-by: Equinox Bot <equinox-bot@eclipse.org>
7 files changed, 86 insertions, 29 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher/.settings/.api_filters b/bundles/org.eclipse.equinox.p2.publisher/.settings/.api_filters new file mode 100644 index 000000000..5fbae6834 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.publisher/.settings/.api_filters @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<component id="org.eclipse.equinox.p2.publisher" version="2"> + <resource path="META-INF/MANIFEST.MF"> + <filter id="926941240"> + <message_arguments> + <message_argument value="1.7.0"/> + <message_argument value="1.6.200"/> + </message_arguments> + </filter> + </resource> +</component> diff --git a/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF index 2568eeee2..693d9e66b 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-SymbolicName: org.eclipse.equinox.p2.publisher;singleton:=true -Bundle-Version: 1.6.200.qualifier +Bundle-Version: 1.7.0.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.publisher.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.publisher/pom.xml b/bundles/org.eclipse.equinox.p2.publisher/pom.xml index aa9c72cd8..9e05ebad8 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/pom.xml +++ b/bundles/org.eclipse.equinox.p2.publisher/pom.xml @@ -9,6 +9,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.p2.publisher</artifactId> - <version>1.6.200-SNAPSHOT</version> + <version>1.7.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java index 497a8a261..5f1dc9d42 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java @@ -504,7 +504,7 @@ public abstract class AbstractPublisherAction implements IPublisherAction { // if all we are doing is indexing things then add the descriptor and get on // with it - if ((publisherInfo.getArtifactOptions() & IPublisherInfo.A_PUBLISH) == 0) { + if (!PublisherHelper.isArtifactPublish(publisherInfo)) { destination.addDescriptor(descriptor, new NullProgressMonitor()); return; } @@ -556,7 +556,7 @@ public abstract class AbstractPublisherAction implements IPublisherAction { return; // if all we are doing is indexing things then add the descriptor and get on // with it - if ((publisherInfo.getArtifactOptions() & IPublisherInfo.A_PUBLISH) == 0) { + if (!PublisherHelper.isArtifactPublish(publisherInfo)) { destination.addDescriptor(descriptor, new NullProgressMonitor()); return; } diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/IPublisherInfo.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/IPublisherInfo.java index 0e88610aa..33796f507 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/IPublisherInfo.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/IPublisherInfo.java @@ -8,8 +8,8 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: + * + * Contributors: * Code 9 - initial API and implementation * IBM - ongoing development ******************************************************************************/ @@ -40,7 +40,7 @@ public interface IPublisherInfo { public static final int A_OVERWRITE = 4; /** - * A bitwise flag indicating that MD5 hash should not be generated when + * A bitwise flag indicating that MD5 hash should not be generated when * publishing an artifact. When this flag is not specified the MD5 hash will * be generated by default. */ @@ -61,9 +61,9 @@ public interface IPublisherInfo { public IMetadataRepository getMetadataRepository(); /** - * Returns whether or not artifacts themselves should be published. - * @return <code>true</code> if artifacts should be published. - * <code>false</code> otherwise. + * Returns a bitflag that controls the publish operation, what is a bitwhise OR + * of {@link #A_INDEX},{@value #A_PUBLISH}, {@link #A_NO_MD5}, + * {@link #A_OVERWRITE} or <code>0</code> if no flags are set. */ public int getArtifactOptions(); @@ -80,7 +80,7 @@ public interface IPublisherInfo { public <T extends IPublisherAdvice> Collection<T> getAdvice(String configSpec, boolean includeDefault, String id, Version version, Class<T> type); /** - * Add the given advice to the set of publishing advices. + * Add the given advice to the set of publishing advices. * @param advice the advice to retain */ public void addAdvice(IPublisherAdvice advice); @@ -95,19 +95,19 @@ public interface IPublisherInfo { public String[] getConfigurations(); /** - * Returns the artifact repository given to the publisher as context for - * the publisher actions. May be <code>null</code>. Note that multiple + * Returns the artifact repository given to the publisher as context for + * the publisher actions. May be <code>null</code>. Note that multiple * repositories may be represented as one composite repository. - * + * * @return the context artifact repository or <code>null</code> if none. */ public IArtifactRepository getContextArtifactRepository(); /** - * Returns the metadata repository given to the publisher as context for - * the publisher actions. May be <code>null</code>. Note that multiple + * Returns the metadata repository given to the publisher as context for + * the publisher actions. May be <code>null</code>. Note that multiple * repositories may be represented as one composite repository. - * + * * @return the context metadata repository or <code>null</code> if none. */ public IMetadataRepository getContextMetadataRepository(); 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 d62b50b90..f074794b7 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 @@ -112,7 +112,7 @@ public class PublisherHelper { descriptor.setProperty(IArtifactDescriptor.ARTIFACT_SIZE, Long.toString(pathOnDisk.length())); descriptor.setProperty(IArtifactDescriptor.DOWNLOAD_SIZE, Long.toString(pathOnDisk.length())); - boolean generateChecksums = info == null || (info.getArtifactOptions() & IPublisherInfo.A_NO_MD5) == 0; + boolean generateChecksums = info == null || isArtifactGenerateChecksums(info); if (generateChecksums) { calculateChecksums(pathOnDisk, descriptor); } @@ -252,4 +252,49 @@ public class PublisherHelper { return new VersionRange(min, includeMin, max, includeMax); } + + /** + * + * @return <code>true</code> if md5 sums should be generated <code>false</code> + * otherwise + * @since 1.7.0 + */ + public static boolean isArtifactGenerateChecksums(IPublisherInfo publisherInfo) { + if ((publisherInfo.getArtifactOptions() & IPublisherInfo.A_NO_MD5) != 0) { + return false; + } + return true; + } + + /** + * + * @return <code>true</code> if existing artifacts should be overwritten + * <code>false</code> otherwise + * @since 1.7.0 + */ + public static boolean isArtifactOverwrite(IPublisherInfo publisherInfo) { + return (publisherInfo.getArtifactOptions() & IPublisherInfo.A_OVERWRITE) != 0; + } + + /** + * + * @return <code>true</code> if artifacts should published <code>false</code> + * otherwise + * @since 1.7.0 + */ + public static boolean isArtifactPublish(IPublisherInfo publisherInfo) { + int artifactOptions = publisherInfo.getArtifactOptions(); + return artifactOptions == 0 || (artifactOptions & IPublisherInfo.A_PUBLISH) != 0; + } + + /** + * + * @return <code>true</code> if the artifact index should be updated + * <code>false</code> otherwise + * @since 1.7.0 + */ + public static boolean isArtifactIndex(IPublisherInfo publisherInfo) { + int artifactOptions = publisherInfo.getArtifactOptions(); + return artifactOptions == 0 || (artifactOptions & IPublisherInfo.A_INDEX) != 0; + } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestData.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestData.java index c423c5dd5..d2a8bc870 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestData.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestData.java @@ -135,15 +135,16 @@ public class TestData { * @throws IOException */ public static void assertEquals(ZipInputStream expected, ZipInputStream actual) throws IOException { - Map<String, Object[]> jar1 = getEntries(expected); - Map<String, Object[]> jar2 = getEntries(actual); - for (String name : jar1.keySet()) { - Object[] file1 = jar1.get(name); - Object[] file2 = jar2.remove(name); - Assert.assertNotNull(file2); - - ZipEntry entry1 = (ZipEntry) file1[0]; - ZipEntry entry2 = (ZipEntry) file2[0]; + Map<String, Object[]> expectedEntries = getEntries(expected); + Map<String, Object[]> actualEntries = getEntries(actual); + for (String name : expectedEntries.keySet()) { + Object[] expectedFiles = expectedEntries.get(name); + Object[] actualFiles = actualEntries.remove(name); + Assert.assertNotNull(name + " entry is missing in actual zip stream (actual=" + actualEntries.keySet() + + ", expected=" + expectedEntries.keySet() + ")", actualFiles); + + ZipEntry entry1 = (ZipEntry) expectedFiles[0]; + ZipEntry entry2 = (ZipEntry) actualFiles[0]; // compare the entries Assert.assertEquals(entry1.getName(), entry2.getName()); Assert.assertEquals(entry1.getSize(), entry2.getSize()); @@ -154,11 +155,11 @@ public class TestData { Assert.assertEquals(entry1.getMethod(), entry2.getMethod()); // check the content of the entries - Assert.assertArrayEquals((byte[]) file1[1], (byte[]) file2[1]); + Assert.assertArrayEquals((byte[]) expectedFiles[1], (byte[]) actualFiles[1]); } // ensure that we have consumed all of the entries in the second JAR - Assert.assertEquals(0, jar2.size()); + Assert.assertEquals(0, actualEntries.size()); } /** |