aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-04-23 15:04:28 -0700
committerXavier Ducrohet <xav@android.com>2012-04-23 16:19:32 -0700
commitb40c415cfa3e54e0d780b3da3915ff476a2ecfb4 (patch)
tree69ec5972ad7933e5e91ce4d22c0da2cd5ffba07c
parent622512420652f1622a8d0ca9b64845e2a0288aa9 (diff)
downloadsdk-b40c415cfa3e54e0d780b3da3915ff476a2ecfb4.zip
sdk-b40c415cfa3e54e0d780b3da3915ff476a2ecfb4.tar.gz
sdk-b40c415cfa3e54e0d780b3da3915ff476a2ecfb4.tar.bz2
Allow src/doc attachement for 3rd party jars in libs/
Since those jars are added dynamically through a classpath container, the devs cannot set the source path and the javadoc through Eclipse UI (container don't allow editing those). To fix this, and to make sure that both paths are picked up not only by the current project, but also by other projects (if the current project is a library project), the value is set by a file sitting next to the jar file. The file is name after the jar file, adding .properties at the end. For instance foo.jar -> foo.jar.properties It can currently contain 2 properties: src: relative or absolute path to the source folder (or archive). doc: relative or absolute path to the javadoc. Change-Id: I4f716374ac99479caf65453973bcb1f35ba84590
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java86
-rw-r--r--testapps/libsAndJarTest/app/libs/basicJar2.jar.properties1
-rw-r--r--testapps/libsAndJarTest/lib2/libs/basicJar.jar.properties1
3 files changed, 85 insertions, 3 deletions
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 c2f2510..ef47494 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
@@ -36,6 +36,8 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IAccessRule;
+import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
@@ -43,13 +45,23 @@ import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Properties;
import java.util.Set;
public class LibraryClasspathContainerInitializer extends BaseClasspathContainerInitializer {
+ private final static String ATTR_SRC = "src"; //$NON-NLS-1$
+ private final static String ATTR_DOC = "doc"; //$NON-NLS-1$
+ private final static String DOT_PROPERTIES = ".properties"; //$NON-NLS-1$
+
public LibraryClasspathContainerInitializer() {
}
@@ -265,9 +277,68 @@ public class LibraryClasspathContainerInitializer extends BaseClasspathContainer
e.getExtraAttributes(),
true /*isExported*/));
} else {
- entries.add(JavaCore.newLibraryEntry(new Path(jarFile.getAbsolutePath()),
- null /*sourceAttachmentPath*/, null /*sourceAttachmentRootPath*/,
- true /*isExported*/));
+ String jarPath = jarFile.getAbsolutePath();
+
+ IPath sourceAttachmentPath = null;
+ IClasspathAttribute javaDocAttribute = null;
+
+ File jarProperties = new File(jarPath + DOT_PROPERTIES);
+ if (jarProperties.isFile()) {
+ Properties p = new Properties();
+ InputStream is = null;
+ try {
+ p.load(is = new FileInputStream(jarProperties));
+
+ String value = p.getProperty(ATTR_SRC);
+ if (value != null) {
+ File srcPath = getFile(jarFile, value);
+
+ if (srcPath.exists()) {
+ sourceAttachmentPath = new Path(srcPath.getAbsolutePath());
+ }
+ }
+
+ value = p.getProperty(ATTR_DOC);
+ if (value != null) {
+ File docPath = getFile(jarFile, value);
+ if (docPath.exists()) {
+ try {
+ javaDocAttribute = JavaCore.newClasspathAttribute(
+ IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
+ docPath.toURI().toURL().toString());
+ } catch (MalformedURLException e) {
+ AdtPlugin.log(e, "Failed to process 'doc' attribute for %s",
+ jarProperties.getAbsolutePath());
+ }
+ }
+ }
+
+ } catch (FileNotFoundException e) {
+ // shouldn't happen since we check upfront
+ } catch (IOException e) {
+ AdtPlugin.log(e, "Failed to read %s", jarProperties.getAbsolutePath());
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ if (javaDocAttribute != null) {
+ entries.add(JavaCore.newLibraryEntry(new Path(jarPath),
+ sourceAttachmentPath, null /*sourceAttachmentRootPath*/,
+ new IAccessRule[0],
+ new IClasspathAttribute[] { javaDocAttribute },
+ true /*isExported*/));
+ } else {
+ entries.add(JavaCore.newLibraryEntry(new Path(jarPath),
+ sourceAttachmentPath, null /*sourceAttachmentRootPath*/,
+ true /*isExported*/));
+ }
}
}
} catch (DifferentLibException e) {
@@ -287,6 +358,15 @@ public class LibraryClasspathContainerInitializer extends BaseClasspathContainer
IClasspathContainer.K_APPLICATION);
}
+ private static File getFile(File root, String value) {
+ File file = new File(value);
+ if (file.isAbsolute() == false) {
+ file = new File(root.getParentFile(), value);
+ }
+
+ return file;
+ }
+
/**
* Finds all the jar files inside a project's libs folder.
* @param project
diff --git a/testapps/libsAndJarTest/app/libs/basicJar2.jar.properties b/testapps/libsAndJarTest/app/libs/basicJar2.jar.properties
new file mode 100644
index 0000000..d8099d2
--- /dev/null
+++ b/testapps/libsAndJarTest/app/libs/basicJar2.jar.properties
@@ -0,0 +1 @@
+src=../../../basicJar2/src/ \ No newline at end of file
diff --git a/testapps/libsAndJarTest/lib2/libs/basicJar.jar.properties b/testapps/libsAndJarTest/lib2/libs/basicJar.jar.properties
new file mode 100644
index 0000000..c6b82fb
--- /dev/null
+++ b/testapps/libsAndJarTest/lib2/libs/basicJar.jar.properties
@@ -0,0 +1 @@
+src=../../../basicJar/src/ \ No newline at end of file