/** @throws Exception If failed. */
  @SuppressWarnings({"TypeMayBeWeakened"})
  public void testCorrectAntGarTask() throws Exception {
    String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir");
    String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir");
    String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_0";
    String metaDirName = baseDirName + File.separator + "META-INF";
    String garFileName = baseDirName + ".gar";
    String garDescDirName =
        U.resolveIgnitePath(GridTestProperties.getProperty("ant.gar.descriptor.dir"))
                .getAbsolutePath()
            + File.separator
            + "ignite.xml";

    // Make base and META-INF dir.
    boolean mkdir = new File(baseDirName).mkdirs();

    assert mkdir;

    mkdir = new File(metaDirName).mkdirs();

    assert mkdir;

    // Make Gar file
    U.copy(new File(garDescDirName), new File(metaDirName + File.separator + "ignite.xml"), true);

    // Copy files to basedir
    U.copy(new File(srcDirName), new File(baseDirName), true);

    IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask();

    Project garProject = new Project();

    garProject.setName("Gar test project");

    garTask.setDestFile(new File(garFileName));
    garTask.setBasedir(new File(baseDirName));
    garTask.setProject(garProject);

    garTask.execute();

    File garFile = new File(garFileName);

    assert garFile.exists();

    boolean res = checkStructure(garFile, true);

    assert res;
  }
  /**
   * @param garFile GAR file.
   * @param hasDescr Whether GAR file has descriptor.
   * @throws IOException If GAR file is not found.
   * @return Whether GAR file structure is correct.
   */
  private boolean checkStructure(File garFile, boolean hasDescr) throws IOException {
    ZipFile zip = new ZipFile(garFile);

    String descr = "META-INF/ignite.xml";

    ZipEntry entry = zip.getEntry(descr);

    if (entry == null && !hasDescr) {
      if (log().isInfoEnabled()) {
        log()
            .info(
                "Process deployment without descriptor file [path="
                    + descr
                    + ", file="
                    + garFile.getAbsolutePath()
                    + ']');
      }

      return true;
    } else if (entry != null && hasDescr) {
      InputStream in = null;

      try {
        in = new BufferedInputStream(zip.getInputStream(entry));

        return true;
      } finally {
        U.close(in, log());
      }
    } else return false;
  }