diff options
author | Raphael <raphael@google.com> | 2010-03-31 16:18:37 -0700 |
---|---|---|
committer | Raphael <raphael@google.com> | 2010-03-31 17:27:16 -0700 |
commit | 94049bef1ac2fc28fb56544eed6d1f3b58d6c0dd (patch) | |
tree | 53ca458420f5aad53be9e7c47e7342d01883824a | |
parent | 42fb7d2c1dccb64cbd4d2d6b544dc99a8f936897 (diff) | |
download | sdk-94049bef1ac2fc28fb56544eed6d1f3b58d6c0dd.zip sdk-94049bef1ac2fc28fb56544eed6d1f3b58d6c0dd.tar.gz sdk-94049bef1ac2fc28fb56544eed6d1f3b58d6c0dd.tar.bz2 |
ADT NPW: logging for missing templates.
This does not solve the NPE, it adds even more logging
which will warn users when something goes horribly wrong.
Basically these logs should never happen.
SDK Bug: 2546962
Change-Id: Ibcd4f6fc9efc478d84236003cabde5ccf520a378
2 files changed, 42 insertions, 10 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java index 6208b45..d10b981 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java @@ -507,7 +507,8 @@ public class AdtPlugin extends AbstractUIPlugin { return total.toString(); } } catch (IOException e) { - // we'll just return null;. + // we'll just return null + AdtPlugin.log(e, "Failed to read text file '%s'", filepath); //$NON-NLS-1$ } return null; @@ -538,6 +539,7 @@ public class AdtPlugin extends AbstractUIPlugin { } } catch (IOException e) { // we'll just return null;. + AdtPlugin.log(e, "Failed to read binary file '%s'", filepath); //$NON-NLS-1$ } return null; @@ -558,8 +560,10 @@ public class AdtPlugin extends AbstractUIPlugin { } } catch (MalformedURLException e) { // we'll just return null. + AdtPlugin.log(e, "Failed to read stream '%s'", filepath); //$NON-NLS-1$ } catch (IOException e) { // we'll just return null;. + AdtPlugin.log(e, "Failed to read stream '%s'", filepath); //$NON-NLS-1$ } return null; @@ -581,7 +585,14 @@ public class AdtPlugin extends AbstractUIPlugin { } // attempt to get a file to one of the template. - return bundle.getEntry(AndroidConstants.WS_SEP + filepath); + String path = AndroidConstants.WS_SEP + filepath; + URL url = bundle.getEntry(path); + + if (url == null) { + AdtPlugin.log(IStatus.INFO, "Bundle file URL not found at path '%s'", path); + } + + return url; } /** diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java index 39be01c..517ffa0 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java @@ -760,6 +760,15 @@ public class NewProjectWizard extends Wizard implements INewWizard { // Replace all keyword parameters manifestTemplate = replaceParameters(manifestTemplate, parameters); + if (manifestTemplate == null) { + // Inform the user there will be not manifest. + AdtPlugin.logAndPrintError(null, getWindowTitle() /*TAG*/, + "Failed to generate the Android manifest. Missing template %s", + TEMPLATE_MANIFEST); + // Abort now, there's no need to continue + return; + } + if (parameters.containsKey(PARAM_ACTIVITY)) { // now get the activity template String activityTemplate = AdtPlugin.readEmbeddedTextFile(TEMPLATE_ACTIVITIES); @@ -770,11 +779,15 @@ public class NewProjectWizard extends Wizard implements INewWizard { // set the intent. String intent = AdtPlugin.readEmbeddedTextFile(TEMPLATE_INTENT_LAUNCHER); - // set the intent to the main activity - activities = activities.replaceAll(PH_INTENT_FILTERS, intent); + if (activities != null) { + if (intent != null) { + // set the intent to the main activity + activities = activities.replaceAll(PH_INTENT_FILTERS, intent); + } - // set the activity(ies) in the manifest - manifestTemplate = manifestTemplate.replaceAll(PH_ACTIVITIES, activities); + // set the activity(ies) in the manifest + manifestTemplate = manifestTemplate.replaceAll(PH_ACTIVITIES, activities); + } } else { // remove the activity(ies) from the manifest manifestTemplate = manifestTemplate.replaceAll(PH_ACTIVITIES, ""); //$NON-NLS-1$ @@ -784,11 +797,17 @@ public class NewProjectWizard extends Wizard implements INewWizard { if (parameters.containsKey(PARAM_TEST_TARGET_PACKAGE)) { // Set the uses-library needed by the test project String usesLibrary = AdtPlugin.readEmbeddedTextFile(TEMPLATE_TEST_USES_LIBRARY); - manifestTemplate = manifestTemplate.replaceAll(PH_TEST_USES_LIBRARY, usesLibrary); + if (usesLibrary != null) { + manifestTemplate = manifestTemplate.replaceAll( + PH_TEST_USES_LIBRARY, usesLibrary); + } // Set the instrumentation element needed by the test project String instru = AdtPlugin.readEmbeddedTextFile(TEMPLATE_TEST_INSTRUMENTATION); - manifestTemplate = manifestTemplate.replaceAll(PH_TEST_INSTRUMENTATION, instru); + if (instru != null) { + manifestTemplate = manifestTemplate.replaceAll( + PH_TEST_INSTRUMENTATION, instru); + } // Replace PARAM_TEST_TARGET_PACKAGE itself now manifestTemplate = replaceParameters(manifestTemplate, parameters); @@ -802,8 +821,10 @@ public class NewProjectWizard extends Wizard implements INewWizard { String minSdkVersion = (String) parameters.get(PARAM_MIN_SDK_VERSION); if (minSdkVersion != null && minSdkVersion.length() > 0) { String usesSdkTemplate = AdtPlugin.readEmbeddedTextFile(TEMPLATE_USES_SDK); - String usesSdk = replaceParameters(usesSdkTemplate, parameters); - manifestTemplate = manifestTemplate.replaceAll(PH_USES_SDK, usesSdk); + if (usesSdkTemplate != null) { + String usesSdk = replaceParameters(usesSdkTemplate, parameters); + manifestTemplate = manifestTemplate.replaceAll(PH_USES_SDK, usesSdk); + } } else { manifestTemplate = manifestTemplate.replaceAll(PH_USES_SDK, ""); } |