Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: The default value of defaultUseCache should be true.

...

  • A test class based on HudsonTestCase (junit3 based)
    Code Block
    public class SomeTest extends HudsonTestCase {
        private boolean origDefaultUseCache = falsetrue;
        
        @Override
        protected void setUp() throws Exception {
            if(Functions.isWindows()) {
                // To avoid JENKINS-4409.
                // URLConnection caches handles to jar files by default,
                // and it prevents delete temporary directories.
                // Disable caching here.
                // Though defaultUseCache is a static field,
                // its setter and getter are provided as instance methods.
                URLConnection aConnection = new File(".").toURI().toURL().openConnection();
                origDefaultUseCache = aConnection.getDefaultUseCaches();
                aConnection.setDefaultUseCaches(false);
            }
            super.setUp();
        }
        
        @Override
        protected void tearDown() throws Exception {
            super.tearDown();
            if(Functions.isWindows()) {
                URLConnection aConnection = new File(".").toURI().toURL().openConnection();
                aConnection.setDefaultUseCaches(origDefaultUseCache);
            }
        }
    
  • A test class based on JenkinsRule (junit4 based)
    Code Block
    public class SomeTest {
        @Rule
        public JenkinsRule j = new JenkinsRule() {
            private boolean origDefaultUseCache = falsetrue;
            
            @Override
            public void before() throws Throwable {
                if(Functions.isWindows()) {
                    // To avoid JENKINS-4409.
                    // URLConnection caches handles to jar files by default,
                    // and it prevents delete temporary directories.
                    // Disable caching here.
                    // Though defaultUseCache is a static field,
                    // its setter and getter are provided as instance methods.
                    URLConnection aConnection = new File(".").toURI().toURL().openConnection();
                    origDefaultUseCache = aConnection.getDefaultUseCaches();
                    aConnection.setDefaultUseCaches(false);
                }
                super.before();
            }
            
            @Override
            public void after() throws Exception {
                super.after();
                if(Functions.isWindows()) {
                    URLConnection aConnection = new File(".").toURI().toURL().openConnection();
                    aConnection.setDefaultUseCaches(origDefaultUseCache);
                }
            }
            
        };
        
        ...
    

...