mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
GBDaoGenerator: Output to and cleanup generated folder
This commit is contained in:
@@ -29,7 +29,7 @@ application.mainClass = "nodomain.freeyourgadget.gadgetbridge.daogen.GBDaoGenera
|
|||||||
|
|
||||||
tasks.register('genSources', JavaExec) {
|
tasks.register('genSources', JavaExec) {
|
||||||
inputs.dir(file("src"))
|
inputs.dir(file("src"))
|
||||||
outputs.dir(project.rootProject.file("app/src/main/java"))
|
outputs.dir(project.rootProject.file("app/build/generated/sources/gbdao"))
|
||||||
|
|
||||||
mainClass = application.mainClass
|
mainClass = application.mainClass
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
|
|||||||
+95
-19
@@ -15,7 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package nodomain.freeyourgadget.gadgetbridge.daogen;
|
package nodomain.freeyourgadget.gadgetbridge.daogen;
|
||||||
|
|
||||||
import java.util.List;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
|
||||||
import de.greenrobot.daogenerator.DaoGenerator;
|
import de.greenrobot.daogenerator.DaoGenerator;
|
||||||
import de.greenrobot.daogenerator.Entity;
|
import de.greenrobot.daogenerator.Entity;
|
||||||
@@ -27,7 +33,10 @@ import de.greenrobot.daogenerator.Schema;
|
|||||||
* Generates entities and DAOs for the example project DaoExample.
|
* Generates entities and DAOs for the example project DaoExample.
|
||||||
* Automatically run during build.
|
* Automatically run during build.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"UnusedReturnValue", "SameParameterValue", "unused"})
|
||||||
public class GBDaoGenerator {
|
public class GBDaoGenerator {
|
||||||
|
private static final String OUTPUT_DIR = "app/build/generated/sources/gbdao";
|
||||||
|
private static final String LEGACY_DIR = "app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities";
|
||||||
|
|
||||||
private static final String VALID_FROM_UTC = "validFromUTC";
|
private static final String VALID_FROM_UTC = "validFromUTC";
|
||||||
private static final String VALID_TO_UTC = "validToUTC";
|
private static final String VALID_TO_UTC = "validToUTC";
|
||||||
@@ -72,7 +81,7 @@ public class GBDaoGenerator {
|
|||||||
deviceAttributes.addStringProperty("volatileIdentifier");
|
deviceAttributes.addStringProperty("volatileIdentifier");
|
||||||
|
|
||||||
Entity tag = addTag(schema);
|
Entity tag = addTag(schema);
|
||||||
Entity userDefinedActivityOverlay = addActivityDescription(schema, tag, user);
|
addActivityDescription(schema, tag, user);
|
||||||
|
|
||||||
addMakibesHR3ActivitySample(schema, user, device);
|
addMakibesHR3ActivitySample(schema, user, device);
|
||||||
addOVTouch26ActivitySample(schema, user, device);
|
addOVTouch26ActivitySample(schema, user, device);
|
||||||
@@ -222,7 +231,66 @@ public class GBDaoGenerator {
|
|||||||
addGenericTrainingLoadChronicSample(schema, user, device);
|
addGenericTrainingLoadChronicSample(schema, user, device);
|
||||||
addGenericWeightSample(schema, user, device);
|
addGenericWeightSample(schema, user, device);
|
||||||
|
|
||||||
new DaoGenerator().generateAll(schema, "app/src/main/java");
|
deleteOldFiles();
|
||||||
|
|
||||||
|
new DaoGenerator().generateAll(schema, OUTPUT_DIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void deleteOldFiles() throws IOException {
|
||||||
|
// Cleanup the legacy directory to avoid classpath conflicts during build for users that pull the latest changes
|
||||||
|
// FIXME: Remove this eventually, and app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/.gitignore as well
|
||||||
|
if (new File(LEGACY_DIR, "DaoSession.java").isFile()) {
|
||||||
|
Files.walkFileTree(new File(LEGACY_DIR).toPath(), new SimpleFileVisitor<>() {
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
|
@Override
|
||||||
|
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) {
|
||||||
|
if (Files.isSymbolicLink(dir)) {
|
||||||
|
return FileVisitResult.SKIP_SUBTREE;
|
||||||
|
}
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) throws IOException {
|
||||||
|
final File file = path.toFile();
|
||||||
|
if (!file.isFile()) {
|
||||||
|
return FileVisitResult.SKIP_SUBTREE;
|
||||||
|
}
|
||||||
|
if (file.getName().endsWith(".java")) {
|
||||||
|
if (!file.getName().startsWith("Abstract") && !file.getName().equals("GenericActivitySample.java")) {
|
||||||
|
System.out.println("Deleting legacy file: " + path);
|
||||||
|
Files.delete(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Files.walkFileTree(new File(OUTPUT_DIR).toPath(), new SimpleFileVisitor<>() {
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
|
@Override
|
||||||
|
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) {
|
||||||
|
if (Files.isSymbolicLink(dir)) {
|
||||||
|
return FileVisitResult.SKIP_SUBTREE;
|
||||||
|
}
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) throws IOException {
|
||||||
|
if (!path.toFile().isFile()) {
|
||||||
|
return FileVisitResult.SKIP_SUBTREE;
|
||||||
|
}
|
||||||
|
if (path.toString().endsWith(".java")) {
|
||||||
|
System.out.println("Deleting: " + path);
|
||||||
|
Files.delete(path);
|
||||||
|
}
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Entity addTag(Schema schema) {
|
private static Entity addTag(Schema schema) {
|
||||||
@@ -439,10 +507,12 @@ public class GBDaoGenerator {
|
|||||||
addCommonTimeSampleProperties("AbstractRespiratoryRateSample", sleepRespiratoryRateSample, user, device);
|
addCommonTimeSampleProperties("AbstractRespiratoryRateSample", sleepRespiratoryRateSample, user, device);
|
||||||
sleepRespiratoryRateSample.addIntProperty("utcOffset").notNull();
|
sleepRespiratoryRateSample.addIntProperty("utcOffset").notNull();
|
||||||
sleepRespiratoryRateSample.addIntProperty("rate").notNull().codeBeforeGetter(
|
sleepRespiratoryRateSample.addIntProperty("rate").notNull().codeBeforeGetter(
|
||||||
"@Override\n" +
|
"""
|
||||||
" public float getRespiratoryRate() {\n" +
|
@Override
|
||||||
" return (float) getRate();\n" +
|
public float getRespiratoryRate() {
|
||||||
" }\n\n"
|
return (float) getRate();
|
||||||
|
}
|
||||||
|
"""
|
||||||
);
|
);
|
||||||
return sleepRespiratoryRateSample;
|
return sleepRespiratoryRateSample;
|
||||||
}
|
}
|
||||||
@@ -1209,9 +1279,11 @@ public class GBDaoGenerator {
|
|||||||
activitySample.setSuperclass(superClass);
|
activitySample.setSuperclass(superClass);
|
||||||
activitySample.addImport(MAIN_PACKAGE + ".devices.SampleProvider");
|
activitySample.addImport(MAIN_PACKAGE + ".devices.SampleProvider");
|
||||||
activitySample.setJavaDoc(
|
activitySample.setJavaDoc(
|
||||||
"This class represents a sample specific to the device. Values like activity kind or\n" +
|
"""
|
||||||
"intensity, are device specific. Normalized values can be retrieved through the\n" +
|
This class represents a sample specific to the device. Values like activity kind or
|
||||||
"corresponding {@link SampleProvider}.");
|
intensity, are device specific. Normalized values can be retrieved through the
|
||||||
|
corresponding {@link SampleProvider}.
|
||||||
|
""");
|
||||||
activitySample.addIntProperty("timestamp").notNull().codeBeforeGetterAndSetter(OVERRIDE).primaryKey();
|
activitySample.addIntProperty("timestamp").notNull().codeBeforeGetterAndSetter(OVERRIDE).primaryKey();
|
||||||
Property deviceId = activitySample.addLongProperty("deviceId").primaryKey().notNull().codeBeforeGetterAndSetter(OVERRIDE).getProperty();
|
Property deviceId = activitySample.addLongProperty("deviceId").primaryKey().notNull().codeBeforeGetterAndSetter(OVERRIDE).getProperty();
|
||||||
activitySample.addToOne(device, deviceId);
|
activitySample.addToOne(device, deviceId);
|
||||||
@@ -1369,7 +1441,7 @@ public class GBDaoGenerator {
|
|||||||
Entity notificatonFilterEntry = addEntity(schema, "NotificationFilterEntry");
|
Entity notificatonFilterEntry = addEntity(schema, "NotificationFilterEntry");
|
||||||
notificatonFilterEntry.addIdProperty().autoincrement();
|
notificatonFilterEntry.addIdProperty().autoincrement();
|
||||||
Property notificationFilterId = notificatonFilterEntry.addLongProperty("notificationFilterId").notNull().getProperty();
|
Property notificationFilterId = notificatonFilterEntry.addLongProperty("notificationFilterId").notNull().getProperty();
|
||||||
notificatonFilterEntry.addStringProperty("notificationFilterContent").notNull().getProperty();
|
notificatonFilterEntry.addStringProperty("notificationFilterContent").notNull();
|
||||||
notificatonFilterEntry.addToOne(notificationFilterEntity, notificationFilterId);
|
notificatonFilterEntry.addToOne(notificationFilterEntity, notificationFilterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1567,16 +1639,20 @@ public class GBDaoGenerator {
|
|||||||
activitySample.addIntProperty(SAMPLE_RAW_INTENSITY).notNull().codeBeforeGetterAndSetter(OVERRIDE);
|
activitySample.addIntProperty(SAMPLE_RAW_INTENSITY).notNull().codeBeforeGetterAndSetter(OVERRIDE);
|
||||||
activitySample.addIntProperty(SAMPLE_STEPS).notNull().codeBeforeGetterAndSetter(OVERRIDE);
|
activitySample.addIntProperty(SAMPLE_STEPS).notNull().codeBeforeGetterAndSetter(OVERRIDE);
|
||||||
activitySample.addIntProperty("calories").notNull().codeBeforeGetter(
|
activitySample.addIntProperty("calories").notNull().codeBeforeGetter(
|
||||||
"@Override\n" +
|
"""
|
||||||
" public int getActiveCalories() {\n" +
|
@Override
|
||||||
" return getCalories();\n" +
|
public int getActiveCalories() {
|
||||||
" }\n"
|
return getCalories();
|
||||||
|
}
|
||||||
|
"""
|
||||||
);
|
);
|
||||||
activitySample.addIntProperty("distance").notNull().codeBeforeGetter(
|
activitySample.addIntProperty("distance").notNull().codeBeforeGetter(
|
||||||
"@Override\n" +
|
"""
|
||||||
" public int getDistanceCm() {\n" +
|
@Override
|
||||||
" return getDistance() == HuaweiActivitySample.NOT_MEASURED ? HuaweiActivitySample.NOT_MEASURED : getDistance() * 100;\n" +
|
public int getDistanceCm() {
|
||||||
" }\n"
|
return getDistance() == HuaweiActivitySample.NOT_MEASURED ? HuaweiActivitySample.NOT_MEASURED : getDistance() * 100;
|
||||||
|
}
|
||||||
|
"""
|
||||||
);
|
);
|
||||||
activitySample.addIntProperty("spo").notNull();
|
activitySample.addIntProperty("spo").notNull();
|
||||||
activitySample.addIntProperty("heartRate").notNull();
|
activitySample.addIntProperty("heartRate").notNull();
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ android {
|
|||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
|
java.srcDirs += "build/generated/sources/gbdao"
|
||||||
res.srcDirs += "build/generated/res/changelog"
|
res.srcDirs += "build/generated/res/changelog"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# As of #5066 this file should not be needed anymore, but keeping it around
|
||||||
|
# to avoid issues with older checkouts.
|
||||||
*.java
|
*.java
|
||||||
!Abstract*.java
|
!Abstract*.java
|
||||||
!GenericActivitySample.java
|
!GenericActivitySample.java
|
||||||
|
|||||||
Reference in New Issue
Block a user