99 *
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12- * WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied. See the
12+ * WARRANTIES OR CONDITIONS OF ANY, either express or implied. See the
1313 * License for the specific language governing permissions and limitations under
1414 * the License.
1515 */
@@ -18,19 +18,19 @@ package flags
1818
1919import (
2020 "flag"
21+ "fmt" // ADDED: Import fmt package
2122 "strings"
2223)
2324
2425const (
25- ALL = "ALL" // All modules
26- DEFAULT = "DEFAULT" // Modules other than those excluded
26+ ALL = "ALL"
27+ DEFAULT = "DEFAULT"
2728 KAFKA = "KAFKA"
2829 SPANNER = "SPANNER"
2930 BIGTABLE = "BIGTABLE"
3031 DATASTREAM = "DATASTREAM"
3132)
3233
33- // Avoid making these vars public.
3434var (
3535 modulesToBuild string
3636 moduleMap = map [string ][]string {
@@ -68,16 +68,24 @@ var (
6868 }
6969)
7070
71- // Registers all common flags. Must be called before flag.Parse().
7271func RegisterCommonFlags () {
7372 flag .StringVar (& modulesToBuild , "modules-to-build" , ALL , "List of modules to build/run commands against" )
7473}
7574
76- // Returns all modules to build.
77- func ModulesToBuild () []string {
75+ // CHANGED: This function now contains all logic for deciding which modules to build.
76+ // It returns a slice of strings that will be passed to Maven.
77+ func ProjectsToBuild () []string {
78+ // If a specific module is given for testing, it takes highest priority.
79+ if ModuleToTest != "" {
80+ // -pl tells Maven to build only this project
81+ // -am tells Maven to also build any dependencies it needs
82+ return []string {"-pl" , ModuleToTest , "-am" }
83+ }
84+
85+ // Otherwise, use the default behavior with --modules-to-build
7886 m := modulesToBuild
87+ var modules []string
7988 if m == "DEFAULT" {
80- // "DEFAULT" is "ALL" minus other modules defined in moduleMap
8189 var s []string
8290 for k , v := range moduleMap {
8391 if k != "ALL" && k != "DEFAULT" {
@@ -88,12 +96,17 @@ func ModulesToBuild() []string {
8896 }
8997 }
9098 }
91- return s
99+ modules = s
92100 } else if val , ok := moduleMap [modulesToBuild ]; ok {
93- return val
101+ modules = val
102+ } else if len (m ) > 0 {
103+ modules = strings .Split (m , "," )
94104 }
95- if len (m ) == 0 {
96- return make ([]string , 0 )
105+
106+ if len (modules ) > 0 {
107+ return []string {"-pl" , strings .Join (modules , "," ), "-am" }
97108 }
98- return strings .Split (m , "," )
109+
110+ // Return empty if ALL modules should be built (Maven's default)
111+ return []string {}
99112}
0 commit comments