Search in sources :

Example 11 with YAMLException

use of org.yaml.snakeyaml.error.YAMLException in project nifi-minifi by apache.

the class SchemaSaver method saveConfigSchema.

public static void saveConfigSchema(ConfigSchema configSchema, OutputStream output) throws IOException {
    DumperOptions dumperOptions = new DumperOptions();
    dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    Yaml yaml = new Yaml(new ConfigRepresenter(), dumperOptions);
    Map<String, Object> yamlMap = configSchema.toMap();
    try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(output)) {
        try {
            yaml.dump(yamlMap, outputStreamWriter);
        } catch (YAMLException e) {
            throw new IOException(e);
        }
    }
}
Also used : DumperOptions(org.yaml.snakeyaml.DumperOptions) YAMLException(org.yaml.snakeyaml.error.YAMLException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Yaml(org.yaml.snakeyaml.Yaml)

Example 12 with YAMLException

use of org.yaml.snakeyaml.error.YAMLException in project Essentials by drtshock.

the class Essentials method onEnable.

@Override
public void onEnable() {
    try {
        if (LOGGER != this.getLogger()) {
            LOGGER.setParent(this.getLogger());
        }
        execTimer = new ExecuteTimer();
        execTimer.start();
        i18n = new I18n(this);
        i18n.onEnable();
        execTimer.mark("I18n1");
        Console.setInstance(this);
        final PluginManager pm = getServer().getPluginManager();
        for (Plugin plugin : pm.getPlugins()) {
            if (plugin.getDescription().getName().startsWith("Essentials") && !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()) && !plugin.getDescription().getName().equals("EssentialsAntiCheat")) {
                getLogger().warning(tl("versionMismatch", plugin.getDescription().getName()));
            }
        }
        for (Method method : Server.class.getDeclaredMethods()) {
            if (method.getName().endsWith("getOnlinePlayers") && method.getReturnType() == Player[].class) {
                oldGetOnlinePlayers = method;
                break;
            }
        }
        forceLoadClasses();
        try {
            final EssentialsUpgrade upgrade = new EssentialsUpgrade(this);
            upgrade.beforeSettings();
            execTimer.mark("Upgrade");
            confList = new ArrayList<>();
            settings = new Settings(this);
            confList.add(settings);
            execTimer.mark("Settings");
            userMap = new UserMap(this);
            confList.add(userMap);
            execTimer.mark("Init(Usermap)");
            kits = new Kits(this);
            confList.add(kits);
            upgrade.convertKits();
            execTimer.mark("Kits");
            upgrade.afterSettings();
            execTimer.mark("Upgrade2");
            warps = new Warps(getServer(), this.getDataFolder());
            confList.add(warps);
            execTimer.mark("Init(Spawn/Warp)");
            worth = new Worth(this.getDataFolder());
            confList.add(worth);
            itemDb = new ItemDb(this);
            confList.add(itemDb);
            execTimer.mark("Init(Worth/ItemDB)");
            jails = new Jails(this);
            confList.add(jails);
            spawnerProvider = new ProviderFactory<>(getLogger(), Arrays.asList(BlockMetaSpawnerProvider.class, v1_8_R2SpawnerProvider.class, v1_8_R1SpawnerProvider.class, LegacySpawnerProvider.class), "mob spawner").getProvider();
            spawnEggProvider = new ProviderFactory<>(getLogger(), Arrays.asList(ReflSpawnEggProvider.class, LegacySpawnEggProvider.class), "spawn egg").getProvider();
            potionMetaProvider = new ProviderFactory<>(getLogger(), Arrays.asList(BasePotionDataProvider.class, LegacyPotionMetaProvider.class), "potion meta").getProvider();
            reload();
        } catch (YAMLException exception) {
            if (pm.getPlugin("EssentialsUpdate") != null) {
                LOGGER.log(Level.SEVERE, tl("essentialsHelp2"));
            } else {
                LOGGER.log(Level.SEVERE, tl("essentialsHelp1"));
            }
            handleCrash(exception);
            return;
        }
        backup = new Backup(this);
        permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions());
        alternativeCommandsHandler = new AlternativeCommandsHandler(this);
        timer = new EssentialsTimer(this);
        scheduleSyncRepeatingTask(timer, 1000, 50);
        Economy.setEss(this);
        execTimer.mark("RegHandler");
        metrics = new Metrics(this);
        if (!metrics.isOptOut()) {
            getLogger().info("Starting Metrics. Opt-out using the global bStats config.");
        } else {
            getLogger().info("Metrics disabled per bStats config.");
        }
        final String timeroutput = execTimer.end();
        if (getSettings().isDebug()) {
            LOGGER.log(Level.INFO, "Essentials load {0}", timeroutput);
        }
    } catch (NumberFormatException ex) {
        handleCrash(ex);
    } catch (Error ex) {
        handleCrash(ex);
        throw ex;
    }
}
Also used : LegacyPotionMetaProvider(net.ess3.nms.legacy.LegacyPotionMetaProvider) LegacySpawnerProvider(net.ess3.nms.legacy.LegacySpawnerProvider) BlockMetaSpawnerProvider(net.ess3.nms.updatedmeta.BlockMetaSpawnerProvider) net.ess3.nms.v1_8_R2.v1_8_R2SpawnerProvider(net.ess3.nms.v1_8_R2.v1_8_R2SpawnerProvider) BasePotionDataProvider(net.ess3.nms.updatedmeta.BasePotionDataProvider) PluginManager(org.bukkit.plugin.PluginManager) LegacySpawnEggProvider(net.ess3.nms.legacy.LegacySpawnEggProvider) Metrics(com.earth2me.essentials.metrics.Metrics) PermissionsHandler(com.earth2me.essentials.perm.PermissionsHandler) ProviderFactory(net.ess3.providers.ProviderFactory) ISettings(net.ess3.api.ISettings) net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider(net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider) YAMLException(org.yaml.snakeyaml.error.YAMLException) Method(java.lang.reflect.Method) ReflSpawnEggProvider(net.ess3.nms.refl.ReflSpawnEggProvider) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Example 13 with YAMLException

