Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Attach binary to release
name: Attach binary on manual release

on:
release:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Java build & test
name: Build & Test

on: [push]

Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/pre_release_on_develop_merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Pre-release on develop merge

on:
workflow_run:
workflows: ["Build & Test"]
types:
- completed

jobs:
build-and-release:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'develop' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 18
uses: actions/setup-java@v3
with:
java-version: '18'
distribution: 'adopt'
cache: maven

- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Build with Maven
run: mvn package

- name: Extract Version from POM
id: extract_version
run: echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT

- name: Generate Timestamp
id: gen_timestamp
run: echo "timestamp=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_OUTPUT

- name: Create Pre-release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: prerelease-${{ steps.extract_version.outputs.version }}-${{ steps.gen_timestamp.outputs.timestamp }}
release_name: Pre-release ${{ steps.extract_version.outputs.version }} (${{ steps.gen_timestamp.outputs.timestamp }})
draft: false
prerelease: true

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./target/macatalauncher-${{ steps.extract_version.outputs.version }}.jar
asset_name: macatalauncher-${{ steps.extract_version.outputs.version }}-${{ steps.gen_timestamp.outputs.timestamp }}.jar
asset_content_type: application/java-archive
6 changes: 5 additions & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=dazednconfused_macata-launcher
run: |
mvn -B verify sonar:sonar \
-Dsonar.projectKey=dazednconfused_macata-launcher \
-Dsonar.organization=dazednconfused \
-Dsonar.token=$SONAR_TOKEN
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.0.24
19.0.2
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

## Requirements

MaCata requires Java 11 to run.
MaCata requires Java 19 to run.

## Installation

