diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/externalSystemIntegration/output/importproject/quickfixes/DownloadArtifactBuildIssue.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/externalSystemIntegration/output/importproject/quickfixes/DownloadArtifactBuildIssue.kt index fa84cf41c5e66..3716de0bc7d28 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/externalSystemIntegration/output/importproject/quickfixes/DownloadArtifactBuildIssue.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/externalSystemIntegration/output/importproject/quickfixes/DownloadArtifactBuildIssue.kt @@ -24,33 +24,32 @@ object DownloadArtifactBuildIssue { override fun getNavigatable(project: Project): Navigatable? = null } } - - @JvmStatic - fun removeBadArtifact(file: File?) { - if (file == null) return - MavenLog.LOG.info("start deleting lastUpdate file from $file") - val files: Array = file.listFiles { dir, name -> name.endsWith(".lastUpdated", true) } ?: return - - for (childFiles in files) { - val deleted = FileUtil.delete(childFiles) - if (!deleted) { - MavenLog.LOG.warn("$childFiles not deleted") - } - } - } } -class MavenReimportQuickFix() : BuildIssueQuickFix { +class CleanBrokenArtifactsAndReimportQuickFix(val unresolvedArtifactFiles: Collection) : BuildIssueQuickFix { override val id: String = ID override fun runQuickFix(project: Project, dataContext: DataContext): CompletableFuture<*> { + unresolvedArtifactFiles.forEach { deleteLastUpdatedFiles(it) } MavenProjectsManager.getInstance(project).forceUpdateProjects() return CompletableFuture.completedFuture(null) } + private fun deleteLastUpdatedFiles(unresolvedArtifactDirectory: File) { + MavenLog.LOG.info("start deleting lastUpdated file from $unresolvedArtifactDirectory") + val files: Array = unresolvedArtifactDirectory.listFiles { dir, name -> name.endsWith(".lastUpdated", true) } ?: return + + for (childFiles in files) { + val deleted = FileUtil.delete(childFiles) + if (!deleted) { + MavenLog.LOG.warn("$childFiles not deleted") + } + } + } + companion object { - const val ID = "maven_reimport_quick_fix" + const val ID = "clean_broken_artifacts_and_reimport_quick_fix" } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectResolver.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectResolver.java index e0482ea23420f..dd724dcf17351 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectResolver.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectResolver.java @@ -17,8 +17,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import org.jetbrains.idea.maven.execution.RunnerBundle; -import org.jetbrains.idea.maven.externalSystemIntegration.output.importproject.quickfixes.DownloadArtifactBuildIssue; -import org.jetbrains.idea.maven.externalSystemIntegration.output.importproject.quickfixes.MavenReimportQuickFix; +import org.jetbrains.idea.maven.externalSystemIntegration.output.importproject.quickfixes.CleanBrokenArtifactsAndReimportQuickFix; import org.jetbrains.idea.maven.importing.MavenImporter; import org.jetbrains.idea.maven.model.*; import org.jetbrains.idea.maven.server.MavenConfigParseException; @@ -173,7 +172,7 @@ public void resolvePlugins(@NotNull Project project, try { process.setText(MavenProjectBundle.message("maven.downloading.pom.plugins", mavenProject.getDisplayName())); - Set unresolvedPlugins = new HashSet<>(); + Map unresolvedPlugins = new HashMap<>(); for (MavenPlugin each : mavenProject.getDeclaredPlugins()) { process.checkCanceled(); @@ -188,13 +187,13 @@ public void resolvePlugins(@NotNull Project project, } } if (artifacts.isEmpty() && myProject != null) { - DownloadArtifactBuildIssue.removeBadArtifact(file); - unresolvedPlugins.add(each); + unresolvedPlugins.put(each, file); } } if (!unresolvedPlugins.isEmpty()) { - MavenReimportQuickFix fix = new MavenReimportQuickFix(); - for (MavenPlugin mavenPlugin : unresolvedPlugins) { + Collection files = unresolvedPlugins.values(); + CleanBrokenArtifactsAndReimportQuickFix fix = new CleanBrokenArtifactsAndReimportQuickFix(files); + for (MavenPlugin mavenPlugin : unresolvedPlugins.keySet()) { MavenProjectsManager.getInstance(myProject) .getSyncConsole().getListener(MavenServerProgressIndicator.ResolveType.PLUGIN) .showBuildIssue(mavenPlugin.getMavenId().getKey(), fix); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java index d46cc86e12fa8..9dc3c7aef01b0 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java @@ -69,8 +69,7 @@ import org.jetbrains.idea.maven.dom.MavenDomUtil; import org.jetbrains.idea.maven.execution.MavenRunnerSettings; import org.jetbrains.idea.maven.execution.SyncBundle; -import org.jetbrains.idea.maven.externalSystemIntegration.output.importproject.quickfixes.DownloadArtifactBuildIssue; -import org.jetbrains.idea.maven.externalSystemIntegration.output.importproject.quickfixes.MavenReimportQuickFix; +import org.jetbrains.idea.maven.externalSystemIntegration.output.importproject.quickfixes.CleanBrokenArtifactsAndReimportQuickFix; import org.jetbrains.idea.maven.model.*; import org.jetbrains.idea.maven.project.MavenProject; import org.jetbrains.idea.maven.project.MavenProjectReaderResult; @@ -1096,9 +1095,9 @@ public static void notifySyncForUnresolved(@NotNull Project project, @NotNull Co } MavenSyncConsole syncConsole = MavenProjectsManager.getInstance(project).getSyncConsole(); - MavenReimportQuickFix fix = new MavenReimportQuickFix(); + List files = ContainerUtil.map(unresolvedArtifacts, a -> a.getFile().getParentFile()); + CleanBrokenArtifactsAndReimportQuickFix fix = new CleanBrokenArtifactsAndReimportQuickFix(files); for (MavenArtifact artifact : unresolvedArtifacts) { - DownloadArtifactBuildIssue.removeBadArtifact(artifact.getFile().getParentFile()); syncConsole.getListener(MavenServerProgressIndicator.ResolveType.DEPENDENCY) .showBuildIssue(artifact.getMavenId().getKey(), fix); }