Search in sources :

Example 6 with Input

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.

the class InputResourcesStep method setContent.

public void setContent() {
    final int[] row = { 0 };
    model.getInputResources().stream().filter(input -> input.kind() == Input.Kind.RESOURCE).forEach(input -> {
        JLabel lblNameResource = new JLabel("<html><span style=\\\"font-family:serif;font-size:10px;font-weight:bold;\\\">" + input.name() + "</span></html");
        addComponent(lblNameResource, null, BORDER_LABEL_NAME, ROW_DIMENSION, 0, row[0], GridBagConstraints.NORTH);
        addTooltip(lblNameResource, input.description().orElse(""));
        row[0] += 1;
        JComboBox cmbValueResource = new JComboBox();
        cmbValueResource = (JComboBox) addComponent(cmbValueResource, TIMES_PLAIN_14, null, ROW_DIMENSION, 0, row[0], GridBagConstraints.NORTH);
        fillComboBox(cmbValueResource, input);
        addListener(input.name(), cmbValueResource);
        row[0] += 1;
    });
}
Also used : ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel) ROW_DIMENSION(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION) TIMES_PLAIN_14(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_14) JLabel(javax.swing.JLabel) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) GridBagConstraints(java.awt.GridBagConstraints) JComboBox(javax.swing.JComboBox) Resource(com.redhat.devtools.intellij.tektoncd.tkn.Resource) BORDER_LABEL_NAME(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel)

Example 7 with Input

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.

the class ParametersStep method setContent.

public void setContent() {
    textFields = new LinkedHashMap<>();
    final int[] row = { 0 };
    // if we are inside the AddTriggerWizard we suggest users which are the params they can use (extracted by the bindings chosen in the previous step)
    if (model instanceof AddTriggerModel) {
        Set<String> variablesToSuggest = ((AddTriggerModel) model).extractVariablesFromSelectedBindings();
        if (!variablesToSuggest.isEmpty()) {
            String suggestVariablesText = "<html><body style=\"font-family: " + Font.DIALOG + ";font-size:10px;\">The following variables can be used as Parameter values in the form $variable:<br><br>";
            int cont = 0;
            for (String variable : variablesToSuggest) {
                suggestVariablesText += "<span style=\"font-size:10px;font-weight:bold;\">" + variable + "</span>   ";
                if (++cont % 4 == 0)
                    suggestVariablesText += "<br>";
            }
            suggestVariablesText += "<br><br>The variables are taken from the bindings chosen in the previous step and they will be<br>" + "filled by the EventListener when evaluating TriggerBindings for an event.</html>";
            JTextPane lblVariableText = new JTextPane();
            lblVariableText.setContentType("text/html");
            lblVariableText.setText(suggestVariablesText);
            lblVariableText.setEditable(false);
            lblVariableText.setBackground(null);
            lblVariableText.setBorder(null);
            addComponent(lblVariableText, null, BORDER_LABEL_NAME, null, 0, row[0], GridBagConstraints.NORTHWEST);
            row[0] += 1;
        }
    }
    model.getParams().stream().filter(input -> input.kind() == Input.Kind.PARAMETER).forEach(input -> {
        String label = "<html><span style=\\\"font-family:serif;font-size:10px;font-weight:bold;\\\">" + input.name() + "</span>  <span style=\\\"font-family:serif;font-size:10;font-weight:normal;font-style:italic;\\\">(" + input.type() + ")</span></html>";
        String tooltip = input.description().isPresent() ? input.description().get() + "\n" : "";
        if (input.type().equals("string")) {
            tooltip += "The parameter " + input.name() + " expects a string value.";
        } else {
            tooltip += "The parameter " + input.name() + " expects an array value (e.g. val1,val2,val3 ...). Leave it empty for an empty array.";
        }
        JLabel lblNameParam = new JLabel(label);
        addComponent(lblNameParam, null, BORDER_LABEL_NAME, ROW_DIMENSION, 0, row[0], GridBagConstraints.NORTHWEST);
        addTooltip(lblNameParam, tooltip);
        row[0] += 1;
        JTextField txtValueParam = new JTextField(input.defaultValue().orElse(""));
        textFields.put(input.name(), txtValueParam);
        txtValueParam = (JTextField) addComponent(txtValueParam, TIMES_PLAIN_14, null, ROW_DIMENSION, 0, row[0], GridBagConstraints.NORTHWEST);
        addListener(input.name(), txtValueParam, txtValueParam.getBorder(), row[0]);
        row[0] += 1;
    });
}
Also used : Color(java.awt.Color) ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel) DocumentListener(javax.swing.event.DocumentListener) TIMES_PLAIN_14(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_14) JTextField(javax.swing.JTextField) Font(java.awt.Font) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ROW_DIMENSION_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION_ERROR) GridBagConstraints(java.awt.GridBagConstraints) Border(javax.swing.border.Border) LinkedHashMap(java.util.LinkedHashMap) RED_BORDER_SHOW_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.RED_BORDER_SHOW_ERROR) ROW_DIMENSION(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION) JLabel(javax.swing.JLabel) Map(java.util.Map) TIMES_PLAIN_10(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_10) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) JTextPane(javax.swing.JTextPane) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) DocumentEvent(javax.swing.event.DocumentEvent) MARGIN_TOP_35(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.MARGIN_TOP_35) BORDER_LABEL_NAME(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME) JTextPane(javax.swing.JTextPane) JLabel(javax.swing.JLabel) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) JTextField(javax.swing.JTextField)

Example 8 with Input

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.

