Allow some duplicates in merged jars
Only take the first MANIFEST.MF or module-info.class file. Test: m -j checkbuild Change-Id: Ifbf9fe272437ef2c2bd51ab4849ac8d7ef37b6fc
This commit is contained in:
@@ -28,7 +28,7 @@ import (
|
||||
|
||||
var (
|
||||
sortEntries = flag.Bool("s", false, "sort entries (defaults to the order from the input zip files)")
|
||||
sortJava = flag.Bool("j", false, "sort zip entries using jar ordering (META-INF first)")
|
||||
emulateJar = flag.Bool("j", false, "sort zip entries using jar ordering (META-INF first)")
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -76,7 +76,7 @@ func main() {
|
||||
}
|
||||
|
||||
// do merge
|
||||
if err := mergeZips(readers, writer, *sortEntries, *sortJava); err != nil {
|
||||
if err := mergeZips(readers, writer, *sortEntries, *emulateJar); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ type fileMapping struct {
|
||||
dest string
|
||||
}
|
||||
|
||||
func mergeZips(readers []namedZipReader, writer *zip.Writer, sortEntries bool, sortJava bool) error {
|
||||
func mergeZips(readers []namedZipReader, writer *zip.Writer, sortEntries bool, emulateJar bool) error {
|
||||
|
||||
mappingsByDest := make(map[string]fileMapping, 0)
|
||||
orderedMappings := []fileMapping{}
|
||||
@@ -128,24 +128,33 @@ func mergeZips(readers []namedZipReader, writer *zip.Writer, sortEntries bool, s
|
||||
source := zipEntry{path: zipEntryPath{zipName: namedReader.path, entryName: file.Name}, content: file}
|
||||
newMapping := fileMapping{source: source, dest: dest}
|
||||
|
||||
// handle duplicates
|
||||
if exists {
|
||||
// handle duplicates
|
||||
wasDir := existingMapping.source.content.FileHeader.FileInfo().IsDir()
|
||||
isDir := newMapping.source.content.FileHeader.FileInfo().IsDir()
|
||||
if !wasDir || !isDir {
|
||||
if wasDir != isDir {
|
||||
return fmt.Errorf("Directory/file mismatch at %v from %v and %v\n",
|
||||
dest, existingMapping.source.path, newMapping.source.path)
|
||||
}
|
||||
if emulateJar &&
|
||||
file.Name == jar.ManifestFile || file.Name == jar.ModuleInfoClass {
|
||||
// Skip manifest and module info files that are not from the first input file
|
||||
continue
|
||||
}
|
||||
if !isDir {
|
||||
return fmt.Errorf("Duplicate path %v found in %v and %v\n",
|
||||
dest, existingMapping.source.path, newMapping.source.path)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// save entry
|
||||
mappingsByDest[mapKey] = newMapping
|
||||
orderedMappings = append(orderedMappings, newMapping)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if sortJava {
|
||||
if emulateJar {
|
||||
jarSort(orderedMappings)
|
||||
} else if sortEntries {
|
||||
alphanumericSort(orderedMappings)
|
||||
|
@@ -62,9 +62,6 @@ type byteReaderCloser struct {
|
||||
io.Closer
|
||||
}
|
||||
|
||||
// the file path in the zip at which a Java manifest file gets written
|
||||
const manifestDest = "META-INF/MANIFEST.MF"
|
||||
|
||||
type fileArg struct {
|
||||
pathPrefixInZip, sourcePrefixToStrip string
|
||||
sourceFiles []string
|
||||
@@ -360,7 +357,7 @@ func (z *zipWriter) write(out string, pathMappings []pathMapping, manifest strin
|
||||
if !*emulateJar {
|
||||
return errors.New("must specify --jar when specifying a manifest via -m")
|
||||
}
|
||||
pathMappings = append(pathMappings, pathMapping{manifestDest, manifest, zip.Deflate})
|
||||
pathMappings = append(pathMappings, pathMapping{jar.ManifestFile, manifest, zip.Deflate})
|
||||
}
|
||||
|
||||
if *emulateJar {
|
||||
@@ -372,7 +369,7 @@ func (z *zipWriter) write(out string, pathMappings []pathMapping, manifest strin
|
||||
defer close(z.writeOps)
|
||||
|
||||
for _, ele := range pathMappings {
|
||||
if *emulateJar && ele.dest == manifestDest {
|
||||
if *emulateJar && ele.dest == jar.ManifestFile {
|
||||
err = z.addManifest(ele.dest, ele.src, ele.zipMethod)
|
||||
} else {
|
||||
err = z.addFile(ele.dest, ele.src, ele.zipMethod)
|
||||
|
12
jar/jar.go
12
jar/jar.go
@@ -19,6 +19,12 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
MetaDir = "META-INF/"
|
||||
ManifestFile = MetaDir + "MANIFEST.MF"
|
||||
ModuleInfoClass = "module-info.class"
|
||||
)
|
||||
|
||||
// EntryNamesLess tells whether <filepathA> should precede <filepathB> in
|
||||
// the order of files with a .jar
|
||||
func EntryNamesLess(filepathA string, filepathB string) (less bool) {
|
||||
@@ -39,9 +45,9 @@ func patternMatch(pattern, name string) bool {
|
||||
}
|
||||
|
||||
var jarOrder = []string{
|
||||
"META-INF/",
|
||||
"META-INF/MANIFEST.MF",
|
||||
"META-INF/*",
|
||||
MetaDir,
|
||||
ManifestFile,
|
||||
MetaDir + "*",
|
||||
"*",
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user