mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
improve SubCommandHandler
This commit is contained in:
@@ -38,6 +38,7 @@ package sonia.scm.cli.cmd;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.ConfigurationException;
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
@@ -47,6 +48,9 @@ import java.io.BufferedReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -59,7 +63,7 @@ public class SubCommandHandler
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String RESOURCE_SERVICES =
|
public static final String RESOURCE_SERVICES =
|
||||||
"/META-INF/services/".concat(SubCommand.class.getName());
|
"META-INF/services/".concat(SubCommand.class.getName());
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static volatile SubCommandHandler instance;
|
private static volatile SubCommandHandler instance;
|
||||||
@@ -122,17 +126,16 @@ public class SubCommandHandler
|
|||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
*/
|
*/
|
||||||
private void loadSubCommands()
|
private void loadSubCommand(URL url)
|
||||||
{
|
{
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
reader = new BufferedReader(
|
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||||
new InputStreamReader(
|
|
||||||
SubCommandOptionHandler.class.getResourceAsStream(
|
|
||||||
RESOURCE_SERVICES)));
|
|
||||||
|
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
|
|
||||||
@@ -152,6 +155,31 @@ public class SubCommandHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void loadSubCommands()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Enumeration<URL> enm =
|
||||||
|
SubCommandHandler.class.getClassLoader().getResources(
|
||||||
|
RESOURCE_SERVICES);
|
||||||
|
|
||||||
|
while (enm.hasMoreElements())
|
||||||
|
{
|
||||||
|
URL url = enm.nextElement();
|
||||||
|
|
||||||
|
loadSubCommand(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
throw new ConfigurationException("could not load SubComamnds", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user