Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public void testManager() throws Exception {
file.getAbsolutePath(),
null,
OnOffAuto.auto,
BlockdevAioOptions._native));
BlockdevAioOptions._native,
null));
options.withReadOnly(true);
options.withNodeName("test-file-node");
options.withCache(new BlockdevCacheOptions().withDirect(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ else if (jsonTree.get("pragma") != null)
element.getName() + "Base");
model.elements.put(parentElement.getName(), parentElement);
}

if (element instanceof QApiEnumDescriptor) {
// Keep track of all the enum types.
QApiEnumDescriptor.ALL_ENUMS.add(element.getName());
}

// LOG.info("Read specific " + element);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static class Field {
public String typeName;
public String name;
public String serializedName;
/**
* Enum field "name"s convert to Java names differently. Save that conversion, too.
*/
public String enumName;
public boolean optional;

public String getAnnotations() {
Expand All @@ -35,6 +39,19 @@ public String getTypeName() {
return typeName;
}

/**
* @return Whether this field is an enum type.
*/
public boolean isEnumType() {
return QApiEnumDescriptor.ALL_ENUMS.contains(getTypeName());
}

public String getAllThem() {
StringBuilder b = new StringBuilder();
QApiEnumDescriptor.ALL_ENUMS.forEach(s -> {b.append(s);b.append(" ");});
return b.toString();
}

public String getTypeNameWrapped() {
return toWrappedJavaType(getTypeName());
}
Expand All @@ -43,6 +60,10 @@ public String getName() {
return name;
}

public String getEnumName() {
return enumName;
}

public String getCapName() {
return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, getName());
}
Expand Down Expand Up @@ -96,6 +117,7 @@ protected boolean preprocess(@Nonnull AbstractQApiTypeDescriptor root) {
field.annotations = "@Nonnull";
}
field.serializedName = field.name;
field.enumName = toJavaEnumName(field.name);
field.name = toJavaName(field.name);

