You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/12/11 13:45:14 UTC
[isis] 01/02: ISIS-2473: tooling: house keeping
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 33aaf192a62b694c1e537ae3434c537be598885e
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Dec 11 13:26:59 2020 +0100
ISIS-2473: tooling: house keeping
---
.../j2adoc/test/ExampleReferenceRewriter.java | 101 +++++++++++++++++++
.../isis/tooling/j2adoc/test/J2AdocTest.java | 108 ++++-----------------
2 files changed, 120 insertions(+), 89 deletions(-)
diff --git a/tooling/java2adoc/src/test/java/org/apache/isis/tooling/j2adoc/test/ExampleReferenceRewriter.java b/tooling/java2adoc/src/test/java/org/apache/isis/tooling/j2adoc/test/ExampleReferenceRewriter.java
new file mode 100644
index 0000000..06443bb
--- /dev/null
+++ b/tooling/java2adoc/src/test/java/org/apache/isis/tooling/j2adoc/test/ExampleReferenceRewriter.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.tooling.j2adoc.test;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import org.apache.isis.commons.internal.base._Text;
+import org.apache.isis.commons.internal.collections._Lists;
+
+import lombok.val;
+
+class ExampleReferenceRewriter {
+
+ static void processAdocExampleReferences(File source) {
+
+ val lines = _Text.readLinesFromFile(source, StandardCharsets.UTF_8);
+
+ val exampleRefs = ExampleReferenceFinder.find(lines);
+ if(exampleRefs.isEmpty()) {
+ return;
+ }
+
+ System.out.println(exampleRefs);
+
+ val fixedLines = _Lists.<String>newArrayList();
+
+ val it = lines.iterator();
+ String line;
+ int i = 0;
+
+ for(val exRef : exampleRefs) {
+
+ // seek chapter start
+ while(i<exRef.chapterStart) {
+ line = it.next();
+ fixedLines.add(line);
+ ++i;
+ }
+
+ appendHeader(exRef.name, fixedLines);
+
+ // seek chapter end
+ while(i<exRef.chapterEnd) {
+ line = it.next();
+ fixedLines.add(line);
+ ++i;
+ }
+
+ appendFooter(fixedLines);
+
+ }
+
+ // seek document end
+ while(it.hasNext()) {
+ fixedLines.add(it.next());
+ }
+
+ _Text.writeLinesToFile(fixedLines, source, StandardCharsets.UTF_8);
+
+ }
+
+ // -- HELPER
+
+ private static void appendHeader(String key, List<String> lines) {
+ lines.add("== API");
+ lines.add("");
+ lines.add(String.format("include::system:generated:page$index/%s.adoc[leveloffset=+2]", key));
+ lines.add("");
+ lines.add("TODO example migration");
+ lines.add("");
+ lines.add(".Deprecated Docs");
+ lines.add("[WARNING]");
+ lines.add("================================");
+ lines.add("");
+ }
+
+ private static void appendFooter(List<String> lines) {
+ lines.add("");
+ lines.add("================================");
+ lines.add("");
+ }
+
+}
diff --git a/tooling/java2adoc/src/test/java/org/apache/isis/tooling/j2adoc/test/J2AdocTest.java b/tooling/java2adoc/src/test/java/org/apache/isis/tooling/j2adoc/test/J2AdocTest.java
index 2fab5ec..775c508 100644
--- a/tooling/java2adoc/src/test/java/org/apache/isis/tooling/j2adoc/test/J2AdocTest.java
+++ b/tooling/java2adoc/src/test/java/org/apache/isis/tooling/j2adoc/test/J2AdocTest.java
@@ -21,7 +21,6 @@ package org.apache.isis.tooling.j2adoc.test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.util.List;
import java.util.function.Consumer;
import org.junit.jupiter.api.Disabled;
@@ -29,7 +28,6 @@ import org.junit.jupiter.api.Test;
import org.apache.isis.commons.collections.Can;
import org.apache.isis.commons.internal.base._Text;
-import org.apache.isis.commons.internal.collections._Lists;
import org.apache.isis.commons.internal.collections._Sets;
import org.apache.isis.tooling.j2adoc.J2AdocContext;
import org.apache.isis.tooling.j2adoc.util.AsciiDocIncludeTagFilter;
@@ -46,7 +44,7 @@ import static guru.nidi.codeassert.config.Language.JAVA;
class J2AdocTest {
@Test //@Disabled
- void testJavaDocMining() {
+ void testJavaDoc2AsciiDoc() {
val analyzerConfig = AnalyzerConfigFactory
.maven(ProjectSampler.apacheIsisApplib(), Language.JAVA)
@@ -60,8 +58,8 @@ class J2AdocTest {
analyzerConfig.getSources(JAVA)
.stream()
- .filter(source->source.toString().contains("XmlSnapshotService"))
- //.peek(source->System.out.println("parsing source: " + source))
+ .filter(source->source.toString().contains("ExecutionMode"))
+ .peek(source->System.out.println("parsing source: " + source))
.forEach(j2aContext::add);
j2aContext.streamUnits()
@@ -76,21 +74,6 @@ class J2AdocTest {
});
}
- @Test @Disabled("DANGER!")
- void removeAdocExampleTags() throws IOException {
-
- val analyzerConfig = AnalyzerConfigFactory
- .maven(ProjectSampler.apacheIsisApplib(), Language.JAVA)
- .main();
-
- analyzerConfig.getSources(JAVA)
- .stream()
- .peek(source->System.out.println("parsing source: " + source))
- .filter(source->source.toString().contains("\\applib\\services\\"))
- .forEach(AsciiDocIncludeTagFilter::removeAdocExampleTags);
-
- }
-
@Test @Disabled
void adocDocMining() throws IOException {
@@ -116,6 +99,21 @@ class J2AdocTest {
}
@Test @Disabled("DANGER!")
+ void removeAdocExampleTags() throws IOException {
+
+ val analyzerConfig = AnalyzerConfigFactory
+ .maven(ProjectSampler.apacheIsisApplib(), Language.JAVA)
+ .main();
+
+ analyzerConfig.getSources(JAVA)
+ .stream()
+ .peek(source->System.out.println("parsing source: " + source))
+ .filter(source->source.toString().contains("\\applib\\services\\"))
+ .forEach(AsciiDocIncludeTagFilter::removeAdocExampleTags);
+
+ }
+
+ @Test @Disabled("DANGER!")
void adocExampleProcessing() throws IOException {
val adocFiles = ProjectSampler.adocFiles(ProjectSampler.apacheIsisRoot());
@@ -123,75 +121,7 @@ class J2AdocTest {
Can.ofCollection(adocFiles)
.stream()
//.filter(source->source.toString().contains("FactoryService"))
- .forEach(file->processAdocExampleTags(file));
- }
-
-
- private static void processAdocExampleTags(File source) {
-
- val lines = _Text.readLinesFromFile(source, StandardCharsets.UTF_8);
-
- val exampleRefs = ExampleReferenceFinder.find(lines);
- if(exampleRefs.isEmpty()) {
- return;
- }
-
- System.out.println(exampleRefs);
-
- val fixedLines = _Lists.<String>newArrayList();
-
- val it = lines.iterator();
- String line;
- int i = 0;
-
- for(val exRef : exampleRefs) {
-
- // seek chapter start
- while(i<exRef.chapterStart) {
- line = it.next();
- fixedLines.add(line);
- ++i;
- }
-
- appendHeader(exRef.name, fixedLines);
-
- // seek chapter end
- while(i<exRef.chapterEnd) {
- line = it.next();
- fixedLines.add(line);
- ++i;
- }
-
- appendFooter(fixedLines);
-
- }
-
- // seek document end
- while(it.hasNext()) {
- fixedLines.add(it.next());
- }
-
- _Text.writeLinesToFile(fixedLines, source, StandardCharsets.UTF_8);
-
- }
-
- private static void appendHeader(String key, List<String> lines) {
- lines.add("== API");
- lines.add("");
- lines.add(String.format("include::system:generated:page$index/%s.adoc[leveloffset=+2]", key));
- lines.add("");
- lines.add("TODO example migration");
- lines.add("");
- lines.add(".Deprecated Docs");
- lines.add("[WARNING]");
- lines.add("================================");
- lines.add("");
- }
-
- private static void appendFooter(List<String> lines) {
- lines.add("");
- lines.add("================================");
- lines.add("");
+ .forEach(ExampleReferenceRewriter::processAdocExampleReferences);
}