Source Code Cross Referenced for P4Label.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 java.text.SimpleDateFormat;
027:        import java.util.Date;
028:        import org.apache.tools.ant.BuildException;
029:        import org.apache.tools.ant.Project;
030:        import org.apache.tools.ant.util.StringUtils;
031:
032:        /**
033:         *  Creates a new Perforce label and set contents to reflect current
034:         *  client file revisions.
035:         *
036:         *  Label name defaults to AntLabel if none set.
037:         *
038:         * Example Usage:
039:         * <pre>
040:         *   &lt;P4Label name="MyLabel-${TSTAMP}-${DSTAMP}" desc="Auto Build Label" /&gt;
041:         * </pre>
042:         *
043:         * @ant.task category="scm"
044:         */
045:        public class P4Label extends P4Base {
046:
047:            // CheckStyle:VisibilityModifier OFF - bc
048:            protected String name;
049:            protected String desc;
050:            protected String lock;
051:
052:            // CheckStyle:VisibilityModifier ON
053:
054:            /**
055:             * The name of the label; optional, default "AntLabel"
056:             * @param name the name of the label
057:             */
058:            public void setName(String name) {
059:                this .name = name;
060:            }
061:
062:            /**
063:             *Label Description; optional
064:             * @param desc description of the label
065:             */
066:            public void setDesc(String desc) {
067:                this .desc = desc;
068:            }
069:
070:            /**
071:             * when set to "locked", Perforce will lock the label once created; optional.
072:             * @param lock only admissible value "locked"
073:             */
074:            public void setLock(String lock) {
075:                this .lock = lock;
076:            }
077:
078:            /**
079:             * do the work
080:             * @throws BuildException if failonerror has been set to true and Perforce fails
081:             */
082:            public void execute() throws BuildException {
083:                log("P4Label exec:", Project.MSG_INFO);
084:
085:                if (P4View == null || P4View.length() < 1) {
086:                    log("View not set, assuming //depot/...", Project.MSG_WARN);
087:                    P4View = "//depot/...";
088:                } else {
089:                    P4View = StringUtils.replace(P4View, ":", "\n\t");
090:                    P4View = StringUtils.replace(P4View, ";", "\n\t");
091:                }
092:
093:                if (desc == null || desc.length() < 1) {
094:                    log("Label Description not set, assuming 'AntLabel'",
095:                            Project.MSG_WARN);
096:                    desc = "AntLabel";
097:                }
098:
099:                if (lock != null && !lock.equalsIgnoreCase("locked")) {
100:                    log("lock attribute invalid - ignoring", Project.MSG_WARN);
101:                }
102:
103:                if (name == null || name.length() < 1) {
104:                    SimpleDateFormat formatter = new SimpleDateFormat(
105:                            "yyyy.MM.dd-hh:mm");
106:                    Date now = new Date();
107:                    name = "AntLabel-" + formatter.format(now);
108:                    log("name not set, assuming '" + name + "'",
109:                            Project.MSG_WARN);
110:                }
111:
112:                //We have to create a unlocked label first
113:                String newLabel = "Label: " + name + "\nDescription: " + desc
114:                        + "\nOptions: unlocked" + "\nView: \n\t" + P4View;
115:
116:                P4Handler handler = new P4HandlerAdapter() {
117:                    public void process(String line) {
118:                        log(line, Project.MSG_VERBOSE);
119:                    }
120:                };
121:
122:                handler.setOutput(newLabel);
123:
124:                execP4Command("label -i", handler);
125:
126:                execP4Command("labelsync -l " + name, new P4HandlerAdapter() {
127:                    public void process(String line) {
128:                        log(line, Project.MSG_VERBOSE);
129:                    }
130:                });
131:
132:                log("Created Label " + name + " (" + desc + ") with view:\n"
133:                        + P4View, Project.MSG_INFO);
134:
135:                //Now lock if required
136:                if (lock != null && lock.equalsIgnoreCase("locked")) {
137:
138:                    log("Modifying lock status to 'locked'", Project.MSG_INFO);
139:
140:                    final StringBuffer labelSpec = new StringBuffer();
141:
142:                    //Read back the label spec from perforce,
143:                    //Replace Options
144:                    //Submit back to Perforce
145:
146:                    handler = new P4HandlerAdapter() {
147:                        public void process(String line) {
148:                            log(line, Project.MSG_VERBOSE);
149:
150:                            if (util.match("/^Options:/", line)) {
151:                                line = "Options: " + lock;
152:                            }
153:
154:                            labelSpec.append(line + "\n");
155:                        }
156:                    };
157:
158:                    execP4Command("label -o " + name, handler);
159:                    log(labelSpec.toString(), Project.MSG_DEBUG);
160:
161:                    log("Now locking label...", Project.MSG_VERBOSE);
162:                    handler = new P4HandlerAdapter() {
163:                        public void process(String line) {
164:                            log(line, Project.MSG_VERBOSE);
165:                        }
166:                    };
167:
168:                    handler.setOutput(labelSpec.toString());
169:                    execP4Command("label -i", handler);
170:                }
171:            }
172:        }
w_ww___.j___a_va_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.