Results 1 to 5 of 5
- 02-22-2011, 07:13 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 19
- Rep Power
- 0
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:
- 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
- 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
- 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.
- 02-22-2011, 07:20 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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.
- 02-22-2011, 07:43 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 19
- Rep Power
- 0
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: 1Last edited by pi4r0n; 02-22-2011 at 08:19 PM.
- 02-22-2011, 08:48 PM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
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.
- 02-25-2011, 02:28 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 19
- Rep Power
- 0
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 :)
CheersJava 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; }
pi4r0n
Similar Threads
-
issue with update on table and prepared statement
By hacktorious in forum JDBCReplies: 1Last Post: 01-10-2011, 01:44 AM -
Deployment
By rob in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 04-08-2009, 10:03 PM -
hot deployment
By Manas Das in forum Advanced JavaReplies: 0Last Post: 01-21-2009, 05:24 PM -
Saving JSP causing redeployment (hot deployment issue?)
By kurt_cobain in forum EclipseReplies: 1Last Post: 06-02-2008, 09:13 PM -
web content filter or internet filter
By sundarjothi in forum Advanced JavaReplies: 3Last Post: 05-15-2008, 11:36 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks