-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathFpDefault.java
More file actions
138 lines (133 loc) · 4.41 KB
/
Copy pathFpDefault.java
File metadata and controls
138 lines (133 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
* SPDX-License-Identifier: MIT
*/
package org.eolang.maven;
import java.nio.file.Path;
import java.util.function.Supplier;
import org.cactoos.Func;
import org.cactoos.io.InputOf;
/**
* Default footprint that covers all the scenarios of updating target
* from source using cache.
* <p>General statements:
* 1) if target is newer than source - target is not updated
* 2) if target is older than source or does not exist - it will be created and filled.
* It can be created from source, or from global cache if cache exists, is cacheable, and
* is newer than source.
* 3) the cache is updated if it is cacheable (it does not exist or if it is older than source)
* </p>
* <p>Excluding any type of errors there are 4 possible scenarios
* of this {@link Footprint} work:
* 1) do nothing and just return target file.
* 2) update target from source and return target.
* 3) update target from source, update cache from target and return target.
* 4) copy content from cache to target and return target.</p>
* @since 0.41
* @todo #4851:60min Remove {@link FpDefault} from codebase.
* The {@link FpDefault} class is used only in tests.
* We should remove it and all tests that use it.
* @checkstyle ParameterNumberCheck (100 lines)
*/
final class FpDefault extends FpEnvelope {
/**
* Ctor.
* @param content Function that returns content from source
* @param base Base cache directory
* @param semver Semver as part of absolute cache path
* @param hash Git hash as part of absolute cache path
* @param tail The last part of absolute cache path
*/
FpDefault(
final Func<Path, String> content,
final Path base,
final String semver,
final String hash,
final Path tail
) {
this(content, base, semver, () -> hash, tail, true);
}
/**
* Ctor.
* @param content Function that returns content from source
* @param base Base cache directory
* @param semver Semver as part of absolute cache path
* @param hash Git hash as part of absolute cache path
* @param tail The last part of absolute cache path
* @param global Is global cache enabled or not
*/
FpDefault(
final Func<Path, String> content,
final Path base,
final String semver,
final Supplier<String> hash,
final Path tail,
final boolean global
) {
this(
new FpGenerated(
src -> new InputOf(content.apply(src))
),
base,
semver,
hash,
tail,
global
);
}
/**
* Ctor.
* @param generated Footprint that generates content
* @param base Base cache path
* @param semver Cache version
* @param hash Cache hash
* @param tail Cache tail path
* @param global Is global cache enabled or not
*/
FpDefault(
final Footprint generated,
final Path base,
final String semver,
final Supplier<String> hash,
final Path tail,
final boolean global
) {
this(generated, hash, new CachePath(base, semver, hash, tail), global);
}
/**
* Ctor.
* <p>Here {@link FpIfReleased} is on the first place because we don't want to work with any
* type of cache (local or global) if we work with SNAPSHOT version of the plugin</p>
* @param generated Footprint that generates content
* @param hash Cache hash
* @param cache Lazy cache path
* @param global Is global cache enabled or not
*/
private FpDefault(
final Footprint generated,
final Supplier<String> hash,
final Supplier<Path> cache,
final boolean global
) {
super(
new FpExistedSource(
new FpIfReleased(
hash,
new FpIfOlder(
new FpIgnore(),
new FpFork(
global,
new FpIfOlder(
target -> cache.get(),
new FpUpdateFromCache(cache),
new FpUpdateBoth(generated, cache)
),
generated
)
),
generated
)
)
);
}
}