mBuildFinalPackage |= dv.getMakeFinalPackage();
}
+ // if the main resources didn't change, then we check for the library
+ // ones (will trigger resource repackaging too)
+ if (mPackageResources == false && libProjects != null &&
+ libProjects.length > 0) {
+ for (IProject libProject : libProjects) {
+ delta = getDelta(libProject);
+ if (delta != null) {
+ LibraryDeltaVisitor visitor = new LibraryDeltaVisitor();
+ delta.accept(visitor);
+
+ mPackageResources = visitor.getResChange();
+
+ if (mPackageResources) {
+ break;
+ }
+ }
+ }
+ }
+
// also go through the delta for all the referenced projects, until we are forced to
// compile anyway
for (int i = 0 ; i < referencedJavaProjects.length &&
* apk file.
*/
private boolean mPackageResources = false;
-
+
/**
* Final package flag. This is set to true if one of the changed/added/removed
* file is a non java file (or aidl) in the resource folder. Upon visiting all the
IFolder outputfolder) {
super(builder);
mSourceFolders = sourceFolders;
-
+
if (outputfolder != null) {
mOutputPath = outputfolder.getFullPath();
}
-
+
IResource assetFolder = builder.getProject().findMember(SdkConstants.FD_ASSETS);
if (assetFolder != null) {
mAssetPath = assetFolder.getFullPath();
if (resFolder != null) {
mResPath = resFolder.getFullPath();
}
-
+
IResource libFolder = builder.getProject().findMember(SdkConstants.FD_NATIVE_LIBS);
if (libFolder != null) {
mLibFolder = libFolder.getFullPath();
public boolean getPackageResources() {
return mPackageResources;
}
-
+
public boolean getMakeFinalPackage() {
return mMakeFinalPackage;
}
/**
* {@inheritDoc}
- * @throws CoreException
+ * @throws CoreException
*
* @see org.eclipse.core.resources.IResourceDeltaVisitor
* #visit(org.eclipse.core.resources.IResourceDelta)
// we are only going to look for changes in res/, src/ and in
// AndroidManifest.xml since the delta visitor goes through the main
- // folder before its childre we can check when the path segment
+ // folder before its children we can check when the path segment
// count is 2 (format will be /$Project/folder) and make sure we are
// processing res/, src/ or AndroidManifest.xml
IResource resource = delta.getResource();
// any for this resource anyway.
return false;
}
-
+
// check the other folders.
if (mOutputPath != null && mOutputPath.isPrefixOf(path)) {
// a resource changed inside the output folder.
if (AndroidConstants.EXT_CLASS.equalsIgnoreCase(ext)) {
mConvertToDex = true;
mMakeFinalPackage = true;
-
+
// no need to check the children, as we are in a package
// and there can only be subpackage children containing
// only .class files
return false;
}
-
+
}
}
}
}
-
+
// if the folder is not inside one of the folders we are interested in (res, assets, output,
// source folders), it could be a folder leading to them, so we return true.
return true;
}
/**
- * Finds a matching Source folder for the current path. This checkds if the current path
+ * Finds a matching Source folder for the current path. This checks if the current path
* leads to, or is a source folder.
* @param sourceFolders The list of source folders
* @param pathSegments The segments of the current path
--- /dev/null
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/org/documents/epl-v10.php
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ide.eclipse.adt.internal.build;
+
+import com.android.sdklib.SdkConstants;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * Delta visitor specifically for Library resources.
+ * The goal is to detect library resource change when compiling the main project
+ * and trigger a resource recompilation/repackaging.
+ *
+ */
+public class LibraryDeltaVisitor implements IResourceDeltaVisitor {
+
+ private boolean mResChange = false;
+
+ public boolean getResChange() {
+ return mResChange;
+ }
+
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ // we are only going to look for changes in res/
+ // Since the delta visitor goes through the main
+ // folder before its children we can check when the path segment
+ // count is 2 (format will be /$Project/folder) and make sure we are
+ // processing res/
+
+ IResource resource = delta.getResource();
+ IPath path = resource.getFullPath();
+ String[] segments = path.segments();
+
+ // since the delta visitor also visits the root we return true if
+ // segments.length = 1
+ if (segments.length == 1) {
+ // this is always the Android project since we call
+ // Builder#getDelta(IProject) on the project itself.
+ return true;
+ } else if (segments.length == 2) {
+ if (SdkConstants.FD_RESOURCES.equalsIgnoreCase(segments[1])) {
+ // res folder was changed!
+ // This is all that matters, we can stop (return false below)
+ mResChange = true;
+ }
+ }
+
+ return false;
+ }
+}
// get the java package from the visitor
javaPackage = dv.getManifestPackage();
minSdkVersion = dv.getMinSdkVersion();
+
+ // if the main resources didn't change, then we check for the library
+ // ones (will trigger resource recompilation too)
+ if (mMustCompileResources == false && libProjects != null &&
+ libProjects.length > 0) {
+ for (IProject libProject : libProjects) {
+ delta = getDelta(libProject);
+ if (delta != null) {
+ LibraryDeltaVisitor visitor = new LibraryDeltaVisitor();
+ delta.accept(visitor);
+
+ mMustCompileResources = visitor.getResChange();
+
+ if (mMustCompileResources) {
+ break;
+ }
+ }
+ }
+ }
}
}
// since the delta visitor also visits the root we return true if
// segments.length = 1
if (segments.length == 1) {
- // FIXME: check this is an Android project.
+ // this is always the Android project since we call
+ // Builder#getDelta(IProject) on the project itself.
return true;
} else if (segments.length == 2) {
// if we are at an item directly under the root directory,
/**
* Reloads the content of the properties.
* <p/>This also reset the reference to the target as it may have changed.
- * <p/>This should be follow by a call to {@link Sdk#loadTarget(ProjectState)}.
+ * <p/>This should be followed by a call to {@link Sdk#loadTarget(ProjectState)}.
*/
public void reloadProperties() {
mTarget = null;