diff --git a/third_party/docfx-doclet-143274/pom.xml b/third_party/docfx-doclet-143274/pom.xml
index 713fb428..fba593b1 100644
--- a/third_party/docfx-doclet-143274/pom.xml
+++ b/third_party/docfx-doclet-143274/pom.xml
@@ -191,12 +191,6 @@
4.23.0
test
-
- com.github.stefanbirkner
- system-rules
- 1.19.0
- test
-
diff --git a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/doclet/DocFxDoclet.java b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/doclet/DocFxDoclet.java
index e4c3051e..2d51aef6 100644
--- a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/doclet/DocFxDoclet.java
+++ b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/doclet/DocFxDoclet.java
@@ -21,14 +21,11 @@ public void init(Locale locale, Reporter reporter) {
@Override
public boolean run(DocletEnvironment environment) {
- String artifactVersion = System.getenv("artifactVersion");
- String librariesBomVersion = System.getenv("librariesBomVersion");
- String repoMetadataFilePath = System.getenv("repoMetadataFilePath");
- Objects.requireNonNull(
- repoMetadataFilePath, "Environment variable 'repoMetadataFilePath' must not be null.");
- reporter.print(Kind.NOTE, "Environment variable artifactVersion: " + artifactVersion);
- reporter.print(Kind.NOTE, "Environment variable librariesBomVersion: " + librariesBomVersion);
- reporter.print(Kind.NOTE, "Environment variable repoMetadataFilePath: " + repoMetadataFilePath);
+ Objects.requireNonNull(repoMetadataFilePath, "repoMetadataFilePath must not be null.");
+
+ reporter.print(Kind.NOTE, "artifactVersion: " + artifactVersion);
+ reporter.print(Kind.NOTE, "librariesBomVersion: " + librariesBomVersion);
+ reporter.print(Kind.NOTE, "repoMetadataFilePath: " + repoMetadataFilePath);
reporter.print(Kind.NOTE, "Output path: " + outputPath);
reporter.print(Kind.NOTE, "Excluded packages: " + Arrays.toString(excludePackages));
reporter.print(Kind.NOTE, "Excluded classes: " + Arrays.toString(excludeClasses));
@@ -61,6 +58,9 @@ public String getName() {
private String projectName;
private boolean disableChangelog;
private boolean disableLibraryOverview;
+ private String artifactVersion;
+ private String librariesBomVersion;
+ private String repoMetadataFilePath;
@Override
public Set extends Option> getSupportedOptions() {
@@ -130,6 +130,36 @@ public boolean process(String option, List arguments) {
return true;
}
},
+ new CustomOption(
+ "Artifact Version",
+ Arrays.asList("-artifactVersion", "--artifactVersion"),
+ "artifactVersion") {
+ @Override
+ public boolean process(String option, List arguments) {
+ artifactVersion = arguments.get(0);
+ return true;
+ }
+ },
+ new CustomOption(
+ "libraries-bom Version",
+ Arrays.asList("-librariesBomVersion", "--librariesBomVersion"),
+ "librariesBomVersion") {
+ @Override
+ public boolean process(String option, List arguments) {
+ librariesBomVersion = arguments.get(0);
+ return true;
+ }
+ },
+ new CustomOption(
+ "repo-metadata.json File Path",
+ Arrays.asList("-repoMetadataFilePath", "--repoMetadataFilePath"),
+ "repoMetadataFilePath") {
+ @Override
+ public boolean process(String option, List arguments) {
+ repoMetadataFilePath = arguments.get(0);
+ return true;
+ }
+ },
// Support next properties for compatibility with Gradle javadoc task.
// According to javadoc spec - these properties used by StandardDoclet and used only when
diff --git a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/doclet/DocletRunner.java b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/doclet/DocletRunner.java
index f7153bb8..e2a4af8f 100644
--- a/third_party/docfx-doclet-143274/src/main/java/com/microsoft/doclet/DocletRunner.java
+++ b/third_party/docfx-doclet-143274/src/main/java/com/microsoft/doclet/DocletRunner.java
@@ -1,5 +1,7 @@
package com.microsoft.doclet;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
import com.microsoft.util.OptionsFileUtil;
import java.util.ArrayList;
import java.util.List;
@@ -20,7 +22,18 @@ public static void main(final String[] args) {
return;
}
- List combined = new ArrayList<>();
+ run(
+ args,
+ new EnvironmentToArgumentsBuilder()
+ .addIfExists("artifactVersion")
+ .addIfExists("librariesBomVersion")
+ .addIfExists("repoMetadataFilePath")
+ .build());
+ }
+
+ @VisibleForTesting
+ static void run(final String[] args, List env) {
+ List combined = new ArrayList<>(env);
for (String arg : args) {
if (!(new java.io.File(arg)).isFile()) {
System.err.println(String.format("File '%s' does not exist", args[0]));
@@ -30,4 +43,27 @@ public static void main(final String[] args) {
ToolProvider.getSystemDocumentationTool()
.run(null, null, null, combined.toArray(new String[0]));
}
+
+ @VisibleForTesting
+ static class EnvironmentToArgumentsBuilder {
+ private final ImmutableList.Builder env = new ImmutableList.Builder<>();
+
+ public EnvironmentToArgumentsBuilder addIfExists(String name) {
+ String value = System.getenv(name);
+ if (value != null) {
+ return add(name, value);
+ }
+ return this;
+ }
+
+ @VisibleForTesting
+ EnvironmentToArgumentsBuilder add(String name, String value) {
+ env.add("-" + name, value);
+ return this;
+ }
+
+ public ImmutableList build() {
+ return env.build();
+ }
+ }
}
diff --git a/third_party/docfx-doclet-143274/src/test/java/com/microsoft/doclet/DocletRunnerTest.java b/third_party/docfx-doclet-143274/src/test/java/com/microsoft/doclet/DocletRunnerTest.java
index 9bc72d5c..cfd29039 100644
--- a/third_party/docfx-doclet-143274/src/test/java/com/microsoft/doclet/DocletRunnerTest.java
+++ b/third_party/docfx-doclet-143274/src/test/java/com/microsoft/doclet/DocletRunnerTest.java
@@ -2,7 +2,6 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import com.microsoft.util.FileUtilTest;
@@ -15,9 +14,7 @@
import java.util.stream.Collectors;
import org.junit.After;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.contrib.java.lang.system.EnvironmentVariables;
public class DocletRunnerTest {
@@ -30,8 +27,6 @@ public class DocletRunnerTest {
private final PrintStream originalOut = System.out;
private final PrintStream originalErr = System.err;
- @Rule public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
-
@Before
public void cleanup() throws IOException {
FileUtilTest.deleteDirectory(OUTPUT_DIR);
@@ -71,17 +66,14 @@ public void testFilesGenerationWhenTargetFileDoesNotExist() {
@Test
public void testFilesGeneration() throws IOException {
- environmentVariables.set("artifactVersion", "0.18.0");
- environmentVariables.set("librariesBomVersion", "26.19.0");
- environmentVariables.set(
- "repoMetadataFilePath", "./src/test/java/com/microsoft/samples/.repo-metadata.json");
- assertEquals("0.18.0", System.getenv("artifactVersion"));
- assertEquals("26.19.0", System.getenv("librariesBomVersion"));
- assertEquals(
- "./src/test/java/com/microsoft/samples/.repo-metadata.json",
- System.getenv("repoMetadataFilePath"));
-
- DocletRunner.main(new String[] {PARAMS_DIR});
+ DocletRunner.run(
+ new String[] {PARAMS_DIR},
+ new DocletRunner.EnvironmentToArgumentsBuilder()
+ .add("artifactVersion", "0.18.0")
+ .add("librariesBomVersion", "26.19.0")
+ .add(
+ "repoMetadataFilePath", "./src/test/java/com/microsoft/samples/.repo-metadata.json")
+ .build());
List expectedFilePaths =
Files.list(Path.of(EXPECTED_GENERATED_FILES_DIR)).sorted().collect(Collectors.toList());
@@ -111,12 +103,6 @@ public void testFilesGeneration() throws IOException {
generatedFileLines[i]);
}
}
- environmentVariables.clear("artifactVersion");
- environmentVariables.clear("librariesBomVersion");
- environmentVariables.clear("repoMetadataFilePath");
- assertNull(System.getenv("artifactVersion"));
- assertNull(System.getenv("librariesBomVersion"));
- assertNull(System.getenv("repoMetadataFilePath"));
}
public void assertSameFileNames(List expected, List generated) {