aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-03-01 13:49:11 -0800
committerXavier Ducrohet <xav@android.com>2012-03-01 13:49:11 -0800
commitfabbec5e8c5f7a052e337972f963cb3163243c36 (patch)
tree3d1a0da540b588bf8090c3769635b23bb72a1a5f /eclipse
parent6c4f5c561d662456f55830a554c51c3d9670d094 (diff)
downloadsdk-fabbec5e8c5f7a052e337972f963cb3163243c36.zip
sdk-fabbec5e8c5f7a052e337972f963cb3163243c36.tar.gz
sdk-fabbec5e8c5f7a052e337972f963cb3163243c36.tar.bz2
Java project dependencies on libs are automatically added to main project.
Android Library projects can reference other Java-only project. This used to be added to the library jar output. This created an issue if two Library projects were referenced by the same app as the java project was added to both library jar files. This change makes it so that the java project output is not in the library jar files but is instead added to the container of the main app as a project classpath entry. Change-Id: I9f8bbb104e29aede5393afd5ea4b8fe882145d49
Diffstat (limited to 'eclipse')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java7
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java33
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java31
3 files changed, 42 insertions, 29 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java
index 7536c2f..ef3a7ac 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java
@@ -19,7 +19,6 @@ package com.android.ide.eclipse.adt.internal.build;
import com.android.ide.eclipse.adt.AdtConstants;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.AndroidPrintStream;
-import com.android.ide.eclipse.adt.internal.build.BuildHelper.ResourceMarker;
import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs;
import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs.BuildVerbosity;
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
@@ -747,6 +746,12 @@ public class BuildHelper {
mOutStream.setPrefix(CONSOLE_PREFIX_DX);
mErrStream.setPrefix(CONSOLE_PREFIX_DX);
+ if (mVerbose) {
+ for (String input : inputPaths) {
+ mOutStream.println("Input: " + input);
+ }
+ }
+
int res = wrapper.run(osOutFilePath,
inputPaths,
mVerbose,
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java
index d65dedf..cdee0aa 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java
@@ -445,11 +445,9 @@ public class PostCompilerBuilder extends BaseBuilder {
IFolder javaOutputFolder = BaseProjectHelper.getJavaOutputFolder(project);
- writeLibraryPackage(jarIFile, project, appPackage, javaOutputFolder,
- referencedJavaProjects);
+ writeLibraryPackage(jarIFile, project, appPackage, javaOutputFolder);
saveProjectBooleanProperty(PROPERTY_CONVERT_TO_DEX, mConvertToDex = false);
-
// refresh the bin folder content with no recursion to update the library
// jar file.
androidOutputFolder.refreshLocal(IResource.DEPTH_ONE, monitor);
@@ -900,8 +898,15 @@ public class PostCompilerBuilder extends BaseBuilder {
return true;
}
+ /**
+ * Writes the library jar file.
+ * @param jarIFile the destination file
+ * @param project the library project
+ * @param appPackage the library android package
+ * @param javaOutputFolder the JDT output folder.
+ */
private void writeLibraryPackage(IFile jarIFile, IProject project, String appPackage,
- IFolder javaOutputFolder, List<IJavaProject> referencedJavaProjects) {
+ IFolder javaOutputFolder) {
JarOutputStream jos = null;
try {
@@ -920,26 +925,6 @@ public class PostCompilerBuilder extends BaseBuilder {
// now write the standard Java resources
BuildHelper.writeResources(jarBuilder, JavaCore.create(project));
- // do the same for all the referencedJava project
- for (IJavaProject javaProject : referencedJavaProjects) {
- // in case an Android project was referenced (which won't work), the
- // best thing is to ignore this project.
- if (javaProject.getProject().hasNature(AdtConstants.NATURE_DEFAULT)) {
- continue;
- }
-
- IFolder refProjectOutput = BaseProjectHelper.getJavaOutputFolder(
- javaProject.getProject());
-
- if (refProjectOutput != null) {
- // write the class files
- writeClassFilesIntoJar(jarBuilder, refProjectOutput, refProjectOutput);
-
- // now write the standard Java resources
- BuildHelper.writeResources(jarBuilder, javaProject);
- }
- }
-
saveProjectBooleanProperty(PROPERTY_CONVERT_TO_DEX, mConvertToDex);
} catch (Exception e) {
AdtPlugin.log(e, "Failed to write jar file %s", jarIFile.getLocation().toOSString());
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java
index 7b6c9b7..d012bc8 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java
@@ -40,6 +40,8 @@ import org.eclipse.jdt.core.JavaModelException;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
public class LibraryClasspathContainerInitializer extends ClasspathContainerInitializer {
@@ -60,7 +62,7 @@ public class LibraryClasspathContainerInitializer extends ClasspathContainerInit
IClasspathContainer[] containers = new IClasspathContainer[projectCount];
for (int i = 0 ; i < projectCount; i++) {
- containers[i] = allocateAndroidContainer(androidProjects[i]);
+ containers[i] = allocateLibraryContainer(androidProjects[i]);
}
// give each project their new container in one call.
@@ -97,7 +99,7 @@ public class LibraryClasspathContainerInitializer extends ClasspathContainerInit
@Override
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
if (AdtConstants.CONTAINER_LIBRARIES.equals(containerPath.toString())) {
- IClasspathContainer container = allocateAndroidContainer(project);
+ IClasspathContainer container = allocateLibraryContainer(project);
if (container != null) {
JavaCore.setClasspathContainer(new Path(AdtConstants.CONTAINER_LIBRARIES),
new IJavaProject[] { project },
@@ -107,7 +109,7 @@ public class LibraryClasspathContainerInitializer extends ClasspathContainerInit
}
}
- private static IClasspathContainer allocateAndroidContainer(IJavaProject javaProject) {
+ private static IClasspathContainer allocateLibraryContainer(IJavaProject javaProject) {
final IProject iProject = javaProject.getProject();
AdtPlugin plugin = AdtPlugin.getDefault();
@@ -158,6 +160,8 @@ public class LibraryClasspathContainerInitializer extends ClasspathContainerInit
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ HashSet<IProject> refProjects = new HashSet<IProject>();
+
List<IProject> libProjects = state.getFullLibraryProjects();
for (IProject libProject : libProjects) {
// get the project output
@@ -186,6 +190,25 @@ public class LibraryClasspathContainerInitializer extends ClasspathContainerInit
entries.add(entry);
}
+
+ // get project dependencies
+ try {
+ IProject[] refs = libProject.getReferencedProjects();
+ refProjects.addAll(Arrays.asList(refs));
+ } catch (CoreException e) {
+ }
+ }
+
+ for (IProject p : refProjects) {
+ // ignore if it's an Android project, or if it's not a Java Project
+ try {
+ if (p.hasNature(JavaCore.NATURE_ID) &&
+ p.hasNature(AdtConstants.NATURE_DEFAULT) == false) {
+ entries.add(JavaCore.newProjectEntry(p.getFullPath()));
+ }
+ } catch (CoreException e) {
+ // can't get the nature? ignore the project.
+ }
}
// annotations support for older version of android
@@ -205,7 +228,7 @@ public class LibraryClasspathContainerInitializer extends ClasspathContainerInit
return new AndroidClasspathContainer(
entries.toArray(new IClasspathEntry[entries.size()]),
new Path(AdtConstants.CONTAINER_LIBRARIES),
- "Library Projects",
+ "Android Dependencies",
IClasspathContainer.K_APPLICATION);
}