Source Code Cross Referenced for LogTrigger.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » plugins » trigger » 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 » Code Analyzer » apache ivy » org.apache.ivy.plugins.trigger 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.ivy.plugins.trigger;
019:
020:        import java.io.BufferedWriter;
021:        import java.io.File;
022:        import java.io.FileOutputStream;
023:        import java.io.FileWriter;
024:        import java.io.IOException;
025:        import java.io.OutputStreamWriter;
026:        import java.io.Writer;
027:
028:        import org.apache.ivy.core.IvyPatternHelper;
029:        import org.apache.ivy.core.event.IvyEvent;
030:        import org.apache.ivy.core.resolve.ResolveProcessException;
031:        import org.apache.ivy.util.Message;
032:
033:        /**
034:         * A trigger performing logging.
035:         * <p>
036:         * The implementation is widely inspired by Ant Echo task.
037:         * </p>
038:         */
039:        public class LogTrigger extends AbstractTrigger {
040:            private static final String LINE_SEPARATOR = System
041:                    .getProperty("line.separator");
042:
043:            private String message = "";
044:
045:            private File file = null;
046:
047:            private boolean append = true;
048:            /** encoding; set to null or empty means 'default' */
049:            private String encoding = "";
050:
051:            public void progress(IvyEvent event) {
052:                log(IvyPatternHelper.substituteVariables(message, event
053:                        .getAttributes()));
054:            }
055:
056:            /**
057:             * Logs the given message.
058:             * 
059:             * @param message the message to log
060:             */
061:            protected void log(String message) {
062:                if (file == null) {
063:                    Message.info(message);
064:                } else {
065:                    Writer out = null;
066:                    try {
067:                        // we add a line separator here for consistency with Message.info which creates a
068:                        // new line each time.
069:                        // we use the system dependent line separator to ease reading the log file
070:                        message += LINE_SEPARATOR;
071:                        String filename = file.getAbsolutePath();
072:                        if (encoding == null || encoding.length() == 0) {
073:                            out = new FileWriter(filename, append);
074:                        } else {
075:                            out = new BufferedWriter(new OutputStreamWriter(
076:                                    new FileOutputStream(filename, append),
077:                                    encoding));
078:                        }
079:                        out.write(message, 0, message.length());
080:                    } catch (IOException e) {
081:                        throw new ResolveProcessException(e);
082:                    } finally {
083:                        if (out != null) {
084:                            try {
085:                                out.close();
086:                            } catch (IOException e) {
087:                                throw new ResolveProcessException(e);
088:                            }
089:                        }
090:                    }
091:                }
092:            }
093:
094:            /**
095:             * Message to write.
096:             *
097:             * @param msg Sets the value for the message variable.
098:             */
099:            public void setMessage(String msg) {
100:                this .message = msg;
101:            }
102:
103:            /**
104:             * File to write to.
105:             * @param file the file to write to, if not set, echo to
106:             *             standard Ivy logging
107:             */
108:            public void setFile(String file) {
109:                this .file = new File(file);
110:            }
111:
112:            /**
113:             * If true, append to existing file.
114:             * @param append if true, append to existing file, default
115:             *               is false.
116:             */
117:            public void setAppend(boolean append) {
118:                this .append = append;
119:            }
120:
121:            /**
122:             * Declare the encoding to use when outputting to a file;
123:             * Use "" for the platform's default encoding.
124:             * @param encoding the character encoding to use.
125:             */
126:            public void setEncoding(String encoding) {
127:                this.encoding = encoding;
128:            }
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.