10
10
11
11
interface BazelSourceFileTarget {
12
12
String getName ();
13
- byte [] getDigest () throws NoSuchAlgorithmException ;
13
+ byte [] getDigest ();
14
14
}
15
15
16
16
class BazelSourceFileTargetImpl implements BazelSourceFileTarget {
17
17
18
18
private String name ;
19
19
private byte [] digest ;
20
20
21
- BazelSourceFileTargetImpl (String name , byte [] digest , Path workingDirectory ) throws IOException {
21
+ BazelSourceFileTargetImpl (String name , byte [] digest , Path workingDirectory ) throws IOException , NoSuchAlgorithmException {
22
22
this .name = name ;
23
+ byte [] data = null ;
23
24
if (workingDirectory != null && name .startsWith ("//" )) {
24
25
String filenameSubstring = name .substring (2 );
25
26
String filenamePath = filenameSubstring .replaceFirst (":" , "/" );
@@ -28,12 +29,18 @@ class BazelSourceFileTargetImpl implements BazelSourceFileTarget {
28
29
ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();
29
30
outputStream .write (Files .readAllBytes (sourceFile .toPath ()));
30
31
outputStream .write (digest );
31
- this . digest = outputStream .toByteArray ();
32
+ data = outputStream .toByteArray ();
32
33
outputStream .close ();
33
34
}
34
35
} else {
35
- this . digest = digest ;
36
+ data = digest ;
36
37
}
38
+ MessageDigest finalDigest = MessageDigest .getInstance ("SHA-256" );
39
+ if (data != null ) {
40
+ finalDigest .update (data );
41
+ }
42
+ finalDigest .update (name .getBytes ());
43
+ this .digest = finalDigest .digest ();
37
44
}
38
45
39
46
@ Override
@@ -42,12 +49,7 @@ public String getName() {
42
49
}
43
50
44
51
@ Override
45
- public byte [] getDigest () throws NoSuchAlgorithmException {
46
- MessageDigest finalDigest = MessageDigest .getInstance ("SHA-256" );
47
- if (digest != null ) {
48
- finalDigest .update (digest );
49
- }
50
- finalDigest .update (name .getBytes ());
51
- return finalDigest .digest ();
52
+ public byte [] getDigest () {
53
+ return this .digest ;
52
54
}
53
55
}
0 commit comments