AI 145098: am: CL 144938 Fix the classpath container cache for project targeting add-ons (bug #1775936).

Also renamed the container for add-ons to include the base platform name (so that at least a version is displayed).
  Original author: xav
  Merged from: //branches/cupcake/...

Automated import of CL 145098
This commit is contained in:
Xavier Ducrohet
2009-04-08 13:36:48 -07:00
committed by The Android Open Source Project
parent 3489bba692
commit 89f2842e04
4 changed files with 57 additions and 33 deletions

View File

@@ -71,10 +71,11 @@ public class AndroidClasspathContainerInitializer extends ClasspathContainerInit
private final static String CACHE_VERSION = "01"; //$NON-NLS-1$ private final static String CACHE_VERSION = "01"; //$NON-NLS-1$
private final static String CACHE_VERSION_SEP = CACHE_VERSION + PATH_SEPARATOR; private final static String CACHE_VERSION_SEP = CACHE_VERSION + PATH_SEPARATOR;
private final static int PATH_ANDROID_JAR = 0; private final static int CACHE_INDEX_JAR = 0;
private final static int PATH_ANDROID_SRC = 1; private final static int CACHE_INDEX_SRC = 1;
private final static int PATH_ANDROID_DOCS = 2; private final static int CACHE_INDEX_DOCS_URI = 2;
private final static int PATH_ANDROID_OPT_DOCS = 3; private final static int CACHE_INDEX_OPT_DOCS_URI = 3;
private final static int CACHE_INDEX_ADD_ON_START = CACHE_INDEX_OPT_DOCS_URI;
public AndroidClasspathContainerInitializer() { public AndroidClasspathContainerInitializer() {
// pass // pass
@@ -172,7 +173,8 @@ public class AndroidClasspathContainerInitializer extends ClasspathContainerInit
// if we are loaded and the target is non null, we create a valid ClassPathContainer // if we are loaded and the target is non null, we create a valid ClassPathContainer
if (sdkIsLoaded && target != null) { if (sdkIsLoaded && target != null) {
String targetName = target.getFullName();
String targetName = target.getClasspathName();
return new AndroidClasspathContainer( return new AndroidClasspathContainer(
createClasspathEntries(iProject, target, targetName), createClasspathEntries(iProject, target, targetName),
@@ -385,26 +387,35 @@ public class AndroidClasspathContainerInitializer extends ClasspathContainerInit
// now we check the paths actually exist. // now we check the paths actually exist.
// There's an exception: If the source folder for android.jar does not exist, this is // There's an exception: If the source folder for android.jar does not exist, this is
// not a problem, so we skip it. // not a problem, so we skip it.
// Also paths[PATH_ANDROID_DOCS] is a URI to the javadoc, so we test it a bit differently. // Also paths[CACHE_INDEX_DOCS_URI] is a URI to the javadoc, so we test it a
// bit differently.
try { try {
if (new File(paths[PATH_ANDROID_JAR]).exists() == false || if (new File(paths[CACHE_INDEX_JAR]).exists() == false ||
new File(new URI(paths[PATH_ANDROID_DOCS])).exists() == false) { new File(new URI(paths[CACHE_INDEX_DOCS_URI])).exists() == false) {
return null; return null;
} }
// check the path for the add-ons, if they exist.
if (paths.length > CACHE_INDEX_ADD_ON_START) {
// check the docs path separately from the rest of the paths as it's a URI.
if (new File(new URI(paths[CACHE_INDEX_OPT_DOCS_URI])).exists() == false) {
return null;
}
// now just check the remaining paths.
for (int i = CACHE_INDEX_ADD_ON_START + 1; i < paths.length; i++) {
String path = paths[i];
if (path.length() > 0) {
File f = new File(path);
if (f.exists() == false) {
return null;
}
}
}
}
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
return null; return null;
} finally {
}
for (int i = 3 ; i < paths.length; i++) {
String path = paths[i];
if (path.length() > 0) {
File f = new File(path);
if (f.exists() == false) {
return null;
}
}
} }
IClasspathEntry[] entries = createClasspathEntriesFromPaths(paths); IClasspathEntry[] entries = createClasspathEntriesFromPaths(paths);
@@ -423,13 +434,13 @@ public class AndroidClasspathContainerInitializer extends ClasspathContainerInit
// First, we create the IClasspathEntry for the framework. // First, we create the IClasspathEntry for the framework.
// now add the android framework to the class path. // now add the android framework to the class path.
// create the path object. // create the path object.
IPath android_lib = new Path(paths[PATH_ANDROID_JAR]); IPath android_lib = new Path(paths[CACHE_INDEX_JAR]);
IPath android_src = new Path(paths[PATH_ANDROID_SRC]); IPath android_src = new Path(paths[CACHE_INDEX_SRC]);
// create the java doc link. // create the java doc link.
IClasspathAttribute cpAttribute = JavaCore.newClasspathAttribute( IClasspathAttribute cpAttribute = JavaCore.newClasspathAttribute(
IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
paths[PATH_ANDROID_DOCS]); paths[CACHE_INDEX_DOCS_URI]);
// create the access rule to restrict access to classes in com.android.internal // create the access rule to restrict access to classes in com.android.internal
IAccessRule accessRule = JavaCore.newAccessRule( IAccessRule accessRule = JavaCore.newAccessRule(
@@ -448,7 +459,7 @@ public class AndroidClasspathContainerInitializer extends ClasspathContainerInit
// now deal with optional libraries // now deal with optional libraries
if (paths.length >= 5) { if (paths.length >= 5) {
String docPath = paths[PATH_ANDROID_OPT_DOCS]; String docPath = paths[CACHE_INDEX_OPT_DOCS_URI];
int i = 4; int i = 4;
while (i < paths.length) { while (i < paths.length) {
Path jarPath = new Path(paths[i++]); Path jarPath = new Path(paths[i++]);
@@ -533,21 +544,21 @@ public class AndroidClasspathContainerInitializer extends ClasspathContainerInit
} }
// compare the main paths (android.jar, main sources, main javadoc) // compare the main paths (android.jar, main sources, main javadoc)
if (new File(targetPaths[PATH_ANDROID_JAR]).equals( if (new File(targetPaths[CACHE_INDEX_JAR]).equals(
new File(cachedPaths[PATH_ANDROID_JAR])) == false || new File(cachedPaths[CACHE_INDEX_JAR])) == false ||
new File(targetPaths[PATH_ANDROID_SRC]).equals( new File(targetPaths[CACHE_INDEX_SRC]).equals(
new File(cachedPaths[PATH_ANDROID_SRC])) == false || new File(cachedPaths[CACHE_INDEX_SRC])) == false ||
new File(targetPaths[PATH_ANDROID_DOCS]).equals( new File(targetPaths[CACHE_INDEX_DOCS_URI]).equals(
new File(cachedPaths[PATH_ANDROID_DOCS])) == false) { new File(cachedPaths[CACHE_INDEX_DOCS_URI])) == false) {
// different paths, force resolve again. // different paths, force resolve again.
i++; i++;
continue; continue;
} }
if (cachedPaths.length > PATH_ANDROID_OPT_DOCS) { if (cachedPaths.length > CACHE_INDEX_OPT_DOCS_URI) {
// compare optional libraries javadoc // compare optional libraries javadoc
if (new File(targetPaths[PATH_ANDROID_OPT_DOCS]).equals( if (new File(targetPaths[CACHE_INDEX_OPT_DOCS_URI]).equals(
new File(cachedPaths[PATH_ANDROID_OPT_DOCS])) == false) { new File(cachedPaths[CACHE_INDEX_OPT_DOCS_URI])) == false) {
// different paths, force resolve again. // different paths, force resolve again.
i++; i++;
continue; continue;

View File

@@ -124,6 +124,10 @@ final class AddOnTarget implements IAndroidTarget {
return String.format("%1$s (%2$s)", mName, mVendor); return String.format("%1$s (%2$s)", mName, mVendor);
} }
public String getClasspathName() {
return String.format("%1$s [%2$s]", mName, mBasePlatform.getName());
}
public String getDescription() { public String getDescription() {
return mDescription; return mDescription;
} }

View File

@@ -96,6 +96,11 @@ public interface IAndroidTarget extends Comparable<IAndroidTarget> {
*/ */
String getFullName(); String getFullName();
/**
* Returns the name to be displayed when representing all the libraries this target contains.
*/
String getClasspathName();
/** /**
* Returns the description of the target. * Returns the description of the target.
*/ */

View File

@@ -105,6 +105,10 @@ final class PlatformTarget implements IAndroidTarget {
return mName; return mName;
} }
public String getClasspathName() {
return mName;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *