Skip to content

Commit

Permalink
Various Java API improvements
Browse files Browse the repository at this point in the history
* Fixed the Node UUID lookup map to actually get populated.
* Added more constructors to allow greater flexibility in populating new
  GTIRB data.
* Fixed ByteInterval handling of things like .bss, so that the size of a
  ByteInterval doesn't need to match the length of its contents.
* Fixed misleading Symbol method names.
* Added a generic version of Node.getByUuid
* Added Gradle settings to allow easy import into Java IDEs like IntelliJ,
  Eclipse, etc.
* Organized AuxData serialization classes into a subdirectory
* More type-safe AuxData type string parsing
  • Loading branch information
Jennifer Berringer committed Dec 16, 2021
1 parent 7e779c6 commit 3fa58fc
Showing 36 changed files with 717 additions and 791 deletions.
5 changes: 5 additions & 0 deletions java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea
.gradle
gradle
gradlew
gradlew.bat
33 changes: 16 additions & 17 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -63,41 +63,44 @@ configure_file(
)

set(GTIRB_API_JAVAS
AuxSerialization/AuxDataSerialization
AuxSerialization/AuxTypeTree
AuxSerialization/Codec
AuxSerialization/DecodeException
AuxSerialization/EncodeException
AuxSerialization/IntegerCodec
AuxSerialization/MappingCodec
AuxSerialization/OffsetCodec
AuxSerialization/SequenceCodec
AuxSerialization/SetCodec
AuxSerialization/StreamSerialization
AuxSerialization/StringCodec
AuxSerialization/TupleCodec
AuxSerialization/UnknownCodecException
AuxSerialization/UnknownData
AuxSerialization/UuidCodec
Alignment
AuxDataContainer
AuxData
AuxDataSerialization
Block
ByteBlock
ByteInterval
CFG
CodeBlock
Codec
Comments
DataBlock
DecodeException
Edge
EncodeException
FiveTuple
FunctionBlocks
FunctionEntries
FunctionNames
IntegerCodec
IR
MappingCodec
Module
Node
OffsetCodec
Offset
Padding
ParsedProduct
ProxyBlock
Section
SequenceCodec
Serialization
SetCodec
StreamSerialization
StringCodec
SymAddrAddr
SymAddrConst
SymbolForwarding
@@ -106,13 +109,9 @@ set(GTIRB_API_JAVAS
ThreeTuple
TreeListItem
TreeListUtils
TupleCodec
TwoTuple
Types
UnknownCodecException
UnknownData
Util
UuidCodec
Version
)

56 changes: 56 additions & 0 deletions java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Gradle build for GTIRB Java API
*
* NOTE: The supported build system is CMake.
* This Gradle build exists as a convenience to make it easier to develop in
* IDEs like IntelliJ, Eclipse, etc.
*
* Before running Gradle, generate Protobuf Java sources:
* $ protoc --java_out=. --proto-path=proto ../proto/*.proto
*
* After IntelliJ import, it may help to add to its .idea/gradle.xml:
* <option name="resolveModulePerSourceSet" value="false" />
*/
apply plugin: 'java'

repositories { mavenCentral() }

sourceSets {
main.java.srcDirs = ['.', "${buildDir}/generated/java"]
}

dependencies {
compile 'com.google.protobuf:protobuf-java:3.11.1'
}

compileJava {
doFirst {
def pkg = "com/grammatech/gtirb"

// Read the version information from version.txt
def versionTxt = new File("${projectDir}/../version.txt")
def versionMap = [:]
versionTxt.eachLine { String line ->
def (name, value) = line.split()
versionMap[name] = value
}

// This version number appears in the output JAR filename
version = versionMap["VERSION_MAJOR"] + "." +
versionMap["VERSION_MINOR"] + "." + versionMap["VERSION_PATCH"]

// Generate Version.java based on the Version.java.in template
ant.mkdir(dir: "${buildDir}/generated/java/${pkg}/gtirb")
def newVersion = new File("${buildDir}/generated/java/${pkg}/Version.java")
def templateVersion = new File("${projectDir}/Version.java.in")
newVersion.withWriter { def writer ->
templateVersion.eachLine { def line ->
def newLine = line
.replace("@PROJECT_VERSION_MAJOR@", versionMap["VERSION_MAJOR"])
.replace("@PROJECT_VERSION_MINOR@", versionMap["VERSION_MINOR"])
.replace("@PROJECT_VERSION_PATCH@", versionMap["VERSION_PATCH"])
.replace("@GTIRB_PROTOBUF_VERSION@", versionMap["VERSION_PROTOBUF"])
writer.write(newLine + "\n");
}
}
}
}
23 changes: 14 additions & 9 deletions java/com/grammatech/gtirb/AuxDataContainer.java
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import java.util.Set;
import java.util.UUID;

import com.google.protobuf.ByteString;
import com.grammatech.gtirb.proto.AuxDataOuterClass;

/**
@@ -30,19 +31,18 @@
*/
public class AuxDataContainer extends Node {

private Map<String, AuxData> auxDataMap;
private final Map<String, AuxData> auxDataMap;

/**
* Class constructor for an AuxDataContainer from a protobuf AuxData Map.
* @param protoAuxDataMap A Map of AuxData names to protocol buffer
* AuxData objects.
* @param protoUuid The UUID of this container.
* @param protoAuxDataMap A Map of AuxData names to protobuf AuxData
* objects.
*/
public AuxDataContainer(
Map<String, AuxDataOuterClass.AuxData> protoAuxDataMap) {
if (this.auxDataMap == null)
this.auxDataMap = new HashMap<String, AuxData>();
else
this.auxDataMap.clear();
AuxDataContainer(ByteString protoUuid,
Map<String, AuxDataOuterClass.AuxData> protoAuxDataMap) {
super(Util.byteStringToUuid(protoUuid));
this.auxDataMap = new HashMap<>();
if (protoAuxDataMap != null) {
Set<String> auxDataNames = protoAuxDataMap.keySet();
for (String name : auxDataNames) {
@@ -54,6 +54,11 @@ public AuxDataContainer(
}
}

public AuxDataContainer() {
super();
this.auxDataMap = new HashMap<>();
}

private List<String> importListOfString(AuxData auxData) {
List<String> entries = new ArrayList<String>();
if (auxData != null) {
Loading

0 comments on commit 3fa58fc

Please sign in to comment.