Source Code Cross Referenced for P4Counter.java in  » Build » ANT » org » apache » tools » ant » taskdefs » optional » perforce » 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 » Build » ANT » org.apache.tools.ant.taskdefs.optional.perforce 
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:        /*
019:         * Portions of this software are based upon public domain software
020:         * originally written at the National Center for Supercomputing Applications,
021:         * University of Illinois, Urbana-Champaign.
022:         */
023:
024:        package org.apache.tools.ant.taskdefs.optional.perforce;
025:
026:        import org.apache.tools.ant.BuildException;
027:        import org.apache.tools.ant.Project;
028:
029:        /**
030:         * Obtains or sets the value of a counter.
031:         *
032:         * <p> When used in its base form
033:         * (where only the counter name is provided), the counter value will be
034:         * printed to the output stream. When the value is provided, the counter
035:         * will be set to the value provided. When a property name is provided,
036:         * the property will be filled with the value of the counter. You may
037:         * not specify to both get and set the value of the counter in the same
038:         * Task.
039:         * </p>
040:         * <P>
041:         * The user performing this task must have Perforce &quot;review&quot; permissions
042:         * as defined by Perforce protections in order for this task to succeed.
043:         </P>
044:
045:         * Example Usage:<br>
046:         * &lt;p4counter name="${p4.counter}" property=${p4.change}"/&gt;
047:         *
048:         * @ant.task category="scm"
049:         */
050:
051:        public class P4Counter extends P4Base {
052:            // CheckStyle:VisibilityModifier OFF - bc
053:            /**
054:             * name of the counter
055:             */
056:            public String counter = null;
057:            /**
058:             * name of an optional property
059:             */
060:            public String property = null;
061:            /**
062:             * flag telling whether the value of the counter should be set
063:             */
064:            public boolean shouldSetValue = false;
065:            /**
066:             * flag telling whether a property should be set
067:             */
068:            public boolean shouldSetProperty = false;
069:            /**
070:             * new value for the counter
071:             */
072:            public int value = 0;
073:
074:            // CheckStyle:VisibilityModifier ON
075:
076:            /**
077:             * The name of the counter; required
078:             * @param counter name of the counter
079:             */
080:            public void setName(String counter) {
081:                this .counter = counter;
082:            }
083:
084:            /**
085:             * The new value for the counter; optional.
086:             * @param value new value for the counter
087:             */
088:            public void setValue(int value) {
089:                this .value = value;
090:                shouldSetValue = true;
091:            }
092:
093:            /**
094:             * A property to be set with the value of the counter
095:             * @param property the name of a property to set with the value
096:             * of the counter
097:             */
098:            public void setProperty(String property) {
099:                this .property = property;
100:                shouldSetProperty = true;
101:            }
102:
103:            /**
104:             * again, properties are mutable in this tsk
105:             * @throws BuildException if the required parameters are not supplied.
106:             */
107:            public void execute() throws BuildException {
108:
109:                if ((counter == null) || counter.length() == 0) {
110:                    throw new BuildException("No counter specified to retrieve");
111:                }
112:
113:                if (shouldSetValue && shouldSetProperty) {
114:                    throw new BuildException(
115:                            "Cannot both set the value of the property and retrieve the "
116:                                    + "value of the property.");
117:                }
118:
119:                String command = "counter " + P4CmdOpts + " " + counter;
120:                if (!shouldSetProperty) {
121:                    // NOTE kirk@radik.com 04-April-2001 -- If you put in the -s, you
122:                    // have to start running through regular expressions here. Much easier
123:                    // to just not include the scripting information than to try to add it
124:                    // and strip it later.
125:                    command = "-s " + command;
126:                }
127:                if (shouldSetValue) {
128:                    command += " " + value;
129:                }
130:
131:                if (shouldSetProperty) {
132:                    final Project myProj = getProject();
133:
134:                    P4Handler handler = new P4HandlerAdapter() {
135:                        public void process(String line) {
136:                            log("P4Counter retrieved line \"" + line + "\"",
137:                                    Project.MSG_VERBOSE);
138:                            try {
139:                                value = Integer.parseInt(line);
140:                                myProj.setProperty(property, "" + value);
141:                            } catch (NumberFormatException nfe) {
142:                                throw new BuildException("Perforce error. "
143:                                        + "Could not retrieve counter value.");
144:                            }
145:                        }
146:                    };
147:
148:                    execP4Command(command, handler);
149:                } else {
150:                    execP4Command(command, new SimpleP4OutputHandler(this));
151:                }
152:            }
153:        }
w__w__w___.ja__v_a__2s_._c___o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.