blob: 4969d48943c3dfa22b05d5b2c6400908d9380300 [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
Colin Cross7f19f372016-11-01 11:10:25 -070020 "github.com/google/blueprint/bootstrap"
21
Colin Cross635c3b02016-05-18 15:37:25 -070022 "android/soong/android"
Colin Cross2fe66872015-03-30 17:20:39 -070023)
24
25var resourceExcludes = []string{
Colin Cross3d7678f2015-04-24 15:16:39 -070026 "**/*.java",
27 "**/package.html",
28 "**/overview.html",
29 "**/.*.swp",
30 "**/.DS_Store",
31 "**/*~",
Colin Cross2fe66872015-03-30 17:20:39 -070032}
33
Dan Willemsen2ef08f42015-06-30 18:15:24 -070034func 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 Cross40a36712017-09-27 17:41:35 -070043func ResourceDirsToJarArgs(ctx android.ModuleContext,
44 resourceDirs, excludeDirs []string) (args []string, deps android.Paths) {
Colin Cross3d7678f2015-04-24 15:16:39 -070045 var excludes []string
Colin Cross2fe66872015-03-30 17:20:39 -070046
Dan Willemsen2ef08f42015-06-30 18:15:24 -070047 for _, exclude := range excludeDirs {
Colin Cross635c3b02016-05-18 15:37:25 -070048 excludes = append(excludes, android.PathForModuleSrc(ctx, exclude, "**/*").String())
Colin Cross3d7678f2015-04-24 15:16:39 -070049 }
50
51 excludes = append(excludes, resourceExcludes...)
52
Colin Cross3d7678f2015-04-24 15:16:39 -070053 for _, resourceDir := range resourceDirs {
Dan Willemsen2ef08f42015-06-30 18:15:24 -070054 if isStringInSlice(resourceDir, excludeDirs) {
Colin Cross3d7678f2015-04-24 15:16:39 -070055 continue
56 }
Colin Cross635c3b02016-05-18 15:37:25 -070057 resourceDir := android.PathForModuleSrc(ctx, resourceDir)
Colin Cross7f19f372016-11-01 11:10:25 -070058 dirs := ctx.Glob(resourceDir.String(), nil)
Colin Cross3d7678f2015-04-24 15:16:39 -070059 for _, dir := range dirs {
Colin Cross635c3b02016-05-18 15:37:25 -070060 fileListFile := android.ResPathWithName(ctx, dir, "resources.list")
Dan Willemsen34cc69e2015-09-23 15:26:20 -070061 depFile := fileListFile.String() + ".d"
Colin Cross3d7678f2015-04-24 15:16:39 -070062
Colin Cross7f19f372016-11-01 11:10:25 -070063 pattern := filepath.Join(dir.String(), "**/*")
64 bootstrap.GlobFile(ctx, pattern, excludes, fileListFile.String(), depFile)
Colin Cross40a36712017-09-27 17:41:35 -070065 args = append(args,
66 "-C", dir.String(),
67 "-l", fileListFile.String())
68 deps = append(deps, fileListFile)
Colin Cross3d7678f2015-04-24 15:16:39 -070069 }
Colin Cross2fe66872015-03-30 17:20:39 -070070 }
71
Colin Cross40a36712017-09-27 17:41:35 -070072 return args, deps
Colin Cross2fe66872015-03-30 17:20:39 -070073}