diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-01-15 16:12:07 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-01-15 16:12:07 -0800 |
commit | 4d360cae64d0e9b5fe962cd339eb1bb933941920 (patch) | |
tree | 8fced5080aa04316ac99f6082499c96d70097a9a /eclipse/plugins/com.android.ide.eclipse.adt/src/com/android | |
parent | a1514dae8668c48feae5436285e3db0ba2133ec3 (diff) | |
download | sdk-4d360cae64d0e9b5fe962cd339eb1bb933941920.zip sdk-4d360cae64d0e9b5fe962cd339eb1bb933941920.tar.gz sdk-4d360cae64d0e9b5fe962cd339eb1bb933941920.tar.bz2 |
auto import from //branches/cupcake/...@126645
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt/src/com/android')
5 files changed, 104 insertions, 14 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/build/ApkBuilder.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/build/ApkBuilder.java index e38419a..6743246 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/build/ApkBuilder.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/build/ApkBuilder.java @@ -648,8 +648,11 @@ public class ApkBuilder extends BaseBuilder { return false; } } catch (Throwable ex) { - String message = String.format(Messages.Dalvik_Error_s, - ex.getMessage()); + String message = ex.getMessage(); + if (message == null) { + message = ex.getClass().getCanonicalName(); + } + message = String.format(Messages.Dalvik_Error_s, message); AdtPlugin.printErrorToConsole(getProject(), message); markProject(AdtConstants.MARKER_ADT, message, IMarker.SEVERITY_ERROR); if ((ex instanceof NoClassDefFoundError) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/project/internal/AndroidClasspathContainer.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/project/internal/AndroidClasspathContainer.java index 945fe52..c7cb427 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/project/internal/AndroidClasspathContainer.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/project/internal/AndroidClasspathContainer.java @@ -32,12 +32,12 @@ class AndroidClasspathContainer implements IClasspathContainer { /** * Constructs the container with the {@link IClasspathEntry} representing the android * framework jar file and the container id - * @param entry the entry representing the android framework. + * @param entries the entries representing the android framework and optional libraries. * @param path the path containing the classpath container id. * @param name the name of the container to display. */ - AndroidClasspathContainer(IClasspathEntry entry, IPath path, String name) { - mClasspathEntry = new IClasspathEntry[] { entry }; + AndroidClasspathContainer(IClasspathEntry[] entries, IPath path, String name) { + mClasspathEntry = entries; mContainerPath = path; mName = name; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/project/internal/AndroidClasspathContainerInitializer.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/project/internal/AndroidClasspathContainerInitializer.java index 4da216c..afa1fb5 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/project/internal/AndroidClasspathContainerInitializer.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/project/internal/AndroidClasspathContainerInitializer.java @@ -22,6 +22,7 @@ import com.android.ide.eclipse.adt.sdk.LoadStatus; import com.android.ide.eclipse.adt.sdk.Sdk; import com.android.ide.eclipse.common.project.BaseProjectHelper; import com.android.sdklib.IAndroidTarget; +import com.android.sdklib.IAndroidTarget.IOptionalLibrary; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; @@ -43,6 +44,9 @@ import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; +import java.util.ArrayList; +import java.util.HashSet; + /** * Classpath container initializer responsible for binding {@link AndroidClasspathContainer} to * {@link IProject}s. This removes the hard-coded path to the android.jar. @@ -141,7 +145,6 @@ public class AndroidClasspathContainerInitializer extends ClasspathContainerInit // just log the error AdtPlugin.log(ce, "Error removing target marker."); } - // First we check if the SDK has been loaded. // By passing the javaProject to getSdkLoadStatus(), we ensure that, should the SDK @@ -255,15 +258,19 @@ public class AndroidClasspathContainerInitializer extends ClasspathContainerInit } /** - * Creates and returns a new {@link IClasspathEntry} object for the android - * framework. <p/>This references the OS path to the android.jar and the + * Creates and returns an array of {@link IClasspathEntry} objects for the android + * framework and optional libraries. + * <p/>This references the OS path to the android.jar and the * java doc directory. This is dynamically created when a project is opened, * and never saved in the project itself, so there's no risk of storing an * obsolete path. * * @param target The target that contains the libraries. */ - private static IClasspathEntry createFrameworkClasspath(IAndroidTarget target) { + private static IClasspathEntry[] createFrameworkClasspath(IAndroidTarget target) { + ArrayList<IClasspathEntry> list = new ArrayList<IClasspathEntry>(); + + // First, we create the IClasspathEntry for the framework. // now add the android framework to the class path. // create the path object. IPath android_lib = new Path(target.getPath(IAndroidTarget.ANDROID_JAR)); @@ -278,14 +285,49 @@ public class AndroidClasspathContainerInitializer extends ClasspathContainerInit new Path("com/android/internal/**"), //$NON-NLS-1$ IAccessRule.K_NON_ACCESSIBLE); - IClasspathEntry classpathEntry = JavaCore.newLibraryEntry(android_lib, + IClasspathEntry frameworkClasspathEntry = JavaCore.newLibraryEntry(android_lib, android_src, // source attachment path null, // default source attachment root path. new IAccessRule[] { accessRule }, new IClasspathAttribute[] { cpAttribute }, false // not exported. ); + + list.add(frameworkClasspathEntry); + + // now deal with optional libraries + IOptionalLibrary[] libraries = target.getOptionalLibraries(); + if (libraries != null) { + HashSet<String> visitedJars = new HashSet<String>(); + for (IOptionalLibrary library : libraries) { + String jarPath = library.getJarPath(); + if (visitedJars.contains(jarPath) == false) { + visitedJars.add(jarPath); + + // create the java doc link, if needed + String targetDocPath = target.getPath(IAndroidTarget.DOCS); + IClasspathAttribute[] attributes = null; + if (targetDocPath != null) { + attributes = new IClasspathAttribute[] { + JavaCore.newClasspathAttribute( + IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, + targetDocPath) + }; + } + + IClasspathEntry entry = JavaCore.newLibraryEntry( + new Path(library.getJarPath()), + null, // source attachment path + null, // default source attachment root path. + null, + attributes, + false // not exported. + ); + list.add(entry); + } + } + } - return classpathEntry; + return list.toArray(new IClasspathEntry[list.size()]); } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/sdk/Sdk.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/sdk/Sdk.java index 19f8f45..a0a3603 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/sdk/Sdk.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/sdk/Sdk.java @@ -145,7 +145,9 @@ public class Sdk { /** * Returns a target from a hash that was generated by {@link IAndroidTarget#hashString()}. - * @param hash the hash + * + * @param hash the {@link IAndroidTarget} hash string. + * @return The matching {@link IAndroidTarget} or null. */ public IAndroidTarget getTargetFromHashString(String hash) { return mManager.getTargetFromHashString(hash); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/wizards/newproject/NewProjectCreationPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/wizards/newproject/NewProjectCreationPage.java index 7fc94ef..33ec2bc 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/wizards/newproject/NewProjectCreationPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/wizards/newproject/NewProjectCreationPage.java @@ -27,6 +27,8 @@ import com.android.ide.eclipse.common.AndroidConstants; import com.android.ide.eclipse.common.project.AndroidManifestHelper; import com.android.sdklib.IAndroidTarget; import com.android.sdklib.SdkConstants; +import com.android.sdklib.project.ProjectProperties; +import com.android.sdklib.project.ProjectProperties.PropertyType; import com.android.sdkuilib.SdkTargetSelector; import org.eclipse.core.filesystem.URIUtil; @@ -129,6 +131,7 @@ public class NewProjectCreationPage extends WizardPage { protected boolean mProjectNameModifiedByUser; protected boolean mApplicationNameModifiedByUser; private boolean mInternalMinSdkVersionUpdate; + private boolean mMinSdkVersionModifiedByUser; /** @@ -402,6 +405,7 @@ public class NewProjectCreationPage extends WizardPage { mSdkTargetSelector.setSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { + onSdkTargetModified(); updateLocationPathField(null); setPageComplete(validatePage()); } @@ -735,6 +739,14 @@ public class NewProjectCreationPage extends WizardPage { try { int version = Integer.parseInt(getMinSdkVersion()); + // Before changing, compare with the currently selected one, if any. + // There can be multiple targets with the same sdk api version, so don't change + // it if it's already at the right version. + IAndroidTarget curr_target = getSdkTarget(); + if (curr_target != null && curr_target.getApiVersionNumber() == version) { + return; + } + for (IAndroidTarget target : mSdkTargetSelector.getTargets()) { if (target.getApiVersionNumber() == version) { mSdkTargetSelector.setSelection(target); @@ -744,6 +756,24 @@ public class NewProjectCreationPage extends WizardPage { } catch (NumberFormatException e) { // ignore } + + mMinSdkVersionModifiedByUser = true; + } + + /** + * Called when an SDK target is modified. + * + * If the minSdkVersion field hasn't been modified by the user yet, we change it + * to reflect the sdk api level that has just been selected. + */ + private void onSdkTargetModified() { + IAndroidTarget target = getSdkTarget(); + + if (target != null && !mMinSdkVersionModifiedByUser) { + mInternalMinSdkVersionUpdate = true; + mMinSdkVersionField.setText(Integer.toString(target.getApiVersionNumber())); + mInternalMinSdkVersionUpdate = false; + } } /** @@ -872,9 +902,22 @@ public class NewProjectCreationPage extends WizardPage { } } - // Select the target matching the manifest's sdk, if any + // Select the target matching the manifest's sdk or build properties, if any boolean foundTarget = false; - if (minSdkVersion != null) { + + ProjectProperties p = ProjectProperties.create(projectLocation, null); + if (p != null) { + // Check the {build|default}.properties files if present + p.merge(PropertyType.BUILD).merge(PropertyType.DEFAULT); + String v = p.getProperty(ProjectProperties.PROPERTY_TARGET); + IAndroidTarget target = Sdk.getCurrent().getTargetFromHashString(v); + if (target != null) { + mSdkTargetSelector.setSelection(target); + foundTarget = true; + } + } + + if (!foundTarget && minSdkVersion != null) { try { int sdkVersion = Integer.parseInt(minSdkVersion); |