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