use of org.yaml.snakeyaml.error.YAMLException in project nzbhydra2 by theotherp.

the class NzbHydra method handleException.

private static void handleException(Exception e) throws Exception {
    String msg;
    if (e.getClass().getName().contains("SilentExitException")) {
        // Sometimes thrown by spring boot devtools
        return;
    }
    if (e instanceof YAMLException) {
        msg = "The file " + new File(dataFolder, "nzbhydra.yml").getAbsolutePath() + " could not be parsed properly. It might be corrupted. Try restoring it from a backup. Error message: " + e.getMessage();
        logger.error(msg);
    }
    if (e instanceof ConnectorStartFailedException) {
        msg = "The selected port is already in use. Either shut the other application down or select another port";
        logger.error(msg);
    } else {
        msg = "An unexpected error occurred during startup: " + e;
        logger.error("An unexpected error occurred during startup", e);
    }
    try {
        if (!GraphicsEnvironment.isHeadless() && isOsWindows()) {
            JOptionPane.showMessageDialog(null, msg, "NZBHydra 2 error", JOptionPane.ERROR_MESSAGE);
        }
    } catch (HeadlessException e1) {
        logger.warn("Unable to show exception in message dialog: {}", e1.getMessage());
    }
    // Rethrow so that spring exception handlers can handle this
    throw e;
}
Also used : YAMLException(org.yaml.snakeyaml.error.YAMLException) File(java.io.File) ConnectorStartFailedException(org.springframework.boot.context.embedded.tomcat.ConnectorStartFailedException)

Example 14 with YAMLException

use of org.yaml.snakeyaml.error.YAMLException in project cassandra by apache.

the class YamlConfigurationLoader method loadConfig.

