1111import com .tw .go .plugin .model .GitConfig ;
1212import com .tw .go .plugin .model .ModifiedFile ;
1313import com .tw .go .plugin .model .Revision ;
14- import com .tw .go .plugin .util .ListUtil ;
15- import com .tw .go .plugin .util .StringUtil ;
1614import in .ashwanthkumar .gocd .github .provider .Provider ;
1715import in .ashwanthkumar .gocd .github .settings .scm .PluginConfigurationView ;
1816import in .ashwanthkumar .gocd .github .util .BranchFilter ;
2220import in .ashwanthkumar .utils .collections .Lists ;
2321import in .ashwanthkumar .utils .func .Function ;
2422import org .apache .commons .io .IOUtils ;
25- import org .apache .commons .lang .StringUtils ;
23+ import org .apache .commons .lang3 .StringUtils ;
2624
2725import java .io .IOException ;
2826import java .lang .reflect .Constructor ;
3432
3533@ Extension
3634public class GitHubPRBuildPlugin implements GoPlugin {
37- private static Logger LOGGER = Logger .getLoggerFor (GitHubPRBuildPlugin .class );
35+ private static final Logger LOGGER = Logger .getLoggerFor (GitHubPRBuildPlugin .class );
3836
3937 public static final String EXTENSION_NAME = "scm" ;
4038 private static final List <String > goSupportedVersions = asList ("1.0" );
@@ -174,7 +172,7 @@ private GoPluginApiResponse getPluginConfiguration(PluginConfigurationView view)
174172 }
175173
176174 private GoPluginApiResponse handleSCMValidation (GoPluginApiRequest goPluginApiRequest ) {
177- Map <String , Object > requestBodyMap = ( Map < String , Object >) fromJSON (goPluginApiRequest .requestBody ());
175+ Map <String , Object > requestBodyMap = fromJSON (goPluginApiRequest .requestBody ());
178176 final Map <String , String > configuration = keyValuePairs (requestBodyMap , "scm-configuration" );
179177 final GitConfig gitConfig = getGitConfig (configuration );
180178
@@ -189,7 +187,7 @@ public void validate(Map<String, Object> fieldValidation) {
189187 }
190188
191189 private GoPluginApiResponse handleSCMCheckConnection (GoPluginApiRequest goPluginApiRequest ) {
192- Map <String , Object > requestBodyMap = ( Map < String , Object >) fromJSON (goPluginApiRequest .requestBody ());
190+ Map <String , Object > requestBodyMap = fromJSON (goPluginApiRequest .requestBody ());
193191 Map <String , String > configuration = keyValuePairs (requestBodyMap , "scm-configuration" );
194192 GitConfig gitConfig = getGitConfig (configuration );
195193
@@ -207,7 +205,7 @@ private GoPluginApiResponse handleSCMCheckConnection(GoPluginApiRequest goPlugin
207205 }
208206
209207 GoPluginApiResponse handleGetLatestRevision (GoPluginApiRequest goPluginApiRequest ) {
210- Map <String , Object > requestBodyMap = ( Map < String , Object >) fromJSON (goPluginApiRequest .requestBody ());
208+ Map <String , Object > requestBodyMap = fromJSON (goPluginApiRequest .requestBody ());
211209 Map <String , String > configuration = keyValuePairs (requestBodyMap , "scm-configuration" );
212210 GitConfig gitConfig = getGitConfig (configuration );
213211 String flyweightFolder = (String ) requestBodyMap .get ("flyweight-folder" );
@@ -249,12 +247,12 @@ private String removeUsernameAndPassword(String message, GitConfig gitConfig) {
249247 }
250248
251249 GoPluginApiResponse handleLatestRevisionSince (GoPluginApiRequest goPluginApiRequest ) {
252- Map <String , Object > requestBodyMap = ( Map < String , Object >) fromJSON (goPluginApiRequest .requestBody ());
250+ Map <String , Object > requestBodyMap = fromJSON (goPluginApiRequest .requestBody (), Map . class );
253251 Map <String , String > configuration = keyValuePairs (requestBodyMap , "scm-configuration" );
254252 final GitConfig gitConfig = getGitConfig (configuration );
255253 Map <String , String > scmData = (Map <String , String >) requestBodyMap .get ("scm-data" );
256- Map <String , String > oldBranchToRevisionMap = ( Map < String , String >) fromJSON (scmData .get (BRANCH_TO_REVISION_MAP ));
257- Map <String , String > lastKnownBranchToRevisionMap = ( Map < String , String >) fromJSON (scmData .get (BRANCH_TO_REVISION_MAP ));
254+ Map <String , String > oldBranchToRevisionMap = fromJSON (scmData .get (BRANCH_TO_REVISION_MAP ));
255+ Map <String , String > lastKnownBranchToRevisionMap = fromJSON (scmData .get (BRANCH_TO_REVISION_MAP ));
258256 String flyweightFolder = (String ) requestBodyMap .get ("flyweight-folder" );
259257 LOGGER .debug (String .format ("Fetching latest for: %s" , gitConfig .getUrl ()));
260258
@@ -352,7 +350,7 @@ public Map<String, Object> apply(Revision revision) {
352350
353351 private Map <String , Object > getRevisionMapForSHA (GitConfig gitConfig , String branch , Revision revision ) {
354352 // patch for building merge commits
355- if (revision .isMergeCommit () && ListUtil . isEmpty ( revision .getModifiedFiles ())) {
353+ if (revision .isMergeCommit () && ( revision . getModifiedFiles () == null || revision .getModifiedFiles (). isEmpty ())) {
356354 revision .setModifiedFiles (Lists .of (new ModifiedFile ("/dev/null" , "deleted" )));
357355 }
358356
@@ -364,7 +362,7 @@ private boolean branchHasNewChange(String previousSHA, String latestSHA) {
364362 }
365363
366364 private GoPluginApiResponse handleCheckout (GoPluginApiRequest goPluginApiRequest ) {
367- Map <String , Object > requestBodyMap = ( Map < String , Object >) fromJSON (goPluginApiRequest .requestBody ());
365+ Map <String , Object > requestBodyMap = fromJSON (goPluginApiRequest .requestBody ());
368366 Map <String , String > configuration = keyValuePairs (requestBodyMap , "scm-configuration" );
369367 GitConfig gitConfig = getGitConfig (configuration );
370368 String destinationFolder = (String ) requestBodyMap .get ("destination-folder" );
@@ -416,7 +414,7 @@ Map<String, Object> getRevisionMap(GitConfig gitConfig, String branch, Revision
416414 response .put ("timestamp" , new SimpleDateFormat (DATE_PATTERN ).format (revision .getTimestamp ()));
417415 response .put ("revisionComment" , revision .getComment ());
418416 List <Map > modifiedFilesMapList = new ArrayList <Map >();
419- if (! ListUtil . isEmpty ( revision .getModifiedFiles ())) {
417+ if (revision . getModifiedFiles () != null && ! revision .getModifiedFiles (). isEmpty ( )) {
420418 for (ModifiedFile modifiedFile : revision .getModifiedFiles ()) {
421419 Map <String , String > modifiedFileMap = new HashMap <String , String >();
422420 modifiedFileMap .put ("fileName" , modifiedFile .getFileName ());
@@ -443,7 +441,7 @@ private Map<String, String> keyValuePairs(Map<String, Object> requestBodyMap, St
443441 }
444442
445443 public void validateUrl (GitConfig gitConfig , Map <String , Object > fieldMap ) {
446- if (StringUtil .isEmpty (gitConfig .getUrl ())) {
444+ if (StringUtils .isEmpty (gitConfig .getUrl ())) {
447445 fieldMap .put ("key" , "url" );
448446 fieldMap .put ("message" , "URL is a required field" );
449447 } else if (!provider .isValidURL (gitConfig .getUrl ())) {
@@ -453,7 +451,7 @@ public void validateUrl(GitConfig gitConfig, Map<String, Object> fieldMap) {
453451 }
454452
455453 public void checkConnection (GitConfig gitConfig , Map <String , Object > response , List <String > messages ) {
456- if (StringUtil .isEmpty (gitConfig .getUrl ())) {
454+ if (StringUtils .isEmpty (gitConfig .getUrl ())) {
457455 response .put ("status" , "failure" );
458456 messages .add ("URL is empty" );
459457 } else if (!provider .isValidURL (gitConfig .getUrl ())) {
0 commit comments