Search in sources :

Example 1 with CommitStepException

use of com.intellij.ide.wizard.CommitStepException in project intellij-community by JetBrains.

the class AbstractProjectWizard method doFinishAction.

@VisibleForTesting
public boolean doFinishAction() {
    if (myDelegate != null) {
        myDelegate.doFinishAction();
        return true;
    }
    int idx = getCurrentStep();
    try {
        do {
            final ModuleWizardStep step = mySteps.get(idx);
            if (step != getCurrentStepObject()) {
                step.updateStep();
            }
            if (!commitStepData(step)) {
                return false;
            }
            step.onStepLeaving();
            try {
                step._commit(true);
            } catch (CommitStepException e) {
                handleCommitException(e);
                return false;
            }
            if (!isLastStep(idx)) {
                idx = getNextStep(idx);
            } else {
                for (ModuleWizardStep wizardStep : mySteps) {
                    try {
                        wizardStep.onWizardFinished();
                    } catch (CommitStepException e) {
                        handleCommitException(e);
                        return false;
                    }
                }
                break;
            }
        } while (true);
    } finally {
        myCurrentStep = idx;
        updateStep();
    }
    return true;
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with CommitStepException

use of com.intellij.ide.wizard.CommitStepException in project android by JetBrains.

the class GradleSignStep method commitForNext.

@Override
protected void commitForNext() throws CommitStepException {
    if (myAndroidModel == null) {
        throw new CommitStepException(AndroidBundle.message("android.apk.sign.gradle.no.model"));
    }
    final String apkFolder = myApkPathField.getText().trim();
    if (apkFolder.isEmpty()) {
        throw new CommitStepException(AndroidBundle.message("android.apk.sign.gradle.missing.destination"));
    }
    File f = new File(apkFolder);
    if (!f.isDirectory() || !f.canWrite()) {
        throw new CommitStepException(AndroidBundle.message("android.apk.sign.gradle.invalid.destination"));
    }
    int[] selectedFlavorIndices = myFlavorsList.getSelectedIndices();
    if (!myFlavorsListModel.isEmpty() && selectedFlavorIndices.length == 0) {
        throw new CommitStepException(AndroidBundle.message("android.apk.sign.gradle.missing.flavors"));
    }
    Object[] selectedFlavors = myFlavorsList.getSelectedValues();
    List<String> flavors = new ArrayList<String>(selectedFlavors.length);
    for (int i = 0; i < selectedFlavors.length; i++) {
        flavors.add((String) selectedFlavors[i]);
    }
    boolean isV1 = myV1JarSignatureCheckBox.isSelected();
    boolean isV2 = myV2FullAPKSignatureCheckBox.isSelected();
    if (myV1JarSignatureCheckBox.isEnabled() && !isV1 && !isV2) {
        throw new CommitStepException(AndroidBundle.message("android.apk.sign.gradle.missing.signature-version"));
    }
    myWizard.setApkPath(apkFolder);
    myWizard.setGradleOptions((String) myBuildTypeCombo.getSelectedItem(), flavors);
    myWizard.setV1Signature(isV1);
    myWizard.setV2Signature(isV2);
    PropertiesComponent properties = PropertiesComponent.getInstance(myWizard.getProject());
    properties.setValue(PROPERTY_APK_PATH, apkFolder);
    properties.setValues(PROPERTY_FLAVORS, ArrayUtil.toStringArray(flavors));
    properties.setValue(PROPERTY_BUILD_TYPE, (String) myBuildTypeCombo.getSelectedItem());
    properties.setValue(PROPERTY_V1_SIGN, myV1JarSignatureCheckBox.isSelected());
    properties.setValue(PROPERTY_V2_SIGN, myV2FullAPKSignatureCheckBox.isSelected());
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.TIntArrayList) File(java.io.File) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 3 with CommitStepException

use of com.intellij.ide.wizard.CommitStepException in project android by JetBrains.

the class KeystoreStep method commitForNext.

@Override
protected void commitForNext() throws CommitStepException {
    final String keyStoreLocation = myKeyStorePathField.getText().trim();
    if (keyStoreLocation.length() == 0) {
        throw new CommitStepException(AndroidBundle.message("android.export.package.specify.keystore.location.error"));
    }
    final char[] keyStorePassword = myKeyStorePasswordField.getPassword();
    if (keyStorePassword.length == 0) {
        throw new CommitStepException(AndroidBundle.message("android.export.package.specify.key.store.password.error"));
    }
    final String keyAlias = myKeyAliasField.getText().trim();
    if (keyAlias.length() == 0) {
        throw new CommitStepException(AndroidBundle.message("android.export.package.specify.key.alias.error"));
    }
    final char[] keyPassword = myKeyPasswordField.getPassword();
    if (keyPassword.length == 0) {
        throw new CommitStepException(AndroidBundle.message("android.export.package.specify.key.password.error"));
    }
    if (myUseGradleForSigning) {
        myWizard.setGradleSigningInfo(new GradleSigningInfo(keyStoreLocation, keyStorePassword, keyAlias, keyPassword));
    } else {
        final KeyStore keyStore = loadKeyStore(new File(keyStoreLocation));
        if (keyStore == null) {
            throw new CommitStepException(AndroidBundle.message("android.export.package.keystore.error.title"));
        }
        loadKeyAndSaveToWizard(keyStore, keyAlias, keyPassword);
    }
    final Project project = myWizard.getProject();
    final GenerateSignedApkSettings settings = GenerateSignedApkSettings.getInstance(project);
    settings.KEY_STORE_PATH = keyStoreLocation;
    settings.KEY_ALIAS = keyAlias;
    final boolean rememberPasswords = myRememberPasswordCheckBox.isSelected();
    settings.REMEMBER_PASSWORDS = rememberPasswords;
    final PasswordSafe passwordSafe = PasswordSafe.getInstance();
    final String keyStorePasswordKey = makePasswordKey(KEY_STORE_PASSWORD_KEY, keyStoreLocation, null);
    final String keyPasswordKey = makePasswordKey(KEY_PASSWORD_KEY, keyStoreLocation, keyAlias);
    passwordSafe.setPassword(KeystoreStep.class, keyStorePasswordKey, rememberPasswords ? new String(keyStorePassword) : null);
    passwordSafe.setPassword(KeystoreStep.class, keyPasswordKey, rememberPasswords ? new String(keyPassword) : null);
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) Project(com.intellij.openapi.project.Project) KeyStore(java.security.KeyStore) File(java.io.File) PasswordSafe(com.intellij.ide.passwordSafe.PasswordSafe)

Example 4 with CommitStepException

use of com.intellij.ide.wizard.CommitStepException in project android by JetBrains.

the class KeystoreStep method loadKeyStore.

private KeyStore loadKeyStore(File keystoreFile) throws CommitStepException {
    final char[] password = myKeyStorePasswordField.getPassword();
    FileInputStream fis = null;
    AndroidUtils.checkPassword(password);
    if (!keystoreFile.isFile()) {
        throw new CommitStepException(AndroidBundle.message("android.cannot.find.file.error", keystoreFile.getPath()));
    }
    final KeyStore keyStore;
    try {
        keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        //noinspection IOResourceOpenedButNotSafelyClosed
        fis = new FileInputStream(keystoreFile);
        keyStore.load(fis, password);
    } catch (Exception e) {
        throw new CommitStepException(e.getMessage());
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException ignored) {
            }
        }
        Arrays.fill(password, '\0');
    }
    return keyStore;
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) CommitStepException(com.intellij.ide.wizard.CommitStepException) IOException(java.io.IOException)

