@NotNull
  static String doValidatePackageName(
      boolean library, @NotNull String candidate, @Nullable ModulesProvider modulesProvider) {
    if (candidate.length() == 0) {
      return AndroidBundle.message("specify.package.name.error");
    }
    if (!AndroidUtils.isValidAndroidPackageName(candidate)) {
      return candidate;
    }
    if (!AndroidCommonUtils.contains2Identifiers(candidate)) {
      return AndroidBundle.message("package.name.must.contain.2.ids.error");
    }

    if (!library) {
      for (Module module : modulesProvider.getModules()) {
        final AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet != null && !facet.isLibraryProject()) {
          final Manifest manifest = facet.getManifest();
          if (manifest != null) {
            final String packageName = manifest.getPackage().getValue();
            if (candidate.equals(packageName)) {
              return "Package name '"
                  + packageName
                  + "' is already used by module '"
                  + module.getName()
                  + "'";
            }
          }
        }
      }
    }
    return "";
  }
    private void reportMissingOnClickProblem(
        OnClickConverter.MyReference reference,
        PsiClass activity,
        String methodName,
        boolean incorrectSignature) {
      String activityName = activity.getName();

      if (activityName == null) {
        activityName = "";
      }
      final String message =
          incorrectSignature
              ? AndroidBundle.message(
                  "android.inspections.on.click.missing.incorrect.signature",
                  methodName,
                  activityName)
              : AndroidBundle.message(
                  "android.inspections.on.click.missing.problem", methodName, activityName);

      final LocalQuickFix[] fixes =
          StringUtil.isJavaIdentifier(methodName)
              ? new LocalQuickFix[] {new MyQuickFix(methodName, reference.getConverter(), activity)}
              : LocalQuickFix.EMPTY_ARRAY;

      myResult.add(
          myInspectionManager.createProblemDescriptor(
              reference.getElement(),
              reference.getRangeInElement(),
              message,
              ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
              myOnTheFly,
              fixes));
    }
 private String validateActivityName() {
   String candidate = myActivityNameField.getText().trim();
   if (!AndroidUtils.isIdentifier(candidate)) {
     return AndroidBundle.message("not.valid.acvitiy.name.error", candidate);
   }
   return "";
 }
  public ApkStep(ExportSignedPackageWizard wizard) {
    myWizard = wizard;
    myApkPathLabel.setLabelFor(myApkPathField);
    myProguardConfigFilePathLabel.setLabelFor(myProguardConfigFilePathField);

    myApkPathField
        .getButton()
        .addActionListener(
            new SaveFileListener(
                myContentPanel,
                myApkPathField,
                AndroidBundle.message("android.extract.package.choose.dest.apk")) {
              @Override
              protected String getDefaultLocation() {
                Module module = myWizard.getFacet().getModule();
                return getContentRootPath(module);
              }
            });

    myProguardConfigFilePathField
        .getButton()
        .addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                final String path = myProguardConfigFilePathField.getText().trim();
                VirtualFile defaultFile =
                    path != null && path.length() > 0
                        ? LocalFileSystem.getInstance().findFileByPath(path)
                        : null;
                final AndroidFacet facet = myWizard.getFacet();

                if (defaultFile == null && facet != null) {
                  defaultFile = AndroidRootUtil.getMainContentRoot(facet);
                }
                final VirtualFile file =
                    FileChooser.chooseFile(
                        myContentPanel,
                        FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(),
                        defaultFile);
                if (file != null) {
                  myProguardConfigFilePathField.setText(
                      FileUtil.toSystemDependentName(file.getPath()));
                }
              }
            });

    myProguardCheckBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            final boolean enabled = myProguardCheckBox.isSelected();
            myProguardConfigFilePathLabel.setEnabled(enabled);
            myProguardConfigFilePathField.setEnabled(enabled);
          }
        });
  }
  @Nullable
  public static ValidationInfo checkIfResourceAlreadyExists(
      @NotNull Module selectedModule,
      @NotNull String resourceName,
      @NotNull ResourceType resourceType,
      @NotNull List<String> dirNames,
      @NotNull String fileName) {
    if (resourceName.length() == 0 || dirNames.size() == 0 || fileName.length() == 0) {
      return null;
    }

    final AndroidFacet facet = AndroidFacet.getInstance(selectedModule);
    final VirtualFile resourceDir = facet != null ? AndroidRootUtil.getResourceDir(facet) : null;
    if (resourceDir == null) {
      return null;
    }

    for (String directoryName : dirNames) {
      final VirtualFile resourceSubdir = resourceDir.findChild(directoryName);
      if (resourceSubdir == null) {
        continue;
      }

      final VirtualFile resFile = resourceSubdir.findChild(fileName);
      if (resFile == null) {
        continue;
      }

      if (resFile.getFileType() != StdFileTypes.XML) {
        return new ValidationInfo(
            "File " + FileUtil.toSystemDependentName(resFile.getPath()) + " is not XML file");
      }

      final Resources resources =
          AndroidUtils.loadDomElement(selectedModule, resFile, Resources.class);
      if (resources == null) {
        return new ValidationInfo(
            AndroidBundle.message(
                "not.resource.file.error", FileUtil.toSystemDependentName(resFile.getPath())));
      }

      for (ResourceElement element :
          AndroidResourceUtil.getValueResourcesFromElement(resourceType.getName(), resources)) {
        if (resourceName.equals(element.getName().getValue())) {
          return new ValidationInfo(
              "resource '"
                  + resourceName
                  + "' already exists in "
                  + FileUtil.toSystemDependentName(resFile.getPath()));
        }
      }
    }
    return null;
  }
  private static boolean askForClosingDebugSessions(@NotNull Project project) {
    final List<Pair<ProcessHandler, RunContentDescriptor>> pairs =
        new ArrayList<Pair<ProcessHandler, RunContentDescriptor>>();

    for (Project p : ProjectManager.getInstance().getOpenProjects()) {
      final ProcessHandler[] processes = ExecutionManager.getInstance(p).getRunningProcesses();

      for (ProcessHandler process : processes) {
        if (!process.isProcessTerminated()) {
          final AndroidSessionInfo info =
              process.getUserData(AndroidDebugRunner.ANDROID_SESSION_INFO);
          if (info != null) {
            pairs.add(Pair.create(process, info.getDescriptor()));
          }
        }
      }
    }

    if (pairs.size() == 0) {
      return true;
    }

    final StringBuilder s = new StringBuilder();

    for (Pair<ProcessHandler, RunContentDescriptor> pair : pairs) {
      if (s.length() > 0) {
        s.append('\n');
      }
      s.append(pair.getSecond().getDisplayName());
    }

    final int r =
        Messages.showYesNoDialog(
            project,
            AndroidBundle.message("android.debug.sessions.will.be.closed", s),
            AndroidBundle.message("android.disable.adb.service.title"),
            Messages.getQuestionIcon());
    return r == Messages.YES;
  }
 public ExportSignedPackageWizard(Project project, List<AndroidFacet> facets) {
   super(AndroidBundle.message("android.export.signed.package.action.text"), project);
   myProject = project;
   assert facets.size() > 0;
   if (facets.size() > 1) {
     addStep(new ChooseModuleStep(this, facets));
   } else {
     myFacet = facets.get(0);
   }
   addStep(new KeystoreStep(this));
   addStep(new InitialKeyStep(this));
   addStep(new NewKeyStep(this));
   addStep(new ApkStep(this));
   init();
 }
  @Override
  public void actionPerformed(AnActionEvent e) {
    final VirtualFile pngFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    if (!isPngFile(pngFile)) {
      return;
    }

    FileSaverDescriptor descriptor =
        new FileSaverDescriptor(
            AndroidBundle.message("android.9patch.creator.save.title"), "", SdkConstants.EXT_PNG);
    FileSaverDialog saveFileDialog =
        FileChooserFactory.getInstance().createSaveFileDialog(descriptor, (Project) null);
    VirtualFileWrapper fileWrapper =
        saveFileDialog.save(
            pngFile.getParent(), pngFile.getNameWithoutExtension().concat(SdkConstants.DOT_9PNG));
    if (fileWrapper == null) {
      return;
    }

    final File patchFile = fileWrapper.getFile();
    new Task.Modal(null, "Creating 9-Patch File", false) {
      private IOException myException;

      @Override
      public void run(@NotNull ProgressIndicator indicator) {
        indicator.setIndeterminate(true);
        try {
          BufferedImage pngImage = ImageIO.read(VfsUtilCore.virtualToIoFile(pngFile));
          BufferedImage patchImage = ImageUtils.addMargin(pngImage, 1);
          ImageIO.write(patchImage, SdkConstants.EXT_PNG, patchFile);
          LocalFileSystem.getInstance().refreshAndFindFileByIoFile(patchFile);
        } catch (IOException e) {
          myException = e;
        }
      }

      @Override
      public void onSuccess() {
        if (myException != null) {
          Messages.showErrorDialog(
              AndroidBundle.message("android.9patch.creator.error", myException.getMessage()),
              AndroidBundle.message("android.9patch.creator.error.title"));
        }
      }
    }.queue();
  }
  private void initToolWindow() {
    myToolWindowForm = new AndroidLayoutPreviewToolWindowForm(this);
    final String toolWindowId = AndroidBundle.message("android.layout.preview.tool.window.title");
    myToolWindow =
        ToolWindowManager.getInstance(myProject)
            .registerToolWindow(toolWindowId, false, ToolWindowAnchor.RIGHT, myProject, true);
    myToolWindow.setIcon(AndroidIcons.AndroidPreview);

    ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject))
        .addToolWindowManagerListener(
            new ToolWindowManagerAdapter() {
              private boolean myVisible = false;

              @Override
              public void stateChanged() {
                if (myProject.isDisposed()) {
                  return;
                }

                final ToolWindow window =
                    ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
                if (window != null && window.isAvailable()) {
                  final boolean visible = window.isVisible();
                  AndroidEditorSettings.getInstance().getGlobalState().setVisible(visible);

                  if (visible && !myVisible) {
                    render();
                  }
                  myVisible = visible;
                }
              }
            });

    final JPanel contentPanel = myToolWindowForm.getContentPanel();
    final ContentManager contentManager = myToolWindow.getContentManager();
    @SuppressWarnings("ConstantConditions")
    final Content content = contentManager.getFactory().createContent(contentPanel, null, false);
    content.setDisposer(myToolWindowForm);
    content.setCloseable(false);
    content.setPreferredFocusableComponent(contentPanel);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content, true);
    myToolWindow.setAvailable(false, null);
  }
  public AndroidSdkComboBoxWithBrowseButton() {
    final JComboBox sdkCombobox = getComboBox();

    sdkCombobox.setRenderer(
        new ListCellRendererWrapper() {
          @Override
          public void customize(
              JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof Sdk) {
              final Sdk sdk = (Sdk) value;
              setText(sdk.getName());
              setIcon(((SdkType) sdk.getSdkType()).getIcon());
            } else {
              setText("<html><font color='red'>[none]</font></html>");
            }
          }
        });

    addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            ProjectJdksEditor editor =
                new ProjectJdksEditor(
                    null,
                    ProjectManager.getInstance().getDefaultProject(),
                    AndroidSdkComboBoxWithBrowseButton.this);
            if (editor.showAndGet()) {
              final Sdk selectedJdk = editor.getSelectedJdk();
              rebuildSdksListAndSelectSdk(selectedJdk);
              if (selectedJdk == null || !isAndroidSdk(selectedJdk)) {
                Messages.showErrorDialog(
                    AndroidSdkComboBoxWithBrowseButton.this,
                    AndroidBundle.message("select.platform.error"),
                    CommonBundle.getErrorTitle());
              }
            }
          }
        });
    getButton().setToolTipText(AndroidBundle.message("android.add.sdk.tooltip"));
  }
 public AndroidEnableAdbServiceAction(@Nullable Icon icon) {
   super(
       AndroidBundle.message("android.enable.adb.service.action.title"),
       AndroidBundle.message("android.enable.adb.service.action.description"),
       icon);
 }
  private boolean loadLibrary(@NotNull IAndroidTarget target)
      throws RenderingException, IOException {
    final String layoutLibJarPath = target.getPath(IAndroidTarget.LAYOUT_LIB);
    final VirtualFile layoutLibJar = LocalFileSystem.getInstance().findFileByPath(layoutLibJarPath);
    if (layoutLibJar == null || layoutLibJar.isDirectory()) {
      throw new RenderingException(
          AndroidBundle.message(
              "android.file.not.exist.error", FileUtil.toSystemDependentName(layoutLibJarPath)));
    }

    final String resFolderPath = target.getPath(IAndroidTarget.RESOURCES);
    final VirtualFile resFolder = LocalFileSystem.getInstance().findFileByPath(resFolderPath);
    if (resFolder == null || !resFolder.isDirectory()) {
      throw new RenderingException(
          AndroidBundle.message(
              "android.directory.cannot.be.found.error",
              FileUtil.toSystemDependentName(resFolderPath)));
    }

    final String fontFolderPath = target.getPath(IAndroidTarget.FONTS);
    final VirtualFile fontFolder = LocalFileSystem.getInstance().findFileByPath(fontFolderPath);
    if (fontFolder == null || !fontFolder.isDirectory()) {
      throw new RenderingException(
          AndroidBundle.message(
              "android.directory.cannot.be.found.error",
              FileUtil.toSystemDependentName(fontFolderPath)));
    }

    final String platformFolderPath =
        target.isPlatform() ? target.getLocation() : target.getParent().getLocation();
    final File platformFolder = new File(platformFolderPath);
    if (!platformFolder.isDirectory()) {
      throw new RenderingException(
          AndroidBundle.message(
              "android.directory.cannot.be.found.error",
              FileUtil.toSystemDependentName(platformFolderPath)));
    }

    final File buildProp = new File(platformFolder, SdkConstants.FN_BUILD_PROP);
    if (!buildProp.isFile()) {
      throw new RenderingException(
          AndroidBundle.message(
              "android.file.not.exist.error", FileUtil.toSystemDependentName(buildProp.getPath())));
    }

    final SimpleLogger logger = new SimpleLogger(LOG);

    myLibrary =
        LayoutLibrary.load(
            layoutLibJar.getPath(),
            logger,
            ApplicationNamesInfo.getInstance().getFullProductName());
    if (myLibrary.getStatus() != LoadStatus.LOADED) {
      throw new RenderingException(myLibrary.getLoadMessage());
    }

    myResources = loadPlatformResources(new File(resFolder.getPath()), logger);

    final Map<String, String> buildPropMap =
        ProjectProperties.parsePropertyFile(new BufferingFileWrapper(buildProp), logger);
    return myLibrary.init(buildPropMap, new File(fontFolder.getPath()), myEnumMap, logger);
  }
 public ConvertToNinePatchAction() {
   super(AndroidBundle.message("android.9patch.creator.title"));
 }
  @Override
  public boolean setupSdkPaths(@NotNull Sdk sdk, @NotNull SdkModel sdkModel) {
    final List<String> javaSdks = Lists.newArrayList();
    final Sdk[] sdks = sdkModel.getSdks();
    for (Sdk jdk : sdks) {
      if (Jdks.isApplicableJdk(jdk)) {
        javaSdks.add(jdk.getName());
      }
    }

    if (javaSdks.isEmpty()) {
      Messages.showErrorDialog(
          AndroidBundle.message("no.jdk.for.android.found.error"), "No Java SDK Found");
      return false;
    }

    MessageBuildingSdkLog log = new MessageBuildingSdkLog();
    AndroidSdkData sdkData = getSdkData(sdk);

    if (sdkData == null) {
      String errorMessage =
          !log.getErrorMessage().isEmpty()
              ? log.getErrorMessage()
              : AndroidBundle.message("cannot.parse.sdk.error");
      Messages.showErrorDialog(errorMessage, "SDK Parsing Error");
      return false;
    }

    IAndroidTarget[] targets = sdkData.getTargets();

    if (targets.length == 0) {
      if (Messages.showOkCancelDialog(
              AndroidBundle.message("no.android.targets.error"),
              CommonBundle.getErrorTitle(),
              "Open SDK Manager",
              Messages.CANCEL_BUTTON,
              Messages.getErrorIcon())
          == Messages.OK) {
        RunAndroidSdkManagerAction.runSpecificSdkManager(null, sdkData.getLocation());
      }
      return false;
    }

    String[] targetNames = new String[targets.length];

    String newestPlatform = null;
    AndroidVersion version = null;

    for (int i = 0; i < targets.length; i++) {
      IAndroidTarget target = targets[i];
      String targetName = getTargetPresentableName(target);
      targetNames[i] = targetName;
      if (target.isPlatform() && (version == null || target.getVersion().compareTo(version) > 0)) {
        newestPlatform = targetName;
        version = target.getVersion();
      }
    }

    AndroidNewSdkDialog dialog =
        new AndroidNewSdkDialog(
            null,
            javaSdks,
            javaSdks.get(0),
            Arrays.asList(targetNames),
            newestPlatform != null ? newestPlatform : targetNames[0]);
    if (!dialog.showAndGet()) {
      return false;
    }
    String name = javaSdks.get(dialog.getSelectedJavaSdkIndex());
    Sdk jdk = sdkModel.findSdk(name);
    IAndroidTarget target = targets[dialog.getSelectedTargetIndex()];
    String sdkName = chooseNameForNewLibrary(target);
    setUpSdk(sdk, sdkName, sdks, target, jdk, true);

    return true;
  }
  @Nullable
  public static String doExtractStyle(
      @NotNull Module module,
      @NotNull final XmlTag viewTag,
      final boolean addStyleAttributeToTag,
      @Nullable MyTestConfig testConfig) {
    final PsiFile file = viewTag.getContainingFile();
    if (file == null) {
      return null;
    }
    final String dialogTitle = AndroidBundle.message("android.extract.style.title");
    final String fileName = AndroidResourceUtil.getDefaultResourceFileName(ResourceType.STYLE);
    assert fileName != null;
    final List<String> dirNames = Arrays.asList(ResourceFolderType.VALUES.getName());
    final List<XmlAttribute> extractableAttributes = getExtractableAttributes(viewTag);
    final Project project = module.getProject();

    if (extractableAttributes.size() == 0) {
      AndroidUtils.reportError(
          project, "The tag doesn't contain any attributes that can be extracted", dialogTitle);
      return null;
    }

    final LayoutViewElement viewElement = getLayoutViewElement(viewTag);
    assert viewElement != null;
    final ResourceValue parentStyleVlaue = viewElement.getStyle().getValue();
    final String parentStyle;
    boolean supportImplicitParent = false;

    if (parentStyleVlaue != null) {
      parentStyle = parentStyleVlaue.getResourceName();
      if (!ResourceType.STYLE.getName().equals(parentStyleVlaue.getResourceType())
          || parentStyle == null
          || parentStyle.length() == 0) {
        AndroidUtils.reportError(
            project, "Invalid parent style reference " + parentStyleVlaue.toString(), dialogTitle);
        return null;
      }
      supportImplicitParent = parentStyleVlaue.getPackage() == null;
    } else {
      parentStyle = null;
    }

    final String styleName;
    final List<XmlAttribute> styledAttributes;
    final Module chosenModule;

    if (testConfig == null) {
      final ExtractStyleDialog dialog =
          new ExtractStyleDialog(
              module,
              fileName,
              supportImplicitParent ? parentStyle : null,
              dirNames,
              extractableAttributes);
      dialog.setTitle(dialogTitle);
      dialog.show();

      if (!dialog.isOK()) {
        return null;
      }
      chosenModule = dialog.getChosenModule();
      assert chosenModule != null;

      styledAttributes = dialog.getStyledAttributes();
      styleName = dialog.getStyleName();
    } else {
      testConfig.validate(extractableAttributes);

      chosenModule = testConfig.getModule();
      styleName = testConfig.getStyleName();
      final Set<String> attrsToExtract =
          new HashSet<String>(Arrays.asList(testConfig.getAttributesToExtract()));
      styledAttributes = new ArrayList<XmlAttribute>();

      for (XmlAttribute attribute : extractableAttributes) {
        if (attrsToExtract.contains(attribute.getName())) {
          styledAttributes.add(attribute);
        }
      }
    }
    final boolean[] success = {false};
    final boolean finalSupportImplicitParent = supportImplicitParent;

    new WriteCommandAction(project, "Extract Android Style '" + styleName + "'", file) {
      @Override
      protected void run(final Result result) throws Throwable {
        final List<XmlAttribute> attributesToDelete = new ArrayList<XmlAttribute>();

        if (!AndroidResourceUtil.createValueResource(
            chosenModule,
            styleName,
            ResourceType.STYLE,
            fileName,
            dirNames,
            new Processor<ResourceElement>() {
              @Override
              public boolean process(ResourceElement element) {
                assert element instanceof Style;
                final Style style = (Style) element;

                for (XmlAttribute attribute : styledAttributes) {
                  if (SdkConstants.NS_RESOURCES.equals(attribute.getNamespace())) {
                    final StyleItem item = style.addItem();
                    item.getName().setStringValue("android:" + attribute.getLocalName());
                    item.setStringValue(attribute.getValue());
                    attributesToDelete.add(attribute);
                  }
                }

                if (parentStyleVlaue != null
                    && (!finalSupportImplicitParent || !styleName.startsWith(parentStyle + "."))) {
                  final String aPackage = parentStyleVlaue.getPackage();
                  style
                      .getParentStyle()
                      .setStringValue((aPackage != null ? aPackage + ":" : "") + parentStyle);
                }
                return true;
              }
            })) {
          return;
        }

        ApplicationManager.getApplication()
            .runWriteAction(
                new Runnable() {
                  @Override
                  public void run() {
                    for (XmlAttribute attribute : attributesToDelete) {
                      attribute.delete();
                    }
                    if (addStyleAttributeToTag) {
                      final LayoutViewElement viewElement = getLayoutViewElement(viewTag);
                      assert viewElement != null;
                      viewElement.getStyle().setStringValue("@style/" + styleName);
                    }
                  }
                });
        success[0] = true;
      }

      @Override
      protected UndoConfirmationPolicy getUndoConfirmationPolicy() {
        return UndoConfirmationPolicy.REQUEST_CONFIRMATION;
      }
    }.execute();

    return success[0] ? styleName : null;
  }
 public String getConfigurationTypeDescription() {
   return AndroidBundle.message("android.run.configuration.type.description");
 }
  @Override
  protected void commitForNext() throws CommitStepException {
    final String apkPath = myApkPathField.getText().trim();
    if (apkPath.length() == 0) {
      throw new CommitStepException(
          AndroidBundle.message("android.extract.package.specify.apk.path.error"));
    }

    AndroidFacet facet = myWizard.getFacet();
    PropertiesComponent properties = PropertiesComponent.getInstance(myWizard.getProject());
    properties.setValue(
        ChooseModuleStep.MODULE_PROPERTY, facet != null ? facet.getModule().getName() : "");
    properties.setValue(APK_PATH_PROPERTY, apkPath);

    File folder = new File(apkPath).getParentFile();
    if (folder == null) {
      throw new CommitStepException(
          AndroidBundle.message("android.cannot.create.file.error", apkPath));
    }
    try {
      if (!folder.exists()) {
        folder.mkdirs();
      }
    } catch (Exception e) {
      throw new CommitStepException(e.getMessage());
    }

    final CompilerManager manager = CompilerManager.getInstance(myWizard.getProject());
    final CompileScope compileScope = manager.createModuleCompileScope(facet.getModule(), true);
    AndroidCompileUtil.setReleaseBuild(compileScope);

    properties.setValue(RUN_PROGUARD_PROPERTY, Boolean.toString(myProguardCheckBox.isSelected()));

    if (myProguardCheckBox.isSelected()) {
      final String proguardCfgPath = myProguardConfigFilePathField.getText().trim();
      if (proguardCfgPath.length() == 0) {
        throw new CommitStepException(
            AndroidBundle.message("android.extract.package.specify.proguard.cfg.path.error"));
      }
      properties.setValue(PROGUARD_CFG_PATH_PROPERTY, proguardCfgPath);

      if (!new File(proguardCfgPath).isFile()) {
        throw new CommitStepException("Cannot find file " + proguardCfgPath);
      }

      compileScope.putUserData(AndroidProguardCompiler.PROGUARD_CFG_PATH_KEY, proguardCfgPath);
    }

    manager.make(
        compileScope,
        new CompileStatusNotification() {
          public void finished(
              boolean aborted, int errors, int warnings, CompileContext compileContext) {
            if (aborted || errors != 0) {
              return;
            }

            final String title = AndroidBundle.message("android.extract.package.task.title");
            ProgressManager.getInstance()
                .run(
                    new Task.Backgroundable(myWizard.getProject(), title, true, null) {
                      public void run(@NotNull ProgressIndicator indicator) {
                        createAndAlignApk(apkPath);
                      }
                    });
          }
        });
  }
 @NotNull
 @Override
 public String getDescription() {
   return AndroidBundle.message("android.renderscript.compiler.description");
 }
 @Override
 @NotNull
 public String getPresentableName() {
   return AndroidBundle.message("android.sdk.presentable.name");
 }
 public String getDisplayName() {
   return AndroidBundle.message("android.run.configuration.type.name");
 }
  @Override
  public boolean setupSdkPaths(Sdk sdk, SdkModel sdkModel) {
    final List<String> javaSdks = new ArrayList<String>();
    final Sdk[] sdks = sdkModel.getSdks();
    for (Sdk jdk : sdks) {
      if (AndroidSdkUtils.isApplicableJdk(jdk)) {
        javaSdks.add(jdk.getName());
      }
    }

    if (javaSdks.isEmpty()) {
      Messages.showErrorDialog(
          AndroidBundle.message("no.jdk.for.android.found.error"), "No Java SDK Found");
      return false;
    }

    int choice =
        Messages.showChooseDialog(
            "Please select Java SDK",
            "Select Internal Java Platform",
            ArrayUtil.toStringArray(javaSdks),
            javaSdks.get(0),
            Messages.getQuestionIcon());

    if (choice == -1) {
      return false;
    }

    final String name = javaSdks.get(choice);
    final Sdk jdk = sdkModel.findSdk(name);

    MessageBuildingSdkLog log = new MessageBuildingSdkLog();
    AndroidSdkData sdkData = AndroidSdkData.parse(sdk.getHomePath(), log);

    if (sdkData == null) {
      String errorMessage =
          log.getErrorMessage().length() > 0
              ? log.getErrorMessage()
              : AndroidBundle.message("cannot.parse.sdk.error");
      Messages.showErrorDialog(errorMessage, "SDK Parsing Error");
      return false;
    }

    IAndroidTarget[] targets = sdkData.getTargets();

    if (targets.length == 0) {
      Messages.showErrorDialog(
          AndroidBundle.message("no.android.targets.error"), CommonBundle.getErrorTitle());
      return false;
    }

    String[] targetNames = new String[targets.length];

    String newestPlatform = null;
    AndroidVersion version = null;

    for (int i = 0; i < targets.length; i++) {
      IAndroidTarget target = targets[i];
      String targetName = AndroidSdkUtils.getTargetPresentableName(target);
      targetNames[i] = targetName;
      if (target.isPlatform() && (version == null || target.getVersion().compareTo(version) > 0)) {
        newestPlatform = targetName;
        version = target.getVersion();
      }
    }

    choice =
        Messages.showChooseDialog(
            "Select build target",
            "Create New Android SDK",
            targetNames,
            newestPlatform != null ? newestPlatform : targetNames[0],
            Messages.getQuestionIcon());

    if (choice == -1) {
      return false;
    }

    AndroidSdkUtils.setUpSdk(sdk, jdk, sdks, targets[choice], true);

    return true;
  }