You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2007/06/06 11:23:08 UTC

DO NOT REPLY [Bug 42603] New: - enhance to search for files using wildecards

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42603>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=42603

           Summary: enhance <available> to search for files using wildecards
           Product: Ant
           Version: 1.6.5
          Platform: Other
        OS/Version: Windows XP
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: Core
        AssignedTo: dev@ant.apache.org
        ReportedBy: christof.engel@web.de


As I use ant to syncronize my buildprocess over seperated computers, I need to
know, if some is still building or not. I do that over filesystem with files
like "abc.building" "def.building" etc.

Now, the main task should wait until none of the others is building any more. 
Until today (I modified my ant version today to achieve the goal) I have to
write it like this:
    <waitfor maxwait="60" maxwaitunit="minute" checkevery="5"
checkeveryunit="second" timeoutproperty="waitforOthersTimeout">
      <not>
        <or>
      <available file="${buildsrv_exchange}\list_abc.building"/>
      <available file="${buildsrv_exchange}\list_def.building"/>
      <available file="${buildsrv_exchange}\list_something.building"/>
      <available file="${buildsrv_exchange}\list_abc.shouldstart"/>
      <available file="${buildsrv_exchange}\list_def.shouldstart"/>
      <available file="${buildsrv_exchange}\list_something.shouldstart"/>
        </or>
      </not>
    </waitfor>

I now can write this like this:
 <available MatchFilename="list*.building" MatchFilepath="${buildsrv_exchange}"/>
 <available MatchFilename="list*.shouldstart"     
MatchFilepath="${buildsrv_exchange}"/>

I have not only 2 tasks to wait for, but many, so it is in deed a gread
enhancement if I can be able to use wildcards like '*" and '?'.

The code is not perfect, but a quick-and-dirty hack for <available>, the
"MatchFilepath" must be set in that case, you can do that better and use the
existend "filepath" instead of introducing a new "MatchFilepath". You can also
easyly add a "scanSubdir" feature.
But here it is (additional lines for Available.java (in v.1.6.5):
add:
    private String matchFilepath = null;
enhance:
    private boolean checkFile() {
        if (matchFilepath != null) {
            return checkMatchFilePath(file, false);
        }

add:
  /**
   * Check if a given filename exists and matches the pattern (no RegEx)
   */

  public void setMatchFilename(String filename) {
    this.filename = filename;
  }
  public void setMatchFilepath(String path) {
    this.matchFilepath = path;
    this.file = new File(path);
  }

	private boolean stringCompare(String strCompare, String strSource) {
		int i = 0;
		int l = strCompare.length();
		if (strSource.length() < l) {
			return false;
		}
		if (strCompare.equalsIgnoreCase(strSource)) {
			return true;
		}
		boolean bMatch = true;
		while (bMatch && (i < l)) {
			switch (strCompare.charAt(i)) {
			case '?':
				break; // ignore single char
			case '*':
				i = l; // ignore rest
				break;
			default:
				if (strCompare.charAt(i) != strSource.charAt(i)) {
					bMatch = false; // Stop here.
				}
				break;
			}
			i++;
		}
		return bMatch;
	}

	private boolean filenameMatchesFilter(String sFilename, String sFilter) {
		if (sFilter.length() == 0) 
		  return true;
		int i = sFilter.lastIndexOf(".");
		int j;
		// filter has file extension?
		if (i > 0) {
			j = sFilename.lastIndexOf(".");
			if (j > 0) {
				// check file extension seperatly
				if (stringCompare(sFilter.substring(i + 1), sFilename.substring(j + 1))) {
					// check filename (without ext)
					return (stringCompare(sFilter.substring(0, i), sFilename.substring(0, j)));
				}
			} else {
				// file has no extension, check filter extension is .*
				if (stringCompare(sFilter.substring(i + 1), "*")) {
					// check filename (without ext)
					return (stringCompare(sFilter.substring(0, i - 1), sFilename));
				}
			}
		} else {
			// filter without file extension
			return (stringCompare(sFilter, sFilename));
		}
		return false;
	}

	private boolean fileMatchFilter(String fi, String filename) {
		if (fi != null) {
			if ((fi == "*.*") || (fi == "*")) {
				// this normally means "all files"
				return true;
			}
			if (filenameMatchesFilter(filename.toUpperCase(), fi.toUpperCase())) {
				return true;
			}
		}
		return false;
	}

  private boolean checkMatchFilePath(File recurDir, boolean scanSubdirs) {
    if ((!recurDir.exists()) || (!recurDir.isDirectory())) {
      return false;
    }
    int i;
    File aDirectory = null;
    File[] aDirList = recurDir.listFiles();
    if (aDirList != null && aDirList.length > 0) {
      for (i = 0; i < aDirList.length; i++) {
        aDirectory = aDirList[i];
        if (aDirectory.canRead()) {
          if (aDirectory.isDirectory()) {
            if (scanSubdirs) {
              if (checkMatchFilePath(aDirectory, true)) {
                return true;
              }
            }
          } else {
            if (fileMatchFilter(this.filename, aDirectory.getName())) {
              return true;
            }
          }
        }
      }
    }
    return false;
  }

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


DO NOT REPLY [Bug 42603] - enhance to search for files using wildecards

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42603>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=42603





------- Additional Comments From carej@us.ibm.com  2007-06-06 05:12 -------
Available already accepts a nested path structure, which in turn accepts a
nested fileset, which in turn already accepts wildcards.

So basically, you can already do this today without any modifications to Ant;
maybe check the user list next time?

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


DO NOT REPLY [Bug 42603] - enhance to search for files using wildecards

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42603>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=42603


gudnabrsam@yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME




------- Additional Comments From gudnabrsam@yahoo.com  2007-06-06 07:18 -------
indeed; I don't see anything here that can't be done in Ant 1.7.  Start with the following, and if you get 
stuck, bring it to user@ant.apache.org:

<waitfor>
  <resourcecount count="0">
    <fileset dir="${buildsrv_exchange}" includes="**/list_*.building,**/list_*.shouldstart" />
  </resourcecount>
</waitfor>



-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


DO NOT REPLY [Bug 42603] - enhance to search for files using wildecards

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42603>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=42603





------- Additional Comments From stevel@apache.org  2007-06-06 05:05 -------
I dont think this should go in available, as available is overloaded. But a
separate findfile task might be useful, especially if it sets a property to the
name of the file that matches. 

I think you may be able to play games with selectors and filesets to achieve the
same result.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


DO NOT REPLY [Bug 42603] - enhance to search for files using wildecards

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42603>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=42603





------- Additional Comments From christof.engel@web.de  2007-06-06 08:11 -------
OK, I don't have tried ANT v1.7 so far, the resourcecount tag was not present in
Ant 1.6.5, so I will try switching to ANT 1.7 and use that.
Thanks so far.

> <waitfor>
>   <resourcecount count="0">
>     <fileset dir="${buildsrv_exchange}"
includes="**/list_*.building,**/list_*.shouldstart" />
>   </resourcecount>
> </waitfor>
> 



-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org