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.start;
20  
21  import java.io.IOException;
22  import java.nio.file.Path;
23  
24  /**
25   * Simple Start .INI handler
26   */
27  public class StartIni extends TextFile
28  {
29      private Path basedir;
30  
31      public StartIni(Path file) throws IOException
32      {
33          super(file);
34      }
35  
36      @Override
37      public void addUniqueLine(String line)
38      {
39          if (line.startsWith("--module="))
40          {
41              int idx = line.indexOf('=');
42              String value = line.substring(idx + 1);
43              for (String part : value.split(","))
44              {
45                  super.addUniqueLine("--module=" + expandBaseDir(part));
46              }
47          }
48          else
49          {
50              super.addUniqueLine(expandBaseDir(line));
51          }
52      }
53  
54      private String expandBaseDir(String line)
55      {
56          if (line == null)
57          {
58              return line;
59          }
60  
61          return line.replace("${start.basedir}",basedir.toString());
62      }
63  
64      @Override
65      public void init()
66      {
67          try
68          {
69              basedir = getFile().getParent().toRealPath();
70          }
71          catch (IOException e)
72          {
73              basedir = getFile().getParent().normalize().toAbsolutePath();
74          }
75      }
76  
77      public Path getBaseDir()
78      {
79          return basedir;
80      }
81  }