1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.idegen; 18 19 import com.google.common.base.Preconditions; 20 import com.google.common.collect.ImmutableList; 21 22 import java.io.File; 23 import java.io.IOException; 24 25 /** 26 * Special module used for framework to build one off resource directory. 27 */ 28 public class FrameworkModule extends Module { 29 30 private static final String REL_OUT_LIB_DIR = "out/target/common/obj/JAVA_LIBRARIES"; 31 32 // Framework needs a special constant for it's intermediates because it does not follow 33 // normal conventions. 34 private static final ImmutableList<String> FRAMEWORK_APP_INTERMEDIATES = ImmutableList.of( 35 "framework-res_intermediates" 36 ); 37 private static final ImmutableList<String> FRAMEWORK_LIB_INTERMEDIATES = ImmutableList.of( 38 "framework_intermediates", 39 "services.core_intermediates" 40 ); 41 FrameworkModule(File moduleDir)42 public FrameworkModule(File moduleDir) throws IOException { 43 super(Preconditions.checkNotNull(moduleDir), false); 44 } 45 46 @Override buildIntermediates()47 protected String buildIntermediates() throws IOException { 48 StringBuilder sb = new StringBuilder(); 49 for (String intermediate : FRAMEWORK_APP_INTERMEDIATES) { 50 appendContentRoot(sb, DirectorySearch.getRepoRoot() + File.separator + 51 REL_OUT_APP_DIR + File.separator + intermediate); 52 } 53 for (String intermediate : FRAMEWORK_LIB_INTERMEDIATES) { 54 appendContentRoot(sb, DirectorySearch.getRepoRoot() + File.separator + 55 REL_OUT_LIB_DIR + File.separator + intermediate); 56 } 57 return sb.toString(); 58 } 59 appendContentRoot(StringBuilder stringBuilder, String rootPath)60 private void appendContentRoot(StringBuilder stringBuilder, String rootPath) 61 throws IOException { 62 File intermediates = new File(rootPath); 63 ImmutableList<File> intermediateSrcDirs = DirectorySearch.findSourceDirs(intermediates); 64 stringBuilder.append(" <content url=\"file://").append(intermediates).append("\">\n"); 65 for (File src : intermediateSrcDirs) { 66 stringBuilder.append(" <sourceFolder url=\"file://") 67 .append(src.getCanonicalPath()).append("\" isTestSource=\"false\" />\n"); 68 } 69 stringBuilder.append(" </content>\n"); 70 } 71 } 72