-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from jenkinsci/data_structures
Add some data structures for future use
- Loading branch information
Showing
12 changed files
with
883 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/main/java/hudson/plugins/tfs/model/GitCodePushedEventArgs.java
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,55 @@ | ||
package hudson.plugins.tfs.model; | ||
|
||
import net.sf.ezmorph.MorpherRegistry; | ||
import net.sf.json.JSONObject; | ||
import net.sf.json.JsonConfig; | ||
import net.sf.json.processors.PropertyNameProcessor; | ||
import net.sf.json.util.JSONUtils; | ||
import net.sf.json.util.JavaIdentifierTransformer; | ||
|
||
import java.net.URI; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class GitCodePushedEventArgs { | ||
public URI collectionUri; | ||
public URI repoUri; | ||
public String projectId; | ||
public String repoId; | ||
public String commit; | ||
public String pushedBy; | ||
public List<WorkItem> workItems; | ||
|
||
public static GitCodePushedEventArgs fromJsonString(final String jsonString) { | ||
final JSONObject jsonObject = JSONObject.fromObject(jsonString); | ||
final GitCodePushedEventArgs result; | ||
|
||
final JsonConfig jsonConfig = new JsonConfig(); | ||
jsonConfig.setRootClass(GitCodePushedEventArgs.class); | ||
final HashMap<String, Class> classMap = new HashMap<String, Class>(); | ||
// TODO: the classMap is used without context, every property named here will try to use the type | ||
classMap.put("workItems", WorkItem.class); | ||
classMap.put("html", Link.class); | ||
jsonConfig.setClassMap(classMap); | ||
jsonConfig.setJavaIdentifierTransformer(new JavaIdentifierTransformer() { | ||
@Override | ||
public String transformToJavaIdentifier(final String str) { | ||
return str.replace(".", "_"); | ||
} | ||
}); | ||
|
||
final MorpherRegistry registry = JSONUtils.getMorpherRegistry(); | ||
|
||
// TODO: I don't like messing with singletons; is there a way to do this with JsonConfig? | ||
registry.registerMorpher(URIMorpher.INSTANCE); | ||
try { | ||
result = (GitCodePushedEventArgs) JSONObject.toBean(jsonObject, jsonConfig); | ||
} | ||
finally { | ||
registry.deregisterMorpher(URIMorpher.INSTANCE); | ||
} | ||
|
||
return result; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/hudson/plugins/tfs/model/GitStatusContext.java
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,29 @@ | ||
package hudson.plugins.tfs.model; | ||
|
||
import net.sf.json.JSONObject; | ||
import net.sf.json.JsonConfig; | ||
|
||
public class GitStatusContext { | ||
public String name; | ||
public String genre; | ||
|
||
public GitStatusContext() { | ||
} | ||
|
||
public GitStatusContext(final String name, final String genre) { | ||
this.name = name; | ||
this.genre = genre; | ||
} | ||
|
||
public static GitStatusContext fromJsonString(final String jsonString) { | ||
final JSONObject jsonObject = JSONObject.fromObject(jsonString); | ||
final GitStatusContext result; | ||
|
||
final JsonConfig jsonConfig = new JsonConfig(); | ||
jsonConfig.setRootClass(GitStatusContext.class); | ||
|
||
result = (GitStatusContext) JSONObject.toBean(jsonObject, jsonConfig); | ||
|
||
return result; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/hudson/plugins/tfs/model/GitStatusState.java
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,21 @@ | ||
package hudson.plugins.tfs.model; | ||
|
||
public enum GitStatusState { | ||
|
||
NotSet(0), | ||
Pending(1), | ||
Succeeded(2), | ||
Failed(3), | ||
Error(4), | ||
; | ||
|
||
private final int value; | ||
|
||
GitStatusState(final int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
} |
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,12 @@ | ||
package hudson.plugins.tfs.model; | ||
|
||
import java.net.URI; | ||
|
||
public class Link { | ||
public URI href; | ||
|
||
@Override | ||
public String toString() { | ||
return href.toString(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/hudson/plugins/tfs/model/PullRequestMergeCommitCreatedEventArgs.java
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,47 @@ | ||
package hudson.plugins.tfs.model; | ||
|
||
import net.sf.ezmorph.MorpherRegistry; | ||
import net.sf.json.JSONObject; | ||
import net.sf.json.JsonConfig; | ||
import net.sf.json.util.JSONUtils; | ||
import net.sf.json.util.JavaIdentifierTransformer; | ||
|
||
import java.util.HashMap; | ||
|
||
public class PullRequestMergeCommitCreatedEventArgs extends GitCodePushedEventArgs { | ||
public int pullRequestId; | ||
public int iterationId; | ||
|
||
public static PullRequestMergeCommitCreatedEventArgs fromJsonString(final String jsonString) { | ||
final JSONObject jsonObject = JSONObject.fromObject(jsonString); | ||
final PullRequestMergeCommitCreatedEventArgs result; | ||
|
||
final JsonConfig jsonConfig = new JsonConfig(); | ||
jsonConfig.setRootClass(PullRequestMergeCommitCreatedEventArgs.class); | ||
final HashMap<String, Class> classMap = new HashMap<String, Class>(); | ||
// TODO: the classMap is used without context, every property named here will try to use the type | ||
classMap.put("workItems", WorkItem.class); | ||
classMap.put("html", Link.class); | ||
jsonConfig.setClassMap(classMap); | ||
jsonConfig.setJavaIdentifierTransformer(new JavaIdentifierTransformer() { | ||
@Override | ||
public String transformToJavaIdentifier(final String str) { | ||
return str.replace(".", "_"); | ||
} | ||
}); | ||
|
||
final MorpherRegistry registry = JSONUtils.getMorpherRegistry(); | ||
|
||
// TODO: I don't like messing with singletons; is there a way to do this with JsonConfig? | ||
registry.registerMorpher(URIMorpher.INSTANCE); | ||
try { | ||
result = (PullRequestMergeCommitCreatedEventArgs) JSONObject.toBean(jsonObject, jsonConfig); | ||
} | ||
finally { | ||
registry.deregisterMorpher(URIMorpher.INSTANCE); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
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,50 @@ | ||
package hudson.plugins.tfs.model; | ||
|
||
import net.sf.ezmorph.MorphException; | ||
import net.sf.ezmorph.ObjectMorpher; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
public class URIMorpher implements ObjectMorpher { | ||
|
||
public static final URIMorpher INSTANCE = new URIMorpher(); | ||
|
||
private URIMorpher() { | ||
|
||
} | ||
|
||
@Override | ||
public Object morph(final Object value) { | ||
if (value == null) { | ||
return null; | ||
} | ||
|
||
if (URI.class.isAssignableFrom(value.getClass())) { | ||
return value; | ||
} | ||
|
||
if (!supports(value.getClass())) { | ||
throw new MorphException(value.getClass() + " is not supported"); | ||
} | ||
|
||
final String s = value.toString(); | ||
try { | ||
final URI result = new URI(s); | ||
return result; | ||
} | ||
catch (final URISyntaxException ignored) { | ||
throw new MorphException("'" + s + "' is not a valid URI"); | ||
} | ||
} | ||
|
||
@Override | ||
public Class morphsTo() { | ||
return URI.class; | ||
} | ||
|
||
@Override | ||
public boolean supports(final Class clazz) { | ||
return String.class.isAssignableFrom(clazz); | ||
} | ||
} |
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,17 @@ | ||
package hudson.plugins.tfs.model; | ||
|
||
import net.sf.json.JSONObject; | ||
|
||
public class VstsGitStatus { | ||
|
||
public GitStatusState state; | ||
public String description; | ||
public String targetUrl; | ||
public GitStatusContext context; | ||
|
||
public String toJson() { | ||
final JSONObject jsonObject = JSONObject.fromObject(this); | ||
final String result = jsonObject.toString(); | ||
return result; | ||
} | ||
} |
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,12 @@ | ||
package hudson.plugins.tfs.model; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
public class WorkItem { | ||
public long id; | ||
public int rev; | ||
public Map<String, Object> fields; | ||
public Map<String, Link> _links; | ||
public URI url; | ||
} |
Oops, something went wrong.