View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.server;
20  
21  import java.io.File;
22  import java.io.IOException;
23  import java.nio.file.Files;
24  import java.nio.file.Path;
25  
26  import org.eclipse.jetty.util.StringUtil;
27  import org.eclipse.jetty.util.log.Log;
28  import org.eclipse.jetty.util.log.Logger;
29  
30  /**
31   * Display an optional Warning Message if the {jetty.home} and {jetty.base} are the same directory.
32   * <p>
33   * This is to warn about not recommended approach to setting up the Jetty Distribution.
34   */
35  public class HomeBaseWarning
36  {
37      private static final Logger LOG = Log.getLogger(HomeBaseWarning.class);
38  
39      public HomeBaseWarning()
40      {
41          boolean showWarn = false;
42          
43          String home = System.getProperty("jetty.home");
44          String base = System.getProperty("jetty.base");
45  
46          if (StringUtil.isBlank(base))
47          {
48              // no base defined? then we are likely running
49              // via direct command line.
50              return;
51          }
52  
53          Path homePath = new File(home).toPath();
54          Path basePath = new File(base).toPath();
55  
56          try
57          {
58              showWarn = Files.isSameFile(homePath,basePath);
59          }
60          catch (IOException e)
61          {
62              LOG.ignore(e);
63              // Can't definitively determine this state
64              return;
65          }
66  
67          if (showWarn)
68          {
69              StringBuilder warn = new StringBuilder();
70              warn.append("This instance of Jetty is not running from a separate {jetty.base} directory");
71              warn.append(", this is not recommended.  See documentation at http://www.eclipse.org/jetty/documentation/current/startup.html");
72              LOG.warn("{}",warn.toString());
73          }
74      }
75  }