Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,17 @@
package org.gradle.plugins.ide

import org.gradle.integtests.fixtures.ToBeFixedForInstantExecution
import org.gradle.integtests.fixtures.executer.GradleContextualExecuter
import org.gradle.test.fixtures.file.TestFile
import org.gradle.test.fixtures.server.http.HttpArtifact
import org.gradle.test.fixtures.server.http.HttpServer
import org.gradle.test.fixtures.server.http.IvyHttpModule
import org.gradle.test.fixtures.server.http.IvyHttpRepository
import org.gradle.test.fixtures.server.http.MavenHttpRepository
import org.junit.Rule
import spock.lang.IgnoreIf

abstract class AbstractSourcesAndJavadocJarsIntegrationTest extends AbstractIdeIntegrationSpec {
@Rule
HttpServer server

String groovyAllVersion = "1.3-2.5.8"

def setup() {
server.start()
executer.requireOwnGradleUserHomeDir()
Expand Down Expand Up @@ -304,193 +299,6 @@ dependencies {
ideFileContainsEntry("module-1.0.jar", "module-1.0-sources.jar", "module-1.0-javadoc.jar")
}

@ToBeFixedForInstantExecution
@IgnoreIf({ GradleContextualExecuter.noDaemon })
def "does not download gradleApi() sources when sources download is disabled"() {
given:
requireGradleDistribution()
executer.withEnvironmentVars('GRADLE_REPO_OVERRIDE': "$server.uri/")

buildScript """
apply plugin: "java"
apply plugin: "idea"
apply plugin: "eclipse"

dependencies {
implementation gradleApi()
}

idea.module.downloadSources = false
eclipse.classpath.downloadSources = false
"""
when:
succeeds ideTask

then:
assertSourcesDirectoryDoesNotExistInDistribution()
ideFileContainsGradleApi("gradle-api")
}

@ToBeFixedForInstantExecution
@IgnoreIf({ GradleContextualExecuter.noDaemon })
def "does not download gradleApi() sources when offline"() {
given:
requireGradleDistribution()
executer.withEnvironmentVars('GRADLE_REPO_OVERRIDE': "$server.uri/")

buildScript """
apply plugin: "java"
apply plugin: "idea"
apply plugin: "eclipse"

dependencies {
implementation gradleApi()
}
"""
when:
args("--offline")
succeeds ideTask

then:
assertSourcesDirectoryDoesNotExistInDistribution()
ideFileContainsGradleApi("gradle-api")
}

@ToBeFixedForInstantExecution
def "sources for localGroovy() are downloaded and attached"() {
given:
def repo = givenGroovyAllExistsInGradleRepo()
executer.withEnvironmentVars('GRADLE_LIBS_REPO_OVERRIDE': "$repo.uri/")

buildScript """
apply plugin: "java"
apply plugin: "idea"
apply plugin: "eclipse"

dependencies {
implementation localGroovy()
}
"""

when:
succeeds ideTask

then:
ideFileContainsEntry("groovy-all-${groovyAllVersion}.jar", ["groovy-all-${groovyAllVersion}-sources.jar"], [])
}

@ToBeFixedForInstantExecution
def "sources for localGroovy() are downloaded and attached when using gradleApi()"() {
given:
def repo = givenGroovyAllExistsInGradleRepo()
executer.withEnvironmentVars('GRADLE_LIBS_REPO_OVERRIDE': "$repo.uri/")

buildScript """
apply plugin: "java"
apply plugin: "idea"
apply plugin: "eclipse"

dependencies {
implementation gradleApi()
}
"""

when:
succeeds ideTask

then:
ideFileContainsEntry("groovy-all-${groovyAllVersion}.jar", ["groovy-all-${groovyAllVersion}-sources.jar"], [])
}

@ToBeFixedForInstantExecution
def "sources for localGroovy() are downloaded and attached when using gradleTestKit()"() {
given:
requireGradleDistribution()
def repo = givenGroovyAllExistsInGradleRepo()
executer.withEnvironmentVars('GRADLE_LIBS_REPO_OVERRIDE': "$repo.uri/")

buildScript """
apply plugin: "java"
apply plugin: "idea"
apply plugin: "eclipse"

dependencies {
implementation gradleTestKit()
}
"""

when:
succeeds ideTask

then:
ideFileContainsEntry("groovy-all-${groovyAllVersion}.jar", ["groovy-all-${groovyAllVersion}-sources.jar"], [])
}

@ToBeFixedForInstantExecution
def "does not download localGroovy() sources when sources download is disabled"() {
given:
executer.withEnvironmentVars('GRADLE_LIBS_REPO_OVERRIDE': "$server.uri/")

buildScript """
apply plugin: "java"
apply plugin: "idea"
apply plugin: "eclipse"

dependencies {
implementation localGroovy()
}

idea.module.downloadSources = false
eclipse.classpath.downloadSources = false
"""

when:
succeeds ideTask

then:
ideFileContainsNoSourcesAndJavadocEntry()
}

@ToBeFixedForInstantExecution
def "does not download localGroovy() sources when offline"() {
given:
executer.withEnvironmentVars('GRADLE_LIBS_REPO_OVERRIDE': "$server.uri/")

buildScript """
apply plugin: "java"
apply plugin: "idea"
apply plugin: "eclipse"

dependencies {
implementation localGroovy()
}
"""

when:
args("--offline")
succeeds ideTask

then:
ideFileContainsNoSourcesAndJavadocEntry()
}

void assertSourcesDirectoryDoesNotExistInDistribution() {
gradleDistributionSrcDir().assertDoesNotExist()
}

private TestFile gradleDistributionSrcDir() {
return new TestFile(distribution.gradleHomeDir, "src")
}

def givenGroovyAllExistsInGradleRepo() {
def repo = mavenHttpRepo
def module = repo.module("org.gradle.groovy", "groovy-all", groovyAllVersion)
module.artifact(classifier: "sources")
module.publish()
module.allowAll()
return repo
}

private useIvyRepo(def repo) {
buildFile << """repositories { ivy { url "$repo.uri" } }"""
}
Expand Down Expand Up @@ -555,8 +363,6 @@ task resolve {

abstract void ideFileContainsEntry(String jar, List<String> sources, List<String> javadoc)

abstract void ideFileContainsGradleApi(String apiJarPrefix)

abstract void ideFileContainsNoSourcesAndJavadocEntry()

abstract void expectBehaviorAfterBrokenMavenArtifact(HttpArtifact httpArtifact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ class EclipseSourcesAndJavadocJarsIntegrationTest extends AbstractSourcesAndJava
}
}

@Override
void ideFileContainsGradleApi(String apiJarPrefix) {
def apiLib = findApiLibrary(apiJarPrefix)
assert apiLib.sourcePath == null
}

EclipseClasspathFixture.EclipseLibrary findApiLibrary(String apiJarPrefix) {
def classpath = EclipseClasspathFixture.create(testDirectory, executer.gradleUserHomeDir)
def libs = classpath.libs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ class IdeaSourcesAndJavadocJarsIntegrationTest extends AbstractSourcesAndJavadoc
libraryEntry.assertHasJavadoc(javadocs)
}

@Override
void ideFileContainsGradleApi(String apiJarPrefix) {
def libraryEntry = findApiLibrary(apiJarPrefix)
assert libraryEntry.source.empty
}

IdeaModuleFixture.ImlModuleLibrary findApiLibrary(String apiJarPrefix) {
IdeaModuleFixture iml = parseIml("root.iml")
def libraryEntry = iml.dependencies.libraries.find { it.jarName.startsWith(apiJarPrefix) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.gradle.plugins.ide.eclipse.model.internal.ClasspathFactory;
import org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory;
import org.gradle.plugins.ide.internal.IdeArtifactRegistry;
import org.gradle.plugins.ide.internal.resolver.DefaultGradleApiSourcesResolver;
import org.gradle.util.ConfigureUtil;

import javax.inject.Inject;
Expand Down Expand Up @@ -323,7 +322,7 @@ public List<ClasspathEntry> resolveDependencies() {
ProjectInternal projectInternal = (ProjectInternal) this.project;
IdeArtifactRegistry ideArtifactRegistry = projectInternal.getServices().get(IdeArtifactRegistry.class);
ProjectStateRegistry projectRegistry = projectInternal.getServices().get(ProjectStateRegistry.class);
ClasspathFactory classpathFactory = new ClasspathFactory(this, ideArtifactRegistry, projectRegistry, new DefaultGradleApiSourcesResolver(project));
ClasspathFactory classpathFactory = new ClasspathFactory(this, ideArtifactRegistry, projectRegistry);
return classpathFactory.createEntries();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.gradle.plugins.ide.eclipse.model.Output;
import org.gradle.plugins.ide.eclipse.model.SourceFolder;
import org.gradle.plugins.ide.internal.IdeArtifactRegistry;
import org.gradle.plugins.ide.internal.resolver.GradleApiSourcesResolver;

import java.util.Collections;
import java.util.List;
Expand All @@ -35,9 +34,9 @@ public class ClasspathFactory {
private final EclipseClasspath classpath;
private final EclipseDependenciesCreator dependenciesCreator;

public ClasspathFactory(EclipseClasspath classpath, IdeArtifactRegistry ideArtifactRegistry, ProjectStateRegistry projectRegistry, GradleApiSourcesResolver gradleApiSourcesResolver) {
public ClasspathFactory(EclipseClasspath classpath, IdeArtifactRegistry ideArtifactRegistry, ProjectStateRegistry projectRegistry) {
this.classpath = classpath;
this.dependenciesCreator = new EclipseDependenciesCreator(classpath, ideArtifactRegistry, projectRegistry, gradleApiSourcesResolver);
this.dependenciesCreator = new EclipseDependenciesCreator(classpath, ideArtifactRegistry, projectRegistry);
}

public List<ClasspathEntry> createEntries() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.gradle.plugins.ide.internal.IdeArtifactRegistry;
import org.gradle.plugins.ide.internal.resolver.IdeDependencySet;
import org.gradle.plugins.ide.internal.resolver.IdeDependencyVisitor;
import org.gradle.plugins.ide.internal.resolver.GradleApiSourcesResolver;
import org.gradle.plugins.ide.internal.resolver.UnresolvedIdeDependencyHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -57,18 +56,16 @@ public class EclipseDependenciesCreator {
private final EclipseClasspath classpath;
private final ProjectDependencyBuilder projectDependencyBuilder;
private final ProjectComponentIdentifier currentProjectId;
private final GradleApiSourcesResolver gradleApiSourcesResolver;

public EclipseDependenciesCreator(EclipseClasspath classpath, IdeArtifactRegistry ideArtifactRegistry, ProjectStateRegistry projectRegistry, GradleApiSourcesResolver gradleApiSourcesResolver) {
public EclipseDependenciesCreator(EclipseClasspath classpath, IdeArtifactRegistry ideArtifactRegistry, ProjectStateRegistry projectRegistry) {
this.classpath = classpath;
this.projectDependencyBuilder = new ProjectDependencyBuilder(ideArtifactRegistry);
this.currentProjectId = projectRegistry.stateFor(classpath.getProject()).getComponentIdentifier();
this.gradleApiSourcesResolver = gradleApiSourcesResolver;
}

public List<AbstractClasspathEntry> createDependencyEntries() {
EclipseDependenciesVisitor visitor = new EclipseDependenciesVisitor(classpath.getProject());
new IdeDependencySet(classpath.getProject().getDependencies(), classpath.getPlusConfigurations(), classpath.getMinusConfigurations(), gradleApiSourcesResolver).visit(visitor);
new IdeDependencySet(classpath.getProject().getDependencies(), classpath.getPlusConfigurations(), classpath.getMinusConfigurations()).visit(visitor);
return visitor.getDependencies();
}

Expand Down Expand Up @@ -129,11 +126,6 @@ public void visitFileDependency(ResolvedArtifactResult artifact, boolean testDep
files.add(createLibraryEntry(artifact.getFile(), null, null, classpath, null, pathToSourceSets, testDependency));
}

@Override
public void visitGradleApiDependency(ResolvedArtifactResult artifact, File sources, boolean testConfiguration) {
files.add(createLibraryEntry(artifact.getFile(), sources, null, classpath, null, pathToSourceSets, testConfiguration));
}

@Override
public void visitUnresolvedDependency(UnresolvedDependencyResult unresolvedDependency) {
File unresolvedFile = unresolvedIdeDependencyHandler.asFile(unresolvedDependency, project.getProjectDir());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.gradle.plugins.ide.eclipse.model.ProjectDependency;
import org.gradle.plugins.ide.internal.resolver.IdeDependencySet;
import org.gradle.plugins.ide.internal.resolver.IdeDependencyVisitor;
import org.gradle.plugins.ide.internal.resolver.NullGradleApiSourcesResolver;

import java.io.File;
import java.util.Collections;
Expand All @@ -62,7 +61,7 @@ public WtpClasspathAttributeSupport(Project project, EclipseModel model) {

private static Set<File> collectFilesFromConfigs(EclipseClasspath classpath, Set<Configuration> configs, Set<Configuration> minusConfigs) {
WtpClasspathAttributeDependencyVisitor visitor = new WtpClasspathAttributeDependencyVisitor(classpath);
new IdeDependencySet(classpath.getProject().getDependencies(), configs, minusConfigs, NullGradleApiSourcesResolver.INSTANCE).visit(visitor);
new IdeDependencySet(classpath.getProject().getDependencies(), configs, minusConfigs).visit(visitor);
return visitor.getFiles();
}

Expand Down Expand Up @@ -149,11 +148,6 @@ public void visitFileDependency(ResolvedArtifactResult artifact, boolean testDep
files.add(artifact.getFile());
}

@Override
public void visitGradleApiDependency(ResolvedArtifactResult artifact, File sources, boolean testDependency) {
files.add(artifact.getFile());
}

public Set<File> getFiles() {
return files;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.gradle.plugins.ide.internal.resolver.IdeDependencySet;
import org.gradle.plugins.ide.internal.resolver.IdeDependencyVisitor;
import org.gradle.plugins.ide.internal.resolver.UnresolvedIdeDependencyHandler;
import org.gradle.plugins.ide.internal.resolver.NullGradleApiSourcesResolver;

import java.io.File;
import java.util.Collections;
Expand Down Expand Up @@ -87,7 +86,7 @@ private List<WbResource> getEntriesFromSourceDirs(EclipseWtpComponent wtp) {

private List<WbDependentModule> getEntriesFromConfigurations(Project project, Set<Configuration> plusConfigurations, Set<Configuration> minusConfigurations, EclipseWtpComponent wtp, String deployPath) {
WtpDependenciesVisitor visitor = new WtpDependenciesVisitor(project, wtp, deployPath);
new IdeDependencySet(project.getDependencies(), plusConfigurations, minusConfigurations, NullGradleApiSourcesResolver.INSTANCE).visit(visitor);
new IdeDependencySet(project.getDependencies(), plusConfigurations, minusConfigurations).visit(visitor);
return visitor.getEntries();
}

Expand Down Expand Up @@ -149,11 +148,6 @@ public void visitFileDependency(ResolvedArtifactResult artifact, boolean testDep
}
}

@Override
public void visitGradleApiDependency(ResolvedArtifactResult artifact, File sources, boolean testDependency) {
visitFileDependency(artifact, testDependency);
}

@Override
public void visitUnresolvedDependency(UnresolvedDependencyResult unresolvedDependency) {
unresolvedIdeDependencyHandler.log(unresolvedDependency);
Expand Down
Loading