Package: VdmTools

VdmTools

nameinstructionbranchcomplexitylinemethod
VdmTools()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createProject(Shell, IVdmProject, List)
M: 243 C: 0
0%
M: 15 C: 0
0%
M: 10 C: 0
0%
M: 45 C: 0
0%
M: 1 C: 0
0%
getFilePath(File, File)
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%
getVdmToolsPath(Shell, IVdmProject)
M: 53 C: 0
0%
M: 10 C: 0
0%
M: 7 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
isMacPlatform()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isWindowsPlatform()
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%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.plugins.csk
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.plugins.csk.internal;
23:
24: import java.io.File;
25: import java.io.IOException;
26: import java.util.ArrayList;
27: import java.util.List;
28:
29: import org.eclipse.core.resources.IProject;
30: import org.eclipse.core.runtime.Platform;
31: import org.eclipse.jface.dialogs.MessageDialog;
32: import org.eclipse.jface.preference.IPreferenceStore;
33: import org.eclipse.swt.widgets.Shell;
34: import org.overture.ide.core.resources.IVdmProject;
35: import org.overture.ide.plugins.csk.Activator;
36: import org.overture.ide.plugins.csk.ICskConstants;
37: import org.overture.ide.ui.utility.PluginFolderInclude;
38:
39: public class VdmTools
40: {
41:         public static final String HEADER1 = "b";
42:         public static final String HEADER2 = ",k13,ProjectFilePPf3,f";
43:         public static final String HEADER2_SL = ",k11,ProjectFilef3,f";
44:
45:         public static final String HEADER_FILE = "e2,m4,filem";
46:
47:         final String VDM_TOOLS_PROJECT_OPT = "FormatVersion:2\n" + "DTC:1\n"
48:                         + "PRE:1\n" + "POST:1\n" + "INV:1\n" + "CONTEXT:0\n"
49:                         + "MAXINSTR:1000\n" + "PRIORITY:0\n"
50:                         + "PRIMARYALGORITHM:instruction_number_slice\n" + "TASKSWITCH:0\n"
51:                         + "MAXTIME:1000\n" + "TIMEFACTOR:1\n" + "STEPSIZE:100\n"
52:                         + "JITTERMODE:Early\n" + "DEFAULTCPUCAPACITY:1000000\n"
53:                         + "DEFAULTVCPUCAPACITY:INFINITE\n" + "LOGARGS:\n"
54:                         + "PRINT_FORMAT:1\n" + "DEF:pos\n" + "errlevel:1\n" + "SEP:1\n"
55:                         + "VDMSLMOD:0\n" + "INDEX:0\n" + "PrettyPrint_RTI:0\n"
56:                         + "CG_RTI:0\n" + "CG_CHECKPREPOST:1\n" + "C_flag:0\n"
57:                         + "JCG_SKEL:0\n" + "JCG_GENPREPOST:0\n" + "JCG_TYPES:0\n"
58:                         + "JCG_SMALLTYPES:0\n" + "JCG_LONGS:1\n" + "JCG_PACKAGE:\n"
59:                         + "JCG_CONCUR:0\n" + "JCG_CHECKPREPOST:0\n" + "JCG_VDMPREFIX:1\n"
60:                         + "JCG_INTERFACES:\n" + "Seed_nondetstmt:-1\n"
61:                         + "j2v_stubsOnly:0\n" + "j2v_transforms:0";
62:
63:         public void createProject(Shell shell, IVdmProject vdmProject,
64:                         List<File> files) throws IOException
65:         {
66:                 IProject project = (IProject) vdmProject.getAdapter(IProject.class);
67:                 File location = project.getLocation().toFile();
68:                 StringBuilder sb = new StringBuilder();
69:                 sb.append(HEADER1);
70:                 sb.append(files.size() + 3);
71:
72:•                switch (vdmProject.getDialect())
73:                 {
74:                         case VDM_PP:
75:                         case VDM_RT:
76:                                 sb.append(HEADER2);
77:                                 break;
78:                         case VDM_SL:
79:                                 sb.append(HEADER2_SL);
80:                                 break;
81:                         case CML:
82:                                 break;
83:                 }
84:
85:                 sb.append(files.size());
86:                 sb.append(",");
87:
88:•                for (File file : files)
89:                 {
90:                         String path = getFilePath(location, file);
91:                         sb.append(HEADER_FILE + path.length() + "," + path);
92:                 }
93:
94:                 File generated = vdmProject.getModelBuildPath().getOutput().getLocation().toFile();// new File(location,
95:                 // "generated");
96:                 generated.mkdirs();
97:                 
98:                 String projectFileName = vdmProject.getName().trim();
99:
100:                 PluginFolderInclude.writeFile(generated, projectFileName + ".prj", sb.toString());
101:                 VdmToolsOptions options = new VdmToolsOptions();
102:                 options.JCG_PACKAGE = (projectFileName.replaceAll(" ", "") + "." + "model").toLowerCase();
103:                 // options.DTC = vdmProject.hasDynamictypechecks();
104:                 // options.INV = vdmProject.hasInvchecks();
105:                 // options.POST = vdmProject.hasPostchecks();
106:                 // options.PRE = vdmProject.hasPrechecks();
107:
108:                 options.Save(generated, projectFileName);
109:
110: //                String projectFileName = projectFileName + ".prj";
111:                 List<String> commandArgs = new ArrayList<String>();
112:                 
113:                 File vdmToolsPath = getVdmToolsPath(shell, vdmProject);
114:
115:•                if (vdmToolsPath != null)
116:                 {
117:•                        if(isMacPlatform())
118:                         {
119:•                                switch (vdmProject.getDialect())
120:                                 {
121:                                         case VDM_PP:
122:                                                 commandArgs.add(vdmToolsPath + "/vppgde.app/Contents/MacOS/vppgde");
123:                                                 break;
124:                                         case VDM_RT:
125:                                                 commandArgs.add(vdmToolsPath+ "/vicegde.app/Contents/MacOS/vicegde");;
126:                                                 break;
127:                                         case VDM_SL:
128:                                                 commandArgs.add(vdmToolsPath + "/vdmgde.app/Contents/MacOS/vdmgde");;
129:                                                 break;
130:                                         case CML:
131:                                                 break;
132:                                 }
133:                                 commandArgs.add(projectFileName +".prj");
134:                         }
135:•                        else if(isWindowsPlatform())
136:                         {
137:                                 commandArgs.add(vdmToolsPath.getCanonicalPath());
138:                                 commandArgs.add(projectFileName+".prj");
139:                         }
140:                         else
141:                         {
142:                                 //Linux platform
143:                                 commandArgs.add(vdmToolsPath.getCanonicalPath());
144:                                 commandArgs.add(projectFileName+".prj");
145:                         }
146:                         ProcessBuilder pb = new ProcessBuilder(commandArgs);
147:                         pb.directory(generated);
148:                         pb.start();
149:                 }
150:         }
151:
152:         private String getFilePath(File location, File file)
153:         {
154:                 return file.getAbsolutePath();
155:         }
156:
157:         public static boolean isMacPlatform()
158:         {
159:                 return Platform.getOS().equalsIgnoreCase(Platform.OS_MACOSX);
160:         }
161:         
162:         public static boolean isWindowsPlatform()
163:         {
164:                 return System.getProperty("os.name").toLowerCase().contains("win");
165:         }
166:
167:         private static File getVdmToolsPath(Shell shell, IVdmProject project)
168:         {
169:                 IPreferenceStore store = Activator.getDefault().getPreferenceStore();
170:                 String path = null;
171:
172:•                switch (project.getDialect())
173:                 {
174:                         case VDM_PP:
175:                                 path = store.getString(ICskConstants.VPPGDE_PATH);
176:                                 break;
177:                         case VDM_RT:
178:                                 path = store.getString(ICskConstants.VRTGDE_PATH);
179:                                 break;
180:                         case VDM_SL:
181:                                 path = store.getString(ICskConstants.VSLGDE_PATH);
182:                                 break;
183:                         case CML:
184:                                 break;
185:                 }
186:
187:•                boolean valid = path.length() > 0;
188:
189:                 File pathfile = new File(path);
190:•                if (valid)
191:                 {
192:                         valid = pathfile.exists();
193:                 }
194:•                if (!valid)
195:                 {
196:                         MessageDialog.openError(shell, "VDMTools Error", "VDMTools path not valid");
197:                         path = null;
198:                 }
199:                 // Assert.isTrue(valid, "VDM Tools path is not valid");
200:                 return pathfile;
201:         }
202:
203:         
204: }