Convenience method that attempts to create an AddOn from the given file. A warning is logged if the add-on is invalid and an error if an error occurred while creating it. @param file the file of the add-on. @return a container with the AddOn, or empty if not valid or an error oc
(Path file)
| 452 | * @since 2.8.0 |
| 453 | */ |
| 454 | public static Optional<AddOn> createAddOn(Path file) { |
| 455 | try { |
| 456 | return Optional.of(new AddOn(file)); |
| 457 | } catch (AddOn.InvalidAddOnException e) { |
| 458 | String logMessage = "Invalid add-on: " + file.toString() + "."; |
| 459 | if (LOGGER.isDebugEnabled() || Constant.isDevMode()) { |
| 460 | LOGGER.warn(logMessage, e); |
| 461 | } else { |
| 462 | LOGGER.warn("{} {}", logMessage, e.getMessage()); |
| 463 | } |
| 464 | } catch (Exception e) { |
| 465 | LOGGER.error("Failed to create an add-on from: {}", file, e); |
| 466 | } |
| 467 | return Optional.empty(); |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Constructs an {@code AddOn} from the given {@code file}. |
no test coverage detected