@Override
    public void build(final CompileContext context) throws ProjectBuildException {
      JpsProject project = context.getProjectDescriptor().getProject();
      JpsAntBuildFileOptions options = JpsAntExtensionService.getOptions(project, myExtension.getFileUrl());

      JpsTypedLibrary<JpsSdk<JpsDummyElement>> jdkLibrary;
      String jdkName = options.getCustomJdkName();
      if (!StringUtil.isEmpty(jdkName)) {
        jdkLibrary = project.getModel().getGlobal().getLibraryCollection().findLibrary(jdkName, JpsJavaSdkType.INSTANCE);
        if (jdkLibrary == null) {
          reportError(context, "JDK '" + jdkName + "' not found");
          throw new StopBuildException();
        }
      }
      else {
        JpsSdkReference<JpsDummyElement> reference = project.getSdkReferencesTable().getSdkReference(JpsJavaSdkType.INSTANCE);
        if (reference == null) {
          reportError(context, "project JDK is not specified");
          throw new StopBuildException();
        }

        jdkLibrary = reference.resolve();
        if (jdkLibrary == null) {
          reportError(context, "JDK '" + reference.getSdkName() + "' not found");
          throw new StopBuildException();
        }
      }
      JpsSdk<?> jdk = jdkLibrary.getProperties();

      JpsAntInstallation antInstallation = JpsAntExtensionService.getAntInstallationForBuildFile(context.getProjectDescriptor().getModel(),
                                                                                                 myExtension.getFileUrl());
      if (antInstallation == null) {
        reportError(context, "Ant installation is not configured");
        throw new StopBuildException();
      }

      List<String> classpath = new ArrayList<>();
      File jreHome = new File(jdk.getHomePath(), "jre");
      for (File file : jdkLibrary.getFiles(JpsOrderRootType.COMPILED)) {
        if (!FileUtil.isAncestor(jreHome, file, false)) {
          classpath.add(file.getAbsolutePath());
        }
      }
      classpath.addAll(options.getAdditionalClasspath());
      classpath.addAll(antInstallation.getClasspath());
      JpsAntInstallationImpl.addAllJarsFromDirectory(classpath, new File(SystemProperties.getUserHome(), ".ant/lib"));
      classpath.add(PathManager.getJarPathForClass(AntMain2.class));

      List<String> vmParams = new ArrayList<>();
      vmParams.add("-Xmx" + options.getMaxHeapSize() + "m");
      vmParams.add("-Xss" + options.getMaxStackSize() + "m");
      vmParams.add("-Dant.home=" + antInstallation.getAntHome().getAbsolutePath());

      List<String> programParams = new ArrayList<>();
      for (String param : ParametersListUtil.parse(options.getAntCommandLineParameters())) {
        if (param.startsWith("-J")) {
          String vmParam = StringUtil.trimStart(param, "-J");
          if (!vmParam.isEmpty()) {
            vmParams.add(vmParam);
          }
        }
        else {
          programParams.add(param);
        }
      }

      for (List<BuildFileProperty> properties : Arrays.asList(myExtension.getAntProperties(), options.getProperties())) {
        for (BuildFileProperty property : properties) {
          programParams.add("-D" + property.getPropertyName() + "=" + property.getPropertyValue());
        }
      }
      programParams.add("-buildfile");
      final String buildFilePath = JpsPathUtil.urlToPath(myExtension.getFileUrl());
      programParams.add(buildFilePath);
      final String targetName = myExtension.getTargetName();
      if (targetName != null) {
        programParams.add(targetName);
      }

      @NlsSafe String buildFileName = PathUtilRt.getFileName(buildFilePath);

      String targetDisplayName = targetName != null ? targetName : AntJpsBundle.message("ant.target.default.name");
      context.processMessage(new ProgressMessage(AntJpsBundle.message("running.ant.target.from.file", targetDisplayName, buildFileName)));
      Iterable<AntBuildTaskListener> listeners = JpsServiceManager.getInstance().getExtensions(AntBuildTaskListener.class);
      for (AntBuildTaskListener listener : listeners) {
        listener.beforeAntBuildTaskStarted(myExtension, vmParams, programParams);
      }

      List<String> commandLine = ExternalProcessUtil.buildJavaCommandLine(JpsJavaSdkType.getJavaExecutable(jdk), AntMain2.class.getName(),
                                                                          Collections.emptyList(), classpath, vmParams, programParams,
                                                                          false);
      try {
        Process process = new ProcessBuilder(commandLine).directory(new File(buildFilePath).getParentFile()).start();
        String commandLineString = StringUtil.join(commandLine, " ");
        if (LOG.isDebugEnabled()) {
          LOG.debug("Starting ant target:" + commandLineString);
        }
        BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLineString, null);
        final AtomicBoolean hasErrors = new AtomicBoolean();
        @NlsSafe final StringBuilder errorOutput = new StringBuilder();
        handler.addProcessListener(new ProcessAdapter() {
          @Override
          public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
            if (outputType == ProcessOutputTypes.STDERR) {
              errorOutput.append(event.getText());
            }
          }

          @Override
          public void processTerminated(@NotNull ProcessEvent event) {
            int exitCode = event.getExitCode();
            if (exitCode != 0) {
              context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, errorOutput.toString()));

              String message = AntJpsBundle.message("target.finished.with.exit.code", targetName, buildFilePath, exitCode);
              context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, message));
              hasErrors.set(true);
            }
          }
        });
        handler.startNotify();
        handler.waitFor();
        if (hasErrors.get()) {
          throw new StopBuildException();
        }
      }
      catch (IOException e) {
        throw new ProjectBuildException(e);
      }
    }
@Override
    public void build(final CompileContext context)