Search in sources :

Example 1 with PhoneGapCommandLine

use of com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine in project intellij-plugins by JetBrains.

the class PhoneGapPluginsView method runOnPooledThread.

private synchronized void runOnPooledThread(String path, String workDir, PhoneGapConfigurable.RepositoryStore repositoryStore, final VersionCallback callback) {
    final Ref<PhoneGapPackageManagementService> service = new Ref<>();
    final Ref<String> error = new Ref<>();
    final Ref<String> warning = new Ref<>();
    final Ref<String> version = new Ref<>();
    try {
        PhoneGapCommandLine commandLine = checkParams(error, warning, version, path, workDir);
        if (error.get() == null) {
            service.set(new PhoneGapPackageManagementService(commandLine, repositoryStore));
        }
    } catch (Exception e) {
        error.set(PhoneGapBundle.message("phonegap.plugins.executable.error"));
    }
    UIUtil.invokeLaterIfNeeded(() -> {
        myPanel.updatePackages(service.get());
        if (error.get() != null) {
            packagesNotificationPanel.showError(error.get(), null, null);
        }
        if (warning.get() != null) {
            packagesNotificationPanel.showWarning(warning.get());
        }
        callback.forVersion(version.get());
    });
}
Also used : Ref(com.intellij.openapi.util.Ref) PhoneGapCommandLine(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine) ExecutionException(com.intellij.execution.ExecutionException)

Example 2 with PhoneGapCommandLine

use of com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine in project intellij-plugins by JetBrains.

the class PhoneGapPluginsView method checkParams.

private PhoneGapCommandLine checkParams(Ref<String> error, Ref<String> warning, Ref<String> version, String path, String workDir) throws ExecutionException {
    boolean pathError = false;
    if (!new File(workDir).exists()) {
        pathError = true;
        workDir = myProject.getBasePath();
    }
    PhoneGapCommandLine commandLine = new PhoneGapCommandLine(path, workDir);
    if (!commandLine.isCorrectExecutable()) {
        error.set(PhoneGapBundle.message("phonegap.plugins.executable.error"));
        return commandLine;
    }
    version.set(commandLine.version());
    if (pathError) {
        error.set(PhoneGapBundle.message("phonegap.plugins.executable.work.path.error", commandLine.getPlatformName()));
        return commandLine;
    }
    ProcessOutput output = commandLine.pluginListRaw();
    if (!StringUtil.isEmpty(output.getStderr())) {
        error.set(PhoneGapBundle.message("phonegap.plugins.executable.work.path.error", commandLine.getPlatformName()));
        return commandLine;
    }
    if (commandLine.isOld()) {
        warning.set(PhoneGapBundle.message("phonegap.plugins.executable.version.error"));
    }
    return commandLine;
}
Also used : PhoneGapCommandLine(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) File(java.io.File)

Example 3 with PhoneGapCommandLine

use of com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine in project intellij-plugins by JetBrains.

the class PhoneGapRunConfiguration method getCommandLine.

public PhoneGapCommandLine getCommandLine() {
    PhoneGapCommandLine current = myCommandLine;
    String executable = getExecutable();
    String workDir = getWorkDir();
    boolean passParentEnv = myPassParent;
    Map<String, String> env = myEnvs;
    if (current != null && StringUtil.equals(current.getPath(), executable) && StringUtil.equals(current.getWorkDir(), workDir) && passParentEnv == current.isPassParentEnv() && env.equals(current.getEnv())) {
        return current;
    }
    assert executable != null;
    assert workDir != null;
    current = new PhoneGapCommandLine(executable, workDir, passParentEnv, env);
    myCommandLine = current;
    return current;
}
Also used : PhoneGapCommandLine(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine)

Example 4 with PhoneGapCommandLine

use of com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine in project intellij-plugins by JetBrains.

the class PhoneGapProjectPeer method validate.

