Skip to content

Commit

Permalink
Update java version to 21 (#90)
Browse files Browse the repository at this point in the history
* refactor: updated java to 21

* refactor: updated gradle wrapper to 8.7

* refactor: updated cicd to java 21

* chore: updated README.md

* refactor: added try catch for executioner

* refactor: added line trim for meaning.ftl

* refactor: removed shutdown invocation

* chore: added spotless

* style: style
  • Loading branch information
Dankoy authored May 6, 2024
1 parent a59c82c commit 8952f74
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dependencies_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/gradle-build-action@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/gradle-build-action@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ imported to anki

### Stack

* Java 17
* Spring boot 3.2.2
* Java 21
* Spring boot 3.2.5
* Spring shell
* Spring boot jdbc
* Caffeine cache
Expand Down
24 changes: 23 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.2.5'
id 'io.spring.dependency-management' version '1.1.5'
id 'com.diffplug.spotless' version '6.25.0'
}

apply plugin: "io.spring.dependency-management"
Expand All @@ -10,7 +11,7 @@ group = 'ru.dankoy'
version = '0.1.7-SNAPSHOT'

java {
sourceCompatibility = '17'
sourceCompatibility = '21'
}

configurations {
Expand Down Expand Up @@ -60,6 +61,9 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.liquibase:liquibase-core'

// spotless
implementation 'com.diffplug.spotless:spotless-lib:2.45.0'
}

