Home | History | Annotate | Download | only in build
      1 /*
      2  * Copyright (C) 2013 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;
     18 
     19 import com.android.SdkConstants;
     20 import com.android.annotations.NonNull;
     21 import com.android.ide.eclipse.adt.AdtPlugin;
     22 import com.android.sdklib.build.RenderScriptChecker;
     23 
     24 import org.eclipse.core.resources.IFile;
     25 
     26 import java.io.File;
     27 import java.io.IOException;
     28 import java.util.Set;
     29 
     30 public class RsSourceChangeHandler implements SourceChangeHandler {
     31 
     32     private final RenderScriptChecker mChecker;
     33     private boolean mIsCheckerLoaded = false;
     34 
     35     private boolean mMustCompile = false;
     36 
     37     public RsSourceChangeHandler(@NonNull RenderScriptChecker checker) {
     38         mChecker = checker;
     39     }
     40 
     41     @Override
     42     public boolean handleGeneratedFile(IFile file, int kind) {
     43         if (mMustCompile) {
     44             return false;
     45         }
     46 
     47         if (!mIsCheckerLoaded) {
     48             try {
     49                 mChecker.loadDependencies();
     50             } catch (IOException e) {
     51                 // failed to load the dependency files, force a compilation, log the error.
     52                 AdtPlugin.log(e, "Failed to read dependency files");
     53                 mMustCompile = true;
     54                 return false;
     55             }
     56         }
     57 
     58         Set<File> oldOutputs = mChecker.getOldOutputs();
     59         // mustCompile is always false here.
     60         mMustCompile = oldOutputs.contains(file.getLocation().toFile());
     61         return mMustCompile;
     62     }
     63 
     64     @Override
     65     public void handleSourceFile(IFile file, int kind) {
     66         if (mMustCompile) {
     67             return;
     68         }
     69 
     70         String ext = file.getFileExtension();
     71         if (SdkConstants.EXT_RS.equals(ext) ||
     72                 SdkConstants.EXT_FS.equals(ext) ||
     73                 SdkConstants.EXT_RSH.equals(ext)) {
     74             mMustCompile = true;
     75         }
     76     }
     77 
     78     public boolean mustCompile() {
     79         return mMustCompile;
     80     }
     81 
     82     @NonNull
     83     public RenderScriptChecker getChecker() {
     84         return mChecker;
     85     }
     86 
     87     public void prepareFullBuild() {
     88         mMustCompile = true;
     89     }
     90 }
     91