1 /* 2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. 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 26 package jdk.jpackage.internal; 27 28 import java.io.File; 29 import java.nio.file.Path; 30 import java.util.ArrayList; 31 import java.util.Arrays; 32 import java.util.EnumSet; 33 import java.util.List; 34 35 final class ModuleManager { 36 private final List<String> folders = new ArrayList<String>(); 37 38 enum SearchType {UnnamedJar, ModularJar, Jmod, ExplodedModule} 39 40 ModuleManager(String folders) { 41 super(); 42 String lfolders = folders.replaceAll("^\"|\"$", ""); 43 List<Path> paths = new ArrayList<Path>(); 44 45 for (String folder : 46 Arrays.asList(lfolders.split(File.pathSeparator))) { 47 File file = new File(folder); 48 paths.add(file.toPath()); 49 } 50 51 initialize(paths); 52 } 53 54 ModuleManager(List<Path> Paths) { 55 super(); 56 initialize(Paths); 57 } 58 59 private void initialize(List<Path> Paths) { 60 for (Path path : Paths) { 61 folders.add(path.toString().replaceAll("^\"|\"$", "")); 62 } 63 } 64 65 List<ModFile> getModules(EnumSet<SearchType> Search) { 66 List<ModFile> result = new ArrayList<ModFile>(); 67 68 for (String folder : folders) { 69 result.addAll(getAllModulesInDirectory(folder, Search)); 70 } 71 72 return result; 73 } 74 75 private static List<ModFile> getAllModulesInDirectory(String folder, 76 EnumSet<SearchType> Search) { 77 List<ModFile> result = new ArrayList<ModFile>(); 78 File lfolder = new File(folder); 79 File[] files = { lfolder }; 80 if (lfolder.isDirectory()) { 81 files = lfolder.listFiles(); 82 } 83 84 if (files != null) { 85 for (File file : files) { 86 ModFile modFile = new ModFile(file); 87 88 switch (modFile.getModType()) { 89 case Unknown: 90 break; 91 case UnnamedJar: 92 if (Search.contains(SearchType.UnnamedJar)) { 93 result.add(modFile); 94 } 95 break; 96 case ModularJar: 97 if (Search.contains(SearchType.ModularJar)) { 98 result.add(modFile); 99 } 100 break; 101 case Jmod: 102 if (Search.contains(SearchType.Jmod)) { 103 result.add(modFile); 104 } 105 break; 106 case ExplodedModule: 107 if (Search.contains(SearchType.ExplodedModule)) { 108 result.add(modFile); 109 } 110 break; 111 } 112 } 113 } 114 return result; 115 } 116 }