415826 start.jar module --enable and --disable
Implemented the options, but not yet created the individual *.ini files
This commit is contained in:
parent
e224ba5e94
commit
3ad746a355
|
@ -34,6 +34,7 @@ import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -354,7 +355,7 @@ public class Main
|
||||||
for (String enabledModule : args.getEnabledModules())
|
for (String enabledModule : args.getEnabledModules())
|
||||||
{
|
{
|
||||||
StartLog.debug("Enabling module: %s",enabledModule);
|
StartLog.debug("Enabling module: %s",enabledModule);
|
||||||
modules.enable(enabledModule,args.getModulesSources(enabledModule));
|
modules.enable(enabledModule,args.getSources(enabledModule));
|
||||||
}
|
}
|
||||||
StartLog.debug("Building Module Graph");
|
StartLog.debug("Building Module Graph");
|
||||||
modules.buildGraph();
|
modules.buildGraph();
|
||||||
|
@ -454,6 +455,17 @@ public class Main
|
||||||
download(url);
|
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
|
// Informational command line, don't run jetty
|
||||||
if (!args.isRun())
|
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()
|
private void usage()
|
||||||
{
|
{
|
||||||
String usageResource = "org/eclipse/jetty/start/usage.txt";
|
String usageResource = "org/eclipse/jetty/start/usage.txt";
|
||||||
|
|
|
@ -39,6 +39,7 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public class StartArgs
|
public class StartArgs
|
||||||
{
|
{
|
||||||
|
public static final String CMD_LINE_SOURCE="<cmd-line>";
|
||||||
public static final String VERSION;
|
public static final String VERSION;
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -67,8 +68,8 @@ public class StartArgs
|
||||||
private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration";
|
private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration";
|
||||||
|
|
||||||
private List<String> commandLine = new ArrayList<>();
|
private List<String> commandLine = new ArrayList<>();
|
||||||
private Set<String> enabledModules = new HashSet<>();
|
private Set<String> modules = new HashSet<>();
|
||||||
private Map<String,List<String>> moduleSources = new HashMap<>();
|
private Map<String,List<String>> sources = new HashMap<>();
|
||||||
private List<String> downloads = new ArrayList<>();
|
private List<String> downloads = new ArrayList<>();
|
||||||
private Classpath classpath;
|
private Classpath classpath;
|
||||||
private List<String> xmlRefs = new ArrayList<>();
|
private List<String> xmlRefs = new ArrayList<>();
|
||||||
|
@ -76,6 +77,8 @@ public class StartArgs
|
||||||
private Properties properties = new Properties();
|
private Properties properties = new Properties();
|
||||||
private Set<String> systemPropertyKeys = new HashSet<>();
|
private Set<String> systemPropertyKeys = new HashSet<>();
|
||||||
private List<String> jvmArgs = new ArrayList<>();
|
private List<String> jvmArgs = new ArrayList<>();
|
||||||
|
private List<String> enable = new ArrayList<>();
|
||||||
|
private List<String> disable = new ArrayList<>();
|
||||||
private Modules allModules;
|
private Modules allModules;
|
||||||
|
|
||||||
// Should the server be run?
|
// Should the server be run?
|
||||||
|
@ -323,6 +326,16 @@ public class StartArgs
|
||||||
return this.commandLine;
|
return this.commandLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getEnable()
|
||||||
|
{
|
||||||
|
return enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getDisable()
|
||||||
|
{
|
||||||
|
return disable;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getDownloads()
|
public List<String> getDownloads()
|
||||||
{
|
{
|
||||||
return downloads;
|
return downloads;
|
||||||
|
@ -330,7 +343,7 @@ public class StartArgs
|
||||||
|
|
||||||
public Set<String> getEnabledModules()
|
public Set<String> getEnabledModules()
|
||||||
{
|
{
|
||||||
return this.enabledModules;
|
return this.modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getJvmArgs()
|
public List<String> getJvmArgs()
|
||||||
|
@ -338,9 +351,9 @@ public class StartArgs
|
||||||
return jvmArgs;
|
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
|
public CommandLineBuilder getMainArgs(BaseHome baseHome, boolean addJavaInit) throws IOException
|
||||||
|
@ -424,6 +437,22 @@ public class StartArgs
|
||||||
return value;
|
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()
|
public List<File> getXmlFiles()
|
||||||
{
|
{
|
||||||
return xmls;
|
return xmls;
|
||||||
|
@ -488,6 +517,9 @@ public class StartArgs
|
||||||
{
|
{
|
||||||
if ("--help".equals(arg) || "-?".equals(arg))
|
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;
|
help = true;
|
||||||
run = false;
|
run = false;
|
||||||
return;
|
return;
|
||||||
|
@ -501,6 +533,8 @@ public class StartArgs
|
||||||
|
|
||||||
if ("--stop".equals(arg))
|
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;
|
stopCommand = true;
|
||||||
run = false;
|
run = false;
|
||||||
//
|
//
|
||||||
|
@ -541,6 +575,8 @@ public class StartArgs
|
||||||
|
|
||||||
if ("--dry-run".equals(arg) || "--exec-print".equals(arg))
|
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;
|
dryRun = true;
|
||||||
run = false;
|
run = false;
|
||||||
return;
|
return;
|
||||||
|
@ -554,44 +590,41 @@ public class StartArgs
|
||||||
|
|
||||||
if (arg.startsWith("--enable="))
|
if (arg.startsWith("--enable="))
|
||||||
{
|
{
|
||||||
String moduleName = getValue(arg);
|
if (!CMD_LINE_SOURCE.equals(source))
|
||||||
// TODO:
|
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
|
||||||
|
enable.addAll(getValues(arg));
|
||||||
run = false;
|
run = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.startsWith("--disable="))
|
if (arg.startsWith("--disable="))
|
||||||
{
|
{
|
||||||
String moduleName = getValue(arg);
|
if (!CMD_LINE_SOURCE.equals(source))
|
||||||
// TODO:
|
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
|
||||||
|
disable.addAll(getValues(arg));
|
||||||
run = false;
|
run = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.startsWith("--module="))
|
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();
|
list.add(source);
|
||||||
enabledModules.add(moduleName);
|
|
||||||
List<String> sources=moduleSources.get(moduleName);
|
|
||||||
if (sources==null)
|
|
||||||
{
|
|
||||||
sources=new ArrayList<String>();
|
|
||||||
moduleSources.put(moduleName,sources);
|
|
||||||
}
|
|
||||||
sources.add(source);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.startsWith("MODULE=") || arg.startsWith("MODULES="))
|
if (arg.startsWith("MODULE=") || arg.startsWith("MODULES="))
|
||||||
{
|
{
|
||||||
System.err.println("ERROR: Ignored deprecated arg: "+arg);
|
StartLog.warn("Ignored deprecated arg: {}",arg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -672,7 +705,7 @@ public class StartArgs
|
||||||
{
|
{
|
||||||
for (String line : commandLine)
|
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("StartArgs [commandLine=");
|
||||||
builder.append(commandLine);
|
builder.append(commandLine);
|
||||||
builder.append(", enabledModules=");
|
builder.append(", enabledModules=");
|
||||||
builder.append(enabledModules);
|
builder.append(modules);
|
||||||
builder.append(", xmlRefs=");
|
builder.append(", xmlRefs=");
|
||||||
builder.append(xmlRefs);
|
builder.append(xmlRefs);
|
||||||
builder.append(", properties=");
|
builder.append(", properties=");
|
||||||
|
|
Loading…
Reference in New Issue