Source Code Cross Referenced for ConflictsFinder.java in  » Groupware » LibreSource » org » libresource » so6 » plugin » builders » 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 » Groupware » LibreSource » org.libresource.so6.plugin.builders 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * LibreSource
003:         * Copyright (C) 2004-2008 Artenum SARL / INRIA
004:         * http://www.libresource.org - contact@artenum.com
005:         *
006:         * This file is part of the LibreSource software, 
007:         * which can be used and distributed under license conditions.
008:         * The license conditions are provided in the LICENSE.TXT file 
009:         * at the root path of the packaging that enclose this file. 
010:         * More information can be found at 
011:         * - http://dev.libresource.org/home/license
012:         *
013:         * Initial authors :
014:         *
015:         * Guillaume Bort / INRIA
016:         * Francois Charoy / Universite Nancy 2
017:         * Julien Forest / Artenum
018:         * Claude Godart / Universite Henry Poincare
019:         * Florent Jouille / INRIA
020:         * Sebastien Jourdain / INRIA / Artenum
021:         * Yves Lerumeur / Artenum
022:         * Pascal Molli / Universite Henry Poincare
023:         * Gerald Oster / INRIA
024:         * Mariarosa Penzi / Artenum
025:         * Gerard Sookahet / Artenum
026:         * Raphael Tani / INRIA
027:         *
028:         * Contributors :
029:         *
030:         * Stephane Bagnier / Artenum
031:         * Amadou Dia / Artenum-IUP Blois
032:         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033:         */package org.libresource.so6.plugin.builders;
034:
035:        import org.eclipse.core.resources.IFile;
036:        import org.eclipse.core.resources.IFolder;
037:        import org.eclipse.core.resources.IMarker;
038:        import org.eclipse.core.resources.IProject;
039:        import org.eclipse.core.resources.IResource;
040:        import org.eclipse.core.resources.IResourceDelta;
041:        import org.eclipse.core.resources.IResourceDeltaVisitor;
042:        import org.eclipse.core.resources.IResourceVisitor;
043:        import org.eclipse.core.resources.IncrementalProjectBuilder;
044:        import org.eclipse.core.runtime.CoreException;
045:        import org.eclipse.core.runtime.IProgressMonitor;
046:
047:        import org.libresource.so6.core.WsConnection;
048:        import org.libresource.so6.core.engine.DBType;
049:        import org.libresource.so6.core.tf.TextFileFunctions;
050:        import org.libresource.so6.plugin.core.So6Util;
051:
052:        /**
053:         * @author Guillaume Bort
054:         */
055:        import java.io.FileInputStream;
056:
057:        import java.nio.CharBuffer;
058:        import java.nio.MappedByteBuffer;
059:        import java.nio.channels.FileChannel;
060:        import java.nio.charset.Charset;
061:        import java.nio.charset.CharsetDecoder;
062:
063:        import java.util.Map;
064:        import java.util.regex.Matcher;
065:        import java.util.regex.Pattern;
066:
067:        /**
068:         * DOCUMENT ME!
069:         *
070:         * @author $author$
071:         * @version $Revision: 1.3 $
072:         */
073:        public class ConflictsFinder extends IncrementalProjectBuilder {
074:            /** DOCUMENT ME! */
075:            public static final String ID = "org.libresource.so6.plugin.conflictsFinder";
076:            private static Charset charset = Charset.forName("UTF-8");
077:            private static CharsetDecoder decoder = charset.newDecoder();
078:            private static Pattern linePattern = Pattern.compile(".*\r?\n");
079:
080:            /**
081:             * DOCUMENT ME!
082:             *
083:             * @param kind DOCUMENT ME!
084:             * @param args DOCUMENT ME!
085:             * @param monitor DOCUMENT ME!
086:             *
087:             * @return DOCUMENT ME!
088:             *
089:             * @throws CoreException DOCUMENT ME!
090:             */
091:            protected IProject[] build(int kind, Map args,
092:                    IProgressMonitor monitor) throws CoreException {
093:                IResourceDelta delta = ((kind != FULL_BUILD) ? getDelta(getProject())
094:                        : null);
095:
096:                if ((delta == null) || (kind == FULL_BUILD)) {
097:                    IProject project = getProject();
098:
099:                    if (So6Util.isSo6Project(project)) {
100:                        project.accept(new Visitor(monitor));
101:                    }
102:                } else {
103:                    delta.accept(new DeltaVisitor(monitor));
104:                }
105:
106:                return null;
107:            }
108:
109:            /**
110:             * DOCUMENT ME!
111:             *
112:             * @param resource DOCUMENT ME!
113:             * @param monitor DOCUMENT ME!
114:             */
115:            protected void findConflict(IResource resource,
116:                    IProgressMonitor monitor) {
117:                So6Util.deleteProblemMarkersOnResource(resource);
118:
119:                try {
120:                    WsConnection connection = So6Util.getWsConnection(resource
121:                            .getProject());
122:                    int fileType = connection.getDBType().getType(
123:                            resource.getProjectRelativePath().toString());
124:
125:                    if (resource.getName().indexOf("#") != -1) {
126:                        So6Util.createProblemMarker(resource,
127:                                "Conflict on file", IMarker.SEVERITY_ERROR);
128:                    }
129:
130:                    WsConnection wsConnection = new WsConnection(
131:                            So6Util.getAbsoluteSo6PropertiesPath(resource
132:                                    .getProject()));
133:
134:                    if (fileType == DBType.TYPE_FILE_TXT) {
135:                        FileInputStream fis = new FileInputStream(resource
136:                                .getLocation().toFile());
137:                        FileChannel fc = fis.getChannel();
138:                        int sz = (int) fc.size();
139:                        MappedByteBuffer bb = fc.map(
140:                                FileChannel.MapMode.READ_ONLY, 0, sz);
141:                        CharBuffer cb = decoder.decode(bb);
142:                        Matcher lm = linePattern.matcher(cb);
143:                        Matcher pm = null;
144:                        int lines = 0;
145:
146:                        while (lm.find()) {
147:                            lines++;
148:
149:                            CharSequence cs = lm.group(); // The current line
150:
151:                            if (cs.toString().startsWith(
152:                                    TextFileFunctions.CONFLICT_BLOC_START)) {
153:                                String type = cs.toString().substring(
154:                                        TextFileFunctions.CONFLICT_BLOC_START
155:                                                .length()).trim();
156:                                So6Util.createProblemMarker((IFile) resource,
157:                                        "Conflict " + type + " in file",
158:                                        IMarker.SEVERITY_ERROR, lines);
159:                            }
160:
161:                            if (lm.end() == cb.limit()) {
162:                                break;
163:                            }
164:                        }
165:                    }
166:                } catch (Exception e) {
167:                    e.printStackTrace();
168:                }
169:            }
170:
171:            private class DeltaVisitor implements  IResourceDeltaVisitor {
172:                private IProgressMonitor monitor;
173:
174:                public DeltaVisitor(IProgressMonitor monitor) {
175:                    this .monitor = monitor;
176:                }
177:
178:                public boolean visit(IResourceDelta aDelta) {
179:                    boolean visitChildren = false;
180:
181:                    IResource resource = aDelta.getResource();
182:
183:                    if (resource instanceof  IProject) {
184:                        // Only check projects with So6 nature
185:                        visitChildren = So6Util
186:                                .isSo6Project((IProject) resource);
187:                    } else if (resource instanceof  IFile
188:                            || resource instanceof  IFolder) {
189:                        switch (aDelta.getKind()) {
190:                        case IResourceDelta.ADDED:
191:                            findConflict(resource, monitor);
192:
193:                            break;
194:
195:                        case IResourceDelta.CHANGED:
196:                            findConflict(resource, monitor);
197:
198:                            break;
199:
200:                        case IResourceDelta.REMOVED:
201:                            break;
202:                        }
203:                    }
204:
205:                    return visitChildren;
206:                }
207:            }
208:
209:            private class Visitor implements  IResourceVisitor {
210:                private IProgressMonitor monitor;
211:
212:                public Visitor(IProgressMonitor monitor) {
213:                    this .monitor = monitor;
214:                }
215:
216:                public boolean visit(IResource resource) {
217:                    if (resource instanceof  IFile
218:                            || resource instanceof  IFolder) {
219:                        findConflict(resource, monitor);
220:                    }
221:
222:                    return true;
223:                }
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.