2424import java .nio .file .Paths ;
2525import java .nio .file .SimpleFileVisitor ;
2626import java .nio .file .attribute .BasicFileAttributes ;
27+ import java .util .Arrays ;
28+ import java .util .Collections ;
29+ import java .util .LinkedHashSet ;
30+ import java .util .List ;
31+ import java .util .Set ;
2732import java .util .stream .Collectors ;
2833import java .util .stream .Stream ;
2934import org .apache .commons .cli .CommandLine ;
3035import org .apache .commons .io .FileUtils ;
3136import org .apache .commons .lang3 .StringUtils ;
37+ import org .w3c .dom .Document ;
38+ import org .w3c .dom .Node ;
3239import software .amazon .awssdk .utils .Validate ;
3340import software .amazon .awssdk .utils .internal .CodegenNamingUtils ;
3441
4653 * --service-module-name service-module-name
4754 * --service-protocol json"
4855 * </pre>
56+ *
57+ * <p>By default the service new pom will include a dependency to the http-auth-aws module, this is only needed if the service
58+ * has one or more operations signed by any of the aws algorithms, e.g., sigv4 or sigv4a, but not needed if the service uses,
59+ * say, bearer auth (e.g., codecatalyst at the moment). Excluding this can be done by adding the
60+ * {@code --exclude-internal-dependency http-auth-aws} switch. For example
61+ * <pre>
62+ * mvn exec:java -pl :release-scripts \
63+ * -Dexec.mainClass="software.amazon.awssdk.release.CreateNewServiceModuleMain" \
64+ * -Dexec.args="--maven-project-root /path/to/root
65+ * --maven-project-version 2.1.4-SNAPSHOT
66+ * --service-id 'Service Id'
67+ * --service-module-name service-module-name
68+ * --service-protocol json
69+ * --exclude-internal-dependency http-auth-aws"
70+ * </pre>
4971 */
5072public class CreateNewServiceModuleMain extends Cli {
73+
74+ private static final Set <String > DEFAULT_INTERNAL_DEPENDENCIES = toSet ("http-auth-aws" );
75+
5176 private CreateNewServiceModuleMain () {
5277 super (requiredOption ("service-module-name" , "The name of the service module to be created." ),
5378 requiredOption ("service-id" , "The service ID of the service module to be created." ),
5479 requiredOption ("service-protocol" , "The protocol of the service module to be created." ),
5580 requiredOption ("maven-project-root" , "The root directory for the maven project." ),
56- requiredOption ("maven-project-version" , "The maven version of the service module to be created." ));
81+ requiredOption ("maven-project-version" , "The maven version of the service module to be created." ),
82+ optionalMultiValueOption ("include-internal-dependency" , "Includes an internal dependency from new service pom." ),
83+ optionalMultiValueOption ("exclude-internal-dependency" , "Excludes an internal dependency from new service pom." ));
5784 }
5885
5986 public static void main (String [] args ) {
6087 new CreateNewServiceModuleMain ().run (args );
6188 }
6289
90+ static Set <String > toSet (String ...args ) {
91+ Set <String > result = new LinkedHashSet <>();
92+ for (String arg : args ) {
93+ result .add (arg );
94+ }
95+ return Collections .unmodifiableSet (result );
96+
97+ }
98+
99+ static List <String > toList (String [] optionValues ) {
100+ if (optionValues == null ) {
101+ return Collections .emptyList ();
102+ }
103+ return Arrays .asList (optionValues );
104+ }
105+
106+ static Set <String > computeInternalDependencies (List <String > includes , List <String > excludes ) {
107+ Set <String > result = new LinkedHashSet <>(DEFAULT_INTERNAL_DEPENDENCIES );
108+ result .addAll (includes );
109+ excludes .forEach (result ::remove );
110+ return Collections .unmodifiableSet (result );
111+ }
112+
63113 @ Override
64114 protected void run (CommandLine commandLine ) throws Exception {
65115 new NewServiceCreator (commandLine ).run ();
@@ -71,14 +121,18 @@ private static class NewServiceCreator {
71121 private final String serviceModuleName ;
72122 private final String serviceId ;
73123 private final String serviceProtocol ;
124+ private final Set <String > internalDependencies ;
74125
75126 private NewServiceCreator (CommandLine commandLine ) {
76127 this .mavenProjectRoot = Paths .get (commandLine .getOptionValue ("maven-project-root" ).trim ());
77128 this .mavenProjectVersion = commandLine .getOptionValue ("maven-project-version" ).trim ();
78129 this .serviceModuleName = commandLine .getOptionValue ("service-module-name" ).trim ();
79130 this .serviceId = commandLine .getOptionValue ("service-id" ).trim ();
80131 this .serviceProtocol = transformSpecialProtocols (commandLine .getOptionValue ("service-protocol" ).trim ());
81-
132+ this .internalDependencies = computeInternalDependencies (toList (commandLine
133+ .getOptionValues ("include-internal-dependency" )),
134+ toList (commandLine
135+ .getOptionValues ("exclude-internal-dependency" )));
82136 Validate .isTrue (Files .exists (mavenProjectRoot ), "Project root does not exist: " + mavenProjectRoot );
83137 }
84138
@@ -98,6 +152,9 @@ public void run() throws Exception {
98152
99153 createNewModuleFromTemplate (templateModulePath , newServiceModulePath );
100154 replaceTemplatePlaceholders (newServiceModulePath );
155+
156+ Path newServicePom = newServiceModulePath .resolve ("pom.xml" );
157+ new AddInternalDependenciesTransformer (internalDependencies ).transform (newServicePom );
101158 }
102159
103160 private void createNewModuleFromTemplate (Path templateModulePath , Path newServiceModule ) throws IOException {
@@ -142,4 +199,22 @@ private String mavenName(String serviceId) {
142199 .collect (Collectors .joining (" " ));
143200 }
144201 }
202+
203+ static class AddInternalDependenciesTransformer extends PomTransformer {
204+ private final Set <String > internalDependencies ;
205+
206+ AddInternalDependenciesTransformer (Set <String > internalDependencies ) {
207+ this .internalDependencies = internalDependencies ;
208+ }
209+
210+ @ Override
211+ protected void updateDocument (Document doc ) {
212+ Node project = findChild (doc , "project" );
213+ Node dependencies = findChild (project , "dependencies" );
214+ for (String internalDependency : internalDependencies ) {
215+ dependencies .appendChild (sdkDependencyElement (doc , internalDependency ));
216+ }
217+ }
218+ }
219+
145220}
0 commit comments