Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #42 Kotlin Doc rework after Dysprosium-RELEASE issues #43

Merged
merged 2 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/main/java/io/projectreactor/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,37 @@ private BiFunction<HttpServerRequest, HttpServerResponse, Publisher<Void>> pageN
);
}

private BiFunction<HttpServerRequest, HttpServerResponse, Publisher<Void>> kdocNotFound(
String moduleAndVersionInfo) {
String resolvedModule;
String resolvedVersion;
try {
String[] split = moduleAndVersionInfo.split(":");
resolvedModule = split[0];
resolvedVersion = split[1];
}
catch (Exception e) {
resolvedModule = "COULDNT_PARSE_MODULE: " + moduleAndVersionInfo;
resolvedVersion = "COULDNT_PARSE_VERSION: " + moduleAndVersionInfo;
}

final Map<String, Object> variables = new HashMap<>();
variables.put("actualModule", resolvedModule);
variables.put("actualVersion", resolvedVersion);

//the template parsing is dynamic to inject the requested url
return (req, resp) -> {
variables.put("requestedPage", req.path());
return resp
.status(404)
.sendString(
Mono.just(templateEngine.process("404NoKDoc",
new Context(Locale.US, variables)
))
);
};
}

private Publisher<Void> repoProxy(HttpServerRequest req, HttpServerResponse resp) {
String requestedModule = req.param("module");
String requestedVersion = req.param("version");
Expand All @@ -181,6 +212,9 @@ private Publisher<Void> repoProxy(HttpServerRequest req, HttpServerResponse resp
if (url == null) {
return pageNotFound().apply(req, resp);
}
else if (url.startsWith(DocUtils.WARNING_NO_KDOC)) {
return kdocNotFound(url.replace(DocUtils.WARNING_NO_KDOC, "")).apply(req, resp);
}

return client.headers(h -> filterXHeaders(req.requestHeaders()))
.get()
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/io/projectreactor/DocUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public static String moduleToUrl(String reqUri, String versionType,
12, "index.html", "-javadoc.jar", "", "");
}
else if (reqUri.contains("/kdoc-api/")) {
if (isKDocSpecialCases(actualModule.getName(), actualVersion)) {
return WARNING_NO_KDOC + actualModule.getArtifactId() + ":" + actualVersion;
}
url = moduleToKdocUrl(reqUri, versionType, requestedModuleName,
requestedVersion, actualModule, actualVersion);
}
Expand All @@ -122,6 +125,25 @@ else if (reqUri.contains("/kdoc-api/")) {
return url;
}

static boolean isKDocSpecialCases(String module, String version) {
switch (module) {
case "core":
case "extra":
case "test":
//core/addons/test >= Dysprosium
return !version.startsWith("3.0")
&& !version.startsWith("3.1")
&& !version.startsWith("3.2");
case "kotlin":
//exception for 1.0.0 pre-releases
//for now all kotlin >= 1.0.0.RELEASE have no kdoc
//TODO restrict to a version range when kdoc are eventually generated
return version.equals("1.0.0.RELEASE") || !version.startsWith("1.0.0");
default:
return false;
}
}

static String moduleToKdocUrl(String reqUri, String versionType,
String requestedModuleName, String requestedVersion, Module actualModule,
String actualVersion) {
Expand Down Expand Up @@ -173,4 +195,8 @@ static String moduleToArtifactUrl(String reqUri, String versionType,
return url;
}

/**
* static 404 we send to when a KDoc is requested for a special project+version combination that doesn't have them
*/
public static final String WARNING_NO_KDOC = "warningNoKDoc:";
}
58 changes: 58 additions & 0 deletions src/main/resources/static/templates/404NoKDoc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html th:replace="~{layout :: layout('404', ~{::title}, ~{::meta[@name='description']}, ~{::link}, ~{::body})}" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Project Reactor - 404 No Kotlin Doc Available</title>
<meta name="description" content="404 No Kotlin Doc Available" />
<link href="/assets/css/docs.css" media="all" rel="stylesheet"/>
</head>
<body>

<div class="content" id="content">
<section class="page404">
<img height="145px" src="/assets/img/404.jpg" />
<h1>The artifact and version you requested doesn't have Kotlin Doc.</h1>
<article>
<p class="desc">
You tried to access Kotlin Doc through <span class="version pre" th:text="${requestedPage}">PAGE PLACEHOLDER</span>.
<br/>Component <span class="version pre" th:text="${actualModule}">COMPONENT PLACEHOLDER</span>
and version <span class="version pre" th:text="${actualVersion}">VERSION PLACEHOLDER</span>
</p>
<p class="desc">
This combination doesn't have Kotlin Docs, because it belongs to one of the cases below:
<br/>
<table>
<tr>
<td>
<code>reactor-core</code> and <code>reactor-extra</code>, 3.3.0+ (Dysprosium and above)
</td>
<td>
The Kotlin extensions have been moved to <code>reactor-kotlin-extensions</code>
(see below)
</td>
</tr>
<tr>
<td>
<code>reactor-kotlin-extension</code> from version <code>1.0.0.RELEASE</code>
to version <code>to be determined</code>
</td>
<td>
A blocking bug in the dokka tooling prevents us from publishing kdoc and javadoc,
and we HAVE to publish javadocs on Maven Central.
<br/>
You can try to access javadocs instead (replace <code>kdoc-api</code> with <code>api</code>
in the <strong>original</strong> URL you tried to access).
</td>
</tr>
</table>
</p>
<p class="desc">
You can also find some helpful links in the footer below, or try a page from the navigation bar on top...
<br/>If you think this URL should have worked, please open an
<a href="https://github.com/reactor/projectreactor.io/issues">issue</a>.
</p>
</article>
</section>
</div>

</body>
</html>
18 changes: 12 additions & 6 deletions src/main/resources/static/templates/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ <h1>Reactor Core</h1>
<a href="/docs/core/release/api/">Release</a> |
<span th:if="${milestone.coreVersion} != null"><a href="/docs/core/milestone/api/">Milestone</a> |</span>
<a href="/docs/core/snapshot/api/">Snapshot</a> |
<a href="/docs/core/release/kdoc-api/">Kotlin Doc</a>
<!-- <a href="/docs/core/release/kdoc-api/">Kotlin Doc</a>-->
</div>
<div class="reference">
<strong>Reference</strong><br />
Expand Down Expand Up @@ -245,7 +245,7 @@ <h1>Reactor Test</h1>
<a href="/docs/test/release/api/">Release</a> |
<span th:if="${milestone.testVersion} != null"><a href="/docs/test/milestone/api/">Milestone</a> |</span>
<a href="/docs/test/snapshot/api/">Snapshot</a> |
<a href="/docs/test/release/kdoc-api/">Kotlin Doc</a>
<!-- <a href="/docs/test/release/kdoc-api/">Kotlin Doc</a>-->

</div>
<div class="reference">
Expand Down Expand Up @@ -702,11 +702,17 @@ <h1>Reactor Kotlin Extensions</h1>
Github
</a>
</div>
<!-- <div class="javadoc">-->
<!-- <strong>Kotlin Doc</strong><br />-->
<!-- <a href="/docs/kotlin/release/kdoc-api/">Release</a> |-->
<!-- <span th:if="${milestone.kotlinVersion} != null"><a href="/docs/kotlin/milestone/kdoc-api/">Milestone</a> |</span>-->
<!-- <a href="/docs/kotlin/snapshot/kdoc-api/">Snapshot</a>-->
<!-- </div>-->
<div class="javadoc">
<strong>Kotlin Doc</strong><br />
<a href="/docs/kotlin/release/kdoc-api/">Release</a> |
<span th:if="${milestone.kotlinVersion} != null"><a href="/docs/kotlin/milestone/kdoc-api/">Milestone</a> |</span>
<a href="/docs/kotlin/snapshot/kdoc-api/">Snapshot</a>
<strong>Javadoc (temporarily instead of Kotlin Doc)</strong><br />
<a href="/docs/kotlin/release/api/">Release</a> |
<span th:if="${milestone.kotlinVersion} != null"><a href="/docs/kotlin/milestone/api/">Milestone</a> |</span>
<a href="/docs/kotlin/snapshot/api/">Snapshot</a>
</div>
<div class="reference">
<strong>Reference</strong> <br/>
Expand Down
90 changes: 89 additions & 1 deletion src/test/java/io/projectreactor/DocUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.projectreactor;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;

import reactor.util.function.Tuple2;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -423,4 +423,92 @@ public void checkModuleVersionReleaseCandidateIsMilestone() {
assertThat(DocUtils.checkModuleVersion("3.1.0.RC2", "MILESTONE")).isTrue();
}

@Test
public void coreCaliforniumAndBelowIsNotKotlinDocSpecial() {
assertThat(DocUtils.isKDocSpecialCases("core", "3.0.0"))
.as("3.0.0").isFalse();
assertThat(DocUtils.isKDocSpecialCases("core", "3.1.0"))
.as("3.1.0").isFalse();
assertThat(DocUtils.isKDocSpecialCases("core", "3.2.0"))
.as("3.2.0").isFalse();
}

@Test
public void coreDysprosiumAndAboveIsKotlinDocSpecial() {
assertThat(DocUtils.isKDocSpecialCases("core", "3.3.0.M1"))
.as("3.0.0.M1").isTrue();
assertThat(DocUtils.isKDocSpecialCases("core", "3.3.1.RELEASE"))
.as("3.3.1.RELEASE").isTrue();
assertThat(DocUtils.isKDocSpecialCases("core", "3.4.0.x"))
.as("3.4.0.x").isTrue();
assertThat(DocUtils.isKDocSpecialCases("core", "3.6.1.BUILD-SNAPSHOT"))
.as("3.6.1.BUILD-SNAPSHOT").isTrue();
}

@Test
public void extraCaliforniumAndBelowIsNotIsKotlinDocSpecial() {
assertThat(DocUtils.isKDocSpecialCases("extra", "3.0.0"))
.as("3.0.0").isFalse();
assertThat(DocUtils.isKDocSpecialCases("extra", "3.1.0"))
.as("3.1.0").isFalse();
assertThat(DocUtils.isKDocSpecialCases("extra", "3.2.0"))
.as("3.2.0").isFalse();
}

@Test
public void extraDysprosiumAndAboveIsKotlinDocSpecial() {
assertThat(DocUtils.isKDocSpecialCases("extra", "3.3.0.M1"))
.as("3.0.0.M1").isTrue();
assertThat(DocUtils.isKDocSpecialCases("extra", "3.3.1.RELEASE"))
.as("3.3.1.RELEASE").isTrue();
assertThat(DocUtils.isKDocSpecialCases("extra", "3.4.0.x"))
.as("3.4.0.x").isTrue();
assertThat(DocUtils.isKDocSpecialCases("extra", "3.6.1.BUILD-SNAPSHOT"))
.as("3.6.1.BUILD-SNAPSHOT").isTrue();
}

@Test
public void testCaliforniumAndBelowIsNotKotlinDocSpecial() {
assertThat(DocUtils.isKDocSpecialCases("test", "3.0.0"))
.as("3.0.0").isFalse();
assertThat(DocUtils.isKDocSpecialCases("test", "3.1.0"))
.as("3.1.0").isFalse();
assertThat(DocUtils.isKDocSpecialCases("test", "3.2.0"))
.as("3.2.0").isFalse();
}

@Test
public void testDysprosiumAndAboveIsKotlinDocSpecial() {
assertThat(DocUtils.isKDocSpecialCases("test", "3.3.0.M1"))
.as("3.0.0.M1").isTrue();
assertThat(DocUtils.isKDocSpecialCases("test", "3.3.1.RELEASE"))
.as("3.3.1.RELEASE").isTrue();
assertThat(DocUtils.isKDocSpecialCases("test", "3.4.0.x"))
.as("3.4.0.x").isTrue();
assertThat(DocUtils.isKDocSpecialCases("test", "3.6.1.BUILD-SNAPSHOT"))
.as("3.6.1.BUILD-SNAPSHOT").isTrue();
}

@Test
public void kotlinExtensionsDysprosiumReleaseAndAboveIsKotlinDocSpecial() {
assertThat(DocUtils.isKDocSpecialCases("kotlin", "1.0.0.RELEASE"))
.as("1.0.0.RELEASE").isTrue();
assertThat(DocUtils.isKDocSpecialCases("kotlin", "1.0.1.BUILD-SNAPSHOT"))
.as("1.0.1.BUILD-SNAPSHOT").isTrue();
assertThat(DocUtils.isKDocSpecialCases("kotlin", "1.0.1.M1"))
.as("1.0.1.M1").isTrue();
assertThat(DocUtils.isKDocSpecialCases("kotlin", "1.0.1.RC1"))
.as("1.0.1.RC1").isTrue();
}

@Test
public void kotlinExtensionsDysprosiumPreReleasesAreNotKotlinDocSpecial() {
assertThat(DocUtils.isKDocSpecialCases("kotlin", "1.0.0.BUILD-SNAPSHOT"))
.as("1.0.0.BUILD-SNAPSHOT").isFalse();
assertThat(DocUtils.isKDocSpecialCases("kotlin", "1.0.0.M1"))
.as("1.0.0.M1").isFalse();
assertThat(DocUtils.isKDocSpecialCases("kotlin", "1.0.0.RC1"))
.as("1.0.0.RC1").isFalse();
}

}