From 6c168cfe231110ae16233c866d1f069f2423a14f Mon Sep 17 00:00:00 2001
From: Srikanta <51379715+srnagar@users.noreply.github.com>
Date: Sun, 21 Nov 2021 18:17:34 -0800
Subject: [PATCH] Azure SDK Maven archetype for creating new projects (#25465)
* Azure SDK Maven archetype for creating new projects
---
eng/.docsettings.yml | 1 +
eng/pipelines/templates/jobs/ci.tests.yml | 5 +-
eng/versioning/version_client.txt | 1 +
pom.xml | 1 +
sdk/tools/azure-sdk-archetype/CHANGELOG.md | 11 ++
sdk/tools/azure-sdk-archetype/README.md | 37 +++++
sdk/tools/azure-sdk-archetype/pom.xml | 70 +++++++++
.../META-INF/archetype-post-generate.groovy | 13 ++
.../META-INF/maven/archetype-metadata.xml | 31 ++++
.../resources/archetype-resources/pom.xml | 142 ++++++++++++++++++
.../src/main/java/App.java | 10 ++
.../src/test/java/AppTest.java | 17 +++
sdk/tools/ci.yml | 28 ++++
sdk/tools/pom.xml | 14 ++
14 files changed, 380 insertions(+), 1 deletion(-)
create mode 100644 sdk/tools/azure-sdk-archetype/CHANGELOG.md
create mode 100644 sdk/tools/azure-sdk-archetype/README.md
create mode 100644 sdk/tools/azure-sdk-archetype/pom.xml
create mode 100644 sdk/tools/azure-sdk-archetype/src/main/resources/META-INF/archetype-post-generate.groovy
create mode 100644 sdk/tools/azure-sdk-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
create mode 100644 sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/pom.xml
create mode 100644 sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/src/main/java/App.java
create mode 100644 sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/src/test/java/AppTest.java
create mode 100644 sdk/tools/ci.yml
create mode 100644 sdk/tools/pom.xml
diff --git a/eng/.docsettings.yml b/eng/.docsettings.yml
index 716142d42c32c..45b3edcdea942 100644
--- a/eng/.docsettings.yml
+++ b/eng/.docsettings.yml
@@ -133,6 +133,7 @@ known_content_issues:
- ['sdk/storage/azure-storage-blob-nio/README.md', '#3113']
- ['sdk/storage/azure-storage-internal-avro/README.md', '#3113']
- ['sdk/storage/README.md', '#3113']
+ - ['sdk/tools/azure-sdk-archetype/README.md', '#3113']
package_indexing_exclusion_list:
- azure-loganalytics-sample
diff --git a/eng/pipelines/templates/jobs/ci.tests.yml b/eng/pipelines/templates/jobs/ci.tests.yml
index 345ccd6f61f6c..6cd4704b8ff87 100644
--- a/eng/pipelines/templates/jobs/ci.tests.yml
+++ b/eng/pipelines/templates/jobs/ci.tests.yml
@@ -34,6 +34,9 @@ parameters:
- name: UsePlatformContainer
type: boolean
default: false
+ - name: SkipAggregateReports
+ type: boolean
+ default: false
jobs:
- job: 'Test'
@@ -110,7 +113,7 @@ jobs:
- task: Maven@3
displayName: 'Generate aggregate code coverage report'
- condition: and(eq(variables['Agent.OS'], 'Windows_NT'), eq(variables['JavaTestVersion'], '1.11'), eq('${{ parameters.SDKType }}', 'client'))
+ condition: and(eq(variables['Agent.OS'], 'Windows_NT'), eq(variables['JavaTestVersion'], '1.11'), eq('${{ parameters.SDKType }}', 'client'), eq('${{ parameters.SkipAggregateReports }}', 'false'))
inputs:
mavenPomFile: sdk/${{ parameters.ServiceDirectory }}/pom.xml
options: '$(DefaultOptions) -Pcoverage'
diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt
index 70645d59b9e21..59b5636219bcb 100644
--- a/eng/versioning/version_client.txt
+++ b/eng/versioning/version_client.txt
@@ -323,6 +323,7 @@ com.azure.resourcemanager:azure-resourcemanager-logz;1.0.0-beta.1;1.0.0-beta.2
com.azure.resourcemanager:azure-resourcemanager-storagepool;1.0.0-beta.1;1.0.0-beta.2
com.azure.resourcemanager:azure-resourcemanager-dataprotection;1.0.0-beta.1;1.0.0-beta.2
com.azure.resourcemanager:azure-resourcemanager-desktopvirtualization;1.0.0-beta.1;1.0.0-beta.2
+com.azure.tools:azure-sdk-archetype;1.0.0;1.0.0
# Unreleased dependencies: Copy the entry from above, prepend "unreleased_" and remove the current
# version. Unreleased dependencies are only valid for dependency versions.
diff --git a/pom.xml b/pom.xml
index 7e6a817f6ddad..b306ab55b97da 100644
--- a/pom.xml
+++ b/pom.xml
@@ -837,6 +837,7 @@
sdk/template
sdk/textanalytics
sdk/timeseriesinsights
+ sdk/tools
sdk/translation
sdk/videoanalyzer
sdk/vmwarecloudsimple
diff --git a/sdk/tools/azure-sdk-archetype/CHANGELOG.md b/sdk/tools/azure-sdk-archetype/CHANGELOG.md
new file mode 100644
index 0000000000000..607cb813ea90a
--- /dev/null
+++ b/sdk/tools/azure-sdk-archetype/CHANGELOG.md
@@ -0,0 +1,11 @@
+# Release History
+
+## 1.0.0 (Unreleased)
+
+### Features Added
+- A dependency on the latest `azure-sdk-bom` BOM release, to ensure that all Azure SDK for Java dependencies are aligned
+ and give you the best developer experience possible.
+- Built-in support for GraalVM native image compilation.
+- Support for generating a new project with a specified set of Azure SDK for Java client libraries.
+- Integration with the Azure SDK for Java build tooling that will give build-time analysis of your project to ensure
+ as many best practices are followed.
diff --git a/sdk/tools/azure-sdk-archetype/README.md b/sdk/tools/azure-sdk-archetype/README.md
new file mode 100644
index 0000000000000..a41783ad0bd80
--- /dev/null
+++ b/sdk/tools/azure-sdk-archetype/README.md
@@ -0,0 +1,37 @@
+# Azure SDK Maven Archetype
+
+The Azure SDK Maven archetype can accelerate the bootstrapping of a new project. The Azure SDK for Java Maven archetype
+creates a new application, with files and a directory structure that follows best practices. In particular, the
+Azure SDK for Java Maven archetype creates a new Maven project with the following features:
+
+* A dependency on the latest `azure-sdk-bom` BOM release, to ensure that all Azure SDK for Java dependencies are aligned and give you the best developer experience possible.
+* Built-in support for GraalVM native image compilation.
+* Support for generating a new project with a specified set of Azure SDK for Java client libraries.
+* Integration with the Azure SDK for Java build tooling that will give build-time analysis of your project to ensure as many best practices are followed.
+
+As the Azure SDK for Java Maven archetype is published to Maven Central, we can bootstrap a new application by using
+the archetype directly.
+
+```shell
+mvn archetype:generate \
+ -DarchetypeGroupId=com.azure.tools \
+ -DarchetypeArtifactId=azure-sdk-archetype
+```
+
+After entering this command, a series of prompts will ask for details about your project so that the archetype can
+generate the right output for you.
+
+
+| Name | Description |
+|----------------|--------------|
+| groupId | (Required) Specifies the Maven groupId to use in the POM file created for the generated project. |
+| artifactId | (Required) Specifies the Maven artifactId to use in the POM file created for the generated project. |
+| package | (Optional) Specifies the package name to put the generated code into. If not specified, it is inferred from the groupId. |
+| azureLibraries | (Optional) A comma-separated list of Azure SDK for Java libraries, using their Maven artifact IDs. A list of such artifact IDs can be found [here](https://azure.github.io/azure-sdk/releases/latest/java.html). |
+| enableGraalVM | (Optional) By default GraalVM support will be enabled, but if `enableGraalVM` is set to false, the generated Maven POM file will not include support for compiling your application to a native image using GraalVM. |
+| javaVersion | (Optional) Specifies the minimum version of the JDK to target when building the generated project. By default it is the latest LTS release (currently Java 17), with valid ranges from Java 8 up. The value should just be the required Java version, for example, '8', '11', '17', etc. |
+| junitVersion | (Optional) The version of JUnit to include as a dependency. By default JUnit 5 will be used, but valid values are '4' and '5'. |
+
+If you would rather provide these values at the time of calling the archetype command above (for example, for
+automation purposes), you can specify them as parameters using the standard Maven syntax of appending `-D` to the
+parameter name, for example, `-DjavaVersion=17`.
diff --git a/sdk/tools/azure-sdk-archetype/pom.xml b/sdk/tools/azure-sdk-archetype/pom.xml
new file mode 100644
index 0000000000000..ffabdfee24529
--- /dev/null
+++ b/sdk/tools/azure-sdk-archetype/pom.xml
@@ -0,0 +1,70 @@
+
+
+
+ 4.0.0
+ com.azure.tools
+ azure-sdk-archetype
+ 1.0.0
+ Azure SDK Maven archetype
+ Azure SDK archetype to generate a new Maven project with
+ recommended Azure SDK tools and configuration.
+
+ 8
+ 8
+
+
+ https://github.com/azure/azure-sdk-for-java
+
+ Microsoft Corporation
+ http://microsoft.com
+
+
+
+
+
+ The MIT License (MIT)
+ http://opensource.org/licenses/MIT
+ repo
+
+
+
+
+
+ microsoft
+ Microsoft Corporation
+
+
+
+
+ GitHub
+ https://github.com/Azure/azure-sdk-for-java/issues
+
+
+
+ https://github.com/Azure/azure-sdk-for-java
+ scm:git:https://github.com/Azure/azure-sdk-for-java.git
+
+ HEAD
+
+
+
+
+
+ org.apache.maven.archetype
+ archetype-packaging
+ 3.2.0
+
+
+
+
+
+ org.apache.maven.archetype
+ maven-archetype-plugin
+ 3.2.0
+
+
+
+
+
diff --git a/sdk/tools/azure-sdk-archetype/src/main/resources/META-INF/archetype-post-generate.groovy b/sdk/tools/azure-sdk-archetype/src/main/resources/META-INF/archetype-post-generate.groovy
new file mode 100644
index 0000000000000..7e70593b8e877
--- /dev/null
+++ b/sdk/tools/azure-sdk-archetype/src/main/resources/META-INF/archetype-post-generate.groovy
@@ -0,0 +1,13 @@
+dir = new File(new File(request.outputDirectory), request.artifactId)
+
+def run(String cmd) {
+ def process = cmd.execute(null, dir)
+ process.waitForProcessOutput((Appendable)System.out, System.err)
+ if (process.exitValue() != 0) {
+ throw new Exception("Command '$cmd' exited with code: ${process.exitValue()}")
+ }
+}
+def mvnFileName = System.properties['os.name'].toLowerCase().contains('windows') ? 'mvn.cmd' : 'mvn'
+
+run("echo 'Updating to latest versions...'")
+run("$mvnFileName versions:update-properties -DincludeProperties=bom.version -DgenerateBackupPoms=false")
diff --git a/sdk/tools/azure-sdk-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/sdk/tools/azure-sdk-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
new file mode 100644
index 0000000000000..f3feeeb06b1c9
--- /dev/null
+++ b/sdk/tools/azure-sdk-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -0,0 +1,31 @@
+
+
+
+ src/main/java
+
+
+ src/test/java
+
+
+
+
+
+ (true|false)
+ true
+
+
+ 17
+
+
+ (4|5)
+ 5
+
+
+
+
+
+
+
diff --git a/sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/pom.xml b/sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/pom.xml
new file mode 100644
index 0000000000000..e950b74ed7510
--- /dev/null
+++ b/sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/pom.xml
@@ -0,0 +1,142 @@
+
+ 4.0.0
+
+ ${groupId}
+ ${artifactId}
+ ${version}
+ jar
+
+ ${artifactId}
+
+
+ ${javaVersion}
+ ${javaVersion}
+ 1.0.2
+ 21.2.0
+#if( ${junitVersion} == '4')
+ 4.12
+#end
+#if( ${junitVersion} == '5')
+ 5.7.2
+#end
+
+
+
+
+
+ com.azure
+ azure-sdk-bom
+ ${bom.version}
+ pom
+ import
+
+
+
+
+
+
+#set($libraries = ${azureLibraries})
+#set($dependencies = $libraries.split(","))
+#foreach($dependency in $dependencies)
+
+ com.azure
+ $dependency.trim()
+
+#end
+#if( ${enableGraalVM} == 'true')
+
+ org.graalvm.sdk
+ graal-sdk
+ ${graalvm.version}
+ provided
+
+#end
+
+#if( ${junitVersion} == '4')
+
+ junit
+ junit
+ ${junit4.version}
+ test
+
+#end
+
+#if( ${junitVersion} == '5')
+
+ org.junit.jupiter
+ junit-jupiter-api
+ ${junit5.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit5.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-params
+ ${junit5.version}
+ test
+
+#end
+
+
+
+
+
+
+ com.azure.tools
+ azure-maven-plugin
+ 1.0.0-SNAPSHOT
+
+ true
+ true
+ true
+ true
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 3.0.0
+
+ ${package}.App
+
+
+
+
+
+#if( ${enableGraalVM} == 'true')
+
+
+ native
+
+
+
+ org.graalvm.nativeimage
+ native-image-maven-plugin
+ ${graalvm.version}
+
+
+
+ native-image
+
+ package
+
+
+
+ ${artifactId}
+ ${package}.App
+
+
+
+
+
+
+#end
+
+
diff --git a/sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/src/main/java/App.java b/sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/src/main/java/App.java
new file mode 100644
index 0000000000000..a9e39de369c3f
--- /dev/null
+++ b/sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/src/main/java/App.java
@@ -0,0 +1,10 @@
+package ${package};
+
+/**
+ * A sample Azure application.
+ */
+public class App {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/src/test/java/AppTest.java b/sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/src/test/java/AppTest.java
new file mode 100644
index 0000000000000..7b93c3ede686f
--- /dev/null
+++ b/sdk/tools/azure-sdk-archetype/src/main/resources/archetype-resources/src/test/java/AppTest.java
@@ -0,0 +1,17 @@
+package ${package};
+
+#if( ${junitVersion} == 4 )
+import org.junit.Test;
+#end
+
+#if( ${junitVersion} == 5)
+import org.junit.jupiter.api.Test;
+#end
+
+public class AppTest {
+
+ @Test
+ public void testApp() {
+ // hello world
+ }
+}
diff --git a/sdk/tools/ci.yml b/sdk/tools/ci.yml
new file mode 100644
index 0000000000000..c8e26fc06e803
--- /dev/null
+++ b/sdk/tools/ci.yml
@@ -0,0 +1,28 @@
+trigger:
+ branches:
+ include:
+ - main
+ paths:
+ include:
+ - /sdk/tools/azure-sdk-archetype/
+
+pr:
+ branches:
+ include:
+ - main
+ - feature/*
+ - hotfix/*
+ - release/*
+ paths:
+ include:
+ - /sdk/tools/azure-sdk-archetype/
+
+extends:
+ template: /eng/pipelines/templates/stages/archetype-sdk-client.yml
+ parameters:
+ ServiceDirectory: tools
+ SkipAggregateReports: true
+ Artifacts:
+ - name: azure-sdk-archetype
+ groupId: com.azure.tools
+ safeName: azuresdkarchetype
diff --git a/sdk/tools/pom.xml b/sdk/tools/pom.xml
new file mode 100644
index 0000000000000..4e99e5b20b1a7
--- /dev/null
+++ b/sdk/tools/pom.xml
@@ -0,0 +1,14 @@
+
+
+ 4.0.0
+ com.azure
+ azure-tools-service
+ pom
+ 1.0.0
+
+ azure-sdk-archetype
+
+