class AgentUtils {

  public static Metainfo getApplicationMetainfo(SliderFileSystem fileSystem,
      String metainfoPath, boolean metainfoForAddon) throws IOException,
      BadConfigException {
    log.info("Reading metainfo at {}", metainfoPath);
    Metainfo metainfo = getApplicationMetainfoFromSummaryFile(fileSystem,
        metainfoPath, metainfoForAddon);
    if (metainfo != null) {
      log.info("Got metainfo from summary file");
      return metainfo;
    }

    FileSystem fs = fileSystem.getFileSystem();
    Path appPath = new Path(metainfoPath);

    InputStream metainfoJsonStream = SliderUtils.getApplicationResourceInputStream(
        fs, appPath, "metainfo.json");
    if (metainfoJsonStream == null) {
      InputStream metainfoXMLStream = SliderUtils.getApplicationResourceInputStream(
          fs, appPath, "metainfo.xml");
      if (metainfoXMLStream != null) {
        metainfo = parseMetainfo(metainfoXMLStream, metainfoForAddon, "xml");
      }
    } else {
      metainfo = parseMetainfo(metainfoJsonStream, metainfoForAddon, "json");
    }

    if (metainfo == null) {
      log.error("metainfo is unavailable at {}.", metainfoPath);
      throw new FileNotFoundException("metainfo.xml/json is required in app package. " +
                                      appPath);
    }
    return metainfo;
  }

}