author | pchilanomate |
Fri, 31 Aug 2018 10:22:04 -0400 | |
changeset 51610 | cdef4df6b0e7 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39308
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
36511 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
package jdk.tools.jlink.internal; |
|
26 |
||
38871
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
27 |
import java.net.URI; |
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
28 |
import java.nio.file.FileSystem; |
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
29 |
import java.nio.file.FileSystems; |
39042 | 30 |
import java.nio.file.Path; |
38871
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
31 |
import java.nio.file.PathMatcher; |
36511 | 32 |
import java.util.ArrayList; |
39042 | 33 |
import java.util.Arrays; |
36511 | 34 |
import java.util.Comparator; |
35 |
import java.util.List; |
|
39042 | 36 |
import java.util.stream.Collectors; |
36511 | 37 |
import jdk.tools.jlink.plugin.Plugin; |
39042 | 38 |
import jdk.tools.jlink.plugin.Plugin.Category; |
36511 | 39 |
|
40 |
public class Utils { |
|
41 |
||
42 |
private Utils() {} |
|
43 |
||
39042 | 44 |
// jrt-fs file system |
45 |
private static FileSystem JRT_FILE_SYSTEM; |
|
46 |
||
36511 | 47 |
// current module |
48 |
private static final Module THIS_MODULE = Utils.class.getModule(); |
|
49 |
||
39042 | 50 |
public static List<String> parseList(String arguments) { |
51 |
return Arrays.stream(arguments.split(",")) |
|
52 |
.map((p) -> p.trim()) |
|
53 |
.filter((p) -> !p.isEmpty()) |
|
54 |
.collect(Collectors.toList()); |
|
55 |
} |
|
36511 | 56 |
|
57 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39308
diff
changeset
|
58 |
public static List<Plugin> getSortedPlugins(List<Plugin> plugins) { |
39042 | 59 |
List<Plugin> res = new ArrayList<>(); |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39308
diff
changeset
|
60 |
res.addAll(plugins); |
36511 | 61 |
res.sort(new Comparator<Plugin>() { |
62 |
@Override |
|
63 |
public int compare(Plugin o1, Plugin o2) { |
|
64 |
return o1.getName().compareTo(o2.getName()); |
|
65 |
} |
|
66 |
}); |
|
67 |
return res; |
|
68 |
} |
|
69 |
||
70 |
public static boolean isFunctional(Plugin prov) { |
|
38320 | 71 |
return prov.getState().contains(Plugin.State.FUNCTIONAL); |
36511 | 72 |
} |
73 |
||
74 |
public static boolean isAutoEnabled(Plugin prov) { |
|
38320 | 75 |
return prov.getState().contains(Plugin.State.AUTO_ENABLED); |
36511 | 76 |
} |
77 |
||
78 |
public static boolean isDisabled(Plugin prov) { |
|
38320 | 79 |
return prov.getState().contains(Plugin.State.DISABLED); |
36511 | 80 |
} |
81 |
||
82 |
// is this a builtin (jdk.jlink) plugin? |
|
83 |
public static boolean isBuiltin(Plugin prov) { |
|
84 |
return THIS_MODULE.equals(prov.getClass().getModule()); |
|
85 |
} |
|
38871
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
86 |
|
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
87 |
public static FileSystem jrtFileSystem() { |
39042 | 88 |
if (JRT_FILE_SYSTEM == null) { |
89 |
JRT_FILE_SYSTEM = FileSystems.getFileSystem(URI.create("jrt:/")); |
|
90 |
} |
|
91 |
||
92 |
return JRT_FILE_SYSTEM; |
|
38871
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
93 |
} |
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
94 |
|
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
95 |
public static PathMatcher getPathMatcher(FileSystem fs, String pattern) { |
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
96 |
if (!pattern.startsWith("glob:") && !pattern.startsWith("regex:")) { |
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
97 |
pattern = "glob:" + pattern; |
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
98 |
} |
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
99 |
|
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
100 |
return fs.getPathMatcher(pattern); |
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
101 |
} |
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
102 |
|
39042 | 103 |
public static PathMatcher getJRTFSPathMatcher(String pattern) { |
38871
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
104 |
return getPathMatcher(jrtFileSystem(), pattern); |
ec08bf1979d4
8158402: jlink: should use regex for all pattern operations (--order-resources or --exclude-resources)
jlaskey
parents:
38320
diff
changeset
|
105 |
} |
39042 | 106 |
|
107 |
public static Path getJRTFSPath(String first, String... more) { |
|
108 |
return jrtFileSystem().getPath(first, more); |
|
109 |
} |
|
36511 | 110 |
} |