001package com.ganteater.ae; 002 003import java.awt.Color; 004import java.awt.Toolkit; 005import java.io.BufferedReader; 006import java.io.Console; 007import java.io.File; 008import java.io.FileInputStream; 009import java.io.FileOutputStream; 010import java.io.IOException; 011import java.io.InputStream; 012import java.io.InputStreamReader; 013import java.io.UnsupportedEncodingException; 014import java.lang.reflect.Method; 015import java.lang.reflect.Modifier; 016import java.net.Authenticator; 017import java.net.Inet4Address; 018import java.net.InetAddress; 019import java.net.NetworkInterface; 020import java.net.PasswordAuthentication; 021import java.net.SocketException; 022import java.net.URL; 023import java.nio.file.Files; 024import java.nio.file.NoSuchFileException; 025import java.nio.file.Path; 026import java.nio.file.Paths; 027import java.util.ArrayList; 028import java.util.Arrays; 029import java.util.Base64; 030import java.util.Enumeration; 031import java.util.HashMap; 032import java.util.HashSet; 033import java.util.Iterator; 034import java.util.LinkedHashMap; 035import java.util.List; 036import java.util.Locale; 037import java.util.Map; 038import java.util.Properties; 039import java.util.Set; 040import java.util.regex.Pattern; 041import java.util.stream.Stream; 042 043import org.apache.commons.collections.CollectionUtils; 044import org.apache.commons.collections.MapUtils; 045import org.apache.commons.io.FileUtils; 046import org.apache.commons.io.IOUtils; 047import org.apache.commons.lang.ArrayUtils; 048import org.apache.commons.lang.BooleanUtils; 049import org.apache.commons.lang.ObjectUtils; 050import org.apache.commons.lang.StringUtils; 051import org.apache.commons.lang.SystemUtils; 052import org.apache.log4j.PropertyConfigurator; 053import org.apache.maven.shared.invoker.DefaultInvocationRequest; 054import org.apache.maven.shared.invoker.DefaultInvoker; 055import org.apache.maven.shared.invoker.InvocationRequest; 056import org.apache.maven.shared.invoker.InvocationResult; 057import org.apache.maven.shared.invoker.Invoker; 058import org.apache.maven.shared.invoker.MavenInvocationException; 059 060import com.ganteater.ae.processor.BaseProcessor; 061import com.ganteater.ae.processor.MessageHandler; 062import com.ganteater.ae.processor.Processor; 063import com.ganteater.ae.processor.SpecialCommands; 064import com.ganteater.ae.util.AEUtils; 065import com.ganteater.ae.util.Encryptor; 066import com.ganteater.ae.util.xml.easyparser.EasyParser; 067import com.ganteater.ae.util.xml.easyparser.Node; 068 069public class AEWorkspace implements AEManager { 070 071 public static final String CONFIGURATION_TITLE = "Configuration"; 072 073 public static final String ENVIRONMENT_FILE_TITLE = "Environment file"; 074 075 public static final String MESSAGE_PASSWORD_REQUIRED = "This configuration requires encryption for user preferences data.\nEnter the encryption password: "; 076 077 public static final String CONFIG_SUFIX_PROP_NAME = ".config"; 078 079 private static ILogger log = new Logger("AEWorkspace"); 080 081 private static String fUser = System.getProperty("user.name"); 082 083 private static Properties fUserPreferences; 084 085 private long startTime = System.currentTimeMillis(); 086 087 private Node allConfigNode; 088 089 private Map<String, Object> fSystemVariables = new HashMap<>(); 090 091 private Node fConfigNode; 092 093 private Properties fTestsDescList = new Properties(); 094 095 protected boolean defaultMode; 096 097 private String fConfigurationName; 098 099 private Set<RecipeRunner> runners = new HashSet<RecipeRunner>(); 100 101 private File baseDir = SystemUtils.getUserDir(); 102 103 private static AEWorkspace instance; 104 105 private Set<Class<?>> operationsClasses; 106 107 private Map<String, OperationHolder> opsMethods = new HashMap<String, OperationHolder>(); 108 109 private Encryptor cryptoUtilAesGcm; 110 111 private List<Runnable> closeHooks = new ArrayList<>(); 112 113 private RecipesScanner recipesScaner; 114 115 public AEWorkspace() { 116 this(new File(System.getProperty("user.dir"))); 117 } 118 119 public AEWorkspace(File startDir) { 120 instance = this; 121 System.out.println("Start dir: " + startDir); 122 recipesScaner = new RecipesScanner(this, startDir); 123 } 124 125 public String loadConfiguration(String confName, boolean refreshTaskPath) { 126 getHomeConfigurationsDir().mkdirs(); 127 File homeConfiguration = new File(getHomeConfigurationsDir(), ConfigConstants.AE_CONFIG_XML); 128 129 if (homeConfiguration.exists()) { 130 System.out.println("User home configuration file: " + homeConfiguration.getAbsolutePath() + " - found"); 131 } 132 133 Node configNodes; 134 try { 135 configNodes = getConfiguration(); 136 137 String config = selectConfiguration(confName, configNodes, refreshTaskPath); 138 TemplateProcessor tp = new TemplateProcessor(fSystemVariables, fConfigNode, getStartDir()); 139 recipesScaner.loadTaskPath(fConfigNode, tp); 140 141 String password = System.getProperty("configEncriptKey"); 142 initUserPreferencesEncryption(password); 143 return config; 144 145 } catch (TaskCancelingException e) { 146 throw e; 147 148 } catch (Exception e) { 149 throw new ConfigurationException("Configuration loading failed.", e); 150 } 151 152 } 153 154 protected Node getConfiguration() throws IOException { 155 Node configuration = null; 156 File configFile = getConfigurationFile(); 157 158 if (configFile == null || !configFile.exists()) { 159 160 try (InputStream openStream = AEWorkspace.class.getResourceAsStream("/" + ConfigConstants.AE_CONFIG_XML)) { 161 if (openStream != null) { 162 String recipeXml = IOUtils.toString(openStream); 163 try { 164 configuration = new EasyParser().getObject(recipeXml); 165 } catch (Exception e) { 166 throw new IllegalArgumentException(recipeXml, null); 167 } 168 } else { 169 configFile = findAlternativeConfiguration(""); 170 } 171 } 172 } 173 174 if (configuration == null) { 175 if (configFile != null && configFile.exists()) { 176 this.baseDir = configFile.getParentFile(); 177 System.out.println(ENVIRONMENT_FILE_TITLE + ": " + configFile.getAbsolutePath()); 178 179 configuration = new EasyParser().getObject(configFile); 180 } else { 181 throw new ConfigurationException(ENVIRONMENT_FILE_TITLE + " (" + ConfigConstants.AE_CONFIG_XML 182 + ") must be defined in " + getHomeWorkingDir() + " or " + getStartDir() + "."); 183 } 184 } 185 186 return configuration; 187 } 188 189 protected File getConfigurationFile() { 190 File confFile; 191 loadCustomProperties(); 192 193 String theConfigurationFile = System.getProperty(ConfigConstants.AE_CONFIG_SYS_PROPERTY_NAME); 194 if (theConfigurationFile == null) { 195 confFile = new File(SystemUtils.getUserDir(), ConfigConstants.AE_CONFIG_XML); 196 if (!confFile.exists()) { 197 confFile = new File(getHomeWorkingDir(), ConfigConstants.AE_CONFIG_XML); 198 if (!confFile.exists()) { 199 confFile = new File(getStartDir(), ConfigConstants.AE_CONFIG_XML); 200 } 201 } 202 } else { 203 confFile = new File(theConfigurationFile); 204 } 205 206 if (!confFile.exists()) { 207 URL resource = AEWorkspace.class.getResource("/" + ConfigConstants.AE_CONFIG_XML); 208 if (resource == null) { 209 confFile = findAlternativeConfiguration(""); 210 } else { 211 confFile = new File(resource.toString()); 212 } 213 } 214 215 return confFile; 216 } 217 218 protected File findAlternativeConfiguration(String aeDir) { 219 File confFile = null; 220 File userDir = getBaseDir(); 221 List<String> confFiles = findAEconfigs(userDir); 222 223 if (!confFiles.isEmpty()) { 224 225 String confPropName = userDir.getPath() + CONFIG_SUFIX_PROP_NAME; 226 String defaultValue = AEWorkspace.getInstance().getDefaultUserConfiguration(confPropName, null); 227 228 String aeConfFileName = inputChoice("Projects", null, confFiles.toArray(new String[confFiles.size()]), 229 defaultValue, null, false); 230 231 AEWorkspace.getInstance().setDefaultUserConfiguration(confPropName, aeConfFileName); 232 233 File pomFile = getPomLocation(aeConfFileName, aeDir); 234 235 if (pomFile != null) { 236 System.err.println("[ERROR] For the configuration: " + aeConfFileName + " found pom.xml file: " 237 + pomFile + ". This Anteter version does not support ae:do, please run it manually."); 238 System.exit(1); 239 240 } else { 241 confFile = new File(aeConfFileName); 242 } 243 return confFile; 244 } 245 246 if (confFile == null) { 247 confFile = selectConfiguration(); 248 } 249 250 return confFile; 251 } 252 253 protected File selectConfiguration() { 254 File userDir = getBaseDir(); 255 String confPropName = userDir.getPath() + CONFIG_SUFIX_PROP_NAME; 256 String config = AEWorkspace.getInstance().getDefaultUserConfiguration(confPropName, ""); 257 258 config = inputValue(ENVIRONMENT_FILE_TITLE, null, config, null, null); 259 260 AEWorkspace.getInstance().setDefaultUserConfiguration(confPropName, config); 261 return new File(config); 262 } 263 264 public File getHomeWorkingDir() { 265 return new File(System.getProperty("user.home"), "anteater"); 266 } 267 268 private void configuration() { 269 if (fConfigNode != null) { 270 Node[] theLogNodes = fConfigNode.getNodes("Logger"); 271 if (!ArrayUtils.isEmpty(theLogNodes)) { 272 Node logNode = theLogNodes[theLogNodes.length - 1]; 273 initLogger(logNode); 274 } 275 } 276 277 final String username = (String) fSystemVariables.get("HTTP_USERNAME"); 278 final String password = (String) fSystemVariables.get("HTTP_PASSWORD"); 279 if (username != null && password != null) { 280 Authenticator.setDefault(new Authenticator() { 281 protected PasswordAuthentication getPasswordAuthentication() { 282 return new PasswordAuthentication(username, password.toCharArray()); 283 } 284 }); 285 } 286 } 287 288 protected String choicePriorityRecipeFolder(String text, String[] possibleValues) { 289 String result = inputChoice(text, null, possibleValues, possibleValues[0], null, false); 290 return result; 291 } 292 293 public void runSetupNodes() throws Exception { 294 if (!Boolean.valueOf(System.getProperty("skip.startup"))) { 295 Node[] theNodes = fConfigNode.getNodes(SpecialCommands.STARTUP); 296 TemplateProcessor tp = new TemplateProcessor(fSystemVariables, fConfigNode, getStartDir()); 297 if (theNodes != null) { 298 for (Node node : theNodes) { 299 final String theAttribut = tp.replaceProperties(node.getAttribute("task")); 300 boolean async = false; 301 String asyncValue = tp.replaceProperties(node.getAttribute("async")); 302 if (asyncValue != null) { 303 async = Boolean.valueOf(asyncValue); 304 } 305 if (theAttribut != null) { 306 runTask(theAttribut, async); 307 } else { 308 RecipeRunner taskEditor = createTestRunner(null); 309 taskEditor.runTest(new Node[] { node }); 310 } 311 } 312 } 313 } 314 } 315 316 protected void loadCustomProperties() { 317 if (fUserPreferences == null) { 318 fUserPreferences = new Properties(); 319 320 // loading users preferences 321 File preferencesFile = getPreferencesFile(); 322 try { 323 FileInputStream fileInputStream = new FileInputStream(preferencesFile); 324 fUserPreferences.load(fileInputStream); 325 fileInputStream.close(); 326 327 } catch (IOException e) { 328 // System.out.println("User preferences configuration file is not found: " + 329 // preferencesFile); 330 } 331 } 332 } 333 334 protected File getPreferencesFile() { 335 String configurationName = getConfigurationName(); 336 String fileName; 337 if (configurationName != null) { 338 fileName = configurationName + ".properties"; 339 } else { 340 fileName = ".properties"; 341 } 342 File preferencesDir = new File(getHomeWorkingDir(), "preferences"); 343 if(preferencesDir.exists() == false) { 344 preferencesDir.mkdirs(); 345 } 346 return new File(preferencesDir, fileName); 347 } 348 349 public String getCustomConfPropFileName(String configurationName) { 350 return getHomeConfigurationsDir() + "/" + fUser + "." + configurationName + ".properties"; 351 } 352 353 public File getHomeConfigurationsDir() { 354 File file = new File(getHomeWorkingDir(), "configuration"); 355 return file; 356 } 357 358 public void refreshTaskPath() throws IOException { 359 fTestsDescList.clear(); 360 TemplateProcessor tp = new TemplateProcessor(fSystemVariables, fConfigNode, getStartDir()); 361 getRecipesScaner().loadTaskPath(getConfigNode(), tp); 362 } 363 364 public void progressValue(int i, int length, boolean success) { 365 366 } 367 368 public void progressText(String name) { 369 370 } 371 372 public File getFile(String filePath) { 373 File file = null; 374 if (!StringUtils.startsWithAny(filePath, new String[] { "https:", "http:" })) { 375 if (filePath != null) { 376 if (filePath.startsWith("classpath:") || filePath.startsWith("jar:") || filePath.startsWith("file:") 377 || '/' == filePath.charAt(0) || '\\' == filePath.charAt(0) || filePath.indexOf(":\\") > 0 378 || '/' == filePath.charAt(0)) { 379 file = new File(filePath); 380 } else { 381 file = new File(baseDir, filePath); 382 } 383 } 384 } 385 386 return file; 387 } 388 389 public String inputValue(String aName, String description, String aValue, ILogger log, String type, 390 boolean notifyMe, Processor processor) { 391 System.out.print("Input "); 392 String line = inputValue(aName, description, null, type, null); 393 return line; 394 } 395 396 public String inputValue(String name, String description, String defaultValue, String type, Processor processor) { 397 if (defaultValue == null) { 398 defaultValue = AEWorkspace.getInstance().getDefaultUserConfiguration(".inputValue." + name, defaultValue); 399 } 400 401 boolean password = "password".equalsIgnoreCase(type); 402 403 String showValue = !password ? defaultValue 404 : (defaultValue != null ? StringUtils.repeat("*", defaultValue.length()) : ""); 405 String message = "\"" + StringUtils.defaultIfEmpty(description, name) + "\"" 406 + (StringUtils.isEmpty(defaultValue) ? "" : " [" + showValue + "]") + ": "; 407 System.out.print(message); 408 409 String line = null; 410 if (!Processor.isSilentMode(processor)) { 411 line = readLine(password); 412 if (StringUtils.isEmpty(line)) { 413 line = defaultValue; 414 } else { 415 AEWorkspace.getInstance().setDefaultUserConfiguration(".inputValue." + name, line); 416 } 417 } else { 418 line = defaultValue; 419 System.out.println(defaultValue); 420 } 421 return line; 422 } 423 424 @Override 425 public boolean confirmation(String name, String message, Processor unit, boolean notifyMe) throws Exception { 426 if (StringUtils.isBlank(name)) { 427 System.out.print(message + ", (yes/no): "); 428 } else { 429 System.out.print(name + " [" + message + "], (yes/no): "); 430 } 431 boolean result = false; 432 String line = readLine(false); 433 result = BooleanUtils.toBoolean(line); 434 return result; 435 } 436 437 public void inputDataTable(Processor unit, Node aTableNode, boolean notifyMe) throws IOException { 438 Node[] theVariablesNodes = aTableNode.getNodes("var"); 439 String theLine = null; 440 441 String theFileAttribut = aTableNode.getAttribute("file"); 442 if (unit != null) 443 theFileAttribut = unit.replaceProperties(aTableNode.getAttribute("file")); 444 445 if (theFileAttribut != null) { 446 File file = unit.getFile(theFileAttribut); 447 if (file.exists()) { 448 while ((theLine = readLine(false)) != null) { 449 theLine = theLine.trim(); 450 if (theLine.length() == 0) { 451 continue; 452 } 453 if (theLine.charAt(0) == '#') { 454 continue; 455 } 456 int thePbrk = theLine.indexOf('='); 457 458 String theName = StringUtils.upperCase(theLine.substring(0, thePbrk)); 459 String theValue = theLine.substring(thePbrk + 1); 460 461 Node theNode = new Node("var"); 462 theNode.setAttribute("name", theName); 463 theNode.setAttribute("value", theValue); 464 465 for (Node node : theVariablesNodes) { 466 if (node.getAttribute("name").equalsIgnoreCase(theName)) { 467 node.setAttribute("value", theValue); 468 } 469 } 470 471 } 472 } 473 } else { 474 String title = aTableNode.getAttribute("name"); 475 476 for (Node node : theVariablesNodes) { 477 String name = node.getAttribute("name"); 478 String value = node.getAttribute("value"); 479 480 String defaultValue = value; 481 482 String savedVarName = ".inputValue." + title + "." + StringUtils.upperCase(name); 483 if (defaultValue == null) { 484 defaultValue = AEWorkspace.getInstance().getDefaultUserConfiguration(savedVarName, null); 485 } 486 if (defaultValue == null) { 487 defaultValue = node.getAttribute("default"); 488 } 489 490 if (Processor.isSilentMode(unit)) { 491 value = defaultValue; 492 } else { 493 value = inputValue(name, null, defaultValue, null, unit); 494 AEWorkspace.getInstance().setDefaultUserConfiguration(savedVarName, value); 495 } 496 497 unit.setVariableValue(name, value); 498 } 499 } 500 } 501 502 public void loadConfProperties() throws IOException { 503 504 fSystemVariables.clear(); 505 506 Properties properties = new Properties(); 507 File theConfFile = new File(getCustomConfPropFileName(getConfigurationName())); 508 if (theConfFile.exists()) { 509 FileInputStream theFile = new FileInputStream(theConfFile); 510 properties.load(theFile); 511 theFile.close(); 512 } 513 514 Node[] theVarConfs = fConfigNode.getNodes("Var"); 515 for (int i = 0; i < theVarConfs.length; i++) { 516 Node varNode = theVarConfs[i]; 517 String name = StringUtils.upperCase(varNode.getAttribute("name")); 518 519 if (name != null) { 520 Map<String, String> variableDefinition = parseVariableDefinition(varNode); 521 fSystemVariables.putAll(variableDefinition); 522 523 } else { 524 Processor templateProcessor = new BaseProcessor(fSystemVariables, fConfigNode, getStartDir()); 525 String filePath = templateProcessor.replaceProperties(varNode.getAttribute("file")); 526 File file = getFile(filePath); 527 templateProcessor.loadProperties(file, fSystemVariables, true); 528 } 529 } 530 531 for (String key : properties.stringPropertyNames()) { 532 fSystemVariables.put(key, properties.getProperty(key)); 533 } 534 535 fSystemVariables.put("ENV", System.getenv()); 536 fSystemVariables.put("SYSTEM", System.getProperties()); 537 538 fSystemVariables.put("WORKINGDIR", getStartDir().getAbsolutePath()); 539 fSystemVariables.put("HOME_WORKINGDIR", getHomeWorkingDir().getAbsolutePath()); 540 fSystemVariables.put("START_TIME", Long.toString(startTime)); 541 fSystemVariables.put("USER_NAME", fUser); 542 543 Node[] theTableVarConfs = fConfigNode.getNodes("Table"); 544 Processor unit = new BaseProcessor(this, log, getStartDir()); 545 Processor.setSilentMode(unit, true); 546 547 for (int i = 0; i < theTableVarConfs.length; i++) { 548 inputDataTable(unit, theTableVarConfs[i], false); 549 fSystemVariables.putAll(unit.getVariables()); 550 } 551 552 boolean stopped = unit.isStopped(); 553 if (stopped) { 554 throw new TaskCancelingException(); 555 } 556 557 } 558 559 private Map<String, String> parseVariableDefinition(Node varNode) { 560 Map<String, String> properties = new HashMap<>(); 561 562 String name = StringUtils.upperCase(varNode.getAttribute("name")); 563 564 String attribute = varNode.getAttribute("init"); 565 String type = varNode.getAttribute("type"); 566 567 Object inputValue; 568 String typeValue = StringUtils.defaultIfBlank(type, "string"); 569 switch (typeValue) { 570 case "array": 571 Node[] nodes = varNode.getNodes("item"); 572 inputValue = new ArrayList<String>(); 573 for (Node node : nodes) { 574 String text = node.getInnerText(); 575 @SuppressWarnings("unchecked") 576 List<String> valueList = (List<String>) inputValue; 577 valueList.add(text); 578 } 579 break; 580 case "map": 581 inputValue = getMap(varNode); 582 break; 583 584 default: 585 inputValue = varNode.getAttribute("value"); 586 if (inputValue == null) { 587 inputValue = varNode.getInnerText(); 588 if (StringUtils.isEmpty((String) inputValue)) { 589 inputValue = getMap(varNode); 590 } 591 } 592 break; 593 } 594 595 if ("mandatory".equals(attribute) && properties.get(name) == null) { 596 attribute = "console"; 597 } 598 599 if ("console".equals(attribute)) { 600 inputValue = inputValue(name, null, ObjectUtils.toString(inputValue, null), log, type, false, null); 601 602 switch (StringUtils.defaultIfBlank(type, "string")) { 603 case "array": 604 break; 605 case "map": 606 inputValue = AEUtils.convertStringToMap((String) inputValue); 607 break; 608 609 default: 610 break; 611 } 612 } 613 614 if (inputValue != null) 615 fSystemVariables.put(StringUtils.upperCase(name), inputValue); 616 else 617 fSystemVariables.remove(name); 618 619 String savedValue = (String) properties.get(name); 620 Object value = null; 621 if (savedValue != null) { 622 switch (StringUtils.defaultIfBlank(type, "string")) { 623 case "array": 624 @SuppressWarnings("unchecked") 625 List<String> list = (List<String>) inputValue; 626 list.remove(savedValue); 627 628 List<String> arrayList = new ArrayList<>(); 629 arrayList.add(savedValue); 630 arrayList.addAll(list); 631 value = arrayList; 632 break; 633 case "map": 634 value = AEUtils.convertStringToMap(savedValue); 635 break; 636 637 default: 638 value = savedValue; 639 break; 640 } 641 642 fSystemVariables.put(StringUtils.upperCase(name), value); 643 } 644 645 return properties; 646 } 647 648 private Object getMap(Node varNode) { 649 Object result = null; 650 Node[] nodes = varNode.getNodes("item"); 651 if (nodes.length > 0) { 652 result = new LinkedHashMap<String, String>(); 653 for (Node node : nodes) { 654 @SuppressWarnings("unchecked") 655 Map<String, String> valueMap = (Map<String, String>) result; 656 String value = node.getAttribute("value"); 657 if (value == null) { 658 value = node.getInnerText(); 659 } 660 valueMap.put(node.getAttribute("key"), value); 661 } 662 } 663 return result; 664 } 665 666 public String selectConfiguration(String confName, Node configNodes, boolean refreshTaskPath) throws IOException { 667 668 allConfigNode = configNodes; 669 670 String configurationName = System.getProperty(ConfigConstants.CONFIG_NAME_SYS_PRPERTY_NAME); 671 if (confName != null) { 672 configurationName = confName; 673 } 674 675 fConfigNode = getCurrentConfig(allConfigNode, configurationName); 676 677 if (fConfigNode == null) { 678 System.out.println("Configuration '" + configurationName + "' not found in " + ConfigConstants.AE_CONFIG_XML 679 + " file."); 680 return configurationName; 681 682 } else { 683 setConfigurationName(fConfigNode.getAttribute("name")); 684 685 if (configurationName == null) { 686 configurationName = fConfigNode.getAttribute("name"); 687 if (configurationName == null) 688 configurationName = fConfigNode.getAttribute("description"); 689 } 690 691 loadConfProperties(); 692 693 Node[] theLocations = fConfigNode.getNodes("Locale"); 694 if (theLocations != null && theLocations.length > 0) { 695 Node theLocation = theLocations[0]; 696 String theISO3Language = theLocation.getAttribute("ISO3Language"); 697 String theDisplayName = theLocation.getAttribute("DisplayName"); 698 Locale[] availableLocales = Locale.getAvailableLocales(); 699 700 boolean theFound = false; 701 for (int l = 0; l < availableLocales.length; l++) { 702 if (availableLocales[l].getISO3Language().equals(theISO3Language)) { 703 Locale.setDefault(availableLocales[l]); 704 System.out.println("Set location ISO3Language: " + theISO3Language); 705 theFound = true; 706 break; 707 } 708 if (availableLocales[l].getDisplayName().equals(theDisplayName)) { 709 Locale.setDefault(availableLocales[l]); 710 System.out.println("Set location DisplayName: " + theDisplayName); 711 theFound = true; 712 break; 713 } 714 } 715 716 if (theFound == false) { 717 for (int j = 0; j < availableLocales.length; j++) { 718 System.out.println(j + ". " + availableLocales[j].getDisplayName()); 719 } 720 } 721 } 722 723 configuration(); 724 725 return fConfigurationName; 726 } 727 728 } 729 730 public void setDefaultUserConfiguration(String propertyName, String value) { 731 732 propertyName = getFullConfPropertyName(propertyName); 733 734 if (value != null) { 735 if (cryptoUtilAesGcm != null) { 736 value = cryptoUtilAesGcm.encrypt(value); 737 } 738 739 fUserPreferences.setProperty(propertyName, value); 740 741 try { 742 File preferencesFile = getPreferencesFile(); 743 FileOutputStream fileInputStream = new FileOutputStream(preferencesFile); 744 745 fUserPreferences.store(fileInputStream, null); 746 fileInputStream.close(); 747 748 } catch (IOException e) { 749 System.out.println("Write default user setting is failed. Error: " + e.getMessage()); 750 } 751 } else { 752 if (fUserPreferences.get(propertyName) != null) { 753 fUserPreferences.remove(propertyName); 754 } 755 } 756 757 } 758 759 private String getFullConfPropertyName(String propertyName) { 760 return propertyName; 761 } 762 763 public String getDefaultUserConfiguration(String aName, String theDefaultConfiguration) { 764 aName = getFullConfPropertyName(aName); 765 766 loadCustomProperties(); 767 String theProperty = fUserPreferences.getProperty(aName); 768 769 if (theProperty != null) { 770 if (cryptoUtilAesGcm != null) { 771 theDefaultConfiguration = cryptoUtilAesGcm.decrypt(theProperty); 772 } else { 773 theDefaultConfiguration = theProperty; 774 } 775 } 776 777 return theDefaultConfiguration; 778 } 779 780 public Node getCurrentConfig(Node configs, String aNameConfiguration) { 781 Node[] configNodes = configs.getNodes(CONFIGURATION_TITLE); 782 783 ArrayList<String> possibleValues = new ArrayList<>(); 784 785 for (int i = 0; i < configNodes.length; i++) { 786 Node node = configNodes[i]; 787 String name = node.getAttribute("name"); 788 String ip = node.getAttribute("ip"); 789 if (ip == null || isEnableIp(ip)) { 790 791 if (possibleValues.contains(name)) { 792 throw new IllegalArgumentException("Duplication name configuration: " + name); 793 } 794 795 if (!name.startsWith("#")) { 796 possibleValues.add(name); 797 } 798 } 799 } 800 801 if (CollectionUtils.isNotEmpty(possibleValues)) { 802 String configName = possibleValues.get(0); 803 if (aNameConfiguration != null) { 804 configName = aNameConfiguration; 805 } 806 807 if (possibleValues.size() > 1 && aNameConfiguration == null) { 808 configName = selectConfiguration(possibleValues.toArray(new String[possibleValues.size()])); 809 } 810 811 Node theConfigNode = prepareConfigurationNode(configs, configName); 812 return theConfigNode; 813 } 814 815 return null; 816 } 817 818 private boolean isEnableIp(String ip) { 819 Enumeration<NetworkInterface> networkInterfaces; 820 Pattern compile = Pattern.compile(ip); 821 try { 822 networkInterfaces = NetworkInterface.getNetworkInterfaces(); 823 while (networkInterfaces.hasMoreElements()) { 824 NetworkInterface nextElement = networkInterfaces.nextElement(); 825 Enumeration<InetAddress> inetAddresses = nextElement.getInetAddresses(); 826 while (inetAddresses.hasMoreElements()) { 827 InetAddress nextElement2 = inetAddresses.nextElement(); 828 if (nextElement2 instanceof Inet4Address) { 829 Inet4Address address = (Inet4Address) nextElement2; 830 String hostAddress = address.getHostAddress(); 831 if (compile.matcher(hostAddress).matches()) { 832 return true; 833 } 834 } 835 } 836 } 837 } catch (SocketException e) { 838 e.printStackTrace(); 839 } 840 return false; 841 } 842 843 private Node prepareConfigurationNode(Node configs, String configName) { 844 845 Node configNode = configs.findNode(CONFIGURATION_TITLE, "name", configName); 846 Node baseNode = null; 847 848 if (configNode != null) { 849 String baseConfig = configNode.getAttribute("base"); 850 851 if (baseConfig != null) { 852 baseNode = prepareConfigurationNode(configs, baseConfig); 853 854 if (baseNode != null) { 855 baseNode = (Node) baseNode.clone(); 856 baseNode.setAttributes(configNode.getAttributes()); 857 858 for (Iterator<Node> theIterator = configNode.iterator(); theIterator.hasNext();) { 859 Node theNode = theIterator.next(); 860 861 String theTagName = theNode.getTag(); 862 Node[] theNodeArray = baseNode.getNodes(theTagName); 863 864 if (theNodeArray.length > 1) { 865 String theName = theNode.getAttribute("name"); 866 867 Node theBaseTag = baseNode.findNode(theTagName, "name", theName); 868 869 if (theBaseTag != null) { 870 System.out.println( 871 "Change node: " + theTagName + " name=" + theName + " Value: " + theNode); 872 int indexOf = baseNode.indexOf(theBaseTag); 873 Node object = baseNode.get(indexOf); 874 if (object.getTag() == theTagName) 875 baseNode.remove(indexOf); 876 } 877 } 878 baseNode.add(theNode); 879 } 880 881 } else { 882 System.out.println("Base configuration is not found. Name: " + baseConfig); 883 baseNode = configNode; 884 } 885 } else 886 baseNode = configNode; 887 888 } else 889 baseNode = configNode; 890 891 return baseNode; 892 } 893 894 public File getStartDir() { 895 return getRecipesScaner().getStartDir(); 896 } 897 898 public String inputChoice(String name, String description, String[] values, String defaultValue, 899 Processor taskProcessor, boolean notifyMe) { 900 if (defaultValue == null && values.length > 0) { 901 String value = getDefaultUserConfiguration(".choice." + name, null); 902 if (value != null) { 903 defaultValue = value; 904 } 905 } 906 907 System.out.println("List of values for [" + name + "]:"); 908 if (!Processor.isSilentMode(taskProcessor)) { 909 int i = 1; 910 for (String val : values) { 911 println(String.format("%3s: ", i++) + val, Color.green); 912 } 913 defaultValue = inputInteger(name, values, defaultValue); 914 } else { 915 System.out.println("Saved selection applied: " + defaultValue); 916 } 917 918 return defaultValue; 919 } 920 921 public String[] inputMultiChoice(String name, String[] values, String defaultValue, Processor taskProcessor) { 922 String[] result = null; 923 924 if (defaultValue == null && values.length > 0) { 925 String value = getDefaultUserConfiguration("MultiTaskRunDialog:" + name, null); 926 if (value != null) { 927 defaultValue = value; 928 } 929 } 930 boolean silent = taskProcessor != null && Processor.isSilentMode(taskProcessor); 931 932 boolean isDone = false; 933 do { 934 try { 935 System.out.println("List of values for [" + name + "]:"); 936 if (!silent) { 937 int i = 1; 938 939 for (String val : values) { 940 println(String.format("%3s: ", i++) + val, Color.green); 941 } 942 String preset = null; 943 System.out.print("Please select "); 944 defaultValue = inputValue(name, preset, defaultValue, null, taskProcessor); 945 result = getValue(values, defaultValue); 946 isDone = true; 947 948 AEWorkspace.getInstance().setDefaultUserConfiguration("MultiTaskRunDialog:" + name, defaultValue); 949 } else { 950 if (defaultValue != null) { 951 result = getValue(values, defaultValue); 952 System.out.println("Saved selection applied: [" + StringUtils.join(result, ",") + "]"); 953 } 954 } 955 } catch (ArrayIndexOutOfBoundsException e) { 956 System.out.println(defaultValue + " - invalid value."); 957 isDone = false; 958 } 959 } while (!isDone && !silent); 960 961 return result; 962 } 963 964 private void println(String text, Color color) { 965 System.out.println(text); 966 } 967 968 protected String[] getValue(String[] values, String defaultValue) { 969 String[] result = null; 970 if (defaultValue != null) { 971 String[] split = StringUtils.split(defaultValue, ";"); 972 973 try { 974 result = new String[split.length]; 975 for (int j = 0; j < split.length; j++) { 976 result[j] = values[Integer.parseInt(split[j]) - 1]; 977 } 978 } catch (NumberFormatException e) { 979 result = split; 980 } 981 } 982 return result; 983 } 984 985 public String inputInteger(String name, String[] values, String defaultValue) { 986 987 boolean isDone = false; 988 do { 989 System.out.print( 990 "Please select" + (StringUtils.isEmpty(defaultValue) ? "" : " [" + defaultValue + "]") + ": "); 991 992 int inputValue; 993 String readLine = null; 994 try { 995 readLine = readLine(false); 996 if (!StringUtils.isEmpty(readLine)) { 997 inputValue = Integer.parseInt(readLine) - 1; 998 defaultValue = values[inputValue]; 999 setDefaultUserConfiguration(".choice." + name, defaultValue); 1000 } 1001 1002 isDone = true; 1003 1004 } catch (Exception e) { 1005 System.out.println(readLine + " - invalid value."); 1006 defaultValue = null; 1007 } 1008 } while (!isDone); 1009 1010 return defaultValue; 1011 } 1012 1013 public String inputFile(String name, String description, File aDefaultFile, ILogger log, Processor taskProcessor) { 1014 String theResult = getDefaultUserConfiguration(".inputFile", 1015 aDefaultFile == null ? null : aDefaultFile.getAbsolutePath()); 1016 return theResult; 1017 } 1018 1019 public void executeAnteaterMaven(File aeConfigFile, String action) { 1020 Invoker invoker = new DefaultInvoker(); 1021 InvocationRequest request = new DefaultInvocationRequest(); 1022 request.setPomFile(aeConfigFile); 1023 Properties properties = new Properties(); 1024 String recipes = System.getProperty(ConfigConstants.RECIPES_PARAM_NAME); 1025 if (recipes != null) { 1026 properties.setProperty(ConfigConstants.RECIPES_PARAM_NAME, recipes); 1027 } 1028 request.setProperties(properties); 1029 request.addArg("ae:" + action); 1030 request.setDebug(Boolean.parseBoolean(System.getProperty("debug", "false"))); 1031 request.setBaseDirectory(aeConfigFile.getParentFile()); 1032 request.setInputStream(System.in); 1033 InvocationResult result; 1034 try { 1035 result = invoker.execute(request); 1036 if (result.getExitCode() == 0) { 1037 System.out.println("Maven build completed successfully!"); 1038 1039 } else { 1040 System.err.println("Maven build failed with exit code: " + result.getExitCode()); 1041 if (result.getExecutionException() != null) { 1042 result.getExecutionException().printStackTrace(); 1043 } 1044 } 1045 1046 System.exit(result.getExitCode()); 1047 } catch (MavenInvocationException e) { 1048 e.printStackTrace(); 1049 System.exit(1); 1050 } 1051 } 1052 1053 public File getPomLocation(String confFileName, String aeDir) { 1054 aeDir = StringUtils.defaultIfBlank(aeDir, ""); 1055 confFileName = confFileName.replace('\\', '/'); 1056 String pomFilePath = null; 1057 if (StringUtils.isEmpty(aeDir)) { 1058 pomFilePath = StringUtils.substringBeforeLast(confFileName, "/src/"); 1059 } else { 1060 String relativePath = aeDir + "/" + ConfigConstants.AE_CONFIG_XML; 1061 if (StringUtils.endsWith(confFileName, relativePath)) { 1062 pomFilePath = StringUtils.replace(confFileName, relativePath, ""); 1063 } 1064 } 1065 1066 File pomFile = null; 1067 if (pomFilePath != null) { 1068 pomFile = new File(pomFilePath, "pom.xml"); 1069 if (!pomFile.exists()) { 1070 System.out.println("POM file not found: " + pomFilePath); 1071 pomFile = null; 1072 } 1073 } 1074 return pomFile; 1075 } 1076 1077 public List<String> findAEconfigs(File path) { 1078 if (path == null) { 1079 path = SystemUtils.getUserDir(); 1080 } 1081 1082 List<String> confFiles = new ArrayList<>(); 1083 try (Stream<Path> stream = Files.walk(Paths.get(path.getAbsolutePath()), 10)) { 1084 stream.filter(f -> f.endsWith(ConfigConstants.AE_CONFIG_XML)).forEach(f -> confFiles.add(f.toString())); 1085 } catch (NoSuchFileException e) { 1086 // do nothing. 1087 } catch (IOException e) { 1088 e.printStackTrace(); 1089 } 1090 return confFiles; 1091 } 1092 1093 protected String selectConfiguration(String[] configNames) { 1094 String configName = choiceValue(CONFIGURATION_TITLE, null, configNames, null, true, null); 1095 return configName; 1096 } 1097 1098 public String getTestPath(String name) { 1099 String recipePath = null; 1100 if (name != null) { 1101 recipePath = fTestsDescList.getProperty(name); 1102 } 1103 return recipePath; 1104 } 1105 1106 public RecipeRunner runTask(String name, boolean async) { 1107 RecipeRunner runner = null; 1108 if (name != null) { 1109 runner = createTestRunner(name); 1110 String testPath = getTestPath(name); 1111 if (testPath != null) { 1112 if (async) { 1113 TaskThread theThread = new TaskThread(runner, testPath); 1114 theThread.start(); 1115 1116 } else { 1117 try { 1118 runner.makeRecipe(testPath); 1119 } catch (CommandException e) { 1120 log.error("Task failed.", e); 1121 } 1122 } 1123 } 1124 } 1125 1126 return runner; 1127 } 1128 1129 protected RecipeRunner createTestRunner(String name) { 1130 RecipeRunner runner = new RecipeRunner(this); 1131 Processor processor = new BaseProcessor(this, log, getStartDir()); 1132 processor.setTestListener(runner); 1133 runner.setProcessor(processor); 1134 runner.setLog(log); 1135 return runner; 1136 } 1137 1138 public void removeTestPath(String name) { 1139 if (fTestsDescList.get(name) != null) 1140 fTestsDescList.remove(name); 1141 } 1142 1143 public void setTestPath(String name, String path) { 1144 fTestsDescList.put(name, path); 1145 } 1146 1147 public String getWorkingDir() { 1148 return getStartDir().getAbsolutePath(); 1149 } 1150 1151 public MultiTaskRunDialog tasksChoice(MultiTaskRunDialog dialog, String[] list, boolean exceptionIgnoreFlag, 1152 Object setup, Processor taskProcessor, boolean visible) { 1153 1154 if (setup == null) { 1155 boolean consoleDefaultInput = isConsoleDefaultInput(dialog.getName(), null); 1156 setup = inputMultiChoice(dialog.getName(), list, null, taskProcessor); 1157 dialog.select((String[]) setup, consoleDefaultInput); 1158 } 1159 1160 dialog.setExceptionIgnore(exceptionIgnoreFlag); 1161 dialog.setVisible(visible); 1162 dialog.showDialog(dialog.getName(), list, taskProcessor.getListener().isNotifyMe()); 1163 1164 return dialog; 1165 } 1166 1167 public Map<String, Object> getSystemVariables() { 1168 return fSystemVariables; 1169 } 1170 1171 public void setConsoleDefaultInput(boolean defaultMode) { 1172 this.defaultMode = defaultMode; 1173 } 1174 1175 public boolean isConsoleDefaultInput(String varName, String description) { 1176 return defaultMode; 1177 } 1178 1179 public Node getConfigNode() { 1180 return fConfigNode; 1181 } 1182 1183 public Node getAllConfigNode() { 1184 return allConfigNode; 1185 } 1186 1187 public Properties getTasksMap() { 1188 return fTestsDescList; 1189 } 1190 1191 public Properties getTestsDescList() { 1192 return fTestsDescList; 1193 } 1194 1195 public Object[] getPublicTestsList() { 1196 Enumeration<Object> keys = fTestsDescList.keys(); 1197 List<String> result = new ArrayList<String>(); 1198 while (keys.hasMoreElements()) { 1199 String key = (String) keys.nextElement(); 1200 if (!key.startsWith("#")) { 1201 result.add(key); 1202 } 1203 } 1204 String[] a = result.toArray(new String[result.size()]); 1205 Arrays.sort(a); 1206 return a; 1207 } 1208 1209 public void startTaskNotify(RecipeRunner task) { 1210 1211 } 1212 1213 public String choiceValue(String name, String description, Object[] possibleValues, ILogger log, boolean notifyMe, 1214 Processor processor) { 1215 String result = null; 1216 description = StringUtils.defaultString(description, name); 1217 1218 if (possibleValues != null && possibleValues.length > 0) { 1219 result = getDefaultUserConfiguration(".choiceValue." + name, null); 1220 1221 String[] values = Arrays.copyOf(possibleValues, possibleValues.length, String[].class); 1222 result = inputChoice(description, null, values, result, processor, notifyMe); 1223 1224 AEWorkspace.getInstance().setDefaultUserConfiguration(".choiceValue." + name, result); 1225 } else { 1226 result = (String) possibleValues[0]; 1227 } 1228 1229 return result; 1230 } 1231 1232 public static AEWorkspace getInstance() { 1233 return instance; 1234 } 1235 1236 public void resetConfiguration() { 1237 fConfigNode = null; 1238 } 1239 1240 public void resetConfigurationName() { 1241 setConfigurationName(null); 1242 } 1243 1244 public String getConfigurationName() { 1245 return this.fConfigurationName; 1246 } 1247 1248 public void loadConfiguration(boolean refreshTaskMap) { 1249 loadConfiguration(null, refreshTaskMap); 1250 } 1251 1252 public void addRunner(RecipeRunner testRunner) { 1253 runners.add(testRunner); 1254 } 1255 1256 public void removeRunner(RecipeRunner testRunner) { 1257 runners.remove(testRunner); 1258 } 1259 1260 public void stopAllRunners() { 1261 RecipeRunner[] array = runners.toArray(new RecipeRunner[runners.size()]); 1262 for (RecipeRunner runner : array) { 1263 runner.stopTest(); 1264 } 1265 } 1266 1267 public void setBaseDir(File baseDir) { 1268 this.baseDir = baseDir; 1269 } 1270 1271 public File getBaseDir() { 1272 return this.baseDir; 1273 } 1274 1275 public Set<Class<?>> getOperationsClasses() { 1276 return operationsClasses; 1277 } 1278 1279 public void setOperationsClasses(@SuppressWarnings("rawtypes") Set<Class> operationsClasses) { 1280 if (operationsClasses != null) { 1281 opsMethods = new HashMap<String, OperationHolder>(); 1282 try { 1283 Method[] methods = Object.class.getMethods(); 1284 String exclude[] = new String[methods.length]; 1285 for (int i = 0; i < exclude.length; i++) { 1286 exclude[i] = methods[i].getName(); 1287 } 1288 Arrays.sort(exclude); 1289 1290 for (Class<?> operationClass : operationsClasses) { 1291 methods = operationClass.getMethods(); 1292 for (Method method : methods) { 1293 if (Arrays.binarySearch(exclude, method.getName()) < 0 1294 && method.getModifiers() == Modifier.PUBLIC) { 1295 String shortClassName = operationClass.getName(); 1296 opsMethods.put(shortClassName + "." + method.getName(), 1297 new OperationHolder(operationClass, method)); 1298 } 1299 } 1300 } 1301 } catch (Exception e) { 1302 throw new IllegalArgumentException(e); 1303 } 1304 } 1305 } 1306 1307 public OperationHolder getOperationsMethod(String name) { 1308 return opsMethods.get(name); 1309 } 1310 1311 public Map<String, OperationHolder> getOperationsMethods() { 1312 return opsMethods; 1313 } 1314 1315 public Set<RecipeRunner> getRunners() { 1316 return runners; 1317 } 1318 1319 @Override 1320 public void finished(String aTestFile) { 1321 } 1322 1323 public static Properties getUserPreferences() { 1324 return fUserPreferences; 1325 } 1326 1327 public String[] getTestsList() { 1328 String[] array = fTestsDescList.keySet().toArray(new String[fTestsDescList.size()]); 1329 Arrays.sort(array); 1330 return array; 1331 } 1332 1333 @Override 1334 public MessageHandler message(Processor taskProcessor, String description, String message, boolean notifyMe) { 1335 return new MessageHandler(); 1336 } 1337 1338 public void setConfigurationName(String fConfigurationName) { 1339 this.fConfigurationName = fConfigurationName; 1340 fUserPreferences = null; 1341 loadCustomProperties(); 1342 } 1343 1344 public void initUserPreferencesEncryption(String password) { 1345 Node configNode = getConfigNode(); 1346 boolean userPreferencesEncryption = Boolean.parseBoolean(configNode.getAttribute("userPreferencesEncryption")); 1347 1348 if (userPreferencesEncryption) { 1349 if (password == null) { 1350 System.out.print(MESSAGE_PASSWORD_REQUIRED); 1351 1352 Console console = System.console(); 1353 if (console == null) { 1354 password = readLine(true); 1355 } else { 1356 char[] pwd = console.readPassword(); 1357 password = new String(pwd); 1358 } 1359 } 1360 1361 byte[] pwdBytes; 1362 try { 1363 pwdBytes = new String(password).getBytes("UTF-8"); 1364 } catch (UnsupportedEncodingException e) { 1365 throw new IllegalArgumentException(e); 1366 } 1367 password = Base64.getEncoder().encodeToString(pwdBytes); 1368 cryptoUtilAesGcm = new Encryptor(password); 1369 Enumeration<Object> keys = fUserPreferences.keys(); 1370 while (keys.hasMoreElements()) { 1371 String name = (String) keys.nextElement(); 1372 getDefaultUserConfiguration(name, name); 1373 break; 1374 } 1375 } 1376 } 1377 1378 public void close() { 1379 closeHooks.forEach(e -> e.run()); 1380 } 1381 1382 public void addCloseHook(Runnable shutdownHook) { 1383 closeHooks.add(shutdownHook); 1384 } 1385 1386 public RecipesScanner getRecipesScaner() { 1387 return recipesScaner; 1388 } 1389 1390 public void setStartDir(File startDir) { 1391 recipesScaner.setStartDir(startDir); 1392 } 1393 1394 private String readLine(boolean password) { 1395 try { 1396 Console console = System.console(); 1397 String line; 1398 Toolkit.getDefaultToolkit().beep(); 1399 if (console != null) { 1400 if (password) { 1401 line = new String(console.readPassword()); 1402 } else { 1403 line = console.readLine(); 1404 } 1405 } else { 1406 InputStreamReader inputStreamReader = new InputStreamReader(System.in); 1407 BufferedReader reader = new BufferedReader(inputStreamReader); 1408 try { 1409 line = reader.readLine(); 1410 } catch (IOException e) { 1411 line = null; 1412 } 1413 } 1414 1415 return line; 1416 1417 } catch (RuntimeException e) { 1418 throw new TaskCancelingException(); 1419 } 1420 } 1421 1422 protected void initLogger(Node configNode) { 1423 Properties logProperties = fillLogProperties(configNode); 1424 PropertyConfigurator.configure(logProperties); 1425 log = new Logger("AEWorkspace"); 1426 } 1427 1428 protected Properties fillLogProperties(Node configNode) { 1429 Properties logProperties = new Properties(); 1430 if (configNode != null) { 1431 logProperties = MapUtils.toProperties(configNode.getAttributes()); 1432 } 1433 Node[] theLoggerNodes = fConfigNode.getNodes("Logger"); 1434 Node node = theLoggerNodes[0]; 1435 boolean consoleOn = false; 1436 if (theLoggerNodes != null && theLoggerNodes.length > 0) { 1437 node = theLoggerNodes[0]; 1438 logProperties.putAll(node.getAttributes()); 1439 } 1440 1441 TemplateProcessor templateProcessor = new TemplateProcessor(fSystemVariables, fConfigNode, getStartDir()); 1442 1443 if (logProperties.getProperty("rootLogger") != null) { 1444 String rootLogger = templateProcessor.replaceProperties(logProperties.getProperty("rootLogger")); 1445 1446 consoleOn = rootLogger.indexOf("CONSOLE") >= 0; 1447 1448 logProperties.setProperty("log4j.rootLogger", rootLogger); 1449 logProperties.remove("rootLogger"); 1450 } 1451 if (logProperties.getProperty("File") != null) { 1452 String lofFileName = templateProcessor.replaceProperties(logProperties.getProperty("File")); 1453 File file = new File(lofFileName); 1454 if (file != null && file.getParentFile() != null && file.getParentFile().exists() == false) 1455 file.getParentFile().mkdirs(); 1456 logProperties.setProperty("log4j.appender.LOGFILE.File", lofFileName); 1457 } 1458 if (logProperties.getProperty("Threshold") != null) { 1459 logProperties.setProperty("log4j.appender.LOGFILE.Threshold", 1460 templateProcessor.replaceProperties(logProperties.getProperty("Threshold"))); 1461 if (consoleOn) 1462 logProperties.setProperty("log4j.appender.CONSOLE.Threshold", 1463 templateProcessor.replaceProperties(logProperties.getProperty("Threshold"))); 1464 logProperties.remove("Threshold"); 1465 } 1466 if (logProperties.getProperty("ConversionPattern") != null) { 1467 logProperties.setProperty("log4j.appender.LOGFILE.layout.ConversionPattern", 1468 templateProcessor.replaceProperties(logProperties.getProperty("ConversionPattern"))); 1469 if (consoleOn) 1470 logProperties.setProperty("log4j.appender.CONSOLE.layout.ConversionPattern", 1471 templateProcessor.replaceProperties(logProperties.getProperty("ConversionPattern"))); 1472 logProperties.remove("ConversionPattern"); 1473 } else { 1474 logProperties.setProperty("log4j.appender.LOGFILE.layout.ConversionPattern", 1475 "%d{dd.MM.yyyy HH:mm:ss} %-5p %m %n"); 1476 if (consoleOn) 1477 logProperties.setProperty("log4j.appender.CONSOLE.layout.ConversionPattern", 1478 "%d{dd.MM.yyyy HH:mm:ss} %-5p %m %n"); 1479 } 1480 logProperties.setProperty("log4j.appender.logfile.DatePattern", "'.'yyyy-MM-dd"); 1481 logProperties.setProperty("log4j.appender.LOGFILE", "org.apache.log4j.DailyRollingFileAppender"); 1482 if (consoleOn) 1483 logProperties.setProperty("log4j.appender.CONSOLE", "org.apache.log4j.ConsoleAppender"); 1484 logProperties.setProperty("log4j.appender.LOGFILE.layout", "org.apache.log4j.PatternLayout"); 1485 if (consoleOn) 1486 logProperties.setProperty("log4j.appender.CONSOLE.layout", "org.apache.log4j.PatternLayout"); 1487 1488 logProperties.setProperty("log4j.logger.java.desktop", "ERROR"); 1489 return logProperties; 1490 } 1491 1492}