Search in sources :

Example 6 with CommitStepException

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

the class NewKeyForm method loadKeystoreAndKey.

private void loadKeystoreAndKey(String keystoreLocation, String keystorePassword, String keyAlias, String keyPassword) throws CommitStepException {
    FileInputStream fis = null;
    try {
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        fis = new FileInputStream(new File(keystoreLocation));
        keyStore.load(fis, keystorePassword.toCharArray());
        myKeyStore = keyStore;
        KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(keyAlias, new KeyStore.PasswordProtection(keyPassword.toCharArray()));
        if (entry == null) {
            throw new CommitStepException(AndroidBundle.message("android.extract.package.cannot.find.key.error", keyAlias));
        }
        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", keyAlias));
        }
        myPrivateKey = privateKey;
        myCertificate = (X509Certificate) certificate;
    } catch (Exception e) {
        throw new CommitStepException("Error: " + e.getMessage());
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException ignored) {
            }
        }
    }
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) PrivateKey(java.security.PrivateKey) IOException(java.io.IOException) KeyStore(java.security.KeyStore) File(java.io.File) FileInputStream(java.io.FileInputStream) CommitStepException(com.intellij.ide.wizard.CommitStepException) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 7 with CommitStepException

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

the class ApkStep method _commit.

@Override
public void _commit(boolean finishChosen) 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(getApkPathPropertyName(), 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 CompileScope compileScope = CompilerManager.getInstance(myWizard.getProject()).createModuleCompileScope(facet.getModule(), true);
    AndroidCompileUtil.setReleaseBuild(compileScope);
    properties.setValue(RUN_PROGUARD_PROPERTY, Boolean.toString(myProguardCheckBox.isSelected()));
    if (myProguardCheckBox.isSelected()) {
        final List<String> proguardOsCfgPaths = myProGuardConfigFilesPanel.getOsPaths();
        if (proguardOsCfgPaths.isEmpty()) {
            throw new CommitStepException(AndroidBundle.message("android.extract.package.specify.proguard.cfg.path.error"));
        }
        final String proguardPathsStr = mergeProguardCfgPathsToOneString(proguardOsCfgPaths);
        properties.setValue(PROGUARD_CFG_PATHS_PROPERTY, proguardPathsStr);
        for (String path : proguardOsCfgPaths) {
            if (!new File(path).isFile()) {
                throw new CommitStepException("Cannot find file " + path);
            }
        }
        compileScope.putUserData(AndroidCompileUtil.PROGUARD_CFG_PATHS_KEY, proguardPathsStr);
    }
    myWizard.setCompileScope(compileScope);
    myWizard.setApkPath(apkPath);
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) CompileScope(com.intellij.openapi.compiler.CompileScope) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) CommitStepException(com.intellij.ide.wizard.CommitStepException)

Example 8 with CommitStepException

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

the class ChooseModuleStep method commitForNext.

@Override
protected void commitForNext() throws CommitStepException {
    if (myCheckModulePanel.hasError()) {
        throw new CommitStepException(AndroidBundle.message("android.project.contains.errors.error"));
    }
    AndroidFacet selectedFacet = getSelectedFacet();
    assert selectedFacet != null;
    myWizard.setFacet(selectedFacet);
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 9 with CommitStepException

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

the class ModuleWizardStepAdapterTest method onWizardFinishedLogsExceptions.

@Test
public void onWizardFinishedLogsExceptions() throws CommitStepException {
    Logger testLogger = mock(Logger.class);
    ModuleWizardStepAdapter.setLog(testLogger);
    ModuleWizardStepAdapter.AdapterModel model = new ModuleWizardStepAdapter.AdapterModel(myToWrap);
    doThrow(new CommitStepException("Test Message")).when(myToWrap).onWizardFinished();
    model.handleFinished();
    verify(testLogger).error("Test Message");
    ModuleWizardStepAdapter.setLog(null);
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) Logger(com.intellij.openapi.diagnostic.Logger) Test(org.junit.Test)

Example 10 with CommitStepException

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

the class BeanStep method _commit.

public void _commit(boolean finishChosen) throws CommitStepException {
    final boolean newBindToNewBean = myRbBindToNewBean.isSelected();
    if (myData.myBindToNewBean != newBindToNewBean) {
        resetBindings();
    }
    myData.myBindToNewBean = newBindToNewBean;
    if (myData.myBindToNewBean) {
        // new bean
        final String oldShortClassName = myData.myShortClassName;
        final String oldPackageName = myData.myPackageName;
        final String shortClassName = myTfShortClassName.getText().trim();
        if (shortClassName.length() == 0) {
            throw new CommitStepException(UIDesignerBundle.message("error.please.specify.class.name.of.the.bean.to.be.created"));
        }
        final PsiManager psiManager = PsiManager.getInstance(myData.myProject);
        if (!PsiNameHelper.getInstance(psiManager.getProject()).isIdentifier(shortClassName)) {
            throw new CommitStepException(UIDesignerBundle.message("error.X.is.not.a.valid.class.name", shortClassName));
        }
        final String packageName = myTfWithBtnChoosePackage.getText().trim();
        if (packageName.length() != 0 && JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(packageName) == null) {
            throw new CommitStepException(UIDesignerBundle.message("error.package.with.name.X.does.not.exist", packageName));
        }
        myData.myShortClassName = shortClassName;
        myData.myPackageName = packageName;
        // check whether new class already exists
        {
            final String fullClassName = packageName.length() != 0 ? packageName + "." + shortClassName : shortClassName;
            final Module module = ModuleUtil.findModuleForFile(myData.myFormFile, myData.myProject);
            if (JavaPsiFacade.getInstance(psiManager.getProject()).findClass(fullClassName, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)) != null) {
                throw new CommitStepException(UIDesignerBundle.message("error.cannot.create.class.X.because.it.already.exists", fullClassName));
            }
        }
        if (!Comparing.equal(oldShortClassName, shortClassName) || !Comparing.equal(oldPackageName, packageName)) {
            // After bean class changed we need to reset all previously set bindings
            resetBindings();
        }
    } else {
        // existing bean
        final String oldFqClassName = myData.myBeanClass != null ? myData.myBeanClass.getQualifiedName() : null;
        final String newFqClassName = myTfWitgBtnChooseClass.getText().trim();
        if (newFqClassName.length() == 0) {
            throw new CommitStepException(UIDesignerBundle.message("error.please.specify.fully.qualified.name.of.bean.class"));
        }
        final PsiClass aClass = JavaPsiFacade.getInstance(myData.myProject).findClass(newFqClassName, GlobalSearchScope.allScope(myData.myProject));
        if (aClass == null) {
            throw new CommitStepException(UIDesignerBundle.message("error.class.with.name.X.does.not.exist", newFqClassName));
        }
        myData.myBeanClass = aClass;
        if (!Comparing.equal(oldFqClassName, newFqClassName)) {
            // After bean class changed we need to reset all previously set bindings
            resetBindings();
        }
    }
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) Module(com.intellij.openapi.module.Module)

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