diff --git a/build.gradle.kts b/build.gradle.kts index a1cff95..660e3af 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -84,7 +84,7 @@ tasks { patchPluginXml { version.set(properties("pluginVersion")) sinceBuild.set(properties("pluginSinceBuild")) - untilBuild.set(properties("pluginUntilBuild")) + //untilBuild.set(properties("pluginUntilBuild")) // Extract the section from README.md and provide for the plugin's manifest pluginDescription.set( diff --git a/gradle.properties b/gradle.properties index 945f365..9d7b2a3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,20 +7,20 @@ pluginVersion = 1.3.3 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. -pluginSinceBuild = 192 -pluginUntilBuild = 231.* +pluginSinceBuild = 211.6693.111 +# pluginUntilBuild = 231.* # Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl # See https://jb.gg/intellij-platform-builds-list for available build versions. -pluginVerifierIdeVersions = 2021.1.3, 2022.1 +pluginVerifierIdeVersions = 211.6693.111 platformType = IC -platformVersion = 2019.3.4 +platformVersion = 2021.1 platformDownloadSources = true # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 -platformPlugins = maven, java, PythonCore:193.6911.18 +platformPlugins = maven, java, PythonCore:211.6693.119 # Opt-out flag for bundling Kotlin standard library. # See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details. diff --git a/src/main/java/net/servicestack/idea/AddRef.java b/src/main/java/net/servicestack/idea/AddRef.java index 28c81e8..9cd4c94 100644 --- a/src/main/java/net/servicestack/idea/AddRef.java +++ b/src/main/java/net/servicestack/idea/AddRef.java @@ -207,7 +207,7 @@ private void processOK() { builder.append(metadataInputLine); - JsonElement jElement = new JsonParser().parse(builder.toString()); + JsonElement jElement = JsonParser.parseString(builder.toString()); if (jElement.getAsJsonArray().size() > 0) { String latestTag = jElement.getAsJsonArray().get(0).getAsJsonObject().get("name").getAsJsonPrimitive().getAsString(); DepConfig.setServiceStackVersion(latestTag.substring(1)); diff --git a/src/main/java/net/servicestack/idea/AddServiceStackAction.java b/src/main/java/net/servicestack/idea/AddServiceStackAction.java index 94b719d..669bfbe 100644 --- a/src/main/java/net/servicestack/idea/AddServiceStackAction.java +++ b/src/main/java/net/servicestack/idea/AddServiceStackAction.java @@ -14,7 +14,9 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl; +import com.intellij.openapi.roots.LanguageLevelModuleExtension; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; @@ -60,28 +62,6 @@ public void actionPerformed(@NotNull AnActionEvent e) { if (mainPackage != null) { dialog.setSelectedPackage(mainPackage); } - } else if (module.getModuleFile() != null) { - try { - PsiDirectory selectedDir = (PsiDirectory) element; - String packageName = ""; - String moduleDirectoryPath = module.getModuleFile().getParent().getPath(); - List packageArray = new ArrayList<>(); - while (selectedDir != null && !(moduleDirectoryPath.equals(selectedDir.getVirtualFile().getPath()))) { - packageArray.add(selectedDir.getName()); - selectedDir = selectedDir.getParent(); - PsiPackage mainPackage = testPackage(module, packageName, packageArray); - if (mainPackage != null) { - //"java" is a valid package name in an empty project according to openapi so we have to ignore it and no pre-populate package name.... - if(mainPackage.getQualifiedName().equals("java")) { - break; - } - dialog.setSelectedPackage(mainPackage); - break; - } - } - } catch (Exception ex) { - //do nothing, can't get package name. - } } ShowDialog(module, dialog, e); @@ -192,12 +172,27 @@ public boolean isJavaProject(Module module) { return false; } - LanguageLevelModuleExtensionImpl languageLevelExtension = LanguageLevelModuleExtensionImpl.getInstance(module); + LanguageLevelModuleExtension languageLevelModuleExtension = ModuleRootManager.getInstance(module).getModuleExtension(LanguageLevelModuleExtension.class); + + LanguageLevel languageLevel = null; + + if (languageLevelModuleExtension != null) { + languageLevel = languageLevelModuleExtension.getLanguageLevel(); + } + + if (languageLevel == null) { // module does not have a specific language level, let's check global project setting + LanguageLevelProjectExtension languageLevelProjectExtension = LanguageLevelProjectExtension.getInstance(module.getProject()); + if (languageLevelProjectExtension != null) { + languageLevel = languageLevelProjectExtension.getLanguageLevel(); + } + } - // Check if language level is not null and it is at least JDK_1_3 - return languageLevelExtension != null && - languageLevelExtension.getLanguageLevel() != null && - languageLevelExtension.getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_3); + // Check if language is not null and at least JDK_1_1 (or your required Java level.) + if (languageLevel != null && languageLevel.isAtLeast(LanguageLevel.JDK_1_3)) { + return true; + } + + return false; } static Module getModule(Project project) { diff --git a/src/main/java/net/servicestack/idea/IDEAPomFileHelper.java b/src/main/java/net/servicestack/idea/IDEAPomFileHelper.java index 3c2f41f..898e468 100644 --- a/src/main/java/net/servicestack/idea/IDEAPomFileHelper.java +++ b/src/main/java/net/servicestack/idea/IDEAPomFileHelper.java @@ -1,17 +1,22 @@ package net.servicestack.idea; +import com.intellij.ide.highlighter.XmlFileType; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.DocumentRunnable; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; +import com.intellij.psi.search.FileTypeIndex; import com.intellij.psi.search.FilenameIndex; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.indexing.FileBasedIndex; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -29,6 +34,8 @@ import java.io.File; import java.io.IOException; import java.io.StringWriter; +import java.util.Collection; +import java.util.Objects; public class IDEAPomFileHelper { @@ -49,19 +56,15 @@ public boolean addMavenDependency(final Module module,File pomFile, String group public static String findNearestModulePomFile(Module module) { - PsiFile[] pomLibFiles = FilenameIndex.getFilesByName(module.getProject(), "pom.xml", GlobalSearchScope.allScope(module.getProject())); - String pomFilePath = null; - for(PsiFile psiPom : pomLibFiles) { - PsiDirectory psiPomParent = psiPom.getParent(); - Project project = module.getProject(); - if(psiPomParent == null) { - continue; - } - if(psiPomParent.getVirtualFile().getPath().equals(project.getBasePath())) { - pomFilePath = psiPom.getVirtualFile().getPath(); - } + Project project = module.getProject(); + VirtualFile projectDir = VfsUtil.findRelativeFile(Objects.requireNonNull(project.getBasePath()), project.getWorkspaceFile()); + VirtualFile pomFile = VfsUtilCore.findRelativeFile("pom.xml", projectDir); + + if (pomFile != null && Objects.equals(project.getBasePath(), pomFile.getParent().getPath())) { + return pomFile.getPath(); } - return pomFilePath; + + return null; } private void PomAppendDependency(final Module module, final File pomFile, String groupId, String packageId, String version) throws ParserConfigurationException, IOException, SAXException, TransformerException { diff --git a/src/main/java/net/servicestack/idea/UpdateServiceStackReferenceIntention.java b/src/main/java/net/servicestack/idea/UpdateServiceStackReferenceIntention.java index 136b08d..556a94d 100644 --- a/src/main/java/net/servicestack/idea/UpdateServiceStackReferenceIntention.java +++ b/src/main/java/net/servicestack/idea/UpdateServiceStackReferenceIntention.java @@ -59,6 +59,6 @@ public boolean startInWriteAction() { @Override public Icon getIcon(@IconFlags int i) { - return IconLoader.getIcon("/servicestack.svg"); + return IconLoader.getIcon("/servicestack.svg",UpdateServiceStackReferenceIntention.class); } } diff --git a/src/main/java/net/servicestack/idea/common/Analytics.java b/src/main/java/net/servicestack/idea/common/Analytics.java index e3b8e16..7885aad 100644 --- a/src/main/java/net/servicestack/idea/common/Analytics.java +++ b/src/main/java/net/servicestack/idea/common/Analytics.java @@ -1,5 +1,7 @@ package net.servicestack.idea.common; +import com.intellij.openapi.project.Project; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; diff --git a/src/main/java/net/servicestack/idea/common/PluginSettingsConfigurable.java b/src/main/java/net/servicestack/idea/common/PluginSettingsConfigurable.java index 424a9cd..db9e1c7 100644 --- a/src/main/java/net/servicestack/idea/common/PluginSettingsConfigurable.java +++ b/src/main/java/net/servicestack/idea/common/PluginSettingsConfigurable.java @@ -2,6 +2,7 @@ import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SearchableConfigurable; +import com.intellij.openapi.project.ProjectManager; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/net/servicestack/idea/common/PluginSettingsService.java b/src/main/java/net/servicestack/idea/common/PluginSettingsService.java index 3ee4795..d45528d 100644 --- a/src/main/java/net/servicestack/idea/common/PluginSettingsService.java +++ b/src/main/java/net/servicestack/idea/common/PluginSettingsService.java @@ -1,7 +1,7 @@ package net.servicestack.idea.common; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.util.xmlb.XmlSerializerUtil; @@ -27,6 +27,6 @@ public void loadState(@NotNull PluginSettingsService pluginSettingsService) { } public static PluginSettingsService getInstance() { - return ServiceManager.getService( PluginSettingsService.class ); + return ApplicationManager.getApplication().getService( PluginSettingsService.class ); } }