1 // Copyright 2015 Google Inc. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package java 16 17 import ( 18 "path/filepath" 19 20 "android/soong/common" 21 ) 22 23 var resourceExcludes = []string{ 24 "**/*.java", 25 "**/package.html", 26 "**/overview.html", 27 "**/.*.swp", 28 "**/.DS_Store", 29 "**/*~", 30 } 31 32 func isStringInSlice(str string, slice []string) bool { 33 for _, s := range slice { 34 if s == str { 35 return true 36 } 37 } 38 return false 39 } 40 41 func ResourceDirsToJarSpecs(ctx common.AndroidModuleContext, resourceDirs, excludeDirs []string) []jarSpec { 42 var excludes []string 43 44 for _, exclude := range excludeDirs { 45 excludes = append(excludes, common.PathForModuleSrc(ctx, exclude, "**/*").String()) 46 } 47 48 excludes = append(excludes, resourceExcludes...) 49 50 var jarSpecs []jarSpec 51 52 for _, resourceDir := range resourceDirs { 53 if isStringInSlice(resourceDir, excludeDirs) { 54 continue 55 } 56 resourceDir := common.PathForModuleSrc(ctx, resourceDir) 57 dirs := ctx.Glob("java_resources", resourceDir.String(), nil) 58 for _, dir := range dirs { 59 fileListFile := common.ResPathWithName(ctx, dir, "resources.list") 60 depFile := fileListFile.String() + ".d" 61 62 glob := filepath.Join(dir.String(), "**/*") 63 common.GlobRule(ctx, glob, excludes, fileListFile.String(), depFile) 64 jarSpecs = append(jarSpecs, jarSpec{fileListFile, dir}) 65 } 66 } 67 68 return jarSpecs 69 } 70