Source Code Cross Referenced for CommentCorrecterTask.java in  » IDE-Netbeans » nbi » org » netbeans » installer » infra » utils » comment » ant » 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 » nbi » org.netbeans.installer.infra.utils.comment.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         * 
006:         * The contents of this file are subject to the terms of either the GNU General
007:         * Public License Version 2 only ("GPL") or the Common Development and Distribution
008:         * License("CDDL") (collectively, the "License"). You may not use this file except in
009:         * compliance with the License. You can obtain a copy of the License at
010:         * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011:         * License for the specific language governing permissions and limitations under the
012:         * License.  When distributing the software, include this License Header Notice in
013:         * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP.  Sun
014:         * designates this particular file as subject to the "Classpath" exception as
015:         * provided by Sun in the GPL Version 2 section of the License file that
016:         * accompanied this code. If applicable, add the following below the License Header,
017:         * with the fields enclosed by brackets [] replaced by your own identifying
018:         * information: "Portions Copyrighted [year] [name of copyright owner]"
019:         * 
020:         * Contributor(s):
021:         * 
022:         * The Original Software is NetBeans. The Initial Developer of the Original Software
023:         * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024:         * Rights Reserved.
025:         * 
026:         * If you wish your version of this file to be governed by only the CDDL or only the
027:         * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028:         * this software in this distribution under the [CDDL or GPL Version 2] license." If
029:         * you do not indicate a single choice of license, a recipient has the option to
030:         * distribute your version of this file under either the CDDL, the GPL Version 2 or
031:         * to extend the choice of license to its licensees as provided above. However, if
032:         * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033:         * the option applies only if the new code is made subject to such option by the
034:         * copyright holder.
035:         */
036:
037:        package org.netbeans.installer.infra.utils.comment.ant;
038:
039:        import java.io.File;
040:        import java.io.IOException;
041:        import java.util.LinkedList;
042:        import java.util.List;
043:        import org.apache.tools.ant.BuildException;
044:        import org.apache.tools.ant.DirectoryScanner;
045:        import org.apache.tools.ant.Task;
046:        import org.apache.tools.ant.types.FileSet;
047:        import org.netbeans.installer.infra.utils.comment.CommentCorrecter;
048:        import org.netbeans.installer.infra.utils.comment.handlers.FileHandler;
049:        import org.netbeans.installer.infra.utils.comment.utils.Utils;
050:
051:        /**
052:         * This is the apache ant interface of the initial comment correcting utility.
053:         *
054:         * <p>
055:         * The ant task defined in this class supports two arguments: <code>text</code> -
056:         * its value should be the path to the file which contains the desired intiial
057:         * comment text; 'lineLength' - a positive integer defining the requried line length
058:         * for the comment (optional).
059:         *
060:         * <p>
061:         * The task supports the nested <code>&lt;fileset&gt;</code> elements which should be
062:         * used to define the set of files for which the correction should take place.
063:         *
064:         * @author Kirill Sorokin
065:         */
066:        public final class CommentCorrecterTask extends Task {
067:            /////////////////////////////////////////////////////////////////////////////////
068:            // Instance
069:            /**
070:             * The file with the desired initial comment text.
071:             */
072:            private File text;
073:
074:            /**
075:             * The desired line length for the comment.
076:             */
077:            private int lineLength;
078:
079:            /**
080:             * List of <code>FileSet</code> which define the set of files for which the
081:             * comment correction should take place.
082:             */
083:            private List<FileSet> filesets;
084:
085:            // constructor //////////////////////////////////////////////////////////////////
086:            /**
087:             * The default and only constructor for the ant task. It only sets the defaults
088:             * values for the class fields.
089:             */
090:            public CommentCorrecterTask() {
091:                lineLength = CommentCorrecter.DEFAULT_LINE_LENGTH;
092:                filesets = new LinkedList<FileSet>();
093:            }
094:
095:            // setters //////////////////////////////////////////////////////////////////////
096:            /**
097:             * Setter for the <code>text</code> property.
098:             *
099:             * @param path New value for the <code>text</code> property.
100:             */
101:            public void setText(String path) {
102:                text = new File(path).getAbsoluteFile();
103:            }
104:
105:            /**
106:             * Setter for the <code>lineLength</code> property.
107:             *
108:             * @param string New value for the <code>text</code> property as a string - it
109:             *      will be converted to an integer.
110:             */
111:            public void setLineLength(String string) {
112:                try {
113:                    lineLength = Integer.parseInt(string);
114:                } catch (NumberFormatException e) {
115:                    log(e.getMessage());
116:                }
117:            }
118:
119:            /**
120:             * Adds a new <code>FileSet</code> to the list. The list of file sets will be
121:             * used to perform the comment correction.
122:             *
123:             * @param fileset The file set to add to the list.
124:             */
125:            public void addFileSet(FileSet fileset) {
126:                filesets.add(fileset);
127:            }
128:
129:            /**
130:             * Executes the ant task, performing initial comment correction on the set of
131:             * files defined in <code>filesets</code>. Overrides the <code>execute()</code>
132:             * method in the <code>Task</code> class.
133:             *
134:             * @throws org.apache.tools.ant.BuildException if parameters validation fails or
135:             *      an I/O error occurs
136:             */
137:            @Override
138:            public void execute() throws BuildException {
139:                if (text == null) {
140:                    throw new BuildException(
141:                            "The 'text' attribute is required."); // NOI18N
142:                }
143:
144:                try {
145:                    final String comment = Utils.readFile(text);
146:
147:                    for (FileSet fileset : filesets) {
148:                        final DirectoryScanner scanner = fileset
149:                                .getDirectoryScanner(getProject());
150:
151:                        for (String filename : scanner.getIncludedFiles()) {
152:                            final File file = new File(fileset
153:                                    .getDir(getProject()), filename);
154:
155:                            log(file.getAbsolutePath());
156:
157:                            final FileHandler handler = CommentCorrecter
158:                                    .getInstance().getHandler(file);
159:                            if (handler != null) {
160:                                handler.load(file);
161:
162:                                final String current = handler
163:                                        .getCurrentComment();
164:                                if (current == null) {
165:                                    log("    ...inserting " + // NOI18N
166:                                            "the initial comment"); // NOI18N
167:                                    handler.insertComment(comment, lineLength);
168:                                } else {
169:                                    final String correct = handler
170:                                            .getCorrectComment(comment,
171:                                                    lineLength);
172:                                    if (current.equals(correct)) {
173:                                        log("    ...skipping -- " + // NOI18N
174:                                                "the comment is up to date"); // NOI18N
175:                                    } else {
176:                                        log("    ...updating " + // NOI18N
177:                                                "the initial comment"); // NOI18N
178:                                        handler.updateComment(comment,
179:                                                lineLength);
180:                                    }
181:                                }
182:
183:                                handler.save(file);
184:                            } else {
185:                                log("   ...skipping -- " + // NOI18N
186:                                        "not recognized by any handler"); // NOI18N
187:                            }
188:                        }
189:                    }
190:                } catch (IOException e) {
191:                    throw new BuildException(e);
192:                }
193:            }
194:        }
ww__w._j___a___va__2__s__.___c_o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.