blob: 76ff6b23bd974e2b2e8c54f0df078bb7eaf552ad (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.start.builders;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import org.eclipse.jetty.start.BaseBuilder;
import org.eclipse.jetty.start.BaseHome;
import org.eclipse.jetty.start.FS;
import org.eclipse.jetty.start.Module;
import org.eclipse.jetty.start.StartLog;
import org.eclipse.jetty.start.graph.OnlyTransitivePredicate;
/**
* Management of the <code>${jetty.base}/start.d/</code> based configuration.
* <p>
* Implementation of the <code>--add-to-startd=[name]</code> command line behavior
*/
public class StartDirBuilder implements BaseBuilder.Config
{
private final BaseHome baseHome;
private final Path startDir;
public StartDirBuilder(BaseBuilder baseBuilder) throws IOException
{
this.baseHome = baseBuilder.getBaseHome();
this.startDir = baseHome.getBasePath("start.d");
FS.ensureDirectoryExists(startDir);
}
@Override
public boolean addModule(Module module) throws IOException
{
if (module.isDynamic())
{
if (module.hasIniTemplate())
{
// warn
StartLog.warn("%-15s not adding [ini-template] from dynamic module",module.getName());
}
return false;
}
String mode = "";
boolean isTransitive = module.matches(OnlyTransitivePredicate.INSTANCE);
if (isTransitive)
{
mode = "(transitively) ";
}
if (module.hasIniTemplate() || !isTransitive)
{
// Create start.d/{name}.ini
Path ini = startDir.resolve(module.getName() + ".ini");
StartLog.info("%-15s initialised %sin %s",module.getName(),mode,baseHome.toShortForm(ini));
try (BufferedWriter writer = Files.newBufferedWriter(ini,StandardCharsets.UTF_8,StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING))
{
writeModuleSection(writer,module);
}
return true;
}
return false;
}
protected void writeModuleSection(BufferedWriter writer, Module module)
{
PrintWriter out = new PrintWriter(writer);
out.println("# --------------------------------------- ");
out.println("# Module: " + module.getName());
out.println("--module=" + module.getName());
out.println();
for (String line : module.getIniTemplate())
{
out.println(line);
}
out.println();
out.flush();
}
}
|