From de3f3f43312c021518f444db0f67e827f9beb481 Mon Sep 17 00:00:00 2001 From: Guy Mahieu Date: Sat, 16 Nov 2024 21:08:20 +0100 Subject: [PATCH] Allow skipping downloads of artifacts that are actually other modules in the same project. --- .../config/model/IvyIdeaProjectSettings.java | 11 ++++++++++- .../ui/IvyIdeaProjectSettingsPanel.form | 13 ++++++++++++- .../ui/IvyIdeaProjectSettingsPanel.java | 2 ++ .../ivyidea/resolve/DependencyResolver.java | 19 +++++++++++++------ .../resolve/IntellijModuleDependencies.java | 5 +++++ 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/clarent/ivyidea/config/model/IvyIdeaProjectSettings.java b/src/main/java/org/clarent/ivyidea/config/model/IvyIdeaProjectSettings.java index 49eb6cc0..b8d3df52 100644 --- a/src/main/java/org/clarent/ivyidea/config/model/IvyIdeaProjectSettings.java +++ b/src/main/java/org/clarent/ivyidea/config/model/IvyIdeaProjectSettings.java @@ -36,7 +36,7 @@ public class IvyIdeaProjectSettings { private boolean libraryNameIncludesConfiguration = false; private boolean detectDependenciesOnOtherModules = true; private String ivyLogLevelThreshold = IvyLogLevel.None.name(); - + private boolean skipArtifactDownloadForInternalModules = false; private ArtifactTypeSettings artifactTypeSettings = new ArtifactTypeSettings(); @@ -154,9 +154,18 @@ public void setArtifactTypeSettings(ArtifactTypeSettings artifactTypeSettings) { this.artifactTypeSettings = artifactTypeSettings; } + public boolean isSkipArtifactDownloadForInternalModules() { + return skipArtifactDownloadForInternalModules; + } + + public void setSkipArtifactDownloadForInternalModules(boolean skipArtifactDownloadForInternalModules) { + this.skipArtifactDownloadForInternalModules = skipArtifactDownloadForInternalModules; + } + public void updateResolveOptions(ResolveOptions options) { options.setValidate(isValidateIvyFiles()); options.setTransitive(isResolveTransitively()); options.setUseCacheOnly(isResolveCacheOnly()); + options.setDownload(!isSkipArtifactDownloadForInternalModules()); } } diff --git a/src/main/java/org/clarent/ivyidea/intellij/ui/IvyIdeaProjectSettingsPanel.form b/src/main/java/org/clarent/ivyidea/intellij/ui/IvyIdeaProjectSettingsPanel.form index f505701d..9faa6eba 100644 --- a/src/main/java/org/clarent/ivyidea/intellij/ui/IvyIdeaProjectSettingsPanel.form +++ b/src/main/java/org/clarent/ivyidea/intellij/ui/IvyIdeaProjectSettingsPanel.form @@ -3,7 +3,7 @@ - + @@ -294,6 +294,17 @@ + + + + + + + + + + + diff --git a/src/main/java/org/clarent/ivyidea/intellij/ui/IvyIdeaProjectSettingsPanel.java b/src/main/java/org/clarent/ivyidea/intellij/ui/IvyIdeaProjectSettingsPanel.java index b5eb5342..2f09a295 100644 --- a/src/main/java/org/clarent/ivyidea/intellij/ui/IvyIdeaProjectSettingsPanel.java +++ b/src/main/java/org/clarent/ivyidea/intellij/ui/IvyIdeaProjectSettingsPanel.java @@ -61,6 +61,7 @@ public class IvyIdeaProjectSettingsPanel { private JCheckBox autoAttachSources; private JCheckBox autoAttachJavadocs; private JCheckBox detectDependenciesOnOtherModules; + private JCheckBox skipDownloadForInternalIntellijModules; private JPanel pnlIvyFiles; private JPanel pnlArtefactTypes; private IvyIdeaProjectSettings internalState; @@ -116,6 +117,7 @@ public void apply() { internalState.setAlwaysAttachJavadocs(autoAttachJavadocs.isSelected()); internalState.setUseCustomIvySettings(useYourOwnIvySettingsRadioButton.isSelected()); internalState.setDetectDependenciesOnOtherModules(detectDependenciesOnOtherModules.isSelected()); + internalState.setSkipArtifactDownloadForInternalModules(skipDownloadForInternalIntellijModules.isSelected()); final PropertiesSettings propertiesSettings = new PropertiesSettings(); propertiesSettings.setPropertyFiles(getPropertiesFiles()); internalState.setPropertiesSettings(propertiesSettings); diff --git a/src/main/java/org/clarent/ivyidea/resolve/DependencyResolver.java b/src/main/java/org/clarent/ivyidea/resolve/DependencyResolver.java index c75ac156..a677f0cd 100644 --- a/src/main/java/org/clarent/ivyidea/resolve/DependencyResolver.java +++ b/src/main/java/org/clarent/ivyidea/resolve/DependencyResolver.java @@ -27,6 +27,7 @@ import org.apache.ivy.core.report.ResolveReport; import org.apache.ivy.core.resolve.DownloadOptions; import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.ResolveOptions; import org.clarent.ivyidea.config.IvyIdeaConfigHelper; import org.clarent.ivyidea.config.model.ArtifactTypeSettings; import org.clarent.ivyidea.exception.IvyFileReadException; @@ -81,15 +82,22 @@ public void resolve(Module module, IvyManager ivyManager) throws IvySettingsNotF final Ivy ivy = ivyManager.getIvy(module); try { - final ResolveReport resolveReport = ivy.resolve(ivyFile.toURI().toURL(), IvyIdeaConfigHelper.createResolveOptions(module)); - extractDependencies(ivy, resolveReport, new IntellijModuleDependencies(module, ivyManager)); + final IntellijModuleDependencies moduleDependencies = new IntellijModuleDependencies(module, ivyManager); + final ResolveOptions resolveOptions = IvyIdeaConfigHelper.createResolveOptions(module); + final ResolveReport resolveReport = ivy.resolve(ivyFile.toURI().toURL(), resolveOptions); + if (!resolveOptions.isDownload()) { + // Artifacts not yet downloaded - this means we will download only the non-internal module artifacts + ivy.getResolveEngine().downloadArtifacts(resolveReport, artifact -> !moduleDependencies.isInternalIntellijModuleDependency(artifact), new DownloadOptions()); + } + extractDependencies(ivy, resolveReport, moduleDependencies); } catch (ParseException | IOException e) { throw new IvyFileReadException(ivyFile.getAbsolutePath(), module.getName(), e); } } + // TODO: This method performs way too much tasks -- refactor it! - protected void extractDependencies(Ivy ivy, ResolveReport resolveReport, IntellijModuleDependencies moduleDependencies) { + protected void extractDependencies(Ivy ivy, ResolveReport resolveReport, IntellijModuleDependencies moduleDependencies) throws IOException { final String[] resolvedConfigurations = resolveReport.getConfigurations(); for (String resolvedConfiguration : resolvedConfigurations) { ConfigurationResolveReport configurationReport = resolveReport.getConfigurationReport(resolvedConfiguration); @@ -130,7 +138,7 @@ protected void extractDependencies(Ivy ivy, ResolveReport resolveReport, Intelli // TODO: if sources are found, don't bother attaching javadoc? // That way, IDEA will generate the javadoc and resolve links to other javadocs if ((attachSources && isSource(project, artifact)) - || (attachJavadocs && isJavadoc(project, artifact))) { + || (attachJavadocs && isJavadoc(project, artifact))) { if (resolveReport.getArtifacts().contains(artifact)) { continue; // already resolved, ignore. } @@ -154,8 +162,7 @@ private void addExternalDependency(Artifact artifact, File artifactFile, String "Unrecognized artifact type: " + artifact.getType() + ", will not add this as a dependency in IntelliJ.", null)); LOGGER.warning("Artifact of unrecognized type " + artifact.getType() + " found, *not* adding as a dependency."); - } - else if (externalDependency.isMissing()) { + } else if (externalDependency.isMissing()) { resolveProblems.add(new ResolveProblem( artifact.getModuleRevisionId().toString(), "File not found: " + externalDependency.getLocalFile().getAbsolutePath()) diff --git a/src/main/java/org/clarent/ivyidea/resolve/IntellijModuleDependencies.java b/src/main/java/org/clarent/ivyidea/resolve/IntellijModuleDependencies.java index 85bd1f34..3ba82f3e 100644 --- a/src/main/java/org/clarent/ivyidea/resolve/IntellijModuleDependencies.java +++ b/src/main/java/org/clarent/ivyidea/resolve/IntellijModuleDependencies.java @@ -17,6 +17,7 @@ package org.clarent.ivyidea.resolve; import com.intellij.openapi.module.Module; +import org.apache.ivy.core.module.descriptor.Artifact; import org.apache.ivy.core.module.descriptor.DependencyDescriptor; import org.apache.ivy.core.module.descriptor.ModuleDescriptor; import org.apache.ivy.core.module.id.ModuleId; @@ -52,6 +53,10 @@ public Module getModule() { return module; } + public boolean isInternalIntellijModuleDependency(Artifact artifact) { + return moduleDependencies.containsKey(artifact.getModuleRevisionId().getModuleId()); + } + public boolean isInternalIntellijModuleDependency(ModuleId moduleId) { return moduleDependencies.containsKey(moduleId); }