Skip to content

Commit

Permalink
Add logging to determine which recommendation module was selected, wh…
Browse files Browse the repository at this point in the history
…en recommendations are advising version
  • Loading branch information
jkschneider committed Dec 3, 2015
1 parent bc91e4d commit 6a0615e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.*;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.plugins.ExtraPropertiesExtension;
import org.gradle.api.plugins.JavaPlugin;

import java.util.ArrayList;
import java.util.List;

public class DependencyRecommendationsPlugin implements Plugin<Project> {
private Logger logger = Logging.getLogger(DependencyRecommendationsPlugin.class);

@Override
public void apply(final Project project) {
project.getExtensions().create("dependencyRecommendations", RecommendationProviderContainer.class, project);
Expand Down Expand Up @@ -57,6 +61,7 @@ public void execute(DependencyResolveDetails details) {

String version = getRecommendedVersionRecursive(project, requested);
if (version != null && firstOrderDepsWithoutVersions.contains(coord)) {
logger.info("Recommending version " + version + " for dependency " + requested.getGroup() + ":" + requested.getName());
details.useVersion(version);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.internal.typeconversion.NotationConvertResult;

import java.io.File;
Expand All @@ -15,6 +18,7 @@

public abstract class FileBasedRecommendationProvider extends AbstractRecommendationProvider {
protected Project project;
private Logger logger = Logging.getLogger(FileBasedRecommendationProvider.class);

protected InputStreamProvider inputProvider = new InputStreamProvider() {
@Override
Expand Down Expand Up @@ -98,7 +102,11 @@ public InputStream getInputStream() throws Exception {
// create a temporary configuration to resolve the file
Configuration conf = project.getConfigurations().detachedConfiguration(
project.getDependencies().create(dependencyNotation));
return new FileInputStream(conf.resolve().iterator().next());

ResolvedArtifact artifactId = conf.getResolvedConfiguration().getResolvedArtifacts().iterator().next();
logger.info("Selected recommendation source " + artifactId.getId() + ", you requested " + dependencyNotation);

return new FileInputStream(artifactId.getFile());
}
};
return inputProvider;
Expand Down

0 comments on commit 6a0615e

Please sign in to comment.