-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerParser.java
More file actions
828 lines (721 loc) · 28 KB
/
Copy pathDockerParser.java
File metadata and controls
828 lines (721 loc) · 28 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
import models.*;
import models.commands.*;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
/**
* Created by salizumberi-laptop on 22.10.2016.
*/
public class DockerParser {
Snapshot dockerfile = new Snapshot();
public String localDockerfilePath;
public String localPath;
public From from;
public Maintainer maintainer;
public Cmd cmd;
public EntryPoint entryPoint;
public StopSignal stopSignal;
public Healthcheck healthcheck;
public List<Run> runs = new ArrayList<>();
public List<Label> labels = new ArrayList<>();
public List<Env> envs = new ArrayList<>();
public List<Expose> exposes = new ArrayList<>();
public List<Add> adds = new ArrayList<>();
public List<Copy> copies = new ArrayList<>();
public List<Volume> volumes = new ArrayList<>();
public List<User> users = new ArrayList<>();
public List<WorkDir> workDirs = new ArrayList<>();
public List<Arg> args = new ArrayList<>();
public List<OnBuild> onBuilds = new ArrayList<>();
public List<Comment> comments = new ArrayList<>();
public DockerParser(String localpath, String localDockerfilePath) {
String[] pathTokens = localDockerfilePath.split("/");
if (pathTokens.length == 1) {
this.localDockerfilePath = "";
} else {
String newPath = "";
for (int i = 0; i < pathTokens.length - 1; i++) {
newPath += pathTokens[i] + "/";
}
this.localDockerfilePath = newPath;
}
this.localPath = localpath;
}
public DockerParser(String localpath) {
this.localDockerfilePath = "";
this.localPath = localpath;
}
public Snapshot getDockerfileObject(String fileName) throws IOException {
dockerfile = new Snapshot();
File fileToBeFlat = new File(fileName);
File flatDockerfile = getFlatDockerFile(fileToBeFlat);
doClassificationOfLines(flatDockerfile);
assignToDockerObject(fileToBeFlat);
return dockerfile;
}
public Snapshot getDockerfileObject() throws IOException {
dockerfile = new Snapshot();
File fileToBeFlat = new File(this.localPath + "/" + this.localDockerfilePath + "/" + "Dockerfile");
File flatDockerfile = getFlatDockerFile(fileToBeFlat);
doClassificationOfLines(flatDockerfile);
assignToDockerObject(fileToBeFlat);
return dockerfile;
}
public void printLines(File file) throws IOException {
try (Stream<String> lines = Files.lines(file.toPath(), Charset.defaultCharset())) {
lines.forEachOrdered(System.out::println);
}
}
private boolean checkForInstruction(String line){
boolean a = isContainExactWord(line, "FROM");
boolean b = isContainExactWord(line, "ADD");
boolean c = isContainExactWord(line, "COPY");
boolean d = isContainExactWord(line, "RUN");
boolean e = isContainExactWord(line, "LABEL");
boolean f = isContainExactWord(line, "ENV");
boolean g = isContainExactWord(line, "ARG");
boolean h = isContainExactWord(line, "VOLUME");
boolean i = isContainExactWord(line, "MAINTAINER");
boolean j = isContainExactWord(line, "HEALTHCHECK");
boolean k = isContainExactWord(line, "STOPSIGNAL");
boolean l = isContainExactWord(line, "EXPOSE");
boolean m = isContainExactWord(line, "CMD");
boolean n = isContainExactWord(line, "ENTRYPOINT");
boolean o = isContainExactWord(line, "ONBUILD");
boolean p = isContainExactWord(line, "USER");
boolean q = isContainExactWord(line, "WORKDIR");
if(a || b || c ||d ||e ||f ||g ||h ||i|| j ||k|| l|| m|| n|| o|| p|| q){
return true;
}else{
return false;
}
}
private boolean isContainExactWord(String fullString, String partWord){
String pattern = "\\b"+partWord+"\\b";
Pattern p=Pattern.compile(pattern);
Matcher m=p.matcher(fullString);
return m.find();
}
public List<Comment> getCommentsFromDockerfile(File flatDockerFile, Snapshot snapshot) throws IOException {
List<Comment> comments = new ArrayList<>();
FileInputStream fis = new FileInputStream(flatDockerFile);
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String line = null;
String instruction = "";
String newLine = "";
boolean out = false;
boolean commentFlag = false;
boolean header = false;
while ((line = reader.readLine()) != null) {
statement:
if (line.startsWith("#")) {
String tempLine = line;
tempLine = tempLine.replaceFirst("#","");
if(checkForInstruction(tempLine)){
boolean outCommInstruction = true;
Comment c = new Comment(snapshot, "commented out: " + getInstructionInString(tempLine),tempLine);
comments.add(c);
break statement;
}
if(commentFlag){
String concatComment = line.replaceFirst("#"," ");
newLine += concatComment;
}else{
newLine += line;
commentFlag = true;
}
}else if (line.trim().isEmpty()) {
if(commentFlag && header){
Comment c = new Comment(snapshot, "standalone",newLine);
comments.add(c);
}else if(commentFlag && !header){
Comment c = new Comment(snapshot, "header",newLine);
comments.add(c);
header = true;
}
newLine = "";
instruction = "";
commentFlag = false;
}else if (doesLineHaveAnInstruction(line) && commentFlag) {
if(line.contains("\t")){
String uname = " ";
line = line.replaceAll("\t", uname);
}
String arr[] = line.split(" ", 2);
String foundInstruction = arr[0];
Comment c = new Comment(snapshot, "before " + foundInstruction,newLine);
comments.add(c);
newLine = "";
instruction = "";
commentFlag = false;
}
}
reader.close();
fis.close();
if(comments.size()>0){
return comments;
}
return comments;
}
public File getFlatDockerFile(File dockerFile) throws IOException {
File flatDockerfile = new File(dockerFile.getParentFile().getPath() + "\\DockerFileFlat");
/*if(!flatDockerfile.createNewFile()){
flatDockerfile = this.findFile("DockerFileFlat",new File(this.localPath + "/" + this.localDockerfilePath) );
}*/
BufferedWriter writer = new BufferedWriter(new FileWriter(flatDockerfile));
FileInputStream fis = new FileInputStream(dockerFile);
//Construct BufferedReader from InputStreamReader
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String line = null;
String newLine = null;
boolean hc = false;
boolean concatFlag = false;
while ((line = reader.readLine()) != null) {
if (doesLineHaveAnInstruction(line) && line.contains(" \\")) {
newLine = "";
newLine += line;
concatFlag = true;
} else if (line.contains(" \\") && concatFlag) {
newLine += line;
} else if (newLine != null && newLine.contains("HEALTHCHECK") && !hc) {
newLine += line;
hc = true;
} else if (!doesLineHaveAnInstruction(line) && !line.contains(" \\") && concatFlag) {
newLine += line;
newLine = newLine.replace(" \\", "");
newLine = newLine.trim().replaceAll(" +", " ");
writer.write(newLine);
writer.newLine();
concatFlag = false;
} else if (doesLineHaveAnInstruction(line) && !line.contains(" \\")) {
line = line.trim().replaceAll(" +", " ");
writer.write(line);
writer.newLine();
}
}
writer.close();
reader.close();
fis.close();
return flatDockerfile;
}
public File getFlatDockerFile(String localRepoPath, String localDockerfilePath) throws IOException {
String localPathtoDockerfile = localRepoPath.concat("/").concat(localDockerfilePath);
File dockerfile = findFile("Dockerfile", new File(localPathtoDockerfile));
return getFlatDockerFile(dockerfile);
}
public File getFlatDockerFile(String fileName) throws IOException {
String localPathtoDockerfile = localPath.concat("/").concat("/").concat(localDockerfilePath);
File dockerfile = findFile(fileName, new File(localPathtoDockerfile));
return getFlatDockerFile(dockerfile);
}
private static String getInstructionInString(String line) {
if (line.contains("ADD")) {
return "ADD";
} else if (line.contains("FROM")) {
return "FROM";
} else if (line.contains("CMD")) {
return "CMD";
} else if (line.contains("COPY")) {
return "COPY";
} else if (line.contains("ENTRYPOINT")) {
return "ENTRYPOINT";
} else if (line.contains("ENV")) {
return "ENV";
} else if (line.contains("EXPOSE")) {
return "EXPOSE";
} else if (line.contains("FROM")) {
return "FROM";
} else if (line.contains("HEALTHCHECK")) {
return "HEALTHCHECK";
} else if (line.contains("INSTRUCTION")) {
return "INSTRUCTION";
} else if (line.contains("LABEL")) {
return "LABEL";
} else if (line.contains("MAINTAINER")) {
return "MAINTAINER";
} else if (line.contains("ONBUILD")) {
return "ONBUILD";
} else if (line.contains("RUN")) {
return "RUN";
} else if (line.contains("STOPSIGNAL")) {
return "STOPSIGNAL";
} else if (line.contains("USER")) {
return "USER";
} else if (line.contains("VOLUME")) {
return "VOLUME";
} else if (line.contains("WORKDIR")) {
return "WORKDIR";
}else{
return "";
}
}
private static boolean doesLineHaveAnInstruction(String line) {
if (line.contains("ADD")) {
return true;
} else if (line.contains("FROM")) {
return true;
} else if (line.contains("CMD")) {
return true;
} else if (line.contains("COPY")) {
return true;
} else if (line.contains("ENTRYPOINT")) {
return true;
} else if (line.contains("ENV")) {
return true;
} else if (line.contains("EXPOSE")) {
return true;
} else if (line.contains("FROM")) {
return true;
} else if (line.contains("HEALTHCHECK")) {
return true;
} else if (line.contains("INSTRUCTION")) {
return true;
} else if (line.contains("LABEL")) {
return true;
} else if (line.contains("MAINTAINER")) {
return true;
} else if (line.contains("ONBUILD")) {
return true;
} else if (line.contains("RUN")) {
return true;
} else if (line.contains("STOPSIGNAL")) {
return true;
} else if (line.contains("USER")) {
return true;
} else if (line.contains("VOLUME")) {
return true;
} else if (line.contains("WORKDIR")) {
return true;
} else if (line.startsWith("#")) {
return true;
} else {
return false;
}
}
public void doClassificationOfLines(File file) throws IOException {
try (Stream<String> lines = Files.lines(file.toPath(), Charset.defaultCharset())) {
lines.forEachOrdered(line -> fillDockerFileObject(getClassification(line)));
}
}
public void fillDockerFileObject(Instruction instructions) {
}
public Instruction getClassification(String newLine) {
String line = newLine;
if (line.startsWith("#")) {
return null;
}
if(line.contains("\t")){
String uname = " ";
line = line.replaceAll("\t", uname);
}
String arr[] = line.split(" ", 2);
String instruction = arr[0]; //Instruction
String command;
if (arr.length > 1) {
command = arr[1];
} else {
command = "";
}
switch (instruction) {
case "FROM":
return parseFromInstruction(command);
case "ENV":
return (parseEnvInstruction(command));
case "MAINTAINER":
return (parseMaintainerInstruction(command));
case "RUN":
return (parseRunInstruction(command));
case "CMD":
return (parseCMDInstruction(command));
case "ADD":
return (parseAddInstruction(command));
case "COPY":
return (parseCopyInstruction(command));
case "EXPOSE":
return (parseExposeInstruction(command));
case "LABEL":
return (parseLabelInstruction(command));
case "ENTRYPOINT":
return (parseEntryPointInstruction(command));
case "VOLUME":
return (parseVolumeInstruction(command));
case "WORKDIR":
return (parseWorkDirInstruction(command));
case "ARG":
return (parseArgInstruction(command));
case "ONBUILD":
return (parseOnBuildInstruction(command));
case "STOPSIGNAL":
return (parseStopSignalInstruction(command));
case "HEALTHCHECK":
return (parseHealthCheckInstruction(command));
case "SHELL":
return (parseShellInstruction(command));
case "USER":
return (parseUserInstruction(command));
}
return null;
}
private Instruction parseExposeInstruction(String ports) {
String[] parts = ports.split(" ");
for (int i = 0; i < parts.length; i++) {
exposes.add(new Expose(dockerfile,parts[i]));
}
return null;
}
private Instruction parseEntryPointInstruction(String command) {
String executable = null;
List<String> params = new ArrayList<>();
if (command.contains("[")) {
Pattern p = Pattern.compile("\"(.*?)\"");
Matcher m = p.matcher(command);
List<String> matches = new ArrayList<String>();
while (m.find()) {
matches.add(m.group(1));
}
for (int i = 0; i < matches.size(); i++) {
if (i == 0) {
executable = matches.get(i);
} else {
params.add(matches.get(i));
}
}
} else {
String[] parts = command.split(" ");
for (int i = 0; i < parts.length; i++) {
if (i == 0) {
executable = parts[i];
} else {
params.add(parts[i]);
}
}
}
if(executable.length()>0){
entryPoint = new EntryPoint(dockerfile, executable, params);
}
return null;
}
public Instruction copyAndAdd(String command, String instruction) {
String source = null;
String destinatation = null;
if (command.contains("[")) {
Pattern p = Pattern.compile("\"(.*?)\"");
Matcher m = p.matcher(command);
List<String> matches = new ArrayList<String>();
while (m.find()) {
matches.add(m.group(1));
}
for (int i = 0; i < matches.size(); i++) {
if (i == 0) {
source = matches.get(i);
} else {
source = matches.get(i);
}
}
} else {
String[] parts = command.split(" ");
for (int i = 0; i < parts.length; i++) {
if (i == 0) {
source = parts[i];
} else {
destinatation = parts[i];
}
}
}
if (instruction.equals("ADD")) {
adds.add(new Add(dockerfile, source, destinatation));
} else if (instruction.equals("COPY")) {
copies.add(new Copy(dockerfile, source, destinatation));
}
return null;
}
private Instruction parseCopyInstruction(String command) {
return copyAndAdd(command, "COPY");
}
private Instruction parseAddInstruction(String command) {
return copyAndAdd(command, "ADD");
}
private Instruction parseWorkDirInstruction(String path) {
workDirs.add(new WorkDir(dockerfile, path));
return new WorkDir(dockerfile, path);
}
private Instruction parseLabelInstruction(String command) {
String[] parts = command.split(" ");
for (int i = 0; i < parts.length; i++) {
String[] split = command.split("=");
String key = split[0];
String value = split[0];
Pattern p = Pattern.compile("\"(.*?)\"");
Matcher m = p.matcher(value);
while (m.find()) {
value = m.group(1);
}
labels.add(new Label(dockerfile, key, value));
}
return new Label(dockerfile, "", "");
}
private Instruction parseHealthCheckInstruction(String command) {
Healthcheck hc= null;
String instruction = getInstructionInString(command);
String[] split = command.split(" ",2);
if(checkForInstruction(split[0]) && split.length>0){
hc = new Healthcheck(dockerfile, instruction,split[1]);
}else{
int index = command.indexOf(instruction);
String paramter = command.substring(0, index);
String fullInstruction = command.substring(index);
String[] fullInstructions = fullInstruction.split(" ",2);
hc = new Healthcheck(dockerfile,instruction,paramter, fullInstructions[1]);
}
healthcheck = hc;
return hc;
}
private Instruction parseCMDInstruction(String command) {
String executable = null;
List<String> params = new ArrayList<>();
if (command.contains("[")) {
Pattern p = Pattern.compile("\"(.*?)\"");
Matcher m = p.matcher(command);
List<String> matches = new ArrayList<String>();
while (m.find()) {
matches.add(m.group(1));
}
for (int i = 0; i < matches.size(); i++) {
if (i == 0) {
executable = matches.get(i);
} else {
params.add(matches.get(i));
}
}
} else {
String[] parts = command.split(" ");
for (int i = 0; i < parts.length; i++) {
if (i == 0) {
executable = parts[i];
} else {
params.add(parts[i]);
}
}
}
// cmds.add(new Cmd(dockerfile,executable, params));
if(executable.length()>0){
cmd = new Cmd(dockerfile, executable, params);
}
return null;
}
private Instruction parseStopSignalInstruction(String signal) {
stopSignal = new StopSignal(dockerfile, signal);
return new StopSignal(dockerfile, signal);
}
private Instruction parseArgInstruction(String arg) {
args.add(new Arg(dockerfile,arg));
return new Arg(dockerfile,arg);
}
private Instruction parseRunInstruction(String commandx) {
String command = commandx;
if (commandx.contains("(") && !commandx.contains("echo ")) {
Matcher m = Pattern.compile("\\(([^)]+)\\)").matcher(commandx);
while (m.find()) {
command = m.group(1);
}
}
String[] runentry = command.split(" && ");
for (String run : runentry) {
String executable = "";
List<String> params = new ArrayList<>();
if (commandx.contains("echo")) {
executable = "echo";
String arr[] = commandx.split(" ", 2);
for (int i = 0; i < arr.length; i++) {
params.add(arr[i]);
}
}else{
if (command.contains("[")) {
Pattern p = Pattern.compile("\"(.*?)\"");
Matcher m = p.matcher(command);
List<String> matches = new ArrayList<String>();
while (m.find()) {
matches.add(m.group(1));
}
for (int i = 0; i < matches.size(); i++) {
if (i == 0) {
executable = matches.get(i);
} else {
params.add(matches.get(i));
}
}
}else {
String[] parts = run.split(" ");
for (int i = 0; i < parts.length; i++) {
if (i == 0) {
executable = parts[i];
} else {
params.add(parts[i]);
}
}
}
}
if(executable.length()>0){
runs.add(new Run(dockerfile, executable, params));
}
}
return null;
}
private Instruction parseVolumeInstruction(String command) {
if (command.contains("[")) {
Pattern p = Pattern.compile("\"(.*?)\"");
Matcher m = p.matcher(command);
List<String> matches = new ArrayList<String>();
while (m.find()) {
matches.add(m.group(1));
}
for (String match :
matches) {
volumes.add(new Volume(dockerfile, match));
}
} else {
String[] parts = command.split(" ");
for (int i = 0; i < parts.length; i++) {
volumes.add(new Volume(dockerfile, parts[i]));
}
}
return new Volume(dockerfile, "test");
}
private Instruction parseOnBuildInstruction(String command) {
OnBuild onBuild= null;
String instruction = getInstructionInString(command);
String[] split = command.split(" ",2);
if(checkForInstruction(split[0]) && split.length>0){
onBuild = new OnBuild(dockerfile, instruction,split[1]);
}
onBuilds.add(onBuild);
return onBuild;
}
private Instruction parseUserInstruction(String command) {
users.add(new User(dockerfile, command));
return new User(dockerfile, command);
}
private Instruction parseShellInstruction(String command) {
return null;
}
private Instruction parseMaintainerInstruction(String user) {
maintainer = new Maintainer(dockerfile, user);
return new Maintainer(dockerfile, user);
}
private Env parseEnvInstruction(String command) {
String[] parts = command.split(" ");
String key = parts[0];
String value = "";
if (parts.length > 1) {
value = parts[1];
}
envs.add(new Env(dockerfile, key, value));
return new Env(dockerfile, key, value);
}
private Instruction parseFromInstruction(String command) {
if (command.contains("/")) {
from = new From(dockerfile,command);
return from;
} else if (command.contains("@")) {
String[] parts = command.split("@");
String image = parts[0];
String imageVersion = parts[1];
from = new From(dockerfile,image, imageVersion, "digest");
return from;
} else if (command.split("\\w+").length == 0) {
from = new From(dockerfile,command);
return from;
} else if (command.matches(".*\\d+.*")) {
Double imageVersion = Double.parseDouble(getStringFromRegexPattern("\\d+\\.?\\d+", command));
String[] parts = command.split(":");
String image = parts[0];
from = new From(dockerfile,image, imageVersion);
return from;
} else if (command.matches("\\w*(:)\\w+")){
String[] parts = command.split(":");
String image = parts[0];
String imageVersion = parts[1];
from = new From(dockerfile,image, imageVersion, "imageVersion");
return from;
}
return from;
}
public String getStringFromRegexPattern(String patternInput, String data) {
Pattern pattern = Pattern.compile(patternInput);
Matcher matcher = pattern.matcher(data);
try {
if (matcher.find()) {
// System.out.println("getStringFromRegexPattern" + matcher.group(0));
}
return matcher.group(0);
}catch (Exception e){
e.printStackTrace();
return "";
}
}
public File findFile(String name, File path) {
File[] list = path.listFiles();
if (list != null)
for (File file : list) {
if (file.isDirectory()) {
findFile(name, file);
} else if (name.equalsIgnoreCase(file.getName())) {
return file;
}
}
return null;
}
public void assignToDockerObject(File file) throws IOException {
dockerfile.comments = getCommentsFromDockerfile(file, dockerfile);
dockerfile.from = from;
dockerfile.maintainer = maintainer;
dockerfile.cmd = cmd;
dockerfile.entryPoint = entryPoint;
dockerfile.stopSignals = stopSignal;
dockerfile.healthCheck = healthcheck;
dockerfile.runs = this.runs;
dockerfile.labels = this.labels;
dockerfile.envs = this.envs;
dockerfile.exposes = this.exposes;
dockerfile.adds = this.adds;
dockerfile.copies = this.copies;
dockerfile.volumes = this.volumes;
dockerfile.users = this.users;
dockerfile.workDirs = this.workDirs;
dockerfile.args = this.args;
dockerfile.onBuilds = this.onBuilds;
}
/* @Override
public String toString() {
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(JsonMethod.FIELD, JsonAutoDetect.Visibility.ANY);
String json = null;
try {
//Convert object to JSON string and save into file directly
mapper.writeValue(new File(localPath + "/" + "dockerfile.json"), dockerfile);
//Convert object to JSON string
json = mapper.writeValueAsString(dockerfile);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(json);
String prettyJsonString = gson.toJson(je);
String header = "*************************************************** \n";
String footer = "*************************************************** \n";
return header + prettyJsonString + footer;
}
public void printDockerfile(DockerfileSnapshot dockerfileSnapshot) {
System.out.println(this.toString());
}*/
}