mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 09:17:42 +00:00
Merge pull request #6231 from kellykelly3/6787-commandline-failure-issue
6787 commandline failure issue
This commit is contained in:
commit
9be752c45d
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Autopsy Forensic Browser
|
|
||||||
*
|
|
||||||
* Copyright 2014 Basis Technology Corp.
|
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.sleuthkit.autopsy.casemodule;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import org.netbeans.api.sendopts.CommandException;
|
|
||||||
import org.netbeans.spi.sendopts.Env;
|
|
||||||
import org.netbeans.spi.sendopts.Option;
|
|
||||||
import org.netbeans.spi.sendopts.OptionProcessor;
|
|
||||||
import org.openide.util.lookup.ServiceProvider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows Autopsy to get path to .aut file passed in via associating the file
|
|
||||||
* type in Windows.
|
|
||||||
*/
|
|
||||||
@ServiceProvider(service = OptionProcessor.class)
|
|
||||||
public class OpenFromArguments extends OptionProcessor {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Stores the .aut file if it was passed in as argument
|
|
||||||
*/
|
|
||||||
private String autPath = "";
|
|
||||||
private final Option option1 = Option.defaultArguments();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Set<Option> getOptions() {
|
|
||||||
final Set<Option> options = new HashSet<>();
|
|
||||||
options.add(option1);
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void process(Env env, Map<Option, String[]> maps) throws CommandException {
|
|
||||||
if (maps.containsKey(option1)) {
|
|
||||||
autPath = maps.get(option1)[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDefaultArg() {
|
|
||||||
return autPath;
|
|
||||||
}
|
|
||||||
}
|
|
@ -59,14 +59,14 @@ public class StartupWindowProvider implements StartupWindowInterface {
|
|||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
if (startupWindowToUse == null) {
|
if (startupWindowToUse == null) {
|
||||||
|
|
||||||
if (openCaseInUI()) {
|
|
||||||
new CommandLineOpenCaseManager().start();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// first check whether we are running from command line
|
// first check whether we are running from command line
|
||||||
if (isRunningFromCommandLine()) {
|
if (isRunningFromCommandLine()) {
|
||||||
|
|
||||||
|
String defaultArg = getDefaultArgument();
|
||||||
|
if(defaultArg != null) {
|
||||||
|
new CommandLineOpenCaseManager(defaultArg).start();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
// Autopsy is running from command line
|
// Autopsy is running from command line
|
||||||
logger.log(Level.INFO, "Running from command line"); //NON-NLS
|
logger.log(Level.INFO, "Running from command line"); //NON-NLS
|
||||||
startupWindowToUse = new CommandLineStartupWindow();
|
startupWindowToUse = new CommandLineStartupWindow();
|
||||||
@ -74,6 +74,7 @@ public class StartupWindowProvider implements StartupWindowInterface {
|
|||||||
new CommandLineIngestManager().start();
|
new CommandLineIngestManager().start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//discover the registered windows
|
//discover the registered windows
|
||||||
Collection<? extends StartupWindowInterface> startupWindows
|
Collection<? extends StartupWindowInterface> startupWindows
|
||||||
@ -124,40 +125,24 @@ public class StartupWindowProvider implements StartupWindowInterface {
|
|||||||
*/
|
*/
|
||||||
private boolean isRunningFromCommandLine() {
|
private boolean isRunningFromCommandLine() {
|
||||||
|
|
||||||
// first look up all OptionProcessors and see if running from command line option is set
|
CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
|
||||||
Collection<? extends OptionProcessor> optionProcessors = Lookup.getDefault().lookupAll(OptionProcessor.class);
|
if(processor != null) {
|
||||||
Iterator<? extends OptionProcessor> optionsIterator = optionProcessors.iterator();
|
return processor.isRunFromCommandLine();
|
||||||
while (optionsIterator.hasNext()) {
|
|
||||||
// find CommandLineOptionProcessor
|
|
||||||
OptionProcessor processor = optionsIterator.next();
|
|
||||||
if ((processor instanceof CommandLineOptionProcessor)) {
|
|
||||||
// check if we are running from command line
|
|
||||||
return ((CommandLineOptionProcessor) processor).isRunFromCommandLine();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether Autopsy was launched from the command line with the option
|
* Get the default argument from the CommandLineOptionProcessor.
|
||||||
* to open an existing case.
|
|
||||||
*
|
*
|
||||||
* @return True if opening an existing case.
|
* @return If set, the default argument otherwise null.
|
||||||
*/
|
*/
|
||||||
private boolean openCaseInUI() {
|
private String getDefaultArgument() {
|
||||||
// first look up all OptionProcessors and see if running from command line option is set
|
CommandLineOptionProcessor processor = Lookup.getDefault().lookup(CommandLineOptionProcessor.class);
|
||||||
Collection<? extends OptionProcessor> optionProcessors = Lookup.getDefault().lookupAll(OptionProcessor.class);
|
if(processor != null) {
|
||||||
Iterator<? extends OptionProcessor> optionsIterator = optionProcessors.iterator();
|
return processor.getDefaultArgument();
|
||||||
while (optionsIterator.hasNext()) {
|
|
||||||
// find CommandLineOptionProcessor
|
|
||||||
OptionProcessor processor = optionsIterator.next();
|
|
||||||
if ((processor instanceof OpenFromArguments)) {
|
|
||||||
// check if we are running from command line
|
|
||||||
String arg = ((OpenFromArguments) processor).getDefaultArg();
|
|
||||||
return arg != null && !arg.isEmpty();
|
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,14 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.commandlineingest;
|
package org.sleuthkit.autopsy.commandlineingest;
|
||||||
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.netbeans.spi.sendopts.OptionProcessor;
|
|
||||||
import org.openide.util.Lookup;
|
|
||||||
import org.sleuthkit.autopsy.casemodule.CaseActionException;
|
import org.sleuthkit.autopsy.casemodule.CaseActionException;
|
||||||
import org.sleuthkit.autopsy.casemodule.OpenFromArguments;
|
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,6 +29,11 @@ import org.sleuthkit.autopsy.coreutils.Logger;
|
|||||||
public class CommandLineOpenCaseManager extends CommandLineManager {
|
public class CommandLineOpenCaseManager extends CommandLineManager {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(CommandLineOpenCaseManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(CommandLineOpenCaseManager.class.getName());
|
||||||
|
private final String casePath;
|
||||||
|
|
||||||
|
public CommandLineOpenCaseManager(String casePath) {
|
||||||
|
this.casePath = casePath;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the thread to open the case.
|
* Starts the thread to open the case.
|
||||||
@ -51,21 +50,6 @@ public class CommandLineOpenCaseManager extends CommandLineManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String casePath = "";
|
|
||||||
|
|
||||||
// first look up all OptionProcessors and get input data from CommandLineOptionProcessor
|
|
||||||
Collection<? extends OptionProcessor> optionProcessors = Lookup.getDefault().lookupAll(OptionProcessor.class);
|
|
||||||
Iterator<? extends OptionProcessor> optionsIterator = optionProcessors.iterator();
|
|
||||||
while (optionsIterator.hasNext()) {
|
|
||||||
// find CommandLineOptionProcessor
|
|
||||||
OptionProcessor processor = optionsIterator.next();
|
|
||||||
if (processor instanceof OpenFromArguments) {
|
|
||||||
// check if we are running from command line
|
|
||||||
casePath = Paths.get(((OpenFromArguments) processor).getDefaultArg()).toAbsolutePath().toString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (casePath == null || casePath.isEmpty()) {
|
if (casePath == null || casePath.isEmpty()) {
|
||||||
LOGGER.log(Level.SEVERE, "No command line commands specified");
|
LOGGER.log(Level.SEVERE, "No command line commands specified");
|
||||||
System.out.println("No command line commands specified");
|
System.out.println("No command line commands specified");
|
||||||
|
@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.commandlineingest;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -52,6 +53,7 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
private final Option ingestProfileOption = Option.requiredArgument('p', "ingestProfile");
|
private final Option ingestProfileOption = Option.requiredArgument('p', "ingestProfile");
|
||||||
private final Option listAllDataSourcesCommandOption = Option.withoutArgument('l', "listAllDataSources");
|
private final Option listAllDataSourcesCommandOption = Option.withoutArgument('l', "listAllDataSources");
|
||||||
private final Option generateReportsOption = Option.optionalArgument('g', "generateReports");
|
private final Option generateReportsOption = Option.optionalArgument('g', "generateReports");
|
||||||
|
private final Option defaultArgument = Option.defaultArguments();
|
||||||
|
|
||||||
private boolean runFromCommandLine = false;
|
private boolean runFromCommandLine = false;
|
||||||
|
|
||||||
@ -60,6 +62,8 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
final static String CASETYPE_MULTI = "multi";
|
final static String CASETYPE_MULTI = "multi";
|
||||||
final static String CASETYPE_SINGLE = "single";
|
final static String CASETYPE_SINGLE = "single";
|
||||||
|
|
||||||
|
private String defaultArgumentValue = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Option> getOptions() {
|
protected Set<Option> getOptions() {
|
||||||
Set<Option> set = new HashSet<>();
|
Set<Option> set = new HashSet<>();
|
||||||
@ -75,6 +79,7 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
set.add(ingestProfileOption);
|
set.add(ingestProfileOption);
|
||||||
set.add(listAllDataSourcesCommandOption);
|
set.add(listAllDataSourcesCommandOption);
|
||||||
set.add(generateReportsOption);
|
set.add(generateReportsOption);
|
||||||
|
set.add(defaultArgument);
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,16 +87,19 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
protected void process(Env env, Map<Option, String[]> values) throws CommandException {
|
protected void process(Env env, Map<Option, String[]> values) throws CommandException {
|
||||||
logger.log(Level.INFO, "Processing Autopsy command line options"); //NON-NLS
|
logger.log(Level.INFO, "Processing Autopsy command line options"); //NON-NLS
|
||||||
System.out.println("Processing Autopsy command line options");
|
System.out.println("Processing Autopsy command line options");
|
||||||
runFromCommandLine = false;
|
|
||||||
|
if (values.containsKey(defaultArgument)) {
|
||||||
|
defaultArgumentValue = values.get(defaultArgument)[0];
|
||||||
|
runFromCommandLine = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// input arguments must contain at least one command
|
// input arguments must contain at least one command
|
||||||
if (!(values.containsKey(createCaseCommandOption) || values.containsKey(addDataSourceCommandOption)
|
if (!(values.containsKey(createCaseCommandOption) || values.containsKey(addDataSourceCommandOption)
|
||||||
|| values.containsKey(runIngestCommandOption) || values.containsKey(listAllDataSourcesCommandOption)
|
|| values.containsKey(runIngestCommandOption) || values.containsKey(listAllDataSourcesCommandOption)
|
||||||
|| values.containsKey(generateReportsOption))) {
|
|| values.containsKey(generateReportsOption))) {
|
||||||
// not running from command line
|
// not running from command line
|
||||||
logger.log(Level.INFO, "No command line commands passed in as inputs. Not running from command line."); //NON-NLS
|
handleError("Invalid command line, an input option must be supplied.");
|
||||||
System.out.println("No command line commands passed in as inputs. Not running from command line.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse input parameters
|
// parse input parameters
|
||||||
@ -100,16 +108,12 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
if (values.containsKey(caseNameOption)) {
|
if (values.containsKey(caseNameOption)) {
|
||||||
argDirs = values.get(caseNameOption);
|
argDirs = values.get(caseNameOption);
|
||||||
if (argDirs.length < 1) {
|
if (argDirs.length < 1) {
|
||||||
logger.log(Level.SEVERE, "Missing argument 'caseName'");
|
handleError("Missing argument 'caseName'");
|
||||||
System.out.println("Missing argument 'caseName'");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
inputCaseName = argDirs[0];
|
inputCaseName = argDirs[0];
|
||||||
|
|
||||||
if (inputCaseName == null || inputCaseName.isEmpty()) {
|
if (inputCaseName == null || inputCaseName.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "'caseName' argument is empty");
|
handleError("'caseName' argument is empty");
|
||||||
System.out.println("'caseName' argument is empty");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,28 +122,16 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
argDirs = values.get(caseTypeOption);
|
argDirs = values.get(caseTypeOption);
|
||||||
|
|
||||||
if (argDirs.length < 1) {
|
if (argDirs.length < 1) {
|
||||||
logger.log(Level.SEVERE, "Missing argument 'caseType'");
|
handleError("Missing argument 'caseType'");
|
||||||
System.out.println("Missing argument 'caseType'");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
caseType = argDirs[0];
|
caseType = argDirs[0];
|
||||||
|
|
||||||
if (caseType == null || caseType.isEmpty()) {
|
if (caseType == null || caseType.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "'caseType' argument is empty");
|
handleError("'caseType' argument is empty");
|
||||||
System.out.println("'caseType' argument is empty");
|
} else if (!caseType.equalsIgnoreCase(CASETYPE_MULTI) && !caseType.equalsIgnoreCase(CASETYPE_SINGLE)) {
|
||||||
return;
|
handleError("'caseType' argument is invalid");
|
||||||
}
|
} else if (caseType.equalsIgnoreCase(CASETYPE_MULTI) && !FeatureAccessUtils.canCreateMultiUserCases()) {
|
||||||
|
handleError("Unable to create multi user case. Confirm that multi user settings are configured correctly.");
|
||||||
if (!caseType.equalsIgnoreCase(CASETYPE_MULTI) && !caseType.equalsIgnoreCase(CASETYPE_SINGLE)) {
|
|
||||||
logger.log(Level.SEVERE, "'caseType' argument is invalid");
|
|
||||||
System.out.println("'caseType' argument is invalid");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (caseType.equalsIgnoreCase(CASETYPE_MULTI) && !FeatureAccessUtils.canCreateMultiUserCases()) {
|
|
||||||
logger.log(Level.SEVERE, "Unable to create multi user case.");
|
|
||||||
System.out.println("Unable to create multi user case. Confirm that multi user settings are configured correctly.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,22 +139,16 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
if (values.containsKey(caseBaseDirOption)) {
|
if (values.containsKey(caseBaseDirOption)) {
|
||||||
argDirs = values.get(caseBaseDirOption);
|
argDirs = values.get(caseBaseDirOption);
|
||||||
if (argDirs.length < 1) {
|
if (argDirs.length < 1) {
|
||||||
logger.log(Level.SEVERE, "Missing argument 'caseBaseDir'");
|
handleError("Missing argument 'caseBaseDir'");
|
||||||
System.out.println("Missing argument 'caseBaseDir'");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
caseBaseDir = argDirs[0];
|
caseBaseDir = argDirs[0];
|
||||||
|
|
||||||
if (caseBaseDir == null || caseBaseDir.isEmpty()) {
|
if (caseBaseDir == null || caseBaseDir.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "Missing argument 'caseBaseDir' option");
|
handleError("Missing argument 'caseBaseDir' option");
|
||||||
System.out.println("Missing argument 'caseBaseDir' option");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(new File(caseBaseDir).exists()) || !(new File(caseBaseDir).isDirectory())) {
|
if (!(new File(caseBaseDir).exists()) || !(new File(caseBaseDir).isDirectory())) {
|
||||||
logger.log(Level.SEVERE, "'caseBaseDir' {0} directory doesn''t exist or is not a directory", caseBaseDir);
|
handleError("'caseBaseDir' directory doesn't exist or is not a directory: " + caseBaseDir);
|
||||||
System.out.println("'caseBaseDir' directory doesn't exist or is not a directory: " + caseBaseDir);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,23 +157,17 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
|
|
||||||
argDirs = values.get(dataSourcePathOption);
|
argDirs = values.get(dataSourcePathOption);
|
||||||
if (argDirs.length < 1) {
|
if (argDirs.length < 1) {
|
||||||
logger.log(Level.SEVERE, "Missing argument 'dataSourcePath'");
|
handleError("Missing argument 'dataSourcePath'");
|
||||||
System.out.println("Missing argument 'dataSourcePath'");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
dataSourcePath = argDirs[0];
|
dataSourcePath = argDirs[0];
|
||||||
|
|
||||||
// verify inputs
|
// verify inputs
|
||||||
if (dataSourcePath == null || dataSourcePath.isEmpty()) {
|
if (dataSourcePath == null || dataSourcePath.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "Missing argument 'dataSourcePath'");
|
handleError("Missing argument 'dataSourcePath'");
|
||||||
System.out.println("Missing argument 'dataSourcePath'");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(new File(dataSourcePath).exists())) {
|
if (!(new File(dataSourcePath).exists())) {
|
||||||
logger.log(Level.SEVERE, "Input data source file {0} doesn''t exist", dataSourcePath);
|
handleError("Input data source file " + dataSourcePath + " doesn't exist");
|
||||||
System.out.println("Input data source file " + dataSourcePath + " doesn't exist");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,17 +176,13 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
|
|
||||||
argDirs = values.get(dataSourceObjectIdOption);
|
argDirs = values.get(dataSourceObjectIdOption);
|
||||||
if (argDirs.length < 1) {
|
if (argDirs.length < 1) {
|
||||||
logger.log(Level.SEVERE, "Missing argument 'dataSourceObjectIdOption'");
|
handleError("Missing argument 'dataSourceObjectIdOption'");
|
||||||
System.out.println("Missing argument 'dataSourceObjectIdOption'");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
dataSourceId = argDirs[0];
|
dataSourceId = argDirs[0];
|
||||||
|
|
||||||
// verify inputs
|
// verify inputs
|
||||||
if (dataSourceId == null || dataSourceId.isEmpty()) {
|
if (dataSourceId == null || dataSourceId.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "Input data source id is empty");
|
handleError("Input data source id is empty");
|
||||||
System.out.println("Input data source id is empty");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,23 +191,17 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
|
|
||||||
argDirs = values.get(caseDirOption);
|
argDirs = values.get(caseDirOption);
|
||||||
if (argDirs.length < 1) {
|
if (argDirs.length < 1) {
|
||||||
logger.log(Level.SEVERE, "Argument missing from 'caseDir' option");
|
handleError("Argument missing from 'caseDir' option");
|
||||||
System.out.println("Argument missing from 'caseDir' option");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
caseDir = argDirs[0];
|
caseDir = argDirs[0];
|
||||||
|
|
||||||
// verify inputs
|
// verify inputs
|
||||||
if (caseDir == null || caseDir.isEmpty()) {
|
if (caseDir == null || caseDir.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "Argument missing from 'caseDir'");
|
handleError("Argument missing from 'caseDir'");
|
||||||
System.out.println("Argument missing from 'caseDir'");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(new File(caseDir).exists()) || !(new File(caseDir).isDirectory())) {
|
if (!(new File(caseDir).exists()) || !(new File(caseDir).isDirectory())) {
|
||||||
logger.log(Level.SEVERE, "Case directory {0} does not exist or is not a directory", caseDir);
|
handleError("Case directory " + caseDir + " does not exist or is not a directory");
|
||||||
System.out.println("Case directory " + caseDir + " does not exist or is not a directory");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,17 +210,13 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
|
|
||||||
argDirs = values.get(ingestProfileOption);
|
argDirs = values.get(ingestProfileOption);
|
||||||
if (argDirs.length < 1) {
|
if (argDirs.length < 1) {
|
||||||
logger.log(Level.SEVERE, "Argument missing from 'ingestProfile' option");
|
handleError("Argument missing from 'ingestProfile' option");
|
||||||
System.out.println("Argument missing from 'ingestProfile' option");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
ingestProfile = argDirs[0];
|
ingestProfile = argDirs[0];
|
||||||
|
|
||||||
// verify inputs
|
// verify inputs
|
||||||
if (ingestProfile == null || ingestProfile.isEmpty()) {
|
if (ingestProfile == null || ingestProfile.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "Missing argument 'ingestProfile'");
|
handleError("Missing argument 'ingestProfile'");
|
||||||
System.out.println("Missing argument 'ingestProfile'");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,19 +225,13 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
if (values.containsKey(createCaseCommandOption)) {
|
if (values.containsKey(createCaseCommandOption)) {
|
||||||
|
|
||||||
// 'caseName' must always be specified for "CREATE_CASE" command
|
// 'caseName' must always be specified for "CREATE_CASE" command
|
||||||
if (inputCaseName.isEmpty()) {
|
if (inputCaseName == null || inputCaseName.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "'caseName' argument is empty");
|
handleError("'caseName' argument is empty");
|
||||||
System.out.println("'caseName' argument is empty");
|
|
||||||
runFromCommandLine = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 'caseBaseDir' must always be specified for "CREATE_CASE" command
|
// 'caseBaseDir' must always be specified for "CREATE_CASE" command
|
||||||
if (caseBaseDir.isEmpty()) {
|
if (caseBaseDir == null || caseBaseDir.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "'caseBaseDir' argument is empty");
|
handleError("'caseBaseDir' argument is empty");
|
||||||
System.out.println("'caseBaseDir' argument is empty");
|
|
||||||
runFromCommandLine = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.CREATE_CASE);
|
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.CREATE_CASE);
|
||||||
@ -288,18 +248,12 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
// 'caseDir' must only be specified if the case is not being created during the current run
|
// 'caseDir' must only be specified if the case is not being created during the current run
|
||||||
if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
|
if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
|
||||||
// new case is not being created during this run, so 'caseDir' should have been specified
|
// new case is not being created during this run, so 'caseDir' should have been specified
|
||||||
logger.log(Level.SEVERE, "'caseDir' argument is empty");
|
handleError("'caseDir' argument is empty");
|
||||||
System.out.println("'caseDir' argument is empty");
|
|
||||||
runFromCommandLine = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 'dataSourcePath' must always be specified for "ADD_DATA_SOURCE" command
|
// 'dataSourcePath' must always be specified for "ADD_DATA_SOURCE" command
|
||||||
if (dataSourcePath.isEmpty()) {
|
if (dataSourcePath == null || dataSourcePath.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "'dataSourcePath' argument is empty");
|
handleError("'dataSourcePath' argument is empty");
|
||||||
System.out.println("'dataSourcePath' argument is empty");
|
|
||||||
runFromCommandLine = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.ADD_DATA_SOURCE);
|
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.ADD_DATA_SOURCE);
|
||||||
@ -315,19 +269,13 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
// 'caseDir' must only be specified if the case is not being created during the current run
|
// 'caseDir' must only be specified if the case is not being created during the current run
|
||||||
if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
|
if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
|
||||||
// new case is not being created during this run, so 'caseDir' should have been specified
|
// new case is not being created during this run, so 'caseDir' should have been specified
|
||||||
logger.log(Level.SEVERE, "'caseDir' argument is empty");
|
handleError("'caseDir' argument is empty");
|
||||||
System.out.println("'caseDir' argument is empty");
|
|
||||||
runFromCommandLine = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if new data source is being added during this run, then 'dataSourceId' is not specified
|
// if new data source is being added during this run, then 'dataSourceId' is not specified
|
||||||
if (!values.containsKey(addDataSourceCommandOption) && dataSourceId.isEmpty()) {
|
if (!values.containsKey(addDataSourceCommandOption) && dataSourceId.isEmpty()) {
|
||||||
// data source is not being added during this run, so 'dataSourceId' should have been specified
|
// data source is not being added during this run, so 'dataSourceId' should have been specified
|
||||||
logger.log(Level.SEVERE, "'dataSourceId' argument is empty");
|
handleError("'dataSourceId' argument is empty");
|
||||||
System.out.println("'dataSourceId' argument is empty");
|
|
||||||
runFromCommandLine = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.RUN_INGEST);
|
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.RUN_INGEST);
|
||||||
@ -342,12 +290,9 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
if (values.containsKey(listAllDataSourcesCommandOption)) {
|
if (values.containsKey(listAllDataSourcesCommandOption)) {
|
||||||
|
|
||||||
// 'caseDir' must only be specified if the case is not being created during the current run
|
// 'caseDir' must only be specified if the case is not being created during the current run
|
||||||
if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
|
if (!values.containsKey(createCaseCommandOption) && (caseDir == null || caseDir.isEmpty())) {
|
||||||
// new case is not being created during this run, so 'caseDir' should have been specified
|
// new case is not being created during this run, so 'caseDir' should have been specified
|
||||||
logger.log(Level.SEVERE, "'caseDir' argument is empty");
|
handleError("'caseDir' argument is empty");
|
||||||
System.out.println("'caseDir' argument is empty");
|
|
||||||
runFromCommandLine = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.LIST_ALL_DATA_SOURCES);
|
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.LIST_ALL_DATA_SOURCES);
|
||||||
@ -363,10 +308,7 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
// 'caseDir' must only be specified if the case is not being created during the current run
|
// 'caseDir' must only be specified if the case is not being created during the current run
|
||||||
if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
|
if (!values.containsKey(createCaseCommandOption) && caseDir.isEmpty()) {
|
||||||
// new case is not being created during this run, so 'caseDir' should have been specified
|
// new case is not being created during this run, so 'caseDir' should have been specified
|
||||||
logger.log(Level.SEVERE, "'caseDir' argument is empty");
|
handleError("'caseDir' argument is empty");
|
||||||
System.out.println("'caseDir' argument is empty");
|
|
||||||
runFromCommandLine = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
argDirs = values.get(generateReportsOption);
|
argDirs = values.get(generateReportsOption);
|
||||||
@ -378,10 +320,7 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
// argsDirs length will be 0, so if reportProfile is empty
|
// argsDirs length will be 0, so if reportProfile is empty
|
||||||
// something is not right.
|
// something is not right.
|
||||||
if (reportProfile != null && reportProfile.isEmpty()) {
|
if (reportProfile != null && reportProfile.isEmpty()) {
|
||||||
logger.log(Level.SEVERE, "'generateReports' argument is empty");
|
handleError("'generateReports' argument is empty");
|
||||||
System.out.println("'generateReports' argument is empty");
|
|
||||||
runFromCommandLine = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.GENERATE_REPORTS);
|
CommandLineCommand newCommand = new CommandLineCommand(CommandLineCommand.CommandType.GENERATE_REPORTS);
|
||||||
@ -403,12 +342,33 @@ public class CommandLineOptionProcessor extends OptionProcessor {
|
|||||||
return runFromCommandLine;
|
return runFromCommandLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the value of the default argument.
|
||||||
|
*
|
||||||
|
* @return The default argument value or null if one was not set.
|
||||||
|
*/
|
||||||
|
public String getDefaultArgument() {
|
||||||
|
return defaultArgumentValue;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns list of all commands passed in via command line.
|
* Returns list of all commands passed in via command line.
|
||||||
*
|
*
|
||||||
* @return list of input commands
|
* @return list of input commands
|
||||||
*/
|
*/
|
||||||
List<CommandLineCommand> getCommands() {
|
List<CommandLineCommand> getCommands() {
|
||||||
return commands;
|
return Collections.unmodifiableList(commands);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the error message to the log file and create the exception.
|
||||||
|
*
|
||||||
|
* @param errorMessage
|
||||||
|
*
|
||||||
|
* @throws CommandException
|
||||||
|
*/
|
||||||
|
private void handleError(String errorMessage) throws CommandException {
|
||||||
|
logger.log(Level.SEVERE, errorMessage);
|
||||||
|
throw new CommandException(1, errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user