| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.qedeq.kernel.bo.service; |
| 17 |
|
|
| 18 |
|
import java.io.File; |
| 19 |
|
import java.io.FileFilter; |
| 20 |
|
import java.io.FileNotFoundException; |
| 21 |
|
import java.io.FileOutputStream; |
| 22 |
|
import java.io.IOException; |
| 23 |
|
import java.io.InputStream; |
| 24 |
|
import java.io.Reader; |
| 25 |
|
import java.io.UnsupportedEncodingException; |
| 26 |
|
import java.lang.reflect.InvocationTargetException; |
| 27 |
|
import java.net.HttpURLConnection; |
| 28 |
|
import java.net.MalformedURLException; |
| 29 |
|
import java.net.URL; |
| 30 |
|
import java.net.URLConnection; |
| 31 |
|
import java.net.URLEncoder; |
| 32 |
|
import java.util.ArrayList; |
| 33 |
|
import java.util.List; |
| 34 |
|
import java.util.Map; |
| 35 |
|
|
| 36 |
|
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; |
| 37 |
|
import org.apache.commons.httpclient.HttpClient; |
| 38 |
|
import org.apache.commons.httpclient.HttpStatus; |
| 39 |
|
import org.apache.commons.httpclient.methods.GetMethod; |
| 40 |
|
import org.apache.commons.httpclient.params.HttpMethodParams; |
| 41 |
|
import org.qedeq.base.io.IoUtility; |
| 42 |
|
import org.qedeq.base.io.SourceArea; |
| 43 |
|
import org.qedeq.base.io.SourcePosition; |
| 44 |
|
import org.qedeq.base.io.TextInput; |
| 45 |
|
import org.qedeq.base.trace.Trace; |
| 46 |
|
import org.qedeq.base.utility.StringUtility; |
| 47 |
|
import org.qedeq.base.utility.YodaUtility; |
| 48 |
|
import org.qedeq.kernel.base.module.Qedeq; |
| 49 |
|
import org.qedeq.kernel.base.module.Specification; |
| 50 |
|
import org.qedeq.kernel.bo.QedeqBo; |
| 51 |
|
import org.qedeq.kernel.bo.context.KernelContext; |
| 52 |
|
import org.qedeq.kernel.bo.context.KernelProperties; |
| 53 |
|
import org.qedeq.kernel.bo.context.KernelServices; |
| 54 |
|
import org.qedeq.kernel.bo.log.QedeqLog; |
| 55 |
|
import org.qedeq.kernel.bo.module.InternalKernelServices; |
| 56 |
|
import org.qedeq.kernel.bo.module.KernelQedeqBo; |
| 57 |
|
import org.qedeq.kernel.bo.module.QedeqFileDao; |
| 58 |
|
import org.qedeq.kernel.common.DefaultModuleAddress; |
| 59 |
|
import org.qedeq.kernel.common.DefaultSourceFileExceptionList; |
| 60 |
|
import org.qedeq.kernel.common.LoadingState; |
| 61 |
|
import org.qedeq.kernel.common.ModuleAddress; |
| 62 |
|
import org.qedeq.kernel.common.ModuleDataException; |
| 63 |
|
import org.qedeq.kernel.common.Plugin; |
| 64 |
|
import org.qedeq.kernel.common.SourceFileException; |
| 65 |
|
import org.qedeq.kernel.common.SourceFileExceptionList; |
| 66 |
|
import org.qedeq.kernel.dto.module.QedeqVo; |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
@author |
| 73 |
|
|
|
|
|
| 35.6% |
Uncovered Elements: 378 (587) |
Complexity: 140 |
Complexity Density: 0.32 |
|
| 74 |
|
public class DefaultInternalKernelServices implements KernelServices, InternalKernelServices, Plugin { |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
private static final Class CLASS = DefaultInternalKernelServices.class; |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
private static final Object MONITOR = new Object(); |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
private volatile int processCounter = 0; |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
private final KernelQedeqBoStorage modules; |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
private final KernelProperties kernel; |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
private final QedeqFileDao qedeqFileDao; |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
private final PluginManager pluginManager; |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
private boolean validate = true; |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
@param |
| 104 |
|
@param |
| 105 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 106 |
54
|
public DefaultInternalKernelServices(final KernelProperties kernel, final QedeqFileDao loader) {... |
| 107 |
54
|
modules = new KernelQedeqBoStorage(); |
| 108 |
54
|
pluginManager = new PluginManager(); |
| 109 |
54
|
pluginManager.addPlugin("org.qedeq.kernel.bo.service.latex.Qedeq2LatexPlugin"); |
| 110 |
54
|
this.kernel = kernel; |
| 111 |
54
|
this.qedeqFileDao = loader; |
| 112 |
54
|
loader.setServices(this); |
| 113 |
|
} |
| 114 |
|
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 115 |
54
|
public void startupServices() {... |
| 116 |
54
|
if (kernel.getConfig().isAutoReloadLastSessionChecked()) { |
| 117 |
0
|
autoReloadLastSessionChecked(); |
| 118 |
|
} |
| 119 |
|
} |
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 124 |
0
|
public void autoReloadLastSessionChecked() {... |
| 125 |
0
|
if (kernel.getConfig().isAutoReloadLastSessionChecked()) { |
| 126 |
0
|
final Thread thread = new Thread() { |
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 127 |
0
|
public void run() {... |
| 128 |
0
|
final String method = "autoReloadLastSessionChecked.thread.run()"; |
| 129 |
0
|
try { |
| 130 |
0
|
Trace.begin(CLASS, this, method); |
| 131 |
0
|
QedeqLog.getInstance().logMessage( |
| 132 |
|
"Trying to load previously successfully loaded modules."); |
| 133 |
0
|
final int number = kernel.getConfig().getPreviouslyCheckedModules().length; |
| 134 |
0
|
if (loadPreviouslySuccessfullyLoadedModules()) { |
| 135 |
0
|
QedeqLog.getInstance().logMessage( |
| 136 |
|
"Loading of " + number + " previously successfully loaded module" |
| 137 |
0
|
+ (number != 1 ? "s" : "") + " successfully done."); |
| 138 |
|
} else { |
| 139 |
0
|
QedeqLog.getInstance().logMessage( |
| 140 |
|
"Loading of all previously successfully checked modules failed. " |
| 141 |
0
|
+ number + " module" + (number != 1 ? "s" : "") |
| 142 |
|
+ " were tried."); |
| 143 |
|
} |
| 144 |
|
} catch (Exception e) { |
| 145 |
0
|
Trace.trace(CLASS, this, method, e); |
| 146 |
|
} finally { |
| 147 |
0
|
Trace.end(CLASS, this, method); |
| 148 |
|
} |
| 149 |
|
} |
| 150 |
|
}; |
| 151 |
0
|
thread.setDaemon(true); |
| 152 |
0
|
thread.start(); |
| 153 |
|
} |
| 154 |
|
} |
| 155 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 156 |
0
|
public void removeAllModules() {... |
| 157 |
0
|
do { |
| 158 |
0
|
synchronized (this) { |
| 159 |
0
|
if (processCounter == 0) { |
| 160 |
0
|
getModules().removeAllModules(); |
| 161 |
0
|
return; |
| 162 |
|
} |
| 163 |
|
} |
| 164 |
|
|
| 165 |
0
|
synchronized (MONITOR) { |
| 166 |
0
|
try { |
| 167 |
0
|
MONITOR.wait(10000); |
| 168 |
|
} catch (InterruptedException e) { |
| 169 |
|
} |
| 170 |
|
} |
| 171 |
|
} while (true); |
| 172 |
|
|
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
@param |
| 179 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 180 |
0
|
public void removeModule(final ModuleAddress address) {... |
| 181 |
0
|
final QedeqBo prop = getQedeqBo(address); |
| 182 |
0
|
if (prop != null) { |
| 183 |
0
|
removeModule(getModules().getKernelQedeqBo(this, address)); |
| 184 |
0
|
if (validate) { |
| 185 |
0
|
modules.validateDependencies(); |
| 186 |
|
} |
| 187 |
|
} |
| 188 |
|
} |
| 189 |
|
|
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
@param |
| 195 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 196 |
0
|
private void removeModule(final DefaultKernelQedeqBo prop) {... |
| 197 |
0
|
do { |
| 198 |
0
|
synchronized (this) { |
| 199 |
0
|
if (processCounter == 0) { |
| 200 |
|
|
| 201 |
|
|
| 202 |
|
|
| 203 |
|
|
| 204 |
0
|
prop.delete(); |
| 205 |
0
|
getModules().removeModule(prop); |
| 206 |
0
|
return; |
| 207 |
|
} |
| 208 |
|
} |
| 209 |
|
|
| 210 |
0
|
synchronized (MONITOR) { |
| 211 |
0
|
try { |
| 212 |
0
|
MONITOR.wait(10000); |
| 213 |
|
} catch (InterruptedException e) { |
| 214 |
|
} |
| 215 |
|
} |
| 216 |
|
} while (true); |
| 217 |
|
|
| 218 |
|
} |
| 219 |
|
|
| 220 |
|
|
| 221 |
|
|
| 222 |
|
|
| 223 |
|
@throws |
| 224 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 225 |
0
|
public void clearLocalBuffer() throws IOException {... |
| 226 |
0
|
removeAllModules(); |
| 227 |
0
|
final File bufferDir = getBufferDirectory().getCanonicalFile(); |
| 228 |
0
|
if (bufferDir.exists() && !IoUtility.deleteDir(bufferDir, new FileFilter() { |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 229 |
0
|
public boolean accept(final File pathname) {... |
| 230 |
0
|
return pathname.getName().endsWith(".xml"); |
| 231 |
|
} |
| 232 |
|
})) { |
| 233 |
0
|
throw new IOException("buffer could not be deleted: " + bufferDir); |
| 234 |
|
} |
| 235 |
|
} |
| 236 |
|
|
|
|
|
| 85.2% |
Uncovered Elements: 4 (27) |
Complexity: 6 |
Complexity Density: 0.26 |
|
| 237 |
160
|
public QedeqBo loadModule(final ModuleAddress address) throws SourceFileExceptionList {... |
| 238 |
160
|
final String method = "loadModule(ModuleAddress)"; |
| 239 |
160
|
processInc(); |
| 240 |
160
|
final DefaultKernelQedeqBo prop = getModules().getKernelQedeqBo(this, address); |
| 241 |
160
|
try { |
| 242 |
160
|
synchronized (prop) { |
| 243 |
160
|
if (prop.isLoaded()) { |
| 244 |
98
|
return prop; |
| 245 |
|
} |
| 246 |
62
|
QedeqLog.getInstance().logRequest("Load module \"" + IoUtility.easyUrl(address.getUrl()) + "\""); |
| 247 |
62
|
if (prop.getModuleAddress().isFileAddress()) { |
| 248 |
52
|
loadLocalModule(prop); |
| 249 |
|
} else { |
| 250 |
|
|
| 251 |
10
|
try { |
| 252 |
10
|
getCanonicalReadableFile(prop); |
| 253 |
|
} catch (ModuleFileNotFoundException e) { |
| 254 |
|
|
| 255 |
0
|
saveQedeqFromWebToBuffer(prop); |
| 256 |
|
} |
| 257 |
10
|
loadBufferedModule(prop); |
| 258 |
|
} |
| 259 |
56
|
QedeqLog.getInstance().logSuccessfulReply( |
| 260 |
|
"Module \"" + prop.getModuleAddress().getFileName() |
| 261 |
|
+ "\" was successfully loaded."); |
| 262 |
|
} |
| 263 |
|
} catch (SourceFileExceptionList e) { |
| 264 |
6
|
Trace.trace(CLASS, this, method, e); |
| 265 |
6
|
QedeqLog.getInstance().logFailureState("Loading of module failed!", IoUtility.easyUrl(address.getUrl()), |
| 266 |
|
e.toString()); |
| 267 |
6
|
throw e; |
| 268 |
|
} catch (final RuntimeException e) { |
| 269 |
0
|
Trace.fatal(CLASS, this, method, "unexpected problem", e); |
| 270 |
0
|
QedeqLog.getInstance().logFailureReply("Loading failed", e.getMessage()); |
| 271 |
0
|
throw e; |
| 272 |
|
} finally { |
| 273 |
160
|
processDec(); |
| 274 |
|
} |
| 275 |
56
|
return prop; |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
|
| 279 |
|
|
| 280 |
|
|
| 281 |
|
@param |
| 282 |
|
@throws |
| 283 |
|
|
|
|
|
| 64.3% |
Uncovered Elements: 5 (14) |
Complexity: 3 |
Complexity Density: 0.21 |
|
| 284 |
10
|
private void loadBufferedModule(final DefaultKernelQedeqBo prop)... |
| 285 |
|
throws SourceFileExceptionList { |
| 286 |
10
|
prop.setLoadingProgressState(LoadingState.STATE_LOADING_FROM_BUFFER); |
| 287 |
10
|
final File localFile; |
| 288 |
10
|
try { |
| 289 |
10
|
localFile = getCanonicalReadableFile(prop); |
| 290 |
|
} catch (ModuleFileNotFoundException e) { |
| 291 |
0
|
final SourceFileExceptionList sfl = createSourceFileExceptionList(prop.getUrl(), e); |
| 292 |
0
|
prop.setLoadingFailureState(LoadingState.STATE_LOADING_FROM_BUFFER_FAILED, sfl); |
| 293 |
0
|
throw sfl; |
| 294 |
|
} |
| 295 |
|
|
| 296 |
10
|
prop.setQedeqFileDao(getQedeqFileDao()); |
| 297 |
10
|
final Qedeq qedeq; |
| 298 |
10
|
try { |
| 299 |
10
|
qedeq = getQedeqFileDao().loadQedeq(prop, localFile); |
| 300 |
|
} catch (SourceFileExceptionList sfl) { |
| 301 |
0
|
prop.setLoadingFailureState(LoadingState.STATE_LOADING_FROM_BUFFER_FAILED, sfl); |
| 302 |
0
|
throw sfl; |
| 303 |
|
} |
| 304 |
10
|
setCopiedQedeq(prop, qedeq); |
| 305 |
|
} |
| 306 |
|
|
| 307 |
|
|
| 308 |
|
|
| 309 |
|
|
| 310 |
|
@param |
| 311 |
|
@throws |
| 312 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0.21 |
|
| 313 |
140
|
private void loadLocalModule(final DefaultKernelQedeqBo prop) throws SourceFileExceptionList {... |
| 314 |
140
|
prop.setLoadingProgressState(LoadingState.STATE_LOADING_FROM_LOCAL_FILE); |
| 315 |
140
|
final File localFile; |
| 316 |
140
|
try { |
| 317 |
140
|
localFile = getCanonicalReadableFile(prop); |
| 318 |
|
} catch (ModuleFileNotFoundException e) { |
| 319 |
3
|
final SourceFileExceptionList sfl = createSourceFileExceptionList(prop.getUrl(), e); |
| 320 |
3
|
prop.setLoadingFailureState(LoadingState.STATE_LOADING_FROM_LOCAL_FILE_FAILED, sfl); |
| 321 |
3
|
throw sfl; |
| 322 |
|
} |
| 323 |
137
|
prop.setQedeqFileDao(getQedeqFileDao()); |
| 324 |
|
|
| 325 |
137
|
final Qedeq qedeq; |
| 326 |
137
|
try { |
| 327 |
137
|
qedeq = getQedeqFileDao().loadQedeq(prop, localFile); |
| 328 |
|
} catch (SourceFileExceptionList sfl) { |
| 329 |
4
|
prop.setLoadingFailureState(LoadingState.STATE_LOADING_FROM_LOCAL_FILE_FAILED, sfl); |
| 330 |
4
|
throw sfl; |
| 331 |
|
} |
| 332 |
133
|
setCopiedQedeq(prop, qedeq); |
| 333 |
|
} |
| 334 |
|
|
|
|
|
| 73.3% |
Uncovered Elements: 4 (15) |
Complexity: 3 |
Complexity Density: 0.2 |
|
| 335 |
143
|
private void setCopiedQedeq(final DefaultKernelQedeqBo prop, final Qedeq qedeq)... |
| 336 |
|
throws SourceFileExceptionList { |
| 337 |
143
|
final String method = "setCopiedQedeq(DefaultKernelQedeqBo, Qedeq)"; |
| 338 |
143
|
prop.setLoadingProgressState(LoadingState.STATE_LOADING_INTO_MEMORY); |
| 339 |
143
|
QedeqVo vo = null; |
| 340 |
143
|
try { |
| 341 |
143
|
vo = QedeqVoBuilder.createQedeq(prop.getModuleAddress(), qedeq); |
| 342 |
|
} catch (ModuleDataException e) { |
| 343 |
0
|
Trace.trace(CLASS, this, method, e); |
| 344 |
0
|
final SourceFileExceptionList xl = prop.createSourceFileExceptionList(this, e, qedeq); |
| 345 |
0
|
prop.setLoadingFailureState(LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, xl); |
| 346 |
0
|
throw xl; |
| 347 |
|
} |
| 348 |
143
|
prop.setQedeqVo(vo); |
| 349 |
143
|
ModuleLabelsCreator moduleNodesCreator = new ModuleLabelsCreator(this, prop); |
| 350 |
143
|
try { |
| 351 |
143
|
prop.setLoaded(vo, moduleNodesCreator.createLabels()); |
| 352 |
|
} catch (SourceFileExceptionList sfl) { |
| 353 |
2
|
prop.setLoadingFailureState(LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, sfl); |
| 354 |
2
|
throw sfl; |
| 355 |
|
} |
| 356 |
|
} |
| 357 |
|
|
| 358 |
|
|
| 359 |
|
|
| 360 |
|
|
| 361 |
|
|
| 362 |
|
@param |
| 363 |
|
@return |
| 364 |
|
@throws |
| 365 |
|
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 366 |
160
|
private File getCanonicalReadableFile(final QedeqBo prop) throws ModuleFileNotFoundException {... |
| 367 |
160
|
final String method = "getCanonicalReadableFile(File)"; |
| 368 |
160
|
final File localFile = getLocalFilePath(prop.getModuleAddress()); |
| 369 |
160
|
final File file; |
| 370 |
160
|
try { |
| 371 |
160
|
file = localFile.getCanonicalFile(); |
| 372 |
|
} catch (IOException e) { |
| 373 |
0
|
Trace.trace(CLASS, this, method, e); |
| 374 |
0
|
throw new ModuleFileNotFoundException("file path not correct: " + localFile); |
| 375 |
|
} |
| 376 |
160
|
if (!file.canRead()) { |
| 377 |
3
|
Trace.trace(CLASS, this, method, "file not readable=" + file); |
| 378 |
3
|
throw new ModuleFileNotFoundException("file not readable: " + file); |
| 379 |
|
} |
| 380 |
157
|
return file; |
| 381 |
|
} |
| 382 |
|
|
| 383 |
|
|
| 384 |
|
|
| 385 |
|
|
| 386 |
|
@param |
| 387 |
|
@param |
| 388 |
|
@return |
| 389 |
|
@throws |
| 390 |
|
|
|
|
|
| 67.4% |
Uncovered Elements: 14 (43) |
Complexity: 9 |
Complexity Density: 0.26 |
|
| 391 |
161
|
public KernelQedeqBo loadModule(final ModuleAddress parent, final Specification spec)... |
| 392 |
|
throws SourceFileExceptionList { |
| 393 |
|
|
| 394 |
161
|
final String method = "loadModule(Module, Specification)"; |
| 395 |
161
|
Trace.begin(CLASS, this, method); |
| 396 |
161
|
Trace.trace(CLASS, this, method, spec); |
| 397 |
161
|
processInc(); |
| 398 |
161
|
DefaultKernelQedeqBo prop = null; |
| 399 |
161
|
try { |
| 400 |
161
|
final ModuleAddress[] modulePaths; |
| 401 |
161
|
try { |
| 402 |
161
|
modulePaths = parent.getModulePaths(spec); |
| 403 |
|
} catch (IOException e) { |
| 404 |
0
|
Trace.trace(CLASS, this, method, e); |
| 405 |
0
|
throw createSourceFileExceptionList(parent.getUrl(), e); |
| 406 |
|
} |
| 407 |
|
|
| 408 |
|
|
| 409 |
161
|
for (int i = 0; i < modulePaths.length; i++) { |
| 410 |
161
|
prop = getModules().getKernelQedeqBo(this, modulePaths[i]); |
| 411 |
161
|
Trace.trace(CLASS, this, method, "synchronizing at prop=" + prop); |
| 412 |
161
|
synchronized (prop) { |
| 413 |
161
|
if (prop.isLoaded()) { |
| 414 |
73
|
return (prop); |
| 415 |
|
} |
| 416 |
88
|
try { |
| 417 |
88
|
if (prop.getModuleAddress().isFileAddress()) { |
| 418 |
88
|
loadLocalModule(prop); |
| 419 |
|
} else { |
| 420 |
|
|
| 421 |
0
|
try { |
| 422 |
0
|
getCanonicalReadableFile(prop); |
| 423 |
|
} catch (ModuleFileNotFoundException e) { |
| 424 |
|
|
| 425 |
0
|
saveQedeqFromWebToBuffer(prop); |
| 426 |
|
} |
| 427 |
0
|
loadBufferedModule(prop); |
| 428 |
|
} |
| 429 |
|
|
| 430 |
85
|
return prop; |
| 431 |
|
} catch (SourceFileExceptionList e) { |
| 432 |
3
|
Trace.trace(CLASS, this, method, e); |
| 433 |
3
|
if (i + 1 < modulePaths.length) { |
| 434 |
0
|
QedeqLog.getInstance().logMessage("trying alternate path"); |
| 435 |
|
|
| 436 |
|
} else { |
| 437 |
|
|
| 438 |
3
|
throw e; |
| 439 |
|
} |
| 440 |
|
} |
| 441 |
|
} |
| 442 |
|
} |
| 443 |
0
|
return prop; |
| 444 |
|
} catch (final RuntimeException e) { |
| 445 |
0
|
Trace.fatal(CLASS, this, method, "unexpected problem", e); |
| 446 |
0
|
QedeqLog.getInstance().logFailureReply("Loading failed", e.getMessage()); |
| 447 |
0
|
throw e; |
| 448 |
|
} finally { |
| 449 |
161
|
processDec(); |
| 450 |
161
|
Trace.end(CLASS, this, method); |
| 451 |
|
} |
| 452 |
|
} |
| 453 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 454 |
54
|
public ModuleAddress[] getAllLoadedModules() {... |
| 455 |
54
|
return getModules().getAllLoadedModules(); |
| 456 |
|
} |
| 457 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 458 |
70
|
public void loadRequiredModules(final ModuleAddress address) throws SourceFileExceptionList {... |
| 459 |
70
|
final DefaultKernelQedeqBo prop = (DefaultKernelQedeqBo) loadModule(address); |
| 460 |
70
|
if (prop.hasBasicFailures()) { |
| 461 |
2
|
throw prop.getErrors(); |
| 462 |
|
} |
| 463 |
68
|
LoadRequiredModules.loadRequired(this, prop); |
| 464 |
|
} |
| 465 |
|
|
| 466 |
|
|
| 467 |
|
|
| 468 |
|
|
| 469 |
|
@return |
| 470 |
|
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.31 |
|
| 471 |
0
|
public boolean loadPreviouslySuccessfullyLoadedModules() {... |
| 472 |
0
|
processInc(); |
| 473 |
0
|
try { |
| 474 |
0
|
final String[] list = kernel.getConfig().getPreviouslyCheckedModules(); |
| 475 |
0
|
boolean errors = false; |
| 476 |
0
|
for (int i = 0; i < list.length; i++) { |
| 477 |
0
|
try { |
| 478 |
0
|
final ModuleAddress address = getModuleAddress(list[i]); |
| 479 |
0
|
final QedeqBo prop = loadModule(address); |
| 480 |
0
|
if (prop.hasErrors()) { |
| 481 |
0
|
errors = true; |
| 482 |
|
} |
| 483 |
|
} catch (IOException e) { |
| 484 |
0
|
Trace.fatal(CLASS, this, "loadPreviouslySuccessfullyLoadedModules", |
| 485 |
|
"internal error: " + "saved URLs are malformed", e); |
| 486 |
0
|
errors = true; |
| 487 |
|
} catch (SourceFileExceptionList e) { |
| 488 |
0
|
Trace.fatal(CLASS, this, "loadPreviouslySuccessfullyLoadedModules", |
| 489 |
|
"loading error: " + "module could not be loaded", e); |
| 490 |
0
|
errors = true; |
| 491 |
|
} |
| 492 |
|
} |
| 493 |
0
|
return !errors; |
| 494 |
|
} finally { |
| 495 |
0
|
processDec(); |
| 496 |
|
} |
| 497 |
|
} |
| 498 |
|
|
| 499 |
|
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0.29 |
|
| 500 |
0
|
public boolean loadAllModulesFromQedeq() {... |
| 501 |
0
|
processInc(); |
| 502 |
0
|
try { |
| 503 |
0
|
final String prefix = "http://www.qedeq.org/" + kernel.getKernelVersionDirectory() + "/"; |
| 504 |
0
|
final String[] list = new String[] { |
| 505 |
|
prefix + "doc/math/qedeq_logic_v1.xml", |
| 506 |
|
prefix + "doc/math/qedeq_set_theory_v1.xml", |
| 507 |
|
prefix + "doc/project/qedeq_basic_concept.xml", |
| 508 |
|
prefix + "doc/project/qedeq_logic_language.xml", |
| 509 |
|
prefix + "sample/qedeq_sample1.xml", prefix + "sample/qedeq_error_sample_00.xml", |
| 510 |
|
prefix + "sample/qedeq_error_sample_01.xml", |
| 511 |
|
prefix + "sample/qedeq_error_sample_02.xml", |
| 512 |
|
prefix + "sample/qedeq_error_sample_03.xml", |
| 513 |
|
prefix + "sample/qedeq_error_sample_04.xml", |
| 514 |
|
prefix + "sample/qedeq_sample2_error.xml", |
| 515 |
|
prefix + "sample/qedeq_sample3_error.xml", |
| 516 |
|
prefix + "sample/qedeq_sample4_error.xml", |
| 517 |
|
prefix + "sample/qedeq_sample5_error.xml", |
| 518 |
|
prefix + "sample/qedeq_sample6_error.xml", |
| 519 |
|
prefix + "sample/qedeq_sample7_error.xml", |
| 520 |
|
prefix + "sample/qedeq_sample8_error.xml", }; |
| 521 |
0
|
boolean errors = false; |
| 522 |
0
|
for (int i = 0; i < list.length; i++) { |
| 523 |
0
|
try { |
| 524 |
0
|
final ModuleAddress address = getModuleAddress(list[i]); |
| 525 |
0
|
final QedeqBo prop = loadModule(address); |
| 526 |
0
|
if (prop.hasErrors()) { |
| 527 |
0
|
errors = true; |
| 528 |
|
} |
| 529 |
|
} catch (IOException e) { |
| 530 |
0
|
Trace.fatal(CLASS, this, "loadPreviouslySuccessfullyLoadedModules", |
| 531 |
|
"internal error: " + "saved URLs are malformed", e); |
| 532 |
0
|
errors = true; |
| 533 |
|
} catch (SourceFileExceptionList e) { |
| 534 |
0
|
Trace.fatal(CLASS, this, "loadPreviouslySuccessfullyLoadedModules", |
| 535 |
|
"loading error: " + "module could not be loaded", e); |
| 536 |
0
|
errors = true; |
| 537 |
|
} |
| 538 |
|
} |
| 539 |
0
|
return !errors; |
| 540 |
|
} finally { |
| 541 |
0
|
processDec(); |
| 542 |
|
} |
| 543 |
|
} |
| 544 |
|
|
| 545 |
|
|
| 546 |
|
|
| 547 |
|
|
| 548 |
|
@param |
| 549 |
|
@throws |
| 550 |
|
|
|
|
|
| 0% |
Uncovered Elements: 107 (107) |
Complexity: 23 |
Complexity Density: 0.31 |
|
| 551 |
0
|
private void saveQedeqFromWebToBuffer(final DefaultKernelQedeqBo prop)... |
| 552 |
|
throws SourceFileExceptionList { |
| 553 |
0
|
final String method = "saveQedeqFromWebToBuffer(DefaultKernelQedeqBo)"; |
| 554 |
0
|
Trace.begin(CLASS, this, method); |
| 555 |
|
|
| 556 |
|
|
| 557 |
|
|
| 558 |
0
|
if (!KernelContext.getInstance().isSetConnectionTimeOutSupported() |
| 559 |
|
&& !IoUtility.isWebStarted()) { |
| 560 |
0
|
saveQedeqFromWebToBufferApache(prop); |
| 561 |
0
|
Trace.end(CLASS, this, method); |
| 562 |
0
|
return; |
| 563 |
|
} |
| 564 |
|
|
| 565 |
|
|
| 566 |
0
|
if (!IoUtility.isWebStarted()) { |
| 567 |
0
|
if (kernel.getConfig().getHttpProxyHost() != null) { |
| 568 |
0
|
System.setProperty("http.proxyHost", kernel.getConfig().getHttpProxyHost()); |
| 569 |
|
} |
| 570 |
0
|
if (kernel.getConfig().getHttpProxyPort() != null) { |
| 571 |
0
|
System.setProperty("http.proxyPort", kernel.getConfig().getHttpProxyPort()); |
| 572 |
|
} |
| 573 |
0
|
if (kernel.getConfig().getHttpNonProxyHosts() != null) { |
| 574 |
0
|
System.setProperty("http.nonProxyHosts", kernel.getConfig().getHttpNonProxyHosts()); |
| 575 |
|
} |
| 576 |
|
} |
| 577 |
|
|
| 578 |
0
|
if (prop.getModuleAddress().isFileAddress()) { |
| 579 |
0
|
Trace.fatal(CLASS, this, method, "tried to make a local copy for a local module", null); |
| 580 |
0
|
Trace.end(CLASS, this, method); |
| 581 |
0
|
return; |
| 582 |
|
} |
| 583 |
0
|
prop.setLoadingProgressState(LoadingState.STATE_LOADING_FROM_WEB); |
| 584 |
|
|
| 585 |
0
|
FileOutputStream out = null; |
| 586 |
0
|
InputStream in = null; |
| 587 |
0
|
final File f = getLocalFilePath(prop.getModuleAddress()); |
| 588 |
0
|
try { |
| 589 |
0
|
final URLConnection connection = new URL(prop.getUrl()).openConnection(); |
| 590 |
|
|
| 591 |
0
|
if (connection instanceof HttpURLConnection) { |
| 592 |
0
|
final HttpURLConnection httpConnection = (HttpURLConnection) connection; |
| 593 |
|
|
| 594 |
0
|
if (KernelContext.getInstance().isSetConnectionTimeOutSupported()) { |
| 595 |
0
|
try { |
| 596 |
0
|
YodaUtility.executeMethod(httpConnection, "setConnectTimeout", |
| 597 |
|
new Class[] {Integer.TYPE}, new Object[] {new Integer( |
| 598 |
|
kernel.getConfig().getConnectTimeout())}); |
| 599 |
|
} catch (NoSuchMethodException e) { |
| 600 |
0
|
Trace.fatal(CLASS, this, method, |
| 601 |
|
"URLConnection.setConnectTimeout was previously found", e); |
| 602 |
|
} catch (InvocationTargetException e) { |
| 603 |
0
|
Trace.fatal(CLASS, this, method, |
| 604 |
|
"URLConnection.setConnectTimeout throwed an error", e); |
| 605 |
|
} |
| 606 |
|
} |
| 607 |
|
|
| 608 |
0
|
if (KernelContext.getInstance().isSetReadTimeoutSupported()) { |
| 609 |
0
|
try { |
| 610 |
0
|
YodaUtility.executeMethod(httpConnection, "setReadTimeout", |
| 611 |
|
new Class[] {Integer.TYPE}, new Object[] {new Integer( |
| 612 |
|
kernel.getConfig().getReadTimeout())}); |
| 613 |
|
} catch (NoSuchMethodException e) { |
| 614 |
0
|
Trace.fatal(CLASS, this, method, |
| 615 |
|
"URLConnection.setReadTimeout was previously found", e); |
| 616 |
|
} catch (InvocationTargetException e) { |
| 617 |
0
|
Trace.fatal(CLASS, this, method, |
| 618 |
|
"URLConnection.setReadTimeout throwed an error", e); |
| 619 |
|
} |
| 620 |
|
} |
| 621 |
0
|
int responseCode = httpConnection.getResponseCode(); |
| 622 |
0
|
if (responseCode == 200) { |
| 623 |
0
|
in = httpConnection.getInputStream(); |
| 624 |
|
} else { |
| 625 |
0
|
in = httpConnection.getErrorStream(); |
| 626 |
0
|
final String errorText = IoUtility.loadStreamWithoutException(in, 1000); |
| 627 |
0
|
throw new IOException("Response code from HTTP server was " + responseCode |
| 628 |
0
|
+ (errorText.length() > 0 ? "\nResponse text from HTTP server was:\n" |
| 629 |
|
+ errorText : "")); |
| 630 |
|
} |
| 631 |
|
} else { |
| 632 |
0
|
Trace.paramInfo(CLASS, this, method, "connection.getClass", connection.getClass() |
| 633 |
|
.toString()); |
| 634 |
0
|
in = connection.getInputStream(); |
| 635 |
|
} |
| 636 |
|
|
| 637 |
0
|
if (!prop.getUrl().equals(connection.getURL().toString())) { |
| 638 |
0
|
throw new FileNotFoundException("\"" + prop.getUrl() + "\" was substituted by " |
| 639 |
|
+ "\"" + connection.getURL() + "\" from server"); |
| 640 |
|
} |
| 641 |
0
|
final int maximum = connection.getContentLength(); |
| 642 |
0
|
IoUtility.createNecessaryDirectories(f); |
| 643 |
0
|
out = new FileOutputStream(f); |
| 644 |
0
|
final byte[] buffer = new byte[4096]; |
| 645 |
|