Skip to content

Commit 8e758db

Browse files
sobychackomarkpollack
authored andcommitted
Introduce checkstyle plugin
- Based on https://github.com/spring-io/spring-javaformat - In this iteration, checkstyles are only enabled for spring-ai-core
1 parent 33a7241 commit 8e758db

File tree

1,412 files changed

+25662
-20628
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,412 files changed

+25662
-20628
lines changed

.devcontainer/scripts/onCreateCommand.sh

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/bin/bash
22

3+
#
4+
# Copyright 2023-2024 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
set -x
420

521
az extension add --name spring

.editorconfig

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ indent_style = tab
88
indent_size = 4
99
continuation_indent_size = 8
1010
end_of_line = lf
11+
12+
insert_final_newline = true

.mvn/extensions.xml

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2023-2024 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
218
<extensions>
319
<extension>
420
<groupId>fr.jcgay.maven</groupId>

.mvn/wrapper/maven-wrapper.properties

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
# Licensed to the Apache Software Foundation (ASF) under one
2-
# or more contributor license agreements. See the NOTICE file
3-
# distributed with this work for additional information
4-
# regarding copyright ownership. The ASF licenses this file
5-
# to you under the Apache License, Version 2.0 (the
6-
# "License"); you may not use this file except in compliance
7-
# with the License. You may obtain a copy of the License at
81
#
9-
# https://www.apache.org/licenses/LICENSE-2.0
2+
# Copyright 2023-2024 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
1015
#
11-
# Unless required by applicable law or agreed to in writing,
12-
# software distributed under the License is distributed on an
13-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
# KIND, either express or implied. See the License for the
15-
# specific language governing permissions and limitations
16-
# under the License.
1716
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
1817
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar

document-readers/markdown-reader/pom.xml

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2023-2024 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
218
<project xmlns="http://maven.apache.org/POM/4.0.0"
319
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
420
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

document-readers/markdown-reader/src/main/java/org/springframework/ai/reader/markdown/MarkdownDocumentReader.java

