Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying warn level messages for file collisions #126

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class ShadowCopyAction implements CopyAction {
private final PatternSet patternSet
private final ShadowStats stats

private Set<String> visitedFiles = new HashSet<String>()
private Map<String, Map> visitedFiles = new HashMap<String, Map>()

public StreamAction(ZipOutputStream zipOutStr, List<Transformer> transformers, List<Relocator> relocators,
PatternSet patternSet, ShadowStats stats) {
Expand All @@ -157,8 +157,25 @@ public class ShadowCopyAction implements CopyAction {
fileDetails.relativePath.pathString.endsWith('.zip')
}

private boolean recordVisit(RelativePath path) {
return visitedFiles.add(path.pathString)
private boolean recordVisit(path, size, originJar) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please using typing on arguments.

if (visitedFiles.containsKey(path.toString())) {
return false
}

if (originJar == null) {
originJar = ""
}

visitedFiles.put(path.toString(), [size: size, originJar: originJar])
return true
}

private boolean recordVisit(path) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument typing.

return recordVisit(path.toString(), 0, null)
}

private boolean recordVisit(FileCopyDetails fileCopyDetails) {
return recordVisit(fileCopyDetails.relativePath, fileCopyDetails.size, null)
}

private void visitFile(FileCopyDetails fileDetails) {
Expand All @@ -180,7 +197,7 @@ public class ShadowCopyAction implements CopyAction {
} else if (isClass) {
remapClass(fileDetails)
}
recordVisit(fileDetails.relativePath)
recordVisit(fileDetails)
} catch (Exception e) {
throw new GradleException(String.format("Could not add %s to ZIP '%s'.", fileDetails, zipFile), e)
}
Expand All @@ -201,29 +218,41 @@ public class ShadowCopyAction implements CopyAction {
}
filteredArchiveElements.each { ArchiveFileTreeElement archiveElement ->
if (archiveElement.relativePath.file) {
visitArchiveFile(archiveElement, archive)
visitArchiveFile(archiveElement, archive, fileDetails)
}
}
archive.close()
stats.finishJar()
}

private void visitArchiveDirectory(RelativeArchivePath archiveDir) {
if (recordVisit(archiveDir)) {
if (recordVisit(archiveDir.toString())) {
zipOutStr.putNextEntry(archiveDir.entry)
zipOutStr.closeEntry()
}
}

private void visitArchiveFile(ArchiveFileTreeElement archiveFile, ZipFile archive) {
private void visitArchiveFile(ArchiveFileTreeElement archiveFile, ZipFile archive, FileCopyDetails fileDetails) {
def archiveFilePath = archiveFile.relativePath
def archiveFileSize = archiveFile.size

if (archiveFile.classFile || !isTransformable(archiveFile)) {
if (recordVisit(archiveFilePath)) {
if (recordVisit(archiveFilePath.toString(), archiveFileSize, fileDetails.relativePath)) {
if (!remapper.hasRelocators() || !archiveFile.classFile) {
copyArchiveEntry(archiveFilePath, archive)
} else {
remapClass(archiveFilePath, archive)
}
} else {
def archiveFileInVisitedFiles = visitedFiles.get(archiveFilePath.toString())
if (archiveFileInVisitedFiles && (archiveFileInVisitedFiles.size != fileDetails.size)) {
log.warn("IGNORING ${archiveFilePath} from ${fileDetails.relativePath}, size is different (${fileDetails.size} vs ${archiveFileInVisitedFiles.size})")
if (archiveFileInVisitedFiles.originJar) {
log.warn(" --> origin JAR was ${archiveFileInVisitedFiles.originJar}")
} else {
log.warn(" --> file originated from project sourcecode")
}
}
}
} else {
transform(archiveFile, archive)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@ class ShadowPluginSpec extends PluginSpecification {
assert output.exists()
}

def 'warns when a file is masked by a previously shadowed resource'() {
given:
URL artifact = this.class.classLoader.getResource('test-artifact-1.0-SNAPSHOT.jar')
URL project = this.class.classLoader.getResource('test-project-1.0-SNAPSHOT.jar')

buildFile << """
|task shadow(type: ${ShadowJar.name}) {
| destinationDir = buildDir
| baseName = 'shadow'
| from('${artifact.path}')
| from('${project.path}')
|}
""".stripMargin()

when:
runner.arguments << 'shadow'
ExecutionResult result = runner.run()

then:
success(result)
assert result.standardOutput =~ /IGNORING META-INF\/MANIFEST\.MF from test-artifact-1\.0-SNAPSHOT\.jar, size is different \(3115 vs 25\)\s --> file originated from project sourcecode/
assert result.standardOutput =~ /IGNORING META-INF\/MANIFEST\.MF from test-project-1\.0-SNAPSHOT\.jar, size is different \(3906 vs 25\)\s --> file originated from project sourcecode/
}

def 'include project sources'() {
given:
file('src/main/java/shadow/Passed.java') << '''
Expand Down