コード例 #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);
  }
コード例 #2
0
  /** 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;
  }
コード例 #3
0
ファイル: MatchNode.java プロジェクト: mkuznyetsov/che
  @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);
    }
  }
コード例 #4
0
  /**
   * 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;
  }
コード例 #5
0
 private void handleError(PromiseError error) {
   view.showLoader(false);
   final ServiceError serviceError =
       dtoFactory.createDtoFromJson(error.getMessage(), ServiceError.class);
   notificationManager.notify(serviceError.getMessage(), FAIL, true);
   view.showError(serviceError.getMessage());
 }
コード例 #6
0
ファイル: BranchPresenter.java プロジェクト: jgallimore/che
  /**
   * Handler some action whether some exception happened.
   *
   * @param throwable exception what happened
   * @param console console for displaying error
   */
  void handleError(@NotNull Throwable throwable, GitOutputConsole console) {
    String errorMessage = throwable.getMessage();
    if (errorMessage == null) {
      console.printError(constant.branchDeleteFailed());
      notificationManager.notify(
          constant.branchDeleteFailed(), FAIL, true, project.getRootProject());
      return;
    }

    try {
      errorMessage = dtoFactory.createDtoFromJson(errorMessage, ServiceError.class).getMessage();
      if (errorMessage.equals("Unable get private ssh key")) {
        console.printError(constant.messagesUnableGetSshKey());
        notificationManager.notify(
            constant.messagesUnableGetSshKeyTitle(),
            constant.messagesUnableGetSshKey(),
            FAIL,
            true,
            project.getRootProject());
        return;
      }
      console.printError(errorMessage);
      notificationManager.notify(errorMessage, FAIL, true, project.getRootProject());
    } catch (Exception e) {
      console.printError(errorMessage);
      notificationManager.notify(errorMessage, FAIL, true, project.getRootProject());
    }
  }
コード例 #7
0
  /** {@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));
  }
コード例 #8
0
ファイル: BranchPresenter.java プロジェクト: jgallimore/che
  /** {@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);
          }
        });
  }
コード例 #9
0
  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;
  }
コード例 #10
0
  protected void init() {
    setProvider(getNativeProvider());
    setTemplating(
        dtoFactory.createDtoFromJson(
            javaScriptResources.completionTemplatingJson().getText(), Templating.class));

    // build trie
    buildTrie();

    // set context factory using JSNI
    setContextFactory(new JSNIContextFactory());
  }
コード例 #11
0
ファイル: JsonRpcResult.java プロジェクト: sleshchenko/che
 public <T> T getAs(Class<T> type) {
   if (type.equals(String.class)) {
     return (T) result.asString();
   } else if (type.equals(Double.class)) {
     return (T) (Double) result.asNumber();
   } else if (type.equals(Boolean.class)) {
     return (T) (Boolean) result.asBoolean();
   } else if (type.equals(Void.class)) {
     return (T) null;
   } else {
     return dtoFactory.createDtoFromJson(result.toJson(), type);
   }
 }
コード例 #12
0
  @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));
  }
コード例 #13
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();
  }
コード例 #14
0
ファイル: JsonRpcResult.java プロジェクト: sleshchenko/che
  public <T> List<T> getAsListOf(Class<T> type) {
    List<T> list = new ArrayList<>(resultList.size());

    for (int i = 0; i < resultList.size(); i++) {
      JsonValue jsonValue = resultList.get(i);
      T item;
      if (type.equals(String.class)) {
        item = (T) jsonValue.asString();
      } else if (type.equals(Double.class)) {
        item = (T) (Double) jsonValue.asNumber();
      } else if (type.equals(Boolean.class)) {
        item = (T) (Boolean) jsonValue.asBoolean();
      } else {
        item = dtoFactory.createDtoFromJson(jsonValue.toJson(), type);
      }
      list.add(i, item);
    }

    return list;
  }
コード例 #15
0
  @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;
  }
コード例 #16
0
  /** {@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();
    }
  }
コード例 #17
0
 private <T> T newDto(Class<T> clazz) {
   return dtoFactory.createDto(clazz);
 }