if (e.getValue() instanceof Map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;

/**
Expand All @@ -16,6 +18,9 @@
*/
public class QApiEnumDescriptor extends QApiElementDescriptor {

/** Save a record of all the enum types after we convert them to Java class names. */
public static final Set<String> ALL_ENUMS = new HashSet<>();

public static class Field {

public String name;
Expand Down
4 changes: 4 additions & 0 deletions qemu-qapi/src/generate/resources/velocity/union.vm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public class $element.className extends #{if} ($element.superClassName)$element.
self.type = Discriminator.${field.underscoreName};
#end
#if ($element.fieldDiscriminated)
#if ($element.discriminatorField.isEnumType())
self.${element.discriminatorField.name} = ${element.discriminatorField.typeName}.${field.enumName};
#else
self.${element.discriminatorField.name} = ${element.discriminatorField.typeName}.${field.underscoreName};
#end
#end
self.${field.name} = $field.name;
return self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
/**
* Autogenerated class.
*
* <pre>QApiStructDescriptor{name=BlockJobInfo, data={type=str, device=str, len=int, offset=int, busy=bool, paused=bool, speed=int, io-status=BlockDeviceIoStatus, ready=bool, status=BlockJobStatus, auto-finalize=bool, auto-dismiss=bool}, innerTypes=null, fields=null, base=null}</pre>
* <pre>QApiStructDescriptor{name=BlockJobInfo, data={type=str, device=str, len=int, offset=int, busy=bool, paused=bool, speed=int, io-status=BlockDeviceIoStatus, ready=bool, status=BlockJobStatus, auto-finalize=bool, auto-dismiss=bool, *error=str}, innerTypes=null, fields=null, base=null}</pre>
*/
// QApiStructDescriptor{name=BlockJobInfo, data={type=str, device=str, len=int, offset=int, busy=bool, paused=bool, speed=int, io-status=BlockDeviceIoStatus, ready=bool, status=BlockJobStatus, auto-finalize=bool, auto-dismiss=bool}, innerTypes=null, fields=null, base=null}
// QApiStructDescriptor{name=BlockJobInfo, data={type=str, device=str, len=int, offset=int, busy=bool, paused=bool, speed=int, io-status=BlockDeviceIoStatus, ready=bool, status=BlockJobStatus, auto-finalize=bool, auto-dismiss=bool, *error=str}, innerTypes=null, fields=null, base=null}
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class BlockJobInfo extends QApiType {

Expand Down Expand Up @@ -66,6 +66,10 @@ public class BlockJobInfo extends QApiType {
@JsonProperty("auto-dismiss")
@Nonnull
public boolean autoDismiss;
@SuppressFBWarnings("NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
@JsonProperty("error")
@CheckForNull
public java.lang.String error;

@Nonnull
public BlockJobInfo withType(java.lang.String value) {
Expand Down Expand Up @@ -139,10 +143,16 @@ public BlockJobInfo withAutoDismiss(boolean value) {
return this;
}

@Nonnull
public BlockJobInfo withError(java.lang.String value) {
this.error = value;
return this;
}

public BlockJobInfo() {
}

public BlockJobInfo(java.lang.String type, java.lang.String device, long len, long offset, boolean busy, boolean paused, long speed, BlockDeviceIoStatus ioStatus, boolean ready, BlockJobStatus status, boolean autoFinalize, boolean autoDismiss) {
public BlockJobInfo(java.lang.String type, java.lang.String device, long len, long offset, boolean busy, boolean paused, long speed, BlockDeviceIoStatus ioStatus, boolean ready, BlockJobStatus status, boolean autoFinalize, boolean autoDismiss, java.lang.String error) {
this.type = type;
this.device = device;
this.len = len;
Expand All @@ -155,6 +165,7 @@ public BlockJobInfo(java.lang.String type, java.lang.String device, long len, lo
this.status = status;
this.autoFinalize = autoFinalize;
this.autoDismiss = autoDismiss;
this.error = error;
}

@JsonIgnore
Expand All @@ -173,6 +184,7 @@ public java.util.List<java.lang.String> getFieldNames() {
names.add("status");
names.add("auto-finalize");
names.add("auto-dismiss");
names.add("error");
return names;
}

Expand Down Expand Up @@ -202,6 +214,8 @@ public Object getFieldByName(@Nonnull java.lang.String name) throws NoSuchFieldE
return autoFinalize;
if ("auto-dismiss".equals(name))
return autoDismiss;
if ("error".equals(name))
return error;
return super.getFieldByName(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Autogenerated class.
*
* <pre>QApiUnionDescriptor{name=BlockdevCreateOptions, discriminator=driver, data={blkdebug=BlockdevCreateNotSupported, blkverify=BlockdevCreateNotSupported, bochs=BlockdevCreateNotSupported, cloop=BlockdevCreateNotSupported, dmg=BlockdevCreateNotSupported, file=BlockdevCreateOptionsFile, ftp=BlockdevCreateNotSupported, ftps=BlockdevCreateNotSupported, gluster=BlockdevCreateOptionsGluster, host_cdrom=BlockdevCreateNotSupported, host_device=BlockdevCreateNotSupported, http=BlockdevCreateNotSupported, https=BlockdevCreateNotSupported, iscsi=BlockdevCreateNotSupported, luks=BlockdevCreateOptionsLUKS, nbd=BlockdevCreateNotSupported, nfs=BlockdevCreateOptionsNfs, null-aio=BlockdevCreateNotSupported, null-co=BlockdevCreateNotSupported, nvme=BlockdevCreateNotSupported, parallels=BlockdevCreateOptionsParallels, qcow=BlockdevCreateOptionsQcow, qcow2=BlockdevCreateOptionsQcow2, qed=BlockdevCreateOptionsQed, quorum=BlockdevCreateNotSupported, raw=BlockdevCreateNotSupported, rbd=BlockdevCreateOptionsRbd, replication=BlockdevCreateNotSupported, sheepdog=BlockdevCreateOptionsSheepdog, ssh=BlockdevCreateOptionsSsh, throttle=BlockdevCreateNotSupported, vdi=BlockdevCreateOptionsVdi, vhdx=BlockdevCreateOptionsVhdx, vmdk=BlockdevCreateNotSupported, vpc=BlockdevCreateOptionsVpc, vvfat=BlockdevCreateNotSupported, vxhs=BlockdevCreateNotSupported}, innerTypes=null, fields=null, base={driver=BlockdevDriver}, discriminatorField=null}</pre>
* <pre>QApiUnionDescriptor{name=BlockdevCreateOptions, discriminator=driver, data={blkdebug=BlockdevCreateNotSupported, blkverify=BlockdevCreateNotSupported, bochs=BlockdevCreateNotSupported, cloop=BlockdevCreateNotSupported, copy-on-read=BlockdevCreateNotSupported, dmg=BlockdevCreateNotSupported, file=BlockdevCreateOptionsFile, ftp=BlockdevCreateNotSupported, ftps=BlockdevCreateNotSupported, gluster=BlockdevCreateOptionsGluster, host_cdrom=BlockdevCreateNotSupported, host_device=BlockdevCreateNotSupported, http=BlockdevCreateNotSupported, https=BlockdevCreateNotSupported, iscsi=BlockdevCreateNotSupported, luks=BlockdevCreateOptionsLUKS, nbd=BlockdevCreateNotSupported, nfs=BlockdevCreateOptionsNfs, null-aio=BlockdevCreateNotSupported, null-co=BlockdevCreateNotSupported, nvme=BlockdevCreateNotSupported, parallels=BlockdevCreateOptionsParallels, qcow=BlockdevCreateOptionsQcow, qcow2=BlockdevCreateOptionsQcow2, qed=BlockdevCreateOptionsQed, quorum=BlockdevCreateNotSupported, raw=BlockdevCreateNotSupported, rbd=BlockdevCreateOptionsRbd, replication=BlockdevCreateNotSupported, sheepdog=BlockdevCreateOptionsSheepdog, ssh=BlockdevCreateOptionsSsh, throttle=BlockdevCreateNotSupported, vdi=BlockdevCreateOptionsVdi, vhdx=BlockdevCreateOptionsVhdx, vmdk=BlockdevCreateNotSupported, vpc=BlockdevCreateOptionsVpc, vvfat=BlockdevCreateNotSupported, vxhs=BlockdevCreateNotSupported}, innerTypes=null, fields=null, base={driver=BlockdevDriver}, discriminatorField=null}</pre>
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class BlockdevCreateOptions extends BlockdevCreateOptionsBase implements QApiUnion {
Expand All @@ -40,6 +40,11 @@ public class BlockdevCreateOptions extends BlockdevCreateOptionsBase implements
@CheckForNull
public BlockdevCreateNotSupported cloop;
@SuppressFBWarnings("NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
@JsonProperty("copy-on-read")
@JsonUnwrapped
@CheckForNull
public BlockdevCreateNotSupported copyOnRead;
@SuppressFBWarnings("NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
@JsonProperty("dmg")
@JsonUnwrapped
@CheckForNull
Expand Down Expand Up @@ -238,6 +243,14 @@ public static BlockdevCreateOptions cloop(@Nonnull BlockdevCreateNotSupported cl
return self;
}

@Nonnull
public static BlockdevCreateOptions copyOnRead(@Nonnull BlockdevCreateNotSupported copyOnRead) {
BlockdevCreateOptions self = new BlockdevCreateOptions();
self.driver = BlockdevDriver.copy_on_read;
self.copyOnRead = copyOnRead;
return self;
}

@Nonnull
public static BlockdevCreateOptions dmg(@Nonnull BlockdevCreateNotSupported dmg) {
BlockdevCreateOptions self = new BlockdevCreateOptions();
Expand Down Expand Up @@ -509,6 +522,7 @@ public java.util.List<java.lang.String> getFieldNames() {
names.add("blkverify");
names.add("bochs");
names.add("cloop");
names.add("copy-on-read");
names.add("dmg");
names.add("file");
names.add("ftp");
Expand Down Expand Up @@ -556,6 +570,8 @@ public Object getFieldByName(@Nonnull java.lang.String name) throws NoSuchFieldE
return bochs;
if ("cloop".equals(name))
return cloop;
if ("copy-on-read".equals(name))
return copyOnRead;
if ("dmg".equals(name))
return dmg;
if ("file".equals(name))
Expand Down Expand Up @@ -636,6 +652,8 @@ public boolean isValidUnion() {
count++;
if (cloop != null)
count++;
if (copyOnRead != null)
count++;
if (dmg != null)
count++;
if (file != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
/**
* Autogenerated class.
*
* <pre>QApiEnumDescriptor{name=BlockdevDriver, data=[blkdebug, blkverify, bochs, cloop, dmg, file, ftp, ftps, gluster, host_cdrom, host_device, http, https, iscsi, luks, nbd, nfs, null-aio, null-co, nvme, parallels, qcow, qcow2, qed, quorum, raw, rbd, replication, sheepdog, ssh, throttle, vdi, vhdx, vmdk, vpc, vvfat, vxhs], fields=null}</pre>
* <pre>QApiEnumDescriptor{name=BlockdevDriver, data=[blkdebug, blkverify, bochs, cloop, copy-on-read, dmg, file, ftp, ftps, gluster, host_cdrom, host_device, http, https, iscsi, luks, nbd, nfs, null-aio, null-co, nvme, parallels, qcow, qcow2, qed, quorum, raw, rbd, replication, sheepdog, ssh, throttle, vdi, vhdx, vmdk, vpc, vvfat, vxhs], fields=null}</pre>
*/
// QApiEnumDescriptor{name=BlockdevDriver, data=[blkdebug, blkverify, bochs, cloop, dmg, file, ftp, ftps, gluster, host_cdrom, host_device, http, https, iscsi, luks, nbd, nfs, null-aio, null-co, nvme, parallels, qcow, qcow2, qed, quorum, raw, rbd, replication, sheepdog, ssh, throttle, vdi, vhdx, vmdk, vpc, vvfat, vxhs], fields=null}
// QApiEnumDescriptor{name=BlockdevDriver, data=[blkdebug, blkverify, bochs, cloop, copy-on-read, dmg, file, ftp, ftps, gluster, host_cdrom, host_device, http, https, iscsi, luks, nbd, nfs, null-aio, null-co, nvme, parallels, qcow, qcow2, qed, quorum, raw, rbd, replication, sheepdog, ssh, throttle, vdi, vhdx, vmdk, vpc, vvfat, vxhs], fields=null}
public enum BlockdevDriver {
blkdebug("blkdebug"),
blkverify("blkverify"),
bochs("bochs"),
cloop("cloop"),
copy_on_read("copy-on-read"),
dmg("dmg"),
file("file"),
ftp("ftp"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Autogenerated class.
*
* <pre>QApiUnionDescriptor{name=BlockdevOptions, discriminator=driver, data={blkdebug=BlockdevOptionsBlkdebug, blkverify=BlockdevOptionsBlkverify, bochs=BlockdevOptionsGenericFormat, cloop=BlockdevOptionsGenericFormat, dmg=BlockdevOptionsGenericFormat, file=BlockdevOptionsFile, ftp=BlockdevOptionsCurlFtp, ftps=BlockdevOptionsCurlFtps, gluster=BlockdevOptionsGluster, host_cdrom=BlockdevOptionsFile, host_device=BlockdevOptionsFile, http=BlockdevOptionsCurlHttp, https=BlockdevOptionsCurlHttps, iscsi=BlockdevOptionsIscsi, luks=BlockdevOptionsLUKS, nbd=BlockdevOptionsNbd, nfs=BlockdevOptionsNfs, null-aio=BlockdevOptionsNull, null-co=BlockdevOptionsNull, nvme=BlockdevOptionsNVMe, parallels=BlockdevOptionsGenericFormat, qcow2=BlockdevOptionsQcow2, qcow=BlockdevOptionsQcow, qed=BlockdevOptionsGenericCOWFormat, quorum=BlockdevOptionsQuorum, raw=BlockdevOptionsRaw, rbd=BlockdevOptionsRbd, replication=BlockdevOptionsReplication, sheepdog=BlockdevOptionsSheepdog, ssh=BlockdevOptionsSsh, throttle=BlockdevOptionsThrottle, vdi=BlockdevOptionsGenericFormat, vhdx=BlockdevOptionsGenericFormat, vmdk=BlockdevOptionsGenericCOWFormat, vpc=BlockdevOptionsGenericFormat, vvfat=BlockdevOptionsVVFAT, vxhs=BlockdevOptionsVxHS}, innerTypes=null, fields=null, base={driver=BlockdevDriver, *node-name=str, *discard=BlockdevDiscardOptions, *cache=BlockdevCacheOptions, *read-only=bool, *force-share=bool, *detect-zeroes=BlockdevDetectZeroesOptions}, discriminatorField=null}</pre>
* <pre>QApiUnionDescriptor{name=BlockdevOptions, discriminator=driver, data={blkdebug=BlockdevOptionsBlkdebug, blkverify=BlockdevOptionsBlkverify, bochs=BlockdevOptionsGenericFormat, cloop=BlockdevOptionsGenericFormat, copy-on-read=BlockdevOptionsGenericFormat, dmg=BlockdevOptionsGenericFormat, file=BlockdevOptionsFile, ftp=BlockdevOptionsCurlFtp, ftps=BlockdevOptionsCurlFtps, gluster=BlockdevOptionsGluster, host_cdrom=BlockdevOptionsFile, host_device=BlockdevOptionsFile, http=BlockdevOptionsCurlHttp, https=BlockdevOptionsCurlHttps, iscsi=BlockdevOptionsIscsi, luks=BlockdevOptionsLUKS, nbd=BlockdevOptionsNbd, nfs=BlockdevOptionsNfs, null-aio=BlockdevOptionsNull, null-co=BlockdevOptionsNull, nvme=BlockdevOptionsNVMe, parallels=BlockdevOptionsGenericFormat, qcow2=BlockdevOptionsQcow2, qcow=BlockdevOptionsQcow, qed=BlockdevOptionsGenericCOWFormat, quorum=BlockdevOptionsQuorum, raw=BlockdevOptionsRaw, rbd=BlockdevOptionsRbd, replication=BlockdevOptionsReplication, sheepdog=BlockdevOptionsSheepdog, ssh=BlockdevOptionsSsh, throttle=BlockdevOptionsThrottle, vdi=BlockdevOptionsGenericFormat, vhdx=BlockdevOptionsGenericFormat, vmdk=BlockdevOptionsGenericCOWFormat, vpc=BlockdevOptionsGenericFormat, vvfat=BlockdevOptionsVVFAT, vxhs=BlockdevOptionsVxHS}, innerTypes=null, fields=null, base={driver=BlockdevDriver, *node-name=str, *discard=BlockdevDiscardOptions, *cache=BlockdevCacheOptions, *read-only=bool, *force-share=bool, *detect-zeroes=BlockdevDetectZeroesOptions}, discriminatorField=null}</pre>
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class BlockdevOptions extends BlockdevOptionsBase implements QApiUnion {
Expand All @@ -40,6 +40,11 @@ public class BlockdevOptions extends BlockdevOptionsBase implements QApiUnion {
@CheckForNull
public BlockdevOptionsGenericFormat cloop;
@SuppressFBWarnings("NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
@JsonProperty("copy-on-read")
@JsonUnwrapped
@CheckForNull
public BlockdevOptionsGenericFormat copyOnRead;
@SuppressFBWarnings("NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
@JsonProperty("dmg")
@JsonUnwrapped
@CheckForNull
Expand Down Expand Up @@ -238,6 +243,14 @@ public static BlockdevOptions cloop(@Nonnull BlockdevOptionsGenericFormat cloop)
return self;
}

@Nonnull
public static BlockdevOptions copyOnRead(@Nonnull BlockdevOptionsGenericFormat copyOnRead) {
BlockdevOptions self = new BlockdevOptions();
self.driver = BlockdevDriver.copy_on_read;
self.copyOnRead = copyOnRead;
return self;
}

@Nonnull
public static BlockdevOptions dmg(@Nonnull BlockdevOptionsGenericFormat dmg) {
BlockdevOptions self = new BlockdevOptions();
Expand Down Expand Up @@ -509,6 +522,7 @@ public java.util.List<java.lang.String> getFieldNames() {
names.add("blkverify");
names.add("bochs");
names.add("cloop");
names.add("copy-on-read");
names.add("dmg");
names.add("file");
names.add("ftp");
Expand Down Expand Up @@ -556,6 +570,8 @@ public Object getFieldByName(@Nonnull java.lang.String name) throws NoSuchFieldE
return bochs;
if ("cloop".equals(name))
return cloop;
if ("copy-on-read".equals(name))
return copyOnRead;
if ("dmg".equals(name))
return dmg;
if ("file".equals(name))
Expand Down Expand Up @@ -636,6 +652,8 @@ public boolean isValidUnion() {
count++;
if (cloop != null)
count++;
if (copyOnRead != null)
count++;
if (dmg != null)
count++;
if (file != null)
Expand Down
Loading