• 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 
visit(IResourceDelta delta)46     public boolean visit(IResourceDelta delta) throws CoreException {
47         // we are only going to look for changes in res/
48         // Since the delta visitor goes through the main
49         // folder before its children we can check when the path segment
50         // count is 2 (format will be /$Project/folder) and make sure we are
51         // processing res/
52 
53         IResource resource = delta.getResource();
54         IPath path = resource.getFullPath();
55         String[] segments = path.segments();
56 
57         // since the delta visitor also visits the root we return true if
58         // segments.length = 1
59         if (segments.length == 1) {
60             // this is always the Android project since we call
61             // Builder#getDelta(IProject) on the project itself.
62             return true;
63         } else if (segments.length == 2) {
64             if (SdkConstants.FD_RESOURCES.equalsIgnoreCase(segments[1])) {
65                 // res folder was changed!
66                 // This is all that matters, we can stop (return false below)
67                 mResChange = true;
68             } else if (SdkConstants.FD_NATIVE_LIBS.equalsIgnoreCase(segments[1])) {
69                 // libs folder was changed.
70                 // This is all that matters, we can stop (return false below)
71                 mLibChange = true;
72             }
73         }
74 
75         return false;
76     }
77 }
78