Skip to content

Commit

Permalink
Allow skipping downloads of artifacts that are actually other modules…
Browse files Browse the repository at this point in the history
… in the same project.
  • Loading branch information
guymahieu committed Nov 16, 2024
1 parent e13b9d6 commit de3f3f4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<grid id="27dc6" binding="projectSettingsPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="829" height="627"/>
<xy x="20" y="20" width="837" height="690"/>
</constraints>
<properties/>
<border type="none"/>
Expand Down Expand Up @@ -294,6 +294,17 @@
<toolTipText value="Uncheck this option if you want IvyIDEA to ignore internal module dependencies and just resolve all dependencies to external libraries"/>
</properties>
</component>
<component id="ba137" class="javax.swing.JCheckBox" binding="skipDownloadForInternalIntellijModules">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
<selected value="false"/>
<text value="Skip redundant download of artifacts for project modules"/>
<toolTipText value="Do not download artifacts that are actually other modules in this IntelliJ project as they would just be ignored."/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/org/clarent/ivyidea/resolve/DependencyResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
}
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit de3f3f4

Please sign in to comment.