From e7fcbdd489c46e3a32f6eae707617ab178e9ac82 Mon Sep 17 00:00:00 2001 From: Staicy Mathew <40750411+staicy123@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:28:58 +0530 Subject: [PATCH] Updated constant name from LIBERTY_BUILD_FILE to LIBERTY_BUILD_FILE_DATAKEY and added comments --- .../java/io/openliberty/tools/intellij/LibertyExplorer.java | 2 +- .../tools/intellij/actions/LibertyGeneralAction.java | 5 ++++- .../intellij/runConfiguration/LibertyRunConfiguration.java | 2 +- .../java/io/openliberty/tools/intellij/util/Constants.java | 3 ++- .../io/openliberty/tools/intellij/util/TreeDataProvider.java | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/LibertyExplorer.java b/src/main/java/io/openliberty/tools/intellij/LibertyExplorer.java index 1a4f1355e..fbec073db 100644 --- a/src/main/java/io/openliberty/tools/intellij/LibertyExplorer.java +++ b/src/main/java/io/openliberty/tools/intellij/LibertyExplorer.java @@ -279,7 +279,7 @@ public void invokePopup(Component comp, int x, int y) { menu.setDataContext(() -> SimpleDataContext.builder() .add(CommonDataKeys.PROJECT, libertyNode.getProject()) - .add(Constants.LIBERTY_BUILD_FILE, libertyNode.getFilePath()).build()); + .add(Constants.LIBERTY_BUILD_FILE_DATAKEY, libertyNode.getFilePath()).build()); menu.getComponent().show(comp, x, y); } diff --git a/src/main/java/io/openliberty/tools/intellij/actions/LibertyGeneralAction.java b/src/main/java/io/openliberty/tools/intellij/actions/LibertyGeneralAction.java index cd309adba..6bccbcfae 100644 --- a/src/main/java/io/openliberty/tools/intellij/actions/LibertyGeneralAction.java +++ b/src/main/java/io/openliberty/tools/intellij/actions/LibertyGeneralAction.java @@ -55,7 +55,10 @@ public void actionPerformed(@NotNull AnActionEvent e) { // Obtain the liberty module associated to the current action. LibertyModule libertyModule = null; - VirtualFile buildFile = e.getDataContext().getData(Constants.LIBERTY_BUILD_FILE); + //Using DataKey instead of a string because the getData(String) method is deprecated + // and does not work as expected in IntelliJ 2024.2 and later versions. + // This ensures compatibility and proper retrieval of the build file across all supported versions. + VirtualFile buildFile = e.getDataContext().getData(Constants.LIBERTY_BUILD_FILE_DATAKEY); if (buildFile != null) { // The action is being driven from the project drop-down tree menu or from the project context menu. libertyModule = LibertyModules.getInstance().getLibertyModule(buildFile); diff --git a/src/main/java/io/openliberty/tools/intellij/runConfiguration/LibertyRunConfiguration.java b/src/main/java/io/openliberty/tools/intellij/runConfiguration/LibertyRunConfiguration.java index 1a20cc454..ae636f75b 100644 --- a/src/main/java/io/openliberty/tools/intellij/runConfiguration/LibertyRunConfiguration.java +++ b/src/main/java/io/openliberty/tools/intellij/runConfiguration/LibertyRunConfiguration.java @@ -143,7 +143,7 @@ public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEn if (CommonDataKeys.PROJECT.is(dataId)) { return libertyModule.getProject(); } - if (Constants.LIBERTY_BUILD_FILE.getName().equals(dataId)) { + if (Constants.LIBERTY_BUILD_FILE_DATAKEY.getName().equals(dataId)) { return libertyModule.getBuildFile(); } return null; diff --git a/src/main/java/io/openliberty/tools/intellij/util/Constants.java b/src/main/java/io/openliberty/tools/intellij/util/Constants.java index b27556d66..009bc40e7 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/Constants.java +++ b/src/main/java/io/openliberty/tools/intellij/util/Constants.java @@ -49,7 +49,8 @@ public final class Constants { /** * Constants for Data Context, passing information between the tree nodes and the Actions */ - public static final DataKey LIBERTY_BUILD_FILE = DataKey.create("LIBERTY_BUILD_FILE"); + // Using DataKey instead of a string because the getData(String) method is deprecated starting with intellij 2024.2 + public static final DataKey LIBERTY_BUILD_FILE_DATAKEY = DataKey.create("LIBERTY_BUILD_FILE"); public static final String LIBERTY_PROJECT_NAME = "LIBERTY_PROJECT_NAME"; public static final String LIBERTY_PROJECT_TYPE = "LIBERTY_PROJECT_TYPE"; public static final String LIBERTY_PROJECT_MAP = "LIBERTY_PROJECT_MAP"; diff --git a/src/main/java/io/openliberty/tools/intellij/util/TreeDataProvider.java b/src/main/java/io/openliberty/tools/intellij/util/TreeDataProvider.java index d161a218b..824b6fe10 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/TreeDataProvider.java +++ b/src/main/java/io/openliberty/tools/intellij/util/TreeDataProvider.java @@ -28,7 +28,7 @@ public class TreeDataProvider implements DataProvider { @Nullable @Override public Object getData(@NotNull String dataId) { - if (dataId.equals(Constants.LIBERTY_BUILD_FILE.getName())) { + if (dataId.equals(Constants.LIBERTY_BUILD_FILE_DATAKEY.getName())) { return this.currentFile; } else if (dataId.equals(Constants.LIBERTY_PROJECT_NAME)) { return this.projectName;