Package: VdmCoreBuilder

VdmCoreBuilder

nameinstructionbranchcomplexitylinemethod
VdmCoreBuilder()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
build(int, Map, IProgressMonitor)
M: 57 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
getVdmProject()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
syncProjectResources()
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
validateProject()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.core
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.core.builder;
23:
24: import java.util.Map;
25:
26: import org.eclipse.core.resources.IFile;
27: import org.eclipse.core.resources.IProject;
28: import org.eclipse.core.resources.IResource;
29: import org.eclipse.core.resources.IResourceDelta;
30: import org.eclipse.core.resources.IResourceDeltaVisitor;
31: import org.eclipse.core.resources.IncrementalProjectBuilder;
32: import org.eclipse.core.runtime.CoreException;
33: import org.eclipse.core.runtime.IProgressMonitor;
34: import org.overture.ide.core.VdmCore;
35: import org.overture.ide.core.resources.IVdmProject;
36:
37: public abstract class VdmCoreBuilder extends IncrementalProjectBuilder
38: {
39:         private class DeltaFileVisitor implements IResourceDeltaVisitor
40:         {
41:                 private boolean sourceFound = false;
42:
43:                 public boolean isSourceFound()
44:                 {
45:                         return sourceFound;
46:                 }
47:
48:                 public boolean visit(IResourceDelta delta) throws CoreException
49:                 {
50:                         IResource resource = delta.getResource();
51:                         
52:                         if (resource instanceof IFile && resource.exists() && resource.isSynchronized(IResource.DEPTH_ZERO) && ((IFile) resource).getContentDescription()!=null)
53:                         {
54:
55:                                 if (getVdmProject().isModelFile((IFile) resource))
56:                                 {
57:                                         sourceFound = true;
58:                                         return false;// do not visit children
59:                                 }
60:                         }
61:                         return true;
62:                 }
63:
64:         }
65:
66:         @Override
67:         protected final IProject[] build(int kind, @SuppressWarnings("rawtypes") Map args,
68:                         IProgressMonitor monitor) throws CoreException
69:         {
70:•                if (!validateProject())
71:                 {
72:                         // Project who invoked the builder is not supported
73:                         return new IProject[0];
74:                 }
75:         
76:                 getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
77:
78:•                if (kind == IncrementalProjectBuilder.FULL_BUILD)
79:                 {        initialize();
80:                         clean(monitor);
81:                         build(monitor);
82:                 } else
83:                 {
84:                         IResourceDelta delta = getDelta(getProject());
85:                         // if (delta == null)
86:                         DeltaFileVisitor visitor = new DeltaFileVisitor();
87:                         delta.accept(visitor, IResourceDelta.ADDED | IResourceDelta.CHANGED);
88:                         // {
89:•                        if (visitor.isSourceFound())
90:                         {
91:                                 initialize();
92:                                 build(monitor);
93:                         }
94:                         // } else
95:                         // {
96:                         // incrementalBuild(delta, monitor);
97:                         // }
98:                 }
99:
100:                 endBuild(monitor);
101:                 return new IProject[]{getProject()};
102:                 
103:         }
104:
105:         public abstract void initialize();
106:
107:         // private void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor)
108:         // {
109:         // System.out.println("incremental build on " + delta);
110:         // try
111:         // {
112:         // delta.accept(new IResourceDeltaVisitor() {
113:         // public boolean visit(IResourceDelta delta)
114:         // {
115:         // System.out.println("changed: "
116:         // + delta.getResource().getRawLocation());
117:         // return true; // visit children too
118:         // }
119:         // });
120:         // } catch (CoreException e)
121:         // {
122:         // e.printStackTrace();
123:         // }
124:         // }
125:
126:         public abstract void build(IProgressMonitor monitor) throws CoreException;
127:
128:         public abstract void endBuild(IProgressMonitor monitor);
129:
130:         /***
131:          * This method sync the project resources. It is called before an instance of the AbstractBuilder is created
132:          */
133:         public void syncProjectResources()
134:         {
135:•                if (!getProject().isSynchronized(IResource.DEPTH_INFINITE))
136:                         try
137:                         {
138:                                 getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
139:
140:                         } catch (CoreException e)
141:                         {
142:                                 VdmCore.log("VdmCoreBuilder:syncProjectResources", e);
143:                         }
144:         }
145:
146:         
147:
148:         /***
149:          * Validated that the project who invoked the builder is a supported VDM project
150:          */
151:         protected boolean validateProject()
152:         {
153:•                return getProject().getAdapter(IVdmProject.class) != null;
154:         }
155:
156:         /***
157:          * This method should be used instead of the getProject
158:          */
159:         public final IVdmProject getVdmProject()
160:         {
161:                 return (IVdmProject) getProject().getAdapter(IVdmProject.class);
162:         }
163:
164: }