Initializes the base directory from system properties if not already set.
()
| 808 | * Initializes the base directory from system properties if not already set. |
| 809 | */ |
| 810 | protected void initBaseDir() { |
| 811 | String catalinaHome = System.getProperty(Globals.CATALINA_HOME_PROP); |
| 812 | if (basedir == null) { |
| 813 | basedir = System.getProperty(Globals.CATALINA_BASE_PROP); |
| 814 | } |
| 815 | if (basedir == null) { |
| 816 | basedir = catalinaHome; |
| 817 | } |
| 818 | if (basedir == null) { |
| 819 | // Create a temp dir. |
| 820 | basedir = System.getProperty("user.dir") + "/tomcat." + port; |
| 821 | } |
| 822 | |
| 823 | File baseFile = new File(basedir); |
| 824 | if (baseFile.exists()) { |
| 825 | if (!baseFile.isDirectory()) { |
| 826 | throw new IllegalArgumentException(sm.getString("tomcat.baseDirNotDir", baseFile)); |
| 827 | } |
| 828 | } else { |
| 829 | if (!baseFile.mkdirs()) { |
| 830 | // Failed to create base directory |
| 831 | throw new IllegalStateException(sm.getString("tomcat.baseDirMakeFail", baseFile)); |
| 832 | } |
| 833 | /* |
| 834 | * If file permissions were going to be set on the newly created directory, this is the place to do it. |
| 835 | * However, even simple calls such as File.setReadable(boolean,boolean) behaves differently on different |
| 836 | * platforms. Therefore, setBaseDir documents that the user needs to do this. |
| 837 | */ |
| 838 | } |
| 839 | try { |
| 840 | baseFile = baseFile.getCanonicalFile(); |
| 841 | } catch (IOException ioe) { |
| 842 | baseFile = baseFile.getAbsoluteFile(); |
| 843 | } |
| 844 | server.setCatalinaBase(baseFile); |
| 845 | System.setProperty(Globals.CATALINA_BASE_PROP, baseFile.getPath()); |
| 846 | basedir = baseFile.getPath(); |
| 847 | |
| 848 | if (catalinaHome == null) { |
| 849 | server.setCatalinaHome(baseFile); |
| 850 | } else { |
| 851 | File homeFile = new File(catalinaHome); |
| 852 | if (!homeFile.isDirectory() && !homeFile.mkdirs()) { |
| 853 | // Failed to create home directory |
| 854 | throw new IllegalStateException(sm.getString("tomcat.homeDirMakeFail", homeFile)); |
| 855 | } |
| 856 | try { |
| 857 | homeFile = homeFile.getCanonicalFile(); |
| 858 | } catch (IOException ioe) { |
| 859 | homeFile = homeFile.getAbsoluteFile(); |
| 860 | } |
| 861 | server.setCatalinaHome(homeFile); |
| 862 | } |
| 863 | System.setProperty(Globals.CATALINA_HOME_PROP, server.getCatalinaHome().getPath()); |
| 864 | } |
| 865 | |
| 866 | private static final String[] silences = new String[] { "org.apache.coyote.http11.Http11NioProtocol", |
| 867 | "org.apache.catalina.core.StandardService", "org.apache.catalina.core.StandardEngine", |
no test coverage detected