mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[gradle][IDEA-275594] cleanup in AuxiliaryConfigurationArtifacts
GitOrigin-RevId: 7bdc214147f769bf681770f977a3b4f9cd9e7b30
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b7bd550d6a
commit
42e2e4c08a
@@ -19,8 +19,6 @@ import org.gradle.api.artifacts.result.ResolvedArtifactResult;
|
||||
import org.gradle.api.artifacts.result.ResolvedComponentResult;
|
||||
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
|
||||
import org.gradle.internal.resolve.ModuleVersionResolveException;
|
||||
import org.gradle.language.base.artifact.SourcesArtifact;
|
||||
import org.gradle.language.java.artifact.JavadocArtifact;
|
||||
import org.gradle.util.Path;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -258,11 +256,11 @@ public final class GradleDependencyResolver {
|
||||
libraryDependency.setFile(artifactFile);
|
||||
|
||||
ComponentIdentifier componentIdentifier = artifact.getId().getComponentIdentifier();
|
||||
File sourcesFile = auxiliaryArtifacts.getArtifact(componentIdentifier, artifactFile, SourcesArtifact.class);
|
||||
File sourcesFile = auxiliaryArtifacts.getSources(componentIdentifier, artifactFile);
|
||||
if (sourcesFile != null) {
|
||||
libraryDependency.setSource(sourcesFile);
|
||||
}
|
||||
File javadocFile = auxiliaryArtifacts.getArtifact(componentIdentifier, artifactFile, JavadocArtifact.class);
|
||||
File javadocFile = auxiliaryArtifacts.getJavadoc(componentIdentifier, artifactFile);
|
||||
if (javadocFile != null) {
|
||||
libraryDependency.setJavadoc(javadocFile);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
package com.intellij.gradle.toolingExtension.impl.model.dependencyModel.auxiliary;
|
||||
|
||||
import org.gradle.api.artifacts.component.ComponentIdentifier;
|
||||
import org.gradle.api.component.Artifact;
|
||||
import org.gradle.language.base.artifact.SourcesArtifact;
|
||||
import org.gradle.language.java.artifact.JavadocArtifact;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -31,28 +28,24 @@ public class AuxiliaryConfigurationArtifacts {
|
||||
this.javadocs = javadocs;
|
||||
}
|
||||
|
||||
public @Nullable File getArtifact(@NotNull ComponentIdentifier identifier,
|
||||
@NotNull File artifactFile,
|
||||
@NotNull Class<? extends Artifact> artifactType
|
||||
public @Nullable File getJavadoc(@NotNull ComponentIdentifier identifier,
|
||||
@NotNull File artifactFile
|
||||
) {
|
||||
Map<ComponentIdentifier, Set<File>> artifactSource = chooseArtifactSource(artifactType);
|
||||
Set<File> files = artifactSource.get(identifier);
|
||||
Set<File> files = javadocs.get(identifier);
|
||||
if (files == null) {
|
||||
return null;
|
||||
}
|
||||
return chooseAuxiliaryArtifactFile(artifactFile, files);
|
||||
}
|
||||
|
||||
private @NotNull Map<ComponentIdentifier, Set<File>> chooseArtifactSource(@NotNull Class<? extends Artifact> artifactType) {
|
||||
if (SourcesArtifact.class == artifactType) {
|
||||
return sources;
|
||||
}
|
||||
else if (JavadocArtifact.class == artifactType) {
|
||||
return javadocs;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unexpected artifact type was requested: " + artifactType.getCanonicalName());
|
||||
public @Nullable File getSources(@NotNull ComponentIdentifier identifier,
|
||||
@NotNull File artifactFile
|
||||
) {
|
||||
Set<File> files = sources.get(identifier);
|
||||
if (files == null) {
|
||||
return null;
|
||||
}
|
||||
return chooseAuxiliaryArtifactFile(artifactFile, files);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,13 +3,8 @@ package com.intellij.gradle.toolingExtension.impl.model.dependencyModel.auxiliar
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.gradle.api.artifacts.component.ComponentIdentifier
|
||||
import org.gradle.ivy.IvyDescriptorArtifact
|
||||
import org.gradle.language.base.artifact.SourcesArtifact
|
||||
import org.gradle.language.java.artifact.JavadocArtifact
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNull
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
@@ -28,13 +23,6 @@ class AuxiliaryConfigurationArtifactsTest {
|
||||
|
||||
private fun testFile(name: String) = File(tempDir, name)
|
||||
|
||||
@Test
|
||||
fun `choose artifact from empty container`() {
|
||||
val stub = AuxiliaryConfigurationArtifacts(emptyMap(), emptyMap())
|
||||
val main = testFile("foo-bar.jar")
|
||||
assertNull(stub.getArtifact(TestComponentIdentifier(), main, SourcesArtifact::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `choose javadoc artifact`() {
|
||||
val identifier = TestComponentIdentifier()
|
||||
@@ -47,7 +35,7 @@ class AuxiliaryConfigurationArtifactsTest {
|
||||
mapOf(identifier to setOf(javadoc))
|
||||
)
|
||||
|
||||
val file = stub.getArtifact(identifier, main, JavadocArtifact::class.java)
|
||||
val file = stub.getJavadoc(identifier, main)
|
||||
assertEquals(javadoc, file)
|
||||
}
|
||||
|
||||
@@ -63,19 +51,10 @@ class AuxiliaryConfigurationArtifactsTest {
|
||||
mapOf(identifier to setOf(javadoc))
|
||||
)
|
||||
|
||||
val file = stub.getArtifact(identifier, main, SourcesArtifact::class.java)
|
||||
val file = stub.getSources(identifier, main)
|
||||
assertEquals(sources, file)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `choose unsupported artifact`() {
|
||||
val stub = AuxiliaryConfigurationArtifacts(emptyMap(), emptyMap())
|
||||
val main = testFile("foo-bar.jar")
|
||||
assertThrows<IllegalArgumentException> {
|
||||
stub.getArtifact(TestComponentIdentifier(), main, IvyDescriptorArtifact::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `choose auxiliary artifact file when there is none to choose from`() {
|
||||
val main = testFile("foo-bar.jar")
|
||||
|
||||
Reference in New Issue
Block a user