Compare commits

..

2 commits

Author SHA1 Message Date
Morten Delenk
fbe4fe643a
add hydra jobs 2022-08-13 17:44:23 +01:00
Morten Delenk
c90059f532
build the server with nix 2022-08-13 17:42:42 +01:00
3 changed files with 103 additions and 1 deletions

View file

@ -9,3 +9,27 @@ plugins {
task clean(type: Delete) {
delete rootProject.buildDir
}
task resolveDependencies {
doLast {
project.rootProject.allprojects.each { subProject ->
subProject.buildscript.configurations.each { configuration ->
resolveConfiguration(subProject, configuration, "buildscript config '${configuration.name}'")
}
subProject.configurations.each { configuration ->
resolveConfiguration(subProject, configuration, "config '${configuration.name}'")
}
}
}
}
void resolveConfiguration(subProject, configuration, name) {
// TODO: fix this
if (subProject.name == "app") {
return;
}
if (configuration.canBeResolved) {
logger.info("Resolving project {} {}", subProject.name, name)
configuration.resolve()
}
}

View file

@ -19,7 +19,7 @@
allowUnfree = true;
};
};
in {
in rec {
formatter = pkgs.alejandra;
devShells.default = let
androidSdk = pkgs.androidenv.androidPkgs_9_0.androidsdk;
@ -35,5 +35,47 @@
# override the aapt2 that gradle uses with the nix-shipped version
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/32.0.0/aapt2";
};
packages = rec {
invtracker-deps = pkgs.stdenv.mkDerivation {
pname = "invtracker-deps";
version = self.lastModifiedDate;
src = self;
nativeBuildInputs = with pkgs; [gradle openjdk_headless perl];
buildPhase = ''
export GRADLE_USER_HOME=$(mktemp -d)
# Fetch the maven deps
gradle --no-daemon --info -Dorg.gradle.java.home=${pkgs.openjdk_headless} resolveDependencies
'';
installPhase = ''
find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)$' \
| perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/maven/$x/$3/$4/$5" #e' \
| sh
'';
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = "sha256-OXNB19WPC5MyLEoDAtnVM9XykY7e0mKGRH5Aw8C/lMo=";
};
invtracker-server = pkgs.stdenv.mkDerivation {
pname = "invtracker-server";
version = self.lastModifiedDate;
src = self;
nativeBuildInputs = with pkgs; [gradle openjdk_headless];
buildPhase = ''
sed -i 's#gradlePluginPortal..#maven { url "${invtracker-deps}/maven" }#' settings.gradle
sed -i 's#google..#maven { url "${invtracker-deps}/maven" }#' settings.gradle
export GRADLE_USER_HOME=$(mktemp -d)
gradle --offline --no-daemon --info -Dorg.gradle.java.home=${pkgs.openjdk_headless} server:installDist
'';
installPhase = ''
cp -rv server/build/install/server $out/
'';
};
};
hydraJobs =
if system == "x86_64-linux"
then devShells // packages
else {};
});
}

View file

@ -25,18 +25,48 @@ import rs.chir.db.DBConnection;
import rs.chir.invtracker.model.Cursor;
import rs.chir.invtracker.model.GeoLocation;
/**
* A table for storing locations for tracked items.
*/
public class LocationLogTable implements Map<Long, GeoLocation> {
/**
* The page size to use for API cursors
*/
private static final int PAGE_SIZE = 50;
/**
* The database connection to use for accessing the table.
*/
private final DBConnection dbConnection;
/**
* The user ID to use for accessing the table.
*/
private final long userId;
/**
* The item ID to use for accessing the table.
*/
private final long itemId;
/**
* Creates a new table.
*
* @param dbConnection the database connection to use for accessing the table.
* @param userId the user ID to use for accessing the table.
* @param itemId the item ID to use for accessing the table.
*/
private LocationLogTable(DBConnection dbConnection, long userId, long itemId) {
this.dbConnection = dbConnection;
this.userId = userId;
this.itemId = itemId;
}
/**
* Retrieve the table for the given user and item.
*
* @param dbConnection the database connection to use for accessing the table.
* @param userId the user ID to use for accessing the table.
* @param itemId the item ID to use for accessing the table.
* @return the new table.
*/
@NonNull
public static LocationLogTable getInstance(@NonNull DBConnection dbConnection, long userId, long itemId) {
// TODO: add caching maybe
@ -45,6 +75,12 @@ public class LocationLogTable implements Map<Long, GeoLocation> {
return result;
}
/**
* Converts a row from the database to a location.
* @param resultSet the result set to convert.
* @return the location.
* @throws SQLException if an error occurs.
*/
@NonNull
@Contract("_ -> new")
private static GeoLocation fromResultSet(@NonNull ResultSet rs) throws SQLException {