mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-06 08:36:01 +00:00
Merge pull request #1429 from dominiquebrice/jenkins-5253b
[JENKINS-5253] Allow case insensitive patterns in Artifacts Archiving
This commit is contained in:
commit
4fd10ed723
8 files changed
+111
-25
No files matched your search
@@ -2345,7 +2345,14 @@ public final class FilePath implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Default bound for {@link #validateAntFileMask(String, int)}.
|
||||
* Same as {@link #validateFileMask(String, int, boolean)} with caseSensitive set to true
|
||||
*/
|
||||
public String validateAntFileMask(final String fileMasks, final int bound) throws IOException, InterruptedException {
|
||||
return validateAntFileMask(fileMasks, bound, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default bound for {@link #validateAntFileMask(String, int, boolean)}.
|
||||
* @since 1.592
|
||||
*/
|
||||
public static int VALIDATE_ANT_FILE_MASK_BOUND = Integer.getInteger(FilePath.class.getName() + ".VALIDATE_ANT_FILE_MASK_BOUND", 10000);
|
||||
@@ -2363,7 +2370,7 @@ public final class FilePath implements Serializable {
|
||||
* @throws InterruptedException not only in case of a channel failure, but also if too many operations were performed without finding any matches
|
||||
* @since 1.484
|
||||
*/
|
||||
public String validateAntFileMask(final String fileMasks, final int bound) throws IOException, InterruptedException {
|
||||
public String validateAntFileMask(final String fileMasks, final int bound, final boolean caseSensitive) throws IOException, InterruptedException {
|
||||
return act(new MasterToSlaveFileCallable<String>() {
|
||||
private static final long serialVersionUID = 1;
|
||||
public String invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException {
|
||||
@@ -2374,15 +2381,21 @@ public final class FilePath implements Serializable {
|
||||
|
||||
while(tokens.hasMoreTokens()) {
|
||||
final String fileMask = tokens.nextToken().trim();
|
||||
if(hasMatch(dir,fileMask))
|
||||
if(hasMatch(dir,fileMask,caseSensitive))
|
||||
continue; // no error on this portion
|
||||
|
||||
// JENKINS-5253 - if we can get some match in case insensitive mode
|
||||
// and user requested case sensitive match, notify the user
|
||||
if (caseSensitive && hasMatch(dir, fileMask, false)) {
|
||||
return Messages.FilePath_validateAntFileMask_matchWithCaseInsensitive(fileMask);
|
||||
}
|
||||
|
||||
// in 1.172 we introduced an incompatible change to stop using ' ' as the separator
|
||||
// so see if we can match by using ' ' as the separator
|
||||
if(fileMask.contains(" ")) {
|
||||
boolean matched = true;
|
||||
for (String token : Util.tokenize(fileMask))
|
||||
matched &= hasMatch(dir,token);
|
||||
matched &= hasMatch(dir,token,caseSensitive);
|
||||
if(matched)
|
||||
return Messages.FilePath_validateAntFileMask_whitespaceSeprator();
|
||||
}
|
||||
@@ -2398,7 +2411,7 @@ public final class FilePath implements Serializable {
|
||||
if(idx==-1) break;
|
||||
f=f.substring(idx+1);
|
||||
|
||||
if(hasMatch(dir,f))
|
||||
if(hasMatch(dir,f,caseSensitive))
|
||||
return Messages.FilePath_validateAntFileMask_doesntMatchAndSuggest(fileMask,f);
|
||||
}
|
||||
}
|
||||
@@ -2406,6 +2419,7 @@ public final class FilePath implements Serializable {
|
||||
{// check the (2) above next as this is more expensive.
|
||||
// Try prepending "**/" to see if that results in a match
|
||||
FileSet fs = Util.createFileSet(reading(dir),"**/"+fileMask);
|
||||
fs.setCaseSensitive(caseSensitive);
|
||||
DirectoryScanner ds = fs.getDirectoryScanner(new Project());
|
||||
if(ds.getIncludedFilesCount()!=0) {
|
||||
// try shorter name first so that the suggestion results in least amount of changes
|
||||
@@ -2425,7 +2439,7 @@ public final class FilePath implements Serializable {
|
||||
|
||||
prefix+=f.substring(0,idx)+'/';
|
||||
f=f.substring(idx+1);
|
||||
if(hasMatch(dir,prefix+fileMask))
|
||||
if(hasMatch(dir,prefix+fileMask,caseSensitive))
|
||||
return Messages.FilePath_validateAntFileMask_doesntMatchAndSuggest(fileMask, prefix+fileMask);
|
||||
}
|
||||
}
|
||||
@@ -2437,7 +2451,7 @@ public final class FilePath implements Serializable {
|
||||
String pattern = fileMask;
|
||||
|
||||
while(true) {
|
||||
if(hasMatch(dir,pattern)) {
|
||||
if(hasMatch(dir,pattern,caseSensitive)) {
|
||||
// found a match
|
||||
if(previous==null)
|
||||
return Messages.FilePath_validateAntFileMask_portionMatchAndSuggest(fileMask,pattern);
|
||||
@@ -2463,7 +2477,7 @@ public final class FilePath implements Serializable {
|
||||
return null; // no error
|
||||
}
|
||||
|
||||
private boolean hasMatch(File dir, String pattern) throws InterruptedException {
|
||||
private boolean hasMatch(File dir, String pattern, boolean bCaseSensitive) throws InterruptedException {
|
||||
class Cancel extends RuntimeException {}
|
||||
DirectoryScanner ds = bound == Integer.MAX_VALUE ? new DirectoryScanner() : new DirectoryScanner() {
|
||||
int ticks;
|
||||
@@ -2481,6 +2495,7 @@ public final class FilePath implements Serializable {
|
||||
};
|
||||
ds.setBasedir(reading(dir));
|
||||
ds.setIncludes(new String[] {pattern});
|
||||
ds.setCaseSensitive(bCaseSensitive);
|
||||
try {
|
||||
ds.scan();
|
||||
} catch (Cancel c) {
|
||||
@@ -2507,18 +2522,32 @@ public final class FilePath implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for {@link #validateFileMask(String)} in case the left-hand side can be null.
|
||||
* Short for {@code validateFileMask(path, value, true)}
|
||||
*/
|
||||
public static FormValidation validateFileMask(@CheckForNull FilePath path, String value) throws IOException {
|
||||
return FilePath.validateFileMask(path, value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for {@link #validateFileMask(String,true,boolean)} as the left-hand side can be null.
|
||||
*/
|
||||
public static FormValidation validateFileMask(@CheckForNull FilePath path, String value, boolean caseSensitive) throws IOException {
|
||||
if(path==null) return FormValidation.ok();
|
||||
return path.validateFileMask(value);
|
||||
return path.validateFileMask(value, true, caseSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Short for {@code validateFileMask(value,true)}
|
||||
* Short for {@code validateFileMask(value, true, true)}
|
||||
*/
|
||||
public FormValidation validateFileMask(String value) throws IOException {
|
||||
return validateFileMask(value,true);
|
||||
return validateFileMask(value, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Short for {@code validateFileMask(value, errorIfNotExist, true)}
|
||||
*/
|
||||
public FormValidation validateFileMask(String value, boolean errorIfNotExist) throws IOException {
|
||||
return validateFileMask(value, errorIfNotExist, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2527,7 +2556,7 @@ public final class FilePath implements Serializable {
|
||||
* or admin permission if no such ancestor is found.
|
||||
* @since 1.294
|
||||
*/
|
||||
public FormValidation validateFileMask(String value, boolean errorIfNotExist) throws IOException {
|
||||
public FormValidation validateFileMask(String value, boolean errorIfNotExist, boolean caseSensitive) throws IOException {
|
||||
checkPermissionForValidate();
|
||||
|
||||
value = fixEmpty(value);
|
||||
@@ -2538,7 +2567,7 @@ public final class FilePath implements Serializable {
|
||||
if(!exists()) // no workspace. can't check
|
||||
return FormValidation.ok();
|
||||
|
||||
String msg = validateAntFileMask(value, VALIDATE_ANT_FILE_MASK_BOUND);
|
||||
String msg = validateAntFileMask(value, VALIDATE_ANT_FILE_MASK_BOUND, caseSensitive);
|
||||
if(errorIfNotExist) return FormValidation.error(msg);
|
||||
else return FormValidation.warning(msg);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
Reference in new issue
Block a user