1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.cli;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24
25
26
27 @Deprecated
28 public class CleanArgument {
29 public static String[] cleanArgs(String[] args) {
30 try {
31 return doCleanArgs(args);
32 } catch (RuntimeException e) {
33 for (String a : args) {
34 System.out.println("Arg: '" + a + "'");
35 }
36 throw e;
37 }
38 }
39
40 private static String[] doCleanArgs(String[] args) {
41 List<String> cleaned = new ArrayList<>();
42
43 StringBuilder currentArg = null;
44
45 for (String arg : args) {
46 boolean addedToBuffer = false;
47
48 if (arg.startsWith("\"")) {
49
50
51 if (currentArg != null) {
52 cleaned.add(currentArg.toString());
53 }
54
55
56 currentArg = new StringBuilder(arg.substring(1));
57 addedToBuffer = true;
58 }
59
60
61 if (addedToBuffer && arg.endsWith("\"")) {
62
63
64 if (!currentArg.isEmpty()) {
65 currentArg.setLength(currentArg.length() - 1);
66 }
67
68 cleaned.add(currentArg.toString());
69
70 currentArg = null;
71 addedToBuffer = false;
72 continue;
73 }
74
75
76
77
78
79 if (!addedToBuffer) {
80 if (currentArg != null) {
81 currentArg.append(' ').append(arg);
82 } else {
83 cleaned.add(arg);
84 }
85 }
86 }
87
88 if (currentArg != null) {
89 cleaned.add(currentArg.toString());
90 }
91
92 int cleanedSz = cleaned.size();
93
94 String[] cleanArgs;
95
96 if (cleanedSz == 0) {
97 cleanArgs = args;
98 } else {
99 cleanArgs = cleaned.toArray(new String[0]);
100 }
101
102 return cleanArgs;
103 }
104 }