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

Implemented the options, but not yet created the individual *.ini files
This commit is contained in:
Greg Wilkins 2013-08-26 18:04:36 +10:00
parent e224ba5e94
commit 3ad746a355
2 changed files with 156 additions and 25 deletions

View File

@ -34,6 +34,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.Collections;
import java.util.List;
@ -354,7 +355,7 @@ public class Main
for (String enabledModule : args.getEnabledModules())
{
StartLog.debug("Enabling module: %s",enabledModule);
modules.enable(enabledModule,args.getModulesSources(enabledModule));
modules.enable(enabledModule,args.getSources(enabledModule));
}
StartLog.debug("Building Module Graph");
modules.buildGraph();
@ -454,6 +455,17 @@ public class Main
download(url);
}
// 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())
{
@ -573,6 +585,92 @@ 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");
if (!disabled.exists() && baseHome.isBaseDifferent())
disabled=new File(new File(baseHome.getHomeDir(),"start.d"),name+".ini.disabled");
if (disabled.exists())
{
// enable module by copying ini template
System.err.printf("Enabling %s in %s from %s%n",name,baseHome.toShortForm(ini),baseHome.toShortForm(disabled));
Files.copy(disabled.toPath(),ini.toPath());
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));
Files.copy(ini.toPath(),disabled.toPath());
return;
}
if (verbose)
StartLog.warn("Module %s, ini file already disabled: %s",name,baseHome.toShortForm(ini));
}
private void usage()
{
String usageResource = "org/eclipse/jetty/start/usage.txt";

View File

@ -39,6 +39,7 @@ import java.util.Set;
*/
public class StartArgs
{
public static final String CMD_LINE_SOURCE="<cmd-line>";
public static final String VERSION;
static
@ -67,8 +68,8 @@ public class StartArgs
private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration";
private List<String> commandLine = new ArrayList<>();
private Set<String> enabledModules = new HashSet<>();
private Map<String,List<String>> moduleSources = new HashMap<>();
private Set<String> modules = new HashSet<>();
private Map<String,List<String>> sources = new HashMap<>();
private List<String> downloads = new ArrayList<>();
private Classpath classpath;
private List<String> xmlRefs = new ArrayList<>();
@ -76,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 Modules allModules;
// Should the server be run?
@ -323,6 +326,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;
@ -330,7 +343,7 @@ public class StartArgs
public Set<String> getEnabledModules()
{
return this.enabledModules;
return this.modules;
}
public List<String> getJvmArgs()
@ -338,9 +351,9 @@ public class StartArgs
return jvmArgs;
}
public List<String> getModulesSources(String enabledModule)
public List<String> getSources(String module)
{
return moduleSources.get(enabledModule);
return sources.get(module);
}
public CommandLineBuilder getMainArgs(BaseHome baseHome, boolean addJavaInit) throws IOException
@ -424,6 +437,22 @@ public class StartArgs
return value;
}
private List<String> getValues(String arg)
{
String v=getValue(arg);
ArrayList<String> l=new ArrayList<>();
for (String s:v.split(","))
{
if (s!=null)
{
s=s.trim();
if (s.length()>0)
l.add(s);
}
}
return l;
}
public List<File> getXmlFiles()
{
return xmls;
@ -488,6 +517,9 @@ public class StartArgs
{
if ("--help".equals(arg) || "-?".equals(arg))
{
if (!CMD_LINE_SOURCE.equals(source))
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
help = true;
run = false;
return;
@ -501,6 +533,8 @@ public class StartArgs
if ("--stop".equals(arg))
{
if (!CMD_LINE_SOURCE.equals(source))
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
stopCommand = true;
run = false;
//
@ -541,6 +575,8 @@ public class StartArgs
if ("--dry-run".equals(arg) || "--exec-print".equals(arg))
{
if (!CMD_LINE_SOURCE.equals(source))
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
dryRun = true;
run = false;
return;
@ -554,44 +590,41 @@ public class StartArgs
if (arg.startsWith("--enable="))
{
String moduleName = getValue(arg);
// TODO:
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="))
{
String moduleName = getValue(arg);
// TODO:
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 : getValue(arg).split(","))
for (String moduleName : getValues(arg))
{
if (moduleName == null)
modules.add(moduleName);
List<String> list=sources.get(moduleName);
if (list==null)
{
continue; // skip
list=new ArrayList<String>();
sources.put(moduleName,list);
}
moduleName=moduleName.trim();
enabledModules.add(moduleName);
List<String> sources=moduleSources.get(moduleName);
if (sources==null)
{
sources=new ArrayList<String>();
moduleSources.put(moduleName,sources);
}
sources.add(source);
list.add(source);
}
return;
}
if (arg.startsWith("MODULE=") || arg.startsWith("MODULES="))
{
System.err.println("ERROR: Ignored deprecated arg: "+arg);
StartLog.warn("Ignored deprecated arg: {}",arg);
return;
}
@ -672,7 +705,7 @@ public class StartArgs
{
for (String line : commandLine)
{
parse(line,"<cmd-line>");
parse(line,StartArgs.CMD_LINE_SOURCE);
}
}
@ -703,7 +736,7 @@ public class StartArgs
builder.append("StartArgs [commandLine=");
builder.append(commandLine);
builder.append(", enabledModules=");
builder.append(enabledModules);
builder.append(modules);
builder.append(", xmlRefs=");
builder.append(xmlRefs);
builder.append(", properties=");