@@ -33,8 +33,6 @@ import {
33
33
listFiles ,
34
34
} from "../helpers/envcontext.js" ;
35
35
import { thoughtLog } from "../helpers/logger.js" ;
36
-
37
- import { analyzeBuildSettings } from "../helpers/package_specific/gradleutils.js" ;
38
36
import {
39
37
CARGO_CMD ,
40
38
CLJ_CMD ,
@@ -226,6 +224,14 @@ if (process.env.GRADLE_USER_HOME) {
226
224
) ;
227
225
}
228
226
227
+ // Construct path to gradle init script
228
+ const GRADLE_INIT_SCRIPT = resolve (
229
+ dirNameStr ,
230
+ "data" ,
231
+ "helpers" ,
232
+ "init.gradle" ,
233
+ ) ;
234
+
229
235
// Construct sbt cache directory
230
236
const SBT_CACHE_DIR =
231
237
process . env . SBT_CACHE_DIR || join ( homedir ( ) , ".ivy2" , "cache" ) ;
@@ -1959,59 +1965,50 @@ export async function createJavaBom(path, options) {
1959
1965
options ,
1960
1966
)
1961
1967
) {
1962
- let rootProjects = [ null ] ;
1963
1968
let allProjectsStr = [ ] ;
1964
- let rootGradleModule = { } ;
1965
- let includedProjectsFound = false ;
1966
1969
if ( process . env . GRADLE_INCLUDED_BUILDS ) {
1967
1970
// Automatically add the colon prefix
1968
- const includedBuilds = process . env . GRADLE_INCLUDED_BUILDS . split ( "," ) . map (
1969
- ( b ) => ( ! b . startsWith ( ":" ) ? `:${ b } ` : b ) ,
1971
+ allProjectsStr = process . env . GRADLE_INCLUDED_BUILDS . split ( "," ) . map ( ( b ) =>
1972
+ ! b . startsWith ( ":" ) ? `:${ b } ` : b ,
1970
1973
) ;
1971
- rootProjects = rootProjects . concat ( includedBuilds ) ;
1972
- includedProjectsFound = true ;
1973
- } else {
1974
- // Automatically detect included builds
1975
- // Only from the root path for now
1976
- for ( const abuildFile of [
1977
- join ( gradleRootPath , "build.gradle" ) ,
1978
- join ( gradleRootPath , "build.gradle.kts" ) ,
1979
- join ( gradleRootPath , "settings.gradle" ) ,
1980
- join ( gradleRootPath , "settings.gradle.kts" ) ,
1981
- ] ) {
1982
- if ( ! safeExistsSync ( abuildFile ) ) {
1983
- continue ;
1974
+ }
1975
+ let parallelPropTaskOut = executeParallelGradleProperties (
1976
+ gradleRootPath ,
1977
+ [ null ] ,
1978
+ process . env . GRADLE_INCLUDED_BUILDS
1979
+ ? [ ]
1980
+ : [ "--init-script" , GRADLE_INIT_SCRIPT ] ,
1981
+ ) ;
1982
+ if ( ! process . env . GRADLE_INCLUDED_BUILDS ) {
1983
+ const outputLines = parallelPropTaskOut . split ( "\n" ) ;
1984
+ for ( const [ i , line ] of outputLines . entries ( ) ) {
1985
+ if ( line . startsWith ( "Root project '" ) ) {
1986
+ break ;
1984
1987
}
1985
- const buildSettings = analyzeBuildSettings ( abuildFile ) ;
1986
- if ( buildSettings ?. includedBuilds ?. length ) {
1987
- for ( const aib of buildSettings . includedBuilds ) {
1988
- if ( ! rootProjects . includes ( aib ) ) {
1989
- rootProjects . push ( aib ) ;
1990
- includedProjectsFound = true ;
1991
- }
1988
+ if ( line . startsWith ( "<CDXGEN:includedBuild>" ) ) {
1989
+ const includedBuild = line . split ( ">" ) ;
1990
+ if ( ! allProjectsStr . includes ( includedBuild [ 1 ] . trim ( ) ) ) {
1991
+ allProjectsStr . push ( includedBuild [ 1 ] . trim ( ) ) ;
1992
1992
}
1993
- break ;
1994
1993
}
1995
1994
}
1996
1995
}
1997
- if ( includedProjectsFound ) {
1996
+ if ( allProjectsStr . length > 0 ) {
1998
1997
thoughtLog (
1999
- `Wait, this gradle project uses composite builds. I must carefully process these ${ rootProjects . length } projects including the root.` ,
1998
+ `Wait, this gradle project uses composite builds. I must carefully process these ${ allProjectsStr . length } projects, in addition to the root.` ,
2000
1999
) ;
2001
2000
if ( DEBUG_MODE ) {
2002
- console . log (
2003
- `Additional root projects: ${ rootProjects . join ( " " ) . trim ( ) } .` ,
2004
- ) ;
2001
+ console . log ( `Composite builds: ${ allProjectsStr . join ( " " ) . trim ( ) } .` ) ;
2005
2002
}
2003
+ parallelPropTaskOut = parallelPropTaskOut . concat (
2004
+ "\n" ,
2005
+ executeParallelGradleProperties ( gradleRootPath , allProjectsStr ) ,
2006
+ ) ;
2007
+ allProjectsStr = [ ] ;
2006
2008
}
2007
- const parallelPropTaskOut = executeParallelGradleProperties (
2008
- gradleRootPath ,
2009
- rootProjects ,
2010
- ) ;
2011
2009
const splitPropTaskOut = splitOutputByGradleProjects ( parallelPropTaskOut , [
2012
2010
"properties" ,
2013
2011
] ) ;
2014
-
2015
2012
for ( const [ key , propTaskOut ] of splitPropTaskOut . entries ( ) ) {
2016
2013
const retMap = parseGradleProperties ( propTaskOut ) ;
2017
2014
const rootProject = retMap . rootProject ;
@@ -2020,26 +2017,18 @@ export async function createJavaBom(path, options) {
2020
2017
rootProject ,
2021
2018
retMap . metadata ,
2022
2019
) ;
2020
+ if ( ! key . startsWith ( ":" ) ) {
2021
+ parentComponent = rootComponent ;
2022
+ }
2023
2023
gradleModules . set ( key , rootComponent ) ;
2024
- if ( ! rootProjects . includes ( key ) ) {
2025
- if ( rootGradleModule . name ) {
2026
- if ( DEBUG_MODE ) {
2027
- console . log (
2028
- `Received new root component: ${ rootComponent . name } with key ${ key } . Please verify the value used for included builds. Using the name ${ rootGradleModule . name } .` ,
2029
- ) ;
2030
- }
2031
- } else {
2032
- rootGradleModule = rootComponent ;
2033
- }
2034
- } else if ( ! allProjectsAddedPurls . includes ( rootComponent [ "purl" ] ) ) {
2024
+ if ( ! allProjectsAddedPurls . includes ( rootComponent [ "purl" ] ) ) {
2035
2025
allProjects . push ( rootComponent ) ;
2036
2026
rootDependsOn . add ( rootComponent [ "bom-ref" ] ) ;
2037
2027
allProjectsAddedPurls . push ( rootComponent [ "purl" ] ) ;
2038
2028
}
2039
2029
allProjectsStr = allProjectsStr . concat ( retMap . projects ) ;
2040
2030
}
2041
2031
}
2042
- parentComponent = rootGradleModule ;
2043
2032
// Get the sub-project properties and set the root dependencies
2044
2033
if ( allProjectsStr ?. length ) {
2045
2034
const modulesToSkip = process . env . GRADLE_SKIP_MODULES
0 commit comments