Home | History | Annotate | Download | only in java
      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 	"github.com/google/blueprint/bootstrap"
     21 
     22 	"android/soong/android"
     23 )
     24 
     25 var resourceExcludes = []string{
     26 	"**/*.java",
     27 	"**/package.html",
     28 	"**/overview.html",
     29 	"**/.*.swp",
     30 	"**/.DS_Store",
     31 	"**/*~",
     32 }
     33 
     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 
     43 func ResourceDirsToJarSpecs(ctx android.ModuleContext, resourceDirs, excludeDirs []string) []jarSpec {
     44 	var excludes []string
     45 
     46 	for _, exclude := range excludeDirs {
     47 		excludes = append(excludes, android.PathForModuleSrc(ctx, exclude, "**/*").String())
     48 	}
     49 
     50 	excludes = append(excludes, resourceExcludes...)
     51 
     52 	var jarSpecs []jarSpec
     53 
     54 	for _, resourceDir := range resourceDirs {
     55 		if isStringInSlice(resourceDir, excludeDirs) {
     56 			continue
     57 		}
     58 		resourceDir := android.PathForModuleSrc(ctx, resourceDir)
     59 		dirs := ctx.Glob(resourceDir.String(), nil)
     60 		for _, dir := range dirs {
     61 			fileListFile := android.ResPathWithName(ctx, dir, "resources.list")
     62 			depFile := fileListFile.String() + ".d"
     63 
     64 			pattern := filepath.Join(dir.String(), "**/*")
     65 			bootstrap.GlobFile(ctx, pattern, excludes, fileListFile.String(), depFile)
     66 			jarSpecs = append(jarSpecs, jarSpec{fileListFile, dir})
     67 		}
     68 	}
     69 
     70 	return jarSpecs
     71 }
     72