13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- package io .micrometer .release .single ;
17
-
18
- import io .micrometer .release .common .ProcessRunner ;
19
-
20
- import java .util .concurrent .atomic .AtomicReference ;
16
+ package io .micrometer .release .common ;
21
17
22
18
import org .slf4j .Logger ;
23
19
import org .slf4j .LoggerFactory ;
24
20
25
- import java .util .ArrayList ;
26
- import java .util .HashSet ;
27
- import java .util .List ;
28
- import java .util .Set ;
21
+ import java .util .*;
22
+ import java .util .concurrent .ConcurrentHashMap ;
29
23
30
- class GradleParser {
24
+ public class GradleParser {
31
25
32
26
private static final Logger log = LoggerFactory .getLogger (GradleParser .class );
33
27
34
- private final List <String > excludedDependencyScopes = List .of ("testCompile" , "testImplementation" , "checkstyle" ,
35
- "runtime" , "nohttp" , "testRuntime" , "optional" );
36
-
37
- private final AtomicReference <Set <Dependency >> dependenciesCache = new AtomicReference <>();
28
+ private final List <String > excludedDependencyScopes = List .of ("testCompile" ,
29
+ "testImplementation" , "checkstyle" ,
30
+ "runtime" , "nohttp" , "testRuntime" , "optional" );
38
31
39
32
private final ProcessRunner processRunner ;
40
33
41
- GradleParser (ProcessRunner processRunner ) {
34
+ public GradleParser (ProcessRunner processRunner ) {
42
35
this .processRunner = processRunner ;
43
36
}
44
37
45
- Set <Dependency > fetchAllDependencies () {
46
- Set <Dependency > cachedDependencies = dependenciesCache .get ();
47
- if (cachedDependencies != null ) {
48
- log .info ("Returned cached dependencies" );
49
- return cachedDependencies ;
50
- }
38
+ public Set <Dependency > fetchAllDependencies () {
51
39
log .info ("Fetching test and optional dependencies..." );
52
40
List <String > projectLines = projectLines ();
53
41
List <String > subprojects = projectLines .stream ()
@@ -72,36 +60,32 @@ Set<Dependency> fetchAllDependencies() {
72
60
boolean finalTestOrOptional = testOrOptional ;
73
61
dependencies .stream ()
74
62
.filter (dependency -> dependency .group ().equalsIgnoreCase (parts [1 ])
75
- && dependency .artifact ().equalsIgnoreCase (parts [2 ]))
63
+ && dependency .artifact ().equalsIgnoreCase (parts [2 ]))
76
64
.findFirst ()
77
65
.ifPresentOrElse (dependency -> {
78
- log .debug ("Dependency {} is already present in compile scope" , parts [1 ] + ":" + parts [2 ]);
66
+ log .debug ("Dependency {} is already present in compile scope" ,
67
+ parts [1 ] + ":" + parts [2 ]);
79
68
if (dependency .toIgnore () && !finalTestOrOptional ) {
80
69
log .debug (
81
- "Dependency {} was previously set in test or compile scope and will be in favour of one in compile scope" ,
82
- dependency );
70
+ "Dependency {} was previously set in test or compile scope and will be in favour of one in compile scope" ,
71
+ dependency );
83
72
dependencies .remove (dependency );
84
- dependencies .add (new Dependency (parts [1 ], parts [2 ], version , finalTestOrOptional ));
73
+ dependencies .add (new Dependency (parts [1 ], parts [2 ], version ,
74
+ finalTestOrOptional ));
85
75
}
86
- }, () -> dependencies .add (new Dependency ( parts [ 1 ], parts [ 2 ], version , finalTestOrOptional )));
87
- }
88
- else if (excludedDependencyScopes .stream ()
76
+ }, () -> dependencies .add (
77
+ new Dependency ( parts [ 1 ], parts [ 2 ], version , finalTestOrOptional )));
78
+ } else if (excludedDependencyScopes .stream ()
89
79
.anyMatch (string -> line .toLowerCase ().contains (string .toLowerCase ()))) {
90
80
testOrOptional = true ;
91
- }
92
- else if (line .isEmpty () || line .isBlank ()) {
81
+ } else if (line .isEmpty () || line .isBlank ()) {
93
82
testOrOptional = false ;
94
83
}
95
84
}
96
85
}
97
- dependenciesCache .set (dependencies );
98
86
return dependencies ;
99
87
}
100
88
101
- void clearCache () {
102
- dependenciesCache .set (null );
103
- }
104
-
105
89
static String extractVersion (String line ) {
106
90
if (line == null || line .trim ().isEmpty ()) {
107
91
return null ;
@@ -123,11 +107,11 @@ static String extractVersion(String line) {
123
107
return null ;
124
108
}
125
109
126
- List <String > dependenciesLines (List <String > gradleCommand ) {
110
+ public List <String > dependenciesLines (List <String > gradleCommand ) {
127
111
return processRunner .runSilently (gradleCommand );
128
112
}
129
113
130
- List <String > projectLines () {
114
+ public List <String > projectLines () {
131
115
return processRunner .runSilently ("./gradlew" , "projects" );
132
116
}
133
117
0 commit comments