Skip to content

Commit

Permalink
Adapt to removed support for loading pack.gz packaged artifacts in P2
Browse files Browse the repository at this point in the history
Eclipse P2 got its support for loading pack.gz packed artifacts from
repositories finally removed in
eclipse-equinox/p2#310.

In order to fix the tests, remove packed duplicates from and replace
only packed ecf artifact with unpacked eclipse.core.runtime artifact in
test repository at '\resources\repositories\packgz'.
  • Loading branch information
HannesWell committed Dec 9, 2023
1 parent b193066 commit 45575c9
Show file tree
Hide file tree
Showing 22 changed files with 142 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ public void testGetArtifactDescriptorsDoesNotReturnDuplicates() {
List<IArtifactDescriptor> result = Arrays.asList(subject.getArtifactDescriptors(BUNDLE_A_KEY));

assertThat(result, hasItem(inCanonicalFormat()));
assertEquals(2, result.size()); // no duplicates
assertEquals(1, result.size()); // no duplicates
}

@Test
public void testContainsArtifactDescriptor() {
assertTrue(subject.contains(canonicalDescriptorFor(BUNDLE_A_KEY)));
assertFalse(subject.contains(canonicalDescriptorFor(BUNDLE_B_KEY)));
assertTrue(subject.contains(canonicalDescriptorFor(BUNDLE_B_KEY)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -81,28 +82,27 @@ public class LocalArtifactRepositoryP2APITest extends TychoPlexusTestCase {
private static final Set<String> ARTIFACT_A_CONTENT = TestRepositoryContent.BUNDLE_A_FILES;

private static final IArtifactDescriptor ARTIFACT_A_CANONICAL = localCanonicalDescriptorFor(ARTIFACT_A_KEY);
private static final IArtifactDescriptor ARTIFACT_A_PACKED = localPackedDescriptorFor(ARTIFACT_A_KEY);
private static final IArtifactDescriptor ARTIFACT_B_PACKED = localPackedDescriptorFor(ARTIFACT_B_KEY);
// not in the repository!
private static final IArtifactDescriptor ARTIFACT_A_PACKED = localPackedDescriptorFor(ARTIFACT_A_KEY); // not in the repository!
private static final IArtifactDescriptor ARTIFACT_B_CANONICAL = localCanonicalDescriptorFor(ARTIFACT_B_KEY);
private static final IArtifactDescriptor ARTIFACT_B_PACKED = localPackedDescriptorFor(ARTIFACT_B_KEY); // not in the repository!

private static final String ARTIFACT_A_CANONICAL_MD5 = TestRepositoryContent.BUNDLE_A_CONTENT_MD5;

private static final IArtifactDescriptor ARTIFACT_A_DESCRIPTOR_1 = ARTIFACT_A_CANONICAL;
private static final IArtifactDescriptor ARTIFACT_A_DESCRIPTOR_2 = ARTIFACT_A_PACKED;
private static final IArtifactDescriptor ARTIFACT_B_DESCRIPTOR = ARTIFACT_B_PACKED;
private static final IArtifactDescriptor ARTIFACT_A_DESCRIPTOR_2 = ARTIFACT_A_PACKED; // not in the repository!
private static final IArtifactDescriptor ARTIFACT_B_DESCRIPTOR = ARTIFACT_B_CANONICAL;

// not in the repository
private static final IArtifactKey OTHER_KEY = TestRepositoryContent.NOT_CONTAINED_ARTIFACT_KEY;
private static final IArtifactDescriptor OTHER_DESCRIPTOR = ARTIFACT_B_CANONICAL;
private static final IArtifactDescriptor OTHER_DESCRIPTOR = ARTIFACT_B_PACKED;

// not (yet) in the repository
private static final IArtifactKey NEW_KEY = TestRepositoryContent.NOT_CONTAINED_ARTIFACT_KEY;
private static final IArtifactDescriptor NEW_DESCRIPTOR = localPackedDescriptorFor(NEW_KEY);

private static final Set<IArtifactKey> ORIGINAL_KEYS = new HashSet<>(Arrays.asList(ARTIFACT_A_KEY, ARTIFACT_B_KEY));
private static final Set<IArtifactDescriptor> ORIGINAL_DESCRIPTORS = new HashSet<>(
Arrays.asList(ARTIFACT_A_CANONICAL, ARTIFACT_A_PACKED, ARTIFACT_B_PACKED));
private static final Set<IArtifactDescriptor> ORIGINAL_DESCRIPTORS = Set.of( //
ARTIFACT_A_CANONICAL, ARTIFACT_B_CANONICAL);

@Rule
public TemporaryLocalMavenRepository temporaryLocalMavenRepo = new TemporaryLocalMavenRepository();
Expand Down Expand Up @@ -159,8 +159,8 @@ public void testGetDescriptors() {
List<IArtifactDescriptor> result = Arrays.asList(subject.getArtifactDescriptors(ARTIFACT_A_KEY));

assertThat(result, hasItem(ARTIFACT_A_DESCRIPTOR_1));
assertThat(result, hasItem(ARTIFACT_A_DESCRIPTOR_2));
assertEquals(2, result.size());
assertThat(result, not(hasItem(ARTIFACT_A_DESCRIPTOR_2)));
assertEquals(1, result.size());
}

@Test
Expand All @@ -185,7 +185,7 @@ public void testQueryDescriptors() {
Set<IArtifactDescriptor> result = allDescriptorsIn(subject);

assertThat(result, hasItem(ARTIFACT_A_DESCRIPTOR_1));
assertThat(result, hasItem(ARTIFACT_A_DESCRIPTOR_2));
assertThat(result, not(hasItem(ARTIFACT_A_DESCRIPTOR_2)));
assertThat(result, hasItem(ARTIFACT_B_DESCRIPTOR));
assertEquals(ORIGINAL_DESCRIPTORS, result);
}
Expand All @@ -199,24 +199,14 @@ public void testRemoveLastDescriptorOfKey() {
assertTotal(-1, -1);
}

@Test
public void testRemoveOneOfDescriptorsOfKey() {
subject.removeDescriptor(ARTIFACT_A_DESCRIPTOR_1);

assertFalse(subject.contains(ARTIFACT_A_DESCRIPTOR_1));
assertTrue(subject.contains(ARTIFACT_A_DESCRIPTOR_2));
assertTrue(subject.contains(ARTIFACT_A_KEY));
assertTotal(0, -1);
}

@Test
public void testRemoveAllDescriptorsOfKey() {
subject.removeDescriptors(new IArtifactDescriptor[] { ARTIFACT_A_DESCRIPTOR_1, ARTIFACT_A_DESCRIPTOR_2 });

assertFalse(subject.contains(ARTIFACT_A_DESCRIPTOR_1));
assertFalse(subject.contains(ARTIFACT_A_DESCRIPTOR_2));
assertFalse(subject.contains(ARTIFACT_A_KEY));
assertTotal(-1, -2);
assertTotal(-1, -1);
}

@Test
Expand Down Expand Up @@ -244,7 +234,7 @@ public void testRemoveKey() {
assertFalse(subject.contains(ARTIFACT_A_KEY));
assertFalse(subject.contains(ARTIFACT_A_DESCRIPTOR_1));
assertFalse(subject.contains(ARTIFACT_A_DESCRIPTOR_2));
assertTotal(-1, -2);
assertTotal(-1, -1);
}

@Test
Expand All @@ -253,7 +243,7 @@ public void testRemoveKeys() {

assertFalse(subject.contains(ARTIFACT_A_KEY));
assertFalse(subject.contains(ARTIFACT_B_KEY));
assertTotal(-2, -3);
assertTotal(-2, -2);
}

@Test
Expand All @@ -271,7 +261,7 @@ public void testRemoveAll() {

assertTrue(allKeysIn(subject).isEmpty());
assertTrue(allDescriptorsIn(subject).isEmpty());
assertTotal(-2, -3);
assertTotal(-2, -2);
}

@Test
Expand All @@ -288,25 +278,16 @@ public void testGetArtifactFileOfNonContainedKey() {
assertNull(result);
}

@Test
public void testGetArtifactFileOfKeyWithoutCanonicalFormat() {
assertFalse(subject.contains(ARTIFACT_B_CANONICAL)); // self-test

File result = subject.getArtifactFile(ARTIFACT_B_KEY);

assertNull(result);
}

@Test
public void testGetRawArtifactFile() {
File result = subject.getArtifactFile(ARTIFACT_B_PACKED);
File result = subject.getArtifactFile(ARTIFACT_B_CANONICAL);

assertThat(result, is(artifactLocationOf(ARTIFACT_B_KEY, ".jar")));
}

@Test
public void testGetRawArtifactFileOfNonContainedFormat() {
File result = subject.getArtifactFile(ARTIFACT_B_CANONICAL);
File result = subject.getArtifactFile(ARTIFACT_B_PACKED);

assertNull(result);
}
Expand All @@ -333,7 +314,7 @@ public void testGetNonContainedArtifact() throws Exception {
@Test
public void testGetCorruptedArtifact() throws Exception {
// simulate corruption of the artifact in the file system
assertTrue(artifactLocationOf(ARTIFACT_B_KEY, "-pack200.jar.pack.gz").delete()); // this is the only format
assertTrue(artifactLocationOf(ARTIFACT_B_KEY, ".jar").delete()); // this is the only format

testSink = newArtifactSinkFor(ARTIFACT_B_KEY);
status = subject.getArtifact(testSink, null);
Expand Down Expand Up @@ -409,11 +390,11 @@ public void testGetRawArtifactForCanonicalFormat() throws Exception {

@Test
public void testGetRawArtifactOfNonContainedFormat() throws Exception {
assertTrue(subject.contains(ARTIFACT_B_PACKED));
assertFalse(subject.contains(ARTIFACT_B_CANONICAL));
assertTrue(subject.contains(ARTIFACT_B_CANONICAL));
assertFalse(subject.contains(ARTIFACT_B_PACKED));

// getRawArtifact does not convert from packed to canonical format
rawTestSink = newRawArtifactSinkFor(ARTIFACT_B_CANONICAL);
// getRawArtifact does not convert from canonical to packed format
rawTestSink = newRawArtifactSinkFor(ARTIFACT_B_PACKED);
status = subject.getRawArtifact(rawTestSink, null);

assertFalse(rawTestSink.writeIsStarted());
Expand All @@ -424,7 +405,7 @@ public void testGetRawArtifactOfNonContainedFormat() throws Exception {
@Test
public void testGetCorruptedRawArtifact() throws Exception {
// simulate corruption of the artifact in the file system
assertTrue(artifactLocationOf(ARTIFACT_B_KEY, "-pack200.jar.pack.gz").delete());
assertTrue(artifactLocationOf(ARTIFACT_B_KEY, ".jar").delete());

rawTestSink = newRawArtifactSinkFor(ARTIFACT_B_PACKED);
status = subject.getRawArtifact(rawTestSink, null);
Expand All @@ -450,10 +431,10 @@ public void testGetRawArtifactForCanonicalFormatToStream() throws Exception {
@SuppressWarnings("deprecation")
@Test
public void testGetRawArtifactOfNonContainedFormatToStream() {
assertFalse(subject.contains(ARTIFACT_B_CANONICAL));
assertFalse(subject.contains(ARTIFACT_B_PACKED));

// getRawArtifact does not convert from packed to canonical format
status = subject.getRawArtifact(ARTIFACT_B_CANONICAL, testOutputStream, null);
// getRawArtifact does not convert from canonical to packed format
status = subject.getRawArtifact(ARTIFACT_B_PACKED, testOutputStream, null);

assertEquals(0, testOutputStream.writtenBytes());
assertThat(testOutputStream.getStatus(), is(errorStatus())); // from IStateful
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.eclipse.tycho.test.util.ProbeArtifactSink.newArtifactSinkFor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;

import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
Expand All @@ -36,7 +37,7 @@

public class MirroringArtifactProviderErrorTest extends TychoPlexusTestCase {

private static final IArtifactKey CORRUPT_ARTIFACT = TestRepositoryContent.BUNDLE_B_KEY;
private static final IArtifactKey CORRUPT_ARTIFACT = TestRepositoryContent.BUNDLE_A_KEY;

@Rule
public LogVerifier logVerifier = new LogVerifier();
Expand All @@ -58,19 +59,15 @@ public void before() throws Exception {
new MockMavenContext(null, logVerifier.getLogger()));
}

@Test(expected = MirroringFailedException.class)
@Test
public void testMirrorCorruptArtifact() throws Exception {
logVerifier.expectError(CORRUPT_ARTIFACT.toString());

testSink = newArtifactSinkFor(CORRUPT_ARTIFACT);
try {
// here we expect an exception, an not (!) an error status, to be consistent with other methods that mirror but don't return a status
subject.getArtifact(testSink, null);

} finally {
assertNotMirrored(CORRUPT_ARTIFACT);
assertFalse(testSink.writeIsStarted());
}
// here we expect an exception, an not (!) an error status, to be consistent with other methods that mirror but don't return a status
assertThrows(MirroringFailedException.class, () -> subject.getArtifact(testSink, null));
assertNotMirrored(CORRUPT_ARTIFACT);
assertFalse(testSink.writeIsStarted());
}

private void assertNotMirrored(IArtifactKey key) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public final class TestRepositoryContent {

public static final IArtifactKey BUNDLE_A_KEY = new ArtifactKey("osgi.bundle", "org.eclipse.osgi",
Version.parseVersion("3.4.3.R34x_v20081215-1030"));
public static final IArtifactKey BUNDLE_B_KEY = new ArtifactKey("osgi.bundle", "org.eclipse.ecf",
Version.parseVersion("3.1.300.v20120319-0616"));
public static final IArtifactKey BUNDLE_B_KEY = new ArtifactKey("osgi.bundle", "org.eclipse.swt",
Version.parseVersion("3.6.1.v3655c"));

public static final Set<String> BUNDLE_A_FILES = new HashSet<>(Arrays.asList("about_files/", "META-INF/",
"META-INF/MANIFEST.MF", "org/", "org/eclipse/", "org/eclipse/core/", "org/eclipse/core/runtime/",
Expand Down Expand Up @@ -73,13 +73,10 @@ public final class TestRepositoryContent {
// repositories (of regular p2 type) containing the test data

/** Repository with bundle A */
public static final URI REPO_BUNDLE_A = P2Repositories.ECLIPSE_342.toURI();
public static final URI REPO_BUNDLE_A = ResourceUtil.resourceFile("repositories/e342").toURI();
public static final URI REPO2_BUNDLE_A = ResourceUtil.resourceFile("repositories2/e342").toURI();
/**
* Repository with bundles A and B. Bundle A is available both in packed and canonical format,
* bundle B only in packed format.
*/
public static final URI REPO_BUNDLE_AB = P2Repositories.PACK_GZ.toURI();
/** Repository with bundles A and B. Both bundles are available in canonical format. */
public static final URI REPO_BUNDLE_AB = ResourceUtil.resourceFile("repositories/e342_3").toURI();

/** Repository that claims to contain bundle A, but accesses to the artifact file will fail */
public static final URI REPO_BUNDLE_A_CORRUPT = ResourceUtil.resourceFile("repositories/e342_missing_file").toURI();
Expand All @@ -88,7 +85,7 @@ public final class TestRepositoryContent {
* format, but the artifact is broken. Bundle A is contained in packed format (artifact missing)
* and in canonical format (working).
*/
public static final URI REPO_BUNLDE_AB_PACK_CORRUPT = ResourceUtil.resourceFile("repositories/packgz_corrupt")
public static final URI REPO_BUNLDE_AB_PACK_CORRUPT = ResourceUtil.resourceFile("repositories/e342_corrupt")
.toURI();

}
30 changes: 30 additions & 0 deletions tycho-core/src/test/resources/repositories/e342_3/artifacts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version='1.0' encoding='UTF-8'?>
<?artifactRepository version='1.1.0'?>
<repository name='e342_3' type='org.eclipse.equinox.p2.artifact.repository.simpleRepository' version='1'>
<properties size='2'>
<property name='p2.compressed' value='false'/>
<property name='p2.timestamp' value='1338060413228'/>
</properties>
<mappings size='3'>
<rule filter='(&amp; (classifier=osgi.bundle))' output='${repoUrl}/plugins/${id}_${version}.jar'/>
<rule filter='(&amp; (classifier=binary))' output='${repoUrl}/binary/${id}_${version}'/>
<rule filter='(&amp; (classifier=org.eclipse.update.feature))' output='${repoUrl}/features/${id}_${version}.jar'/>
</mappings>
<artifacts size='2'>
<artifact id="org.eclipse.swt" classifier="osgi.bundle" version="3.6.1.v3655c">
<properties size="3">
<property name="artifact.size" value="17322" />
<property name="download.size" value="17322" />
<property name="download.md5" value="128d988d0d080d841e455f31c0d91285" />
</properties>
</artifact>
<artifact classifier='osgi.bundle' id='org.eclipse.osgi' version='3.4.3.R34x_v20081215-1030'>
<properties size='4'>
<property name='artifact.size' value='11034'/>
<property name='download.size' value='11034'/>
<property name='download.md5' value='58057045158895009b845b9a93f3eb6e'/>
<property name='download.contentType' value='application/zip'/>
</properties>
</artifact>
</artifacts>
</repository>
Loading

0 comments on commit 45575c9

Please sign in to comment.