Skip to content

Commit

Permalink
Use new javadoc tool to inject code snippets (#25640)
Browse files Browse the repository at this point in the history
* Use new javadoc codesnippet tool

* Update readme samples
  • Loading branch information
srnagar authored Nov 24, 2021
1 parent 3742a40 commit a53fb21
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 64 deletions.
3 changes: 1 addition & 2 deletions sdk/agrifood/azure-verticals-agrifood-farming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.

##### Example
<!-- embedme ./src/samples/java/com/azure/verticals/agrifood/farming/ReadmeSamples.java#L20-L23 -->
```java
```java readme-sample-createFarmersBaseClient
FarmersBaseClient client = new FarmBeatsClientBuilder()
.endpoint("https://<farmbeats resource name>.farmbeats-dogfood.azure.net")
.credential(new DefaultAzureCredentialBuilder().build())
Expand Down
3 changes: 3 additions & 0 deletions sdk/agrifood/azure-verticals-agrifood-farming/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<javaModulesSurefireArgLine>
--add-exports com.azure.core/com.azure.core.implementation.jackson=ALL-UNNAMED
</javaModulesSurefireArgLine>
<codesnippet.skip>false</codesnippet.skip>
<javadocDoclet></javadocDoclet>
<javadocDocletOptions></javadocDocletOptions>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
import com.azure.identity.DefaultAzureCredentialBuilder;

/**
* WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS
* ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING
* LINE NUMBERS OF EXISTING CODE SAMPLES.
*
* Code samples for the README.md
*/
public class ReadmeSamples {
/**
* Sample for creating low level client.
*/
public void createClient() {
// BEGIN: readme-sample-createFarmersBaseClient
FarmersBaseClient client = new FarmBeatsClientBuilder()
.endpoint("https://<farmbeats resource name>.farmbeats-dogfood.azure.net")
.credential(new DefaultAzureCredentialBuilder().build())
.buildFarmersBaseClient();
// END: readme-sample-createFarmersBaseClient
}
}
6 changes: 2 additions & 4 deletions sdk/anomalydetector/azure-ai-anomalydetector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ You will also need to [register a new AAD application][register_aad_app] and [gr
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.

##### Async client
<!-- embedme ./src/samples/java/com/azure/ai/anomalydetector/ReadmeSamples.java#L29-L43 -->
```java
```java readme-sample-createAnomalyDetectorAsyncClient
String endpoint = "<anomaly-detector-resource-endpoint>";
HttpHeaders headers = new HttpHeaders()
.put("Accept", ContentType.APPLICATION_JSON);
Expand All @@ -80,8 +79,7 @@ AnomalyDetectorAsyncClient anomalyDetectorAsyncClient = new AnomalyDetectorClien
```

##### Sync client
<!-- embedme ./src/samples/java/com/azure/ai/anomalydetector/ReadmeSamples.java#L50-L64 -->
```java
```java readme-sample-createAnomalyDetectorClient
String endpoint = "<anomaly-detector-resource-endpoint>";
HttpHeaders headers = new HttpHeaders()
.put("Accept", ContentType.APPLICATION_JSON);
Expand Down
3 changes: 3 additions & 0 deletions sdk/anomalydetector/azure-ai-anomalydetector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<properties>
<!-- Anomaly detector temporarily skipping code coverage until tests are added -->
<jacoco.skip>true</jacoco.skip>
<codesnippet.skip>false</codesnippet.skip>
<javadocDoclet></javadocDoclet>
<javadocDocletOptions></javadocDocletOptions>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
import com.azure.identity.DefaultAzureCredentialBuilder;

/**
* WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS
* ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING
* LINE NUMBERS OF EXISTING CODE SAMPLES.
*
* Code samples for the README.md
*/
public class ReadmeSamples {
Expand All @@ -26,6 +22,7 @@ public class ReadmeSamples {
* Sample for creating async client.
*/
public void createAsyncClient() {
// BEGIN: readme-sample-createAnomalyDetectorAsyncClient
String endpoint = "<anomaly-detector-resource-endpoint>";
HttpHeaders headers = new HttpHeaders()
.put("Accept", ContentType.APPLICATION_JSON);
Expand All @@ -41,12 +38,14 @@ public void createAsyncClient() {
.pipeline(httpPipeline)
.endpoint(endpoint)
.buildAsyncClient();
// END: readme-sample-createAnomalyDetectorAsyncClient
}

/**
* Sample for creating sync client.
*/
public void createClient() {
// BEGIN: readme-sample-createAnomalyDetectorClient
String endpoint = "<anomaly-detector-resource-endpoint>";
HttpHeaders headers = new HttpHeaders()
.put("Accept", ContentType.APPLICATION_JSON);
Expand All @@ -62,5 +61,6 @@ public void createClient() {
.pipeline(httpPipeline)
.endpoint(endpoint)
.buildClient();
// END: readme-sample-createAnomalyDetectorClient
}
}
6 changes: 2 additions & 4 deletions sdk/purview/azure-analytics-purview-administration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica

##### Example

<!-- embedme ./src/samples/java/com/azure/analytics/purview/administration/ReadmeSamples.java#L10-L13 -->
```java
```java readme-sample-createAccountsClient
AccountsClient client = new PurviewAccountClientBuilder()
.endpoint(System.getenv("ACCOUNT_ENDPOINT"))
.credential(new DefaultAzureCredentialBuilder().build())
Expand All @@ -69,8 +68,7 @@ AccountsClient client = new PurviewAccountClientBuilder()

## Examples

<!-- embedme ./src/samples/java/com/azure/analytics/purview/administration/GetAccount.java#L11-L15 -->
```java
```java readme-sample-getAccountProperties
AccountsClient client = new PurviewAccountClientBuilder()
.endpoint(System.getenv("ACCOUNT_ENDPOINT"))
.credential(new DefaultAzureCredentialBuilder().build())
Expand Down
3 changes: 3 additions & 0 deletions sdk/purview/azure-analytics-purview-administration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

<properties>
<jacoco.skip>true</jacoco.skip>
<codesnippet.skip>false</codesnippet.skip>
<javadocDoclet></javadocDoclet>
<javadocDocletOptions></javadocDocletOptions>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,34 @@
package com.azure.analytics.purview.administration;

import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.core.util.BinaryData;

/**
* Samples to include in README.md
*/
public class ReadmeSamples {
public static void main(String[] args) {
/**
* Sample to demonstrate creating Purview Accounts client.
*/
public void createClient() {
// BEGIN: readme-sample-createAccountsClient
AccountsClient client = new PurviewAccountClientBuilder()
.endpoint(System.getenv("ACCOUNT_ENDPOINT"))
.credential(new DefaultAzureCredentialBuilder().build())
.buildAccountsClient();
// END: readme-sample-createAccountsClient
}

/**
* Sample to demonstrate getting the properties of an account.
*/
public void getAccounts() {
// BEGIN: readme-sample-getAccountProperties
AccountsClient client = new PurviewAccountClientBuilder()
.endpoint(System.getenv("ACCOUNT_ENDPOINT"))
.credential(new DefaultAzureCredentialBuilder().build())
.buildAccountsClient();
BinaryData response = client.getAccountPropertiesWithResponse(null).getValue();
// END: readme-sample-getAccountProperties
}
}
3 changes: 1 addition & 2 deletions sdk/purview/azure-analytics-purview-catalog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.

##### Example
<!-- embedme ./src/samples/java/com/azure/analytics/purview/catalog/ReadmeSamples.java#L20-L23 -->
```java
```java readme-sample-createGlossaryClient
GlossaryClient client = new PurviewCatalogClientBuilder()
.endpoint(System.getenv("<account-name>.purview.azure.com"))
.credential(new DefaultAzureCredentialBuilder().build())
Expand Down
3 changes: 3 additions & 0 deletions sdk/purview/azure-analytics-purview-catalog/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<javaModulesSurefireArgLine>
--add-exports com.azure.core/com.azure.core.implementation.jackson=ALL-UNNAMED
</javaModulesSurefireArgLine>
<codesnippet.skip>false</codesnippet.skip>
<javadocDoclet></javadocDoclet>
<javadocDocletOptions></javadocDocletOptions>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
import com.azure.identity.DefaultAzureCredentialBuilder;

/**
* WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS
* ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING
* LINE NUMBERS OF EXISTING CODE SAMPLES.
*
* Code samples for the README.md
*/
public class ReadmeSamples {
/**
* Sample for creating low level client.
*/
public void createClient() {
// BEGIN: readme-sample-createGlossaryClient
GlossaryClient client = new PurviewCatalogClientBuilder()
.endpoint(System.getenv("<account-name>.purview.azure.com"))
.credential(new DefaultAzureCredentialBuilder().build())
.buildGlossaryClient();
// END: readme-sample-createGlossaryClient
}
}
3 changes: 1 addition & 2 deletions sdk/purview/azure-analytics-purview-scanning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.

##### Example
<!-- embedme ./src/samples/java/com/azure/analytics/purview/scanning/ReadmeSamples.java#L20-L23 -->
```java
```java readme-sample-createSystemScanRulesetsClient
SystemScanRulesetsClient client = new PurviewScanningClientBuilder()
.endpoint(System.getenv("SCANNING_ENDPOINT"))
.credential(new DefaultAzureCredentialBuilder().build())
Expand Down
3 changes: 3 additions & 0 deletions sdk/purview/azure-analytics-purview-scanning/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<javaModulesSurefireArgLine>
--add-exports com.azure.core/com.azure.core.implementation.jackson=ALL-UNNAMED
</javaModulesSurefireArgLine>
<codesnippet.skip>false</codesnippet.skip>
<javadocDoclet></javadocDoclet>
<javadocDocletOptions></javadocDocletOptions>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
import com.azure.identity.DefaultAzureCredentialBuilder;

/**
* WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS
* ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING
* LINE NUMBERS OF EXISTING CODE SAMPLES.
*
* Code samples for the README.md
*/
public class ReadmeSamples {
/**
* Sample for creating low level client.
*/
public void createClient() {
// BEGIN: readme-sample-createSystemScanRulesetsClient
SystemScanRulesetsClient client = new PurviewScanningClientBuilder()
.endpoint(System.getenv("SCANNING_ENDPOINT"))
.credential(new DefaultAzureCredentialBuilder().build())
.buildSystemScanRulesetsClient();
// END: readme-sample-createSystemScanRulesetsClient
}
}
63 changes: 30 additions & 33 deletions sdk/videoanalyzer/azure-media-videoanalyzer-edge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,40 +62,39 @@ A _pipeline topology_ is a blueprint or template for creating live pipelines. It

To create a pipeline topology you need to define sources and sinks.

<!-- embedme C:\azure-sdk-for-java\sdk\videoanalyzer\azure-media-videoanalyzer-edge\src\samples\java\com\azure\media\videoanalyzer\edge\LvaInvokeModuleSample.java#L30-L79 -->
```java
```java readme-sample-buildPipelineTopology
private static PipelineTopology buildPipeLineTopology() {
IotHubMessageSource msgSource = new IotHubMessageSource("iotMsgSource")
.setHubInputName("${hubSourceInput}");
.setHubInputName("${hubSourceInput}");

UsernamePasswordCredentials creds = new UsernamePasswordCredentials("${rtspUsername}", "${rtspPassword}");

UnsecuredEndpoint endpoint = new UnsecuredEndpoint("${rtspUrl}")
.setCredentials(creds);
.setCredentials(creds);

RtspSource rtspSource = new RtspSource("rtspSource", endpoint);

NodeInput rtspInput = new NodeInput("rtspSource");

OutputSelector rtspOutputSelector = new OutputSelector()
.setProperty(OutputSelectorProperty.MEDIA_TYPE)
.setOperator(OutputSelectorOperator.IS)
.setValue("video");
.setProperty(OutputSelectorProperty.MEDIA_TYPE)
.setOperator(OutputSelectorOperator.IS)
.setValue("video");
ImageScale imageScale = new ImageScale()
.setMode(ImageScaleMode.PRESERVE_ASPECT_RATIO)
.setHeight("416")
.setWidth("416");
.setMode(ImageScaleMode.PRESERVE_ASPECT_RATIO)
.setHeight("416")
.setWidth("416");
ImageFormatBmp imageFormat = new ImageFormatBmp();
ImageProperties image = new ImageProperties()
.setScale(imageScale)
.setFormat(imageFormat);
.setScale(imageScale)
.setFormat(imageFormat);
ExtensionProcessorBase httpExtension = new HttpExtension("inferenceClient", Arrays.asList(rtspInput), endpoint, image);

NodeInput nodeInput = new NodeInput("inferenceClient");

IotHubMessageSink msgSink = new IotHubMessageSink("msgSink",
Arrays.asList(nodeInput),
"${hubSinkOutputName}");
Arrays.asList(nodeInput),
"${hubSinkOutputName}");

ParameterDeclaration userName = new ParameterDeclaration("rtspUserName", ParameterType.STRING);

Expand All @@ -104,13 +103,13 @@ private static PipelineTopology buildPipeLineTopology() {
ParameterDeclaration hubOutput = new ParameterDeclaration("hubSinkOutputName", ParameterType.STRING);

PipelineTopologyProperties pipeProps = new PipelineTopologyProperties()
.setParameters(Arrays.asList(userName, password, url, hubOutput))
.setSources(Arrays.asList(rtspSource))
.setSinks(Arrays.asList(msgSink))
.setProcessors(Arrays.asList(httpExtension));
.setParameters(Arrays.asList(userName, password, url, hubOutput))
.setSources(Arrays.asList(rtspSource))
.setSinks(Arrays.asList(msgSink))
.setProcessors(Arrays.asList(httpExtension));

PipelineTopology pipelineTopology = new PipelineTopology(TOPOLOGY_NAME)
.setProperties(pipeProps);
.setProperties(pipeProps);

return pipelineTopology;
}
Expand All @@ -120,37 +119,35 @@ private static PipelineTopology buildPipeLineTopology() {

To create a live pipeline, you need to have an existing pipeline topology.

<!-- embedme C:\azure-sdk-for-java\sdk\videoanalyzer\azure-media-videoanalyzer-edge\src\samples\java\com\azure\media\videoanalyzer\edge\LvaInvokeModuleSample.java#L85-L103 -->
```java
```java readme-sample-buildLivePipeline
private static LivePipeline buildLivePipeline() {
ParameterDefinition hubParam = new ParameterDefinition("hubSinkOutputName")
.setValue("testHubOutput");
.setValue("testHubOutput");
ParameterDefinition userParam = new ParameterDefinition("rtspUserName")
.setValue("testuser");
.setValue("testuser");
ParameterDefinition urlParam = new ParameterDefinition("rtspUrl")
.setValue("rtsp://sample-url-from-camera");
.setValue("rtsp://sample-url-from-camera");
ParameterDefinition passParam = new ParameterDefinition("rtspPassword")
.setValue("testpass");
.setValue("testpass");

LivePipelineProperties livePipelineProps = new LivePipelineProperties()
.setParameters(Arrays.asList(urlParam, userParam, passParam, hubParam))
.setTopologyName(TOPOLOGY_NAME);
.setParameters(Arrays.asList(urlParam, userParam, passParam, hubParam))
.setTopologyName(TOPOLOGY_NAME);

LivePipeline livePipeline = new LivePipeline(LIVE_PIPELINE_NAME)
.setProperties(livePipelineProps);
.setProperties(livePipelineProps);

return livePipeline;
}
```

### Invoking a direct method

<!-- embedme C:\azure-sdk-for-java\sdk\videoanalyzer\azure-media-videoanalyzer-edge\src\samples\java\com\azure\media\videoanalyzer\edge\LvaInvokeModuleSample.java#L132-L142 -->
```java
```java readme-sample-invokeDirectMethodHelper
private static MethodResult invokeDirectMethodHelper(DeviceMethod client, String methodName, String payload) throws IOException, IotHubException {
MethodResult result = null;
try {
result = client.invoke(DEVICE_ID, MODULE_ID, methodName, null, null, payload);
result = client.invoke(iothubDeviceid, iothubModuleid, methodName, null, null, payload);
} catch (IotHubException e) {
System.out.println("An error has occurred.");
System.out.println(e.toString());
Expand All @@ -160,10 +157,10 @@ private static MethodResult invokeDirectMethodHelper(DeviceMethod client, String
}
```

<!-- embedme C:\azure-sdk-for-java\sdk\videoanalyzer\azure-media-videoanalyzer-edge\src\samples\java\com\azure\media\videoanalyzer\edge\LvaInvokeModuleSample.java#L160-L161 -->
```java
```java readme-sample-setPipelineTopologyRequest
PipelineTopologySetRequest setPipelineTopologyRequest = new PipelineTopologySetRequest(pipelineTopology);
MethodResult setPipelineResult = invokeDirectMethodHelper(dClient, setPipelineTopologyRequest.getMethodName(), setPipelineTopologyRequest.getPayloadAsJson());
System.out.println(setPipelineResult.getPayload());
```

## Troubleshooting
Expand Down
Loading

0 comments on commit a53fb21

Please sign in to comment.