Add FileAccess class with many exceptions
All checks were successful
PRs & Pushes / build (push) Successful in 2m7s
PRs & Pushes / build-apidoc (push) Successful in 2m22s

The FileAccess class is an almost 1:1 rewrite of the old FileAccess class from v1-alpha9, just with some method names changed, a set of "verify" methods, no setPosixPermissions method anymore and wrapper exceptions around Java exceptions to avoid direct contact with Java stuff for public API. See the NonKotlinContact annotation for more information.
The old FileAccess class (for reference): 1e978e3146/base/src/main/java/de/staropensource/engine/base/utility/FileAccess.java
This commit is contained in:
JeremyStar™ 2024-12-15 01:15:50 +01:00
parent 56152536f9
commit 8393818043
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
8 changed files with 1546 additions and 0 deletions

View file

@ -21,6 +21,7 @@
package de.staropensource.engine.base
import de.staropensource.engine.base.utility.Environment
import de.staropensource.engine.base.utility.FileAccess
import de.staropensource.engine.logging.Logger
/**
@ -120,6 +121,7 @@ class Engine private constructor() {
// Run initialization code
Environment.detect()
FileAccess.updateDefaultPaths()
state = State.INITIALIZED
}
@ -142,6 +144,7 @@ class Engine private constructor() {
// Run shutdown code
Environment.unset()
FileAccess.unsetDefaultPaths()
state = State.SHUT_DOWN
}

View file

@ -0,0 +1,29 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
* with an exception allowing classpath linking.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.base.exception
/**
* Thrown when being unable to
* find a file or directory.
*
* @since v1-alpha10
*/
class FileOrDirectoryNotFoundException(val path: String, val throwable: Throwable? = null) : RuntimeException("The file or directory '${path}' could not be found", throwable)

View file

@ -0,0 +1,30 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
* with an exception allowing classpath linking.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.base.exception
/**
* Thrown when reading a file fails
* due to it being larger than the
* configured max heap size.
*
* @since v1-alpha10
*/
class FileTooLargeException(val path: String, val throwable: Throwable? = null) : RuntimeException("Unable to read file '${path}' as it is larger than the configured heap size", throwable)

View file

@ -0,0 +1,28 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
* with an exception allowing classpath linking.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.base.exception
/**
* Thrown when an IO error occurs.
*
* @since v1-alpha10
*/
class IOAccessException(val error: String? = null, val throwable: Throwable? = null) : RuntimeException(error, throwable)

View file

@ -0,0 +1,28 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
* with an exception allowing classpath linking.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.engine.base.exception
/**
* Thrown when a verification fails.
*
* @since v1-alpha10
*/
class VerificationFailedException(val error: String? = null, val throwable: Throwable? = null) : RuntimeException(error, throwable)

View file

@ -0,0 +1,26 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors
* Licensed under the GNU Affero General Public License v3
* with an exception allowing classpath linking.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Exceptions thrown by the engine.
*
* @since v1-alpha10
*/
package de.staropensource.engine.base.exception

File diff suppressed because it is too large Load diff

8
dist/detekt.yml vendored
View file

@ -18,6 +18,10 @@ build:
complexity:
TooManyFunctions:
active: false
NestedBlockDepth:
threshold: 6
ComplexCondition:
active: false
naming:
MemberNameEqualsClassName:
@ -38,3 +42,7 @@ style:
active: false
UnusedParameter:
active: false
ReturnCount:
active: false
WildcardImport:
active: false