Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 e3869b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Expand Up @@ -66,6 +66,7 @@ public class GitParameterDefinition extends ParameterDefinition implements Compa
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;
Expand All @@ -79,8 +80,6 @@ public class GitParameterDefinition extends ParameterDefinition implements Compa
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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -297,15 +294,15 @@ public Map<String, String> generateContents(JobWrapper jobWrapper, GitSCM git) {
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);
Expand Down Expand Up @@ -337,7 +334,7 @@ private Set<String> getTag(GitClient gitClient, String gitUrl) throws Interrupte
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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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);

Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
}
Expand Down

0 comments on commit e3869b1

Please sign in to comment.