hotspot/src/share/tools/launcher/wildcard.c
author coleenp
Mon, 14 Jan 2013 11:01:39 -0500
changeset 15194 a35093d73168
parent 7410 f5b282e7a7a6
child 16668 18d44c04282d
permissions -rw-r--r--
8006005: Fix constant pool index validation and alignment trap for method parameter reflection Summary: This patch addresses an alignment trap due to the storage format of method parameters data in constMethod. It also adds code to validate constant pool indexes for method parameters data. Reviewed-by: jrose, dholmes Contributed-by: eric.mccorkle@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7410
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
     1
/*
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
     2
 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
     4
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
     8
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    13
 * accompanied this code).
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    14
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    18
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    21
 * questions.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    22
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    23
 */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    24
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    25
/*
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    26
 * Class-Path Wildcards
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    27
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    28
 * The syntax for wildcards is a single asterisk. The class path
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    29
 * foo/"*", e.g., loads all jar files in the directory named foo.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    30
 * (This requires careful quotation when used in shell scripts.)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    31
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    32
 * Only files whose names end in .jar or .JAR are matched.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    33
 * Files whose names end in .zip, or which have a particular
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    34
 * magic number, regardless of filename extension, are not
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    35
 * matched.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    36
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    37
 * Files are considered regardless of whether or not they are
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    38
 * "hidden" in the UNIX sense, i.e., have names beginning with '.'.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    39
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    40
 * A wildcard only matches jar files, not class files in the same
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    41
 * directory.  If you want to load both class files and jar files from
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    42
 * a single directory foo then you can say foo:foo/"*", or foo/"*":foo
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    43
 * if you want the jar files to take precedence.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    44
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    45
 * Subdirectories are not searched recursively, i.e., foo/"*" only
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    46
 * looks for jar files in foo, not in foo/bar, foo/baz, etc.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    47
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    48
 * Expansion of wildcards is done early, prior to the invocation of a
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    49
 * program's main method, rather than late, during the class-loading
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    50
 * process itself.  Each element of the input class path containing a
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    51
 * wildcard is replaced by the (possibly empty) sequence of elements
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    52
 * generated by enumerating the jar files in the named directory.  If
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    53
 * the directory foo contains a.jar, b.jar, and c.jar,
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    54
 * e.g., then the class path foo/"*" is expanded into
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    55
 * foo/a.jar:foo/b.jar:foo/c.jar, and that string would be the value
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    56
 * of the system property java.class.path.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    57
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    58
 * The order in which the jar files in a directory are enumerated in
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    59
 * the expanded class path is not specified and may vary from platform
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    60
 * to platform and even from moment to moment on the same machine.  A
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    61
 * well-constructed application should not depend upon any particular
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    62
 * order.  If a specific order is required then the jar files can be
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    63
 * enumerated explicitly in the class path.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    64
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    65
 * The CLASSPATH environment variable is not treated any differently
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    66
 * from the -classpath (equiv. -cp) command-line option,
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    67
 * i.e. wildcards are honored in all these cases.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    68
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    69
 * Class-path wildcards are not honored in the Class-Path jar-manifest
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    70
 * header.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    71
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    72
 * Class-path wildcards are honored not only by the Java launcher but
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    73
 * also by most other command-line tools that accept class paths, and
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    74
 * in particular by javac and javadoc.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    75
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    76
 * Class-path wildcards are not honored in any other kind of path, and
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    77
 * especially not in the bootstrap class path, which is a mere
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    78
 * artifact of our implementation and not something that developers
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    79
 * should use.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    80
 *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    81
 * Classpath wildcards are only expanded in the Java launcher code,
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    82
 * supporting the use of wildcards on the command line and in the
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    83
 * CLASSPATH environment variable.  We do not support the use of
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    84
 * wildcards by applications that embed the JVM.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    85
 */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    86
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    87
#include <stddef.h>
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    88
#include <stdio.h>
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    89
#include <stdlib.h>
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    90
#include <string.h>
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    91
#include <sys/types.h>
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    92
#include "java.h"       /* Strictly for PATH_SEPARATOR/FILE_SEPARATOR */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    93
#include "jli_util.h"
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    94
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    95
#ifdef _WIN32
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    96
#include <windows.h>
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    97
#else /* Unix */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    98
#include <unistd.h>
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
    99
#include <dirent.h>
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   100
#endif /* Unix */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   101
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   102
static int
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   103
exists(const char* filename)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   104
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   105
#ifdef _WIN32
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   106
    return _access(filename, 0) == 0;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   107
