@@ -63,9 +63,10 @@ func main() {
63
63
logging .SetLevel (logging .INFO , "main" )
64
64
}
65
65
66
- jars := listAllJars (targetDir , mode )
66
+ filePaths := listAllFiles (targetDir )
67
+ jars := listAllJars (filePaths , mode )
67
68
keepJars := computeJarsToKeep (jars )
68
- count := cleanJars (clean , jars , keepJars )
69
+ count := cleanJars (clean , filePaths , jars , keepJars )
69
70
70
71
if clean {
71
72
log .Infof ("Total files removed: %d" , count )
@@ -76,18 +77,29 @@ func main() {
76
77
77
78
}
78
79
79
- func listAllJars (targetDir string , mode string ) []JarProperties {
80
- log .Info ( "Finding and parsing JARs" )
80
+ func listAllFiles (targetDir string ) []string {
81
+ log .Infof ( "Listing all files in target directory: %v" , targetDir )
81
82
files , err := ioutil .ReadDir (targetDir )
82
83
if err != nil {
83
84
log .Fatal (err )
84
85
}
85
- jars := []JarProperties {}
86
+ filePaths := []string {}
86
87
for _ , f := range files {
87
- if strings .HasSuffix (f .Name (), ".jar" ) {
88
- log .Debugf ("Processing JAR: %v" , f .Name ())
88
+ if ! f .IsDir () {
89
89
filePath := filepath .Join (targetDir , f .Name ())
90
- jarProp := getJarProps (filePath , mode )
90
+ filePaths = append (filePaths , filePath )
91
+ }
92
+ }
93
+ return filePaths
94
+ }
95
+
96
+ func listAllJars (filePaths []string , mode string ) []JarProperties {
97
+ log .Info ("Finding and parsing JARs" )
98
+ jars := []JarProperties {}
99
+ for _ , f := range filePaths {
100
+ if strings .HasSuffix (f , ".jar" ) {
101
+ log .Debugf ("Processing JAR: %v" , f )
102
+ jarProp := getJarProps (f , mode )
91
103
if strings .Compare (jarProp .filePath , "" ) != 0 {
92
104
jars = append (jars , jarProp )
93
105
}
@@ -294,26 +306,36 @@ func computeJarsToKeep(jars []JarProperties) map[string]JarProperties {
294
306
return keepJars
295
307
}
296
308
297
- func cleanJars (remove bool , jars []JarProperties , keepJars map [string ]JarProperties ) int {
309
+ func cleanJars (remove bool , filePaths [] string , jars []JarProperties , keepJars map [string ]JarProperties ) int {
298
310
log .Info ("Cleaning..." )
299
- count := 0
311
+ jarsCount := 0
312
+ metafilesCount := 0
300
313
for _ , jar := range jars {
301
314
jarToKeep := keepJars [jar .packageName ]
302
315
if strings .Compare (jar .filePath , jarToKeep .filePath ) != 0 {
303
- if _ , err := os .Stat (jar .filePath ); err == nil {
304
- if remove {
305
- log .Warningf ("Removing duplicate of %v: %v" , jar .packageName , jar .fileName )
306
- os .Remove (jar .filePath )
307
- } else {
308
- log .Warningf ("Would remove duplicate of %v: %v" , jar .packageName , jar .fileName )
316
+ for _ , filePath := range filePaths {
317
+ if _ , err := os .Stat (filePath ); err == nil {
318
+ if strings .HasPrefix (filePath , jar .filePath ) {
319
+ if remove {
320
+ log .Warningf ("Removing file %v: %v" , jar .packageName , filePath )
321
+ os .Remove (filePath )
322
+ } else {
323
+ log .Warningf ("Would remove file %v: %v" , jar .packageName , filePath )
324
+ }
325
+ if strings .HasSuffix (filePath , ".jar" ) {
326
+ jarsCount ++
327
+ } else {
328
+ metafilesCount ++
329
+ }
330
+ }
309
331
}
310
- count ++
311
332
}
312
333
} else {
313
334
log .Debugf ("Keeping jar: %v" , jar )
314
335
}
315
336
}
316
- return count
337
+ log .Infof ("Clean up %v jars and %v meta files" , jarsCount , metafilesCount )
338
+ return jarsCount + metafilesCount
317
339
}
318
340
319
341
func convertVersionToNumber (version string ) int {
0 commit comments