Skip to content

Commit

Permalink
fix: correct incompatibilities to IC-2024.1 (#207)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Mar 14, 2024
1 parent 9c0aae5 commit 8d85168
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
package com.redhat.devtools.intellij.common.utils;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.io.HttpRequests;
import com.redhat.devtools.intellij.common.CommonConstants;
import com.twelvemonkeys.lang.Platform;
Expand All @@ -28,7 +27,6 @@
import org.apache.commons.compress.compressors.CompressorStreamFactory;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;

import java.io.BufferedInputStream;
Expand All @@ -45,10 +43,8 @@
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DownloadHelper {
Expand All @@ -60,9 +56,9 @@ public class DownloadHelper {
}
});

private static final UnaryOperator<InputStream> UNTAR = (input -> new TarArchiveInputStream(input));
private static final UnaryOperator<InputStream> UNTAR = (TarArchiveInputStream::new);

private static final UnaryOperator<InputStream> UNZIP = (input -> new ZipArchiveInputStream(input));
private static final UnaryOperator<InputStream> UNZIP = (ZipArchiveInputStream::new);

private static final Map<String, UnaryOperator<InputStream>> MAPPERS = new HashMap<>();

Expand Down Expand Up @@ -223,15 +219,15 @@ public CompletableFuture<String> downloadIfRequiredAsync(String toolName, URL ur

private boolean isDownloadAllowed(String tool, String currentVersion, String requiredVersion) {
return UIHelper.executeInUI(() ->
Messages.showYesNoCancelDialog(StringUtils.isEmpty(currentVersion) ? tool + " not found , do you want to download " + tool + " " + requiredVersion + " ?" : tool + " " + currentVersion + " found, required version is " + requiredVersion + ", do you want to download " + tool + " ?", tool + " tool required", Messages.getQuestionIcon()) == Messages.YES);
Messages.showYesNoCancelDialog(StringUtil.isEmpty(currentVersion) ? tool + " not found , do you want to download " + tool + " " + requiredVersion + " ?" : tool + " " + currentVersion + " found, required version is " + requiredVersion + ", do you want to download " + tool + " ?", tool + " tool required", Messages.getQuestionIcon()) == Messages.YES);
}

private boolean areCompatible(String version, String versionMatchRegExpr) {
boolean compatible = true;
if (StringUtils.isNotBlank(versionMatchRegExpr)) {
if (!StringUtil.isEmptyOrSpaces(versionMatchRegExpr)) {
Pattern pattern = Pattern.compile(versionMatchRegExpr);
compatible = pattern.matcher(version).matches();
} else if (StringUtils.isBlank(version)) {
} else if (StringUtil.isEmptyOrSpaces(version)) {
compatible = false;
}
return compatible;
Expand All @@ -245,12 +241,13 @@ private String getVersionFromPath(ToolsConfig.Tool tool, ToolsConfig.Platform pl
String output = ExecHelper.execute(platform.getCmdFileName(), false, arguments);
try (BufferedReader reader = new BufferedReader(new StringReader(output))) {
version = reader.lines().
map(line -> pattern.matcher(line)).
filter(matcher -> matcher.matches()).
map(pattern::matcher).
filter(Matcher::matches).
map(matcher -> matcher.group(1)).
findFirst().orElse("");
}
} catch (IOException e) {
// swallow
}
return version;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@
******************************************************************************/
package com.redhat.devtools.intellij.common.utils;

import com.intellij.ide.ui.LafManager;
import com.intellij.ide.ui.laf.darcula.DarculaLaf;
import com.intellij.openapi.application.ApplicationManager;

import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import java.util.Arrays;
import java.util.Collection;
import java.util.function.Supplier;

public class UIHelper {

private static final Collection<String> DARK_THEMES = Arrays.asList(
"Darcula",
"Dark",
"High contrast");

public static void executeInUI(Runnable runnable) {
if (ApplicationManager.getApplication().isDispatchThread()) {
runnable.run();
Expand All @@ -37,7 +44,10 @@ public static <T> T executeInUI(Supplier<T> supplier) {
}

public static boolean isDarkMode() {
UIManager.LookAndFeelInfo lafInfo = LafManager.getInstance().getCurrentLookAndFeel();
return lafInfo != null && lafInfo.getClassName().equals(DarculaLaf.class.getName());
LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
if (lookAndFeel == null) {
return false;
}
return DARK_THEMES.contains(lookAndFeel.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
package com.redhat.devtools.intellij.common.validation;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider;
import com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -25,10 +30,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SchemasProviderFactory implements JsonSchemaProviderFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(SchemasProviderFactory.class);
Expand All @@ -43,9 +44,9 @@ private void load() {
try (InputStream list = SchemasProviderFactory.class.getResourceAsStream("/schemas/index.properties")) {
if (list != null) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(list, StandardCharsets.UTF_8))) {
reader.lines().filter(line -> StringUtils.isNotBlank(line)).forEach(line -> {
loadSchema(line);
});
reader.lines()
.filter(line -> !StringUtil.isEmptyOrSpaces(line))
.forEach(this::loadSchema);
}
}
} catch (IOException e) {
Expand Down

0 comments on commit 8d85168

Please sign in to comment.