#else
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   108
    return access(filename, F_OK) == 0;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   109
#endif
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   110
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   111
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   112
#define NEW_(TYPE) ((TYPE) JLI_MemAlloc(sizeof(struct TYPE##_)))
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   113
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   114
/*
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   115
 * Wildcard directory iteration.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   116
 * WildcardIterator_for(wildcard) returns an iterator.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   117
 * Each call to that iterator's next() method returns the basename
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   118
 * of an entry in the wildcard's directory.  The basename's memory
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   119
 * belongs to the iterator.  The caller is responsible for prepending
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   120
 * the directory name and file separator, if necessary.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   121
 * When done with the iterator, call the close method to clean up.
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   122
 */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   123
typedef struct WildcardIterator_* WildcardIterator;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   124
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   125
#ifdef _WIN32
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   126
struct WildcardIterator_
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   127
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   128
    HANDLE handle;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   129
    char *firstFile; /* Stupid FindFirstFile...FindNextFile */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   130
};
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   131
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   132
static WildcardIterator
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   133
WildcardIterator_for(const char *wildcard)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   134
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   135
    WIN32_FIND_DATA find_data;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   136
    WildcardIterator it = NEW_(WildcardIterator);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   137
    HANDLE handle = FindFirstFile(wildcard, &find_data);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   138
    if (handle == INVALID_HANDLE_VALUE)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   139
        return NULL;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   140
    it->handle = handle;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   141
    it->firstFile = find_data.cFileName;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   142
    return it;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   143
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   144
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   145
static char *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   146
WildcardIterator_next(WildcardIterator it)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   147
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   148
    WIN32_FIND_DATA find_data;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   149
    if (it->firstFile != NULL) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   150
        char *firstFile = it->firstFile;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   151
        it->firstFile = NULL;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   152
        return firstFile;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   153
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   154
    return FindNextFile(it->handle, &find_data)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   155
        ? find_data.cFileName : NULL;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   156
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   157
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   158
static void
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   159
WildcardIterator_close(WildcardIterator it)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   160
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   161
    if (it) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   162
        FindClose(it->handle);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   163
        JLI_MemFree(it->firstFile);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   164
        JLI_MemFree(it);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   165
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   166
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   167
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   168
#else /* Unix */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   169
struct WildcardIterator_
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   170
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   171
    DIR *dir;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   172
};
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   173
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   174
static WildcardIterator
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   175
WildcardIterator_for(const char *wildcard)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   176
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   177
    DIR *dir;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   178
    int wildlen = strlen(wildcard);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   179
    if (wildlen < 2) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   180
        dir = opendir(".");
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   181
    } else {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   182
        char *dirname = JLI_StringDup(wildcard);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   183
        dirname[wildlen - 1] = '\0';
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   184
        dir = opendir(dirname);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   185
        JLI_MemFree(dirname);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   186
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   187
    if (dir == NULL)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   188
        return NULL;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   189
    else {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   190
        WildcardIterator it = NEW_(WildcardIterator);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   191
        it->dir = dir;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   192
        return it;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   193
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   194
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   195
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   196
static char *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   197
WildcardIterator_next(WildcardIterator it)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   198
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   199
    struct dirent* dirp = readdir(it->dir);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   200
    return dirp ? dirp->d_name : NULL;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   201
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   202
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   203
static void
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   204
WildcardIterator_close(WildcardIterator it)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   205
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   206
    if (it) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   207
        closedir(it->dir);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   208
        JLI_MemFree(it);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   209
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   210
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   211
#endif /* Unix */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   212
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   213
static int
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   214
equal(const char *s1, const char *s2)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   215
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   216
    return strcmp(s1, s2) == 0;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   217
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   218
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   219
/*
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   220
 * FileList ADT - a dynamic list of C filenames
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   221
 */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   222
struct FileList_
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   223
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   224
    char **files;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   225
    int size;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   226
    int capacity;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   227
};
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   228
typedef struct FileList_ *FileList;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   229
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   230
static FileList
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   231
FileList_new(int capacity)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   232
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   233
    FileList fl = NEW_(FileList);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   234
    fl->capacity = capacity;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   235
    fl->files = (char **) JLI_MemAlloc(capacity * sizeof(fl->files[0]));
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   236
    fl->size = 0;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   237
    return fl;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   238
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   239
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   240
#ifdef DEBUG_WILDCARD
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   241
static void
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   242
FileList_print(FileList fl)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   243
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   244
    int i;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   245
    putchar('[');
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   246
    for (i = 0; i < fl->size; i++) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   247
        if (i > 0) printf(", ");
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   248
        printf("\"%s\"",fl->files[i]);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   249
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   250
    putchar(']');
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   251
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   252
#endif
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   253
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   254
static void
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   255
FileList_free(FileList fl)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   256
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   257
    if (fl) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   258
        if (fl->files) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   259
            int i;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   260
            for (i = 0; i < fl->size; i++)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   261
                JLI_MemFree(fl->files[i]);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   262
            JLI_MemFree(fl->files);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   263
        }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   264
        JLI_MemFree(fl);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   265
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   266
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   267
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   268
static void
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   269
FileList_ensureCapacity(FileList fl, int capacity)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   270
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   271
    if (fl->capacity < capacity) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   272
        while (fl->capacity < capacity)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   273
            fl->capacity *= 2;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   274
        fl->files = JLI_MemRealloc(fl->files,
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   275
                               fl->capacity * sizeof(fl->files[0]));
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   276
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   277
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   278
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   279
static void
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   280
FileList_add(FileList fl, char *file)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   281
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   282
    FileList_ensureCapacity(fl, fl->size+1);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   283
    fl->files[fl->size++] = file;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   284
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   285
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   286
static void
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   287
FileList_addSubstring(FileList fl, const char *beg, int len)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   288
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   289
    char *filename = (char *) JLI_MemAlloc(len+1);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   290
    memcpy(filename, beg, len);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   291
    filename[len] = '\0';
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   292
    FileList_ensureCapacity(fl, fl->size+1);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   293
    fl->files[fl->size++] = filename;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   294
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   295
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   296
static char *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   297
FileList_join(FileList fl, char sep)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   298
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   299
    int i;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   300
    int size;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   301
    char *path;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   302
    char *p;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   303
    for (i = 0, size = 1; i < fl->size; i++)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   304
        size += strlen(fl->files[i]) + 1;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   305
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   306
    path = JLI_MemAlloc(size);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   307
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   308
    for (i = 0, p = path; i < fl->size; i++) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   309
        int len = strlen(fl->files[i]);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   310
        if (i > 0) *p++ = sep;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   311
        memcpy(p, fl->files[i], len);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   312
        p += len;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   313
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   314
    *p = '\0';
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   315
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   316
    return path;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   317
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   318
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   319
static FileList
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   320
FileList_split(const char *path, char sep)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   321
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   322
    const char *p, *q;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   323
    int len = strlen(path);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   324
    int count;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   325
    FileList fl;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   326
    for (count = 1, p = path; p < path + len; p++)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   327
        count += (*p == sep);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   328
    fl = FileList_new(count);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   329
    for (p = path;;) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   330
        for (q = p; q <= path + len; q++) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   331
            if (*q == sep || *q == '\0') {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   332
                FileList_addSubstring(fl, p, q - p);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   333
                if (*q == '\0')
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   334
                    return fl;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   335
                p = q + 1;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   336
            }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   337
        }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   338
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   339
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   340
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   341
static int
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   342
isJarFileName(const char *filename)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   343
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   344
    int len = strlen(filename);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   345
    return (len >= 4) &&
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   346
        (filename[len - 4] == '.') &&
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   347
        (equal(filename + len - 3, "jar") ||
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   348
         equal(filename + len - 3, "JAR")) &&
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   349
        /* Paranoia: Maybe filename is "DIR:foo.jar" */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   350
        (strchr(filename, PATH_SEPARATOR) == NULL);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   351
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   352
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   353
static char *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   354
wildcardConcat(const char *wildcard, const char *basename)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   355
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   356
    int wildlen = strlen(wildcard);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   357
    int baselen = strlen(basename);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   358
    char *filename = (char *) JLI_MemAlloc(wildlen + baselen);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   359
    /* Replace the trailing '*' with basename */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   360
    memcpy(filename, wildcard, wildlen-1);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   361
    memcpy(filename+wildlen-1, basename, baselen+1);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   362
    return filename;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   363
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   364
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   365
static FileList
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   366
wildcardFileList(const char *wildcard)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   367
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   368
    const char *basename;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   369
    FileList fl = FileList_new(16);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   370
    WildcardIterator it = WildcardIterator_for(wildcard);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   371
    if (it == NULL)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   372
        return NULL;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   373
    while ((basename = WildcardIterator_next(it)) != NULL)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   374
        if (isJarFileName(basename))
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   375
            FileList_add(fl, wildcardConcat(wildcard, basename));
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   376
    WildcardIterator_close(it);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   377
    return fl;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   378
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   379
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   380
static int
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   381
isWildcard(const char *filename)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   382
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   383
    int len = strlen(filename);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   384
    return (len > 0) &&
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   385
        (filename[len - 1] == '*') &&
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   386
        (len == 1 || IS_FILE_SEPARATOR(filename[len - 2])) &&
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   387
        (! exists(filename));
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   388
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   389
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   390
static void
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   391
FileList_expandWildcards(FileList fl)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   392
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   393
    int i, j;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   394
    for (i = 0; i < fl->size; i++) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   395
        if (isWildcard(fl->files[i])) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   396
            FileList expanded = wildcardFileList(fl->files[i]);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   397
            if (expanded != NULL && expanded->size > 0) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   398
                JLI_MemFree(fl->files[i]);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   399
                FileList_ensureCapacity(fl, fl->size + expanded->size);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   400
                for (j = fl->size - 1; j >= i+1; j--)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   401
                    fl->files[j+expanded->size-1] = fl->files[j];
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   402
                for (j = 0; j < expanded->size; j++)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   403
                    fl->files[i+j] = expanded->files[j];
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   404
                i += expanded->size - 1;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   405
                fl->size += expanded->size - 1;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   406
                /* fl expropriates expanded's elements. */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   407
                expanded->size = 0;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   408
            }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   409
            FileList_free(expanded);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   410
        }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   411
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   412
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   413
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   414
const char *
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   415
JLI_WildcardExpandClasspath(const char *classpath)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   416
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   417
    char *expanded;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   418
    FileList fl;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   419
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   420
    if (strchr(classpath, '*') == NULL)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   421
        return classpath;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   422
    fl = FileList_split(classpath, PATH_SEPARATOR);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   423
    FileList_expandWildcards(fl);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   424
    expanded = FileList_join(fl, PATH_SEPARATOR);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   425
    FileList_free(fl);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   426
    if (getenv("_JAVA_LAUNCHER_DEBUG") != 0)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   427
        printf("Expanded wildcards:\n"
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   428
               "    before: \"%s\"\n"
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   429
               "    after : \"%s\"\n",
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   430
               classpath, expanded);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   431
    return expanded;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   432
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   433
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   434
#ifdef DEBUG_WILDCARD
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   435
static void
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   436
wildcardExpandArgv(const char ***argv)
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   437
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   438
    int i;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   439
    for (i = 0; (*argv)[i]; i++) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   440
        if (equal((*argv)[i], "-cp") ||
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   441
            equal((*argv)[i], "-classpath")) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   442
            i++;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   443
            (*argv)[i] = wildcardExpandClasspath((*argv)[i]);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   444
        }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   445
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   446
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   447
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   448
static void
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   449
debugPrintArgv(char *argv[])
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   450
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   451
    int i;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   452
    putchar('[');
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   453
    for (i = 0; argv[i]; i++) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   454
        if (i > 0) printf(", ");
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   455
        printf("\"%s\"", argv[i]);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   456
    }
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   457
    printf("]\n");
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   458
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   459
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   460
int
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   461
main(int argc, char *argv[])
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   462
{
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   463
    argv[0] = "java";
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   464
    wildcardExpandArgv((const char***)&argv);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   465
    debugPrintArgv(argv);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   466
    /* execvp("java", argv); */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   467
    return 0;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   468
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   469
#endif /* DEBUG_WILDCARD */
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   470
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   471
/* Cute little perl prototype implementation....
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   472
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   473
my $sep = ($^O =~ /^(Windows|cygwin)/) ? ";" : ":";
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   474
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   475
sub expand($) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   476
  opendir DIR, $_[0] or return $_[0];
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   477
  join $sep, map {"$_[0]/$_"} grep {/\.(jar|JAR)$/} readdir DIR;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   478
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   479
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   480
sub munge($) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   481
  join $sep,
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   482
    map {(! -r $_ and s/[\/\\]+\*$//) ? expand $_ : $_} split $sep, $_[0];
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   483
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   484
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   485
for (my $i = 0; $i < @ARGV - 1; $i++) {
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   486
  $ARGV[$i+1] = munge $ARGV[$i+1] if $ARGV[$i] =~ /^-c(p|lasspath)$/;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   487
}
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   488
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   489
$ENV{CLASSPATH} = munge $ENV{CLASSPATH} if exists $ENV{CLASSPATH};
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   490
@ARGV = ("java", @ARGV);
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   491
print "@ARGV\n";
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   492
exec @ARGV;
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   493
f5b282e7a7a6 6981484: Update development launcher
sla
parents:
diff changeset
   494
*/