jruby-launcher 0.9.9-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.
data/utilsfuncs.h ADDED
@@ -0,0 +1,84 @@
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
+ #ifndef _UTILSFUNCS_H
46
+ #define _UTILSFUNCS_H
47
+
48
+ #include <string>
49
+ #include <list>
50
+
51
+ bool dirExists(const char *path);
52
+ bool fileExists(const char *path);
53
+ void logMsg(const char *format, ...);
54
+ void logErr(bool appendSysError, bool showMsgBox, const char *format, ...);
55
+ bool checkLoggingArg(int argc, char *argv[], bool delFile);
56
+ bool printToConsole(const char *msg);
57
+ char** convertToArgvArray(std::list<std::string> args);
58
+ void addToArgList(std::list<std::string> & args, int argc, char ** argv);
59
+ char* findOnPath(const char* name);
60
+ bool checkDirectory(const char* path);
61
+ int printArgvToConsole(char** argv);
62
+
63
+ #ifndef WIN32
64
+ #define FILE_SEP '/'
65
+ #define PATH_SEP ':'
66
+ #else // WIN32
67
+ #include <windows.h>
68
+ #define FILE_SEP '\\'
69
+ #define PATH_SEP ';'
70
+
71
+ #ifdef JRUBYW
72
+ bool setupProcess(int &argc, char *argv[], DWORD &parentProcID, const char *attachMsg = 0);
73
+ bool getParentProcessID(DWORD &id);
74
+ #endif /* JRUBYW */
75
+
76
+ bool normalizePath(char *path, int len);
77
+ bool disableFolderVirtualization(HANDLE hProcess);
78
+ char * getCurrentModulePath(char *path, int pathLen);
79
+ bool getStringFromRegistry(HKEY rootKey, const char *keyName, const char *valueName, std::string &value);
80
+ bool getDwordFromRegistry(HKEY rootKey, const char *keyName, const char *valueName, DWORD &value);
81
+ bool isConsoleAttached();
82
+ #endif // WIN32
83
+
84
+ #endif /* _UTILSFUNCS_H */
data/utilsfuncswin.cpp ADDED
@@ -0,0 +1,229 @@
1
+ #include "utilsfuncs.h"
2
+ #include "argnames.h"
3
+ #include <tlhelp32.h>
4
+
5
+ using namespace std;
6
+
7
+ bool normalizePath(char *path, int len) {
8
+ char tmp[MAX_PATH] = "";
9
+ int i = 0;
10
+ while (path[i] && i < MAX_PATH - 1) {
11
+ tmp[i] = path[i] == '/' ? '\\' : path[i];
12
+ i++;
13
+ }
14
+ tmp[i] = '\0';
15
+ return _fullpath(path, tmp, len) != NULL;
16
+ }
17
+
18
+ bool disableFolderVirtualization(HANDLE hProcess) {
19
+ OSVERSIONINFO osvi = {0};
20
+ osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
21
+ if (GetVersionEx(&osvi) && osvi.dwMajorVersion == 6) // check it is Win VISTA
22
+ {
23
+ HANDLE hToken;
24
+ if (OpenProcessToken(hProcess, TOKEN_ALL_ACCESS, &hToken)) {
25
+ DWORD tokenInfoVal = 0;
26
+ if (!SetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS) 24, &tokenInfoVal, sizeof (DWORD))) {
27
+ // invalid token information class (24) is OK, it means there is no folder virtualization on current system
28
+ if (GetLastError() != ERROR_INVALID_PARAMETER) {
29
+ logErr(true, true, "Failed to set token information.");
30
+ return false;
31
+ }
32
+ }
33
+ CloseHandle(hToken);
34
+ } else {
35
+ logErr(true, true, "Failed to open process token.");
36
+ return false;
37
+ }
38
+ }
39
+ return true;
40
+ }
41
+
42
+ bool getStringFromRegistry(HKEY rootKey, const char *keyName, const char *valueName, string &value) {
43
+ logMsg("getStringFromRegistry()\n\tkeyName: %s\n\tvalueName: %s", keyName, valueName);
44
+ HKEY hKey = 0;
45
+ if (RegOpenKeyEx(rootKey, keyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
46
+ DWORD valSize = 4096;
47
+ DWORD type = 0;
48
+ char val[4096] = "";
49
+ if (RegQueryValueEx(hKey, valueName, 0, &type, (BYTE *) val, &valSize) == ERROR_SUCCESS
50
+ && type == REG_SZ) {
51
+ logMsg("%s: %s", valueName, val);
52
+ RegCloseKey(hKey);
53
+ value = val;
54
+ return true;
55
+ } else {
56
+ logErr(true, false, "RegQueryValueEx() failed.");
57
+ }
58
+ RegCloseKey(hKey);
59
+ } else {
60
+ logErr(true, false, "RegOpenKeyEx() failed.");
61
+ }
62
+ return false;
63
+ }
64
+
65
+ bool getDwordFromRegistry(HKEY rootKey, const char *keyName, const char *valueName, DWORD &value) {
66
+ logMsg("getDwordFromRegistry()\n\tkeyName: %s\n\tvalueName: %s", keyName, valueName);
67
+ HKEY hKey = 0;
68
+ if (RegOpenKeyEx(rootKey, keyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
69
+ DWORD valSize = sizeof(DWORD);
70
+ DWORD type = 0;
71
+ if (RegQueryValueEx(hKey, valueName, 0, &type, (BYTE *) &value, &valSize) == ERROR_SUCCESS
72
+ && type == REG_DWORD) {
73
+ logMsg("%s: %u", valueName, value);
74
+ RegCloseKey(hKey);
75
+ return true;
76
+ } else {
77
+ logErr(true, false, "RegQueryValueEx() failed.");
78
+ }
79
+ RegCloseKey(hKey);
80
+ } else {
81
+ logErr(true, false, "RegOpenKeyEx() failed.");
82
+ }
83
+ return false;
84
+ }
85
+
86
+ char * getCurrentModulePath(char *path, int pathLen) {
87
+ MEMORY_BASIC_INFORMATION mbi;
88
+ static int dummy;
89
+ VirtualQuery(&dummy, &mbi, sizeof (mbi));
90
+ HMODULE hModule = (HMODULE) mbi.AllocationBase;
91
+ GetModuleFileName(hModule, path, pathLen);
92
+ return path;
93
+ }
94
+
95
+ #ifdef JRUBYW
96
+ bool setupProcess(int &argc, char *argv[], DWORD &parentProcID, const char *attachMsg) {
97
+ #define CHECK_ARG \
98
+ if (i+1 == argc) {\
99
+ logErr(false, true, "Argument is missing for \"%s\" option.", argv[i]);\
100
+ return false;\
101
+ }
102
+
103
+ parentProcID = 0;
104
+ DWORD cmdLineArgPPID = 0;
105
+ for (int i = 0; i < argc; i++) {
106
+ // break arg parsing, once "--" is found
107
+ if (strcmp("--", argv[i]) == 0) {
108
+ break;
109
+ }
110
+ if (strcmp(ARG_NAME_CONSOLE, argv[i]) == 0) {
111
+ CHECK_ARG;
112
+ if (strcmp("new", argv[i + 1]) == 0){
113
+ logMsg("Allocating new console...");
114
+ AllocConsole();
115
+ } else if (strcmp("suppress", argv[i + 1]) == 0) {
116
+ logMsg("Suppressing the attachment to console...");
117
+ // nothing, no console should be attached
118
+ } else if (strcmp("attach", argv[i + 1]) == 0) {
119
+ logMsg("Trying to attach to the existing console...");
120
+ // attach to parent process console if exists
121
+ // AttachConsole exists since WinXP, so be nice and do it dynamically
122
+ typedef BOOL(WINAPI * LPFAC)(DWORD dwProcessId);
123
+ HINSTANCE hKernel32 = GetModuleHandle("kernel32");
124
+ if (hKernel32) {
125
+ LPFAC attachConsole = (LPFAC) GetProcAddress(hKernel32, "AttachConsole");
126
+ if (attachConsole) {
127
+ if (cmdLineArgPPID) {
128
+ if (!attachConsole(cmdLineArgPPID)) {
129
+ logErr(true, false, "AttachConsole of PPID: %u failed.", cmdLineArgPPID);
130
+ }
131
+ } else {
132
+ if (!attachConsole((DWORD) - 1)) {
133
+ logErr(true, true, "AttachConsole of PP failed.");
134
+ } else {
135
+ getParentProcessID(parentProcID);
136
+ if (attachMsg) {
137
+ printToConsole(attachMsg);
138
+ }
139
+ }
140
+ }
141
+ } else {
142
+ logErr(true, false, "GetProcAddress() for AttachConsole failed.");
143
+ }
144
+ }
145
+ } else {
146
+ logErr(false, true, "Invalid argument for \"%s\" option.", argv[i]);
147
+ return false;
148
+ }
149
+ // remove options
150
+ for (int k = i + 2; k < argc; k++) {
151
+ argv[k-2] = argv[k];
152
+ }
153
+ argc -= 2;
154
+ return true;
155
+ }
156
+ }
157
+ #undef CHECK_ARG
158
+
159
+ return true;
160
+ }
161
+ #endif /* JRUBYW */
162
+
163
+ bool isConsoleAttached() {
164
+ typedef HWND (WINAPI *GetConsoleWindowT)();
165
+ HINSTANCE hKernel32 = GetModuleHandle("kernel32");
166
+ if (hKernel32) {
167
+ GetConsoleWindowT getConsoleWindow = (GetConsoleWindowT) GetProcAddress(hKernel32, "GetConsoleWindow");
168
+ if (getConsoleWindow) {
169
+ if (getConsoleWindow() != NULL) {
170
+ logMsg("Console is attached.");
171
+ return true;
172
+ }
173
+ } else {
174
+ logErr(true, false, "GetProcAddress() for GetConsoleWindow failed.");
175
+ }
176
+ }
177
+ return false;
178
+ }
179
+
180
+ #ifdef JRUBYW
181
+ bool getParentProcessID(DWORD &id) {
182
+ typedef HANDLE (WINAPI * CreateToolhelp32SnapshotT)(DWORD, DWORD);
183
+ typedef BOOL (WINAPI * Process32FirstT)(HANDLE, LPPROCESSENTRY32);
184
+ typedef BOOL (WINAPI * Process32NextT)(HANDLE, LPPROCESSENTRY32);
185
+
186
+ HINSTANCE hKernel32 = GetModuleHandle("kernel32");
187
+ if (!hKernel32) {
188
+ return false;
189
+ }
190
+
191
+ CreateToolhelp32SnapshotT createToolhelp32Snapshot = (CreateToolhelp32SnapshotT) GetProcAddress(hKernel32, "CreateToolhelp32Snapshot");
192
+ Process32FirstT process32First = (Process32FirstT) GetProcAddress(hKernel32, "Process32First");
193
+ Process32NextT process32Next = (Process32NextT) GetProcAddress(hKernel32, "Process32Next");
194
+
195
+ if (createToolhelp32Snapshot == NULL || process32First == NULL || process32Next == NULL) {
196
+ logErr(true, false, "Failed to obtain Toolhelp32 functions.");
197
+ return false;
198
+ }
199
+
200
+ HANDLE hSnapshot = createToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
201
+ if (hSnapshot == INVALID_HANDLE_VALUE) {
202
+ logErr(true, false, "Failed to obtain process snapshot.");
203
+ return false;
204
+ }
205
+
206
+ PROCESSENTRY32 entry = {0};
207
+ entry.dwSize = sizeof (PROCESSENTRY32);
208
+ if (!process32First(hSnapshot, &entry)) {
209
+ CloseHandle(hSnapshot);
210
+ return false;
211
+ }
212
+
213
+ DWORD curID = GetCurrentProcessId();
214
+ logMsg("Current process ID: %u", curID);
215
+
216
+ do {
217
+ if (entry.th32ProcessID == curID) {
218
+ id = entry.th32ParentProcessID;
219
+ logMsg("Parent process ID: %u", id);
220
+ CloseHandle(hSnapshot);
221
+ return true;
222
+ }
223
+ } while (process32Next(hSnapshot, &entry));
224
+
225
+ CloseHandle(hSnapshot);
226
+ return false;
227
+ }
228
+ #endif /* JRUBYW */
229
+
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jruby-launcher
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 9
9
+ version: 0.9.9
10
+ platform: java
11
+ authors:
12
+ - Nick Sieger
13
+ - Vladimir Sizikov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-03-01 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Builds and installs a native launcher for JRuby on your system
23
+ email:
24
+ - nick@nicksieger.com
25
+ - vsizikov@gmail.com
26
+ executables: []
27
+
28
+ extensions:
29
+ - extconf.rb
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - COPYING
34
+ - README.txt
35
+ - Makefile
36
+ - Rakefile
37
+ - ng.c
38
+ - strlcpy.c
39
+ - argparser.cpp
40
+ - jruby.cpp
41
+ - jrubyexe.cpp
42
+ - jvmlauncher.cpp
43
+ - platformlauncher.cpp
44
+ - unixlauncher.cpp
45
+ - utilsfuncs.cpp
46
+ - utilsfuncswin.cpp
47
+ - argnames.h
48
+ - argparser.h
49
+ - jvmlauncher.h
50
+ - nbexecloader.h
51
+ - platformlauncher.h
52
+ - rb_w32_cmdvector.h
53
+ - unixlauncher.h
54
+ - utilsfuncs.h
55
+ - inc/Makefile-conf.mk
56
+ - inc/Makefile-impl.mk
57
+ - inc/Makefile-rules.mk
58
+ - extconf.rb
59
+ - lib/jruby-launcher.rb
60
+ - lib/rubygems/defaults/jruby_native.rb
61
+ - spec/launcher_spec.rb
62
+ - spec/spec_helper.rb
63
+ - resources/jruby.ico
64
+ - resources/jruby.rc
65
+ has_rdoc: true
66
+ homepage: http://jruby.org
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project: jruby-extras
91
+ rubygems_version: 1.3.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Native launcher for JRuby
95
+ test_files: []
96
+