public FileAndDescription getHomeDir ( ServletContextEvent event ) { // check JNDI for the home directory first for ( String name : HOME_NAMES ) { try { InitialContext iniCtxt = new InitialContext ( ) ; Context env = ( Context ) iniCtxt . lookup ( "java:comp/env" ) ; String value = ( String ) env . lookup ( name ) ; if ( value != null && value . trim ( ) . length ( ) > 0 ) return new FileAndDescription ( new File ( value . trim ( ) ) , "JNDI/java:comp/env/" + name ) ; // look at one more place. See issue #1314 value = ( String ) iniCtxt . lookup ( name ) ; if ( value != null && value . trim ( ) . length ( ) > 0 ) return new FileAndDescription ( new File ( value . trim ( ) ) , "JNDI/" + name ) ; } catch ( NamingException e ) { // ignore } } // next the system property for ( String name : HOME_NAMES ) { String sysProp = SystemProperties . getString ( name ) ; if ( sysProp != null ) return new FileAndDescription ( new File ( sysProp . trim ( ) ) , "SystemProperties.getProperty(\"" + name + "\")" ) ; } // look at the env var next for ( String name : HOME_NAMES ) { String env = EnvVars . masterEnvVars . get ( name ) ; if ( env != null ) return new FileAndDescription ( new File ( env . trim ( ) ) . getAbsoluteFile ( ) , "EnvVars.masterEnvVars.get(\"" + name + "\")" ) ; } // otherwise pick a place by ourselves String root = event . getServletContext ( ) . getRealPath ( "/WEB-INF/workspace" ) ; if ( root != null ) { File ws = new File ( root . trim ( ) ) ; if ( ws . exists ( ) ) // Hudson <1.42 used to prefer this before ~/.hudson, so // check the existence and if it's there, use it. // otherwise if this is a new installation, prefer ~/.hudson return new FileAndDescription ( ws , "getServletContext().getRealPath(\"/WEB-INF/workspace\")" ) ; } File legacyHome = new File ( new File ( System . getProperty ( "user.home" ) ) , ".hudson" ) ; if ( legacyHome . exists ( ) ) { return new FileAndDescription ( legacyHome , "$user.home/.hudson" ) ; // before rename, this is where it was stored } File newHome = new File ( new File ( System . getProperty ( "user.home" ) ) , ".jenkins" ) ; return new FileAndDescription ( newHome , "$user.home/.jenkins" ) ; }
Determines the home directory for Jenkins .