Various improvements to the hudson plugin: ignore pattern, make sure the configuration is saved, some more logging.
authorJan Lahoda <jlahoda@netbeans.org>
Wed, 13 Jul 2011 20:12:16 +0200
changeset 634c5f8743a4d61
parent 633 0404696925e7
child 635 41d3e86cd209
Various improvements to the hudson plugin: ignore pattern, make sure the configuration is saved, some more logging.
remoting/server/hudson/src/main/java/org/netbeans/modules/jackpot30/hudson/IndexingBuilder.java
remoting/server/hudson/src/main/resources/org/netbeans/modules/jackpot30/hudson/IndexingBuilder/global.jelly
     1.1 --- a/remoting/server/hudson/src/main/java/org/netbeans/modules/jackpot30/hudson/IndexingBuilder.java	Fri Jul 08 18:01:09 2011 +0200
     1.2 +++ b/remoting/server/hudson/src/main/java/org/netbeans/modules/jackpot30/hudson/IndexingBuilder.java	Wed Jul 13 20:12:16 2011 +0200
     1.3 @@ -61,6 +61,7 @@
     1.4  import java.net.URL;
     1.5  import java.util.Arrays;
     1.6  import java.util.Collection;
     1.7 +import java.util.Comparator;
     1.8  import java.util.HashSet;
     1.9  import java.util.List;
    1.10  import java.util.Set;
    1.11 @@ -120,7 +121,9 @@
    1.12  
    1.13          t = t.forNode(build.getBuiltOn(), listener);
    1.14  
    1.15 -        RemoteResult res = build.getWorkspace().act(new FindProjects(getDescriptor().getProjectMarkers()));
    1.16 +        listener.getLogger().println("Looking for projects in: " + build.getWorkspace().getRemote());
    1.17 +
    1.18 +        RemoteResult res = build.getWorkspace().act(new FindProjects(getDescriptor().getProjectMarkers(), getDescriptor().getIgnorePattern()));
    1.19  
    1.20          listener.getLogger().println("Running: " + toolName + " on projects: " + res);
    1.21  
    1.22 @@ -182,7 +185,7 @@
    1.23          return null;
    1.24      }
    1.25  
    1.26 -    private static void findProjects(File root, Collection<String> result, Pattern markers, StringBuilder relPath) {
    1.27 +    private static void findProjects(File root, Collection<String> result, Pattern markers, Pattern ignore, StringBuilder relPath) {
    1.28          int len = relPath.length();
    1.29          boolean first = relPath.length() == 0;
    1.30  
    1.31 @@ -195,11 +198,17 @@
    1.32          File[] children = root.listFiles();
    1.33  
    1.34          if (children != null) {
    1.35 +            Arrays.sort(children, new Comparator<File>() {
    1.36 +                public int compare(File o1, File o2) {
    1.37 +                    return o1.getName().compareTo(o2.getName());
    1.38 +                }
    1.39 +            });
    1.40              for (File c : children) {
    1.41 +                if (ignore.matcher(c.getName()).matches()) continue;
    1.42                  if (!first)
    1.43                      relPath.append("/");
    1.44                  relPath.append(c.getName());
    1.45 -                findProjects(c, result, markers, relPath);
    1.46 +                findProjects(c, result, markers, ignore, relPath);
    1.47                  relPath.delete(len, relPath.length());
    1.48              }
    1.49          }
    1.50 @@ -220,6 +229,8 @@
    1.51          private File cacheDir;
    1.52          private static final String DEFAULT_PROJECT_MARKERS = "(.*)/(nbproject/project.xml|pom.xml)";
    1.53          private String projectMarkers = DEFAULT_PROJECT_MARKERS;
    1.54 +        private static final String DEFAULT_IGNORE_PATTERN = "CVS|\\.hg|\\.svn";
    1.55 +        private String ignorePattern = DEFAULT_IGNORE_PATTERN;
    1.56  
    1.57          public DescriptorImpl() {
    1.58              Cache.setStandaloneCacheRoot(cacheDir = new File(Hudson.getInstance().getRootDir(), "index").getAbsoluteFile());
    1.59 @@ -237,6 +248,14 @@
    1.60              this.projectMarkers = projectMarkers;
    1.61          }
    1.62  
    1.63 +        public String getIgnorePattern() {
    1.64 +            return ignorePattern;
    1.65 +        }
    1.66 +
    1.67 +        public  void setIgnorePattern(String ignorePattern) {
    1.68 +            this.ignorePattern = ignorePattern;
    1.69 +        }
    1.70 +
    1.71          @Override
    1.72          public Builder newInstance(StaplerRequest req, JSONObject formData) throws FormException {
    1.73              return new IndexingBuilder(req, formData);
    1.74 @@ -246,6 +265,9 @@
    1.75          public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
    1.76              cacheDir = new File(json.getString("cacheDir"));
    1.77              projectMarkers = json.optString("projectMarkers", DEFAULT_PROJECT_MARKERS);
    1.78 +            ignorePattern = json.optString("ignorePattern", DEFAULT_IGNORE_PATTERN);
    1.79 +
    1.80 +            save();
    1.81              
    1.82              return super.configure(req, json);
    1.83          }
    1.84 @@ -265,14 +287,16 @@
    1.85      }
    1.86  
    1.87      private static class FindProjects implements FileCallable<RemoteResult> {
    1.88 +        private final String ignorePattern;
    1.89          private final String markers;
    1.90 -        public FindProjects(String markers) {
    1.91 +        public FindProjects(String markers, String ignorePattern) {
    1.92              this.markers = markers;
    1.93 +            this.ignorePattern = ignorePattern;
    1.94          }
    1.95          public RemoteResult invoke(File file, VirtualChannel vc) throws IOException, InterruptedException {
    1.96              Set<String> projects = new HashSet<String>();
    1.97  
    1.98 -            findProjects(file, projects, Pattern.compile(markers), new StringBuilder());
    1.99 +            findProjects(file, projects, Pattern.compile(markers), Pattern.compile(ignorePattern), new StringBuilder());
   1.100  
   1.101              return new RemoteResult(projects, file.getCanonicalPath()/*XXX: will resolve symlinks!!!*/);
   1.102          }
     2.1 --- a/remoting/server/hudson/src/main/resources/org/netbeans/modules/jackpot30/hudson/IndexingBuilder/global.jelly	Fri Jul 08 18:01:09 2011 +0200
     2.2 +++ b/remoting/server/hudson/src/main/resources/org/netbeans/modules/jackpot30/hudson/IndexingBuilder/global.jelly	Wed Jul 13 20:12:16 2011 +0200
     2.3 @@ -8,6 +8,9 @@
     2.4          <f:entry title="Project markers:" field="projectMarkers">
     2.5              <f:textbox />
     2.6          </f:entry>
     2.7 +        <f:entry title="Ignore pattern:" field="ignorePattern">
     2.8 +            <f:textbox />
     2.9 +        </f:entry>
    2.10          </f:advanced>
    2.11      </f:section>
    2.12