예제 #1
0
  @Nonnull
  public DockerFile newInstance(@Nonnull String href, @Nonnull String name, @Nonnull String path) {
    CurrentProject currentProject = appContext.getCurrentProject();
    if (currentProject == null) {
      throw new IllegalStateException("No project is opened");
    }

    Link link = dtoFactory.createDto(Link.class).withHref(href).withRel(DockerFile.GET_CONTENT);
    List<Link> links = Arrays.asList(link);

    ItemReference recipeFileItem =
        dtoFactory
            .createDto(ItemReference.class)
            .withName(name)
            .withPath(path)
            .withMediaType(TYPE)
            .withLinks(links);

    return new DockerFile(
        eventBus,
        projectServiceClient,
        dtoUnmarshallerFactory,
        recipeFileItem,
        currentProject.getCurrentTree(),
        editorAgent);
  }
  /** Creates and returns 'default' project wizard with pre-defined pages only. */
  private ImportWizard createDefaultWizard() {
    final ProjectConfigDto dataObject =
        dtoFactory
            .createDto(ProjectConfigDto.class)
            .withSource(dtoFactory.createDto(SourceStorageDto.class).withType("").withLocation(""));

    final ImportWizard importWizard = importWizardFactory.newWizard(dataObject);
    importWizard.setUpdateDelegate(this);
    // add pre-defined first page
    importWizard.addPage(mainPage);
    return importWizard;
  }
  /**
   * Adds already running runner.
   *
   * @param processDescriptor The descriptor of new runner
   * @return instance of new runner
   */
  @NotNull
  public Runner addRunner(@NotNull ApplicationProcessDescriptor processDescriptor) {
    RunOptions runOptions = dtoFactory.createDto(RunOptions.class);
    Runner runner = modelsFactory.createRunner(runOptions);

    String environmentId = processDescriptor.getEnvironmentId();

    if (environmentId != null && environmentId.startsWith(PROJECT_PREFIX)) {
      runner.setScope(PROJECT);
    }

    runnersId.add(processDescriptor.getProcessId());

    runner.setProcessDescriptor(processDescriptor);
    runner.setRAM(processDescriptor.getMemorySize());
    runner.setStatus(Runner.Status.DONE);
    runner.resetCreationTime();

    history.addRunner(runner);

    onSelectionChanged(RUNNER);

    runnerTimer.schedule(ONE_SEC.getValue());

    LaunchAction launchAction = actionFactory.createLaunch();
    runnerActions.put(runner, launchAction);

    launchAction.perform(runner);

    selectHistoryTab();

    return runner;
  }
예제 #4
0
  @Override
  public void actionPerformed() {
    if (compilationUnit != null) {
      EditorPartPresenter editorPartPresenter =
          editorAgent.getOpenedEditor(Path.valueOf(compilationUnit.getPath()));
      if (editorPartPresenter != null) {
        editorAgent.activateEditor(editorPartPresenter);
        fileOpened(editorPartPresenter);
        return;
      }

      projectExplorer
          .getNodeByPath(new HasStorablePath.StorablePath(compilationUnit.getPath()))
          .then(selectNode())
          .then(openNode());
    } else if (classFile != null) {
      String className = classFile.getElementName();

      JarEntry jarEntry = dtoFactory.createDto(JarEntry.class);
      jarEntry.setName(className);
      jarEntry.setType(JarEntry.JarEntryType.CLASS_FILE);
      jarEntry.setPath(classFile.getPath());

      JarFileNode jarFileNode =
          javaNodeManager
              .getJavaNodeFactory()
              .newJarFileNode(
                  jarEntry,
                  null,
                  appContext.getCurrentProject().getProjectConfig(),
                  javaNodeManager.getJavaSettingsProvider().getSettings());
      openFile(jarFileNode);
    }
  }
  /** {@inheritDoc} */
  @Override
  public Runner launchRunner() {
    CurrentProject currentProject = appContext.getCurrentProject();
    if (currentProject == null) {
      throw new IllegalStateException(
          "Can't launch runner for current project. Current project is absent...");
    }

    int ram = DEFAULT.getValue();

    RunnersDescriptor runnersDescriptor = currentProject.getProjectDescription().getRunners();
    String defaultRunner = runnersDescriptor.getDefault();

    if (!EnvironmentIdValidator.isValid(defaultRunner)) {
      defaultRunner = URL.encode(defaultRunner);
    }

    RunnerConfiguration defaultConfigs = runnersDescriptor.getConfigs().get(defaultRunner);

    if (defaultRunner != null && defaultConfigs != null) {
      ram = defaultConfigs.getRam();
    }

    RunOptions runOptions =
        dtoFactory
            .createDto(RunOptions.class)
            .withSkipBuild(Boolean.valueOf(currentProject.getAttributeValue("runner:skipBuild")))
            .withEnvironmentId(defaultRunner)
            .withMemorySize(ram);

    Environment environment = chooseRunnerAction.selectEnvironment();
    if (environment != null) {
      if (defaultRunner != null && defaultRunner.equals(environment.getId())) {
        Runner runner = modelsFactory.createRunner(runOptions);
        if (defaultRunner.startsWith(PROJECT_PREFIX)) {
          runner.setScope(PROJECT);
        }
        return launchRunner(runner);
      }
      runOptions =
          runOptions
              .withOptions(environment.getOptions())
              .withMemorySize(environment.getRam())
              .withEnvironmentId(environment.getId());
      Runner runner =
          modelsFactory.createRunner(runOptions, environment.getScope(), environment.getName());
      if (environment.getId().startsWith(PROJECT_PREFIX)) {
        runner.setScope(PROJECT);
      }
      return launchRunner(runner);
    }

    Runner runner = modelsFactory.createRunner(runOptions);
    if (defaultRunner != null && defaultRunner.startsWith(PROJECT_PREFIX)) {
      runner.setScope(PROJECT);
    }
    return launchRunner(modelsFactory.createRunner(runOptions));
  }
