Source Code Cross Referenced for Server.java in  » 6.0-JDK-Modules-com.sun » tools » com » sun » tools » javac » 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 » 6.0 JDK Modules com.sun » tools » com.sun.tools.javac 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package com.sun.tools.javac;
027:
028:        import com.sun.tools.javac.main.JavacOption.Option;
029:        import com.sun.tools.javac.main.RecognizedOptions.GrumpyHelper;
030:        import com.sun.tools.javac.main.RecognizedOptions;
031:        import com.sun.tools.javac.util.Version;
032:        import java.io.*;
033:        import java.net.*;
034:        import java.util.*;
035:        import java.util.concurrent.*;
036:        import java.util.logging.Logger;
037:        import javax.tools.*;
038:
039:        /**
040:         * Java Compiler Server.  Can be used to speed up a set of (small)
041:         * compilation tasks by caching jar files between compilations.
042:         *
043:         * <p><b>This is NOT part of any API supported by Sun Microsystems.
044:         * If you write code that depends on this, you do so at your own
045:         * risk.  This code and its internal interfaces are subject to change
046:         * or deletion without notice.</b></p>
047:         *
048:         * @author Peter von der Ah&eacute;
049:         * @since 1.6
050:         */
051:        @Version("@(#)Server.java	1.14 07/05/05")
052:        class Server implements  Runnable {
053:            private final BufferedReader in;
054:            private final OutputStream out;
055:            private final boolean isSocket;
056:            private static final JavaCompiler tool = ToolProvider
057:                    .getSystemJavaCompiler();
058:            private static Logger logger = Logger
059:                    .getLogger("com.sun.tools.javac");
060:
061:            static class CwdFileManager extends
062:                    ForwardingJavaFileManager<JavaFileManager> {
063:                String cwd;
064:
065:                CwdFileManager(JavaFileManager fileManager) {
066:                    super (fileManager);
067:                }
068:
069:                String getAbsoluteName(String name) {
070:                    if (new File(name).isAbsolute()) {
071:                        return name;
072:                    } else {
073:                        return new File(cwd, name).getPath();
074:                    }
075:                }
076:                //      public JavaFileObject getFileForInput(String name)
077:                //          throws IOException
078:                //      {
079:                //          return super.getFileForInput(getAbsoluteName(name));
080:                //      }
081:            }
082:
083:            // static CwdFileManager fm = new CwdFileManager(tool.getStandardFileManager());
084:            static StandardJavaFileManager fm = tool.getStandardFileManager(
085:                    null, null, null);
086:            static {
087:                // Use the same file manager for all compilations.  This will
088:                // cache jar files in the standard file manager.  Use
089:                // tool.getStandardFileManager().close() to release.
090:                // FIXME tool.setFileManager(fm);
091:                logger.setLevel(java.util.logging.Level.SEVERE);
092:            }
093:
094:            private Server(BufferedReader in, OutputStream out, boolean isSocket) {
095:                this .in = in;
096:                this .out = out;
097:                this .isSocket = isSocket;
098:            }
099:
100:            private Server(BufferedReader in, OutputStream out) {
101:                this (in, out, false);
102:            }
103:
104:            private Server(Socket socket) throws IOException,
105:                    UnsupportedEncodingException {
106:                this (new BufferedReader(new InputStreamReader(socket
107:                        .getInputStream(), "utf-8")), socket.getOutputStream(),
108:                        true);
109:            }
110:
111:            public void run() {
112:                List<String> args = new ArrayList<String>();
113:                int res = -1;
114:                try {
115:                    String line = null;
116:                    try {
117:                        line = in.readLine();
118:                    } catch (IOException e) {
119:                        System.err.println(e.getLocalizedMessage());
120:                        System.exit(0);
121:                        line = null;
122:                    }
123:                    // fm.cwd=null;
124:                    String cwd = null;
125:                    while (line != null) {
126:                        if (line.startsWith("PWD:")) {
127:                            cwd = line.substring(4);
128:                        } else if (line.equals("END")) {
129:                            break;
130:                        } else if (!"-XDstdout".equals(line)) {
131:                            args.add(line);
132:                        }
133:                        try {
134:                            line = in.readLine();
135:                        } catch (IOException e) {
136:                            System.err.println(e.getLocalizedMessage());
137:                            System.exit(0);
138:                            line = null;
139:                        }
140:                    }
141:                    Iterable<File> path = cwd == null ? null : Arrays
142:                            .<File> asList(new File(cwd));
143:                    // try { in.close(); } catch (IOException e) {}
144:                    long msec = System.currentTimeMillis();
145:                    try {
146:                        synchronized (tool) {
147:                            for (StandardLocation location : StandardLocation
148:                                    .values())
149:                                fm.setLocation(location, path);
150:                            res = compile(out, fm, args);
151:                            // FIXME res = tool.run((InputStream)null, null, out, args.toArray(new String[args.size()]));
152:                        }
153:                    } catch (Throwable ex) {
154:                        logger.log(java.util.logging.Level.SEVERE, args
155:                                .toString(), ex);
156:                        PrintWriter p = new PrintWriter(out, true);
157:                        ex.printStackTrace(p);
158:                        p.flush();
159:                    }
160:                    if (res >= 3) {
161:                        logger.severe(String.format("problem: %s", args));
162:                    } else {
163:                        logger.info(String.format("success: %s", args));
164:                    }
165:                    // res = compile(args.toArray(new String[args.size()]), out);
166:                    msec -= System.currentTimeMillis();
167:                    logger.info(String.format("Real time: %sms", -msec));
168:                } finally {
169:                    if (!isSocket) {
170:                        try {
171:                            in.close();
172:                        } catch (IOException e) {
173:                        }
174:                    }
175:                    try {
176:                        out.write(String.format("EXIT: %s%n", res).getBytes());
177:                    } catch (IOException ex) {
178:                        logger.log(java.util.logging.Level.SEVERE, args
179:                                .toString(), ex);
180:                    }
181:                    try {
182:                        out.flush();
183:                        out.close();
184:                    } catch (IOException ex) {
185:                        logger.log(java.util.logging.Level.SEVERE, args
186:                                .toString(), ex);
187:                    }
188:                    logger.info(String.format("EXIT: %s", res));
189:                }
190:            }
191:
192:            public static void main(String... args)
193:                    throws FileNotFoundException {
194:                if (args.length == 2) {
195:                    for (;;) {
196:                        throw new UnsupportedOperationException("TODO");
197:                        //              BufferedReader in = new BufferedReader(new FileReader(args[0]));
198:                        //              PrintWriter out = new PrintWriter(args[1]);
199:                        //              new Server(in, out).run();
200:                        //              System.out.flush();
201:                        //              System.err.flush();
202:                    }
203:                } else {
204:                    ExecutorService pool = Executors.newCachedThreadPool();
205:                    try {
206:                        ServerSocket socket = new ServerSocket(0xcafe, -1, null);
207:                        for (;;) {
208:                            pool.execute(new Server(socket.accept()));
209:                        }
210:                    } catch (IOException e) {
211:                        System.err.format("Error: %s%n", e
212:                                .getLocalizedMessage());
213:                        pool.shutdown();
214:                    }
215:                }
216:            }
217:
218:            private int compile(OutputStream out, StandardJavaFileManager fm,
219:                    List<String> args) {
220:                // FIXME parse args and use getTask
221:                // System.err.println("Running " + args);
222:                return tool.run(null, null, out, args.toArray(new String[args
223:                        .size()]));
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.