public Config loadConfig(URL url) throws ConfigurationException {
    try {
        logger.debug("Loading settings from {}", url);
        byte[] configBytes;
        try (InputStream is = url.openStream()) {
            configBytes = ByteStreams.toByteArray(is);
        } catch (IOException e) {
            // getStorageConfigURL should have ruled this out
            throw new AssertionError(e);
        }
        Constructor constructor = new CustomConstructor(Config.class, Yaml.class.getClassLoader());
        Map<Class<?>, Map<String, Replacement>> replacements = getNameReplacements(Config.class);
        PropertiesChecker propertiesChecker = new PropertiesChecker(replacements);
        constructor.setPropertyUtils(propertiesChecker);
        Yaml yaml = new Yaml(constructor);
        Config result = loadConfig(yaml, configBytes);
        propertiesChecker.check();
        return result;
    } catch (YAMLException e) {
        throw new ConfigurationException("Invalid yaml: " + url, e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CustomClassLoaderConstructor(org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor) Constructor(org.yaml.snakeyaml.constructor.Constructor) YAMLException(org.yaml.snakeyaml.error.YAMLException) IOException(java.io.IOException) Yaml(org.yaml.snakeyaml.Yaml) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with YAMLException

use of org.yaml.snakeyaml.error.YAMLException in project es6draft by anba.

the class Test262Info method readYaml.

private void readYaml(String descriptor, ErrorHandler error) throws MalformedDataException {
    assert descriptor != null && !descriptor.isEmpty();
    boolean lenient = error == ErrorHandler.Ignore;
    Yaml yaml = null;
    if (lenient) {
        yaml = yamlQueue.poll();
    }
    if (yaml == null) {
        Constructor constructor = new Constructor(TestDescriptor.class);
        if (lenient) {
            PropertyUtils utils = new PropertyUtils();
            utils.setSkipMissingProperties(true);
            constructor.setPropertyUtils(utils);
        }
        yaml = new Yaml(constructor);
        if (!lenient) {
            LoaderOptions loaderOptions = new LoaderOptions();
            loaderOptions.setAllowDuplicateKeys(false);
        }
    }
    TestDescriptor desc;
    try {
        desc = yaml.loadAs(descriptor, TestDescriptor.class);
    } catch (YAMLException e) {
        throw new MalformedDataException(e.getMessage(), e);
    }
    if (lenient) {
        yamlQueue.offer(yaml);
    }
    this.description = desc.getDescription();
    this.includes = desc.getIncludes();
    this.features = desc.getFeatures();
    this.errorType = desc.getNegative().getType();
    this.errorPhase = from(desc.getNegative().getPhase(), lenient);
    this.negative = desc.getNegative().getType() != null;
    if (!desc.getFlags().isEmpty()) {
        if (!lenient) {
            for (String flag : desc.getFlags()) {
                if (!allowedFlags.contains(flag)) {
                    throw new MalformedDataException(String.format("Unknown flag '%s'", flag));
                }
            }
        }
        this.noStrict = desc.getFlags().contains("noStrict");
        this.onlyStrict = desc.getFlags().contains("onlyStrict");
        this.module = desc.getFlags().contains("module");
        this.raw = desc.getFlags().contains("raw");
        this.async = desc.getFlags().contains("async");
    }
    if (!lenient && errorPhase == ErrorPhase.Resolution && !module) {
        throw new MalformedDataException(String.format("Invalid error phase 'resolution' for non-module test"));
    }
}
Also used : LoaderOptions(org.yaml.snakeyaml.LoaderOptions) PropertyUtils(org.yaml.snakeyaml.introspector.PropertyUtils) Constructor(org.yaml.snakeyaml.constructor.Constructor) YAMLException(org.yaml.snakeyaml.error.YAMLException) Yaml(org.yaml.snakeyaml.Yaml)

Aggregations

YAMLException (org.yaml.snakeyaml.error.YAMLException)15 Yaml (org.yaml.snakeyaml.Yaml)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)5 Map (java.util.Map)4 Constructor (org.yaml.snakeyaml.constructor.Constructor)4 Metrics (com.earth2me.essentials.metrics.Metrics)2 PermissionsHandler (com.earth2me.essentials.perm.PermissionsHandler)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 ISettings (net.ess3.api.ISettings)2 LegacyPotionMetaProvider (net.ess3.nms.legacy.LegacyPotionMetaProvider)2 LegacySpawnEggProvider (net.ess3.nms.legacy.LegacySpawnEggProvider)2 LegacySpawnerProvider (net.ess3.nms.legacy.LegacySpawnerProvider)2 ReflSpawnEggProvider (net.ess3.nms.refl.ReflSpawnEggProvider)2 BasePotionDataProvider (net.ess3.nms.updatedmeta.BasePotionDataProvider)2 BlockMetaSpawnerProvider (net.ess3.nms.updatedmeta.BlockMetaSpawnerProvider)2 net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider (net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider)2 net.ess3.nms.v1_8_R2.v1_8_R2SpawnerProvider (net.ess3.nms.v1_8_R2.v1_8_R2SpawnerProvider)2 ProviderFactory (net.ess3.providers.ProviderFactory)2