author | kcr |
Thu, 10 Jan 2019 11:30:09 -0800 | |
branch | JDK-8200758-branch |
changeset 57106 | ea870b9ce89a |
parent 57039 | 98d3963b0b7b |
permissions | -rw-r--r-- |
56963
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57039
diff
changeset
|
2 |
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved. |
56963
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
4 |
* |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
8 |
* |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
13 |
* accompanied this code). |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
14 |
* |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
18 |
* |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
21 |
* questions. |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
22 |
*/ |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
23 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
24 |
package jnlp.converter.parser; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
25 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
26 |
import java.util.List; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
27 |
import java.util.ArrayList; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
28 |
import java.util.StringTokenizer; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
29 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
30 |
/* |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
31 |
* Utility class that knows to handle version strings |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
32 |
* A version string is of the form: |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
33 |
* |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
34 |
* (version-id ('+'?) ' ') * |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
35 |
* |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
36 |
*/ |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
37 |
public class VersionString { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
38 |
private final ArrayList<VersionID> _versionIds; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
39 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
40 |
/** Constructs a VersionString object from string */ |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
41 |
public VersionString(String vs) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
42 |
_versionIds = new ArrayList<>(); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
43 |
if (vs != null) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
44 |
StringTokenizer st = new StringTokenizer(vs, " ", false); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
45 |
while (st.hasMoreElements()) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
46 |
// Note: The VersionID class takes care of a postfixed '+' |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
47 |
_versionIds.add(new VersionID(st.nextToken())); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
48 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
49 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
50 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
51 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
52 |
public VersionString(VersionID id) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
53 |
_versionIds = new ArrayList<>(); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
54 |
if (id != null) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
55 |
_versionIds.add(id); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
56 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
57 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
58 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
59 |
public boolean isSimpleVersion() { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
60 |
if (_versionIds.size() == 1) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
61 |
return _versionIds.get(0).isSimpleVersion(); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
62 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
63 |
return false; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
64 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
65 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
66 |
/** Check if this VersionString object contains the VersionID m */ |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
67 |
public boolean contains(VersionID m) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
68 |
for (int i = 0; i < _versionIds.size(); i++) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
69 |
VersionID vi = _versionIds.get(i); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
70 |
boolean check = vi.match(m); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
71 |
if (check) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
72 |
return true; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
73 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
74 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
75 |
return false; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
76 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
77 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
78 |
/** Check if this VersionString object contains the VersionID m, given as a string */ |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
79 |
public boolean contains(String versionid) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
80 |
return contains(new VersionID(versionid)); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
81 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
82 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
83 |
/** Check if this VersionString object contains anything greater than m */ |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
84 |
public boolean containsGreaterThan(VersionID m) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
85 |
for (int i = 0; i < _versionIds.size(); i++) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
86 |
VersionID vi = _versionIds.get(i); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
87 |
boolean check = vi.isGreaterThan(m); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
88 |
if (check) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
89 |
return true; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
90 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
91 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
92 |
return false; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
93 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
94 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
95 |
/** Check if this VersionString object contains anything greater than the VersionID m, given as a string */ |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
96 |
public boolean containsGreaterThan(String versionid) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
97 |
return containsGreaterThan(new VersionID(versionid)); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
98 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
99 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
100 |
/** Check if the versionString 'vs' contains the VersionID 'vi' */ |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
101 |
public static boolean contains(String vs, String vi) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
102 |
return (new VersionString(vs)).contains(vi); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
103 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
104 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
105 |
/** Pretty-print object */ |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
106 |
@Override |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
107 |
public String toString() { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
108 |
StringBuilder sb = new StringBuilder(); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
109 |
for (int i = 0; i < _versionIds.size(); i++) { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
110 |
sb.append(_versionIds.get(i).toString()); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
111 |
sb.append(' '); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
112 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
113 |
return sb.toString(); |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
114 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
115 |
|
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
116 |
public List<VersionID> getAllVersionIDs() { |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
117 |
return _versionIds; |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
118 |
} |
eaca4369b068
8198472: Add support for creating bundles from JNLP files
herrick
parents:
diff
changeset
|
119 |
} |