Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * See the file LICENSE for redistribution information.
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
  package com.sleepycat.persist.model;
 import java.util.List;

An ant task for running the ClassEnhancer.

ClassEnhancerTask objects are thread-safe. Multiple threads may safely call the methods of a shared ClassEnhancerTask object.

Note that in the BDB Java Edition product, the ClassEnhancerTask class is included in je-<version>.jar. However, in the BDB (C-based) product, it is not included in db.jar because the build is not dependent on the Ant libraries. Therefore, in the BDB product, the application must compile the java/src/com/sleepycat/persist/model/ source file and ensure that the compiled class is available to the Ant task. For example the following Ant task definitions could be used.

For BDB Java Edition product:

 <taskdef name="enhance-persistent-classes"

For BDB (C-based Edition) product:

 <taskdef name="enhance-persistent-classes"

The class enhancer task element has no attributes. It may contain one or more nested fileset elements specifying the classes to be enhanced. The class files are replaced when they are enhanced, without changing the file modification date. For example:

 <target name="main">
     <enhance-persistent-classes verbose="no">
         <fileset dir="classes"/>

The verbose attribute may be specified as "true", "yes" or "on" (like other Ant boolean attributes) to print the name of each class file that is enhanced. The total number of class files enhanced will always be printed.

Mark Hayes
 public class ClassEnhancerTask extends Task {
     private List<FileSet> fileSets = new ArrayList<FileSet>();
     private boolean verbose;
     public void execute() throws BuildException {
         if (.size() == 0) {
             throw new BuildException("At least one fileset must be specified");
         try {
             int nFiles = 0;
             ClassEnhancer enhancer = new ClassEnhancer();
             for (FileSet fileSet : ) {
                 DirectoryScanner scanner =
                 String[] fileNames = scanner.getIncludedFiles();
                 for (String fileName : fileNames) {
                     File file = new File(scanner.getBasedir(), fileName);
                     try {
                         nFiles += enhancer.enhanceFile(file);
                     } catch (IOException e) {
                         throw new BuildException(e);
             if (nFiles > 0) {
                 ..println("Enhanced: " + nFiles + " files");
         } catch (RuntimeException e) {
             throw e;
    public void addConfiguredFileset(FileSet files) {
    public void setVerbose(boolean verbose) {
        this. = verbose;
New to GrepCode? Check out our FAQ X