the class TknCliTest method checkRightArgsWhenStartingClusterTaskWithParameters.

@Test
public void checkRightArgsWhenStartingClusterTaskWithParameters() throws IOException {
    Map<String, Input> params = new HashMap<>();
    params.put("param1", new Input("param1", "string", Input.Kind.PARAMETER, "value1", Optional.empty(), Optional.empty()));
    params.put("param2", new Input("param2", "string", Input.Kind.PARAMETER, "value2", Optional.empty(), Optional.empty()));
    MockedStatic<ExecHelper> exec = mockStatic(ExecHelper.class);
    exec.when(() -> ExecHelper.execute(anyString(), anyMap(), any())).thenReturn("");
    tkn.startClusterTask("ns", "name", params, Collections.emptyMap(), Collections.emptyMap(), "", Collections.emptyMap(), "");
    exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("clustertask"), eq("start"), eq("name"), eq("-n"), eq("ns"), eq("-p"), eq("param1=value1"), eq("-p"), eq("param2=value2"), eq(FLAG_SKIP_OPTIONAL_WORKSPACES)));
    exec.close();
}
Also used : ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with Input

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.

the class TknCliTest method checkRightArgsWhenStartingPipelineWithMultipleInputs.

@Test
public void checkRightArgsWhenStartingPipelineWithMultipleInputs() throws IOException {
    Map<String, Input> params = new HashMap<>();
    params.put("param1", new Input("param1", "string", Input.Kind.PARAMETER, "value1", Optional.empty(), Optional.empty()));
    Map<String, String> resources = new HashMap<>();
    resources.put("res1", "value1");
    resources.put("res2", "value2");
    Map<String, String> taskServiceAccount = new HashMap<>();
    taskServiceAccount.put("task1", "value1");
    Map<String, Workspace> workspaces = new HashMap<>();
    workspaces.put("work1", new Workspace("work1", Workspace.Kind.PVC, "value1"));
    workspaces.put("work2", new Workspace("work2", Workspace.Kind.SECRET, "value2"));
    MockedStatic<ExecHelper> exec = mockStatic(ExecHelper.class);
    exec.when(() -> ExecHelper.execute(anyString(), anyMap(), any())).thenReturn("");
    tkn.startPipeline("ns", "name", params, resources, "sa", taskServiceAccount, workspaces, "prefix");
    exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("pipeline"), eq("start"), eq("name"), eq("-n"), eq("ns"), eq("-s=sa"), eq("--task-serviceaccount"), eq("task1=value1"), eq("-w"), eq("name=work2,secret=value2"), eq("-w"), eq("name=work1,claimName=value1"), eq("-p"), eq("param1=value1"), eq("-r"), eq("res1=value1"), eq("-r"), eq("res2=value2"), eq("--prefix-name=prefix"), eq(FLAG_SKIP_OPTIONAL_WORKSPACES)));
    exec.close();
}
Also used : ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) Test(org.junit.Test)

Example 10 with Input

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input in project intellij-tekton by redhat-developer.

the class TknCliTest method checkRightArgsWhenStartingTaskWithMultipleInputs.

@Test
public void checkRightArgsWhenStartingTaskWithMultipleInputs() throws IOException {
    Map<String, Input> params = new HashMap<>();
    params.put("param1", new Input("param1", "string", Input.Kind.PARAMETER, "value1", Optional.empty(), Optional.empty()));
    Map<String, String> inputResources = new HashMap<>();
    inputResources.put("res1", "value1");
    inputResources.put("res2", "value2");
    Map<String, String> outputResources = new HashMap<>();
    outputResources.put("out1", "value1");
    Map<String, Workspace> workspaces = new HashMap<>();
    workspaces.put("work1", new Workspace("work1", Workspace.Kind.PVC, "value1"));
    workspaces.put("work2", new Workspace("work2", Workspace.Kind.SECRET, "value2"));
    MockedStatic<ExecHelper> exec = mockStatic(ExecHelper.class);
    exec.when(() -> ExecHelper.execute(anyString(), anyMap(), any())).thenReturn("");
    tkn.startTask("ns", "name", params, inputResources, outputResources, "sa", workspaces, "prefix");
    exec.verify(() -> ExecHelper.execute(anyString(), anyMap(), eq("task"), eq("start"), eq("name"), eq("-n"), eq("ns"), eq("-s=sa"), eq("-w"), eq("name=work2,secret=value2"), eq("-w"), eq("name=work1,claimName=value1"), eq("-p"), eq("param1=value1"), eq("-i"), eq("res1=value1"), eq("-i"), eq("res2=value2"), eq("-o"), eq("out1=value1"), eq("--prefix-name=prefix"), eq(FLAG_SKIP_OPTIONAL_WORKSPACES)));
    exec.close();
}
Also used : ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) Test(org.junit.Test)

Aggregations

Input (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input)13 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 Workspace (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)3 List (java.util.List)3 Map (java.util.Map)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 TestUtils (com.redhat.devtools.intellij.tektoncd.TestUtils)2 Resource (com.redhat.devtools.intellij.tektoncd.tkn.Resource)2 BORDER_LABEL_NAME (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME)2 ROW_DIMENSION (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION)2 TIMES_PLAIN_14 (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_14)2 ActionToRunModel (com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel)2 Watch (io.fabric8.kubernetes.client.Watch)2 Watcher (io.fabric8.kubernetes.client.Watcher)2 WatcherException (io.fabric8.kubernetes.client.WatcherException)2 TektonClient (io.fabric8.tekton.client.TektonClient)2