Skip to content

Commit

Permalink
[FIXED JENKINS-13693] Add option to disable default excludes
Browse files Browse the repository at this point in the history
  • Loading branch information
bap2000 committed Jul 24, 2012
1 parent 501a237 commit 9b8cd2d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 10 deletions.
52 changes: 44 additions & 8 deletions src/main/java/jenkins/plugins/publish_over/BPTransfer.java
Expand Up @@ -62,6 +62,18 @@ private static FilePath[] listWithExcludes(final FilePath base, final String inc
}
}

@SuppressWarnings("PMD.PreserveStackTrace") // coz the ITE itself is not interesting!
private static FilePath[] listWithNoDefaultExcludes(final FilePath base, final String includes, final String excludes, final boolean noDefaultExcludes) {
final Method list = listWithNoDefaultExcludesMethod();
try {
return (FilePath[]) list.invoke(base, includes, excludes, !noDefaultExcludes);
} catch (IllegalAccessException iae) {
throw new BapPublisherException("No chance!", iae);
} catch (InvocationTargetException ite) {
throw new BapPublisherException(Messages.exception_invokeListNoDefaultExcludes(includes, excludes, noDefaultExcludes), ite.getCause());
}
}

private static Method listWithExcludesMethod() {
try {
return FilePath.class.getMethod("list", String.class, String.class);
Expand All @@ -70,38 +82,53 @@ private static Method listWithExcludesMethod() {
}
}

private static Method listWithNoDefaultExcludesMethod() {
try {
return FilePath.class.getMethod("list", String.class, String.class, boolean.class);
} catch (NoSuchMethodException nsme) {
return null;
}
}

public static boolean canUseExcludes() {
return listWithExcludesMethod() != null;
}

public static boolean canUseNoDefaultExcludes() {
return listWithNoDefaultExcludesMethod() != null;
}

private String remoteDirectory;
private String sourceFiles;
private String excludes;
private String removePrefix;
private boolean remoteDirectorySDF;
private boolean flatten;
private boolean cleanRemote;
private boolean noDefaultExcludes;

// retain original constructor for testing as don't compile against new enough core to enable testing of excludes!
BPTransfer(final String sourceFiles, final String remoteDirectory, final String removePrefix,
final boolean remoteDirectorySDF, final boolean flatten) {
this(sourceFiles, null, remoteDirectory, removePrefix, remoteDirectorySDF, flatten, false);
this(sourceFiles, null, remoteDirectory, removePrefix, remoteDirectorySDF, flatten, false, false);
}

public BPTransfer(final String sourceFiles, final String excludes, final String remoteDirectory, final String removePrefix,
final boolean remoteDirectorySDF, final boolean flatten) {
this(sourceFiles, excludes, remoteDirectory, removePrefix, remoteDirectorySDF, flatten, false);
this(sourceFiles, excludes, remoteDirectory, removePrefix, remoteDirectorySDF, flatten, false, false);
}

public BPTransfer(final String sourceFiles, final String excludes, final String remoteDirectory, final String removePrefix,
final boolean remoteDirectorySDF, final boolean flatten, final boolean cleanRemote) {
final boolean remoteDirectorySDF, final boolean flatten, final boolean cleanRemote,
final boolean noDefaultExcludes) {
this.sourceFiles = sourceFiles;
this.excludes = excludes;
this.remoteDirectory = remoteDirectory;
this.removePrefix = removePrefix;
this.remoteDirectorySDF = remoteDirectorySDF;
this.flatten = flatten;
this.cleanRemote = cleanRemote;
this.noDefaultExcludes = noDefaultExcludes;
}

public String getRemoteDirectory() { return remoteDirectory; }
Expand All @@ -125,6 +152,9 @@ public BPTransfer(final String sourceFiles, final String excludes, final String
public boolean isCleanRemote() { return cleanRemote; }
public void setCleanRemote(final boolean cleanRemote) { this.cleanRemote = cleanRemote; }

public boolean isNoDefaultExcludes() { return noDefaultExcludes; }
public void setNoDefaultExcludes(final boolean noDefaultExcludes) { this.noDefaultExcludes = noDefaultExcludes; }

public boolean hasConfiguredSourceFiles() {
return Util.fixEmptyAndTrim(getSourceFiles()) != null;
}
Expand All @@ -138,8 +168,12 @@ public FilePath[] getSourceFiles(final BPBuildInfo buildInfo) throws IOException
if (useExcludes)
LOG.debug(Messages.log_excludes(excludes, expandedExcludes));
}
return useExcludes ? listWithExcludes(buildInfo.getBaseDirectory(), expanded, expandedExcludes)
: buildInfo.getBaseDirectory().list(expanded);
if (canUseNoDefaultExcludes())
return listWithNoDefaultExcludes(buildInfo.getBaseDirectory(), expanded, expandedExcludes, noDefaultExcludes);
else if (useExcludes)
return listWithExcludes(buildInfo.getBaseDirectory(), expanded, expandedExcludes);
else
return buildInfo.getBaseDirectory().list(expanded);
}

