Reproduced problem in test: old copy of project is still referenced (see below); and second build is not run but not found.
private static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerTimer com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerTimer.instance->
com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerTimer@54f3e538-timer->
java.util.Timer@692dff13-queue->
java.util.TaskQueue@548b26c6-queue->
[Ljava.util.TimerTask;@729e2285-[2]->
com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerTimerTask@7c6dae73-gerritTrigger->
com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger@3248ded0-myProject->
hudson.model.FreeStyleProject@39913454
myProject field is redundant when Trigger.job already exists.
Progress. New leak:
private static com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl.instance->
com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl@75a69570-gerritEventManager->
com.sonyericsson.hudson.plugins.gerrit.trigger.GerritHandlerLifecycle@5d4a7b45-gerritEventListeners->
java.util.concurrent.CopyOnWriteArraySet@3579f74a-al->
java.util.concurrent.CopyOnWriteArrayList@11103fa6-array->
[Ljava.lang.Object;@73bcafa1-[2]->
com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger@10642995-job->
hudson.model.FreeStyleProject@63dd2ec
Moving right along. Now getting:
private static com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.ToGerritRunListener com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.ToGerritRunListener.instance->
com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.ToGerritRunListener@7127c1a1-memory->
com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.model.BuildMemory@4cbf8111-memory->
java.util.TreeMap@26f10c06-root->
java.util.TreeMap$Entry@568b866f-value->
com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.model.BuildMemory$MemoryImprint@4ab70a17-list->
java.util.ArrayList@28967588-elementData->
[Ljava.lang.Object;@3c9b3ade-[0]->
com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.model.BuildMemory$MemoryImprint$Entry@23ac0ff5-project->
hudson.model.FreeStyleProject@3f5c583e
Down to something that looks more like a test artifact than anything else.
private static org.jvnet.hudson.test.TestEnvironment org.jvnet.hudson.test.TestEnvironment.CURRENT->
org.jvnet.hudson.test.TestEnvironment@637edfa7-testCase->
com.sonyericsson.hudson.plugins.gerrit.trigger.spec.SpecGerritTriggerHudsonTest@52c74dec-server->
org.mortbay.jetty.Server@5c420b3d-_sessionIdManager->
org.mortbay.jetty.servlet.HashSessionIdManager@ed5f6a8-_sessions->
org.mortbay.util.MultiMap@376ca809-table->
[Ljava.util.HashMap$Entry;@6dee3245-[8]->
java.util.HashMap$Entry@2e3e2c34-value->
org.mortbay.jetty.servlet.HashSessionManager$Session@78cd92a2-_values->
java.util.HashMap@4a7e47af-table->
[Ljava.util.HashMap$Entry;@647d7bd5-[2]->
java.util.HashMap$Entry@51b14c9-value->
org.kohsuke.stapler.bind.BoundObjectTable$Table@46ae9e11-entries->
java.util.HashMap@26724211-table->
[Ljava.util.HashMap$Entry;@3600505a-[9]->
java.util.HashMap$Entry@25660079-value->
org.kohsuke.stapler.bind.BoundObjectTable$StrongRef@70c97fa5-o->
hudson.widgets.RenderOnDemandClosure@4283613-variables->
hudson.util.PackedMap@62b6b956-kvpairs->
[Ljava.lang.Object;@5d630352-[1]->
hudson.model.FreeStyleProject@61b65bb0
Test still failing (and heap walker broken) and still have old instance in memory, yet bug no longer reproducible live.
hprof heap walk shows this root ref:
this     - value: hudson.model.FreeStyleProject #1
 <- project     - class: com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.TriggeredItemEntity, value: hudson.model.FreeStyleProject #1
  <- item     - class: java.util.LinkedList$Node, value: com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.TriggeredItemEntity #1
   <- last     - class: java.util.LinkedList, value: java.util.LinkedList$Node #1237
    <- builds     - class: com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.actions.manual.TriggerMonitor$EventState, value: java.util.LinkedList #278
     <- item     - class: java.util.LinkedList$Node, value: com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.actions.manual.TriggerMonitor$EventState #1
      <- last     - class: java.util.LinkedList, value: java.util.LinkedList$Node #1236
       <- events     - class: com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.actions.manual.TriggerMonitor, value: java.util.LinkedList #276
        <- value     - class: java.util.HashMap$Entry, value: com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.actions.manual.TriggerMonitor #1
         <- [0]     - class: java.util.HashMap$Entry[], value: java.util.HashMap$Entry #71453
          <- table     - class: java.util.HashMap, value: java.util.HashMap$Entry[] #22502
           <- _values     - class: org.mortbay.jetty.servlet.HashSessionManager$Session, value: java.util.HashMap #24894
            <- value     - class: java.util.HashMap$Entry, value: org.mortbay.jetty.servlet.HashSessionManager$Session #1
             <- [15]     - class: java.util.HashMap$Entry[], value: java.util.HashMap$Entry #60508
              <- table     - class: java.util.HashMap, value: java.util.HashMap$Entry[] #19294
               <- _sessions     - class: org.mortbay.jetty.servlet.HashSessionManager, value: java.util.HashMap #16704
                <- this$0 (Java frame)     - class: org.mortbay.jetty.servlet.HashSessionManager$SessionScavenger, value: org.mortbay.jetty.servlet.HashSessionManager #1
Compilation fix.
CheckStyle is complaining that GerritTrigger.java may be 2000 lines long, but not 2019?!
Added silent start option

When the Silent Start Mode is enabled there
will be no 'build started' messages sent back
to Gerrit.

Change-Id: I6bdfa62bc24bac71909638b93ae62ad1c877486e
Merge "Added silent start option" into internal
Remove instance field in Plugin class

Jenkins creates only one instance from Plugin class then manage it.
So the field which keeps own instance is not needed.

Instead, we should use getPlugin(Class<T> clazz) in Jenkins class.
Change the implementation of server list to CopyOnWriteList

The purpose of this change is to throw away some synchronized methods.

Plugin instance is accessed from a lot of threads. So synchronized
methods block many processes. It would become a critical issue
if implement remote API.

This change solves such situation by using CopyOnWriteList.
It will improve UI performance.
Add remote API

This change adds remote API support.

You can get the status of Gerrit server using belowi url:

$JENKINS_URL/plugin/gerrit-trigger/api/
Fix checkstyle errors
Wait for expected build number instead the number of build
Migrate HudsonTestCase to JenkinsRule

In the latest release of Jenkins, HudsonTestCase is already deprecated.
Seems some extended tests don't work with the latest Jenkins.

This patch migrates HudsonTestCase to JenkinsRule.
Merge pull request #187 from rinrinne/jenkins-rule

Migrate HudsonTestCase to JenkinsRule
Merge pull request #186 from rinrinne/export-api

Add support for remote API
Increase build wait time

Build is occasionally delayed in test. In that case, some test fails
due to timeout.

This patch gives enough time as wait time. In addtion, integrates
to one static value.
No ssh authentication for test

Essentially, we don't need ssh authentication when connect to ssh server
mock. (Maybe it should do at gerrit-events.)

Some tests makes error due to ssh authentication. (But tests are passed.)

This patch removes ssh authentication process from ssh server mock
definitely.