FileDocCategorySizeDatePackage
AutoDeployDirectoryScanner.javaAPI DocGlassfish v2 API7304Fri May 04 22:34:30 BST 2007com.sun.enterprise.deployment.autodeploy

AutoDeployDirectoryScanner

public class AutoDeployDirectoryScanner extends Object implements DirectoryScanner
Implementation of Directory scanner for autodeployment
Providing functionality for scanning the input source directory
and return the list of deployable components for autodeployment.
Provide the list of deployable modules/application, depending upon the "type" entry
passed to getAllDeployableEntity(File autodeployDir, String type).
author
vikas

Fields Summary
private static final Logger
sLogger
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public AutoDeployDirectoryScanner()

    
      
    
Methods Summary
public voiddeployedEntity(java.io.File autodeployDir, java.io.File deployedEntity)

         try {
         AutoDeployedFilesManager adfm = AutoDeployedFilesManager.loadStatus(autodeployDir);
         adfm.setDeployedFileInfo(deployedEntity);
         adfm.writeStatus();
         } catch (Exception e) {
             printException(e);
             // Do nothing
         }

     
public java.io.File[]getAllDeployableModules(java.io.File autodeployDir, boolean includeSubDir)
Get the list of all deployable files

param
autodeployDir
return

        
        AutoDeployedFilesManager adfm = null;
        try {
        adfm = AutoDeployedFilesManager.loadStatus(autodeployDir);
        } catch (Exception e) {
            printException(e);
            return new File[0];
        }
        
        return adfm.getFilesForDeployment(getListOfFiles(autodeployDir, includeSubDir));
    
public java.io.File[]getAllFilesForUndeployment(java.io.File autodeployDir)


        try {
            AutoDeployedFilesManager adfm = AutoDeployedFilesManager.loadStatus(autodeployDir);
            return adfm.getFilesForUndeployment(getListOfFiles(autodeployDir, true));
            } catch (Exception e) {
                printException(e);
                return new File[0];
            }
    
protected java.io.File[]getListOfFiles(java.io.File dir)

        return getListOfFiles(dir, false);
    
protected java.io.File[]getListOfFiles(java.io.File dir, boolean includeSubDir)

        return getListOfFilesAsSet(dir, includeSubDir).toArray(new File[0]);
    
static java.util.SetgetListOfFilesAsSet(java.io.File dir, boolean includeSubDir)

        Set<File> result = new HashSet<File>();
        File[] dirFiles = dir.listFiles();
        for (File dirFile : dirFiles) {
            String name = dirFile.getName();
            String fileType = name.substring(name.lastIndexOf(".") + 1);
            if (fileType != null && !fileType.equals("") &&
                   (fileType.equals(AutoDeployConstants.EAR_EXTENSION) ||
                    fileType.equals(AutoDeployConstants.WAR_EXTENSION) ||
                    fileType.equals(AutoDeployConstants.JAR_EXTENSION) ||
                    fileType.equals(AutoDeployConstants.RAR_EXTENSION))) {
                    result.add(dirFile);
                    continue;
            }
            if (dirFile.isDirectory()) {
                if (includeSubDir && !(dirFile.getName().equals(".autodeploystatus"))) {
                    result.addAll(getListOfFilesAsSet(dirFile, true));
                }
            } else {
                if(fileType != null && !fileType.equals("") &&
                       (fileType.equals(AutoDeployConstants.ZIP_EXTENSION) ||
                        fileType.equals("class"))) {
                    result.add(dirFile);
                }
                
            }
        }
        return result;
    
public booleanhasNewDeployableEntity(java.io.File autodeployDir)
return true if any new deployable entity is present in autodeployDir

param
autodeployDir
return

        boolean newFilesExist=false;
            try {
                AutoDeployedFilesManager adfm = AutoDeployedFilesManager.loadStatus(autodeployDir);
                if(adfm.getFilesForDeployment(getListOfFiles(autodeployDir)).length > 0) {
                    //atleast one new file is there
                     newFilesExist=true;
                }
            } catch (Exception e) {
                printException(e);
                return false;
            }
        
        return newFilesExist;        
        
    
protected voidprintException(java.lang.Exception e)

        sLogger.log(Level.SEVERE, e.getMessage(), e);
        e.printStackTrace();
    
public voidundeployedEntity(java.io.File autodeployDir, java.io.File undeployedEntity)

         try {
         AutoDeployedFilesManager adfm = AutoDeployedFilesManager.loadStatus(autodeployDir);
         adfm.deleteDeployedFileInfo(undeployedEntity);
         adfm.writeStatus();
         } catch (Exception e) {
             printException(e);
             // Do nothing 
         }