예제 #6
0
  /** {@inheritDoc} */
  @Override
  public void onCheckoutClicked() {
    String name = selectedBranch.getDisplayName();

    if (name == null) {
      return;
    }

    final CheckoutRequest checkoutRequest = dtoFactory.createDto(CheckoutRequest.class);
    if (selectedBranch.isRemote()) {
      checkoutRequest.setTrackBranch(selectedBranch.getDisplayName());
    } else {
      checkoutRequest.setName(selectedBranch.getDisplayName());
    }

    final ProjectConfigDto root = project.getRootProject();
    final String path = root.getPath();
    final String projectType = root.getType();

    service.checkout(
        workspaceId,
        root,
        checkoutRequest,
        new AsyncRequestCallback<String>() {
          @Override
          protected void onSuccess(String result) {
            getBranches();
            // In this case we can have unconfigured state of the project,
            // so we must repeat the logic which is performed when we open a project
            projectService.getProject(
                workspaceId,
                path,
                new AsyncRequestCallback<ProjectConfigDto>(
                    dtoUnmarshallerFactory.newUnmarshaller(ProjectConfigDto.class)) {
                  @Override
                  protected void onSuccess(ProjectConfigDto result) {
                    result.setType(projectType);
                    updateProject(result);
                  }

                  @Override
                  protected void onFailure(Throwable exception) {
                    notificationManager.notify(
                        exception.getLocalizedMessage(), FAIL, true, project.getProjectConfig());
                  }
                });
          }

          @Override
          protected void onFailure(Throwable exception) {
            final GitOutputConsole console =
                gitOutputConsoleFactory.create(BRANCH_CHECKOUT_COMMAND_NAME);
            printGitMessage(exception.getMessage(), console);
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachineId(), console);
          }
        });
  }
  private Problem createProblem(JavaAnnotation javaAnnotation, Position pos) {
    Problem problem = dtoFactory.createDto(Problem.class);
    // server use only this fields
    problem.setID(javaAnnotation.getId());
    problem.setError(javaAnnotation.isError());
    problem.setArguments(Arrays.asList(javaAnnotation.getArguments()));
    problem.setSourceStart(pos.getOffset());
    // TODO I don't know why but in that place source end is bugger on 1 char
    problem.setSourceEnd(pos.getOffset() + pos.getLength() - 1);

    return problem;
  }
