Skip to content

Commit

Permalink
Configure Gradle
Browse files Browse the repository at this point in the history
- 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
nagyesta committed Sep 28, 2023
1 parent a9a2892 commit 322946a
Show file tree
Hide file tree
Showing 47 changed files with 1,847 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/add-index-exclusion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Add OSS Index Exclusion action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
fetch-depth: 0
token: ${{ secrets.PUBLISH_KEY }}
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4 # v1.1.0
- name: Set up JDK 17
Expand All @@ -74,17 +74,17 @@ jobs:
distribution: temurin
java-version: 17
- name: Initialize CodeQL
uses: github/codeql-action/init@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5
uses: github/codeql-action/init@ddccb873888234080b77e9bc2d4764d5ccaaccf9 # v2.21.9
with:
languages: 'java'
- name: Build with Gradle
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
uses: gradle/gradle-build-action@b5126f31dbc19dd434c3269bf8c28c315e121da2 # v2.8.1
with:
cache-disabled: true
arguments: build -x test
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5
uses: github/codeql-action/analyze@ddccb873888234080b77e9bc2d4764d5ccaaccf9 # v2.21.9
- name: Check dependencies with Gradle
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
uses: gradle/gradle-build-action@b5126f31dbc19dd434c3269bf8c28c315e121da2 # v2.8.1
with:
arguments: ossIndexAudit -PossIndexUsername=${{ secrets.OSS_INDEX_USER }} -PossIndexPassword=${{ secrets.OSS_INDEX_PASSWORD }}
8 changes: 4 additions & 4 deletions .github/workflows/gradle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

steps:
# Set up build environment
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
fetch-depth: 0
- name: Set up JDK 17
Expand All @@ -55,7 +55,7 @@ jobs:
mkdir -p ${{ runner.temp }}/.gnupg/
echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}" | base64 --decode > ${{ runner.temp }}/.gnupg/secring.gpg
- name: Build with Gradle
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
uses: gradle/gradle-build-action@b5126f31dbc19dd434c3269bf8c28c315e121da2 # v2.8.1
with:
arguments: |
printVersion build sign
Expand All @@ -68,7 +68,7 @@ jobs:
rm -rf ${{ runner.temp }}/.gnupg/
- name: 'Upload Test reports - Core'
if: always()
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: test-report-file-barj-core
path: |
Expand All @@ -77,7 +77,7 @@ jobs:
retention-days: 5
- name: 'Upload Test reports - Job'
if: always()
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: test-report-file-barj-job
path: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle-oss-index-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4 # v1.1.0
- name: Set up JDK 17
Expand All @@ -24,6 +24,6 @@ jobs:
distribution: temurin
java-version: 17
- name: Check dependencies with Gradle
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
uses: gradle/gradle-build-action@b5126f31dbc19dd434c3269bf8c28c315e121da2 # v2.8.1
with:
arguments: ossIndexAudit -PossIndexUsername=${{ secrets.OSS_INDEX_USER }} -PossIndexPassword=${{ secrets.OSS_INDEX_PASSWORD }}
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ jobs:

steps:
# Set up build environment
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
with:
distribution: temurin
java-version: 17
- uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
- uses: gradle/gradle-build-action@b5126f31dbc19dd434c3269bf8c28c315e121da2 # v2.8.1
with:
gradle-home-cache-cleanup: true
arguments: |
Expand All @@ -58,7 +58,7 @@ jobs:
run: |
mkdir -p ${{ runner.temp }}/.gnupg/
echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}" | base64 --decode > ${{ runner.temp }}/.gnupg/secring.gpg
- uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
- uses: gradle/gradle-build-action@b5126f31dbc19dd434c3269bf8c28c315e121da2 # v2.8.1
with:
arguments: |
publish -x test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
name: Release trigger action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
fetch-depth: 0
token: ${{ secrets.PUBLISH_KEY }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-dependency-checksums.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Dependency checksum pin action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
fetch-depth: 0
token: ${{ secrets.PUBLISH_KEY }}
Expand All @@ -24,7 +24,7 @@ jobs:
- name: "Remove previous version"
run: cp gradle/verification-metadata-clean.xml gradle/verification-metadata.xml
- name: "Update checksums"
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
uses: gradle/gradle-build-action@b5126f31dbc19dd434c3269bf8c28c315e121da2 # v2.8.1
with:
cache-disabled: true
arguments: --write-verification-metadata sha256
Expand Down
16 changes: 8 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ versioner.apply()

subprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
apply(plugin = "org.gradle.jacoco")
apply(plugin = "org.gradle.checkstyle")
apply(plugin = "org.gradle.signing")
apply(plugin = "io.freefair.lombok")
apply(plugin = "org.sonatype.gradle.plugins.scan")
apply(plugin = "org.owasp.dependencycheck")
Expand All @@ -98,18 +98,18 @@ subprojects {
tasks.jacocoTestReport {
reports {
xml.required.set(true)
xml.outputLocation.set(layout.buildDirectory.file("/reports/jacoco/report.xml"))
xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/report.xml"))
csv.required.set(false)
html.required.set(true)
html.outputLocation.set(layout.buildDirectory.dir("/reports/jacoco/html"))
html.outputLocation.set(layout.buildDirectory.dir("reports/jacoco/html"))
}
dependsOn(tasks.test)
finalizedBy(tasks.getByName("jacocoTestCoverageVerification"))
}

tasks.withType<JacocoCoverageVerification>().configureEach {
inputs.file(layout.buildDirectory.file("/reports/jacoco/report.xml"))
outputs.file(layout.buildDirectory.file("/reports/jacoco/jacocoTestCoverageVerification"))
inputs.file(layout.buildDirectory.file("reports/jacoco/report.xml"))
outputs.file(layout.buildDirectory.file("reports/jacoco/jacocoTestCoverageVerification"))

violationRules {
rule {
Expand Down Expand Up @@ -141,7 +141,7 @@ subprojects {
}
}
doLast {
layout.buildDirectory.file("/reports/jacoco/jacocoTestCoverageVerification").get().asFile.writeText("Passed")
layout.buildDirectory.file("reports/jacoco/jacocoTestCoverageVerification").get().asFile.writeText("Passed")
}
}

Expand All @@ -164,7 +164,7 @@ subprojects {
tasks.withType<Checkstyle>().configureEach {
configProperties = mutableMapOf<String, Any>(
"base_dir" to rootDir.absolutePath.toString(),
"cache_file" to layout.buildDirectory.file("/checkstyle/cacheFile").get().asFile.absolutePath.toString()
"cache_file" to layout.buildDirectory.file("checkstyle/cacheFile").get().asFile.absolutePath.toString()
)
checkstyle.toolVersion = rootProject.libs.versions.checkstyle.get()
checkstyle.configFile = rootProject.file("config/checkstyle/checkstyle.xml")
Expand All @@ -179,7 +179,7 @@ subprojects {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/nagyesta/lowkey-vault")
url = uri("https://maven.pkg.github.com/nagyesta/file-barj")
credentials {
username = rootProject.extra.get("gitUser").toString()
password = rootProject.extra.get("gitToken").toString()
Expand Down
60 changes: 54 additions & 6 deletions file-barj-core/build.gradle.kts
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"])
}
4 changes: 4 additions & 0 deletions file-barj-core/lombok.config
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
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);
}
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);
}
}
}
Loading

0 comments on commit 322946a

Please sign in to comment.