Source Code Cross Referenced for RbConfigLibrary.java in  » IDE-Netbeans » library » org » jruby » libraries » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » library » org.jruby.libraries 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***** BEGIN LICENSE BLOCK *****
002:         * Version: CPL 1.0/GPL 2.0/LGPL 2.1
003:         *
004:         * The contents of this file are subject to the Common Public
005:         * License Version 1.0 (the "License"); you may not use this file
006:         * except in compliance with the License. You may obtain a copy of
007:         * the License at http://www.eclipse.org/legal/cpl-v10.html
008:         *
009:         * Software distributed under the License is distributed on an "AS
010:         * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
011:         * implied. See the License for the specific language governing
012:         * rights and limitations under the License.
013:         *
014:         * Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
015:         * Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
016:         * Copyright (C) 2005 Charles O Nutter
017:         * Copyright (C) 2006 Nick Sieger
018:         *
019:         * Alternatively, the contents of this file may be used under the terms of
020:         * either of the GNU General Public License Version 2 or later (the "GPL"),
021:         * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
022:         * in which case the provisions of the GPL or the LGPL are applicable instead
023:         * of those above. If you wish to allow use of your version of this file only
024:         * under the terms of either the GPL or the LGPL, and not to allow others to
025:         * use your version of this file under the terms of the CPL, indicate your
026:         * decision by deleting the provisions above and replace them with the notice
027:         * and other provisions required by the GPL or the LGPL. If you do not delete
028:         * the provisions above, a recipient may use your version of this file under
029:         * the terms of any one of the CPL, the GPL or the LGPL.
030:         ***** END LICENSE BLOCK *****/package org.jruby.libraries;
031:
032:        import java.io.IOException;
033:        import java.net.URL;
034:        import java.util.regex.Matcher;
035:        import java.util.regex.Pattern;
036:
037:        import org.jruby.Ruby;
038:        import org.jruby.RubyHash;
039:        import org.jruby.RubyModule;
040:        import org.jruby.runtime.Constants;
041:        import org.jruby.runtime.load.Library;
042:        import org.jruby.util.NormalizedFile;
043:
044:        public class RbConfigLibrary implements  Library {
045:            /**
046:             * Just enough configuration settings (most don't make sense in Java) to run the rubytests
047:             * unit tests. The tests use <code>bindir</code>, <code>RUBY_INSTALL_NAME</code> and
048:             * <code>EXEEXT</code>.
049:             */
050:            public void load(Ruby runtime) {
051:                RubyModule configModule = runtime.defineModule("Config");
052:                RubyHash configHash = RubyHash.newHash(runtime);
053:                configModule.defineConstant("CONFIG", configHash);
054:                runtime.getObject().defineConstant("RbConfig", configModule);
055:
056:                String[] versionParts = Constants.RUBY_VERSION.split("\\.");
057:                setConfig(configHash, "MAJOR", versionParts[0]);
058:                setConfig(configHash, "MINOR", versionParts[1]);
059:                setConfig(configHash, "TEENY", versionParts[2]);
060:                setConfig(configHash, "ruby_version", versionParts[0] + '.'
061:                        + versionParts[1]);
062:                setConfig(configHash, "arch", System.getProperty("os.arch")
063:                        + "-java"
064:                        + System.getProperty("java.specification.version"));
065:
066:                String normalizedHome = new NormalizedFile(runtime
067:                        .getJRubyHome()).getAbsolutePath();
068:                setConfig(configHash, "bindir", new NormalizedFile(
069:                        normalizedHome, "bin").getAbsolutePath());
070:                setConfig(configHash, "RUBY_INSTALL_NAME", jruby_script());
071:                setConfig(configHash, "ruby_install_name", jruby_script());
072:                setConfig(configHash, "SHELL", jruby_shell());
073:                setConfig(configHash, "prefix", normalizedHome);
074:                setConfig(configHash, "exec_prefix", normalizedHome);
075:
076:                setConfig(configHash, "host_os", System.getProperty("os.name"));
077:                setConfig(configHash, "host_vendor", System
078:                        .getProperty("java.vendor"));
079:                setConfig(configHash, "host_cpu", System.getProperty("os.arch"));
080:
081:                setConfig(configHash, "target_os", System
082:                        .getProperty("os.name"));
083:                setConfig(configHash, "target_cpu", System
084:                        .getProperty("os.arch"));
085:
086:                String jrubyJarFile = "jruby.jar";
087:                URL jrubyPropertiesUrl = Ruby.class.getClassLoader()
088:                        .getResource("/org/jruby/jruby.properties");
089:                if (jrubyPropertiesUrl != null) {
090:                    Pattern jarFile = Pattern
091:                            .compile("jar:file:.*?([a-zA-Z0-9.\\-]+\\.jar)!/org/jruby/jruby.properties");
092:                    Matcher jarMatcher = jarFile.matcher(jrubyPropertiesUrl
093:                            .toString());
094:                    jarMatcher.find();
095:                    if (jarMatcher.matches()) {
096:                        jrubyJarFile = jarMatcher.group(1);
097:                    }
098:                }
099:                setConfig(configHash, "LIBRUBY", jrubyJarFile);
100:                setConfig(configHash, "LIBRUBY_SO", jrubyJarFile);
101:
102:                setConfig(configHash, "build", Constants.BUILD);
103:                setConfig(configHash, "target", Constants.TARGET);
104:
105:                String libdir = System.getProperty("jruby.lib");
106:                if (libdir == null) {
107:                    libdir = new NormalizedFile(normalizedHome, "lib")
108:                            .getAbsolutePath();
109:                } else {
110:                    try {
111:                        // Our shell scripts pass in non-canonicalized paths, but even if we didn't
112:                        // anyone who did would become unhappy because Ruby apps expect no relative
113:                        // operators in the pathname (rubygems, for example).
114:                        libdir = new NormalizedFile(libdir).getCanonicalPath();
115:                    } catch (IOException e) {
116:                        libdir = new NormalizedFile(libdir).getAbsolutePath();
117:                    }
118:                }
119:
120:                setConfig(configHash, "libdir", libdir);
121:                setConfig(configHash, "rubylibdir", new NormalizedFile(libdir,
122:                        "ruby/1.8").getAbsolutePath());
123:                setConfig(configHash, "sitedir", new NormalizedFile(libdir,
124:                        "ruby/site_ruby").getAbsolutePath());
125:                setConfig(configHash, "sitelibdir", new NormalizedFile(libdir,
126:                        "ruby/site_ruby/1.8").getAbsolutePath());
127:                setConfig(configHash, "sitearchdir", new NormalizedFile(libdir,
128:                        "ruby/site_ruby/1.8/java").getAbsolutePath());
129:                setConfig(configHash, "archdir", new NormalizedFile(libdir,
130:                        "ruby/site_ruby/1.8/java").getAbsolutePath());
131:                setConfig(configHash, "configure_args", "");
132:                setConfig(configHash, "datadir", new NormalizedFile(
133:                        normalizedHome, "share").getAbsolutePath());
134:                setConfig(configHash, "mandir", new NormalizedFile(
135:                        normalizedHome, "man").getAbsolutePath());
136:                setConfig(configHash, "sysconfdir", new NormalizedFile(
137:                        normalizedHome, "etc").getAbsolutePath());
138:                setConfig(configHash, "DLEXT", "jar");
139:
140:                if (isWindows()) {
141:                    setConfig(configHash, "EXEEXT", ".exe");
142:                } else {
143:                    setConfig(configHash, "EXEEXT", "");
144:                }
145:            }
146:
147:            private static void setConfig(RubyHash configHash, String key,
148:                    String value) {
149:                Ruby runtime = configHash.getRuntime();
150:                configHash.aset(runtime.newString(key), runtime
151:                        .newString(value));
152:            }
153:
154:            private static boolean isWindows() {
155:                return System.getProperty("os.name", "").startsWith("Windows");
156:            }
157:
158:            private String jruby_script() {
159:                return System.getProperty("jruby.script",
160:                        isWindows() ? "jruby.bat" : "jruby").replace('\\', '/');
161:            }
162:
163:            private String jruby_shell() {
164:                return System.getProperty("jruby.shell",
165:                        isWindows() ? "cmd.exe" : "/bin/sh").replace('\\', '/');
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.