private void assertBaseDirectoryExists(final BPBuildInfo buildInfo) throws Exception {
Expand Down Expand Up @@ -299,7 +333,7 @@ private void resetToSubDirectory() throws IOException {

protected HashCodeBuilder addToHashCode(final HashCodeBuilder builder) {
return builder.append(sourceFiles).append(removePrefix).append(remoteDirectory)
.append(remoteDirectorySDF).append(flatten).append(cleanRemote).append(excludes);
.append(remoteDirectorySDF).append(flatten).append(cleanRemote).append(excludes).append(noDefaultExcludes);
}

protected EqualsBuilder addToEquals(final EqualsBuilder builder, final BPTransfer that) {
Expand All @@ -309,7 +343,8 @@ protected EqualsBuilder addToEquals(final EqualsBuilder builder, final BPTransfe
.append(remoteDirectory, that.remoteDirectory)
.append(remoteDirectorySDF, that.remoteDirectorySDF)
.append(flatten, that.flatten)
.append(cleanRemote, that.cleanRemote);
.append(cleanRemote, that.cleanRemote)
.append(noDefaultExcludes, that.noDefaultExcludes);
}

protected ToStringBuilder addToToString(final ToStringBuilder builder) {
Expand All @@ -319,7 +354,8 @@ protected ToStringBuilder addToToString(final ToStringBuilder builder) {
.append("remoteDirectory", remoteDirectory)
.append("remoteDirectorySDF", remoteDirectorySDF)
.append("flatten", flatten)
.append("cleanRemote", cleanRemote);
.append("cleanRemote", cleanRemote)
.append("noDefaultExcludes", noDefaultExcludes);
}

public boolean equals(final Object that) {
Expand Down
Expand Up @@ -97,4 +97,9 @@ public boolean isFlatten() {
public boolean isCleanRemote() {
return false;
}

public boolean isNoDefaultExcludes() {
return false;
}

}
Expand Up @@ -40,4 +40,6 @@ public interface TransferOptions {

boolean isCleanRemote();

boolean isNoDefaultExcludes();

}
Expand Up @@ -46,6 +46,7 @@ exception.failedToGetPromotedBuild=Build is a Promotion, but failed to get the o
exception.cwdRemoteRoot=Failed to change to remote directory [{0}]
exception.readFile=Failed to read file - filename [{0}] (relative to JENKINS_HOME if not absolute). Message: [{1}]
exception.invokeList=Exception calling FilePath.list. includes [{0}], excludes [{1}]
exception.invokeListNoDefaultExcludes=Exception calling FilePath.list. includes [{0}], excludes [{1}], noDefaultExcludes [{2}]
exception.baseDirectoryNotExist=The base directory does not exist. If this is a promotion, have you "Archived the artifacts"?
exception.retryDelayInterrupted=Interrupted whilst sleeping before retry
exception.paramPublish.noParameter=Failed to find parameter named [{0}]
Expand Down
Expand Up @@ -46,6 +46,7 @@ exception.failedToGetPromotedBuild=B*i*d i* a P*o*o*i*n, b*t f*i*e* t* g*t t*e o
exception.cwdRemoteRoot=F*i*e* t* c*a*g* t* r*m*t* d*r*c*o*y [{0}]
exception.readFile=F*i*e* t* r*a* f*l* - f*l*n*m* [{0}] (r*l*t*v* t* J*N*I*S_H*M* i* n*t a*s*l*t*). M*s*a*e: [{1}]
exception.invokeList=E*c*p*i*n c*l*i*g F*l*P*t*.l*s*. i*c*u*e* [{0}], e*c*u*e* [{1}]
exception.invokeListNoDefaultExcludes=E*c*p*i*n ca*l*n* F*l*P*t*.l*s*. i*c*u*e* [{0}], e*c*u*e* [{1}], n*D*f*u*t*x*l*d*s [{2}]
exception.baseDirectoryNotExist=T*e b*s* d*r*c*o*y d*e* n*t e*i*t. I* t*i* i* a p*o*o*i*n, h*v* y*u "A*c*i*e* t*e a*t*f*c*s"?
exception.retryDelayInterrupted=I*t*r*u*t*d w*i*s* s*e*p*n* b*f*r* r*t*y
exception.paramPublish.noParameter=F*i*e* t* f*n* p*r*m*t*r n*m*d [{0}]
Expand Down
Expand Up @@ -28,6 +28,7 @@ remoteDirectory=Remote directory
transfers.envVars=All of the transfer fields support substitution of \
<a href="{0}/env-vars.html" target="_blank">Jenkins environment variables</a>
excludes=Exclude files
noDefaultExcludes=No default excludes
flatten=Flatten files
remoteDirectorySDF=Remote directory<br />is a date format
cleanRemote=Clean remote
Expand Up @@ -28,6 +28,7 @@ remoteDirectory=R*m*t* d*r*c*o*y
transfers.envVars=A*l o* t*e t*a*s*e* f*e*d* s*p*o*t s*b*t*t*t*o* o* \
<a href="{0}/env-vars.html" target="_blank">J*n*i*s e*v*r*n*e*t v*r*a*l*s</a>
excludes=E*c*u*e f*l*s
noDefaultExcludes=N* d*f*u*t e*c*u*e*
flatten=F*a*t*n f*l*s
remoteDirectorySDF=R*m*t* d*r*c*o*y<br />i* a d*t* f*r*a*
cleanRemote=C*e*n r*m*t*
Expand Up @@ -504,7 +504,7 @@ public void testFlattenThrowsExceptionIfTwoFilesHaveSameName() throws Exception
final RandomFile log1 = new RandomFile(baseDir.getRoot(), "1.log");
final RandomFile log2 = new RandomFile(baseDir.getRoot(), "2.log");
final RandomFile log3 = new RandomFile(baseDir.getRoot(), "3.log");
final BPTransfer transfer = new BPTransfer("*", "", "", "", false, false, true);
final BPTransfer transfer = new BPTransfer("*", "", "", "", false, false, true, false);
expect(mockClient.changeToInitialDirectory()).andReturn(true);
mockClient.deleteTree();
expect(mockClient.changeToInitialDirectory()).andReturn(true);
Expand Down Expand Up @@ -533,7 +533,7 @@ public void testFlattenThrowsExceptionIfTwoFilesHaveSameName() throws Exception
final RandomFile log1 = new RandomFile(baseDir.getRoot(), "1.log");
final RandomFile log2 = new RandomFile(baseDir.getRoot(), "2.log");
final RandomFile log3 = new RandomFile(baseDir.getRoot(), "3.log");
final BPTransfer transfer = new BPTransfer("*", "", "", "", false, false, true);
final BPTransfer transfer = new BPTransfer("*", "", "", "", false, false, true, false);
expect(mockClient.changeToInitialDirectory()).andReturn(true);
mockClient.deleteTree();
expectLastCall().andThrow(new IOException());
Expand Down

0 comments on commit 9b8cd2d

Please sign in to comment.