Adding helps and validators to the project configuration form.
1.1 --- a/remoting/server/hudson/src/main/java/org/netbeans/modules/jackpot30/hudson/IndexingBuilder.java Sat Jul 07 23:05:44 2012 +0200
1.2 +++ b/remoting/server/hudson/src/main/java/org/netbeans/modules/jackpot30/hudson/IndexingBuilder.java Sun Jul 08 10:36:57 2012 +0200
1.3 @@ -45,6 +45,7 @@
1.4 import hudson.Launcher;
1.5 import hudson.Proc;
1.6 import hudson.model.AbstractBuild;
1.7 +import hudson.model.AbstractProject;
1.8 import hudson.model.BuildListener;
1.9 import hudson.model.Descriptor;
1.10 import hudson.model.Descriptor.FormException;
1.11 @@ -52,6 +53,7 @@
1.12 import hudson.remoting.VirtualChannel;
1.13 import hudson.tasks.Builder;
1.14 import hudson.util.ArgumentListBuilder;
1.15 +import hudson.util.FormValidation;
1.16 import java.io.File;
1.17 import java.io.FileOutputStream;
1.18 import java.io.IOException;
1.19 @@ -67,8 +69,11 @@
1.20 import java.util.Set;
1.21 import java.util.regex.Matcher;
1.22 import java.util.regex.Pattern;
1.23 +import java.util.regex.PatternSyntaxException;
1.24 import net.sf.json.JSONObject;
1.25 +import org.kohsuke.stapler.AncestorInPath;
1.26 import org.kohsuke.stapler.DataBoundConstructor;
1.27 +import org.kohsuke.stapler.QueryParameter;
1.28 import org.kohsuke.stapler.StaplerRequest;
1.29
1.30 /**
1.31 @@ -137,7 +142,7 @@
1.32
1.33 listener.getLogger().println("Looking for projects in: " + build.getWorkspace().getRemote());
1.34
1.35 - FilePath base = indexSubDirectory == null || indexSubDirectory.isEmpty() ? build.getWorkspace() : build.getWorkspace().child(indexSubDirectory);
1.36 + FilePath base = indexSubDirectory == null || indexSubDirectory.isEmpty() ? build.getWorkspace() : build.getWorkspace().child(indexSubDirectory); //XXX: child also supports absolute paths! absolute paths should not be allowed here (for security)
1.37 RemoteResult res = base.act(new FindProjects(getDescriptor().getProjectMarkers(), getDescriptor().getIgnorePattern(), getIgnorePatterns()));
1.38
1.39 listener.getLogger().println("Running: " + toolName + " on projects: " + res);
1.40 @@ -297,6 +302,30 @@
1.41 public boolean hasNonStandardIndexingTool() {
1.42 return getIndexingTools().size() > 1;
1.43 }
1.44 +
1.45 + public FormValidation doCheckIndexSubDirectory(@AncestorInPath AbstractProject project, @QueryParameter String value) throws IOException, InterruptedException {
1.46 + FilePath workspace = project.getSomeWorkspace();
1.47 + if (workspace == null || !workspace.exists() || value == null || value.isEmpty() || workspace.child(value).isDirectory()) {
1.48 + return FormValidation.ok();
1.49 + } else {
1.50 + return workspace.validateRelativeDirectory(value);
1.51 + }
1.52 + }
1.53 +
1.54 + public FormValidation doCheckIgnorePatterns(@AncestorInPath AbstractProject project, @QueryParameter String ignorePatterns) throws IOException, InterruptedException {
1.55 + FilePath workspace = project.getSomeWorkspace();
1.56 + if (workspace == null || !workspace.exists() || ignorePatterns == null || ignorePatterns.isEmpty()) {
1.57 + return FormValidation.ok();
1.58 + } else {
1.59 + try {
1.60 + Pattern.compile(ignorePatterns);
1.61 + return FormValidation.ok();
1.62 + } catch (PatternSyntaxException ex) {
1.63 + return FormValidation.error("Not a valid regular expression (" + ex.getDescription() + ")");
1.64 + }
1.65 + }
1.66 + }
1.67 +
1.68 }
1.69
1.70 private static class FindProjects implements FileCallable<RemoteResult> {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/remoting/server/hudson/src/main/resources/org/netbeans/modules/jackpot30/hudson/IndexingBuilder/help-ignorePatterns.html Sun Jul 08 10:36:57 2012 +0200
2.3 @@ -0,0 +1,3 @@
2.4 +<div>
2.5 + Regular expression pattern for projects that should not be indexed.
2.6 +</div>
2.7 \ No newline at end of file
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/remoting/server/hudson/src/main/resources/org/netbeans/modules/jackpot30/hudson/IndexingBuilder/help-indexSubDirectory.html Sun Jul 08 10:36:57 2012 +0200
3.3 @@ -0,0 +1,3 @@
3.4 +<div>
3.5 + When non-empty, interpreted as a relative path to a directory inside workspace that should be indexed.
3.6 +</div>
3.7 \ No newline at end of file
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/remoting/server/hudson/src/main/resources/org/netbeans/modules/jackpot30/hudson/IndexingBuilder/help-projectName.html Sun Jul 08 10:36:57 2012 +0200
4.3 @@ -0,0 +1,3 @@
4.4 +<div>
4.5 + A name of the index. Will be shown to the user when selecting indexes to operate on.
4.6 +</div>
4.7 \ No newline at end of file