Skip to content

Commit

Permalink
[maven] IJ-CR-10486 IDEA-200751 During importing of Maven projects "*…
Browse files Browse the repository at this point in the history
….lastUpdated" files might be created in the local repository

revert to old logic. delete lastUpdated files after quick fix perform.

GitOrigin-RevId: 06f93511d409cc5ae6831c27c26dd41def2fe132
  • Loading branch information
Grigoriy Myasoedov authored and intellij-monorepo-bot committed Jul 21, 2021
1 parent 9aa6ff5 commit c621214
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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> = 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<File>) : 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<File> = 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"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -173,7 +172,7 @@ public void resolvePlugins(@NotNull Project project,
try {
process.setText(MavenProjectBundle.message("maven.downloading.pom.plugins", mavenProject.getDisplayName()));

Set<MavenPlugin> unresolvedPlugins = new HashSet<>();
Map<MavenPlugin, File> unresolvedPlugins = new HashMap<>();
for (MavenPlugin each : mavenProject.getDeclaredPlugins()) {
process.checkCanceled();

Expand All @@ -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<File> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1096,9 +1095,9 @@ public static void notifySyncForUnresolved(@NotNull Project project, @NotNull Co
}

MavenSyncConsole syncConsole = MavenProjectsManager.getInstance(project).getSyncConsole();
MavenReimportQuickFix fix = new MavenReimportQuickFix();
List<File> 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);
}
Expand Down

0 comments on commit c621214

Please sign in to comment.