415826 start.jar module --enable and --disable

This commit is contained in:
Greg Wilkins 2013-08-27 13:12:22 +10:00
parent 866a9c96d2
commit ea21a1798a
2 changed files with 138 additions and 1 deletions

View File

@ -35,6 +35,7 @@ import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -508,6 +509,17 @@ public class Main
stop(stopPort,stopKey);
}
}
// Enables/Disable
for (String module : args.getDisable())
{
disable(args,module,true);
}
for (String module : args.getEnable())
{
enable(args,module,true);
}
// Informational command line, don't run jetty
if (!args.isRun())
{
@ -628,6 +640,102 @@ public class Main
}
}
private void enable(StartArgs args, String name, boolean verbose) throws IOException
{
File start_d=baseHome.getFile("start.d");
File ini=new File(start_d,name+".ini");
// Is it already enabled
if (ini.exists())
{
if (verbose)
StartLog.warn("Module %s already enabled by: %s",name,baseHome.toShortForm(ini));
return;
}
// Is there a disabled ini?
File disabled=new File(start_d,name+".ini.disabled");
boolean copy=false;
if (!disabled.exists() && baseHome.isBaseDifferent())
{
copy=true;
disabled=new File(new File(baseHome.getHomeDir(),"start.d"),name+".ini.disabled");
if (!disabled.exists())
disabled=new File(new File(baseHome.getHomeDir(),"start.d"),name+".ini");
}
if (disabled.exists())
{
// enable module by renaming/copying ini template
System.err.printf("Enabling %s in %s from %s%n",name,baseHome.toShortForm(ini),baseHome.toShortForm(disabled));
if (copy)
Files.copy(disabled.toPath(),ini.toPath());
else
disabled.renameTo(ini);
args.parse(baseHome, new StartIni(ini));
}
else if (args.getAllModules().resolveEnabled().contains(args.getAllModules().get(name)))
{
// No ini template and module is already enabled
List<String> sources=args.getSources(name);
if (sources!=null && sources.size()>0)
for (String s: args.getSources(name))
StartLog.warn("Module %s is enabled in %s",name,s);
else
StartLog.warn("Module %s is already enabled (see --list-modules)",name);
}
else if (ini.createNewFile())
{
System.err.printf("Enabling %s in %s%n",name,baseHome.toShortForm(ini));
// Create an ini
try(FileOutputStream out = new FileOutputStream(ini);)
{
out.write(("--module="+name+"\n").getBytes("ISO-8859-1"));
}
args.parse(baseHome, new StartIni(ini));
}
else
{
StartLog.warn("ERROR: Module %s cannot be enabled! ",name);
return;
}
// Process dependencies
Modules modules = args.getAllModules();
Module module=modules.get(name);
for (String parent:module.getParentNames())
enable(args,parent,false);
}
private void disable(StartArgs args, String name, boolean verbose) throws IOException
{
File start_d=baseHome.getFile("start.d");
File ini=new File(start_d,name+".ini");
// Is it enabled?
if (ini.exists())
{
File disabled=new File(start_d,name+".ini.disabled");
if (disabled.exists())
{
StartLog.warn("ERROR: Disabled ini already exists: %s",baseHome.toShortForm(disabled));
return;
}
StartLog.warn("Disabling %s from %s",name,baseHome.toShortForm(ini));
ini.renameTo(disabled);
return;
}
if (verbose)
StartLog.warn("Module %s, ini file already disabled: %s",name,baseHome.toShortForm(ini));
}
public void usage(boolean exit)
{
String usageResource = "org/eclipse/jetty/start/usage.txt";

View File

@ -77,6 +77,8 @@ public class StartArgs
private Properties properties = new Properties();
private Set<String> systemPropertyKeys = new HashSet<>();
private List<String> jvmArgs = new ArrayList<>();
private List<String> enable = new ArrayList<>();
private List<String> disable = new ArrayList<>();
private List<String> modulePersistEnable = new ArrayList<>();
private List<String> modulePersistDisable = new ArrayList<>();
private Modules allModules;
@ -157,7 +159,6 @@ public class StartArgs
dumpSystemProperty("jetty.home");
dumpSystemProperty("jetty.base");
dumpSystemProperty("jetty.version");
}
public void dumpJvmArgs()
@ -358,6 +359,16 @@ public class StartArgs
return this.commandLine;
}
public List<String> getEnable()
{
return enable;
}
public List<String> getDisable()
{
return disable;
}
public List<String> getDownloads()
{
return downloads;
@ -657,6 +668,24 @@ public class StartArgs
return;
}
if (arg.startsWith("--enable="))
{
if (!CMD_LINE_SOURCE.equals(source))
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
enable.addAll(getValues(arg));
run = false;
return;
}
if (arg.startsWith("--disable="))
{
if (!CMD_LINE_SOURCE.equals(source))
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
disable.addAll(getValues(arg));
run = false;
return;
}
if (arg.startsWith("--module="))
{
for (String moduleName : getValues(arg))