Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alicejli committed Sep 20, 2023
1 parent 6c37eb4 commit 4af450d
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public static String getNamePretty() {
public static void setNamePretty(String namePretty) {
RepoMetadata.namePretty = namePretty;
}
public String getApiShortName(){

public String getApiShortName() {
return apiShortName;
}

public static void setApiShortName(String apiShortName) {
RepoMetadata.apiShortName = apiShortName;
}
Expand Down Expand Up @@ -96,14 +98,15 @@ public static void setApiId(String apiId) {
// artifactId is parsed from distributionName
public static String getArtifactId() {
String substrings[] = distributionName.split(":");
return substrings[substrings.length -1];
return substrings[substrings.length - 1];
}

// GithubLink is created from repo and repoShort
public static String getGithubLink() {
String githubRootUri = "https://github.com/";
String githubLink = githubRootUri + repo;
if (Objects.equals(repo, "googleapis/google-cloud-java") || Objects.equals(repo, "googleapis/sdk-platform-java")){
if (Objects.equals(repo, "googleapis/google-cloud-java")
|| Objects.equals(repo, "googleapis/sdk-platform-java")) {
githubLink = githubLink + "/tree/main/" + repoShort;
}
return githubLink;
Expand All @@ -114,18 +117,19 @@ public static String getMavenLink() {
String mavenRootUri = "https://central.sonatype.com/artifact/";
String substrings[] = distributionName.split(":");
String groupName = substrings[0];
String artifactId = substrings[substrings.length -1];
String artifactId = substrings[substrings.length - 1];
String mavenLink = mavenRootUri + groupName + "/" + artifactId;
return mavenLink;
}

public static RepoMetadata parseRepoMetadata(String fileName) {
RepoMetadata repoMetadata = new RepoMetadata();
Gson gson = new Gson();
try(BufferedReader reader = new BufferedReader(new FileReader(fileName))){
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
// convert .repo-metadata.json to a Map of values
Map<?, ?> map = gson.fromJson(reader, Map.class);
for (Map.Entry<?, ?> entry : map.entrySet()) {
switch (entry.getKey().toString()){
switch (entry.getKey().toString()) {
case "api_shortname":
repoMetadata.setApiShortName(entry.getValue().toString());
break;
Expand Down Expand Up @@ -159,4 +163,4 @@ public static RepoMetadata parseRepoMetadata(String fileName) {
}
return repoMetadata;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ public boolean build() {
FileUtil.dumpToFile(processor.tocFile);

// New library overview page
// TODO: @alicejli may make sense to create a super filesBuilder class to combines Yml files with the new overview.md files since those are not technically yml files
if(!disableLibraryOverview){
LibraryOverviewFile libraryOverviewFile = new LibraryOverviewFile(outputPath, "libraryOverview.md");
// TODO: @alicejli may make sense to create a super filesBuilder class to combines Yml files
// with the new overview.md files since those are not technically yml files
if (!disableLibraryOverview) {
LibraryOverviewFile libraryOverviewFile =
new LibraryOverviewFile(outputPath, "libraryOverview.md");
FileUtil.dumpToFile(libraryOverviewFile);
}

Expand All @@ -89,7 +91,8 @@ public boolean build() {
@VisibleForTesting
class Processor {
// table of contents
final TocFile tocFile = new TocFile(outputPath, projectName, disableChangelog, disableLibraryOverview);
final TocFile tocFile =
new TocFile(outputPath, projectName, disableChangelog, disableLibraryOverview);
// overview page
// TODO: @alicejli eventually look to replace this with the new library overview
final MetadataFile projectMetadataFile = new MetadataFile(outputPath, "overview.yml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@

public class LibraryOverviewFile implements YmlFile {
// TODO: @alicejli Update to use generic .repo-metadata.json file if it exists
String repoMetadataFileName = "/home/alicejli/java-docfx-doclet/third_party/docfx-doclet-143274/src/test/java/com/microsoft/samples/.repo-metadata.json";
String repoMetadataFileName =
"/home/alicejli/java-docfx-doclet/third_party/docfx-doclet-143274/src/test/java/com/microsoft/samples/.repo-metadata.json";
RepoMetadata repoMetadata = RepoMetadata.parseRepoMetadata(repoMetadataFileName);

private final String LIBRARY_OVERVIEW_FILE_HEADER = "# " + repoMetadata.getArtifactId() + " overview\n\n";
private final String LIBRARY_OVERVIEW_FILE_HEADER =
"# " + repoMetadata.getArtifactId() + " overview\n\n";

private final String LIBRARY_OVERVIEW_KEY_REFERENCE_HEADER = "## Key Reference Links\n" + repoMetadata.getApiDescription() + "\n\n";
private final String LIBRARY_OVERVIEW_KEY_REFERENCE_HEADER =
"## Key Reference Links\n" + repoMetadata.getApiDescription() + "\n\n";

private final String LIBRARY_OVERVIEW_KEY_REFERENCE_TABLE =
"<table>\n"
+ " <tr>\n"
+ " <td><a href=\"" + repoMetadata.getClientDocumentationUri() +"\">" + repoMetadata.getNamePretty() + " product reference</a></td>\n"
+ " <td><a href=\"" + repoMetadata.getGithubLink() + "\">Github repository (includes samples)</a></td>\n"
+ " <td><a href=\"" + repoMetadata.getMavenLink() + "\">Maven artifact</a></td>\n"
+ " <td><a href=\""
+ repoMetadata.getClientDocumentationUri()
+ "\">"
+ repoMetadata.getNamePretty()
+ " product reference</a></td>\n"
+ " <td><a href=\""
+ repoMetadata.getGithubLink()
+ "\">Github repository (includes samples)</a></td>\n"
+ " <td><a href=\""
+ repoMetadata.getMavenLink()
+ "\">Maven artifact</a></td>\n"
+ " </tr>\n"
+ " </table>"
+ "\n\n";
Expand All @@ -28,15 +39,19 @@ public class LibraryOverviewFile implements YmlFile {
"## Getting Started\n"
+ "In order to use this library, you first need to go through the following steps:"
+ "\n\n"
+ "- [Install a JDK (Java Development Kit)](https://cloud.google.com/java/docs/setup#install_a_jdk_java_development_kit)\n"
+ "- [Select or create a Cloud Platform project](https://console.cloud.google.com/project)\n"
+ "- [Enable billing for your project](\"https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)\n"
+ "- [Enable the API](https://console.cloud.google.com/apis/library/" + repoMetadata.getApiShortName() + ".googleapis.com)\n"
+ "- [Set up authentication](https://cloud.google.com/docs/authentication/client-libraries)\n\n";
+ "- [Install a JDK (Java Development Kit)](https://cloud.google.com/java/docs/setup#install_a_jdk_java_development_kit)\n"
+ "- [Select or create a Cloud Platform project](https://console.cloud.google.com/project)\n"
+ "- [Enable billing for your project](\"https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)\n"
+ "- [Enable the API](https://console.cloud.google.com/apis/library/"
+ repoMetadata.getApiShortName()
+ ".googleapis.com)\n"
+ "- [Set up authentication](https://cloud.google.com/docs/authentication/client-libraries)\n\n";

private final String LIBRARY_OVERVIEW_CLIENT_INSTALLATION_HEADER =
"## Use the " + repoMetadata.getNamePretty() + " for Java\n"
+ "To ensure that your project uses compatible versions of the libraries\n"
"## Use the "
+ repoMetadata.getNamePretty()
+ " for Java\n"
+ "To ensure that your project uses compatible versions of the libraries\n"
+ "and their component artifacts, import `com.google.cloud:libraries-bom` and use\n"
+ "the BOM to specify dependency versions. Be sure to remove any versions that you\n"
+ "set previously. For more information about\n"
Expand All @@ -60,7 +75,9 @@ public class LibraryOverviewFile implements YmlFile {
+ " &lt;groupId&gt;com.google.cloud&lt;/groupId&gt;\n"
+ " &lt;artifactId&gt;libraries-bom&lt;/artifactId&gt;\n"
// TODO: @alicejli determine best way to pull in libraries-bom version for this
+ " &lt;version&gt;" + "26.18.0" + "&lt;/version&gt;\n"
+ " &lt;version&gt;"
+ "26.18.0"
+ "&lt;/version&gt;\n"
+ " &lt;type&gt;pom&lt;/type&gt;\n"
+ " &lt;scope&gt;import&lt;/scope&gt;\n"
+ " &lt;/dependency&gt;\n"
Expand All @@ -69,7 +86,9 @@ public class LibraryOverviewFile implements YmlFile {
+ "&lt;dependencies&gt;\n"
+ " &lt;dependency&gt;\n"
+ " &lt;groupId&gt;com.google.cloud&lt;/groupId&gt;\n"
+ " &lt;artifactId&gt;" + repoMetadata.getArtifactId() + "&lt;/artifactId&gt;\n"
+ " &lt;artifactId&gt;"
+ repoMetadata.getArtifactId()
+ "&lt;/artifactId&gt;\n"
+ " &lt;/dependency&gt;\n"
+ "&lt;/dependencies&gt;\n"
+ "</pre>\n"
Expand All @@ -84,8 +103,12 @@ public class LibraryOverviewFile implements YmlFile {
+ "artifact.</p>\n"
+ "<pre class=\"prettyprint lang-Groovy devsite-click-to-copy\">\n"
// TODO: @alicejli determine best way to pull in libraries-bom version for this
+ "implementation platform(&#39;com.google.cloud:libraries-bom:" + "26.18.0" + "&#39;)\n"
+ "implementation &#39;" + repoMetadata.getDistributionName() + "&#39;\n"
+ "implementation platform(&#39;com.google.cloud:libraries-bom:"
+ "26.18.0"
+ "&#39;)\n"
+ "implementation &#39;"
+ repoMetadata.getDistributionName()
+ "&#39;\n"
+ "</pre>\n"
+ "<p>The <code>platform</code> and <code>enforcedPlatform</code> keywords supply dependency versions\n"
+ "declared in a BOM. The <code>enforcedPlatform</code> keyword enforces the dependency\n"
Expand All @@ -108,37 +131,44 @@ public class LibraryOverviewFile implements YmlFile {
+ "<p>To use the latest version of this library, add this to your dependencies:</p>\n"
+ "<pre class=\"prettyprint lang-Scala devsite-click-to-copy\">\n"
// TODO: @alicejli determine best way to pull in artifact version for this
+ "libraryDependencies += &quot;com.google.cloud&quot; % &quot;" + repoMetadata.getArtifactId() + "&quot; % &quot;" + "0.18.0" + "&quot;\n"
+ "libraryDependencies += &quot;com.google.cloud&quot; % &quot;"
+ repoMetadata.getArtifactId()
+ "&quot; % &quot;"
+ "0.18.0"
+ "&quot;\n"
+ "</pre>\n"
+ "</section>\n"
+ "</devsite-selector>\n"
+ "</div>\n\n";
private final String LIBRARY_OVERVIEW_PACKAGE_SELECTION_SECTION =
"## Which package should I use?\n"
// TODO: @alicejli determine best way to pull in the link to the package for this
+ "The recommended package for new applications is [" + "com.google.api.apikeys.v2" + "](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.google.api.apikeys.v2).\n"
+ "The recommended package for new applications is ["
+ "com.google.api.apikeys.v2"
+ "](https://cloud.google.com/java/docs/reference/google-cloud-apikeys/latest/com.google.api.apikeys.v2).\n"
+ "\n"
+ "Each Cloud Java client library may contain multiple packages. Each package corresponds to a published version of the service.\n"
+ "We recommend using the latest stable version for new production applications, which can be identified by the largest numeric version that does not contain a suffix.\n"
+ "For example, if a client library has two packages: `v1` and `v2alpha`, then the latest stable version is `v1`.\n"
+ "If you use an unstable release, breaking changes may be introduced when upgrading.\n\n";
private final String outputPath;
private String fileName;

public LibraryOverviewFile(String outputPath, String fileName) {
this.outputPath = outputPath;
this.fileName = fileName;
}

@JsonIgnore
@Override
public String getFileContent() {
return LIBRARY_OVERVIEW_FILE_HEADER
+ LIBRARY_OVERVIEW_KEY_REFERENCE_HEADER
+ LIBRARY_OVERVIEW_KEY_REFERENCE_TABLE
+ LIBRARY_OVERVIEW_GETTING_STARTED_SECTION
+ LIBRARY_OVERVIEW_CLIENT_INSTALLATION_HEADER
+ LIBRARY_OVERVIEW_CLIENT_INSTALLATION_SECTION
+ LIBRARY_OVERVIEW_PACKAGE_SELECTION_SECTION
;
+ LIBRARY_OVERVIEW_KEY_REFERENCE_HEADER
+ LIBRARY_OVERVIEW_KEY_REFERENCE_TABLE
+ LIBRARY_OVERVIEW_GETTING_STARTED_SECTION
+ LIBRARY_OVERVIEW_CLIENT_INSTALLATION_HEADER
+ LIBRARY_OVERVIEW_CLIENT_INSTALLATION_SECTION
+ LIBRARY_OVERVIEW_PACKAGE_SELECTION_SECTION;
}

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public class TocContents {
private final String projectName;
private final List<Object> contents = new ArrayList<>();

public TocContents(String projectName, boolean disableChangelog, boolean disableLibraryOverview, List<TocItem> items) {
public TocContents(
String projectName,
boolean disableChangelog,
boolean disableLibraryOverview,
List<TocItem> items) {
this.projectName = projectName;

if (projectName == null || projectName.equals("")) {
Expand All @@ -35,7 +39,10 @@ public TocContents(String projectName, boolean disableChangelog, boolean disable
}

private void createTocContents(
String projectName, boolean disableChangelog, boolean disableLibraryOverview, List<TocItem> items) {
String projectName,
boolean disableChangelog,
boolean disableLibraryOverview,
List<TocItem> items) {
List<Object> tocItems = new ArrayList<>();
// combine guides and tocItems
tocItems.add(new Guide("Overview", "overview.html"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public class TocFile extends ArrayList<TocItem> implements YmlFile {

private final boolean disableLibraryOverview;

public TocFile(String outputPath, String projectName, boolean disableChangelog,
public TocFile(
String outputPath,
String projectName,
boolean disableChangelog,
boolean disableLibraryOverview) {
this.outputPath = outputPath;
this.projectName = projectName;
Expand All @@ -35,13 +38,13 @@ protected void sortByUid() {
@Override
public String getFileContent() {
sortByUid();
List<Object> tocContents = new TocContents(projectName, disableChangelog,
disableLibraryOverview, this).getContents();
List<Object> tocContents =
new TocContents(projectName, disableChangelog, disableLibraryOverview, this).getContents();
return TOC_FILE_HEADER + YamlUtil.objectToYamlString(tocContents);
}

@Override
public String getFileNameWithPath() {
return outputPath + File.separator + TOC_FILE_NAME;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package com.microsoft.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;

public class LibraryOverviewFileTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.microsoft.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -51,7 +50,8 @@ public void setup() {
public void getContentsWithProjectName() {
// should include ProjectContents and Guides
List<Object> tocContents =
new TocContents(projectName, disableChangelog, disableLibraryOverview, tocItems).getContents();
new TocContents(projectName, disableChangelog, disableLibraryOverview, tocItems)
.getContents();

assertEquals("Should only include 1 item", tocContents.size(), 1);
assertEquals(
Expand All @@ -73,7 +73,8 @@ public void getContentsWithProjectName() {

assertEquals("Guide should be third", items.get(2).getClass(), Guide.class);
Guide libraryOverview = (Guide) items.get(2);
assertEquals("Second guide should be Library Overview", libraryOverview.getName(), "Library overview");
assertEquals(
"Second guide should be Library Overview", libraryOverview.getName(), "Library overview");

assertEquals("Item A should be fourth", items.get(3), tocItemA);
assertEquals("Item B should be fifth", items.get(4), tocItemB);
Expand All @@ -82,7 +83,8 @@ public void getContentsWithProjectName() {

@Test
public void getContentsNoProjectName() {
List<Object> tocContents = new TocContents("", disableChangelog, disableLibraryOverview, tocItems).getContents();
List<Object> tocContents =
new TocContents("", disableChangelog, disableLibraryOverview, tocItems).getContents();

// should not include ProjectContents or Guides
assertEquals("Should be 3 items", tocContents.size(), 3);
Expand All @@ -95,7 +97,8 @@ public void getContentsNoProjectName() {
public void getContentsWithDisabledChangelog() {
disableChangelog = true;
List<Object> tocContents =
new TocContents(projectName, disableChangelog, disableLibraryOverview, tocItems).getContents();
new TocContents(projectName, disableChangelog, disableLibraryOverview, tocItems)
.getContents();

ProjectContents contents = (ProjectContents) tocContents.get(0);
List<Object> items = contents.getItems();
Expand All @@ -105,7 +108,9 @@ public void getContentsWithDisabledChangelog() {
assertEquals("First guide should be Overview", overview.getName(), "Overview");
Guide libraryOverview = (Guide) items.get(1);
assertEquals(
"Second item should be Library Overview guide", libraryOverview.getName(), "Library overview");
"Second item should be Library Overview guide",
libraryOverview.getName(),
"Library overview");
assertEquals("Item A should be third", items.get(2), tocItemA);
assertEquals("Item B should be fourth", items.get(3), tocItemB);
assertEquals("Item C should be fifth", items.get(4), tocItemC);
Expand All @@ -115,7 +120,8 @@ public void getContentsWithDisabledChangelog() {
public void getContentsWithDisabledLibraryOverview() {
disableLibraryOverview = true;
List<Object> tocContents =
new TocContents(projectName, disableChangelog, disableLibraryOverview, tocItems).getContents();
new TocContents(projectName, disableChangelog, disableLibraryOverview, tocItems)
.getContents();

ProjectContents contents = (ProjectContents) tocContents.get(0);
List<Object> items = contents.getItems();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.microsoft.util;
// TODO: @alicejli add unit tests
public class RepoMetadataTest {

}
// TODO: @alicejli add unit tests
public class RepoMetadataTest {}

0 comments on commit 4af450d

Please sign in to comment.