1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php 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.ide.eclipse.adt.internal.build.builders; 18 19 import com.android.SdkConstants; 20 import com.android.annotations.NonNull; 21 import com.android.ide.eclipse.adt.AdtConstants; 22 import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper; 23 24 import org.eclipse.core.resources.IFolder; 25 import org.eclipse.core.resources.IProject; 26 import org.eclipse.core.runtime.IPath; 27 28 import java.util.ArrayList; 29 import java.util.List; 30 31 /** 32 * Helper class to generate {@link ChangedFileSet} for given projects. 33 * 34 * Also contains non project specific {@link ChangedFileSet} such as {@link #MANIFEST} 35 * and {@link #NATIVE_LIBS} 36 */ 37 class ChangedFileSetHelper { 38 39 final static ChangedFileSet MANIFEST; 40 final static ChangedFileSet NATIVE_LIBS; 41 42 static { 43 MANIFEST = new ChangedFileSet("manifest", //$NON-NLS-1$ 44 SdkConstants.FN_ANDROID_MANIFEST_XML); 45 46 // FIXME: move compiled native libs to bin/libs/ 47 NATIVE_LIBS = new ChangedFileSet( 48 "nativeLibs", 49 SdkConstants.FD_NATIVE_LIBS + "/*/*.so", //$NON-NLS-1$ 50 SdkConstants.FD_NATIVE_LIBS + "/*/" + SdkConstants.FN_GDBSERVER); //$NON-NLS-1$ 51 } 52 53 /** 54 * Returns a ChangedFileSet for Java resources inside a given project's source folders. 55 * @param project the project. 56 * @return a ChangedFileSet 57 */ 58 static ChangedFileSet getJavaResCfs(@NonNull IProject project) { 59 60 // get the source folder for the given project. 61 IPath projectPath = project.getFullPath(); 62 63 // get the source folders. 64 List<IPath> srcPaths = BaseProjectHelper.getSourceClasspaths(project); 65 List<String> paths = new ArrayList<String>(srcPaths.size()); 66 67 // create a pattern for each of them. 68 for (IPath path : srcPaths) { 69 paths.add(path.makeRelativeTo(projectPath).toString() + "/**"); //$NON-NLS-1$ 70 } 71 72 // custom ChangedFileSet to ignore .java files. 73 return new JavaResChangedSet("javaRes", //$NON-NLS-1$ 74 paths.toArray(new String[paths.size()])); 75 } 76 77 /** 78 * Returns a {@link ChangedFileSet} for all the resources (included assets), and the output 79 * file (compiled resources 80 * @param project the project 81 * @return a ChangeFileSet 82 */ 83 static ChangedFileSet getResCfs(@NonNull IProject project) { 84 ChangedFileSet set = new ChangedFileSet( 85 "resources", //$NON-NLS-1$ 86 SdkConstants.FD_RES + "/**", //$NON-NLS-1$ 87 SdkConstants.FD_ASSETS + "/**"); //$NON-NLS-1$ 88 89 // output file is based on the project's android output folder 90 String path = getRelativeAndroidOut(project); 91 set.setOutput(path + '/' + AdtConstants.FN_RESOURCES_AP_); 92 93 return set; 94 } 95 96 /** 97 * Returns a {@link ChangedFileSet} for all the resources (included assets), and the output 98 * file (compiled resources 99 * @param project the project 100 * @return a ChangeFileSet 101 */ 102 static ChangedFileSet getMergedManifestCfs(@NonNull IProject project) { 103 // input path is inside the project's android output folder 104 String path = getRelativeAndroidOut(project); 105 106 ChangedFileSet set = new ChangedFileSet( 107 "mergedManifest", //$NON-NLS-1$ 108 path + '/' + SdkConstants.FN_ANDROID_MANIFEST_XML); 109 110 return set; 111 } 112 113 /** 114 * Returns a {@link ChangedFileSet} for the generated R.txt file 115 * @param project the project 116 * @return a ChangeFileSet 117 */ 118 static ChangedFileSet getTextSymbols(@NonNull IProject project) { 119 // input path is inside the project's android output folder 120 String path = getRelativeAndroidOut(project); 121 122 ChangedFileSet set = new ChangedFileSet( 123 "textSymbols", //$NON-NLS-1$ 124 path + '/' + SdkConstants.FN_RESOURCE_TEXT); 125 126 return set; 127 } 128 129 /** 130 * Returns a {@link ChangedFileSet} for a project's javac output. 131 * @param project the project 132 * @return a ChangedFileSet 133 */ 134 static ChangedFileSet getByteCodeCfs(@NonNull IProject project) { 135 // input pattern is based on the project's Java compiler's output folder 136 String path = getRelativeJavaCOut(project); 137 138 ChangedFileSet set = new ChangedFileSet("compiledCode", //$NON-NLS-1$ 139 path + "/**/*" + SdkConstants.DOT_CLASS); //$NON-NLS-1$ 140 141 return set; 142 } 143 144 /** 145 * Returns a {@link ChangedFileSet} for a project's complete resources, including 146 * generated resources and crunch cache. 147 * @param project the project 148 * @return a ChangeFileSet 149 */ 150 static ChangedFileSet getFullResCfs(@NonNull IProject project) { 151 // generated res are in the project's android output folder 152 String path = getRelativeAndroidOut(project); 153 154 ChangedFileSet set = new ChangedFileSet("libResources", //$NON-NLS-1$ 155 SdkConstants.FD_RES + "/**", //$NON-NLS-1$ 156 path + '/' + SdkConstants.FD_RES + "/**"); //$NON-NLS-1$ 157 158 return set; 159 } 160 161 /** 162 * Returns a {@link ChangedFileSet} for a project's whole code, including 163 * compiled bytecode, 3rd party libs, and the output file containing the Dalvik 164 * bytecode file. 165 * @param project the project 166 * @return a ChangeFileSet 167 */ 168 static ChangedFileSet getCodeCfs(@NonNull IProject project) { 169 // input pattern is based on the project's Java compiler's output folder 170 String path = getRelativeJavaCOut(project); 171 172 ChangedFileSet set = new ChangedFileSet("classAndJars", //$NON-NLS-1$ 173 path + "/**/*" + SdkConstants.DOT_CLASS, //$NON-NLS-1$ 174 SdkConstants.FD_NATIVE_LIBS + "/*" + SdkConstants.DOT_JAR); //$NON-NLS-1$ 175 176 // output file is based on the project's android output folder 177 path = getRelativeAndroidOut(project); 178 set.setOutput(path + '/' + SdkConstants.FN_APK_CLASSES_DEX); 179 180 return set; 181 } 182 183 private static String getRelativeAndroidOut(@NonNull IProject project) { 184 IFolder folder = BaseProjectHelper.getAndroidOutputFolder(project); 185 return folder.getFullPath().makeRelativeTo(project.getFullPath()).toString(); 186 } 187 188 private static String getRelativeJavaCOut(@NonNull IProject project) { 189 IFolder folder = BaseProjectHelper.getJavaOutputFolder(project); 190 return folder.getFullPath().makeRelativeTo(project.getFullPath()).toString(); 191 } 192 193 } 194