-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Defines initial versions of JSON model/configuration entities - Creates encryption utility for key generation and key encryption tasks - Implements local file metadat parser - Adds Lombok configuration - Adds tests - Configures fat jar for Job - Configures Maven publish - Adds basic Abort-Mission configuration - Fixes some Gradle plugin configuration issues {patch} Signed-off-by: Esta Nagy <[email protected]>
- Loading branch information
Showing
47 changed files
with
1,847 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,64 @@ | ||
plugins { | ||
id("java") | ||
signing | ||
`maven-publish` | ||
alias(libs.plugins.abort.mission) | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
extra.apply { | ||
set("artifactDisplayName", "File BaRJ - Core") | ||
set("artifactDescription", "Defines the inner working mechanism of backup and restore tasks.") | ||
} | ||
|
||
dependencies { | ||
testImplementation(platform("org.junit:junit-bom:5.9.1")) | ||
testImplementation("org.junit.jupiter:junit-jupiter") | ||
implementation(libs.bundles.jackson) | ||
implementation(libs.commons.codec) | ||
implementation(libs.commons.compress) | ||
implementation(libs.commons.crypto) | ||
implementation(libs.commons.io) | ||
testImplementation(platform(libs.junit.bom)) | ||
testImplementation(libs.jupiter) | ||
testImplementation(libs.abort.mission.jupiter) | ||
testImplementation(libs.mockito.core) | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
abortMission { | ||
toolVersion = libs.versions.abortMission.get() | ||
} | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("mavenJava") { | ||
from(components["java"]) | ||
artifactId = tasks.jar.get().archiveBaseName.get() | ||
pom { | ||
name.set(project.extra.get("artifactDisplayName").toString()) | ||
description.set(project.extra.get("artifactDescription").toString()) | ||
url.set(rootProject.extra.get("repoUrl").toString()) | ||
packaging = "jar" | ||
licenses { | ||
license { | ||
name.set(rootProject.extra.get("licenseName").toString()) | ||
url.set(rootProject.extra.get("licenseUrl").toString()) | ||
} | ||
} | ||
developers { | ||
developer { | ||
id.set(rootProject.extra.get("maintainerId").toString()) | ||
name.set(rootProject.extra.get("maintainerName").toString()) | ||
email.set(rootProject.extra.get("maintainerUrl").toString()) | ||
} | ||
} | ||
scm { | ||
connection.set(rootProject.extra.get("scmConnection").toString()) | ||
developerConnection.set(rootProject.extra.get("scmConnection").toString()) | ||
url.set(rootProject.extra.get("scmProjectUrl").toString()) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
signing { | ||
sign(publishing.publications["mavenJava"]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# This file is generated by the 'io.freefair.lombok' Gradle plugin | ||
config.stopBubbling = true | ||
lombok.addLombokGeneratedAnnotation = true | ||
lombok.nonNull.exceptionType = IllegalArgumentException |
20 changes: 20 additions & 0 deletions
20
...-barj-core/src/main/java/com/github/nagyesta/filebarj/core/backup/FileMetadataParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.nagyesta.filebarj.core.backup; | ||
|
||
import com.github.nagyesta.filebarj.core.config.BackupJobConfiguration; | ||
import com.github.nagyesta.filebarj.core.model.FileMetadata; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Parses metadata of Files. | ||
*/ | ||
public interface FileMetadataParser { | ||
|
||
/** | ||
* Reads or calculates metadata of a file we need to include in the backup. | ||
* @param file The current {@link File} we need ot evaluate | ||
* @param configuration The backup configuration | ||
* @return the parsed {@link FileMetadata} | ||
*/ | ||
FileMetadata parse(File file, BackupJobConfiguration configuration); | ||
} |
85 changes: 85 additions & 0 deletions
85
...-core/src/main/java/com/github/nagyesta/filebarj/core/backup/FileMetadataParserLocal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.github.nagyesta.filebarj.core.backup; | ||
|
||
import com.github.nagyesta.filebarj.core.config.BackupJobConfiguration; | ||
import com.github.nagyesta.filebarj.core.model.FileMetadata; | ||
import com.github.nagyesta.filebarj.core.model.enums.Change; | ||
import com.github.nagyesta.filebarj.core.model.enums.FileType; | ||
import org.apache.commons.codec.digest.DigestUtils; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.LinkOption; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.nio.file.attribute.PosixFileAttributes; | ||
import java.nio.file.attribute.PosixFilePermissions; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Local file specific implementation of the {@link FileMetadataParser}. | ||
*/ | ||
public class FileMetadataParserLocal implements FileMetadataParser { | ||
|
||
@Override | ||
public FileMetadata parse(final File file, final BackupJobConfiguration configuration) { | ||
final var posixFileAttributes = posixPermissionsQuietly(file); | ||
final var basicAttributes = basicAttributesQuietly(file); | ||
|
||
return FileMetadata.builder() | ||
.absolutePath(file.toPath().toAbsolutePath()) | ||
.owner(posixFileAttributes.owner().getName()) | ||
.group(posixFileAttributes.group().getName()) | ||
.posixPermissions(PosixFilePermissions.toString(posixFileAttributes.permissions())) | ||
.lastModifiedUtcEpochSeconds(basicAttributes.lastModifiedTime().toInstant().getEpochSecond()) | ||
.originalSizeBytes(basicAttributes.size()) | ||
.fileType(FileType.findForAttributes(basicAttributes)) | ||
.originalChecksum(calculateChecksum(file, configuration)) | ||
.hidden(checkIsHiddenQuietly(file)) | ||
.status(Change.NEW) | ||
.build(); | ||
} | ||
|
||
private PosixFileAttributes posixPermissionsQuietly(final File file) { | ||
try { | ||
return Files.readAttributes(file.toPath(), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS); | ||
} catch (final IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private BasicFileAttributes basicAttributesQuietly(final File file) { | ||
try { | ||
return Files.readAttributes(file.toPath(), BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); | ||
} catch (final IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private boolean checkIsHiddenQuietly(final File file) { | ||
try { | ||
return Files.isHidden(file.toPath()); | ||
} catch (final IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
|
||
private String calculateChecksum(final File file, final BackupJobConfiguration configuration) { | ||
try { | ||
final var messageDigest = Optional.ofNullable(configuration.getChecksumAlgorithm().getAlgorithmName()) | ||
.map(DigestUtils::new); | ||
final var attributes = basicAttributesQuietly(file); | ||
if (messageDigest.isEmpty() || attributes.isOther()) { | ||
return null; | ||
} else { | ||
if (attributes.isSymbolicLink()) { | ||
return messageDigest.get().digestAsHex(Files.readSymbolicLink(file.toPath()).toAbsolutePath()); | ||
} else { | ||
return messageDigest.get().digestAsHex(file); | ||
} | ||
} | ||
} catch (final IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.