public static String getStringPatch( @NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages, int maxSize) { if (patchedUsages.size() == 0) return ""; String patchStr = ConvertUsagesUtil.convertUsages(patchedUsages); if (maxSize > 0 && patchStr.getBytes().length > maxSize) { patchStr = ConvertUsagesUtil.cutPatchString(patchStr, maxSize); } return patchStr; }
public static <T extends UsageDescriptor> String getDataString( @NotNull Map<GroupDescriptor, Set<T>> usages, int maxSize) { if (usages.isEmpty()) { return ""; } String dataStr = ConvertUsagesUtil.convertUsages(usages); return maxSize > 0 && dataStr.getBytes(CharsetToolkit.UTF8_CHARSET).length > maxSize ? ConvertUsagesUtil.cutDataString(dataStr, maxSize) : dataStr; }
public static void persistSentPatch( @NotNull String patchStr, @NotNull SentUsagesPersistence persistenceComponent) { Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = mapToPatchedUsagesMap(ConvertUsagesUtil.convertString(patchStr)); if (patchedUsages.size() > 0) persistenceComponent.persistPatch(patchedUsages); }
private void runTriggers(Executor executor, RunnerAndConfigurationSettings configuration) { final ConfigurationType configurationType = configuration.getType(); if (configurationType != null) { UsageTrigger.trigger( "execute." + ConvertUsagesUtil.ensureProperKey(configurationType.getId()) + "." + executor.getId()); } }
@Nullable private Project generateProject( @NotNull final Project project, @NotNull final AbstractProjectSettingsStep settings) { final DirectoryProjectGenerator generator = settings.getProjectGenerator(); final File location = new File(settings.getProjectLocation()); if (!location.exists() && !location.mkdirs()) { Messages.showErrorDialog( project, "Cannot create directory '" + location + "'", "Create Project"); return null; } final VirtualFile baseDir = ApplicationManager.getApplication() .runWriteAction( new Computable<VirtualFile>() { public VirtualFile compute() { return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location); } }); LOG.assertTrue(baseDir != null, "Couldn't find '" + location + "' in VFS"); baseDir.refresh(false, true); if (baseDir.getChildren().length > 0) { int rc = Messages.showYesNoDialog( project, "The directory '" + location + "' is not empty. Would you like to create a project from existing sources instead?", "Create New Project", Messages.getQuestionIcon()); if (rc == Messages.YES) { return PlatformProjectOpenProcessor.getInstance().doOpenProject(baseDir, null, false); } } String generatorName = generator == null ? "empty" : ConvertUsagesUtil.ensureProperKey(generator.getName()); UsageTrigger.trigger("NewDirectoryProjectAction." + generatorName); GeneralSettings.getInstance().setLastProjectCreationLocation(location.getParent()); return PlatformProjectOpenProcessor.doOpenProject( baseDir, null, false, -1, new ProjectOpenedCallback() { @Override public void projectOpened(Project project, Module module) { if (generator != null) { Object projectSettings = null; if (generator instanceof PythonProjectGenerator) { projectSettings = ((PythonProjectGenerator) generator).getProjectSettings(); } else if (generator instanceof WebProjectTemplate) { projectSettings = ((WebProjectTemplate) generator).getPeer().getSettings(); } if (projectSettings instanceof PyNewProjectSettings) { ((PyNewProjectSettings) projectSettings).setSdk(settings.getSdk()); ((PyNewProjectSettings) projectSettings) .setInstallFramework(settings.installFramework()); } //noinspection unchecked generator.generateProject(project, baseDir, projectSettings, module); } } }, false); }
public static void executeConfiguration( @NotNull ExecutionEnvironment environment, boolean showSettings, boolean assignNewId) { if (ExecutorRegistry.getInstance().isStarting(environment)) { return; } RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings(); if (runnerAndConfigurationSettings != null) { if (!ExecutionTargetManager.canRun(environment)) { ExecutionUtil.handleExecutionError( environment, new ExecutionException( StringUtil.escapeXml( "Cannot run '" + environment.getRunProfile().getName() + "' on '" + environment.getExecutionTarget().getDisplayName() + "'"))); return; } if (!RunManagerImpl.canRunConfiguration(environment) || (showSettings && runnerAndConfigurationSettings.isEditBeforeRun())) { if (!RunDialog.editConfiguration(environment, "Edit configuration")) { return; } while (!RunManagerImpl.canRunConfiguration(environment)) { if (Messages.YES == Messages.showYesNoDialog( environment.getProject(), "Configuration is still incorrect. Do you want to edit it again?", "Change Configuration Settings", "Edit", "Continue Anyway", Messages.getErrorIcon())) { if (!RunDialog.editConfiguration(environment, "Edit configuration")) { return; } } else { break; } } } ConfigurationType configurationType = runnerAndConfigurationSettings.getType(); if (configurationType != null) { UsageTrigger.trigger( "execute." + ConvertUsagesUtil.ensureProperKey(configurationType.getId()) + "." + environment.getExecutor().getId()); } } try { if (assignNewId) { environment.assignNewExecutionId(); } environment.getRunner().execute(environment); } catch (ExecutionException e) { String name = runnerAndConfigurationSettings != null ? runnerAndConfigurationSettings.getName() : null; if (name == null) { name = environment.getRunProfile().getName(); } if (name == null && environment.getContentToReuse() != null) { name = environment.getContentToReuse().getDisplayName(); } if (name == null) { name = "<Unknown>"; } ExecutionUtil.handleExecutionError( environment.getProject(), environment.getExecutor().getToolWindowId(), name, e); } }