/**
  * Sets the {@link BranchProjectFactory}.
  *
  * @param projectFactory the new {@link BranchProjectFactory}.
  */
 public synchronized void setProjectFactory(BranchProjectFactory<P, R> projectFactory) {
   projectFactory.getClass(); // throw NPE if null
   if (factory == projectFactory) {
     return;
   }
   if (factory != null) {
     factory.setOwner(null);
   }
   factory = projectFactory;
   factory.setOwner(this);
 }
 /** Consolidated initialization code. */
 private synchronized void init2() {
   if (sources == null) {
     sources = new PersistedList<BranchSource>(this);
   }
   if (nullSCMSource == null) {
     nullSCMSource = new NullSCMSource();
   }
   nullSCMSource.setOwner(this);
   for (SCMSource source : getSCMSources()) {
     source.setOwner(this);
   }
   final BranchProjectFactory<P, R> factory = getProjectFactory();
   factory.setOwner(this);
 }
 /** {@inheritDoc} */
 @Override
 protected Collection<P> orphanedItems(Collection<P> orphaned, TaskListener listener)
     throws IOException, InterruptedException {
   BranchProjectFactory<P, R> _factory = getProjectFactory();
   for (P project : orphaned) {
     if (!_factory.isProject(project)) {
       listener.getLogger().println("Detected unsupported subitem " + project + ", skipping");
       continue; // TODO perhaps better to remove from list passed to super, and return it from
                 // here
     }
     Branch b = _factory.getBranch(project);
     if (!(b instanceof Branch.Dead)) {
       _factory.decorate(
           _factory.setBranch(project, new Branch.Dead(b.getHead(), b.getProperties())));
     }
   }
   return super.orphanedItems(orphaned, listener);
 }
 private void scheduleBuild(
     BranchProjectFactory<P, R> factory,
     final P item,
     SCMRevision revision,
     TaskListener listener,
     String name) {
   if (ParameterizedJobMixIn.scheduleBuild2(
           item, 0, new CauseAction(new SCMTrigger.SCMTriggerCause("Branch indexing")))
       != null) {
     listener.getLogger().println("Scheduled build for branch: " + name);
     try {
       factory.setRevisionHash(item, revision);
     } catch (IOException e) {
       e.printStackTrace(listener.error("Could not update last revision hash"));
     }
   } else {
     listener.getLogger().println("Failed to schedule build for branch: " + name);
   }
 }