-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-38306] Add a parameter to LocalData to use instead of method name #36
Merged
jglick
merged 1 commit into
jenkinsci:master
from
ikedam:feature/JENKINS-38306_LocalDataParameter
Oct 5, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,13 +25,16 @@ | |
|
||
import hudson.FilePath; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.reflect.Method; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import javax.annotation.CheckForNull; | ||
|
||
/** | ||
* Controls how a {@link HudsonTestCase} initializes <tt>JENKINS_HOME</tt>. | ||
* | ||
|
@@ -106,9 +109,11 @@ public File allocate() throws Exception { | |
*/ | ||
final class Local implements HudsonHomeLoader { | ||
private final Method testMethod; | ||
private final String alterName; | ||
|
||
public Local(Method testMethod) { | ||
public Local(Method testMethod, String alterName) { | ||
this.testMethod = testMethod; | ||
this.alterName = alterName; | ||
} | ||
|
||
public File allocate() throws Exception { | ||
|
@@ -121,11 +126,31 @@ public File allocate() throws Exception { | |
return new CopyExisting(home).allocate(); | ||
} | ||
|
||
public static boolean isJavaIdentifier(@CheckForNull String name) { | ||
if (StringUtils.isEmpty(name)) { | ||
return false; | ||
} | ||
if (!Character.isJavaIdentifierStart(name.charAt(0))) { | ||
return false; | ||
} | ||
for (int pos = 1; pos < name.length(); ++pos) { | ||
if (!Character.isJavaIdentifierPart(name.charAt(pos))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private URL findDataResource() { | ||
// first, check method specific resource | ||
Class<?> clazz = testMethod.getDeclaringClass(); | ||
String methodName = testMethod.getName(); | ||
|
||
if (isJavaIdentifier(alterName)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we care whether it is a Java identifier or not? Should not matter for purposes of resource loading. Anyway, if it is unusable for some reason, we should fail with an error. |
||
methodName = alterName; | ||
} | ||
|
||
for( String middle : new String[]{ '/'+testMethod.getName(), "" }) { | ||
for( String middle : new String[]{ '/'+methodName, "" }) { | ||
for( String suffix : SUFFIXES ) { | ||
URL res = clazz.getResource(clazz.getSimpleName() + middle+suffix); | ||
if(res!=null) return res; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/test/resources/org/jvnet/hudson/test/recipes/LocalDataTest/methodData/config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<version>1.580.1</version> | ||
<systemMessage>This is Jenkins in LocalDataTest#methodData</systemMessage> | ||
</hudson> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be replaced with
SourceVersion.latestSupported().isIdentifier(name)
.