Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-24586
avoid NPE
  • Loading branch information
aendter committed Sep 4, 2014
1 parent 741006f commit caa8a60
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
Expand Up @@ -4,6 +4,7 @@
package alex.jenkins.plugins;

import hudson.Extension;
import hudson.Util;
import hudson.model.ParameterValue;
import hudson.model.ParameterDefinition;
import hudson.util.FormValidation;
Expand All @@ -23,6 +24,7 @@
import java.util.regex.PatternSyntaxException;



import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

Expand Down Expand Up @@ -129,7 +131,7 @@ private FormValidation checkRegex(String regex) {
public FileSystemListParameterDefinition(String name, String description, String path, String selectedType, String regexIncludePattern, String regexExcludePattern, boolean sortByLastModified, boolean sortReverseOrder) {
super(name, description);

this.path = path;
this.path = Util.fixNull(path);
this.selectedType = selectedType;
this.selectedEnumType = FsObjectTypes.valueOf(selectedType);
this.sortByLastModified = sortByLastModified;
Expand Down Expand Up @@ -195,20 +197,23 @@ public List<String> getFsObjectsList() throws IOException {

map = new TreeMap<String, Long>();
File rootDir = new File(path);
File[] listFiles = rootDir.listFiles();

switch (getSelectedEnumType()) {
case SYMLINK:
createSymlinkMap(rootDir);
break;
case DIRECTORY:
createDirectoryMap(rootDir);
break;
case FILE:
createFileMap(rootDir);
break;
default:
createAllObjectsMap(rootDir);
break;
if(listFiles!=null){
switch (getSelectedEnumType()) {
case SYMLINK:
createSymlinkMap(listFiles);
break;
case DIRECTORY:
createDirectoryMap(listFiles);
break;
case FILE:
createFileMap(listFiles);
break;
default:
createAllObjectsMap(listFiles);
break;
}
}


Expand Down Expand Up @@ -301,9 +306,9 @@ private boolean isPatternMatching(String name) {
}


private void createSymlinkMap(File rootDir) throws IOException {
private void createSymlinkMap(File[] listFiles) throws IOException {

for (File file : rootDir.listFiles()) {
for (File file : listFiles) {
if (!file.isHidden() && isSymlink(file) && isPatternMatching(file.getName())) {
map.put(file.getName(),file.lastModified());
LOGGER.finest("add " + file);
Expand All @@ -312,9 +317,9 @@ private void createSymlinkMap(File rootDir) throws IOException {
}


private void createDirectoryMap(File rootDir) throws IOException {
private void createDirectoryMap(File[] listFiles) throws IOException {

for (File file : rootDir.listFiles()) {
for (File file : listFiles) {
if (!file.isHidden() && file.isDirectory() && !isSymlink(file) && isPatternMatching(file.getName())) {
map.put(file.getName(),file.lastModified());
LOGGER.finest("add " + file);
Expand All @@ -323,9 +328,9 @@ private void createDirectoryMap(File rootDir) throws IOException {
}


private void createFileMap(File rootDir) throws IOException {
private void createFileMap(File[] listFiles) throws IOException {

for (File file : rootDir.listFiles()) {
for (File file : listFiles) {
if (!file.isHidden() && file.isFile() && !isSymlink(file) && isPatternMatching(file.getName())) {
map.put(file.getName(),file.lastModified());
LOGGER.finest("add " + file);
Expand All @@ -337,9 +342,9 @@ private void createFileMap(File rootDir) throws IOException {



private void createAllObjectsMap(File rootDir) {
private void createAllObjectsMap(File[] listFiles) {

for (File file : rootDir.listFiles()) {
for (File file : listFiles) {
if (!file.isHidden() && isPatternMatching(file.getName())) {
map.put(file.getName(),file.lastModified());
LOGGER.finest("add " + file);
Expand Down
Expand Up @@ -9,8 +9,8 @@
<f:textarea name="parameter.description" value="${instance.description}" codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" previewEndpoint="/markupFormatter/previewDescription" />
</f:entry>

<f:entry title="Path" field="path">
<f:textbox />
<f:entry title="Path" field="path" >
<f:textbox default="" />
</f:entry>

<f:entry title="Filesystem object type" field="selectedType">
Expand Down

0 comments on commit caa8a60

Please sign in to comment.