예제 #8
0
  @Override
  public void generateFromArchetypeChanged(boolean isGenerateFromArchetype) {
    view.setPackagingVisibility(!isGenerateFromArchetype);
    view.enableArchetypes(isGenerateFromArchetype);
    if (!isGenerateFromArchetype) {
      view.clearArchetypes();
    } else {
      view.setArchetypes(MavenExtension.getAvailableArchetypes());
    }

    final GeneratorDescription generatorDescription =
        dtoFactory.createDto(GeneratorDescription.class);
    if (isGenerateFromArchetype) {
      fillGeneratorDescription(generatorDescription);
    }
    dataObject.getProject().setGeneratorDescription(generatorDescription);

    updateDelegate.updateControls();
  }
  @Test
  public void shouldRestoreState() throws Exception {
    CommandType commandType = mock(CommandType.class);
    CommandConfiguration commandConfiguration = mock(CommandConfiguration.class);
    CommandConfigurationFactory commandConfigurationFactory =
        mock(CommandConfigurationFactory.class);
    CommandOutputConsole outputConsole = mock(CommandOutputConsole.class);
    when(commandTypeRegistry.getCommandTypeById(anyString())).thenReturn(commandType);
    when(commandType.getConfigurationFactory()).thenReturn(commandConfigurationFactory);
    when(commandConfigurationFactory.createFromDto(anyObject())).thenReturn(commandConfiguration);
    when(commandConsoleFactory.create(anyObject(), anyString())).thenReturn(outputConsole);

    CommandDto commandDto = mock(CommandDto.class);
    when(dtoFactory.createDto(anyObject())).thenReturn(commandDto);
    when(commandDto.withName(anyString())).thenReturn(commandDto);
    when(commandDto.withCommandLine(anyString())).thenReturn(commandDto);
    when(commandDto.withType(anyString())).thenReturn(commandDto);

    MachineProcessDto machineProcessDto = mock(MachineProcessDto.class);
    when(machineProcessDto.getOutputChannel()).thenReturn(OUTPUT_CHANNEL);
    when(machineProcessDto.getPid()).thenReturn(PID);
    List<MachineProcessDto> processes = new ArrayList<>(1);
    processes.add(machineProcessDto);

    MachineDto machineDto = mock(MachineDto.class);
    MachineConfigDto machineConfigDto = mock(MachineConfigDto.class);
    when(machineDto.getConfig()).thenReturn(machineConfigDto);
    when(machineConfigDto.isDev()).thenReturn(true);
    when(machineDto.getId()).thenReturn(MACHINE_ID);
    when(machineDto.getStatus()).thenReturn(MachineStatus.RUNNING);
    List<MachineDto> machines = new ArrayList<>(2);
    machines.add(machineDto);

    verify(machinesPromise).then(machinesCaptor.capture());
    machinesCaptor.getValue().apply(machines);

    verify(processesPromise).then(processesCaptor.capture());
    processesCaptor.getValue().apply(processes);

    verify(outputConsole).listenToOutput(eq(OUTPUT_CHANNEL));
    verify(outputConsole).attachToProcess(machineProcessDto);
    verify(workspaceAgent).setActivePart(eq(presenter));
  }
  @Override
  public List<ActionDescriptor> getActions(String projectPath) {
    EditorAgent editorAgent = editorAgentProvider.get();
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();

    final List<ActionDescriptor> actions = new ArrayList<>();

    if (activeEditor == null) {
      return Collections.emptyList();
    }

    VirtualFile virtualFile = activeEditor.getEditorInput().getFile();

    String openNodeActionId = actionManager.getId(openFileAction);

    actions.add(
        dtoFactory
            .createDto(ActionDescriptor.class)
            .withId(openNodeActionId)
            .withParameters(Collections.singletonMap(FILE_PARAM_ID, virtualFile.getPath())));
    return actions;
  }
  /** {@inheritDoc} */
  @Override
  public void onRunButtonClicked() {
    if (State.TEMPLATE.equals(panelState.getState())) {
      RunOptions runOptions =
          dtoFactory
              .createDto(RunOptions.class)
              .withOptions(selectedEnvironment.getOptions())
              .withEnvironmentId(selectedEnvironment.getId())
              .withMemorySize(selectedEnvironment.getRam());

      Runner runner =
          modelsFactory.createRunner(
              runOptions, selectedEnvironment.getScope(), selectedEnvironment.getName());

      if (PROJECT.equals(selectedEnvironment.getScope())) {
        runner.setScope(PROJECT);
      }

      launchRunner(runner);
    } else {
      launchRunner();
    }
  }
 private <T> T newDto(Class<T> clazz) {
   return dtoFactory.createDto(clazz);
 }