Search in sources :

Example 1 with SimpleArtifactDelta

use of org.eclipse.tycho.zipcomparator.internal.SimpleArtifactDelta in project tycho by eclipse.

the class CompoundArtifactDeltaTest method testGetDetailedMessage.

@Test
public void testGetDetailedMessage() {
    Map<String, ArtifactDelta> manifest = new TreeMap<>();
    manifest.put("name1", new SimpleArtifactDelta("present in baseline only"));
    Map<String, ArtifactDelta> main = new TreeMap<>();
    main.put("path/file1", new SimpleArtifactDelta("different"));
    main.put("path/file2", new SimpleArtifactDelta("not present in baseline"));
    main.put("META-INF/MANIFEST.MF", new CompoundArtifactDelta("different", manifest));
    Map<String, ArtifactDelta> delta = new TreeMap<>();
    delta.put("<main>", new CompoundArtifactDelta("different", main));
    delta.put("sources", new SimpleArtifactDelta("different"));
    ArtifactDelta subject = new CompoundArtifactDelta("Baseline and reactor artifacts have the same version but different contents", delta);
    String expected = // 
    "Baseline and reactor artifacts have the same version but different contents\n" + // 
    "   <main>: different\n" + // 
    "      META-INF/MANIFEST.MF: different\n" + // 
    "         name1: present in baseline only\n" + // 
    "      path/file1: different\n" + // 
    "      path/file2: not present in baseline\n" + "   sources: different\n";
    Assert.assertEquals(expected, subject.getDetailedMessage());
}
Also used : CompoundArtifactDelta(org.eclipse.tycho.zipcomparator.internal.CompoundArtifactDelta) SimpleArtifactDelta(org.eclipse.tycho.zipcomparator.internal.SimpleArtifactDelta) ArtifactDelta(org.eclipse.tycho.artifactcomparator.ArtifactDelta) CompoundArtifactDelta(org.eclipse.tycho.zipcomparator.internal.CompoundArtifactDelta) TreeMap(java.util.TreeMap) SimpleArtifactDelta(org.eclipse.tycho.zipcomparator.internal.SimpleArtifactDelta) Test(org.junit.Test)

Example 2 with SimpleArtifactDelta

use of org.eclipse.tycho.zipcomparator.internal.SimpleArtifactDelta in project tycho by eclipse.

the class BaselineValidator method getDelta.

private CompoundArtifactDelta getDelta(BaselineService baselineService, Map<String, IP2Artifact> baselineMetadata, Map<String, IP2Artifact> generatedMetadata, MojoExecution execution) throws IOException {
    Map<String, ArtifactDelta> result = new LinkedHashMap<>();
    // baseline never includes more artifacts
    for (Entry<String, IP2Artifact> classifierEntry : generatedMetadata.entrySet()) {
        // the following types of artifacts are produced/consumed by tycho as of 0.16
        // - bundle jar and jar.pack.gz artifacts
        // - feature jar artifacts
        // - feature rootfiles zip artifacts
        String classifier = classifierEntry.getKey();
        if (RepositoryLayoutHelper.PACK200_CLASSIFIER.equals(classifier)) {
            // but bundle jar files are the same, the build will silently use baseline pack200 file
            continue;
        }
        String deltaKey = classifier != null ? "classifier-" + classifier : "no-classifier";
        IP2Artifact baselineArtifact = baselineMetadata.get(classifier);
        IP2Artifact reactorArtifact = classifierEntry.getValue();
        if (baselineArtifact == null) {
            result.put(deltaKey, new MissingArtifactDelta());
            continue;
        }
        if (!baselineService.isMetadataEqual(baselineArtifact, reactorArtifact)) {
            result.put(deltaKey, new SimpleArtifactDelta("p2 metadata different"));
            continue;
        }
        try {
            ArtifactDelta delta = zipComparator.getDelta(baselineArtifact.getLocation(), reactorArtifact.getLocation(), execution);
            if (delta != null) {
                result.put(deltaKey, delta);
            }
        } catch (IOException e) {
            // do byte-to-byte comparison if jar comparison fails for whatever reason
            if (!FileUtils.contentEquals(baselineArtifact.getLocation(), reactorArtifact.getLocation())) {
                result.put(deltaKey, new SimpleArtifactDelta("different"));
            }
        }
    }
    return !result.isEmpty() ? new CompoundArtifactDelta("baseline and build artifacts have same version but different contents", result) : null;
}
Also used : CompoundArtifactDelta(org.eclipse.tycho.zipcomparator.internal.CompoundArtifactDelta) ArtifactDelta(org.eclipse.tycho.artifactcomparator.ArtifactDelta) SimpleArtifactDelta(org.eclipse.tycho.zipcomparator.internal.SimpleArtifactDelta) CompoundArtifactDelta(org.eclipse.tycho.zipcomparator.internal.CompoundArtifactDelta) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) IOException(java.io.IOException) SimpleArtifactDelta(org.eclipse.tycho.zipcomparator.internal.SimpleArtifactDelta) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArtifactDelta (org.eclipse.tycho.artifactcomparator.ArtifactDelta)2 CompoundArtifactDelta (org.eclipse.tycho.zipcomparator.internal.CompoundArtifactDelta)2 SimpleArtifactDelta (org.eclipse.tycho.zipcomparator.internal.SimpleArtifactDelta)2 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1 IP2Artifact (org.eclipse.tycho.p2.metadata.IP2Artifact)1 Test (org.junit.Test)1