Skip to content

Commit

Permalink
recognize kdoc-api as pointing to kdoc zip (project-version-kdoc.zip)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbasle committed Sep 21, 2017
1 parent 3c48d25 commit 6c71bbf
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
32 changes: 26 additions & 6 deletions src/main/java/io/projectreactor/DocUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,41 @@ public static String moduleToUrl(String reqUri, String versionType,
String requestedModuleName, String requestedVersion, Module actualModule,
String actualVersion) {
//protect against incomplete root api/reference path (offset is set with final / in mind)
if (reqUri.endsWith("/api") || reqUri.endsWith("/reference")) reqUri += "/";
if (reqUri.endsWith("/api")
|| reqUri.endsWith("/reference")
|| reqUri.endsWith("/kdoc-api")) reqUri += "/";

boolean isJavadoc = reqUri.contains("/api/");

int offset = isJavadoc ? 12 : 18;
if (reqUri.contains("/api/")) {
return moduleToArtifactUrl(reqUri, versionType, requestedModuleName,
requestedVersion, actualModule, actualVersion,
12, "index.html", "-javadoc.jar", "");
}
else if (reqUri.contains("/kdoc-api/")) {
return moduleToArtifactUrl(reqUri, versionType, requestedModuleName,
requestedVersion, actualModule, actualVersion,
17, actualModule.getArtifactId() + "/index.html", "-kdoc.zip", "");
}
else {
return moduleToArtifactUrl(reqUri, versionType, requestedModuleName,
requestedVersion, actualModule, actualVersion,
18, "docs/index.html", ".zip", "-docs");
}
}

public static String moduleToArtifactUrl(String reqUri, String versionType,
String requestedModuleName, String requestedVersion, Module actualModule,
String actualVersion,
int offset, String indexFile, String suffix, String artifactSuffix) {
String file = reqUri.substring(offset + requestedModuleName.length() + requestedVersion.length());
if (file.isEmpty()) {
file = isJavadoc ? "index.html" : "docs/index.html";
file = indexFile;
}
String suffix = isJavadoc ? "-javadoc.jar" : ".zip";

//tempfix for non generic kafka doc in M1
boolean isKafkaM1 = actualModule.getArtifactId().contains("kafka")
&& actualVersion.equals("1.0.0.M1");

String artifactSuffix = isJavadoc ? "" : "-docs";
String url = "http://repo.spring.io/" + versionType
+ "/" + actualModule.getGroupId().replace(".", "/")
+ "/" + actualModule.getArtifactId() + (isKafkaM1 ? artifactSuffix : "")
Expand All @@ -125,4 +144,5 @@ public static String moduleToUrl(String reqUri, String versionType,

return url;
}

}
38 changes: 35 additions & 3 deletions src/test/java/io/projectreactor/DocUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,38 @@ public void findVersionType() throws Exception {
assertThat(DocUtils.findVersionType("foobar")).isEqualTo("release");
}

@Test
public void moduleToUrlKdocNoFile() {
String uri = "/docs/test/release/kdoc-api";
String url = DocUtils.moduleToUrl(uri, "repoType",
"test", "release",
urlModule, "testVersion");

assertThat(url).isEqualTo("http://repo.spring.io/repoType/fooGroup/fooArtifact/" +
"testVersion/fooArtifact-testVersion-kdoc.zip!/fooArtifact/index.html");
}

@Test
public void moduleToUrlKdocNoFileFinalSlash() {
String uri = "/docs/test/release/kdoc-api/";
String url = DocUtils.moduleToUrl(uri, "repoType",
"test", "release",
urlModule, "testVersion");

assertThat(url).isEqualTo("http://repo.spring.io/repoType/fooGroup/fooArtifact/" +
"testVersion/fooArtifact-testVersion-kdoc.zip!/fooArtifact/index.html");
}

@Test
public void moduleToUrlKdocAndFile() {
String uri = "/docs/test/release/kdoc-api/fooArtifact/some/path/in/Doc.html";
String url = DocUtils.moduleToUrl(uri, "repoType",
"test", "release",
urlModule, "testVersion");

assertThat(url).isEqualTo("http://repo.spring.io/repoType/fooGroup/fooArtifact/" +
"testVersion/fooArtifact-testVersion-kdoc.zip!/fooArtifact/some/path/in/Doc.html");
}
@Test
public void moduleToUrlJavadocNoFile() {
String uri = "/docs/test/release/api";
Expand Down Expand Up @@ -224,7 +256,7 @@ public void moduleToUrlJavadocAndFile() {
}

@Test
public void moduleToUrlNotJavadocNoFile() {
public void moduleToUrlReferenceNoFile() {
String uri = "/docs/test/release/reference";
String url = DocUtils.moduleToUrl(uri, "repoType",
"test", "release",
Expand All @@ -235,7 +267,7 @@ public void moduleToUrlNotJavadocNoFile() {
}

@Test
public void moduleToUrlNotJavadocNoFileFinalSlash() {
public void moduleToUrlReferenceNoFileFinalSlash() {
String uri = "/docs/test/release/reference/";
String url = DocUtils.moduleToUrl(uri, "repoType",
"test", "release",
Expand All @@ -246,7 +278,7 @@ public void moduleToUrlNotJavadocNoFileFinalSlash() {
}

@Test
public void moduleToUrlNotJavadocAndFile() {
public void moduleToUrlReferenceAndFile() {
String uri = "/docs/test/release/reference/some/absolute/reference/page.html";
String url = DocUtils.moduleToUrl(uri, "repoType",
"test", "release",
Expand Down

0 comments on commit 6c71bbf

Please sign in to comment.