1 //
2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.start;
20
21 import java.nio.file.Path;
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.eclipse.jetty.start.RawArgs.Entry;
27
28 public class RawArgs implements Iterable<Entry>
29 {
30 public class Entry
31 {
32 private String line;
33 private String origin;
34
35 private Entry(String line, String origin)
36 {
37 this.line = line;
38 this.origin = origin;
39 }
40
41 public String getLine()
42 {
43 return line;
44 }
45
46 public String getOrigin()
47 {
48 return origin;
49 }
50
51 public boolean startsWith(String val)
52 {
53 return line.startsWith(val);
54 }
55 }
56
57 /**
58 * All of the args, in argument order
59 */
60 private List<Entry> args = new ArrayList<>();
61
62 public void addAll(List<String> lines, Path sourceFile)
63 {
64 String source = sourceFile.toAbsolutePath().toString();
65 for (String line : lines)
66 {
67 addArg(line,source);
68 }
69 }
70
71 public void addArg(final String rawline, final String source)
72 {
73 if (rawline == null)
74 {
75 return;
76 }
77
78 String line = rawline.trim();
79 if (line.length() == 0)
80 {
81 return;
82 }
83
84 args.add(new Entry(line,source));
85 }
86
87 @Override
88 public Iterator<Entry> iterator()
89 {
90 return args.iterator();
91 }
92
93 public int size()
94 {
95 return args.size();
96 }
97 }