Compute hash
This commit is contained in:
parent
41eb7dde59
commit
c2c4765148
@ -1,6 +1,7 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ClassConfiguration {
|
||||
|
||||
@ -15,4 +16,21 @@ public class ClassConfiguration {
|
||||
public LinkedHashMap<String, String> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ClassConfiguration that = (ClassConfiguration) o;
|
||||
return Objects.equals(stringRepresenter, that.stringRepresenter) && Objects.equals(data, that.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(stringRepresenter, data);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package it.cavallium.data.generator;
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CustomTypesConfiguration {
|
||||
|
||||
@ -29,4 +30,21 @@ public class CustomTypesConfiguration {
|
||||
return ParameterizedTypeName.get(base, genericsResult);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
CustomTypesConfiguration that = (CustomTypesConfiguration) o;
|
||||
return Objects.equals(javaClass, that.javaClass) && Objects.equals(serializer, that.serializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(javaClass, serializer);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,25 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DetailsConfiguration {
|
||||
|
||||
public String changelog;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
DetailsConfiguration that = (DetailsConfiguration) o;
|
||||
return Objects.equals(changelog, that.changelog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(changelog);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package it.cavallium.data.generator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class InterfaceDataConfiguration {
|
||||
@ -10,4 +11,22 @@ public class InterfaceDataConfiguration {
|
||||
public Set<String> extendInterfaces = new HashSet<>();
|
||||
public Map<String, String> commonData = new HashMap<>();
|
||||
public Map<String, String> commonGetters = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InterfaceDataConfiguration that = (InterfaceDataConfiguration) o;
|
||||
return Objects.equals(extendInterfaces, that.extendInterfaces) && Objects.equals(commonData, that.commonData)
|
||||
&& Objects.equals(commonGetters, that.commonGetters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(extendInterfaces, commonData, commonGetters);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class MoveDataConfiguration implements TransformationConfiguration {
|
||||
|
||||
public String transformClass;
|
||||
@ -15,4 +17,23 @@ public class MoveDataConfiguration implements TransformationConfiguration {
|
||||
public String getTransformName() {
|
||||
return "move-data";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
MoveDataConfiguration that = (MoveDataConfiguration) o;
|
||||
return Objects.equals(transformClass, that.transformClass) && Objects.equals(from, that.from) && Objects.equals(to,
|
||||
that.to
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(transformClass, from, to);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class NewDataConfiguration implements TransformationConfiguration {
|
||||
|
||||
public String transformClass;
|
||||
@ -15,4 +17,24 @@ public class NewDataConfiguration implements TransformationConfiguration {
|
||||
public String getTransformName() {
|
||||
return "new-data";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
NewDataConfiguration that = (NewDataConfiguration) o;
|
||||
return Objects.equals(transformClass, that.transformClass) && Objects.equals(to, that.to) && Objects.equals(
|
||||
initializer,
|
||||
that.initializer
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(transformClass, to, initializer);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class RemoveDataConfiguration implements TransformationConfiguration {
|
||||
|
||||
public String transformClass;
|
||||
@ -14,4 +16,21 @@ public class RemoveDataConfiguration implements TransformationConfiguration {
|
||||
public String getTransformName() {
|
||||
return "remove-data";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
RemoveDataConfiguration that = (RemoveDataConfiguration) o;
|
||||
return Objects.equals(transformClass, that.transformClass) && Objects.equals(from, that.from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(transformClass, from);
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +101,26 @@ public class SourcesGenerator {
|
||||
* @param useRecordBuilders if true, the data will have @RecordBuilder annotation
|
||||
*/
|
||||
public void generateSources(String basePackageName, Path outPath, boolean useRecordBuilders) throws IOException {
|
||||
var hashPath = outPath.resolve(".hash");
|
||||
var curHash = computeHash(this.configuration);
|
||||
if (Files.isRegularFile(outPath) && Files.isReadable(outPath)) {
|
||||
var lines = Files.readAllLines(hashPath, StandardCharsets.UTF_8);
|
||||
if (lines.size() >= 3) {
|
||||
var prevBasePackageName = lines.get(0);
|
||||
var prevRecordBuilders = lines.get(1);
|
||||
var prevHash = lines.get(2);
|
||||
|
||||
if (prevBasePackageName.equals(basePackageName) && (prevRecordBuilders.equalsIgnoreCase("true") == useRecordBuilders)
|
||||
&& prevHash.equals(curHash)) {
|
||||
logger.info("Skipped sources generation because it didn't change");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the hash
|
||||
Files.writeString(hashPath, basePackageName + '\n' + useRecordBuilders + '\n' + curHash + '\n',
|
||||
TRUNCATE_EXISTING, WRITE, CREATE);
|
||||
|
||||
// Fix the configuration
|
||||
for (Entry<String, InterfaceDataConfiguration> interfacesDatum : configuration.interfacesData.entrySet()) {
|
||||
@ -2334,6 +2354,10 @@ public class SourcesGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private String computeHash(SourcesGeneratorConfiguration configuration) {
|
||||
return Long.toString(configuration.hashCode());
|
||||
}
|
||||
|
||||
private TypeName getImmutableArrayType(HashMap<String, TypeName> typeTypes, String typeString) {
|
||||
var type = typeTypes.get(typeString);
|
||||
return getImmutableArrayType(type);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SourcesGeneratorConfiguration {
|
||||
public String currentVersion;
|
||||
@ -8,4 +9,21 @@ public class SourcesGeneratorConfiguration {
|
||||
public Map<String, VersionConfiguration> versions;
|
||||
public SourcesGeneratorConfigurationRefs refs;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SourcesGeneratorConfiguration that = (SourcesGeneratorConfiguration) o;
|
||||
return Objects.equals(currentVersion, that.currentVersion) && Objects.equals(interfacesData, that.interfacesData)
|
||||
&& Objects.equals(versions, that.versions) && Objects.equals(refs, that.refs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(currentVersion, interfacesData, versions, refs);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package it.cavallium.data.generator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class SourcesGeneratorConfigurationRefs {
|
||||
@ -9,4 +10,22 @@ public class SourcesGeneratorConfigurationRefs {
|
||||
public Map<String, Map<String, CustomTypesConfiguration>> customTypes;
|
||||
public Map<String, Map<String, ClassConfiguration>> classes;
|
||||
public Map<String, List<VersionTransformation>> transformations;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SourcesGeneratorConfigurationRefs that = (SourcesGeneratorConfigurationRefs) o;
|
||||
return Objects.equals(superTypes, that.superTypes) && Objects.equals(customTypes, that.customTypes)
|
||||
&& Objects.equals(classes, that.classes) && Objects.equals(transformations, that.transformations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(superTypes, customTypes, classes, transformations);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class UpgradeDataConfiguration implements TransformationConfiguration {
|
||||
|
||||
public String transformClass;
|
||||
@ -15,4 +17,24 @@ public class UpgradeDataConfiguration implements TransformationConfiguration {
|
||||
public String getTransformName() {
|
||||
return "upgrade-data";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
UpgradeDataConfiguration that = (UpgradeDataConfiguration) o;
|
||||
return Objects.equals(transformClass, that.transformClass) && Objects.equals(from, that.from) && Objects.equals(
|
||||
upgrader,
|
||||
that.upgrader
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(transformClass, from, upgrader);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package it.cavallium.data.generator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class VersionConfiguration {
|
||||
@ -11,4 +12,24 @@ public class VersionConfiguration {
|
||||
public Map<String, CustomTypesConfiguration> customTypes;
|
||||
public Map<String, ClassConfiguration> classes;
|
||||
public List<VersionTransformation> transformations;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
VersionConfiguration that = (VersionConfiguration) o;
|
||||
return Objects.equals(details, that.details) && Objects.equals(superTypes, that.superTypes) && Objects.equals(
|
||||
customTypes,
|
||||
that.customTypes
|
||||
) && Objects.equals(classes, that.classes) && Objects.equals(transformations, that.transformations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(details, superTypes, customTypes, classes, transformations);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class VersionTransformation {
|
||||
|
||||
public MoveDataConfiguration moveData = null;
|
||||
@ -59,4 +61,24 @@ public class VersionTransformation {
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
VersionTransformation that = (VersionTransformation) o;
|
||||
return Objects.equals(moveData, that.moveData) && Objects.equals(removeData, that.removeData) && Objects.equals(
|
||||
upgradeData,
|
||||
that.upgradeData
|
||||
) && Objects.equals(newData, that.newData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(moveData, removeData, upgradeData, newData);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user