• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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.sdklib.SdkConstants;
20 
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.resources.IResourceDelta;
23 import org.eclipse.core.resources.IResourceDeltaVisitor;
24 import org.eclipse.core.runtime.CoreException;
25 import org.eclipse.core.runtime.IPath;
26 
27 /**
28  * Delta visitor specifically for Library resources.
29  * The goal is to detect library resource/library changes when compiling the main project
30  * and trigger a resource recompilation/repackaging.
31  *
32  */
33 public class LibraryDeltaVisitor implements IResourceDeltaVisitor {
34 
35     private boolean mResChange = false;
36     private boolean mLibChange = false;
37 
getResChange()38     public boolean getResChange() {
39         return mResChange;
40     }
41 
getLibChange()42     public boolean getLibChange() {
43         return mLibChange;
44     }
45 
46     @Override
visit(IResourceDelta delta)47     public boolean visit(IResourceDelta delta) throws CoreException {
48         // we are only going to look for changes in res/
49         // Since the delta visitor goes through the main
50         // folder before its children we can check when the path segment
51         // count is 2 (format will be /$Project/folder) and make sure we are
52         // processing res/
53 
54         IResource resource = delta.getResource();
55         IPath path = resource.getFullPath();
56         String[] segments = path.segments();
57 
58         // since the delta visitor also visits the root we return true if
59         // segments.length = 1
60         if (segments.length == 1) {
61             // this is always the Android project since we call
62             // Builder#getDelta(IProject) on the project itself.
63             return true;
64         } else if (segments.length == 2) {
65             if (SdkConstants.FD_RESOURCES.equalsIgnoreCase(segments[1])) {
66                 // res folder was changed!
67                 // This is all that matters, we can stop (return false below)
68                 mResChange = true;
69             } else if (SdkConstants.FD_NATIVE_LIBS.equalsIgnoreCase(segments[1])) {
70                 // libs folder was changed.
71                 // This is all that matters, we can stop (return false below)
72                 mLibChange = true;
73             } else if (SdkConstants.FD_OUTPUT.equalsIgnoreCase(segments[1])) {
74                 // need to dig into the content of the bin folder.
75                 return true;
76             }
77         } else {
78             // we must be in the bin folder since it's the only case we go deeper.
79             if (SdkConstants.FD_RESOURCES.equalsIgnoreCase(segments[2])) {
80                 mResChange = true;
81             }
82         }
83 
84         return false;
85     }
86 }
87