Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 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 | |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame^] | 20 | "github.com/google/blueprint/bootstrap" |
| 21 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 22 | "android/soong/android" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | var resourceExcludes = []string{ |
Colin Cross | 3d7678f | 2015-04-24 15:16:39 -0700 | [diff] [blame] | 26 | "**/*.java", |
| 27 | "**/package.html", |
| 28 | "**/overview.html", |
| 29 | "**/.*.swp", |
| 30 | "**/.DS_Store", |
| 31 | "**/*~", |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 34 | func isStringInSlice(str string, slice []string) bool { |
| 35 | for _, s := range slice { |
| 36 | if s == str { |
| 37 | return true |
| 38 | } |
| 39 | } |
| 40 | return false |
| 41 | } |
| 42 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 43 | func ResourceDirsToJarSpecs(ctx android.ModuleContext, resourceDirs, excludeDirs []string) []jarSpec { |
Colin Cross | 3d7678f | 2015-04-24 15:16:39 -0700 | [diff] [blame] | 44 | var excludes []string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 45 | |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 46 | for _, exclude := range excludeDirs { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 47 | excludes = append(excludes, android.PathForModuleSrc(ctx, exclude, "**/*").String()) |
Colin Cross | 3d7678f | 2015-04-24 15:16:39 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | excludes = append(excludes, resourceExcludes...) |
| 51 | |
| 52 | var jarSpecs []jarSpec |
| 53 | |
| 54 | for _, resourceDir := range resourceDirs { |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 55 | if isStringInSlice(resourceDir, excludeDirs) { |
Colin Cross | 3d7678f | 2015-04-24 15:16:39 -0700 | [diff] [blame] | 56 | continue |
| 57 | } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 58 | resourceDir := android.PathForModuleSrc(ctx, resourceDir) |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame^] | 59 | dirs := ctx.Glob(resourceDir.String(), nil) |
Colin Cross | 3d7678f | 2015-04-24 15:16:39 -0700 | [diff] [blame] | 60 | for _, dir := range dirs { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 61 | fileListFile := android.ResPathWithName(ctx, dir, "resources.list") |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 62 | depFile := fileListFile.String() + ".d" |
Colin Cross | 3d7678f | 2015-04-24 15:16:39 -0700 | [diff] [blame] | 63 | |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame^] | 64 | pattern := filepath.Join(dir.String(), "**/*") |
| 65 | bootstrap.GlobFile(ctx, pattern, excludes, fileListFile.String(), depFile) |
Colin Cross | 3d7678f | 2015-04-24 15:16:39 -0700 | [diff] [blame] | 66 | jarSpecs = append(jarSpecs, jarSpec{fileListFile, dir}) |
| 67 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | return jarSpecs |
| 71 | } |