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