src/jdk.jpackage/share/classes/jdk/jpackage/internal/ModuleManager.java
author herrick
Sat, 29 Jun 2019 09:11:19 -0400
branchJDK-8200758-branch
changeset 57445 405ddd80496e
parent 57438 4a31db8d42bd
permissions -rw-r--r--
8226904: current working directory wrong running jpackage app Reviewed-by: asemenyuk, almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     1
/*
57106
ea870b9ce89a 8216492: Update copyright of all new jpackage fils to 2019
kcr
parents: 57067
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     4
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    10
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    15
 * accompanied this code).
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    16
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    20
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    23
 * questions.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    24
 */
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    25
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57017
diff changeset
    26
package jdk.jpackage.internal;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    27
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    28
import java.io.File;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    29
import java.nio.file.Path;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    30
import java.util.ArrayList;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    31
import java.util.Arrays;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    32
import java.util.EnumSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    33
import java.util.List;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    34
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57039
diff changeset
    35
final class ModuleManager {
57015
5d2008115309 JDK-8213244: Fix all warnings in jpackager java code
herrick
parents: 56982
diff changeset
    36
    private final List<String> folders = new ArrayList<String>();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    37
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57039
diff changeset
    38
    enum SearchType {UnnamedJar, ModularJar, Jmod, ExplodedModule}
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    39
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57039
diff changeset
    40
    ModuleManager(String folders) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    41
        super();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    42
        String lfolders = folders.replaceAll("^\"|\"$", "");
57015
5d2008115309 JDK-8213244: Fix all warnings in jpackager java code
herrick
parents: 56982
diff changeset
    43
        List<Path> paths = new ArrayList<Path>();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    44
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    45
        for (String folder :
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    46
                Arrays.asList(lfolders.split(File.pathSeparator))) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    47
            File file = new File(folder);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    48
            paths.add(file.toPath());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    49
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    50
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    51
        initialize(paths);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    52
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    53
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57039
diff changeset
    54
    ModuleManager(List<Path> Paths) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    55
        super();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    56
        initialize(Paths);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    57
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    58
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    59
    private void initialize(List<Path> Paths) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    60
        for (Path path : Paths) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    61
            folders.add(path.toString().replaceAll("^\"|\"$", ""));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    62
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    63
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    64
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57039
diff changeset
    65
    List<ModFile> getModules(EnumSet<SearchType> Search) {
57015
5d2008115309 JDK-8213244: Fix all warnings in jpackager java code
herrick
parents: 56982
diff changeset
    66
        List<ModFile> result = new ArrayList<ModFile>();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    67
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    68
        for (String folder : folders) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    69
            result.addAll(getAllModulesInDirectory(folder, Search));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    70
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    71
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    72
        return result;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    73
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    74
57197
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    75
    private static List<ModFile> getAllModulesInDirectory(String folder,
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    76
            EnumSet<SearchType> Search) {
57015
5d2008115309 JDK-8213244: Fix all warnings in jpackager java code
herrick
parents: 56982
diff changeset
    77
        List<ModFile> result = new ArrayList<ModFile>();
57197
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    78
        File lfolder = new File(folder);
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    79
        File[] files = { lfolder };
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    80
        if (lfolder.isDirectory()) {
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    81
            files = lfolder.listFiles();
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    82
        }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    83
57197
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    84
        if (files != null) {
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    85
            for (File file : files) {
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    86
                ModFile modFile = new ModFile(file);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    87
57197
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    88
                switch (modFile.getModType()) {
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    89
                    case Unknown:
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    90
                        break;
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    91
                    case UnnamedJar:
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    92
                        if (Search.contains(SearchType.UnnamedJar)) {
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    93
                            result.add(modFile);
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    94
                        }
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    95
                        break;
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    96
                    case ModularJar:
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    97
                        if (Search.contains(SearchType.ModularJar)) {
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    98
                            result.add(modFile);
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
    99
                        }
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   100
                        break;
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   101
                    case Jmod:
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   102
                        if (Search.contains(SearchType.Jmod)) {
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   103
                            result.add(modFile);
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   104
                        }
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   105
                        break;
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   106
                    case ExplodedModule:
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   107
                        if (Search.contains(SearchType.ExplodedModule)) {
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   108
                            result.add(modFile);
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   109
                        }
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   110
                        break;
7fc5a57945d2 8217798: modular jar linking in jpackage
herrick
parents: 57106
diff changeset
   111
                }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   112
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   113
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   114
        return result;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   115
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   116
}