Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 8af4642

Browse files
committed
simplified usage/async download of odo (#536)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent 7719988 commit 8af4642

File tree

13 files changed

+221
-135
lines changed

13 files changed

+221
-135
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ dependencies {
113113
'org.apache.commons:commons-compress:1.21',
114114
'org.apache.commons:commons-exec:1.3',
115115
'org.apache.commons:commons-lang3:3.9',
116-
'com.redhat.devtools.intellij:intellij-common:1.9.1',
116+
'com.redhat.devtools.intellij:intellij-common:1.9.3-SNAPSHOT',
117117
'io.jsonwebtoken:jjwt-impl:0.11.2',
118118
'io.jsonwebtoken:jjwt-jackson:0.11.2',
119119
'org.keycloak:keycloak-installed-adapter:20.0.5',

src/main/java/org/jboss/tools/intellij/openshift/actions/OdoAction.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@
2020
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
2121
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsTreeStructure;
2222
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
2325

2426
import javax.swing.tree.TreePath;
2527

2628
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.PREFIX_ACTION;
2729

2830
public abstract class OdoAction extends StructureTreeAction implements TelemetryHandler {
2931

30-
protected TelemetrySender telemetrySender;
32+
private static final Logger LOGGER = LoggerFactory.getLogger(OdoAction.class);
33+
34+
protected TelemetrySender telemetrySender;
3135

3236
protected OdoAction(Class... filters) {
3337
super(filters);
@@ -36,12 +40,32 @@ protected OdoAction(Class... filters) {
3640
@Override
3741
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected) {
3842
telemetrySender = new TelemetrySender(PREFIX_ACTION + getTelemetryActionName());
39-
this.actionPerformed(anActionEvent, (Object) getElement(selected), getOdo(anActionEvent));
43+
Odo odo = getOdo(anActionEvent);
44+
if (odo == null) {
45+
return;
46+
}
47+
this.actionPerformed(anActionEvent, (Object) getElement(selected), odo);
4048
}
4149

4250
private Odo getOdo(AnActionEvent anActionEvent) {
43-
Tree tree = getTree(anActionEvent);
44-
return ((ApplicationsRootNode) ((ApplicationsTreeStructure) tree.getClientProperty(Constants.STRUCTURE_PROPERTY)).getApplicationsRoot()).getOdo();
51+
try {
52+
Tree tree = getTree(anActionEvent);
53+
if (tree == null) {
54+
return null;
55+
}
56+
ApplicationsTreeStructure structure = (ApplicationsTreeStructure) tree.getClientProperty(Constants.STRUCTURE_PROPERTY);
57+
if (structure == null) {
58+
return null;
59+
}
60+
ApplicationsRootNode root = (ApplicationsRootNode) structure.getApplicationsRoot();
61+
if (root == null) {
62+
return null;
63+
}
64+
return root.getOdo().getNow(null);
65+
} catch(Exception e) {
66+
LOGGER.warn("Could not get odo: " + e.getMessage(), e);
67+
return null;
68+
}
4569
}
4670

4771
public abstract void actionPerformed(AnActionEvent anActionEvent, Object selected, Odo odo);

src/main/java/org/jboss/tools/intellij/openshift/actions/binding/DeleteBindingAction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public DeleteBindingAction() {
2626

2727
@Override
2828
public void actionPerformed(AnActionEvent anActionEvent, Object selected, Odo odo) {
29+
if (odo == null) {
30+
return;
31+
}
2932
try {
3033
BindingNode node = (BindingNode) selected;
3134
if (Messages.NO == Messages.showYesNoDialog("Delete binding '" + node.getName() + "'.\nAre you sure?",

src/main/java/org/jboss/tools/intellij/openshift/actions/cluster/LoginAction.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,23 @@ public LoginAction() {
3434

3535
@Override
3636
public void actionPerformed(AnActionEvent anActionEvent, Object selected, Odo odo) {
37-
ApplicationsRootNode clusterNode = (ApplicationsRootNode) selected;
3837
CompletableFuture.runAsync(() -> {
39-
try {
40-
LoginDialog loginDialog = UIHelper.executeInUI(() -> {
41-
LoginDialog dialog = new LoginDialog(anActionEvent.getProject(), null, clusterNode.getOdo().getMasterUrl().toString());
42-
dialog.show();
43-
return dialog;
44-
});
45-
if (loginDialog.isOK()) {
46-
odo.login(loginDialog.getClusterURL(), loginDialog.getUserName(), loginDialog.getPassword(), loginDialog.getToken());
47-
sendTelemetryResults(TelemetryResult.SUCCESS);
48-
} else {
49-
sendTelemetryResults(TelemetryResult.ABORTED);
50-
}
51-
} catch (IOException e) {
52-
sendTelemetryError(e);
53-
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Login"));
38+
try {
39+
LoginDialog loginDialog = UIHelper.executeInUI(() -> {
40+
LoginDialog dialog = new LoginDialog(anActionEvent.getProject(), null, odo.getMasterUrl().toString());
41+
dialog.show();
42+
return dialog;
43+
});
44+
if (loginDialog.isOK()) {
45+
odo.login(loginDialog.getClusterURL(), loginDialog.getUserName(), loginDialog.getPassword(), loginDialog.getToken());
46+
sendTelemetryResults(TelemetryResult.SUCCESS);
47+
} else {
48+
sendTelemetryResults(TelemetryResult.ABORTED);
5449
}
55-
});
50+
} catch (IOException e) {
51+
sendTelemetryError(e);
52+
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Login"));
53+
}
54+
});
5655
}
5756
}

src/main/java/org/jboss/tools/intellij/openshift/actions/component/CreateComponentAction.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public static void execute(ParentableNode<?> parentNode) {
5050
CreateComponentAction action = (CreateComponentAction) ActionManager.getInstance().getAction(CreateComponentAction.class.getName());
5151
NamespaceNode namespaceNode = (NamespaceNode) parentNode;
5252
action.telemetrySender = new TelemetrySender(PREFIX_ACTION + action.getTelemetryActionName());
53-
action.doActionPerformed(namespaceNode, namespaceNode.getRoot().getOdo(), namespaceNode.getName(),
53+
Odo odo = namespaceNode.getRoot().getOdo().getNow(null);
54+
if (odo == null) {
55+
return;
56+
}
57+
action.doActionPerformed(namespaceNode, odo, namespaceNode.getName(),
5458
namespaceNode.getRoot(), namespaceNode.getRoot().getProject());
5559
}
5660

src/main/java/org/jboss/tools/intellij/openshift/actions/component/FeatureComponentAction.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.jboss.tools.intellij.openshift.utils.odo.Component;
2121
import org.jboss.tools.intellij.openshift.utils.odo.ComponentFeature;
2222
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
2325

2426
import java.io.IOException;
2527
import java.util.Objects;
@@ -30,6 +32,8 @@
3032

3133
public abstract class FeatureComponentAction extends ContextAwareComponentAction {
3234

35+
private static final Logger LOGGER = LoggerFactory.getLogger(FeatureComponentAction.class);
36+
3337
protected final ComponentFeature feature;
3438

3539
public FeatureComponentAction(ComponentFeature feature) {
@@ -55,11 +59,18 @@ public void update(AnActionEvent e) {
5559
ComponentNode componentNode = ((ComponentNode) adjust(getSelected(getTree(e))));
5660
Component component = componentNode.getComponent();
5761
ComponentFeature feat = getComponentFeature(component);
58-
if (componentNode.getRoot().getOdo().isStarted(componentNode.getNamespace(), component.getPath(),
59-
component.getName(), feat)) {
60-
e.getPresentation().setText("Stop " + getActionName());
61-
} else {
62-
e.getPresentation().setText("Start " + getActionName());
62+
try {
63+
Odo odo = componentNode.getRoot().getOdo().getNow(null);
64+
if (odo == null) {
65+
return;
66+
}
67+
if (odo.isStarted(componentNode.getNamespace(), component.getPath(), component.getName(), feat)) {
68+
e.getPresentation().setText("Stop " + getActionName());
69+
} else {
70+
e.getPresentation().setText("Start " + getActionName());
71+
}
72+
} catch (Exception ex) {
73+
LOGGER.warn("Could not update {}", componentNode.getName(), e);
6374
}
6475
}
6576
}

src/main/java/org/jboss/tools/intellij/openshift/actions/component/ShowLogComponentAction.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,19 @@ private boolean isDebug(Component component) {
123123
}
124124

125125
private boolean isLogRunningForDevOrDebug(ComponentNode componentNode) throws IOException {
126-
return componentNode.getRoot().getOdo().isLogRunning(componentNode.getComponent().getPath(), componentNode.getComponent().getName(), false);
126+
Odo odo = componentNode.getRoot().getOdo().getNow(null);
127+
if (odo == null) {
128+
return false;
129+
}
130+
return odo.isLogRunning(componentNode.getComponent().getPath(), componentNode.getComponent().getName(), false);
127131
}
128132

129133
private boolean isLogRunningForDeploy(ComponentNode componentNode) throws IOException {
130-
return componentNode.getRoot().getOdo().isLogRunning(componentNode.getComponent().getPath(), componentNode.getComponent().getName(), true);
134+
Odo odo = componentNode.getRoot().getOdo().getNow(null);
135+
if (odo == null) {
136+
return false;
137+
}
138+
return odo.isLogRunning(componentNode.getComponent().getPath(), componentNode.getComponent().getName(), true);
131139
}
132140

133141
private boolean isDevOrDebugAndLogNotRunning(ComponentNode componentNode) throws IOException {

src/main/java/org/jboss/tools/intellij/openshift/actions/project/CreateProjectAction.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.IOException;
2626
import java.util.concurrent.CompletableFuture;
27+
import java.util.concurrent.CompletionException;
2728

2829
import static org.jboss.tools.intellij.openshift.Constants.GROUP_DISPLAY_ID;
2930
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.PREFIX_ACTION;
@@ -50,14 +51,18 @@ private void doActioPerformed(ApplicationsRootNode clusterNode) {
5051
if ((projectName != null) && projectName.trim().length() > 0) {
5152
CompletableFuture.runAsync(() -> {
5253
try {
54+
Odo odo = clusterNode.getOdo().getNow(null);
55+
if (odo == null) {
56+
return;
57+
}
5358
Notification notif = new Notification(GROUP_DISPLAY_ID, "Create project", "Creating project " + projectName, NotificationType.INFORMATION);
5459
Notifications.Bus.notify(notif);
55-
clusterNode.getOdo().createProject(projectName);
60+
odo.createProject(projectName);
5661
notif.expire();
5762
Notifications.Bus.notify(new Notification(GROUP_DISPLAY_ID, "Create project", "Project " + projectName + " successfully created", NotificationType.INFORMATION));
5863
clusterNode.getStructure().fireModified(clusterNode);
5964
sendTelemetryResults(TelemetryResult.SUCCESS);
60-
} catch (IOException e) {
65+
} catch (IOException | CompletionException e) {
6166
sendTelemetryError(e);
6267
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Create project"));
6368
}

src/main/java/org/jboss/tools/intellij/openshift/utils/odo/OdoProjectDecorator.java renamed to src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationRootNodeOdo.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,45 @@
88
* Contributors:
99
* Red Hat, Inc. - initial API and implementation
1010
******************************************************************************/
11-
package org.jboss.tools.intellij.openshift.utils.odo;
11+
package org.jboss.tools.intellij.openshift.tree.application;
1212

1313
import com.fasterxml.jackson.databind.node.ObjectNode;
14-
import com.intellij.openapi.util.SystemInfo;
14+
import com.intellij.openapi.util.io.FileUtil;
1515
import com.intellij.openapi.vfs.VfsUtil;
1616
import com.intellij.openapi.vfs.VirtualFile;
1717
import org.apache.commons.io.FileUtils;
1818
import org.apache.commons.lang.StringUtils;
19-
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
19+
import org.jboss.tools.intellij.openshift.utils.odo.Binding;
20+
import org.jboss.tools.intellij.openshift.utils.odo.Component;
21+
import org.jboss.tools.intellij.openshift.utils.odo.ComponentDescriptor;
22+
import org.jboss.tools.intellij.openshift.utils.odo.ComponentFeature;
23+
import org.jboss.tools.intellij.openshift.utils.odo.ComponentFeatures;
24+
import org.jboss.tools.intellij.openshift.utils.odo.ComponentInfo;
25+
import org.jboss.tools.intellij.openshift.utils.odo.ComponentKind;
26+
import org.jboss.tools.intellij.openshift.utils.odo.ComponentMetadata;
27+
import org.jboss.tools.intellij.openshift.utils.odo.ComponentTypeInfo;
28+
import org.jboss.tools.intellij.openshift.utils.odo.DevfileComponentType;
29+
import org.jboss.tools.intellij.openshift.utils.odo.DevfileRegistry;
30+
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
31+
import org.jboss.tools.intellij.openshift.utils.odo.OperatorCRD;
32+
import org.jboss.tools.intellij.openshift.utils.odo.Service;
33+
import org.jboss.tools.intellij.openshift.utils.odo.ServiceTemplate;
34+
import org.jboss.tools.intellij.openshift.utils.odo.URL;
2035

2136
import java.io.File;
2237
import java.io.IOException;
23-
import java.nio.file.Files;
24-
import java.nio.file.attribute.FileAttribute;
25-
import java.nio.file.attribute.PosixFilePermission;
26-
import java.nio.file.attribute.PosixFilePermissions;
2738
import java.util.List;
2839
import java.util.Map;
2940
import java.util.Optional;
30-
import java.util.Set;
3141
import java.util.function.Consumer;
3242

3343
import static org.jboss.tools.intellij.openshift.Constants.DebugStatus;
3444

35-
public class OdoProjectDecorator implements Odo {
45+
public class ApplicationRootNodeOdo implements Odo {
3646
private final Odo delegate;
3747
private final ApplicationsRootNode root;
3848

39-
public OdoProjectDecorator(Odo delegate, ApplicationsRootNode root) {
49+
ApplicationRootNodeOdo(Odo delegate, ApplicationsRootNode root) {
4050
this.delegate = delegate;
4151
this.root = root;
4252
}
@@ -80,14 +90,7 @@ public List<ComponentMetadata> analyze(String path) throws IOException {
8090
@Override
8191
public void createComponent(String project, String componentType, String registryName, String component, String source, String devfile, String starter) throws IOException {
8292
if (StringUtils.isNotBlank(starter)) {
83-
File tmpdir;
84-
if (SystemInfo.isWindows) {
85-
tmpdir = Files.createTempDirectory("odotmp").toFile();
86-
} else {
87-
FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(
88-
PosixFilePermissions.fromString("rwxr-x---"));
89-
tmpdir = Files.createTempDirectory("odotmp", attr).toFile();
90-
}
93+
File tmpdir = FileUtil.createTempDirectory("odotmp", null);
9194
delegate.createComponent(project, componentType, registryName, component, tmpdir.getAbsolutePath(), devfile, starter);
9295
File sourceDir = new File(source);
9396
FileUtils.copyDirectory(tmpdir, sourceDir);
@@ -186,13 +189,18 @@ public List<Component> getComponents(String project) throws IOException {
186189
for (Map.Entry<String, ComponentDescriptor> entry : root.getComponents().entrySet()) {
187190
String path = entry.getKey();
188191
ComponentDescriptor componentDescriptor = entry.getValue();
189-
Optional<Component> found = components.stream().filter(comp1 -> comp1.getName().equals(componentDescriptor.getName())).findFirst();
192+
Optional<Component> found = components.stream()
193+
.filter(comp1 -> comp1.getName().equals(componentDescriptor.getName())).findFirst();
190194
if (found.isPresent()) {
191195
found.get().setPath(path);
192196
found.get().setInfo(getComponentInfo(project, componentDescriptor.getName(), path, ComponentKind.DEVFILE));
193197
} else {
194-
components.add(Component.of(componentDescriptor.getName(), new ComponentFeatures(), path,
195-
getComponentInfo(project, componentDescriptor.getName(), path, ComponentKind.DEVFILE)));
198+
components.add(Component.of(
199+
componentDescriptor.getName(),
200+
new ComponentFeatures(),
201+
path,
202+
getComponentInfo(project, componentDescriptor.getName(), path, ComponentKind.DEVFILE))
203+
);
196204
}
197205
}
198206
return components;

0 commit comments

Comments
 (0)