2424import org .gradle .nativeplatform .toolchain .internal .metadata .CompilerMetaDataProvider ;
2525import org .gradle .nativeplatform .toolchain .internal .metadata .CompilerMetaDataProviderFactory ;
2626import org .gradle .platform .base .internal .toolchain .SearchResult ;
27+ import org .gradle .process .ExecOperations ;
2728import org .gradle .process .ExecSpec ;
2829import org .gradle .util .internal .VersionNumber ;
2930
@@ -36,19 +37,24 @@ public abstract class ToolchainDiscoverer implements Named {
3637 private final Function <String , String > composer ;
3738 private final ToolchainDescriptorBase descriptor ;
3839
39- public static ToolchainDiscoverer createDiscoverer (String name , ToolchainDescriptorBase descriptor , Provider <File > rootDir , Function <String , String > composer , Project project ) {
40+ public static ToolchainDiscoverer createDiscoverer (String name , ToolchainDescriptorBase descriptor ,
41+ Provider <File > rootDir , Function <String , String > composer , Project project ) {
4042 return project .getObjects ().newInstance (ToolchainDiscoverer .class , name , descriptor , rootDir , composer );
4143 }
4244
43- public static ToolchainDiscovererProperty createProperty (String name , ToolchainDescriptorBase descriptor , Provider <File > rootDir , Function <String , String > composer , Project project ) {
45+ public static ToolchainDiscovererProperty createProperty (String name , ToolchainDescriptorBase descriptor ,
46+ Provider <File > rootDir , Function <String , String > composer , Project project ) {
4447 ToolchainDiscovererProperty prop = project .getObjects ().newInstance (ToolchainDiscovererProperty .class , name );
45- Provider <ToolchainDiscoverer > disc = project .provider (() -> project .getObjects ().newInstance (ToolchainDiscoverer .class , name , descriptor , rootDir , composer ));
48+ Provider <ToolchainDiscoverer > disc = project .provider (
49+ () -> project .getObjects ().newInstance (ToolchainDiscoverer .class , name , descriptor , rootDir , composer ));
4650 prop .getDiscoverers ().add (disc );
4751 return prop ;
4852 }
4953
5054 @ Inject
51- public ToolchainDiscoverer (String name , ToolchainDescriptorBase descriptor , Provider <File > rootDir , Function <String , String > composer , CompilerMetaDataProviderFactory metaDataProviderFactory , ProviderFactory providers ) {
55+ public ToolchainDiscoverer (String name , ToolchainDescriptorBase descriptor , Provider <File > rootDir ,
56+ Function <String , String > composer , CompilerMetaDataProviderFactory metaDataProviderFactory ,
57+ ProviderFactory providers ) {
5258 this .name = name ;
5359 this .rootDir = rootDir ;
5460 this .composer = composer ;
@@ -75,7 +81,8 @@ public boolean exists() {
7581 }
7682
7783 public boolean versionValid () {
78- if (!exists ()) return false ;
84+ if (!exists ())
85+ return false ;
7986
8087 VersionNumber v = metadata (null ).get ().getVersion ();
8188 String versionLo = descriptor .getVersionLow ().get ();
@@ -200,22 +207,24 @@ public String getName() {
200207 private Optional <GccMetadata > metadata (File file , DiagnosticsVisitor visitor ) {
201208 if (file == null || !file .exists ())
202209 return Optional .empty ();
203- SearchResult <GccMetadata > searchresult = metadataProvider .getCompilerMetaData (new ArrayList <File >(), compilerSpec -> {
204- compilerSpec .executable (file );
205- });
210+ SearchResult <GccMetadata > searchresult = metadataProvider .getCompilerMetaData (new ArrayList <File >(),
211+ compilerSpec -> {
212+ compilerSpec .executable (file );
213+ });
206214 if (visitor != null )
207215 searchresult .explain (visitor );
208216 return Optional .ofNullable (searchresult .getComponent ());
209217 }
210218
211- public static List <File > systemPath (Project project , ToolchainGraphBuildService tce , Function <String , String > composer ) {
219+ public static List <File > systemPath (Project project , ToolchainGraphBuildService tce ,
220+ Function <String , String > composer , ExecOperations operations ) {
212221 String tool = composer == null ? "g++" : composer .apply ("gcc" );
213222 String whichResult = tce .getWhichResult (tool );
214223 if (whichResult == null ) {
215224 ByteArrayOutputStream os = new ByteArrayOutputStream ();
216225 ByteArrayOutputStream errStr = new ByteArrayOutputStream ();
217226
218- project .exec ((ExecSpec spec ) -> {
227+ operations .exec ((ExecSpec spec ) -> {
219228 spec .commandLine (OperatingSystem .current ().isWindows () ? "where.exe" : "which" , tool );
220229 spec .setStandardOutput (os );
221230 spec .setErrorOutput (errStr );
@@ -228,18 +237,22 @@ public static List<File> systemPath(Project project, ToolchainGraphBuildService
228237
229238 return Arrays .stream (whichResult .split ("\n " ))
230239 .map (String ::trim )
231- .filter (((Predicate <String >)String ::isEmpty ).negate ())
232- .map ((String path ) -> { return new File (path ).getParentFile ().getParentFile (); })
240+ .filter (((Predicate <String >) String ::isEmpty ).negate ())
241+ .map ((String path ) -> {
242+ return new File (path ).getParentFile ().getParentFile ();
243+ })
233244 .collect (Collectors .toList ());
234245 }
235246
236- public static ToolchainDiscovererProperty forSystemPath (Project project , ToolchainGraphBuildService tce , ToolchainDescriptorBase descriptor , Function <String , String > composer ) {
237- ToolchainDiscovererProperty prop = project .getObjects ().newInstance (ToolchainDiscovererProperty .class , "PathList" );
247+ public static ToolchainDiscovererProperty forSystemPath (Project project , ToolchainGraphBuildService tce ,
248+ ToolchainDescriptorBase descriptor , Function <String , String > composer , ExecOperations operations ) {
249+ ToolchainDiscovererProperty prop = project .getObjects ().newInstance (ToolchainDiscovererProperty .class ,
250+ "PathList" );
238251
239252 Provider <List <ToolchainDiscoverer >> p = project .provider (() -> {
240253 List <ToolchainDiscoverer > disc = new ArrayList <>();
241254 int i = 0 ;
242- for (File f : systemPath (project , tce , composer )) {
255+ for (File f : systemPath (project , tce , composer , operations )) {
243256 Provider <File > fp = project .provider (() -> f );
244257 disc .add (ToolchainDiscoverer .createDiscoverer ("Path" + (i ++), descriptor , fp , composer , project ));
245258 }
@@ -250,7 +263,9 @@ public static ToolchainDiscovererProperty forSystemPath(Project project, Toolcha
250263 }
251264
252265 private static Optional <File > join (Optional <File > f , String join ) {
253- return optFile ((File )(f .map ((File file ) -> { return new File (file , join ); }).orElse (null )));
266+ return optFile ((File ) (f .map ((File file ) -> {
267+ return new File (file , join );
268+ }).orElse (null )));
254269 }
255270
256271 private static Optional <File > optFile (File f ) {
0 commit comments