Expand Down Expand Up @@ -66,7 +66,8 @@ While not mandatory, if commits are not properly formatted, they may get rejecte
- [x] Soundpack management
- [x] Launcher autoupdater
- [x] Mod management
- [x] Bright Nights support
- [x] [Bright Nights](https://github.com/cataclysmbnteam/Cataclysm-BN) support
- [x] [The Last Generation](https://github.com/Cataclysm-TLG/Cataclysm-TLG) support

### Planned

Expand Down
6 changes: 6 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,10 @@
</module>
<module name="UnusedImports"/>
</module>

<module name="RegexpMultiline">
<property name="format" value="(\n\s*){3,}"/>
<property name="message" value="Too many consecutive blank lines."/>
<property name="severity" value="error"/>
</module>
</module>
38 changes: 26 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

<groupId>com.dazednconfused</groupId>
<artifactId>macatalauncher</artifactId>
<version>0.3.3</version>
<version>0.4.0</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<sonar.organization>dazednconfused</sonar.organization>
<sonar.organization>dazednconfused</sonar.organization> <!-- should match .github/workflows/sonarcloud.yml -->
<sonar.projectKey>dazednconfused_macata-launcher</sonar.projectKey> <!-- ^ditto -->
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.cpd.exclusions>**/MainWindow.java</sonar.cpd.exclusions>
<sonar.cpd.exclusions>**/gui/**</sonar.cpd.exclusions>
</properties>

<profiles>
Expand Down Expand Up @@ -102,16 +103,11 @@
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.dazednconfused.catalauncher.Application</mainClass>
</manifest>
</archive>
<mainClass>com.dazednconfused.catalauncher.Application</mainClass>
</configuration>
</plugin>

Expand Down Expand Up @@ -248,6 +244,24 @@
<version>3.0</version>
</dependency>

<dependency>
<groupId>li.flor</groupId>
<artifactId>native-j-file-chooser</artifactId>
<version>1.6.4</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19.0.2.1</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>19.0.2.1</version>
</dependency>

<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-all</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -27,6 +28,11 @@ public interface BaseDAO<T extends BaseEntity> {
* */
T insert(T t) throws DAOException;

/**
* Inserts the given {@link BaseEntity}(ies) into the table.
* */
int bulkInsert(Collection<T> t) throws DAOException;

/**
* Updates the given {@link BaseEntity}. It must have an ID set.
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ protected static Result<Throwable, Connection> openConnection(String database) {
).map(Result::success).recover(Result::failure).get();
}


/**
* Completely wipes this database of any and all data, <b>including</b> the underlying schema.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;

import org.slf4j.Logger;
Expand Down Expand Up @@ -43,7 +45,7 @@ public String getDatabaseName() {
public ModEntity insert(ModEntity entity) throws DAOException {
LOGGER.debug("Inserting ModEntity [{}]...", entity);

String sql = "INSERT INTO " + MODS_TABLE_NAME + "" +
String sql = "INSERT INTO " + MODS_TABLE_NAME + " " +
"(name, modinfo, created_date, updated_date) " +
"VALUES " +
"(?, ?, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP())";
Expand All @@ -61,6 +63,39 @@ public ModEntity insert(ModEntity entity) throws DAOException {
}
}

@Override
public int bulkInsert(Collection<ModEntity> entities) throws DAOException {

if (entities == null || entities.isEmpty()) {
LOGGER.warn("No entities provided for bulk insert. No operation shall be performed.");
return 0;
}

LOGGER.debug("Bulk inserting [{}] ModEntity(ies)...", entities.size());

String sql = "INSERT INTO " + MODS_TABLE_NAME + " " +
"(name, modinfo, created_date, updated_date) " +
"VALUES " +
"(?, ?, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP())";

try (Connection conn = this.getConnection(); PreparedStatement pstmt = conn.prepareStatement(sql)) {
for (ModEntity entity : entities) {
pstmt.setString(1, entity.getName());
pstmt.setString(2, entity.getModinfo());
pstmt.addBatch();
}

int[] results = pstmt.executeBatch();

int insertedCount = Arrays.stream(results).filter(result -> result > 0).sum();
LOGGER.debug("Bulk inserted [{}] ModEntity(ies)", insertedCount);
return insertedCount;
} catch (SQLException e) {
LOGGER.error("An error occurred during bulk insert of ModEntity(ies)", e);
throw new DAOException(e);
}
}

@Override
public ModEntity update(ModEntity entity) throws DAOException {
Optional<ModEntity> originalEntity = this.findById(entity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;

import org.slf4j.Logger;
Expand Down Expand Up @@ -41,7 +43,7 @@ public String getDatabaseName() {
public ModfileEntity insert(ModfileEntity entity) throws DAOException {
LOGGER.debug("Inserting ModfileEntity [{}]...", entity);

String sql = "INSERT INTO " + TABLE_NAME + "" +
String sql = "INSERT INTO " + TABLE_NAME + " " +
"(mod_id, path, hash, created_date, updated_date) " +
"VALUES " +
"(?, ?, ?, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP())";
Expand All @@ -60,6 +62,40 @@ public ModfileEntity insert(ModfileEntity entity) throws DAOException {
}
}

@Override
public int bulkInsert(Collection<ModfileEntity> entities) throws DAOException {

if (entities == null || entities.isEmpty()) {
LOGGER.warn("No entities provided for bulk insert. No operation shall be performed.");
return 0;
}

LOGGER.debug("Bulk inserting [{}] ModfileEntity(ies)...", entities.size());

String sql = "INSERT INTO " + TABLE_NAME + " " +
"(mod_id, path, hash, created_date, updated_date) " +
"VALUES " +
"(?, ?, ?, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP())";

try (Connection conn = this.getConnection(); PreparedStatement pstmt = conn.prepareStatement(sql)) {
for (ModfileEntity entity : entities) {
pstmt.setLong(1, entity.getModId());
pstmt.setString(2, entity.getPath());
pstmt.setString(3, entity.getHash());
pstmt.addBatch();
}

int[] results = pstmt.executeBatch();

int insertedCount = Arrays.stream(results).filter(result -> result > 0).sum();
LOGGER.debug("Bulk inserted [{}] ModfileEntity(ies)", insertedCount);
return insertedCount;
} catch (SQLException e) {
LOGGER.error("An error occurred during bulk insert of ModfileEntity(ies)", e);
throw new DAOException(e);
}
}

@Override
public ModfileEntity update(ModfileEntity entity) throws DAOException {
Optional<ModfileEntity> originalEntity = this.findById(entity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.dazednconfused.catalauncher.database.mod.entity.ModfileEntity;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -60,6 +61,20 @@ public ModEntity insert(ModEntity entity) throws DAOException {
return result;
}

@Override
public int bulkInsert(Collection<ModEntity> entities) throws DAOException {
LOGGER.debug("Bulk inserting [{}] ModEntity(ies)...", entities.size());

int insertedCount = (int) entities.stream()
.map(this::insert)
.filter(Objects::nonNull)
.count();

LOGGER.debug("Bulk inserted [{}] ModEntity(ies)", insertedCount);

return insertedCount;
}

@Override
public ModEntity update(ModEntity entity) throws DAOException {
LOGGER.debug("Updating ModEntity: [{}]", entity);
Expand Down Expand Up @@ -121,10 +136,11 @@ public List<ModEntity> findAll() throws DAOException {
private List<ModfileEntity> insertChildEntities(long modId, List<ModfileEntity> entities) throws DAOException {
LOGGER.debug("Inserting [{}] ModfileEntity(s) associated to modId [{}]", entities.size(), modId);

List<ModfileEntity> result = entities.stream()
this.modfileDAO.bulkInsert(entities.stream()
.peek(e -> e.setModId(modId)) // set/overwrite with entity ID
.map(modfileDAO::insert)
.collect(Collectors.toList());
.collect(Collectors.toList())
);
List<ModfileEntity> result = modfileDAO.findAllByModId(modId);

LOGGER.debug("Inserted [{}] ModfileEntity(s) associated to modId [{}]", result.size(), modId);

Expand Down
Loading
Loading