Skip to content

Commit

Permalink
Define more data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 committed Jun 13, 2018
1 parent b777986 commit 88829e1
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 4 deletions.
2 changes: 1 addition & 1 deletion analyzer/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

dependencies {
compile project(':model')
compile project(':logging')
compile project(':util')
// compile 'org.rocksdb:rocksdbjni:5.13.2'
// compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.23.1'
testCompile 'junit:junit:4.12'
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

dependencies {
compile project(":model")
compile project(":logging")
compile project(":util")
compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.2.4'

// Check if lite dep could be used
Expand Down
16 changes: 16 additions & 0 deletions model/src/File.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

option java_package = "castro.file";
option java_multiple_files = true;

message FileLocation {
string fileHash = 1; // git sha1
string repositoryId = 2;
}

message RichDocument {
FileLocation fileLocation = 1;
string path = 2;
string fileContent = 3;
repeated string nodes = 4; // TODO
}
2 changes: 1 addition & 1 deletion model/src/Repository.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ option java_package = "castro.repository";
option java_multiple_files = true;

message Repository {
string uri = 1;
string repositoryId = 1;

string domain = 2;
string name = 3;
Expand Down
21 changes: 21 additions & 0 deletions model/src/SyntaxHighlight.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";

option java_package = "castro.syntaxhighlight";
option java_multiple_files = true;

import "File.proto";

message FileSyntaxHighlight {
FileLocation fileLocation = 1;

message LineSyntaxHight {
int32 line = 1;
repeated SyntaxHightTag tags = 2;
}

message SyntaxHightTag {
int32 start = 1;
int32 end = 2;
string tag = 3;
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include 'logging'
include 'util'
include 'elasticsearch'

include 'backend'
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions util/src/main/java/castro/hash/FileHash.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package castro.hash;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class FileHash {
// https://gist.github.com/alecthegeek/333663
String compute(String content) {
try {
var builder = new StringBuilder();
builder.append("blob ");
builder.append(content.length());
builder.append("\0");
builder.append(content);
var input = builder.toString().getBytes("UTF-8");

MessageDigest msdDigest = MessageDigest.getInstance("SHA-1");
msdDigest.update(input);
BigInteger n = new BigInteger(msdDigest.digest());
return n.toString(16);
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
// Logger.getLogger(Encriptacion.class.getName()).log(Level.SEVERE, null, e);
}
return null;
}
}

0 comments on commit 88829e1

Please sign in to comment.