44import java .util .HashMap ;
55import java .util .List ;
66import java .util .Map ;
7+ import java .util .Optional ;
78import java .util .Set ;
89import java .util .concurrent .Callable ;
910
1718import org .gradle .api .provider .SetProperty ;
1819import org .gradle .api .tasks .util .PatternFilterable ;
1920import org .gradle .api .tasks .util .PatternSet ;
21+ import org .gradle .nativeplatform .BuildType ;
22+ import org .gradle .nativeplatform .platform .NativePlatform ;
2023
2124import edu .wpi .first .nativeutils .NativeUtils ;
2225
2326public abstract class WPIMavenDependency implements NativeDependency {
2427 private final String name ;
2528 private final Project project ;
2629
30+ private final Map <NativePlatform , Map <BuildType , Optional <ResolvedNativeDependency >>> resolvedDependencies = new HashMap <>();
31+
32+ private Map <BuildType , Optional <ResolvedNativeDependency >> getInnerMap (NativePlatform platform ) {
33+ Map <BuildType , Optional <ResolvedNativeDependency >> buildTypeMap = resolvedDependencies .get (platform );
34+
35+ if (buildTypeMap == null ) {
36+ buildTypeMap = new HashMap <>();
37+ resolvedDependencies .put (platform , buildTypeMap );
38+ }
39+
40+ return buildTypeMap ;
41+ }
42+
43+ protected void addToCache (NativePlatform platform , BuildType buildType , Optional <ResolvedNativeDependency > dependency ) {
44+ Map <BuildType , Optional <ResolvedNativeDependency >> innerMap = getInnerMap (platform );
45+ innerMap .put (buildType , dependency );
46+ }
47+
48+ protected Optional <ResolvedNativeDependency > tryFromCache (NativePlatform platform , BuildType buildType ) {
49+ Map <BuildType , Optional <ResolvedNativeDependency >> innerMap = getInnerMap (platform );
50+ return innerMap .getOrDefault (buildType , Optional .empty ());
51+ }
52+
2753 @ Inject
2854 public WPIMavenDependency (String name , Project project ) {
2955 this .name = name ;
@@ -42,7 +68,7 @@ private static class ViewConfigurationContainer {
4268
4369 private final Map <String , ViewConfigurationContainer > classifierViewMap = new HashMap <>();
4470
45- protected FileCollection getArtifactRoots (String classifier , ArtifactType type , FastDownloadDependencySet loaderDependencySet ) {
71+ protected FileCollection getArtifactRoots (String classifier , ArtifactType type , Optional < FastDownloadDependencySet > loaderDependencySet ) {
4672 if (classifier == null ) {
4773 return project .files ();
4874 }
@@ -52,7 +78,7 @@ protected FileCollection getArtifactRoots(String classifier, ArtifactType type,
5278 }
5379
5480 protected FileCollection getArtifactFiles (String targetPlatform , String buildType , List <String > matches ,
55- List <String > excludes , ArtifactType type , FastDownloadDependencySet loaderDependencySet ) {
81+ List <String > excludes , ArtifactType type , Optional < FastDownloadDependencySet > loaderDependencySet ) {
5682 buildType = buildType .equalsIgnoreCase ("debug" ) ? "debug" : "" ;
5783 ArtifactView view = getViewForArtifact (targetPlatform + buildType , type , loaderDependencySet );
5884 PatternFilterable filterable = new PatternSet ();
@@ -62,16 +88,20 @@ protected FileCollection getArtifactFiles(String targetPlatform, String buildTyp
6288 return project .files (cbl );
6389 }
6490
65- protected ArtifactView getViewForArtifact (String classifier , ArtifactType type , FastDownloadDependencySet loaderDependencySet ) {
91+ protected ArtifactView getViewForArtifact (String classifier , ArtifactType type , Optional < FastDownloadDependencySet > loaderDependencySet ) {
6692 ViewConfigurationContainer viewContainer = classifierViewMap .get (classifier );
6793 String configName = name + "_" + classifier ;
6894 if (viewContainer != null ) {
69- loaderDependencySet .addConfiguration (type , viewContainer .configuration );
95+ if (loaderDependencySet .isPresent ()) {
96+ loaderDependencySet .get ().addConfiguration (type , viewContainer .configuration );
97+ }
7098 return viewContainer .view ;
7199 }
72-
100+
73101 Configuration cfg = project .getConfigurations ().create (configName );
74- loaderDependencySet .addConfiguration (type , cfg );
102+ if (loaderDependencySet .isPresent ()) {
103+ loaderDependencySet .get ().addConfiguration (type , cfg );
104+ }
75105 String dep = getGroupId ().get () + ":" + getArtifactId ().get () + ":" + getVersion ().get () + ":" + classifier
76106 + "@" + getExt ().get ();
77107 project .getDependencies ().add (configName , dep );
0 commit comments