Skip to content

Commit

Permalink
Merge 2f603d3 into fa19ad8
Browse files Browse the repository at this point in the history
  • Loading branch information
sghill committed Jul 27, 2018
2 parents fa19ad8 + 2f603d3 commit bfd3243
Show file tree
Hide file tree
Showing 8 changed files with 461 additions and 62 deletions.
8 changes: 1 addition & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ contacts {
}
}

repositories {
jcenter()
maven { url 'https://jitpack.io' } // for xmlunit2
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // for xmlunit2
}

dependencies {
compile 'com.netflix.nebula:nebula-gradle-interop:latest.release'
compile 'org.apache.maven:maven-model-builder:3.+'
testCompile('com.netflix.nebula:nebula-test:latest.release')
testCompile('com.github.xmlunit:xmlunit:7ed02fb294') {
testCompile ('org.xmlunit:xmlunit-core:2.6.0') {
exclude module: 'hamcrest-core'
}
}
Expand Down
90 changes: 45 additions & 45 deletions dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
}
},
Expand All @@ -15,7 +15,7 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
}
},
Expand All @@ -25,15 +25,11 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
}
},
"integTestCompile": {
"com.github.xmlunit:xmlunit": {
"locked": "7ed02fb294",
"requested": "7ed02fb294"
},
"com.netflix.nebula:nebula-gradle-interop": {
"locked": "0.5.0",
"requested": "latest.release"
Expand All @@ -43,15 +39,15 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
},
"org.xmlunit:xmlunit-core": {
"locked": "2.6.0",
"requested": "2.6.0"
}
},
"integTestCompileClasspath": {
"com.github.xmlunit:xmlunit": {
"locked": "7ed02fb294",
"requested": "7ed02fb294"
},
"com.netflix.nebula:nebula-gradle-interop": {
"locked": "0.5.0",
"requested": "latest.release"
Expand All @@ -61,15 +57,15 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
},
"org.xmlunit:xmlunit-core": {
"locked": "2.6.0",
"requested": "2.6.0"
}
},
"integTestRuntime": {
"com.github.xmlunit:xmlunit": {
"locked": "7ed02fb294",
"requested": "7ed02fb294"
},
"com.netflix.nebula:nebula-gradle-interop": {
"locked": "0.5.0",
"requested": "latest.release"
Expand All @@ -79,15 +75,15 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
},
"org.xmlunit:xmlunit-core": {
"locked": "2.6.0",
"requested": "2.6.0"
}
},
"integTestRuntimeClasspath": {
"com.github.xmlunit:xmlunit": {
"locked": "7ed02fb294",
"requested": "7ed02fb294"
},
"com.netflix.nebula:nebula-gradle-interop": {
"locked": "0.5.0",
"requested": "latest.release"
Expand All @@ -97,8 +93,12 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
},
"org.xmlunit:xmlunit-core": {
"locked": "2.6.0",
"requested": "2.6.0"
}
},
"jacocoAgent": {
Expand All @@ -117,7 +117,7 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
}
},
Expand All @@ -127,15 +127,11 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
}
},
"testCompile": {
"com.github.xmlunit:xmlunit": {
"locked": "7ed02fb294",
"requested": "7ed02fb294"
},
"com.netflix.nebula:nebula-gradle-interop": {
"locked": "0.5.0",
"requested": "latest.release"
Expand All @@ -145,15 +141,15 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
},
"org.xmlunit:xmlunit-core": {
"locked": "2.6.0",
"requested": "2.6.0"
}
},
"testCompileClasspath": {
"com.github.xmlunit:xmlunit": {
"locked": "7ed02fb294",
"requested": "7ed02fb294"
},
"com.netflix.nebula:nebula-gradle-interop": {
"locked": "0.5.0",
"requested": "latest.release"
Expand All @@ -163,15 +159,15 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
},
"org.xmlunit:xmlunit-core": {
"locked": "2.6.0",
"requested": "2.6.0"
}
},
"testRuntime": {
"com.github.xmlunit:xmlunit": {
"locked": "7ed02fb294",
"requested": "7ed02fb294"
},
"com.netflix.nebula:nebula-gradle-interop": {
"locked": "0.5.0",
"requested": "latest.release"
Expand All @@ -181,15 +177,15 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
},
"org.xmlunit:xmlunit-core": {
"locked": "2.6.0",
"requested": "2.6.0"
}
},
"testRuntimeClasspath": {
"com.github.xmlunit:xmlunit": {
"locked": "7ed02fb294",
"requested": "7ed02fb294"
},
"com.netflix.nebula:nebula-gradle-interop": {
"locked": "0.5.0",
"requested": "latest.release"
Expand All @@ -199,8 +195,12 @@
"requested": "latest.release"
},
"org.apache.maven:maven-model-builder": {
"locked": "3.5.2",
"locked": "3.5.4",
"requested": "3.+"
},
"org.xmlunit:xmlunit-core": {
"locked": "2.6.0",
"requested": "2.6.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,39 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class DependencyRecommendationsPlugin implements Plugin<Project> {
public static final String NEBULA_RECOMMENDER_BOM = "nebulaRecommenderBom";
public static final boolean CORE_BOM_SUPPORT_ENABLED = Boolean.getBoolean("nebula.features.coreBomSupport");
private Logger logger = Logging.getLogger(DependencyRecommendationsPlugin.class);
private RecommendationProviderContainer recommendationProviderContainer;

@Override
public void apply(final Project project) {
project.getConfigurations().create(NEBULA_RECOMMENDER_BOM);
Configuration bomConfiguration = project.getConfigurations().create(NEBULA_RECOMMENDER_BOM);
recommendationProviderContainer = project.getExtensions().create("dependencyRecommendations", RecommendationProviderContainer.class, project);
applyRecommendations(project);
enhanceDependenciesWithRecommender(project);
enhancePublicationsWithBomProducer(project);

if (CORE_BOM_SUPPORT_ENABLED) {
logger.warn("coreBomSupport feature enabled");
recommendationProviderContainer.excludeConfigurations("archives", NEBULA_RECOMMENDER_BOM, "provided");
applyRecommendationsDirectly(project, bomConfiguration);
} else {
applyRecommendations(project);
enhanceDependenciesWithRecommender(project);
enhancePublicationsWithBomProducer(project);
}
}

private void applyRecommendationsDirectly(final Project project, final Configuration bomConfiguration) {
final Set<String> excluded = recommendationProviderContainer.getExcludedConfigurations();
project.getConfigurations().all(new ExtendRecommenderConfigurationAction(bomConfiguration, excluded, project));
project.subprojects(new Action<Project>() {
@Override
public void execute(Project sub) {
sub.getConfigurations().all(new ExtendRecommenderConfigurationAction(bomConfiguration, excluded, sub));
}
});
}

private void applyRecommendations(final Project project) {
Expand All @@ -66,7 +86,7 @@ public void execute(final Configuration conf) {
ConfigurationsKt.onResolve(conf, new Function1<ResolvableDependencies, Unit>() {
@Override
public Unit invoke(ResolvableDependencies resolvableDependencies) {
if(recommendationProviderContainer.getExcludedConfigurations().contains(conf.getName())) {
if (recommendationProviderContainer.getExcludedConfigurations().contains(conf.getName())) {
return Unit.INSTANCE;
}

Expand Down Expand Up @@ -167,7 +187,7 @@ protected void enhancePublicationsWithBomProducer(Project project) {
/**
* Look for recommended versions in a project and each of its ancestors in order until one is found or the root is reached
*
* @param project the gradle <code>Project</code>
* @param project the gradle <code>Project</code>
* @param mvSelector the module to lookup
* @return the recommended version or <code>null</code>
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package netflix.nebula.dependency.recommender;

import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;

import java.util.Set;

public class ExtendRecommenderConfigurationAction implements Action<Configuration> {
private final Configuration bom;
private final Set<String> excludedConfigurationNames;
private final Project project;

public ExtendRecommenderConfigurationAction(Configuration bom, Set<String> excludedConfigurationNames, Project project) {
this.bom = bom;
this.excludedConfigurationNames = excludedConfigurationNames;
this.project = project;
}

@Override
public void execute(Configuration files) {
if (excludedConfigurationNames.contains(files.getName())) {
return;
}
Configuration toExtend = bom;
if (!project.getRootProject().equals(project)) {
toExtend = bom.copy();
toExtend.setVisible(false);
project.getConfigurations().add(toExtend);
}
files.extendsFrom(toExtend);
}
}
Loading

0 comments on commit bfd3243

Please sign in to comment.