Skip to content
Permalink
Browse files

Merge pull request #52 from jenkinsci/bugfix/JENKINS-46216

Null Pointer exception when no default parameter provided
  • Loading branch information
klimas7 committed Sep 4, 2017
2 parents d8a0c6f + ef4552d commit e3869b10b05b76f1f78f32ccbf7c539624e3e230
@@ -66,6 +66,7 @@
public static final Pattern PULL_REQUEST_REFS_PATTERN = Pattern.compile("refs/pull.*/(\\d+)/[from|head]");

public static final String TEMPORARY_DIRECTORY_PREFIX = "git_parameter_";
public static final String EMPTY_JOB_NAME = "EMPTY_JOB_NAME";
private static final Logger LOGGER = Logger.getLogger(GitParameterDefinition.class.getName());

private final UUID uuid;
@@ -79,8 +80,6 @@
private String useRepository;
private Boolean quickFilterEnabled;

private String customJobName;

@DataBoundConstructor
public GitParameterDefinition(String name, String type, String defaultValue, String description, String branch,
String branchFilter, String tagFilter, SortMode sortMode, SelectedValue selectedValue,
@@ -156,7 +155,7 @@ public ParameterValue getDefaultParameterValue() {
return new GitParameterValue(getName(), valueItems.get(0).value);
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, getCustomeJobName() + Messages.GitParameterDefinition_unexpectedError(), e);
LOGGER.log(Level.SEVERE, getCustomeJobName() + " " + Messages.GitParameterDefinition_unexpectedError(), e);
}
break;
case DEFAULT:
@@ -272,8 +271,6 @@ public int compareTo(GitParameterDefinition pd) {
}

public Map<String, String> generateContents(JobWrapper jobWrapper, GitSCM git) {
customJobName = jobWrapper.getCustomJobName();

Map<String, String> paramList = new LinkedHashMap<String, String>();
try {
EnvVars environment = getEnvironment(jobWrapper);
@@ -297,15 +294,15 @@ public int compareTo(GitParameterDefinition pd) {
getRevision(jobWrapper, git, paramList, environment, repository, remoteURL);
}

if(isPullRequestType()){
if (isPullRequestType()) {
Set<String> pullRequestSet = getPullRequest(gitClient, gitUrl);
sortAndPutToParam(pullRequestSet, paramList);
}
}
}
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, getCustomeJobName() + Messages.GitParameterDefinition_unexpectedError(), e);
LOGGER.log(Level.SEVERE, getCustomeJobName() + " " + Messages.GitParameterDefinition_unexpectedError(), e);
String message = e.getMessage() + Messages.GitParameterDefinition_lookAtLog();
paramList.clear();
paramList.put(message, message);
@@ -337,7 +334,7 @@ private boolean isPullRequestType() {
tagSet.add(tagName.replaceFirst(REFS_TAGS_PATTERN, ""));
}
} catch (GitException e) {
LOGGER.log(Level.WARNING, getCustomeJobName() + Messages.GitParameterDefinition_getTag(), e);
LOGGER.log(Level.WARNING, getCustomeJobName() + " " + Messages.GitParameterDefinition_getTag(), e);
}
return tagSet;
}
@@ -379,7 +376,7 @@ private Pattern compileBranchFilterPattern() {
try {
branchFilterPattern = Pattern.compile(branchFilter);
} catch (Exception e) {
LOGGER.log(Level.INFO, getCustomeJobName() + Messages.GitParameterDefinition_branchFilterNotValid(), e.getMessage());
LOGGER.log(Level.INFO, getCustomeJobName() + " " + Messages.GitParameterDefinition_branchFilterNotValid(), e.getMessage());
branchFilterPattern = Pattern.compile(".*");
}
return branchFilterPattern;
@@ -391,7 +388,7 @@ private String strip(String name, String remote) {
}

/**
*Unfortunately, to get the revisions should do fetch
* Unfortunately, to get the revisions should do fetch
*/
private void getRevision(JobWrapper jobWrapper, GitSCM git, Map<String, String> paramList, EnvVars environment, RemoteConfig repository, URIish remoteURL) throws IOException, InterruptedException {
boolean isRepoScm = RepoSCM.isRepoSCM(repository.getName());
@@ -413,7 +410,6 @@ private void getRevision(JobWrapper jobWrapper, GitSCM git, Map<String, String>
}



private void sortAndPutToParam(Set<String> setElement, Map<String, String> paramList) {
List<String> sorted = sort(setElement);

@@ -475,7 +471,7 @@ private void initWorkspace(FilePathWrapper workspace, GitClient gitClient, URIis
if (isEmptyWorkspace(workspace.getFilePath())) {
gitClient.init();
gitClient.clone(remoteURL.toASCIIString(), DEFAULT_REMOTE, false, null);
LOGGER.log(Level.INFO, getCustomeJobName() + Messages.GitParameterDefinition_genContentsCloneDone());
LOGGER.log(Level.INFO, getCustomeJobName() + " " + Messages.GitParameterDefinition_genContentsCloneDone());
}
}

@@ -526,7 +522,9 @@ public void setUseRepository(String useRepository) {
}

public String getCustomeJobName() {
return customJobName;
Job job = getParentJob();
String fullName = job != null ? job.getFullName() : EMPTY_JOB_NAME;
return "[ " + fullName + " ] ";
}

@Extension
@@ -48,7 +48,7 @@ private SCM getSCMFromDefinition() {
return (SCM) scm;
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, getCustomJobName() + Messages.WorkflowJobWrapper_GetWorkflowRepoScmFail(), e);
LOGGER.log(Level.SEVERE, getCustomJobName() + " " + Messages.WorkflowJobWrapper_GetWorkflowRepoScmFail(), e);
}
return null;
}

0 comments on commit e3869b1

Please sign in to comment.