Skip to content

Commit

Permalink
Remove all use of deprecated and internal APIs.
Browse files Browse the repository at this point in the history
Fix verification versions, and don't use `untilBuild` to avoid constant updating.
  • Loading branch information
Layoric committed Aug 18, 2023
1 parent e54f88d commit be32e38
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 50 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ tasks {
patchPluginXml {
version.set(properties("pluginVersion"))
sinceBuild.set(properties("pluginSinceBuild"))
untilBuild.set(properties("pluginUntilBuild"))
//untilBuild.set(properties("pluginUntilBuild"))

// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription.set(
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/servicestack/idea/AddRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
51 changes: 23 additions & 28 deletions src/main/java/net/servicestack/idea/AddServiceStackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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<String> 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);
Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/net/servicestack/idea/IDEAPomFileHelper.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions src/main/java/net/servicestack/idea/common/Analytics.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 );
}
}

0 comments on commit be32e38

Please sign in to comment.