test {
Expand All @@ -69,3 +73,21 @@ test {
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
}

spotless {
java {
target fileTree('.') {
include '**/*.java'
exclude '**/build/**', '**/build-*/**'
}
toggleOffOn()
googleJavaFormat('1.19.2')
.reflowLongStrings()
.formatJavadoc(true)
.reorderImports(false)
.groupArtifact('com.google.googlejavaformat:google-java-format')
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,53 +64,52 @@ public FileNameFormatterService getFileNameFormatterService() {
public void export(String sourceLanguage, String targetLanguage, List<String> options) {

List<AnkiData> ankiDataList = new CopyOnWriteArrayList<>();
ExecutorService executorService = Executors.newFixedThreadPool(THREADS);

List<Vocabulary> vocabulariesFull = vocabularyService.getAll();
List<Vocabulary> filtered = stateService.filterState(vocabulariesFull);
try (ExecutorService executorService = Executors.newFixedThreadPool(THREADS)) {
List<Vocabulary> vocabulariesFull = vocabularyService.getAll();
List<Vocabulary> filtered = stateService.filterState(vocabulariesFull);

if (!filtered.isEmpty()) {
if (!filtered.isEmpty()) {

if (filtered.size() < THREADS) {
if (filtered.size() < THREADS) {

latch = new CountDownLatch(filtered.size());
executorService.execute(
() -> asyncFunc(ankiDataList, filtered, sourceLanguage, targetLanguage, options));
latch = new CountDownLatch(filtered.size());
executorService.execute(
() -> asyncFunc(ankiDataList, filtered, sourceLanguage, targetLanguage, options));

} else {

latch = new CountDownLatch(THREADS);
List<Vocabulary> oneV = filtered.subList(0, filtered.size() / 2);
List<Vocabulary> twoV = filtered.subList((filtered.size() / 2), filtered.size());
} else {

executorService.execute(
() -> asyncFunc(ankiDataList, oneV, sourceLanguage, targetLanguage, options));
executorService.execute(
() -> asyncFunc(ankiDataList, twoV, sourceLanguage, targetLanguage, options));
}
latch = new CountDownLatch(THREADS);
List<Vocabulary> oneV = filtered.subList(0, filtered.size() / 2);
List<Vocabulary> twoV = filtered.subList((filtered.size() / 2), filtered.size());

try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new KorvoRootException("Interrupted while waiting for task completion", e);
}
executorService.execute(
() -> asyncFunc(ankiDataList, oneV, sourceLanguage, targetLanguage, options));
executorService.execute(
() -> asyncFunc(ankiDataList, twoV, sourceLanguage, targetLanguage, options));
}

executorService.shutdown();
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new KorvoRootException("Interrupted while waiting for task completion", e);
}

var template = templateCreatorService.create(ankiDataList);
var template = templateCreatorService.create(ankiDataList);

var ioService =
getIoService(
getFileProviderService(),
getFileNameFormatterService(),
filesProperties.getExportFileName());
ioService.print(template);
var ioService =
getIoService(
getFileProviderService(),
getFileNameFormatterService(),
filesProperties.getExportFileName());
ioService.print(template);

stateService.saveState(filtered);
stateService.saveState(filtered);

} else {
log.info("State is the same as database. Export is not necessary.");
} else {
log.info("State is the same as database. Export is not necessary.");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,22 @@ public String create(List<AnkiData> ankiDataList) {
// async with splitting list into chunks
int cores = Runtime.getRuntime().availableProcessors();
List<List<AnkiData>> splitted = splitToPartitions(ankiDataList, cores);
ExecutorService executorService = Executors.newFixedThreadPool(cores);

latch = new CountDownLatch(splitted.size());
try (ExecutorService executorService = Executors.newFixedThreadPool(cores)) {
latch = new CountDownLatch(splitted.size());

for (List<AnkiData> sp : splitted) {
executorService.execute(() -> convertToDto(dtos, sp));
}
for (List<AnkiData> sp : splitted) {
executorService.execute(() -> convertToDto(dtos, sp));
}

try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new KorvoRootException("Interrupted while waiting for task completion", e);
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new KorvoRootException("Interrupted while waiting for task completion", e);
}
}

executorService.shutdown();

// create full template
templateDataFull.put("ankiDataList", dtos);

Expand Down
44 changes: 22 additions & 22 deletions src/main/resources/templates/meaning.ftl
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<#if ankiData.transcription?? && ankiData.transcription?has_content>
<p>
transcription: ${ankiData.transcription}
</p>
<p> <#t>
transcription: ${ankiData.transcription}<#t>
</p><#t>
</#if>
<ul>
<ul><#t>
<#if ankiData.meanings?? && ankiData.meanings?has_content>
<#list ankiData.meanings as meaning>
<li><span style="color:yellow">${meaning.type()}</span>
<dl>
<li><span style="color:yellow">${meaning.type()}</span><#t>
<dl><#t>
<#if meaning.definitions()?has_content>
<dt><h5 style="margin-bottom:0;margin-top:0;color:blue">definitions</h5></dt>
<dt><h5 style="margin-bottom:0;margin-top:0;color:blue">definitions</h5></dt><#t>
<#list meaning.definitions() as definition>
<dd style="margin-bottom:10px">
<p style="margin-bottom: 0px">
* ${definition.info()}
</p>
<dd style="margin-bottom:10px"><#t>
<p style="margin-bottom: 0px"><#t>
* ${definition.info()}<#t>
</p><#t>
<#if definition.example()?? && definition.example()?has_content>
<p style="margin-top:1px">
<b>example</b>: <span><i>${definition.example()}</i></span>
</p>
<p style="margin-top:1px"><#t>
<b>example</b>: <span><i>${definition.example()}</i></span><#t>
</p><#t>
</#if>
</dd>
</dd><#t>
</#list>
</#if>
<#if meaning.synonyms()?has_content>
<dt><h5 style="margin-bottom:0;margin-top:0;color:green">synonyms</h5></dt>
<dt><h5 style="margin-bottom:0;margin-top:0;color:green">synonyms</h5></dt><#t>
<#list meaning.synonyms() as synonym>
<dd>${synonym}</dd>
<dd>${synonym}</dd><#t>
</#list>
</#if>
<#if meaning.antonyms()?has_content>
<dt><h5 style="margin-bottom:0;margin-top:10px;color:red">antonyms</h5></dt>
<dt><h5 style="margin-bottom:0;margin-top:10px;color:red">antonyms</h5></dt><#t>
<#list meaning.antonyms() as antonym>
<dd>${antonym}</dd>
<dd>${antonym}</dd><#t>
</#list>
</#if>
</dl>
</li>
</dl><#t>
</li><#t>
</#list>
</#if>
</ul>
</ul><#t>

0 comments on commit 8952f74

Please sign in to comment.