7
7
import com .jcabi .log .Logger ;
8
8
import java .io .File ;
9
9
import java .io .IOException ;
10
+ import java .nio .charset .StandardCharsets ;
10
11
import java .nio .file .Files ;
11
12
import java .nio .file .Path ;
12
13
import java .util .Arrays ;
15
16
import java .util .Optional ;
16
17
import org .apache .maven .plugins .annotations .LifecyclePhase ;
17
18
import org .apache .maven .plugins .annotations .Mojo ;
19
+ import org .cactoos .bytes .BytesOf ;
18
20
import org .cactoos .scalar .Unchecked ;
19
21
20
22
/**
@@ -138,70 +140,6 @@ private long place() {
138
140
.count ();
139
141
}
140
142
141
- /**
142
- * Check if the file is not a source file.
143
- * @param file The file to check.
144
- * @return True if the file is not a source file.
145
- */
146
- private boolean isNotEoSource (final Path file ) {
147
- final boolean res ;
148
- final Path path = this .dir .relativize (file );
149
- if (path .startsWith (CopyMojo .DIR )) {
150
- Logger .debug (
151
- this ,
152
- "File %[file]s (%[size]s) is not a binary, but a source, won't place it" ,
153
- path , path .toFile ().length ()
154
- );
155
- res = false ;
156
- } else {
157
- res = true ;
158
- }
159
- return res ;
160
- }
161
-
162
- /**
163
- * Check whether the binary file has corresponding EO sources in the jar.
164
- *
165
- * <p>The method checks ONLY EO binaries and classes. All other java files or classes in jar
166
- * will be included anyway.
167
- * Let's consider the next filesystem structure:</p>
168
- *
169
- * <pre>
170
- * Source file:
171
- * - "EO-SOURCE/org/eolang/txt/x.eo" -
172
- *
173
- * Correct:
174
- * - "EOorg/EOeolang/EOtxt/x.class" - is correct since has corresponding EO source folder
175
- * - "EOorg/EOeolang/EOtxt/y&z.class" - is correct since has corresponding EO source folder
176
- * - "com/sun/jna/Callback.class" - is correct since binary file is not in EOorg folder
177
- *
178
- * Is incorrect (since has no corresponding EO source folder):
179
- * - "EOorg/EOeolang/EObool.class"
180
- * - "EOorg/x.class"
181
- * </pre>
182
- *
183
- * <p>The filter is disabled by default, works only if the parameter
184
- * "placeBinariesThatHaveSources" is set to true.</p>
185
- *
186
- * @param file The file to check.
187
- * @return True if the file has corresponding EO sources.
188
- */
189
- private boolean hasEoSource (final Path file ) {
190
- final boolean result ;
191
- if (PlaceMojo .this .placeBinariesThatHaveSources && file .toString ().contains ("EOorg" )) {
192
- final Path sources = this .dir .resolve (CopyMojo .DIR )
193
- .resolve (this .dir .relativize (file .getParent ()).toString ().replace ("EO" , "" ));
194
- result = Files .exists (sources )
195
- && Files .isDirectory (sources )
196
- && Arrays .stream (sources .toFile ().listFiles ())
197
- .filter (Objects ::nonNull )
198
- .anyMatch (File ::isFile );
199
- } else {
200
- result = true ;
201
- }
202
- return result ;
203
- }
204
-
205
143
/**
206
144
* Check if the file is not already placed.
207
145
* @param file The file to check.
@@ -266,7 +204,9 @@ private void printLogInfoAboutBinary(final Path file) {
266
204
private void placeBinary (final Path file ) {
267
205
final Path path = this .dir .relativize (file );
268
206
try {
269
- final Footprint generated = new FpGenerated (Files ::readString );
207
+ final Footprint generated = new FpGenerated (
208
+ src -> new String (new BytesOf (src ).asBytes (), StandardCharsets .UTF_8 )
209
+ );
270
210
final Path target = new FpIfTargetExists (
271
211
new FpFork (this .rewrite , generated , new FpIgnore ()),
272
212
generated
@@ -278,10 +218,11 @@ private void placeBinary(final Path file) {
278
218
);
279
219
} catch (final IOException ex ) {
280
220
throw new IllegalStateException (
281
- String .format (
282
- "Failed to place %s to home %s with path %s" ,
221
+ Logger .format (
222
+ "Failed to place %[file] s to home %[file] s with path %s" ,
283
223
file , PlaceMojo .this .outputDir , path
284
- ), ex
224
+ ),
225
+ ex
285
226
);
286
227
}
287
228
}
0 commit comments