예제 #1
0
 public void testLoadUnknounClassTag() {
   try {
     Yaml yaml = new Yaml();
     yaml.load(Util.getLocalResource("constructor/car-without-tags.yaml"));
     fail("Must fail because of unknown tag: !car");
   } catch (YAMLException e) {
     assertTrue(e.getMessage().contains("Invalid tag: !car"));
   }
 }
  @SuppressWarnings("unchecked")
  public void deploy(VFSDeploymentUnit unit) throws DeploymentException {
    TorqueBoxMetaData globalMetaData = unit.getAttachment(TorqueBoxMetaData.class);

    log.debug("Global torquebox.yml: " + globalMetaData);

    Object data = null;

    if (globalMetaData != null) {
      data = globalMetaData.getSection(getSectionName());
      log.debug("Global data section for " + getSectionName() + ": " + data);
    }

    if (data == null && isSupportsStandalone()) {
      VirtualFile metaDataFile = getMetaDataFile(unit, getFileName());

      if ((metaDataFile != null) && metaDataFile.exists()) {
        log.warn("Usage of " + getFileName() + " is deprecated.  Please use torquebox.yml.");
        InputStream in = null;
        try {
          in = metaDataFile.openStream();
          Yaml yaml = new Yaml();
          data = (Map<String, ?>) yaml.load(in);
        } catch (YAMLException e) {
          log.warn("Error parsing: " + metaDataFile + ": " + e.getMessage());
          data = null;
        } catch (IOException e) {
          throw new DeploymentException(e);
        } finally {
          if (in != null) {
            try {
              in.close();
            } catch (IOException e) {
              throw new DeploymentException(e);
            }
          }
        }
      }
    }

    if (data == null) {
      return;
    }

    try {
      parse(unit, data);
    } catch (DeploymentException e) {
      throw e;
    } catch (Exception e) {
      throw new DeploymentException(e);
    }
  }
  /**
   * Validate the response is in expected yaml format
   *
   * @param response response
   * @return Collection of job data maps if format is correct and there is no error
   * @throws com.dtolabs.client.services.CentralDispatcherServerRequestException if the format is
   *     incorrect, or the response indicates an error response.
   */
  private Collection<Map> validateJobsResponseYAML(final WebserviceResponse response)
      throws CentralDispatcherServerRequestException {
    if (null == response) {
      throw new CentralDispatcherServerRequestException("Response was null");
    }

    if (null != response.getResponseMessage()) {
      logger.info("Response: " + response.getResponseMessage());
    }
    String resultContentType = response.getResultContentType();
    if (resultContentType.contains(";")) {
      resultContentType = resultContentType.substring(0, resultContentType.indexOf(";"));
    }
    if (!resultContentType.endsWith("/yaml")) {
      throw new CentralDispatcherServerRequestException(
          "Expected YAML response, unexpected content type: " + response.getResultContentType());
    }
    final ArrayList<Map> dataset = new ArrayList<Map>();
    final Object resobj;
    try {
      final Yaml yaml = new Yaml(new SafeConstructor());
      resobj = yaml.load(response.getResults());
    } catch (YAMLException e) {
      throw new CentralDispatcherServerRequestException(
          "Failed to parse YAML: " + e.getMessage(), e);
    }
    if (resobj instanceof Collection) {
      dataset.addAll((Collection) resobj);
    } else {
      throw new CentralDispatcherServerRequestException(
          "Response had unexpected content type: " + resobj);
    }

    for (final Map map : dataset) {
      if (!map.containsKey("name") || !map.containsKey("id") && !map.containsKey("uuid")) {
        throw new CentralDispatcherServerRequestException(
            "Response had unexpected dataset: " + resobj);
      }
    }
    return dataset;
  }
  @SuppressWarnings("unchecked")
  protected void parse(
      VFSDeploymentUnit unit, VirtualFile file, RubyRuntimeMetaData runtimeMetaData)
      throws Exception {

    Yaml yaml = new Yaml();
    try {
      Map<String, Object> config = (Map<String, Object>) yaml.load(file.openStream());

      if (config != null) {
        Object version = config.get("version");
        if ("1.8".equals("" + version)) {
          runtimeMetaData.setVersion(RubyRuntimeMetaData.Version.V1_8);
        } else if ("1.9".equals("" + version)) {
          runtimeMetaData.setVersion(RubyRuntimeMetaData.Version.V1_9);
        }
      }
    } catch (YAMLException e) {
      log.error("Error parsing ruby.yml: " + e.getMessage());
    }
  }
