Skip to content

Commit

Permalink
feat: add/remove/edit helm repo (redhat-developer#673)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Apr 22, 2024
1 parent 8c4b059 commit 0f82cdb
Show file tree
Hide file tree
Showing 20 changed files with 563 additions and 111 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ dependencies {
'io.fabric8:openshift-client:6.12.0',
'org.apache.commons:commons-compress:1.26.1',
'org.apache.commons:commons-exec:1.4.0',
'com.redhat.devtools.intellij:intellij-common:1.9.5',
'com.redhat.devtools.intellij:intellij-common:1.9.6-SNAPSHOT',
'io.jsonwebtoken:jjwt-impl:0.12.5',
'io.jsonwebtoken:jjwt-jackson:0.12.5',
'org.keycloak:keycloak-installed-adapter:24.0.2',
Expand All @@ -150,7 +150,7 @@ dependencies {
'org.junit.platform:junit-platform-launcher:1.10.2',
'org.mockito:mockito-core:5.11.0',
'org.easytesting:fest-assert:1.4',
'com.redhat.devtools.intellij:intellij-common:1.9.5:test',
'com.redhat.devtools.intellij:intellij-common:1.9.6-SNAPSHOT:test',
'org.awaitility:awaitility:4.2.1',
'org.mock-server:mockserver-client-java:5.15.0',
'org.mock-server:mockserver-netty:5.15.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
******************************************************************************/
package org.jboss.tools.intellij.openshift.test.ui.annotations;

import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.Tag;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

import org.junit.jupiter.api.Tag;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author Ondrej Dockal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import com.intellij.remoterobot.fixtures.FixtureName;
import com.intellij.remoterobot.fixtures.JTextFieldFixture;
import org.jetbrains.annotations.NotNull;

import java.time.Duration;

import static com.intellij.remoterobot.search.locators.Locators.byXpath;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import com.intellij.remoterobot.fixtures.FixtureName;
import com.intellij.remoterobot.fixtures.JTreeFixture;
import org.jetbrains.annotations.NotNull;

import java.time.Duration;

import static com.intellij.remoterobot.search.locators.Locators.byXpath;
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import com.intellij.remoterobot.data.RemoteComponent;
import com.intellij.remoterobot.fixtures.ComponentFixture;
import com.intellij.remoterobot.fixtures.ContainerFixture;
import org.jetbrains.annotations.NotNull;
import com.intellij.remoterobot.fixtures.DefaultXpath;
import com.intellij.remoterobot.fixtures.FixtureName;
import org.jetbrains.annotations.NotNull;

import java.time.Duration;

import static com.intellij.remoterobot.search.locators.Locators.byXpath;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
import com.intellij.remoterobot.fixtures.*;
import com.intellij.remoterobot.fixtures.ComponentFixture;
import com.intellij.remoterobot.fixtures.ContainerFixture;
import com.intellij.remoterobot.fixtures.DefaultXpath;
import com.intellij.remoterobot.fixtures.FixtureName;
import com.intellij.remoterobot.fixtures.JTreeFixture;
import com.intellij.remoterobot.search.locators.Locator;
import com.intellij.remoterobot.utils.Keyboard;
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Chart get(String name, Helm helm) throws Exception {
}

public static void addRepository(Pair<String, String> pair, Helm helm) throws IOException {
helm.addRepo(pair.first, pair.second);
helm.addRepo(pair.first, pair.second, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void testListRepos_should_list_repo_that_was_added() throws IOException {
// given openshift repo was added to helm repos
String name = "openshift";
String url = "https://charts.openshift.io/";
helm.addRepo(name, url);
helm.addRepo(name, url, null);
// when
List<HelmRepository> repositories = helm.listRepos();
// then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.intellij.openshift.actions.helm;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.redhat.devtools.intellij.common.utils.ApplicationUtils;
import com.redhat.devtools.intellij.common.utils.SwingUtils;
import java.awt.Point;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import org.jboss.tools.intellij.openshift.actions.HelmAction;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.tree.application.HelmRepositoriesNode;
import org.jboss.tools.intellij.openshift.ui.helm.AddHelmRepoDialog;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jboss.tools.intellij.openshift.utils.helm.HelmRepository;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class AddHelmRepoAction extends HelmAction {

private static final Logger LOGGER = LoggerFactory.getLogger(AddHelmRepoAction.class);

@Override
public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Helm helm) {
Project project = getEventProject(anActionEvent);
if (!(selected instanceof HelmRepositoriesNode repositoriesNode)) {
return;
}
openAddHelmRepoDialog(repositoriesNode, helm, project, SwingUtils.getMouseLocation(anActionEvent));
}

private void openAddHelmRepoDialog(HelmRepositoriesNode repositoriesNode, Helm helm, Project project, Point location) {
CompletableFuture.supplyAsync(
() -> listRepositories(helm),
ApplicationUtils.PLATFORM_EXECUTOR
).thenAcceptAsync(
repositories -> {
AddHelmRepoDialog dialog = new AddHelmRepoDialog(repositories, repositoriesNode, helm, project, location);
sendTelemetryResults(TelemetryService.TelemetryResult.SUCCESS);
dialog.show();
},
ApplicationUtils.UI_EXECUTOR
);
}

private Collection<HelmRepository> listRepositories(Helm helm) {
try {
return helm.listRepos();
} catch (IOException e) {
LOGGER.warn("Could not list helm repositories", e);
return Collections.emptyList();
}
}

@Override
public String getTelemetryActionName() {
return "helm-add repo";
}

@Override
public boolean isVisible(Object selected) {
return selected instanceof HelmRepositoriesNode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jboss.tools.intellij.openshift.actions.HelmAction;
import org.jboss.tools.intellij.openshift.actions.NodeUtils;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
import org.jboss.tools.intellij.openshift.tree.application.NamespaceNode;
import org.jboss.tools.intellij.openshift.tree.application.ParentableNode;
import org.jboss.tools.intellij.openshift.ui.helm.ChartsDialog;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
Expand All @@ -27,11 +27,10 @@ public class OpenHelmChartsAction extends HelmAction {
@Override
public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Helm helm) {
Project project = getEventProject(anActionEvent);
ParentableNode<?> parentableNode = ((ParentableNode<?>) selected);
if (parentableNode == null) {
ApplicationsRootNode rootNode = NodeUtils.getRoot(selected);
if (rootNode == null) {
return;
}
ApplicationsRootNode rootNode = parentableNode.getRoot();
Odo odo = rootNode.getOdo().getNow(null);
if (odo == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.intellij.openshift.actions.helm;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.redhat.devtools.intellij.common.actions.StructureTreeAction;
import com.redhat.devtools.intellij.common.utils.UIHelper;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.swing.tree.TreePath;
import org.jboss.tools.intellij.openshift.actions.HelmAction;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
import org.jboss.tools.intellij.openshift.tree.application.HelmRepositoryNode;
import org.jboss.tools.intellij.openshift.tree.application.ProcessingNode;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jetbrains.annotations.Nullable;

import static org.jboss.tools.intellij.openshift.actions.ActionUtils.runWithProgress;
import static org.jboss.tools.intellij.openshift.actions.NodeUtils.clearProcessing;
import static org.jboss.tools.intellij.openshift.actions.NodeUtils.setProcessing;

public class RemoveRepositoriesAction extends HelmAction {

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath[] path, Object[] selected) {
Helm helm = getHelm(anActionEvent);
if (helm == null) {
return;
}
Project project = getEventProject(anActionEvent);
List<HelmRepositoryNode> repositories = toHelmRepositoryNodes(selected);
if (repositories == null
|| repositories.isEmpty()) {
return;
}

if (cancelRemoval(repositories)) {
sendTelemetryResults(TelemetryService.TelemetryResult.ABORTED);
return;
}

runWithProgress((ProgressIndicator progress) -> {
removeRepositories(repositories, helm);
},
"Remove Helm Repositories...",
project);
}

private void removeRepositories(List<HelmRepositoryNode> repositories, Helm helm) {
ProcessingNode[] processingNodes = repositories.toArray(new ProcessingNode[0]);
ApplicationsRootNode rootNode = repositories.get(0).getRoot();
try {
setProcessing("removing...", rootNode, processingNodes);
helm.removeRepos(
repositories.stream()
.map(HelmRepositoryNode::getName)
.toArray(String[]::new));
clearProcessing(rootNode, processingNodes);
sendTelemetryResults(TelemetryService.TelemetryResult.SUCCESS);
} catch (Exception e) {
clearProcessing(rootNode, processingNodes);
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Remove Helm Repositories"));
sendTelemetryResults(TelemetryService.TelemetryResult.ERROR);
}
}

@Nullable
private static List<HelmRepositoryNode> toHelmRepositoryNodes(Object[] selected) {
if (selected == null
|| selected.length == 0) {
return null;
}

return Arrays.stream(selected)
.map(StructureTreeAction::getElement)
.filter(HelmRepositoryNode.class::isInstance)
.map(HelmRepositoryNode.class::cast)
.collect(Collectors.toList());
}

private boolean cancelRemoval(List<HelmRepositoryNode> releases) {
String repositoriesNames = releases.stream()
.map(HelmRepositoryNode::getName)
.collect(Collectors.joining(", "));
return Messages.NO == Messages.showYesNoDialog(
"Remove Repositories "
+ repositoriesNames
+ ".\n\nAre you sure?",
"Remove Repositories",
Messages.getQuestionIcon());
}

@Override
public String getTelemetryActionName() {
return "helm-remove repositories";
}

@Override
public boolean isVisible(Object[] selected) {
return Arrays.stream(selected).anyMatch(item -> {
Object node = getElement(item);
if (!(node instanceof HelmRepositoryNode)) {
return false;
}
return !((HelmRepositoryNode) node).isProcessing();
});
}
}
41 changes: 10 additions & 31 deletions src/main/java/org/jboss/tools/intellij/openshift/ui/SwingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,15 @@
******************************************************************************/
package org.jboss.tools.intellij.openshift.ui;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.wm.impl.IdeGlassPaneEx;
import com.intellij.ui.JBColor;
import com.intellij.ui.SizedIcon;
import com.intellij.ui.WindowMoveListener;
import com.intellij.ui.WindowResizeListener;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.scale.JBUIScale;
import com.intellij.ui.table.JBTable;
import com.intellij.util.containers.JBIterable;
import com.intellij.util.ui.JBFont;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;

import javax.swing.AbstractButton;
import javax.swing.DefaultCellEditor;
import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.text.JTextComponent;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
Expand All @@ -47,6 +29,16 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import javax.swing.AbstractButton;
import javax.swing.DefaultCellEditor;
import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.text.JTextComponent;
import org.jetbrains.annotations.NotNull;

public class SwingUtils {

Expand Down Expand Up @@ -136,19 +128,6 @@ private static JBIterable<Component> focusableComponents(@NotNull Component comp
.filter(c -> c instanceof JComboBox || c instanceof AbstractButton || c instanceof JTextComponent);
}

public static void setGlassPaneResizable(JRootPane rootPane, Disposable disposable) {
WindowResizeListener resizeListener = new WindowResizeListener(rootPane, JBUI.insets(10), null);
IdeGlassPaneEx glassPane = (IdeGlassPaneEx) rootPane.getGlassPane();
glassPane.addMousePreprocessor(resizeListener, disposable);
glassPane.addMouseMotionPreprocessor(resizeListener, disposable);
}

public static void setMovable(JRootPane rootPane, JComponent... movableComponents) {
WindowMoveListener windowMoveListener = new WindowMoveListener(rootPane);
Stream.of(movableComponents).forEach(
component -> component.addMouseListener(windowMoveListener));
}

public static Point locationOrMouseLocation(Point location) {
if (location == null) {
location = MouseInfo.getPointerInfo().getLocation();
Expand Down
Loading

0 comments on commit 0f82cdb

Please sign in to comment.