Example #1
0
  @Override
  public void execute() throws MojoExecutionException, MojoFailureException {
    super.execute();
    compiler.setOutputDirectory(outputDirectory);

    try {
      String outputDirectoryName = OutputNamesHelper.getHarValidationOutput(project.getArtifact());
      File outputBase = new File(outputDirectory, outputDirectoryName);

      if (!outputBase.exists()) outputBase.mkdirs();

      if (!skipValidation) {
        validateTargets(outputBase);
      } else {
        getLog().warn("Validation skipped");
      }

      File metadata = createHarMetadata(outputBase);

      ZipArchiver archiver = new ZipArchiver();
      archiver.addFile(metadata, HarMetadata.METADATA_FILE_NAME);

      for (String compileRoot : project.getCompileSourceRoots()) {
        archiver.addDirectory(new File(compileRoot));
      }

      for (File resourceDir : ProjectHelper.getResourceDirectories(project)) {
        archiver.addDirectory(resourceDir);
      }

      File destFile =
          new File(
              outputDirectory, project.getBuild().getFinalName() + "." + HaxeFileExtensions.HAR);
      archiver.setDestFile(destFile);
      archiver.createArchive();
      project.getArtifact().setFile(destFile);
    } catch (IOException e) {
      throw new MojoFailureException("Error occurred during `har` package creation", e);
    } catch (Exception e) {
      throw new MojoFailureException("Har validation failed", e);
    }
  }