add maven stuff
All checks were successful
/ Build & Publish (push) Successful in 50s

This commit is contained in:
Daniella / Tove 2024-06-25 03:32:03 +02:00
parent 84668c7e15
commit e559762bf7
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
4 changed files with 79 additions and 32 deletions

View file

@ -0,0 +1,27 @@
on: [ push ]
jobs:
publish:
name: Build & Publish
runs-on: 'docker'
permissions:
packages: write
steps:
- name: Setup Java
uses: https://github.com/actions/setup-java@v4
with:
distribution: 'adopt'
java-version: 8
- name: Checkout
uses: actions/checkout@v4
- name: Initialize Gradle
uses: https://github.com/gradle/actions/setup-gradle@v3
- name: Build
run: ./gradlew build
- name: Publish
run: TL_VERSION=$(git describe --always) ./gradlew publish
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}

7
.gitignore vendored
View file

@ -1,10 +1,5 @@
/build/classes/ /build
/build/generated/
/build/libs/
/build/tmp/
/build/reports
/.gradle /.gradle
/build/test-results
/.idea /.idea
*.png *.png
deployToGitlab deployToGitlab

View file

@ -1,4 +1,5 @@
import java.nio.file.Paths import java.nio.file.Paths
import java.nio.file.Files
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream import java.util.zip.ZipOutputStream
@ -56,26 +57,33 @@ jar {
doLast { doLast {
File jar = new File("build/libs/tuddylib.jar") File jar = new File("build/libs/tuddylib.jar")
File loc = new File("TuddyLIB.jar") File loc = new File("TuddyLIB.jar")
jar.renameTo(loc) loc.delete()
Files.copy(jar.toPath(), loc.toPath())
} }
} }
//jar.dependsOn("javadoc") //jar.dependsOn("javadoc")
publishing { publishing {
publications { publications {
maven(MavenPublication) { mavenJava(MavenPublication) {
artifact('TuddyLIB.jar') groupId = "de.tudbut"
version = System.getenv("TL_VERSION")
from components.java
} }
} }
repositories { repositories {
maven { maven {
url = "${System.getenv('CI_API_V4_URL')}/groups/<group>/-/packages/maven" name = "Forgejo"
name = "GitLab" url = uri("https://git.tudbut.de/api/packages/TudbuT/maven")
credentials(HttpHeaderCredentials) { credentials(HttpHeaderCredentials) {
name = 'Job-Token' name = "Authorization"
value = System.getenv("CI_JOB_TOKEN") value = "token " + System.getenv("PUBLISH_TOKEN")
} }
authentication { authentication {
header(HttpHeaderAuthentication) header(HttpHeaderAuthentication)
} }

View file

@ -5,6 +5,7 @@ package de.tudbut.tools;
*/ */
public class Lock extends SimpleLock { public class Lock extends SimpleLock {
private boolean isTimed = false;
private long startTime = 0, lockTime = 0; private long startTime = 0, lockTime = 0;
/** /**
@ -31,18 +32,22 @@ public class Lock extends SimpleLock {
} }
/** /**
* @return The time left (or MAX_VALUE) * @return The time left (or MAX_VALUE if not timed)
*/ */
public synchronized long timeLeft() { public synchronized long timeLeft() {
if(lockTime == 0) if(!isTimed)
return Long.MAX_VALUE; return Long.MAX_VALUE;
return waitTime(); return timeLeft0();
} }
/** /**
* @return The time left * @return The time left (or 0 if not timed)
*/ */
public synchronized long waitTime() { public synchronized long timeLeft0() {
if(!super.isLocked())
return 0;
if(!isTimed)
return 0;
return Math.max(lockTime - timeLocked(), 0); return Math.max(lockTime - timeLocked(), 0);
} }
@ -50,9 +55,18 @@ public class Lock extends SimpleLock {
* Wait until unlocked, either by a timer or manually * Wait until unlocked, either by a timer or manually
*/ */
public synchronized void waitHere() { public synchronized void waitHere() {
long wt = waitTime(); if(!isTimed) {
if(wt == 0 && lockTime != 0) super.waitHere();
return;
}
if(!super.isLocked())
return;
long wt = timeLeft0();
if(wt == 0) {
unlock(); unlock();
return;
}
super.waitHere(wt); super.waitHere(wt);
} }
@ -61,19 +75,21 @@ public class Lock extends SimpleLock {
* @param timeout Timeout * @param timeout Timeout
*/ */
public synchronized void waitHere(int timeout) { public synchronized void waitHere(int timeout) {
if(timeout == 0 || !super.isLocked()) if(timeout == 0)
return; return;
if(!isTimed) {
if(lockTime == 0) {
super.waitHere(timeout); super.waitHere(timeout);
} else { return;
long timeLeft = lockTime - (System.currentTimeMillis() - startTime); }
if (timeLeft == 0) {
if(!super.isLocked())
return;
long wt = timeLeft0();
if(wt == 0) {
unlock(); unlock();
return; return;
} }
super.waitHere(Math.min(timeLeft, timeout)); super.waitHere(Math.min(wt, timeout));
}
} }
/** /**
@ -90,7 +106,7 @@ public class Lock extends SimpleLock {
*/ */
public synchronized void lock() { public synchronized void lock() {
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
lockTime = 0; isTimed = false;
super.lock(); super.lock();
} }
@ -104,6 +120,7 @@ public class Lock extends SimpleLock {
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
lockTime = time; lockTime = time;
isTimed = true;
super.lock(); super.lock();
} }