1
1
package com .eternalcode .core .loader .relocation ;
2
2
3
- import com .eternalcode .core .loader .dependency .Dependency ;
4
3
import com .eternalcode .core .loader .repository .LocalRepository ;
5
- import com .google .gson .Gson ;
6
- import com .google .gson .reflect .TypeToken ;
7
4
import java .io .File ;
8
5
import java .nio .charset .StandardCharsets ;
9
6
import java .nio .file .Files ;
@@ -15,22 +12,21 @@ public class RelocationCacheResolver {
15
12
16
13
private static final String RELOCATIONS_FILE = "relocations.txt" ;
17
14
18
- private final LocalRepository localRepository ;
15
+ private final File relocationsFile ;
19
16
20
17
public RelocationCacheResolver (LocalRepository localRepository ) {
21
- this .localRepository = localRepository ;
18
+ this .relocationsFile = localRepository . getRepositoryFolder (). resolve ( RELOCATIONS_FILE ). toFile () ;
22
19
}
23
20
24
- public boolean shouldForceRelocate (Dependency dependency , List <Relocation > relocations ) {
25
- return this .getRawSavedRelocations ( dependency )
21
+ public boolean shouldForceRelocate (List <Relocation > relocations ) {
22
+ return this .getSavedRelocations ( )
26
23
.map (savedRelocations -> !savedRelocations .equals (toRawRelocations (relocations )))
27
24
.orElse (true );
28
25
}
29
26
30
- public void markAsRelocated (Dependency dependency , List <Relocation > relocations ) {
27
+ public void markAsRelocated (List <Relocation > relocations ) {
31
28
try {
32
- File relocationsCache = dependency .toResource (localRepository , RELOCATIONS_FILE ).toFile ();
33
- Files .writeString (relocationsCache .toPath (), toRawRelocations (relocations ), StandardCharsets .UTF_8 );
29
+ Files .writeString (relocationsFile .toPath (), toRawRelocations (relocations ), StandardCharsets .UTF_8 );
34
30
} catch (Exception exception ) {
35
31
throw new RuntimeException ("Failed to save relocations" , exception );
36
32
}
@@ -42,16 +38,14 @@ private static String toRawRelocations(List<Relocation> relocations) {
42
38
.collect (Collectors .joining ("\n " ));
43
39
}
44
40
45
- private Optional <String > getRawSavedRelocations ( Dependency dependency ) {
41
+ private Optional <String > getSavedRelocations ( ) {
46
42
try {
47
- File relocationsCache = dependency .toResource (localRepository , RELOCATIONS_FILE ).toFile ();
48
- if (!relocationsCache .exists ()) {
43
+ if (!relocationsFile .exists ()) {
49
44
return Optional .empty ();
50
45
}
51
- return Optional .of (Files .readString (relocationsCache .toPath ()));
46
+ return Optional .of (Files .readString (relocationsFile .toPath (), StandardCharsets . UTF_8 ));
52
47
} catch (Exception exception ) {
53
48
return Optional .empty ();
54
49
}
55
50
}
56
-
57
51
}
0 commit comments