1 package hudson.maven; 2 3 import hudson.CopyOnWrite; 4 import hudson.FilePath; 5 import hudson.Util; 6 import hudson.model.AbstractProject; 7 import hudson.model.Action; 8 import hudson.model.DependencyGraph; 9 import hudson.model.Descriptor; 10 import hudson.model.Descriptor.FormException; 11 import hudson.model.Hudson; 12 import hudson.model.Item; 13 import hudson.model.ItemGroup; 14 import hudson.model.Job; 15 import hudson.model.Node; 16 import hudson.triggers.Trigger; 17 import hudson.util.DescribableList; 18 import org.apache.maven.project.MavenProject; 19 import org.kohsuke.stapler.StaplerRequest; 20 import org.kohsuke.stapler.StaplerResponse; 21 22 import javax.servlet.ServletException ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.util.Collections ; 26 import java.util.HashMap ; 27 import java.util.List ; 28 import java.util.Map ; 29 import java.util.Set ; 30 import java.util.Vector ; 31 32 37 public final class MavenModule extends AbstractProject<MavenModule,MavenBuild> implements DescribableList.Owner { 38 private DescribableList<MavenReporter,Descriptor<MavenReporter>> reporters = 39 new DescribableList<MavenReporter,Descriptor<MavenReporter>>(this); 40 41 44 private String displayName; 45 46 private transient ModuleName moduleName; 47 48 private String relativePath; 49 50 54 private String goals; 55 56 59 @CopyOnWrite 60 private Set <ModuleName> dependencies; 61 62 69 private transient List<Action> transientActions = new Vector <Action>(); 70 71 MavenModule(MavenModuleSet parent, PomInfo pom, int firstBuildNumber) throws IOException { 72 super(parent, pom.name.toFileSystemName()); 73 reconfigure(pom); 74 updateNextBuildNumber(firstBuildNumber); 75 } 76 77 83 final void reconfigure(PomInfo pom) { 84 this.displayName = pom.displayName; 85 this.relativePath = pom.relativePath; 86 this.dependencies = pom.dependencies; 87 } 88 89 protected void doSetName(String name) { 90 moduleName = ModuleName.fromFileSystemName(name); 91 super.doSetName(moduleName.toString()); 92 } 93 94 @Override 95 public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException { 96 super.onLoad(parent,name); 97 if(reporters==null) 98 reporters = new DescribableList<MavenReporter, Descriptor<MavenReporter>>(this); 99 reporters.setOwner(this); 100 if(dependencies==null) 101 dependencies = Collections.emptySet(); 102 updateTransientActions(); 103 } 104 105 111 public String getRelativePath() { 112 return relativePath; 113 } 114 115 118 public String getGoals() { 119 if(goals!=null) return goals; 120 return getParent().getGoals(); 121 } 122 123 132 public String getUserConfiguredGoals() { 133 return goals; 134 } 135 136 @Override 137 public FilePath getWorkspace() { 138 return getParent().getModuleRoot().child(relativePath); 139 } 140 141 public ModuleName getModuleName() { 142 return moduleName; 143 } 144 145 @Override 146 public String getDisplayName() { 147 return displayName; 148 } 149 150 public MavenModuleSet getParent() { 151 return (MavenModuleSet)super.getParent(); 152 } 153 154 void updateNextBuildNumber(int next) throws IOException { 155 if(next>nextBuildNumber) { 156 this.nextBuildNumber = next; 157 saveNextBuildNumber(); 158 } 159 } 160 161 165 public Node getAssignedNode() { 166 return getParent().getLastBuiltOn(); 167 } 168 169 @Override 170 public MavenBuild newBuild() throws IOException { 171 MavenBuild lastBuild = new MavenBuild(this); 172 builds.put(lastBuild); 173 return lastBuild; 174 } 175 176 @Override 177 protected MavenBuild loadBuild(File dir) throws IOException { 178 return new MavenBuild(this,dir); 179 } 180 181 @Override 182 protected boolean isBuildBlocked() { 183 if(super.isBuildBlocked()) 184 return true; 185 186 MavenModuleSet p = getParent(); 190 return p.isBuilding() || p.isInQueue(); 191 } 192 193 @Override 194 public boolean isFingerprintConfigured() { 195 return true; 196 } 197 198 protected void buildDependencyGraph(DependencyGraph graph) { 199 Map <ModuleName,MavenModule> modules = new HashMap <ModuleName,MavenModule>(); 200 201 for (MavenModule m : Hudson.getInstance().getAllItems(MavenModule.class)) 202 modules.put(m.getModuleName(),m); 203 204 for (ModuleName d : dependencies) { 205 MavenModule src = modules.get(d); 206 if(src!=null) 207 graph.addDependency(src,this); 208 } 209 } 210 211 public synchronized List<Action> getActions() { 212 List<Action> actions = new Vector <Action>(super.getActions()); 214 actions.addAll(transientActions); 215 return actions; 216 } 217 218 void updateTransientActions() { 219 if(transientActions==null) 220 transientActions = new Vector <Action>(); synchronized(transientActions) { 222 transientActions.clear(); 223 224 MavenBuild lb = getLastBuild(); 225 if(lb==null) return; 226 227 List<MavenReporter> list = lb.projectActionReporters; 228 if(list!=null) 229 for (MavenReporter step : list) { 230 Action a = step.getProjectAction(this); 231 if(a!=null) 232 transientActions.add(a); 233 } 234 for (Trigger trigger : triggers) { 235 Action a = trigger.getProjectAction(); 236 if(a!=null) 237 transientActions.add(a); 238 } 239 } 240 } 241 242 245 public DescribableList<MavenReporter, Descriptor<MavenReporter>> getReporters() { 246 return reporters; 247 } 248 249 public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException , ServletException { 250 super.doConfigSubmit(req, rsp); 251 252 try { 253 reporters.rebuild(req,MavenReporters.getConfigurableList(),"reporter"); 254 } catch (FormException e) { 255 sendError(e,req,rsp); 256 } 257 258 goals = Util.fixEmpty(req.getParameter("goals").trim()); 259 260 save(); 261 262 Hudson.getInstance().rebuildDependencyGraph(); 264 } 265 266 269 public void disable() throws IOException { 270 if(!disabled) { 271 disabled = true; 272 save(); 273 } 274 } 275 } 276 | Popular Tags |