@Nullable
@Override
public ValidationInfo validate() {
    String path = myExecutablePathField.getText();
    boolean error;
    if (myValidateCache.containsKey(path)) {
        error = myValidateCache.get(path);
    } else {
        try {
            if (StringUtil.isEmpty(path)) {
                return new ValidationInfo(PhoneGapBundle.message("phonegap.incorrect.path.executable"));
            }
            new PhoneGapCommandLine(path, null).version();
            error = false;
        } catch (Exception e) {
            error = true;
        }
        myValidateCache.put(path, error);
    }
    return error ? new ValidationInfo(PhoneGapBundle.message("phonegap.incorrect.path.error")) : null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) PhoneGapCommandLine(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with PhoneGapCommandLine

use of com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine in project intellij-plugins by JetBrains.

the class PhoneGapProjectTemplateGenerator method generateProject.

@Override
public void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir, @NotNull final PhoneGapProjectTemplateGenerator.PhoneGapProjectSettings settings, @NotNull Module module) {
    try {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            try {
                ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
                indicator.setText("Creating...");
                File tempProject = createTemp();
                PhoneGapCommandLine commandLine = new PhoneGapCommandLine(settings.getExecutable(), tempProject.getPath(), settings.getOptions());
                if (!commandLine.isCorrectExecutable()) {
                    showErrorMessage("Incorrect path");
                    return;
                }
                commandLine.createNewProject(settings.name(), indicator);
                File[] array = tempProject.listFiles();
                if (array != null && array.length != 0) {
                    File from = ContainerUtil.getFirstItem(ContainerUtil.newArrayList(array));
                    assert from != null;
                    FileUtil.copyDir(from, new File(baseDir.getPath()));
                    deleteTemp(tempProject);
                } else {
                    showErrorMessage(PhoneGapBundle.message("phonegap.project.template.create.no.files") + " " + tempProject.getAbsolutePath());
                }
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }, PhoneGapBundle.message("phonegap.project.template.create.title"), false, project);
        ApplicationManager.getApplication().runWriteAction(() -> {
            PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(project);
            propertiesComponent.setValue(PhoneGapSettings.PHONEGAP_WORK_DIRECTORY, project.getBasePath());
            PhoneGapSettings.State state = PhoneGapSettings.getInstance().getState();
            if (!StringUtil.equals(settings.getExecutable(), state.getExecutablePath())) {
                PhoneGapSettings.getInstance().loadState(new PhoneGapSettings.State(settings.executable, state.repositoriesList));
            }
            VfsUtil.markDirty(false, true, baseDir);
            createRunConfiguration(project, settings);
            baseDir.refresh(true, true, () -> {
                if (PhoneGapSettings.getInstance().isExcludePlatformFolder()) {
                    VirtualFile platformsFolder = baseDir.findChild(PhoneGapUtil.FOLDER_PLATFORMS);
                    if (platformsFolder != null) {
                        PhoneGapStartupActivity.excludeFolder(project, platformsFolder);
                    }
                    VirtualFile ionicConfig = baseDir.findChild(PhoneGapUtil.IONIC_CONFIG);
                    if (ionicConfig != null) {
                        VirtualFile wwwFolder = baseDir.findChild(PhoneGapUtil.FOLDER_WWW);
                        if (wwwFolder != null) {
                            PhoneGapStartupActivity.excludeFolder(project, wwwFolder);
                        }
                    }
                }
            });
        });
    } catch (Exception e) {
        LOG.warn(e);
        showErrorMessage(e.getMessage());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PhoneGapCommandLine(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) IOException(java.io.IOException) PhoneGapSettings(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.settings.PhoneGapSettings)

Aggregations

PhoneGapCommandLine (com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine)7 ProcessOutput (com.intellij.execution.process.ProcessOutput)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Ref (com.intellij.openapi.util.Ref)2 File (java.io.File)2 PhoneGapSettings (com.github.masahirosuzuka.PhoneGapIntelliJPlugin.settings.PhoneGapSettings)1 BeforeRunTask (com.intellij.execution.BeforeRunTask)1 ExecutionException (com.intellij.execution.ExecutionException)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1