Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Fix duplicate files in distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed May 6, 2020
1 parent c96b3b7 commit f51e26c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 3 deletions.
29 changes: 26 additions & 3 deletions dist/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ distributions {
include 'gradle/*'
include 'gradle.properties'
}
rootProject.subprojects.each {
include it.projectDir.name + '/src/**'
include it.projectDir.name + '/build.gradle'
rootProject.subprojects.each { s ->
into(s.name) {
if (project != s) {
from s.sourcesJar.outputs.files.collect {
zipTree(it)
}
}
from s.projectDir.toPath().resolve("build.gradle")
}
}
}
}
Expand Down Expand Up @@ -131,6 +137,15 @@ distributions {
}
}

rootProject.subprojects.each {
if (it != project) {
project.distZip.dependsOn it.assemble
project.distTar.dependsOn it.assemble
project.sourcesDistZip.dependsOn it.sourcesJar
project.sourcesDistTar.dependsOn it.sourcesJar
}
}

sourcesDistZip { zip64 = true }

distTar{ compression = Compression.GZIP }
Expand Down Expand Up @@ -186,3 +201,11 @@ task buildRelayerImage(type: DockerBuildImage) {
dockerFile = file("docker/relayer.Dockerfile")
tag = "apache-tuweni/relayer:$project.version"
}
integrationTest.dependsOn build

dependencies {
integrationTestCompile 'org.junit.jupiter:junit-jupiter-api'
integrationTestCompile 'org.junit.jupiter:junit-jupiter-params'

integrationTestRuntime 'org.junit.jupiter:junit-jupiter-engine'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
* file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
* to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.apache.tuweni.dist;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.junit.jupiter.api.Test;

/**
* Tests no duplicate entries are present in the distribution zip file.
*/
class DistributionTest {

private static Path distributionsFolder() {
File currentFile = new File(DistributionTest.class.getProtectionDomain().getCodeSource().getLocation().getPath());
// dist/build/classes/java/org/apache/tuweni/dist
Path parentFolder = currentFile.toPath();
while (!"dist".equals(parentFolder.getFileName().toString()) && parentFolder.getParent() != null) {
parentFolder = parentFolder.getParent();
}
return parentFolder.resolve("build/distributions");
}

@Test
void testZipFileContents() throws IOException {
Map<String, Set<String>> dupes = new HashMap<>();
boolean foundOneZipFile = false;
for (File archive : distributionsFolder().toFile().listFiles()) {
if (archive.getName().endsWith(".zip")) {
foundOneZipFile = true;
Set<String> duplicates = new HashSet<>();
Set<String> files = new HashSet<>();
try (ZipFile zip = new ZipFile(archive)) {
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!files.add(entry.getName())) {
duplicates.add(entry.getName());
dupes.putIfAbsent(archive.getName(), duplicates);
}
}
}

}
}
assertTrue(foundOneZipFile);
for (Map.Entry<String, Set<String>> entry : dupes.entrySet()) {
System.out.println("Archive :" + entry.getKey());
for (String file : entry.getValue()) {
System.out.println("\t-" + file);
}
}
assertTrue(dupes.isEmpty());
}
}

0 comments on commit f51e26c

Please sign in to comment.