Skip to content

Commit

Permalink
close #53, do not create source remapped dirs, create dest remapped dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrengelman committed Jun 27, 2014
1 parent 279572b commit a791252
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ v1.0.0
+ Properly configure the ShadowJar task inputs to observe the include/excludes from the `dependencies` block. This
allows UP-TO-DATE checking to work properly when changing the `dependencies` rules ([Issue #54](https://github.com/johnrengelman/shadow/issues/54))
+ Apply relocation remappings to classes and imports in source project ([Issue #55](https://github.com/johnrengelman/shadow/issues/55))
+ Do not create directories in jar for source of remapped class, created directories in jar for destination of remapped classes ([Issue #53](https://github.com/johnrengelman/shadow/issues/53))

v0.9.0-M5
=========
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.github.jengelman.gradle.plugins.shadow.impl

import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction.RelativeArchivePath
import org.objectweb.asm.commons.Remapper

import java.util.regex.Matcher
Expand Down Expand Up @@ -99,4 +100,12 @@ class RelocatorRemapper extends Remapper {
return value
}

String mapPath(String path) {
map(path.substring(0, path.indexOf('.')))
}

String mapPath(RelativeArchivePath path) {
mapPath(path.pathString)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public class ShadowCopyAction implements CopyAction {
}
filteredArchivePaths.each { RelativeArchivePath relativePath ->
if (!relativePath.file) {
visitArchiveDirectory(relativePath)
// visitArchiveDirectory(relativePath)
} else {
visitArchiveFile(relativePath, archive)
}
Expand Down Expand Up @@ -219,8 +219,18 @@ public class ShadowCopyAction implements CopyAction {
}
}

private void addParentDirectories(RelativeArchivePath file) {
if (file) {
addParentDirectories(file.parent)
if (!file.file) {
visitArchiveDirectory(file)
}
}
}

private void remapClass(RelativeArchivePath file, ZipFile archive) {
if (file.classFile) {
addParentDirectories(new RelativeArchivePath(new ZipEntry(remapper.mapPath(file) + '.class'), null))
remapClass(archive.getInputStream(file.entry), file.pathString)
}
}
Expand Down Expand Up @@ -253,7 +263,7 @@ public class ShadowCopyAction implements CopyAction {
byte[] renamedClass = cw.toByteArray()

// Need to take the .class off for remapping evaluation
String mappedName = remapper.map(path.substring(0, path.indexOf('.')))
String mappedName = remapper.mapPath(path)

try {
// Now we put it back on so the class file is written out with the right extension.
Expand All @@ -266,6 +276,7 @@ public class ShadowCopyAction implements CopyAction {
}

private void copyArchiveEntry(RelativeArchivePath archiveFile, ZipFile archive) {
addParentDirectories(archiveFile)
zipOutStr.putNextEntry(archiveFile.entry)
IOUtils.copyLarge(archive.getInputStream(archiveFile.entry), zipOutStr)
zipOutStr.closeEntry()
Expand Down Expand Up @@ -311,6 +322,18 @@ public class ShadowCopyAction implements CopyAction {
boolean isClassFile() {
return lastName.endsWith('.class')
}

RelativeArchivePath getParent() {
if (!segments) {
return null
} else if (segments.length == 1) {
return new RelativeArchivePath(new ZipEntry('/'), null)
} else {
//Parent is always a directory so add / to the end of the path
String path = segments[0..-2].join('/') + '/'
return new RelativeArchivePath(new ZipEntry(path), null)
}
}
}

class ArchiveFileTreeElement implements FileTreeElement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class RelocationSpec extends PluginSpecification {
])
}

@Issue('SHADOW-55')
@Issue(['SHADOW-55', 'SHADOW-53'])
def "remap class names for relocated files in project source"() {
given:
buildFile << """
Expand Down Expand Up @@ -179,10 +179,12 @@ class RelocationSpec extends PluginSpecification {
contains(output, [
'shadow/ShadowTest.class',
'shadow/junit/Test.class',
'shadow/junit'
])

and:
doesNotContain(output, [
'junit/framework',
'junit/framework/Test.class'
])

Expand Down

0 comments on commit a791252

Please sign in to comment.