blob: dfdbeb5dd7fb491657082805fa1e95e17bf0109b [file] [log] [blame]
Colin Cross2fe66872015-03-30 17:20:39 -07001// 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
15package java
16
17import (
18 "path/filepath"
19
20 "android/soong/common"
21)
22
23var resourceExcludes = []string{
Colin Cross3d7678f2015-04-24 15:16:39 -070024 "**/*.java",
25 "**/package.html",
26 "**/overview.html",
27 "**/.*.swp",
28 "**/.DS_Store",
29 "**/*~",
Colin Cross2fe66872015-03-30 17:20:39 -070030}
31
Dan Willemsen2ef08f42015-06-30 18:15:24 -070032func 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
41func ResourceDirsToJarSpecs(ctx common.AndroidModuleContext, resourceDirs, excludeDirs []string) []jarSpec {
Colin Cross3d7678f2015-04-24 15:16:39 -070042 var excludes []string
Colin Cross2fe66872015-03-30 17:20:39 -070043
Dan Willemsen2ef08f42015-06-30 18:15:24 -070044 for _, exclude := range excludeDirs {
45 excludes = append(excludes, filepath.Join(common.ModuleSrcDir(ctx), exclude, "**/*"))
Colin Cross3d7678f2015-04-24 15:16:39 -070046 }
47
48 excludes = append(excludes, resourceExcludes...)
49
50 var jarSpecs []jarSpec
51
52 for _, resourceDir := range resourceDirs {
Dan Willemsen2ef08f42015-06-30 18:15:24 -070053 if isStringInSlice(resourceDir, excludeDirs) {
Colin Cross3d7678f2015-04-24 15:16:39 -070054 continue
55 }
56 resourceDir := filepath.Join(common.ModuleSrcDir(ctx), resourceDir)
Colin Cross8f101b42015-06-17 15:09:06 -070057 dirs := ctx.Glob(resourceDir, nil)
Colin Cross3d7678f2015-04-24 15:16:39 -070058 for _, dir := range dirs {
59 fileListFile := filepath.Join(common.ModuleOutDir(ctx), "res", dir, "resources.list")
60 depFile := fileListFile + ".d"
61
62 glob := filepath.Join(dir, "**/*")
63 common.GlobRule(ctx, glob, excludes, fileListFile, depFile)
64 jarSpecs = append(jarSpecs, jarSpec{fileListFile, dir})
65 }
Colin Cross2fe66872015-03-30 17:20:39 -070066 }
67
68 return jarSpecs
69}