Skip to content

Commit

Permalink
469982 - Produce warning for dynamic modules with ini-templates seen …
Browse files Browse the repository at this point in the history
…during --add-to-start

+ Chaning Module.isVirtual() to Module.isDynamic()
+ Adding javadoc for Module.isDynamic()
+ Adding warning for builders on start.ini and start.d/*.ini with
  dynamic modules with [ini-template] sections
  • Loading branch information
joakime committed Jun 11, 2015
1 parent c78f9e2 commit ae3e9ac
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
13 changes: 10 additions & 3 deletions jetty-start/src/main/java/org/eclipse/jetty/start/Module.java
Expand Up @@ -241,7 +241,12 @@ private void init(BaseHome basehome)
setName(this.fileRef);
}

public boolean isVirtual()
/**
* Indicates a module that is dynamic in nature
*
* @return a module where the declared metadata name does not match the filename reference (aka a dynamic module)
*/
public boolean isDynamic()
{
return !getName().equals(fileRef);
}
Expand Down Expand Up @@ -289,6 +294,8 @@ public void process(BaseHome basehome) throws FileNotFoundException, IOException
// blank lines and comments are valid for ini-template section
if ((line.length() == 0) || line.startsWith("#"))
{
// Remember ini comments and whitespace (empty lines)
// for the [ini-template] section
if ("INI-TEMPLATE".equals(sectionType))
{
iniTemplate.add(line);
Expand All @@ -308,7 +315,7 @@ public void process(BaseHome basehome) throws FileNotFoundException, IOException
case "FILES":
files.add(line);
break;
case "DEFAULTS": // old name from 9.2.x
case "DEFAULTS": // old name introduced in 9.2.x
case "INI": // new name for 9.3+
defaultConfig.add(line);
hasDefaultConfig = true;
Expand Down Expand Up @@ -372,7 +379,7 @@ public String toString()
{
StringBuilder str = new StringBuilder();
str.append("Module[").append(getName());
if (isVirtual())
if (isDynamic())
{
str.append(",file=").append(fileRef);
}
Expand Down
Expand Up @@ -42,21 +42,24 @@ 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.isVirtual())
if (module.isDynamic())
{
// skip, no need to reference
StartLog.info("%-15s skipping (virtual module)",module.getName());
if (module.hasIniTemplate())
{
// warn
StartLog.warn("%-15s not adding [ini-template] from dynamic module",module.getName());
}
return false;
}

Expand All @@ -67,12 +70,12 @@ public boolean addModule(Module module) throws IOException
mode = "(transitively) ";
}

// Create start.d/{name}.ini
Path ini = startDir.resolve(module.getName() + ".ini");
StartLog.info("%-15s initialised %sin %s",module.getName(),mode,baseHome.toShortForm(ini));

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);
Expand All @@ -82,15 +85,15 @@ public boolean addModule(Module module) throws IOException

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())
{
Expand Down
Expand Up @@ -40,8 +40,7 @@
/**
* Management of the <code>${jetty.base}/start.ini</code> based configuration.
* <p>
* Implementation of the <code>--add-to-start=[name]</code> command line
* behavior
* Implementation of the <code>--add-to-start=[name]</code> command line behavior
*/
public class StartIniBuilder implements BaseBuilder.Config
{
Expand Down Expand Up @@ -96,25 +95,28 @@ public boolean addModule(Module module) throws IOException
// skip, already present
return false;
}
if (module.isVirtual())

if (module.isDynamic())
{
// skip, no need to reference
StartLog.info("%-15s skipping (virtual module)",module.getName());
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) ";
}

StartLog.info("%-15s initialised %sin %s",module.getName(),mode,baseHome.toShortForm(startIni));

if (module.hasIniTemplate() || !isTransitive)
{
StartLog.info("%-15s initialised %sin %s",module.getName(),mode,baseHome.toShortForm(startIni));

// Append to start.ini
try (BufferedWriter writer = Files.newBufferedWriter(startIni,StandardCharsets.UTF_8,StandardOpenOption.APPEND,StandardOpenOption.CREATE))
{
Expand All @@ -137,7 +139,6 @@ protected void writeModuleSection(BufferedWriter writer, Module module)

for (String line : module.getIniTemplate())
{
// TODO: validate property keys
out.println(line);
}

Expand Down

0 comments on commit ae3e9ac

Please sign in to comment.