Example 5 with CommitStepException

use of com.intellij.ide.wizard.CommitStepException in project android by JetBrains.

the class KeystoreStep method loadKeyAndSaveToWizard.

private void loadKeyAndSaveToWizard(KeyStore keyStore, String alias, char[] keyPassword) throws CommitStepException {
    KeyStore.PrivateKeyEntry entry;
    try {
        assert keyStore != null;
        entry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias, new KeyStore.PasswordProtection(keyPassword));
    } catch (Exception e) {
        throw new CommitStepException("Error: " + e.getMessage());
    }
    if (entry == null) {
        throw new CommitStepException(AndroidBundle.message("android.extract.package.cannot.find.key.error", alias));
    }
    PrivateKey privateKey = entry.getPrivateKey();
    Certificate certificate = entry.getCertificate();
    if (privateKey == null || certificate == null) {
        throw new CommitStepException(AndroidBundle.message("android.extract.package.cannot.find.key.error", alias));
    }
    myWizard.setPrivateKey(privateKey);
    myWizard.setCertificate((X509Certificate) certificate);
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) PrivateKey(java.security.PrivateKey) KeyStore(java.security.KeyStore) CommitStepException(com.intellij.ide.wizard.CommitStepException) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

CommitStepException (com.intellij.ide.wizard.CommitStepException)11 File (java.io.File)4 KeyStore (java.security.KeyStore)4 IOException (java.io.IOException)3 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)2 FileInputStream (java.io.FileInputStream)2 PrivateKey (java.security.PrivateKey)2 Certificate (java.security.cert.Certificate)2 X509Certificate (java.security.cert.X509Certificate)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 PasswordSafe (com.intellij.ide.passwordSafe.PasswordSafe)1 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)1 CompileScope (com.intellij.openapi.compiler.CompileScope)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiNameHelper (com.intellij.psi.PsiNameHelper)1 TIntArrayList (gnu.trove.TIntArrayList)1