Bugfixes
This commit is contained in:
parent
938b404ec7
commit
16b22d2e49
@ -213,11 +213,20 @@ public class DataModel {
|
|||||||
if (definition.isEmpty()) {
|
if (definition.isEmpty()) {
|
||||||
throw new IllegalArgumentException(transformCoordinate + " refers to an unknown field: " + t.from);
|
throw new IllegalArgumentException(transformCoordinate + " refers to an unknown field: " + t.from);
|
||||||
}
|
}
|
||||||
var prevDef = tryInsertAtIndex(transformClass.data,
|
String prevDef;
|
||||||
t.to,
|
if (t.index != null) {
|
||||||
definition.get().getValue(),
|
prevDef = tryInsertAtIndex(transformClass.data,
|
||||||
definition.get().getKey()
|
t.to,
|
||||||
);
|
definition.get().getValue(),
|
||||||
|
t.index
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
prevDef = tryInsertAtIndex(transformClass.data,
|
||||||
|
t.to,
|
||||||
|
definition.get().getValue(),
|
||||||
|
definition.get().getKey()
|
||||||
|
);
|
||||||
|
}
|
||||||
if (prevDef != null) {
|
if (prevDef != null) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
transformCoordinate + " tries to overwrite the existing field \"" + t.to + "\" of value \""
|
transformCoordinate + " tries to overwrite the existing field \"" + t.to + "\" of value \""
|
||||||
|
@ -29,6 +29,9 @@ public class MavenPlugin extends AbstractMojo {
|
|||||||
@Parameter( required = true, defaultValue = "false")
|
@Parameter( required = true, defaultValue = "false")
|
||||||
private String useRecordBuilder;
|
private String useRecordBuilder;
|
||||||
|
|
||||||
|
@Parameter(defaultValue = "false")
|
||||||
|
private String generateTestResources;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @parameter default-value="${project}"
|
* @parameter default-value="${project}"
|
||||||
* @required
|
* @required
|
||||||
@ -41,7 +44,8 @@ public class MavenPlugin extends AbstractMojo {
|
|||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
try {
|
try {
|
||||||
SourcesGenerator sourcesGenerator = SourcesGenerator.load(configPath.toPath());
|
SourcesGenerator sourcesGenerator = SourcesGenerator.load(configPath.toPath());
|
||||||
Path genRecordsPath = project.getBasedir().getAbsoluteFile().toPath().resolve("target").resolve("generated-sources").resolve("database-classes");
|
project.hasLifecyclePhase("generate-test-sources");
|
||||||
|
Path genRecordsPath = project.getBasedir().getAbsoluteFile().toPath().resolve("target").resolve(Boolean.parseBoolean(generateTestResources) ? "generated-test-sources" : "generated-sources").resolve("database-classes");
|
||||||
|
|
||||||
Path outPath = genRecordsPath.resolve("java");
|
Path outPath = genRecordsPath.resolve("java");
|
||||||
this.project.addCompileSourceRoot(outPath.toString());
|
this.project.addCompileSourceRoot(outPath.toString());
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package it.cavallium.datagen.plugin;
|
package it.cavallium.datagen.plugin;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public final class MoveDataConfiguration implements TransformationConfiguration {
|
public final class MoveDataConfiguration implements TransformationConfiguration {
|
||||||
|
|
||||||
public String transformClass;
|
public String transformClass;
|
||||||
public String from;
|
public String from;
|
||||||
public String to;
|
public String to;
|
||||||
|
@Nullable
|
||||||
|
public Integer index;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransformClass() {
|
public String getTransformClass() {
|
||||||
@ -27,9 +30,8 @@ public final class MoveDataConfiguration implements TransformationConfiguration
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MoveDataConfiguration that = (MoveDataConfiguration) o;
|
MoveDataConfiguration that = (MoveDataConfiguration) o;
|
||||||
return Objects.equals(transformClass, that.transformClass) && Objects.equals(from, that.from) && Objects.equals(to,
|
return Objects.equals(transformClass, that.transformClass) && Objects.equals(from, that.from)
|
||||||
that.to
|
&& Objects.equals(to, that.to) && Objects.equals(index, that.index);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -38,6 +40,7 @@ public final class MoveDataConfiguration implements TransformationConfiguration
|
|||||||
hash += ConfigUtils.hashCode(transformClass);
|
hash += ConfigUtils.hashCode(transformClass);
|
||||||
hash += ConfigUtils.hashCode(from);
|
hash += ConfigUtils.hashCode(from);
|
||||||
hash += ConfigUtils.hashCode(to);
|
hash += ConfigUtils.hashCode(to);
|
||||||
|
hash += ConfigUtils.hashCode(index);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +49,7 @@ public final class MoveDataConfiguration implements TransformationConfiguration
|
|||||||
if (this.transformClass != null) c.transformClass = this.transformClass;
|
if (this.transformClass != null) c.transformClass = this.transformClass;
|
||||||
if (this.from != null) c.from = this.from;
|
if (this.from != null) c.from = this.from;
|
||||||
if (this.to != null) c.to = this.to;
|
if (this.to != null) c.to = this.to;
|
||||||
|
if (this.index != null) c.index = this.index;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,11 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class GenSerializerArrayX extends ClassGenerator {
|
public class GenSerializerArrayX extends ClassGenerator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enabling this option can slow down deserialization updates
|
||||||
|
*/
|
||||||
|
private static final boolean USE_NATIVE_TYPED_ARRAYS = false;
|
||||||
|
|
||||||
public GenSerializerArrayX(ClassGeneratorParams params) {
|
public GenSerializerArrayX(ClassGeneratorParams params) {
|
||||||
super(params);
|
super(params);
|
||||||
}
|
}
|
||||||
@ -96,23 +101,37 @@ public class GenSerializerArrayX extends ClassGenerator {
|
|||||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||||
|
|
||||||
var typeArrayClassName = typeArray.getJTypeName(basePackageName);
|
var typeArrayClassName = typeArray.getJTypeName(basePackageName);
|
||||||
|
|
||||||
|
var arrayComponentTypeName = typeArray.getBase().getJTypeName(basePackageName);
|
||||||
|
var typedArrayTypeName = ArrayTypeName.of(arrayComponentTypeName);
|
||||||
|
|
||||||
method.returns(typeArrayClassName);
|
method.returns(typeArrayClassName);
|
||||||
method.addAnnotation(NotNull.class);
|
method.addAnnotation(NotNull.class);
|
||||||
|
|
||||||
method.addParameter(ParameterSpec.builder(SafeDataInput.class, "in").build());
|
method.addParameter(ParameterSpec.builder(SafeDataInput.class, "in").build());
|
||||||
|
|
||||||
method.addStatement("int sz = in.readInt()");
|
method.addStatement("int sz = in.readInt()");
|
||||||
var arrayTypeName = ArrayTypeName.of(typeArray.getBase().getJTypeName(basePackageName));
|
if (USE_NATIVE_TYPED_ARRAYS) {
|
||||||
method.addStatement("$T a = new $T[sz]", arrayTypeName, arrayTypeName.componentType);
|
method.addStatement("$T a = new $T[sz]", typedArrayTypeName, arrayComponentTypeName);
|
||||||
|
} else {
|
||||||
|
method.addStatement("$T a = new $T[sz]", Object[].class, Object.class);
|
||||||
|
}
|
||||||
method.addCode("\n");
|
method.addCode("\n");
|
||||||
method.beginControlFlow("for (int i = 0; i < sz; ++i)");
|
method.beginControlFlow("for (int i = 0; i < sz; ++i)");
|
||||||
var baseSerializerInstance = typeArray.getBase().getJSerializerInstance(basePackageName);
|
var baseSerializerInstance = typeArray.getBase().getJSerializerInstance(basePackageName);
|
||||||
|
|
||||||
method.addStatement("a[i] = $T.$N.deserialize(in)", baseSerializerInstance.className(), baseSerializerInstance.fieldName());
|
method.addStatement("a[i] = $T.$N.deserialize(in)", baseSerializerInstance.className(), baseSerializerInstance.fieldName());
|
||||||
method.endControlFlow();
|
method.endControlFlow();
|
||||||
|
|
||||||
method.addCode("\n");
|
method.addCode("\n");
|
||||||
method.addStatement("return new $T(a)", ParameterizedTypeName.get(ClassName.get(ImmutableWrappedArrayList.class),
|
if (USE_NATIVE_TYPED_ARRAYS) {
|
||||||
typeArray.getBase().getJTypeName(basePackageName)));
|
method.addStatement("return new $T(a)", ParameterizedTypeName.get(ClassName.get(ImmutableWrappedArrayList.class), arrayComponentTypeName));
|
||||||
|
} else {
|
||||||
|
method.addStatement("return ($T) new $T(a)",
|
||||||
|
ParameterizedTypeName.get(ClassName.get(ImmutableWrappedArrayList.class), arrayComponentTypeName),
|
||||||
|
ClassName.get(ImmutableWrappedArrayList.class)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
classBuilder.addMethod(method.build());
|
classBuilder.addMethod(method.build());
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,37 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>3.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-javadoc</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<doclint>all,-missing</doclint>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -25,19 +25,4 @@ public class BufDataInput extends SafeDataInputStream {
|
|||||||
public void close() {
|
public void close() {
|
||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mark(int readlimit) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reset() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean markSupported() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -624,7 +624,7 @@ public class ImmutableWrappedArrayList<K> extends AbstractObjectList<K> implemen
|
|||||||
/**
|
/**
|
||||||
* Compares this type-specific array list to another one.
|
* Compares this type-specific array list to another one.
|
||||||
*
|
*
|
||||||
* @apiNote This method exists only for sake of efficiency. The implementation inherited from the
|
* This method exists only for sake of efficiency. The implementation inherited from the
|
||||||
* abstract implementation would already work.
|
* abstract implementation would already work.
|
||||||
*
|
*
|
||||||
* @param l a type-specific array list.
|
* @param l a type-specific array list.
|
||||||
@ -655,7 +655,7 @@ public class ImmutableWrappedArrayList<K> extends AbstractObjectList<K> implemen
|
|||||||
/**
|
/**
|
||||||
* Compares this array list to another array list.
|
* Compares this array list to another array list.
|
||||||
*
|
*
|
||||||
* @apiNote This method exists only for sake of efficiency. The implementation inherited from the
|
* This method exists only for sake of efficiency. The implementation inherited from the
|
||||||
* abstract implementation would already work.
|
* abstract implementation would already work.
|
||||||
*
|
*
|
||||||
* @param l an array list.
|
* @param l an array list.
|
||||||
|
@ -7,8 +7,9 @@ public class UpgradeUtil {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <A, B> List<B> upgradeArray(List<A> from, DataUpgrader<A, B> upgrader) {
|
public static <A, B> List<B> upgradeArray(List<A> from, DataUpgrader<A, B> upgrader) {
|
||||||
Object[] array;
|
Object[] array;
|
||||||
if (from instanceof ImmutableWrappedArrayList<A> immutableWrappedArrayList) {
|
if (from.getClass() == ImmutableWrappedArrayList.class
|
||||||
array = immutableWrappedArrayList.a;
|
&& ((ImmutableWrappedArrayList<?>) from).a.getClass() == Object[].class) {
|
||||||
|
array = ((ImmutableWrappedArrayList<?>) from).a;
|
||||||
} else {
|
} else {
|
||||||
array = from.toArray();
|
array = from.toArray();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user