-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
176 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../netflix/nebula/dependency/recommender/OnlyReccomendIfFirstOrderWithoutVersionExists.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package netflix.nebula.dependency.recommender; | ||
|
||
import org.gradle.api.artifacts.Dependency; | ||
import org.gradle.api.artifacts.DependencyResolveDetails; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class OnlyReccomendIfFirstOrderWithoutVersionExists extends RecommendationStrategy { | ||
|
||
private List<String> firstOrderDepsWithoutVersions = new ArrayList<>(); | ||
|
||
@Override | ||
public void inspectDependency(Dependency dependency) { | ||
if (dependency.getVersion() == null || dependency.getVersion().isEmpty()) { | ||
firstOrderDepsWithoutVersions.add(dependency.getGroup() + ":" + dependency.getName()); | ||
} | ||
} | ||
|
||
@Override | ||
public void recommendVersion(DependencyResolveDetails details, String version) { | ||
if (version != null && firstOrderDepsWithoutVersions.contains(getCoord(details))) { | ||
details.useVersion(version); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...y/netflix/nebula/dependency/recommender/OnlyReccomendIfNoFirstOrderWithVersionExists.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package netflix.nebula.dependency.recommender; | ||
|
||
import org.gradle.api.artifacts.Dependency; | ||
import org.gradle.api.artifacts.DependencyResolveDetails; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class OnlyReccomendIfNoFirstOrderWithVersionExists extends RecommendationStrategy { | ||
|
||
private List<String> firstOrderDepsWithVersions = new ArrayList<>(); | ||
|
||
@Override | ||
public void inspectDependency(Dependency dependency) { | ||
if (dependency.getVersion() != null && !dependency.getVersion().isEmpty()) { | ||
firstOrderDepsWithVersions.add(dependency.getGroup() + ":" + dependency.getName()); | ||
} | ||
} | ||
|
||
@Override | ||
public void recommendVersion(DependencyResolveDetails details, String version) { | ||
if (version != null && !firstOrderDepsWithVersions.contains(getCoord(details))) { | ||
details.useVersion(version); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/groovy/netflix/nebula/dependency/recommender/RecommendationStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package netflix.nebula.dependency.recommender; | ||
|
||
import org.gradle.api.artifacts.Dependency; | ||
import org.gradle.api.artifacts.DependencyResolveDetails; | ||
import org.gradle.api.artifacts.ModuleVersionSelector; | ||
|
||
/** | ||
* Defines in which cases recommendations are applied | ||
*/ | ||
public abstract class RecommendationStrategy { | ||
|
||
/** | ||
* This hook is called for each dependency in a project. It collects the dependencies we are interested in for determining if a recommendation should be applied. | ||
* @param dependency the dependency to inspect. | ||
*/ | ||
public abstract void inspectDependency(Dependency dependency); | ||
|
||
/** | ||
* Puts the recommended version on details.useVersion depending on the strategy used. | ||
* @param details the details to recommend a version for | ||
* @param version the version to be potentially recommended for the requested artifact. | ||
*/ | ||
public abstract void recommendVersion(DependencyResolveDetails details, String version); | ||
|
||
/** | ||
* @param details the details to get coordinates from | ||
* @return the coordinates in the form of "<group>:<name>", taken from details.requested. | ||
*/ | ||
protected String getCoord(DependencyResolveDetails details) { | ||
ModuleVersionSelector requested = details.getRequested(); | ||
return requested.getGroup() + ":" + requested.getName(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/groovy/netflix/nebula/dependency/recommender/RecommendationStrategyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package netflix.nebula.dependency.recommender; | ||
|
||
import netflix.nebula.dependency.recommender.provider.RecommendationProviderContainer; | ||
import org.gradle.api.Project; | ||
|
||
/** | ||
* Creates RecommendationStrategy lazily on demand and caches it. | ||
* This is used to allow for scoped recommendationStrategies (e.g. per configuration as in DependencyRecommendationsPlugin) | ||
*/ | ||
public class RecommendationStrategyFactory { | ||
private final Project project; | ||
private RecommendationStrategy recommendationStrategy; | ||
|
||
public RecommendationStrategyFactory(Project project) { | ||
this.project = project; | ||
} | ||
|
||
public RecommendationStrategy getRecommendationStrategy() { | ||
if(recommendationStrategy == null) { | ||
try { | ||
RecommendationProviderContainer recommendationProviderContainer = project.getExtensions().getByType(RecommendationProviderContainer.class); | ||
recommendationStrategy = recommendationProviderContainer.getRecommendationStrategy().newInstance(); | ||
} catch (Exception e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
return recommendationStrategy; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters