All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.shiftleft.cpgloading.tinkergraphshiftleft.ProtoToCpg Maven / Gradle / Ivy

There is a newer version: 0.9.115
Show newest version
package io.shiftleft.cpgloading.tinkergraphshiftleft;

import io.shiftleft.cpgloading.ProtoToCpgBase;
import io.shiftleft.proto.cpg.Cpg;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;

public class ProtoToCpg extends ProtoToCpgBase {

  public ProtoToCpg() {
    super(TinkerGraph.open(
      // TODO generate factories for case classes
      // io.shiftleft.codepropertygraph.generated.nodes.Factories$.MODULE$.AllAsJava(),
      // io.shiftleft.codepropertygraph.generated.edges.Factories$.MODULE$.AllAsJava()
    ));
  }

  @Override
  public void addNodes(Cpg.CpgStruct protoCpg) {
    for (Cpg.CpgStruct.Node protoNode : protoCpg.getNodeList()) {
      // if (elementImportCounter % 1000 == 0) {
      //   long millisSinceLastBatch = System.currentTimeMillis() - lastStart;
      //   lastStart = System.currentTimeMillis();
      //   System.out.println("importing node " + elementImportCounter + "; millis since last batch: " + millisSinceLastBatch);
      // }
      elementImportCounter++;
      Vertex node;
      try {
        node = graph.addVertex(T.id, protoNode.getKey(),
          T.label, protoNode.getType().name());
        keyToVertexId.put(protoNode.getKey(), node.id());
      } catch (IllegalArgumentException exception) {
        logger.warn("Failed to insert a vertex", exception);
        continue;
      }
      for (Cpg.CpgStruct.Node.Property property : protoNode.getPropertyList()) {
        addPropertyToElement(node, property.getName().name(), property.getValue());
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy