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/generated/
/build/libs/
/build/tmp/
/build/reports
/build
/.gradle
/build/test-results
/.idea
*.png
deployToGitlab

View file

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

View file

@ -5,6 +5,7 @@ package de.tudbut.tools;
*/
public class Lock extends SimpleLock {
private boolean isTimed = false;
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() {
if(lockTime == 0)
if(!isTimed)
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);
}
@ -50,9 +55,18 @@ public class Lock extends SimpleLock {
* Wait until unlocked, either by a timer or manually
*/
public synchronized void waitHere() {
long wt = waitTime();
if(wt == 0 && lockTime != 0)
if(!isTimed) {
super.waitHere();
return;
}
if(!super.isLocked())
return;
long wt = timeLeft0();
if(wt == 0) {
unlock();
return;
}
super.waitHere(wt);
}
@ -61,19 +75,21 @@ public class Lock extends SimpleLock {
* @param timeout Timeout
*/
public synchronized void waitHere(int timeout) {
if(timeout == 0 || !super.isLocked())
if(timeout == 0)
return;
if(lockTime == 0) {
if(!isTimed) {
super.waitHere(timeout);
} else {
long timeLeft = lockTime - (System.currentTimeMillis() - startTime);
if (timeLeft == 0) {
return;
}
if(!super.isLocked())
return;
long wt = timeLeft0();
if(wt == 0) {
unlock();
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() {
startTime = System.currentTimeMillis();
lockTime = 0;
isTimed = false;
super.lock();
}
@ -104,6 +120,7 @@ public class Lock extends SimpleLock {
startTime = System.currentTimeMillis();
lockTime = time;
isTimed = true;
super.lock();
}