예제 #5
0
	@Override
	public void onEnable()
	{
		execTimer = new ExecuteTimer();
		execTimer.start();
		i18n = new I18n(this);
		i18n.onEnable();
		execTimer.mark("I18n1");
		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"))
			{
				LOGGER.log(Level.WARNING, _("versionMismatch", plugin.getDescription().getName()));
			}
		}
		final Matcher versionMatch = Pattern.compile("git-Bukkit-(?:(?:[0-9]+)\\.)+[0-9]+-R[\\.0-9]+-(?:[0-9]+-g[0-9a-f]+-)?b([0-9]+)jnks.*").matcher(getServer().getVersion());
		if (versionMatch.matches())
		{
			final int versionNumber = Integer.parseInt(versionMatch.group(1));
			if (versionNumber < BUKKIT_VERSION && versionNumber > 100)
			{
				LOGGER.log(Level.SEVERE, " * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! *");
				LOGGER.log(Level.SEVERE, _("notRecommendedBukkit"));
				LOGGER.log(Level.SEVERE, _("requiredBukkit", Integer.toString(BUKKIT_VERSION)));
				LOGGER.log(Level.SEVERE, " * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! *");
				this.setEnabled(false);
				return;
			}
		}
		else
		{
			LOGGER.log(Level.INFO, _("bukkitFormatChanged"));
			LOGGER.log(Level.INFO, getServer().getVersion());
			LOGGER.log(Level.INFO, getServer().getBukkitVersion());
		}
		execTimer.mark("BukkitCheck");
		try
		{
			final EssentialsUpgrade upgrade = new EssentialsUpgrade(this);
			upgrade.beforeSettings();
			execTimer.mark("Upgrade");
			confList = new ArrayList<IConf>();
			settings = new Settings(this);
			confList.add(settings);
			execTimer.mark("Settings");
			upgrade.afterSettings();
			execTimer.mark("Upgrade2");
			i18n.updateLocale(settings.getLocale());
			userMap = new UserMap(this);
			confList.add(userMap);
			execTimer.mark("Init(Usermap)");
			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)");
			reload();
		}
		catch (YAMLException exception)
		{
			if (pm.getPlugin("EssentialsUpdate") != null)
			{
				LOGGER.log(Level.SEVERE, _("essentialsHelp2"));
			}
			else
			{
				LOGGER.log(Level.SEVERE, _("essentialsHelp1"));
			}
			LOGGER.log(Level.SEVERE, exception.toString());
			pm.registerEvents(new Listener()
			{
				@EventHandler(priority = EventPriority.LOW)
				public void onPlayerJoin(final PlayerJoinEvent event)
				{
					event.getPlayer().sendMessage("Essentials failed to load, read the log file.");
				}
			}, this);
			for (Player player : getServer().getOnlinePlayers())
			{
				player.sendMessage("Essentials failed to load, read the log file.");
			}
			this.setEnabled(false);
			return;
		}
		backup = new Backup(this);
		permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions());
		alternativeCommandsHandler = new AlternativeCommandsHandler(this);
		final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
		pm.registerEvents(serverListener, this);
		confList.add(serverListener);

		final EssentialsPlayerListener playerListener = new EssentialsPlayerListener(this);
		pm.registerEvents(playerListener, this);

		final EssentialsBlockListener blockListener = new EssentialsBlockListener(this);
		pm.registerEvents(blockListener, this);

		final SignBlockListener signBlockListener = new SignBlockListener(this);
		pm.registerEvents(signBlockListener, this);

		final SignPlayerListener signPlayerListener = new SignPlayerListener(this);
		pm.registerEvents(signPlayerListener, this);

		final SignEntityListener signEntityListener = new SignEntityListener(this);
		pm.registerEvents(signEntityListener, this);

		final EssentialsEntityListener entityListener = new EssentialsEntityListener(this);
		pm.registerEvents(entityListener, this);

		final EssentialsWorldListener worldListener = new EssentialsWorldListener(this);
		pm.registerEvents(worldListener, this);

		//TODO: Check if this should be here, and not above before reload()
		jails = new Jails(this);
		confList.add(jails);

		pm.registerEvents(tntListener, this);

		final EssentialsTimer timer = new EssentialsTimer(this);
		getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100);
		Economy.setEss(this);
		execTimer.mark("RegListeners");

		final MetricsStarter metricsStarter = new MetricsStarter(this);
		if (metricsStarter.getStart() != null && metricsStarter.getStart() == true)
		{
			getScheduler().scheduleAsyncDelayedTask(this, metricsStarter, 1);
		}
		else if (metricsStarter.getStart() != null && metricsStarter.getStart() == false)
		{
			final MetricsListener metricsListener = new MetricsListener(this, metricsStarter);
			pm.registerEvents(metricsListener, this);
		}

		final String timeroutput = execTimer.end();
		if (getSettings().isDebug())
		{
			LOGGER.log(Level.INFO, "Essentials load " + timeroutput);
		}
	}