All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.bonita.ant.tasks.GenerateBar Maven / Gradle / Ivy

package org.ow2.bonita.ant.tasks;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.ow2.bonita.util.BusinessArchiveFactory;
import org.ow2.bonita.util.Misc;

public class GenerateBar extends Task {

  private static final Logger LOG = Logger.getLogger(GenerateBar.class.getName());
  
  protected File destfile = null;
  protected Collection fileSets = new ArrayList();

  public void setDestfile(File destfile) {
    this.destfile = destfile;
  }

  public void addFileset(FileSet fileSet) {
    fileSets.add(fileSet);
  }

  @Override
  public void execute() {
    if (destfile == null) {
      throw new BuildException("You must specify destfile attribute for task " + this.getClass().getName());
    }
    try {
      if (!destfile.exists()) {
        destfile.createNewFile();
      }
      Map resources = new HashMap();
      for (FileSet fileSet : fileSets) {
        DirectoryScanner directoryScanner = fileSet.getDirectoryScanner(getProject()); 
        String[] files = directoryScanner.getIncludedFiles();
        for (String file : files) {
          File f = new File(directoryScanner.getBasedir().getAbsolutePath() + File.separatorChar + file);
          if (!f.exists()) {
            LOG.severe("File : " + f + " does not exist. Can't add it to the BAR.");
          }
          resources.put(file, Misc.getAllContentFrom(f));
        }
      }
      if (resources.isEmpty()) {
        throw new BuildException("Resources is empty. Please add filesets under task " + this.getClass().getName());
      }
      
      BusinessArchiveFactory.generateBusinessArchiveFile(destfile, resources);
    } catch (IOException e) {
      throw new BuildException(e);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy