aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2013-07-12 16:27:18 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-07-12 16:27:18 -0700
commitb8f351131d86077e07bd4fe2f76561ccfd8ed46f (patch)
tree7ad8257754a772c6d6e476570ef3ccb60fad58de
parenta5e16a222cedde19069f49b952aef3fb3478c363 (diff)
parentb251da9ccb6a00567c10c80579c0d7039e2c837c (diff)
downloadplatform_sdk-b8f351131d86077e07bd4fe2f76561ccfd8ed46f.tar.gz
platform_sdk-b8f351131d86077e07bd4fe2f76561ccfd8ed46f.tar.bz2
platform_sdk-b8f351131d86077e07bd4fe2f76561ccfd8ed46f.zip
am b251da9c: Merge "Force containers to be exported if maven is not used."
* commit 'b251da9ccb6a00567c10c80579c0d7039e2c837c': Force containers to be exported if maven is not used.
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ProjectHelper.java81
1 files changed, 69 insertions, 12 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ProjectHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ProjectHelper.java
index 0297206a1..2fceffe10 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ProjectHelper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ProjectHelper.java
@@ -73,7 +73,7 @@ public final class ProjectHelper {
public final static int COMPILER_COMPLIANCE_CODEGEN_TARGET = 3;
/**
- * Adds the corresponding source folder to the class path entries.
+ * Adds the given ClasspathEntry object to the class path entries.
* This method does not check whether the entry is already defined in the project.
*
* @param entries The class path entries to read. A copy will be returned.
@@ -90,6 +90,32 @@ public final class ProjectHelper {
}
/**
+ * Replaces the given ClasspathEntry in the classpath entries.
+ *
+ * If the classpath does not yet exists (Check is based on entry path), then it is added.
+ *
+ * @param entries The class path entries to read. The same array (replace) or a copy (add)
+ * will be returned.
+ * @param newEntry The new class path entry to add.
+ * @return The same array (replace) or a copy (add) will be returned.
+ *
+ * @see IClasspathEntry#getPath()
+ */
+ public static IClasspathEntry[] replaceEntryInClasspath(
+ IClasspathEntry[] entries, IClasspathEntry newEntry) {
+
+ IPath path = newEntry.getPath();
+ for (int i = 0, count = entries.length; i < count ; i++) {
+ if (path.equals(entries[i].getPath())) {
+ entries[i] = newEntry;
+ return entries;
+ }
+ }
+
+ return addEntryToClasspath(entries, newEntry);
+ }
+
+ /**
* Adds the corresponding source folder to the project's class path entries.
* This method does not check whether the entry is already defined in the project.
*
@@ -285,6 +311,7 @@ public final class ProjectHelper {
// get the project classpath
IClasspathEntry[] entries = javaProject.getRawClasspath();
IClasspathEntry[] oldEntries = entries;
+ boolean forceRewriteOfCPE = false;
// check if the JRE is set as library
int jreIndex = ProjectHelper.findClasspathEntryByPath(entries, JavaRuntime.JRE_CONTAINER,
@@ -298,8 +325,8 @@ public final class ProjectHelper {
IPath outputFolder = javaProject.getOutputLocation();
boolean foundFrameworkContainer = false;
- boolean foundLibrariesContainer = false;
- boolean foundDependenciesContainer = false;
+ IClasspathEntry foundLibrariesContainer = null;
+ IClasspathEntry foundDependenciesContainer = null;
for (int i = 0 ; i < entries.length ;) {
// get the entry and kind
@@ -319,18 +346,26 @@ public final class ProjectHelper {
String path = entry.getPath().toString();
if (AdtConstants.CONTAINER_FRAMEWORK.equals(path)) {
foundFrameworkContainer = true;
- }
- if (AdtConstants.CONTAINER_PRIVATE_LIBRARIES.equals(path)) {
- foundLibrariesContainer = true;
- }
- if (AdtConstants.CONTAINER_DEPENDENCIES.equals(path)) {
- foundDependenciesContainer = true;
+ } else if (AdtConstants.CONTAINER_PRIVATE_LIBRARIES.equals(path)) {
+ foundLibrariesContainer = entry;
+ } else if (AdtConstants.CONTAINER_DEPENDENCIES.equals(path)) {
+ foundDependenciesContainer = entry;
}
}
i++;
}
+ // look to see if we have the m2eclipse nature
+ boolean m2eNature = false;
+ try {
+ m2eNature = javaProject.getProject().hasNature("org.eclipse.m2e.core.maven2Nature");
+ } catch (CoreException e) {
+ AdtPlugin.log(e, "Failed to query project %s for m2e nature",
+ javaProject.getProject().getName());
+ }
+
+
// if the framework container is not there, we add it
if (!foundFrameworkContainer) {
// add the android container to the array
@@ -339,23 +374,45 @@ public final class ProjectHelper {
}
// same thing for the library container
- if (!foundLibrariesContainer) {
+ if (foundLibrariesContainer == null) {
// add the exported libraries android container to the array
entries = ProjectHelper.addEntryToClasspath(entries,
JavaCore.newContainerEntry(
new Path(AdtConstants.CONTAINER_PRIVATE_LIBRARIES), true));
+ } else if (!m2eNature && !foundLibrariesContainer.isExported()) {
+ // the container is present but it's not exported and since there's no m2e nature
+ // we do want it to be exported.
+ // keep all the other parameters the same.
+ entries = ProjectHelper.replaceEntryInClasspath(entries,
+ JavaCore.newContainerEntry(
+ new Path(AdtConstants.CONTAINER_PRIVATE_LIBRARIES),
+ foundLibrariesContainer.getAccessRules(),
+ foundLibrariesContainer.getExtraAttributes(),
+ true));
+ forceRewriteOfCPE = true;
}
// same thing for the dependencies container
- if (!foundDependenciesContainer) {
+ if (foundDependenciesContainer == null) {
// add the android dependencies container to the array
entries = ProjectHelper.addEntryToClasspath(entries,
JavaCore.newContainerEntry(
new Path(AdtConstants.CONTAINER_DEPENDENCIES), true));
+ } else if (!m2eNature && !foundDependenciesContainer.isExported()) {
+ // the container is present but it's not exported and since there's no m2e nature
+ // we do want it to be exported.
+ // keep all the other parameters the same.
+ entries = ProjectHelper.replaceEntryInClasspath(entries,
+ JavaCore.newContainerEntry(
+ new Path(AdtConstants.CONTAINER_DEPENDENCIES),
+ foundDependenciesContainer.getAccessRules(),
+ foundDependenciesContainer.getExtraAttributes(),
+ true));
+ forceRewriteOfCPE = true;
}
// set the new list of entries to the project
- if (entries != oldEntries) {
+ if (entries != oldEntries || forceRewriteOfCPE) {
javaProject.setRawClasspath(entries, new NullProgressMonitor());
}