jruby-launcher 1.1.1-java → 1.1.2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,22 @@
1
- /*
2
- * Copyright 2009-2010 JRuby Team (www.jruby.org).
3
- */
4
-
5
-
6
- #ifndef _UNIXLAUNCHER_H_
7
- #define _UNIXLAUNCHER_H_
8
-
9
- #include "argparser.h"
10
-
11
- class UnixLauncher : public ArgParser {
12
- public:
13
- UnixLauncher();
14
- virtual ~UnixLauncher();
15
-
16
- int run(int argc, char* argv[], char* envp[]);
17
-
18
- private:
19
- UnixLauncher(const UnixLauncher& orig);
20
- };
21
-
22
- #endif // ! _UNIXLAUNCHER_H_
1
+ /*
2
+ * Copyright 2009-2010 JRuby Team (www.jruby.org).
3
+ */
4
+
5
+
6
+ #ifndef _UNIXLAUNCHER_H_
7
+ #define _UNIXLAUNCHER_H_
8
+
9
+ #include "argparser.h"
10
+
11
+ class UnixLauncher : public ArgParser {
12
+ public:
13
+ UnixLauncher();
14
+ virtual ~UnixLauncher();
15
+
16
+ int run(int argc, char* argv[], char* envp[]);
17
+
18
+ private:
19
+ UnixLauncher(const UnixLauncher& orig);
20
+ };
21
+
22
+ #endif // ! _UNIXLAUNCHER_H_
@@ -1,279 +1,279 @@
1
- /*
2
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
- *
4
- * Copyright 2009-2010 JRuby Team (www.jruby.org).
5
- * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
6
- *
7
- * The contents of this file are subject to the terms of either the GNU
8
- * General Public License Version 2 only ("GPL") or the Common
9
- * Development and Distribution License("CDDL") (collectively, the
10
- * "License"). You may not use this file except in compliance with the
11
- * License. You can obtain a copy of the License at
12
- * http://www.netbeans.org/cddl-gplv2.html
13
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
14
- * specific language governing permissions and limitations under the
15
- * License. When distributing the software, include this License Header
16
- * Notice in each file and include the License file at
17
- * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
18
- * particular file as subject to the "Classpath" exception as provided
19
- * by Sun in the GPL Version 2 section of the License file that
20
- * accompanied this code. If applicable, add the following below the
21
- * License Header, with the fields enclosed by brackets [] replaced by
22
- * your own identifying information:
23
- * "Portions Copyrighted [year] [name of copyright owner]"
24
- *
25
- * Contributor(s):
26
- *
27
- * The Original Software is NetBeans. The Initial Developer of the Original
28
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
29
- * Microsystems, Inc. All Rights Reserved.
30
- *
31
- * If you wish your version of this file to be governed by only the CDDL
32
- * or only the GPL Version 2, indicate your decision by adding
33
- * "[Contributor] elects to include this software in this distribution
34
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
35
- * single choice of license, a recipient has the option to distribute
36
- * your version of this file under either the CDDL, the GPL Version 2 or
37
- * to extend the choice of license to its licensees as provided above.
38
- * However, if you add GPL Version 2 code and therefore, elected the GPL
39
- * Version 2 license, then the option applies only if the new code is
40
- * made subject to such option by the copyright holder.
41
- *
42
- * Author: Tomas Holy
43
- */
44
-
45
- #include <stdio.h>
46
- #include <stdarg.h>
47
- #include <cstring>
48
- #include <cstdlib>
49
- #include <memory>
50
- #include <list>
51
- #include <algorithm>
52
- #include <iterator>
53
- #include <iostream>
54
- #include <unistd.h>
55
- #include "utilsfuncs.h"
56
- #include "argnames.h"
57
-
58
- #ifndef WIN32
59
- #include <sys/stat.h>
60
- #include <errno.h>
61
- #include <string.h>
62
- #endif
63
-
64
- #ifdef __SUNOS__
65
- #include <sys/varargs.h>
66
- #endif
67
-
68
- using namespace std;
69
-
70
- bool checkExists(const char* path, unsigned int flags) {
71
- #ifdef WIN32
72
- WIN32_FIND_DATA fd = {0};
73
- HANDLE hFind = 0;
74
- hFind = FindFirstFile(path, &fd);
75
- if (hFind == INVALID_HANDLE_VALUE) {
76
- return false;
77
- }
78
- FindClose(hFind);
79
- if (flags == 0) {
80
- return true;
81
- }
82
- return (fd.dwFileAttributes & flags) != 0;
83
- #else
84
- struct stat dir;
85
- if (stat(path, &dir) != 0) {
86
- return false;
87
- }
88
- if (flags == 0) {
89
- return true;
90
- }
91
- return dir.st_mode & flags;
92
- #endif
93
- }
94
-
95
- bool checkDirectory(const char* path) {
96
- #ifdef WIN32
97
- unsigned int flags = FILE_ATTRIBUTE_DIRECTORY;
98
- #else
99
- unsigned int flags = S_IFDIR;
100
- #endif
101
- return checkExists(path, flags);
102
- }
103
-
104
- bool dirExists(const char *path) {
105
- if (!checkDirectory(path)) {
106
- logMsg("Dir \"%s\" does not exist", path);
107
- return false;
108
- }
109
- logMsg("Dir \"%s\" exists", path);
110
- return true;
111
- }
112
-
113
- bool fileExists(const char *path) {
114
- if (!checkExists(path, 0)) {
115
- logMsg("File \"%s\" does not exist", path);
116
- return false;
117
- }
118
- logMsg("File \"%s\" exists", path);
119
- return true;
120
- }
121
-
122
- string findOnPath(const char* name) {
123
- string path(getenv("PATH"));
124
- size_t start = 0;
125
- size_t sep;
126
- char * found;
127
-
128
- while (start < path.length()) {
129
- sep = path.find(PATH_SEP, start);
130
- if (sep == string::npos) {
131
- sep = path.length();
132
- }
133
-
134
- string elem(path.substr(start, sep - start));
135
- if (elem[elem.length() - 1] != FILE_SEP) {
136
- elem += FILE_SEP;
137
- }
138
- elem += name;
139
-
140
- if (checkExists(elem.c_str(), 0)) {
141
- string found_string(elem);
142
- return found_string;
143
- }
144
-
145
- start = sep + 1;
146
- }
147
- return "";
148
- }
149
-
150
- const char* getSysError(char *str, int strSize) {
151
- #ifdef WIN32
152
- int err = GetLastError();
153
- LPTSTR lpMsgBuf;
154
- FormatMessage(
155
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
156
- FORMAT_MESSAGE_FROM_SYSTEM |
157
- FORMAT_MESSAGE_IGNORE_INSERTS,
158
- NULL,
159
- err,
160
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
161
- (LPTSTR) & lpMsgBuf,
162
- 0,
163
- NULL
164
- );
165
- LPTSTR tmp = strchr(lpMsgBuf, '\r');
166
- if (tmp != NULL) {
167
- *tmp = '\0';
168
- }
169
-
170
- _snprintf(str, strSize, " %s (%u)", lpMsgBuf, err);
171
- LocalFree(lpMsgBuf);
172
- #else
173
- const char* error = strerror(errno);
174
- snprintf(str, strSize, " %s (%u)", error, errno);
175
- #endif
176
- return str;
177
- }
178
-
179
- string gLogFileName;
180
-
181
- void logV(bool appendSysError, bool showMsgBox, const char *format, va_list args) {
182
- char msg[4096] = "";
183
- vsnprintf(msg, 4096, format, args);
184
-
185
- if (appendSysError) {
186
- char sysErr[512] = "";
187
- getSysError(sysErr, 512);
188
- strncat(msg, sysErr, 4096 - strlen(msg));
189
- }
190
-
191
- if (!gLogFileName.empty() && gLogFileName != "''") {
192
- FILE *file = fopen(gLogFileName.c_str(), "a");
193
- if (file) {
194
- fprintf(file, "%s\n", msg);
195
- fclose(file);
196
- }
197
- }
198
-
199
- if (showMsgBox) {
200
- #ifdef WIN32
201
- // Pop-up the message box only if there is no console
202
- if (!isConsoleAttached()) {
203
- ::MessageBox(NULL, msg, "JRuby Error", MB_OK | MB_ICONSTOP);
204
- }
205
- #endif
206
- fprintf(stdout, "%s\n", msg);
207
- }
208
- }
209
-
210
- void logErr(bool appendSysError, bool showMsgBox, const char *format, ...) {
211
- va_list args;
212
- va_start(args, format);
213
- logV(appendSysError, showMsgBox, format, args);
214
- }
215
-
216
- void logMsg(const char *format, ...) {
217
- va_list args;
218
- va_start(args, format);
219
- logV(false, false, format, args);
220
- }
221
-
222
- bool checkLoggingArg(int argc, char *argv[], bool delFile) {
223
- for (int i = 0; i < argc; i++) {
224
- if (strcmp("--", argv[i]) == 0) {
225
- break;
226
- }
227
- if (strcmp(ARG_NAME_LAUNCHER_LOG, argv[i]) == 0) {
228
- if (i+1 == argc || *argv[i+1] == '-') {
229
- return false;
230
- }
231
- gLogFileName = argv[++i];
232
- if (delFile) {
233
- #ifdef WIN32
234
- DeleteFile(gLogFileName.c_str());
235
- #else
236
- unlink(gLogFileName.c_str());
237
- #endif
238
- }
239
- break;
240
- }
241
- }
242
- return true;
243
- }
244
-
245
- bool printToConsole(const char *msg) {
246
- fprintf(stdout, "%s", msg);
247
- return false;
248
- }
249
-
250
- char** convertToArgvArray(list<string> args) {
251
- char ** argv = new char*[args.size()+1];
252
- int i = 0;
253
- for (list<string>::iterator it = args.begin(); it != args.end(); ++it, ++i) {
254
- argv[i] = strdup((*it).c_str());
255
- }
256
- argv[args.size()] = NULL;
257
- return argv;
258
- }
259
-
260
- void addToArgList(list<string> & args, int argc, char ** argv) {
261
- for (int i = 0; i < argc; i++) {
262
- std::string str(argv[i]);
263
- args.push_back(str);
264
- }
265
- }
266
-
267
- void printListToConsole(list<string> values) {
268
- for (list<string>::iterator it = values.begin(); it != values.end(); ++it) {
269
- std::cout << *it << std::endl;
270
- }
271
- }
272
-
273
- string trimTrailingBackslashes(string orig) {
274
- while (orig.size() > 0 &&
275
- orig.at(orig.size() - 1) == '\\') {
276
- orig.erase(orig.size() - 1);
277
- }
278
- return orig;
279
- }
1
+ /*
2
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
+ *
4
+ * Copyright 2009-2010 JRuby Team (www.jruby.org).
5
+ * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
6
+ *
7
+ * The contents of this file are subject to the terms of either the GNU
8
+ * General Public License Version 2 only ("GPL") or the Common
9
+ * Development and Distribution License("CDDL") (collectively, the
10
+ * "License"). You may not use this file except in compliance with the
11
+ * License. You can obtain a copy of the License at
12
+ * http://www.netbeans.org/cddl-gplv2.html
13
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
14
+ * specific language governing permissions and limitations under the
15
+ * License. When distributing the software, include this License Header
16
+ * Notice in each file and include the License file at
17
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
18
+ * particular file as subject to the "Classpath" exception as provided
19
+ * by Sun in the GPL Version 2 section of the License file that
20
+ * accompanied this code. If applicable, add the following below the
21
+ * License Header, with the fields enclosed by brackets [] replaced by
22
+ * your own identifying information:
23
+ * "Portions Copyrighted [year] [name of copyright owner]"
24
+ *
25
+ * Contributor(s):
26
+ *
27
+ * The Original Software is NetBeans. The Initial Developer of the Original
28
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
29
+ * Microsystems, Inc. All Rights Reserved.
30
+ *
31
+ * If you wish your version of this file to be governed by only the CDDL
32
+ * or only the GPL Version 2, indicate your decision by adding
33
+ * "[Contributor] elects to include this software in this distribution
34
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
35
+ * single choice of license, a recipient has the option to distribute
36
+ * your version of this file under either the CDDL, the GPL Version 2 or
37
+ * to extend the choice of license to its licensees as provided above.
38
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
39
+ * Version 2 license, then the option applies only if the new code is
40
+ * made subject to such option by the copyright holder.
41
+ *
42
+ * Author: Tomas Holy
43
+ */
44
+
45
+ #include <stdio.h>
46
+ #include <stdarg.h>
47
+ #include <cstring>
48
+ #include <cstdlib>
49
+ #include <memory>
50
+ #include <list>
51
+ #include <algorithm>
52
+ #include <iterator>
53
+ #include <iostream>
54
+ #include <unistd.h>
55
+ #include "utilsfuncs.h"
56
+ #include "argnames.h"
57
+
58
+ #ifndef WIN32
59
+ #include <sys/stat.h>
60
+ #include <errno.h>
61
+ #include <string.h>
62
+ #endif
63
+
64
+ #ifdef __SUNOS__
65
+ #include <sys/varargs.h>
66
+ #endif
67
+
68
+ using namespace std;
69
+
70
+ bool checkExists(const char* path, unsigned int flags) {
71
+ #ifdef WIN32
72
+ WIN32_FIND_DATA fd = {0};
73
+ HANDLE hFind = 0;
74
+ hFind = FindFirstFile(path, &fd);
75
+ if (hFind == INVALID_HANDLE_VALUE) {
76
+ return false;
77
+ }
78
+ FindClose(hFind);
79
+ if (flags == 0) {
80
+ return true;
81
+ }
82
+ return (fd.dwFileAttributes & flags) != 0;
83
+ #else
84
+ struct stat dir;
85
+ if (stat(path, &dir) != 0) {
86
+ return false;
87
+ }
88
+ if (flags == 0) {
89
+ return true;
90
+ }
91
+ return dir.st_mode & flags;
92
+ #endif
93
+ }
94
+
95
+ bool checkDirectory(const char* path) {
96
+ #ifdef WIN32
97
+ unsigned int flags = FILE_ATTRIBUTE_DIRECTORY;
98
+ #else
99
+ unsigned int flags = S_IFDIR;
100
+ #endif
101
+ return checkExists(path, flags);
102
+ }
103
+
104
+ bool dirExists(const char *path) {
105
+ if (!checkDirectory(path)) {
106
+ logMsg("Dir \"%s\" does not exist", path);
107
+ return false;
108
+ }
109
+ logMsg("Dir \"%s\" exists", path);
110
+ return true;
111
+ }
112
+
113
+ bool fileExists(const char *path) {
114
+ if (!checkExists(path, 0)) {
115
+ logMsg("File \"%s\" does not exist", path);
116
+ return false;
117
+ }
118
+ logMsg("File \"%s\" exists", path);
119
+ return true;
120
+ }
121
+
122
+ string findOnPath(const char* name) {
123
+ string path(getenv("PATH"));
124
+ size_t start = 0;
125
+ size_t sep;
126
+ char * found;
127
+
128
+ while (start < path.length()) {
129
+ sep = path.find(PATH_SEP, start);
130
+ if (sep == string::npos) {
131
+ sep = path.length();
132
+ }
133
+
134
+ string elem(path.substr(start, sep - start));
135
+ if (elem[elem.length() - 1] != FILE_SEP) {
136
+ elem += FILE_SEP;
137
+ }
138
+ elem += name;
139
+
140
+ if (checkExists(elem.c_str(), 0)) {
141
+ string found_string(elem);
142
+ return found_string;
143
+ }
144
+
145
+ start = sep + 1;
146
+ }
147
+ return "";
148
+ }
149
+
150
+ const char* getSysError(char *str, int strSize) {
151
+ #ifdef WIN32
152
+ int err = GetLastError();
153
+ LPTSTR lpMsgBuf;
154
+ FormatMessage(
155
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
156
+ FORMAT_MESSAGE_FROM_SYSTEM |
157
+ FORMAT_MESSAGE_IGNORE_INSERTS,
158
+ NULL,
159
+ err,
160
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
161
+ (LPTSTR) & lpMsgBuf,
162
+ 0,
163
+ NULL
164
+ );
165
+ LPTSTR tmp = strchr(lpMsgBuf, '\r');
166
+ if (tmp != NULL) {
167
+ *tmp = '\0';
168
+ }
169
+
170
+ _snprintf(str, strSize, " %s (%u)", lpMsgBuf, err);
171
+ LocalFree(lpMsgBuf);
172
+ #else
173
+ const char* error = strerror(errno);
174
+ snprintf(str, strSize, " %s (%u)", error, errno);
175
+ #endif
176
+ return str;
177
+ }
178
+
179
+ string gLogFileName;
180
+
181
+ void logV(bool appendSysError, bool showMsgBox, const char *format, va_list args) {
182
+ char msg[4096] = "";
183
+ vsnprintf(msg, 4096, format, args);
184
+
185
+ if (appendSysError) {
186
+ char sysErr[512] = "";
187
+ getSysError(sysErr, 512);
188
+ strncat(msg, sysErr, 4096 - strlen(msg));
189
+ }
190
+
191
+ if (!gLogFileName.empty() && gLogFileName != "''") {
192
+ FILE *file = fopen(gLogFileName.c_str(), "a");
193
+ if (file) {
194
+ fprintf(file, "%s\n", msg);
195
+ fclose(file);
196
+ }
197
+ }
198
+
199
+ if (showMsgBox) {
200
+ #ifdef WIN32
201
+ // Pop-up the message box only if there is no console
202
+ if (!isConsoleAttached()) {
203
+ ::MessageBox(NULL, msg, "JRuby Error", MB_OK | MB_ICONSTOP);
204
+ }
205
+ #endif
206
+ fprintf(stdout, "%s\n", msg);
207
+ }
208
+ }
209
+
210
+ void logErr(bool appendSysError, bool showMsgBox, const char *format, ...) {
211
+ va_list args;
212
+ va_start(args, format);
213
+ logV(appendSysError, showMsgBox, format, args);
214
+ }
215
+
216
+ void logMsg(const char *format, ...) {
217
+ va_list args;
218
+ va_start(args, format);
219
+ logV(false, false, format, args);
220
+ }
221
+
222
+ bool checkLoggingArg(int argc, char *argv[], bool delFile) {
223
+ for (int i = 0; i < argc; i++) {
224
+ if (strcmp("--", argv[i]) == 0) {
225
+ break;
226
+ }
227
+ if (strcmp(ARG_NAME_LAUNCHER_LOG, argv[i]) == 0) {
228
+ if (i+1 == argc || *argv[i+1] == '-') {
229
+ return false;
230
+ }
231
+ gLogFileName = argv[++i];
232
+ if (delFile) {
233
+ #ifdef WIN32
234
+ DeleteFile(gLogFileName.c_str());
235
+ #else
236
+ unlink(gLogFileName.c_str());
237
+ #endif
238
+ }
239
+ break;
240
+ }
241
+ }
242
+ return true;
243
+ }
244
+
245
+ bool printToConsole(const char *msg) {
246
+ fprintf(stdout, "%s", msg);
247
+ return false;
248
+ }
249
+
250
+ char** convertToArgvArray(list<string> args) {
251
+ char ** argv = new char*[args.size()+1];
252
+ int i = 0;
253
+ for (list<string>::iterator it = args.begin(); it != args.end(); ++it, ++i) {
254
+ argv[i] = strdup((*it).c_str());
255
+ }
256
+ argv[args.size()] = NULL;
257
+ return argv;
258
+ }
259
+
260
+ void addToArgList(list<string> & args, int argc, char ** argv) {
261
+ for (int i = 0; i < argc; i++) {
262
+ std::string str(argv[i]);
263
+ args.push_back(str);
264
+ }
265
+ }
266
+
267
+ void printListToConsole(list<string> values) {
268
+ for (list<string>::iterator it = values.begin(); it != values.end(); ++it) {
269
+ std::cout << *it << std::endl;
270
+ }
271
+ }
272
+
273
+ string trimTrailingBackslashes(string orig) {
274
+ while (orig.size() > 0 &&
275
+ orig.at(orig.size() - 1) == '\\') {
276
+ orig.erase(orig.size() - 1);
277
+ }
278
+ return orig;
279
+ }