+58-31
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
1+
/*
2+
* Copyright 2023-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ai.reader.markdown;
218

3-
import org.commonmark.node.*;
19+
import java.io.IOException;
20+
import java.io.InputStreamReader;
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
import org.commonmark.node.AbstractVisitor;
25+
import org.commonmark.node.BlockQuote;
26+
import org.commonmark.node.Code;
27+
import org.commonmark.node.FencedCodeBlock;
28+
import org.commonmark.node.HardLineBreak;
29+
import org.commonmark.node.Heading;
30+
import org.commonmark.node.ListItem;
31+
import org.commonmark.node.Node;
32+
import org.commonmark.node.SoftLineBreak;
33+
import org.commonmark.node.Text;
34+
import org.commonmark.node.ThematicBreak;
435
import org.commonmark.parser.Parser;
36+
537
import org.springframework.ai.document.Document;
638
import org.springframework.ai.document.DocumentReader;
739
import org.springframework.ai.reader.markdown.config.MarkdownDocumentReaderConfig;
840
import org.springframework.core.io.DefaultResourceLoader;
941
import org.springframework.core.io.Resource;
1042

11-
import java.io.IOException;
12-
import java.io.InputStreamReader;
13-
import java.util.ArrayList;
14-
import java.util.List;
15-
1643
/**
1744
* Reads the given Markdown resource and groups headers, paragraphs, or text divided by
1845
* horizontal lines (depending on the
@@ -58,10 +85,10 @@ public MarkdownDocumentReader(Resource markdownResource, MarkdownDocumentReaderC
5885
*/
5986
@Override
6087
public List<Document> get() {
61-
try (var input = markdownResource.getInputStream()) {
62-
Node node = parser.parseReader(new InputStreamReader(input));
88+
try (var input = this.markdownResource.getInputStream()) {
89+
Node node = this.parser.parseReader(new InputStreamReader(input));
6390

64-
DocumentVisitor documentVisitor = new DocumentVisitor(config);
91+
DocumentVisitor documentVisitor = new DocumentVisitor(this.config);
6592
node.accept(documentVisitor);
6693

6794
return documentVisitor.getDocuments();
@@ -90,7 +117,7 @@ public DocumentVisitor(MarkdownDocumentReaderConfig config) {
90117

91118
@Override
92119
public void visit(org.commonmark.node.Document document) {
93-
currentDocumentBuilder = Document.builder();
120+
this.currentDocumentBuilder = Document.builder();
94121
super.visit(document);
95122
}
96123

@@ -102,7 +129,7 @@ public void visit(Heading heading) {
102129

103130
@Override
104131
public void visit(ThematicBreak thematicBreak) {
105-
if (config.horizontalRuleCreateDocument) {
132+
if (this.config.horizontalRuleCreateDocument) {
106133
buildAndFlush();
107134
}
108135
super.visit(thematicBreak);
@@ -128,32 +155,32 @@ public void visit(ListItem listItem) {
128155

129156
@Override
130157
public void visit(BlockQuote blockQuote) {
131-
if (!config.includeBlockquote) {
158+
if (!this.config.includeBlockquote) {
132159
buildAndFlush();
133160
}
134161

135162
translateLineBreakToSpace();
136-
currentDocumentBuilder.withMetadata("category", "blockquote");
163+
this.currentDocumentBuilder.withMetadata("category", "blockquote");
137164
super.visit(blockQuote);
138165
}
139166

140167
@Override
141168
public void visit(Code code) {
142-
currentParagraphs.add(code.getLiteral());
143-
currentDocumentBuilder.withMetadata("category", "code_inline");
169+
this.currentParagraphs.add(code.getLiteral());
170+
this.currentDocumentBuilder.withMetadata("category", "code_inline");
144171
super.visit(code);
145172
}
146173

147174
@Override
148175
public void visit(FencedCodeBlock fencedCodeBlock) {
149-
if (!config.includeCodeBlock) {
176+
if (!this.config.includeCodeBlock) {
150177
buildAndFlush();
151178
}
152179

153180
translateLineBreakToSpace();
154-
currentParagraphs.add(fencedCodeBlock.getLiteral());
155-
currentDocumentBuilder.withMetadata("category", "code_block");
156-
currentDocumentBuilder.withMetadata("lang", fencedCodeBlock.getInfo());
181+
this.currentParagraphs.add(fencedCodeBlock.getLiteral());
182+
this.currentDocumentBuilder.withMetadata("category", "code_block");
183+
this.currentDocumentBuilder.withMetadata("lang", fencedCodeBlock.getInfo());
157184

158185
buildAndFlush();
159186

@@ -163,11 +190,11 @@ public void visit(FencedCodeBlock fencedCodeBlock) {
163190
@Override
164191
public void visit(Text text) {
165192
if (text.getParent() instanceof Heading heading) {
166-
currentDocumentBuilder.withMetadata("category", "header_%d".formatted(heading.getLevel()))
193+
this.currentDocumentBuilder.withMetadata("category", "header_%d".formatted(heading.getLevel()))
167194
.withMetadata("title", text.getLiteral());
168195
}
169196
else {
170-
currentParagraphs.add(text.getLiteral());
197+
this.currentParagraphs.add(text.getLiteral());
171198
}
172199

173200
super.visit(text);
@@ -176,29 +203,29 @@ public void visit(Text text) {
176203
public List<Document> getDocuments() {
177204
buildAndFlush();
178205

179-
return documents;
206+
return this.documents;
180207
}
181208

182209
private void buildAndFlush() {
183-
if (!currentParagraphs.isEmpty()) {
184-
String content = String.join("", currentParagraphs);
210+
if (!this.currentParagraphs.isEmpty()) {
211+
String content = String.join("", this.currentParagraphs);
185212

186-
Document.Builder builder = currentDocumentBuilder.withContent(content);
213+
Document.Builder builder = this.currentDocumentBuilder.withContent(content);
187214

188-
config.additionalMetadata.forEach(builder::withMetadata);
215+
this.config.additionalMetadata.forEach(builder::withMetadata);
189216

190217
Document document = builder.build();
191218

192-
documents.add(document);
219+
this.documents.add(document);
193220

194-
currentParagraphs.clear();
221+
this.currentParagraphs.clear();
195222
}
196-
currentDocumentBuilder = Document.builder();
223+
this.currentDocumentBuilder = Document.builder();
197224
}
198225

199226
private void translateLineBreakToSpace() {
200-
if (!currentParagraphs.isEmpty()) {
201-
currentParagraphs.add(" ");
227+
if (!this.currentParagraphs.isEmpty()) {
228+
this.currentParagraphs.add(" ");
202229
}
203230
}
204231

document-readers/markdown-reader/src/main/java/org/springframework/ai/reader/markdown/config/MarkdownDocumentReaderConfig.java

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
/*
2+
* Copyright 2023-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ai.reader.markdown.config;
218

19+
import java.util.HashMap;
20+
import java.util.Map;
21+
322
import org.springframework.ai.document.Document;
423
import org.springframework.ai.reader.markdown.MarkdownDocumentReader;
524
import org.springframework.util.Assert;
625

7-
import java.util.HashMap;
8-
import java.util.Map;
9-
1026
/**
1127
* Common configuration for the {@link MarkdownDocumentReader}.
1228
*
@@ -23,10 +39,10 @@ public class MarkdownDocumentReaderConfig {
2339
public final Map<String, Object> additionalMetadata;
2440

2541
public MarkdownDocumentReaderConfig(Builder builder) {
26-
horizontalRuleCreateDocument = builder.horizontalRuleCreateDocument;
27-
includeCodeBlock = builder.includeCodeBlock;
28-
includeBlockquote = builder.includeBlockquote;
29-
additionalMetadata = builder.additionalMetadata;
42+
this.horizontalRuleCreateDocument = builder.horizontalRuleCreateDocument;
43+
this.includeCodeBlock = builder.includeCodeBlock;
44+
this.includeBlockquote = builder.includeBlockquote;
45+
this.additionalMetadata = builder.additionalMetadata;
3046
}
3147

3248
/**

document-readers/markdown-reader/src/test/java/org/springframework/ai/reader/markdown/MarkdownDocumentReaderTest.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1+
/*
2+
* Copyright 2023-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ai.reader.markdown;
218

19+
import java.util.List;
20+
import java.util.Map;
21+
322
import org.junit.jupiter.api.Test;
23+
424
import org.springframework.ai.document.Document;
525
import org.springframework.ai.reader.markdown.config.MarkdownDocumentReaderConfig;
626

7-
import java.util.List;
8-
import java.util.Map;
9-
1027
import static org.assertj.core.api.Assertions.assertThat;
1128
import static org.assertj.core.groups.Tuple.tuple;
1229

document-readers/pdf-reader/pom.xml

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2023-2024 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
218
<project xmlns="http://maven.apache.org/POM/4.0.0"
319
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
420
<modelVersion>4.0.0</modelVersion>

0 commit comments

Comments
 (0)