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
26 package jdk.jpackage.internal;
27
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.FileNotFoundException;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.zip.ZipEntry;
35 import java.util.zip.ZipInputStream;
36
37 final class ModFile {
38 private final String filename;
39 private final ModType moduleType;
40
41 enum JarType {All, UnnamedJar, ModularJar}
42 enum ModType {
43 Unknown, UnnamedJar, ModularJar, Jmod, ExplodedModule}
44
45 ModFile(File aFile) {
46 super();
80 else if (status == JarType.UnnamedJar) {
81 result = ModType.UnnamedJar;
82 }
83 }
84 }
85 else if (aFile.isDirectory()) {
86 File moduleInfo = new File(
87 filename + File.separator + "module-info.class");
88
89 if (moduleInfo.exists()) {
90 result = ModType.ExplodedModule;
91 }
92 }
93
94 return result;
95 }
96
97 private static JarType isModularJar(String FileName) {
98 JarType result = JarType.All;
99
100 try {
101 ZipInputStream zip =
102 new ZipInputStream(new FileInputStream(FileName));
103 result = JarType.UnnamedJar;
104
105 try {
106 for (ZipEntry entry = zip.getNextEntry(); entry != null;
107 entry = zip.getNextEntry()) {
108 if (entry.getName().matches("module-info.class")) {
109 result = JarType.ModularJar;
110 break;
111 }
112 }
113
114 zip.close();
115 } catch (IOException ex) {
116 }
117 } catch (FileNotFoundException e) {
118 }
119
120 return result;
121 }
122
123 private static String getFileWithoutExtension(String FileName) {
124 return FileName.replaceFirst("[.][^.]+$", "");
125 }
126 }
|
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
26 package jdk.incubator.jpackage.internal;
27
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.FileNotFoundException;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.zip.ZipEntry;
35 import java.util.zip.ZipInputStream;
36
37 final class ModFile {
38 private final String filename;
39 private final ModType moduleType;
40
41 enum JarType {All, UnnamedJar, ModularJar}
42 enum ModType {
43 Unknown, UnnamedJar, ModularJar, Jmod, ExplodedModule}
44
45 ModFile(File aFile) {
46 super();
80 else if (status == JarType.UnnamedJar) {
81 result = ModType.UnnamedJar;
82 }
83 }
84 }
85 else if (aFile.isDirectory()) {
86 File moduleInfo = new File(
87 filename + File.separator + "module-info.class");
88
89 if (moduleInfo.exists()) {
90 result = ModType.ExplodedModule;
91 }
92 }
93
94 return result;
95 }
96
97 private static JarType isModularJar(String FileName) {
98 JarType result = JarType.All;
99
100 try (ZipInputStream zip =
101 new ZipInputStream(new FileInputStream(FileName))) {
102 result = JarType.UnnamedJar;
103
104 for (ZipEntry entry = zip.getNextEntry(); entry != null;
105 entry = zip.getNextEntry()) {
106 if (entry.getName().matches("module-info.class")) {
107 result = JarType.ModularJar;
108 break;
109 }
110 }
111 } catch (IOException ex) {
112 }
113
114 return result;
115 }
116
117 private static String getFileWithoutExtension(String FileName) {
118 return FileName.replaceFirst("[.][^.]+$", "");
119 }
120 }
|