Skip to content

Commit

Permalink
chore: new features to 223
Browse files Browse the repository at this point in the history
  • Loading branch information
gmyasoedov committed Jan 4, 2025
1 parent 9bb9afb commit 00e7649
Show file tree
Hide file tree
Showing 22 changed files with 56 additions and 183 deletions.
4 changes: 3 additions & 1 deletion gmaven/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ repositories {
dependencies {
implementation(project(":server-api"))
runtimeOnly(project(":maven-ext-event-handler"))
runtimeOnly("io.github.grisha9:maven-model-reader-plugin:0.4")
runtimeOnly("io.github.grisha9:maven-model-reader-plugin:0.4") {
exclude("com.google.code.gson", "gson")
}
}

// Configure Gradle IntelliJ Plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public static MavenExecutionSettings getExecutionSettings(
result.setOutputLevel(projectSettings.getOutputLevel());
result.setCheckSources(settings.isCheckSourcesInLocalRepo());
result.setSkipTests(settings.isSkipTests());
result.setIncrementalSync(projectSettings.getIncrementalSync());
result.setShowPluginNodes(!Registry.is("gmaven.import.readonly") && projectSettings.getShowPluginNodes());
result.setReadonly(Registry.is("gmaven.import.readonly"));
if (result.isReadonly()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class MavenExecutionSettings extends ExternalSystemExecutionSettings {
private boolean showPluginNodes = true;
private boolean isSkipTests = false;
private boolean readonly = false;
private boolean incrementalSync = false;
@NotNull
private ProjectSettingsControlBuilder.OutputLevelType outputLevel = DEFAULT;
@NotNull
Expand Down Expand Up @@ -189,14 +188,6 @@ public void setReadonly(boolean readonly) {
this.readonly = readonly;
}

public boolean isIncrementalSync() {
return incrementalSync;
}

public void setIncrementalSync(boolean incrementalSync) {
this.incrementalSync = incrementalSync;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ public class MavenExecutionWorkspace implements Serializable {
private String subProjectBuildFile;
@Nullable
private String externalProjectPath;
@Nullable
private String multiModuleProjectDirectory;
@Nullable
private String incrementalProjectName;

public void addProfile(@Nullable ProfileExecution data) {
if (data != null) {
Expand Down Expand Up @@ -74,21 +70,4 @@ public String getExternalProjectPath() {
public void setExternalProjectPath(String externalProjectPath) {
this.externalProjectPath = externalProjectPath;
}

@Nullable
public String getMultiModuleProjectDirectory() {
return multiModuleProjectDirectory;
}

public void setMultiModuleProjectDirectory(@Nullable String multiModuleProjectDirectory) {
this.multiModuleProjectDirectory = multiModuleProjectDirectory;
}

public @Nullable String getIncrementalProjectName() {
return incrementalProjectName;
}

public void setIncrementalProjectName(@Nullable String incrementalProjectName) {
this.incrementalProjectName = incrementalProjectName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public class MavenUtils {
private MavenUtils() {
}

@Nullable
public static Path toNioPathOrNull(@Nullable VirtualFile file) {
if (file == null) return null;
try {
return file.toNioPath();
} catch (Exception e) {
return null;
}
}

@NotNull
public static VirtualFile getVFile(File file) {
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.toNioPathOrNull
import com.intellij.psi.PsiElement
import com.intellij.psi.xml.XmlFile
import com.intellij.psi.xml.XmlTag
Expand Down Expand Up @@ -50,7 +49,8 @@ class PomXmlDomGutterAnnotator : Annotator {
addGutterIcon(parentPath, xmlTag, holder, GMavenIcons.ParentProject, "GMaven:parent")
} else if (tagName == MODULE) {
val moduleName = xmlTag.value.text
val modulePath = xmlTag.containingFile.parent?.virtualFile?.toNioPathOrNull()?.resolve(moduleName) ?: return
val virtualFile = xmlTag.containingFile.parent?.virtualFile ?: return
val modulePath = MavenUtils.toNioPathOrNull(virtualFile)?.resolve(moduleName) ?: return
addGutterIcon(modulePath, xmlTag, holder, AllIcons.Gutter.OverridenMethod, "GMaven:module")
} else if (tagName == DEPENDENCY && xmlTag.parentTag?.parentTag?.name != DEPENDENCY_MANAGEMENT) {
val management = getDependencyManagement(xmlFile, settingsHolder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.intellij.lang.xml.XMLLanguage
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.readText
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiFileFactory
Expand Down Expand Up @@ -61,8 +60,9 @@ object XmlPsiUtil {
val psiFile = PsiManager.getInstance(project).findFile(virtualFile) ?: return null
return if (psiFile is XmlFile) psiFile else {
try {
val content = String(virtualFile.contentsToByteArray())
PsiFileFactory.getInstance(project)
.createFileFromText(filePath.name, XMLLanguage.INSTANCE, virtualFile.readText()) as? XmlFile
.createFileFromText(filePath.name, XMLLanguage.INSTANCE, content) as? XmlFile
} catch (e: Exception) {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.intellij.codeInsight.completion.CompletionType.BASIC
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementDecorator
import com.intellij.codeInsight.template.TemplateManager
import com.intellij.openapi.vfs.toNioPathOrNull
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.xml.XmlFile
import com.intellij.psi.xml.XmlTag
Expand All @@ -28,7 +27,7 @@ class PomXmlCompletionTagListenerContributor : CompletionContributor() {
return // Don't brake the template.
}
val psiFile = parameters.originalFile as? XmlFile ?: return
val filePath = psiFile.virtualFile.toNioPathOrNull()?.toString() ?: return
val filePath = MavenUtils.toNioPathOrNull(psiFile.virtualFile)?.toString() ?: return
if (!CachedModuleDataService.getDataHolder(psiFile.project).isConfigPath(filePath)) return

result.runRemainingContributors(parameters) { r ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ru.rzn.gmyasoedov.gmaven.dom.reference
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.openapi.util.TextRange
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.toNioPathOrNull
import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiManager
Expand All @@ -14,6 +13,7 @@ import com.intellij.psi.xml.XmlTag
import ru.rzn.gmyasoedov.gmaven.dom.XmlPsiUtil
import ru.rzn.gmyasoedov.gmaven.settings.MavenSettings
import ru.rzn.gmyasoedov.gmaven.utils.MavenArtifactUtil
import ru.rzn.gmyasoedov.gmaven.utils.MavenUtils
import java.nio.file.Path
import java.util.*

Expand Down Expand Up @@ -85,7 +85,7 @@ class MavenPropertyPsiReference(
}

if (propertyName == MULTIPROJECT_DIR_PROP) {
val dirPath = xmlFile.parent?.virtualFile?.toNioPathOrNull()?.toString() ?: return null
val dirPath = MavenUtils.toNioPathOrNull(xmlFile.parent?.virtualFile)?.toString() ?: return null
val setting = MavenSettings.getInstance(element.project)
.getLinkedProjectSettings(dirPath) ?: return null
val virtualFile = LocalFileSystem.getInstance().findFileByPath(setting.externalProjectPath) ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private fun linkProjectLibrary(

val libraryData = cache.computeIfAbsent(libraryName) {
var newValueToCache = ExternalSystemApiUtil
.findChild(ideProject, ProjectKeys.LIBRARY) { it.data.externalName == libraryName }
.find(ideProject, ProjectKeys.LIBRARY) { it.data.externalName == libraryName }
if (newValueToCache == null) {
newValueToCache = ideProject.createChild(ProjectKeys.LIBRARY, library)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExe
import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode
import com.intellij.openapi.externalSystem.task.TaskCallback
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil
import com.intellij.openapi.vfs.toNioPathOrNull
import com.intellij.psi.PsiFileFactory
import com.intellij.util.execution.ParametersListUtil
import ru.rzn.gmyasoedov.gmaven.GMavenConstants
Expand All @@ -22,6 +21,7 @@ import ru.rzn.gmyasoedov.gmaven.util.CachedModuleDataService
import ru.rzn.gmyasoedov.gmaven.util.GMavenNotification
import ru.rzn.gmyasoedov.gmaven.util.MavenPathUtil
import ru.rzn.gmyasoedov.gmaven.utils.MavenLog
import ru.rzn.gmyasoedov.gmaven.utils.MavenUtils
import java.io.IOException
import java.nio.file.Files
import kotlin.io.path.absolutePathString
Expand All @@ -42,13 +42,13 @@ class EffectivePomAction : ExternalSystemAction() {
override fun isVisible(e: AnActionEvent): Boolean {
val virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE) ?: return false
val project = e.getData(CommonDataKeys.PROJECT) ?: return false
val filePath = virtualFile.toNioPathOrNull()?.toString() ?: return false
val filePath = MavenUtils.toNioPathOrNull(virtualFile)?.toString() ?: return false
return CachedModuleDataService.getDataHolder(project).isConfigPath(filePath)
}

override fun actionPerformed(e: AnActionEvent) {
val virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE) ?: return
val configNioPath = virtualFile.toNioPathOrNull() ?: return
val configNioPath = MavenUtils.toNioPathOrNull(virtualFile) ?: return
val project = e.getData(CommonDataKeys.PROJECT) ?: return
val projectSettings = MavenSettings.getInstance(project)
.getLinkedProjectSettings(configNioPath.parent.toString()) ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.toNioPathOrNull
import ru.rzn.gmyasoedov.gmaven.GMavenConstants
import ru.rzn.gmyasoedov.gmaven.GMavenConstants.SYSTEM_ID
import ru.rzn.gmyasoedov.gmaven.bundle.GBundle
import ru.rzn.gmyasoedov.gmaven.settings.MavenSettings
import ru.rzn.gmyasoedov.gmaven.util.CachedModuleDataService
import ru.rzn.gmyasoedov.gmaven.utils.MavenLog
import ru.rzn.gmyasoedov.gmaven.utils.MavenUtils
import java.nio.file.Path
import kotlin.io.path.isDirectory

Expand All @@ -40,7 +40,7 @@ class IgnoreMavenProjectAction : ExternalSystemToggleAction() {
override fun isVisible(e: AnActionEvent): Boolean {
val virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE) ?: return false
val project = e.getData(CommonDataKeys.PROJECT) ?: return false
val nioPath = virtualFile.toNioPathOrNull()?.toString() ?: return false
val nioPath = MavenUtils.toNioPathOrNull(virtualFile)?.toString() ?: return false

return if (virtualFile.isDirectory)
MavenSettings.getInstance(project).getLinkedProjectSettings(nioPath) != null
Expand All @@ -49,7 +49,7 @@ class IgnoreMavenProjectAction : ExternalSystemToggleAction() {
}

override fun setSelected(e: AnActionEvent, state: Boolean) {
val nioPath = e.getData(CommonDataKeys.VIRTUAL_FILE)?.toNioPathOrNull() ?: return
val nioPath = MavenUtils.toNioPathOrNull(e.getData(CommonDataKeys.VIRTUAL_FILE)) ?: return
val project = e.getData(CommonDataKeys.PROJECT) ?: return
val projectDataNode = getProjectDataNode(project, nioPath) ?: return
val allModuleNodes = ExternalSystemApiUtil.findAll(projectDataNode, ProjectKeys.MODULE)
Expand Down Expand Up @@ -78,7 +78,7 @@ class IgnoreMavenProjectAction : ExternalSystemToggleAction() {

override fun doIsSelected(e: AnActionEvent): Boolean {
try {
val nioPath = e.getData(CommonDataKeys.VIRTUAL_FILE)?.toNioPathOrNull() ?: return false
val nioPath = MavenUtils.toNioPathOrNull(e.getData(CommonDataKeys.VIRTUAL_FILE)) ?: return false
val project = e.getData(CommonDataKeys.PROJECT) ?: return false
val projectDataNode = getProjectDataNode(project, nioPath) ?: return false
val allModuleNodes = ExternalSystemApiUtil.findAll(projectDataNode, ProjectKeys.MODULE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ru.rzn.gmyasoedov.gmaven.project.action
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.externalSystem.action.ExternalSystemAction
import com.intellij.openapi.vfs.toNioPathOrNull
import ru.rzn.gmyasoedov.gmaven.bundle.GBundle
import ru.rzn.gmyasoedov.gmaven.util.CachedModuleDataService
import ru.rzn.gmyasoedov.gmaven.utils.MavenUtils
Expand All @@ -21,7 +20,7 @@ class ImportProjectFromBuildFIleAction : ExternalSystemAction() {
override fun isVisible(e: AnActionEvent): Boolean {
val virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE) ?: return false
val project = e.getData(CommonDataKeys.PROJECT) ?: return false
val filePath = virtualFile.toNioPathOrNull()?.toString() ?: return false
val filePath = MavenUtils.toNioPathOrNull(virtualFile)?.toString() ?: return false
if (CachedModuleDataService.getDataHolder(project).isConfigPath(filePath)) return false
return MavenUtils.isSimplePomFile(virtualFile.name) || MavenUtils.isPotentialPomFile(virtualFile.name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package ru.rzn.gmyasoedov.gmaven.project.externalSystem.service
import com.intellij.openapi.externalSystem.service.settings.ExternalSystemConfigLocator
import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.toNioPathOrNull
import ru.rzn.gmyasoedov.gmaven.GMavenConstants
import ru.rzn.gmyasoedov.gmaven.util.CachedModuleDataService
import ru.rzn.gmyasoedov.gmaven.utils.MavenUtils

class GMavenSystemConfigLocator : ExternalSystemConfigLocator {
override fun getTargetExternalSystemId() = GMavenConstants.SYSTEM_ID
Expand All @@ -16,7 +16,7 @@ class GMavenSystemConfigLocator : ExternalSystemConfigLocator {
val cachedDataHolder = CachedModuleDataService.getCurrentData()
for (child in configPath.children) {
if (child.isDirectory) continue
val nioPath = child.toNioPathOrNull()?.toString() ?: continue
val nioPath = MavenUtils.toNioPathOrNull(child)?.toString() ?: continue
if (cachedDataHolder.isConfigPath(nioPath)) return child
}
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListen
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.isFile
import com.intellij.projectImport.ProjectOpenProcessor
import ru.rzn.gmyasoedov.gmaven.GMavenConstants.SYSTEM_ID
import ru.rzn.gmyasoedov.gmaven.settings.MavenProjectSettings
Expand All @@ -21,7 +20,7 @@ class UnlinkedProjectAware : ExternalSystemUnlinkedProjectAware {
override val systemId = SYSTEM_ID

override fun isBuildFile(project: Project, buildFile: VirtualFile): Boolean {
return buildFile.isFile && MavenUtils.isSimplePomFile(buildFile)
return !buildFile.isDirectory && MavenUtils.isSimplePomFile(buildFile)
}

override fun isLinkedProject(project: Project, externalProjectPath: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ private fun setupImportParamsFromSettings(request: GServerRequest, commandLine:
request.settings.argumentsImport?.forEach { commandLine.addParameter(it) }
val importTaskName = "$PLUGIN_BASE_NAME:" + (if (request.readOnly) "read" else "resolve")
commandLine.addParameter(importTaskName)
if (request.settings.executionWorkspace.incrementalProjectName != null) {
commandLine.parametersList.addProperty("incremental", "true")
commandLine.addParameters("-pl", request.settings.executionWorkspace.incrementalProjectName, "-am", "-amd")
}
}

private fun runMavenImport(
Expand Down Expand Up @@ -201,7 +197,7 @@ private fun runMavenImportInner(
} finally {
if (processSupport.exitCode != 0) {
FileUtil.delete(resultFilePath)
} else if (!request.settings.isIncrementalSync && Registry.`is`("gmaven.process.remove.result.file")) {
} else if (Registry.`is`("gmaven.process.remove.result.file")) {
if (!resultFilePath.parent.name.equals("target", true)) FileUtil.delete(resultFilePath)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class MavenProjectSettings : ExternalProjectSettings() {
var resolveModulePerSourceSet = true
var nonRecursive = false
var showPluginNodes = true
var incrementalSync = false
var snapshotUpdateType = SnapshotUpdateType.DEFAULT
var outputLevel = OutputLevelType.DEFAULT
var threadCount: String? = null
Expand All @@ -37,7 +36,6 @@ class MavenProjectSettings : ExternalProjectSettings() {
result.arguments = arguments
result.argumentsImport = argumentsImport
result.localRepositoryPath = localRepositoryPath
result.incrementalSync = incrementalSync
return result
}
}
Loading

0 comments on commit 00e7649

Please sign in to comment.