aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-04-23 16:22:03 -0700
committerandroid code review <noreply-gerritcodereview@google.com>2012-04-23 16:22:03 -0700
commit0061ec26c6c895d118d32d81a6612c6b5c42d112 (patch)
treedada47fd549390bfb8e6ff03df2b7718a3fb8d44 /eclipse
parent7892606914a8ccbc349ff37f2b4e142d2ff84ad4 (diff)
parentb40c415cfa3e54e0d780b3da3915ff476a2ecfb4 (diff)
downloadsdk-0061ec26c6c895d118d32d81a6612c6b5c42d112.zip
sdk-0061ec26c6c895d118d32d81a6612c6b5c42d112.tar.gz
sdk-0061ec26c6c895d118d32d81a6612c6b5c42d112.tar.bz2
Merge "Allow src/doc attachement for 3rd party jars in libs/"
Diffstat (limited to 'eclipse')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java86
1 files changed, 83 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