Results 1 to 5 of 5
  1. #1
    pi4r0n is offline Member
    Join Date
    Jan 2011
    Posts
    19
    Rep Power
    0

    Default Issue with deployment script when if statement/filter not valid

    Hello everyone

    Can I ask you for you assistance please. Before I start let me give you a brief description what I am doing.

    I am working on deployment script which will:

    1. Scan my folder (see below) for a list of folders and store it in ArrayList,
      String buildsLocation = "\\\\10.10.10.10\\Development\\1.0\\v0\\alpha" ;


      Folder example=
      old
      410
      411
      415
      420

    2. then it will get the myListOfDirectoryArray ArrayList index and scan each folder to check whether the build is valid (must have minimum these 2, see exe64IsThere and exe32IsThere ) and save it to a validBuildsList ArrayList

      String exe64IsThere = ("Build 1.0.0." + availableBuilds + "(Win-x64)"); e.g,
      String exe32IsThere = ("Build 1.0.0." + availableBuilds + "(Win-x32)");


      Folder example:-
      Valid folder: 415 with 2 files (Build 1.0.0.415 (Win-x64) and Build 1.0.0.415 (Win-x32))
      Not valid: 420 with 1 file Build 1.0.0.415 (Win-x64) only

    3. when when build is valid (got these 2 files from above) then return string if not it should go back and check the latest valid build / folder which is valid


    The problem I have got is that the script works fine if there are these 2 files, but as soon as there is only 1 file lets say 64 I got NullPointException -1 :(

    Can someone advice what I am doing wrong please ??

    Java Code:
    package deplaysqlmarinamasterscriptv2;
    
    import java.io.*;
    import java.util.*;
    
    /**
     *
     * @author arek.jarosiewicz
     */
    public class Build {
    
        /**
         * This will scan myserver for a the latest build
         * @return build number (latestBuildNumber)
         */
        public static String getLatestBuildNumber() {
    
            String buildsLocation = "\\\\10.10.10.10\\Development\\1.0\\v0\\alpha";
            
            File dir = new File(buildsLocation);
            File listDir[] = dir.listFiles();
    
            String latestBuildNumber = "";
            String availableBuilds = "";
    
            ArrayList<String> myListOfDirectoryArray = new ArrayList<String>();
            ArrayList<String> validBuildsList = new ArrayList<String>();
    
            for (int i = 0; i < listDir.length; i++) {
    
                if (listDir[i].isDirectory()) {
    
                    availableBuilds = listDir[i].getName();
    
                    if (!(availableBuilds.equals("old"))) {
    
                        myListOfDirectoryArray.add(availableBuilds);
    
                        File subFolder = new File(buildsLocation + "\\" + availableBuilds);
                        File filesList[] = subFolder.listFiles();
    
                        for (int k =0; k < filesList.length; k++)
                        {
                            String strFile = filesList[k].getName();
                            String exe64IsThere = ("Build 1.0.0." + availableBuilds + "(Win-x64)");
                            String exe32IsThere = ("Build 1.0.0." + availableBuilds + "(Win-x32)");
    
                            if (strFile.contains(exe64IsThere) || strFile.contains(exe32IsThere))
                            {
                                validBuildsList.add(availableBuilds);
                            }
                        }
                    }
                }
            }
            Collections.sort(validBuildsList);
    
            latestBuildNumber = validBuildsList.get(validBuildsList.size() - 1);
            return latestBuildNumber;
        }
    }
    Last edited by pi4r0n; 02-22-2011 at 08:08 PM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    as there is only 1 file lets say 64 I got NullPointException -1

    Please copy and post the entire stack trace. It will refer to some line number in Build.java and it is a good idea to say which line (of the code you posted) corresponds to that number.

  3. #3
    pi4r0n is offline Member
    Join Date
    Jan 2011
    Posts
    19
    Rep Power
    0

    Default

    Here you go pbrockway2. I think its refernig to this line latestBuildNumber = validBuildsList.get(validBuildsList.size() - 1);

    Java Code:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
            at java.util.ArrayList.get(ArrayList.java:324)
            at deplaysqlmarinamasterscriptv2.Build.getLatestBuildNumber(Build.java:58)
            at deplaysqlmarinamasterscriptv2.Main.main(Main.java:23)
    Java Result: 1
    Last edited by pi4r0n; 02-22-2011 at 08:19 PM.

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    It would appear that validBuildsList.size() is equal to 0 when you reach that line, ArrayIndexOutOfBoundsException: -1 is the exception;

    validBuildsList.size()-1 = -1 , when validBuildsList.size() = 0.
    Last edited by al_Marshy_1981; 02-22-2011 at 08:51 PM.

  5. #5
    pi4r0n is offline Member
    Join Date
    Jan 2011
    Posts
    19
    Rep Power
    0

    Default

    Thanks al_Marshy_1981 for your tip I managed to fix it on the end.

    The problem I had was that I trying to check whether strFile.contains(exe64IsThere) where exe64IsThere was declared as String and contains returns boolean :)

    Java Code:
        public static String getLatestMarinaBuildNumber() {
    
            String buildsLocation = "\\\\10.10.10.10\\Development\\1.0\\v0\\alpha";
            //String buildsLocation = "C:/Alpha";
    
            File dir = new File(buildsLocation);
            File listDir[] = dir.listFiles();
    
            String latestBuildNumber = "";
            String availableBuilds = "";
    
            ArrayList<String> myListOfDirectoryArray = new ArrayList<String>();
            ArrayList<String> listOfFilesArray = new ArrayList<String>();
            ArrayList<String> validBuildsList = new ArrayList<String>();
    
    
    		for (int i = 0; i < listDir.length; i++) {
    
                if (listDir[i].isDirectory()) {
    
                    if (!(availableBuilds.equals("old"))) {
                        availableBuilds = listDir[i].getName();
    
                        File subFolder = new File(buildsLocation + "\\" + availableBuilds);
                        File[] filesList = subFolder.listFiles();
    
                        for (int k = 0; k < filesList.length; k++) {
                            listOfFilesArray.add(filesList[k].getName());
                        }
    
                        boolean found64bit = listOfFilesArray.contains("Build 1.0.0." + availableBuilds + " (Win-x64).exe");
                        boolean found32bit = listOfFilesArray.contains("Build 1.0.0." + availableBuilds + " (Win-x86).exe");
    
                        if (found64bit && found32bit) {
                            myListOfDirectoryArray.add(availableBuilds);
                        } else {
                            myListOfDirectoryArray.remove(availableBuilds);
                        }
                    }
                }
                Collections.sort(validBuildsList);
                           
            }
    
            latestBuildNumber = myListOfDirectoryArray.get(myListOfDirectoryArray.size() - 1);
    
            return latestBuildNumber;
        }
    Cheers

    pi4r0n

Similar Threads

  1. Replies: 1
    Last Post: 01-10-2011, 01:44 AM
  2. Deployment
    By rob in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 04-08-2009, 10:03 PM
  3. hot deployment
    By Manas Das in forum Advanced Java
    Replies: 0
    Last Post: 01-21-2009, 05:24 PM
  4. Replies: 1
    Last Post: 06-02-2008, 09:13 PM
  5. web content filter or internet filter
    By sundarjothi in forum Advanced Java
    Replies: 3
    Last Post: 05-15-2008, 11:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •