KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > maven > FilteredChangeLogSet


1 package hudson.maven;
2
3 import hudson.scm.ChangeLogSet;
4 import hudson.scm.ChangeLogSet.Entry;
5
6 import java.util.Iterator JavaDoc;
7 import java.util.List JavaDoc;
8 import java.util.ArrayList JavaDoc;
9
10 /**
11  * {@link ChangeLogSet} implementation used for {@link MavenBuild}.
12  *
13  * @author Kohsuke Kawaguchi
14  */

15 public class FilteredChangeLogSet extends ChangeLogSet<Entry> {
16     private final List JavaDoc<Entry> master = new ArrayList JavaDoc<Entry>();
17
18     public final ChangeLogSet<? extends Entry> core;
19
20     /*package*/ FilteredChangeLogSet(MavenBuild build) {
21         super(build);
22         MavenModule mod = build.getParent();
23
24         // modules that are under 'mod'. lazily computed
25
List JavaDoc<MavenModule> subsidiaries = null;
26
27         MavenModuleSetBuild parentBuild = build.getParentBuild();
28         if(parentBuild==null) {
29             core = ChangeLogSet.createEmpty(build);
30             return;
31         }
32         
33         core = parentBuild.getChangeSet();
34
35         for (Entry e : core) {
36             boolean belongs = false;
37
38             for (String JavaDoc path : e.getAffectedPaths()) {
39                 if(path.startsWith(mod.getRelativePath())) {
40                     belongs = true;
41                     break;
42                 }
43             }
44
45             if(belongs) {
46                 // make sure at least one change belongs to this module proper,
47
// and not its subsidiary module
48
if(subsidiaries==null) {
49                     subsidiaries = new ArrayList JavaDoc<MavenModule>();
50                     for (MavenModule mm : mod.getParent().getModules()) {
51                         if(mm!=mod && mm.getRelativePath().startsWith(mod.getRelativePath()))
52                             subsidiaries.add(mm);
53                     }
54                 }
55
56                 belongs = false;
57
58                 for (String JavaDoc path : e.getAffectedPaths()) {
59                     if(!belongsToSubsidiary(subsidiaries, path)) {
60                         belongs = true;
61                         break;
62                     }
63                 }
64
65                 if(belongs)
66                     master.add(e);
67             }
68         }
69     }
70
71     private boolean belongsToSubsidiary(List JavaDoc<MavenModule> subsidiaries, String JavaDoc path) {
72         for (MavenModule sub : subsidiaries)
73             if(path.startsWith(sub.getRelativePath()))
74                 return true;
75         return false;
76     }
77
78     public Iterator JavaDoc<Entry> iterator() {
79         return master.iterator();
80     }
81
82     public boolean isEmptySet() {
83         return master.isEmpty();
84     }
85 }
86
Popular Tags