Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ protected void createOptionsForCmdArgumentHandler() {
Option fileIDOption = new Option(Constants.FILE_ID_ARG, Constants.HAS_ARGUMENT, "The id for the file to perform the operation on.");
fileIDOption.setRequired(isFileIDArgumentRequired());
cmdHandler.addOption(fileIDOption);

Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " +
"pillar where the operation should be performed. If undefined the operation is performed on all pillars.");
pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED);
cmdHandler.addOption(pillarOption);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ private Constants() {}
/**
* The argument for the location of the results.
*/
public static final String LOCATION = "l";
public static final String LOCATION_ARG = "l";

public static final String PILLAR_DESC =
"The id of the pillar where the operation should be performed. " +
"If undefined the operation is performed on all pillars.";

public static final int EXIT_SUCCESS = 0;
public static final int EXIT_ARGUMENT_FAILURE = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ protected boolean isFileIDArgumentRequired() {
protected void createOptionsForCmdArgumentHandler() {
super.createOptionsForCmdArgumentHandler();

Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, Constants.PILLAR_DESC);
pillarOption.setRequired(Constants.ARGUMENT_IS_REQUIRED);
cmdHandler.addOption(pillarOption);

Option checksumOption = new Option(Constants.CHECKSUM_ARG, Constants.HAS_ARGUMENT,
"[OPTIONAL] The checksum of the file to be deleted.");
checksumOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ protected boolean isFileIDArgumentRequired() {
protected void createOptionsForCmdArgumentHandler() {
super.createOptionsForCmdArgumentHandler();

Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT,
"[OPTIONAL] " + Constants.PILLAR_DESC);
pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED);
cmdHandler.addOption(pillarOption);

Option checksumTypeOption = new Option(Constants.REQUEST_CHECKSUM_TYPE_ARG, Constants.HAS_ARGUMENT,
"[OPTIONAL] The algorithm of checksum to request in the response from the pillars. "
+ "If no such argument is given, then the default from settings is retrieved.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ protected boolean isFileIDArgumentRequired() {
@Override
protected void createOptionsForCmdArgumentHandler() {
super.createOptionsForCmdArgumentHandler();
Option checksumOption = new Option(Constants.LOCATION, Constants.HAS_ARGUMENT,

Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT,
"[OPTIONAL] " + Constants.PILLAR_DESC);
pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED);
cmdHandler.addOption(pillarOption);

Option checksumOption = new Option(Constants.LOCATION_ARG, Constants.HAS_ARGUMENT,
"[OPTIONAL] The location where the file should be placed (either total path or directory). "
+ "If no argument, then the file is placed in the directory where the script is located.");
checksumOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED);
Expand Down Expand Up @@ -128,8 +134,8 @@ private OperationEvent performConversation() {
private void downloadFile() {
output.debug("Downloading the file.");
File outputFile;
if (cmdHandler.hasOption(Constants.LOCATION)) {
File location = new File(cmdHandler.getOptionValue(Constants.LOCATION));
if (cmdHandler.hasOption(Constants.LOCATION_ARG)) {
File location = new File(cmdHandler.getOptionValue(Constants.LOCATION_ARG));
if (location.isDirectory()) {
outputFile = new File(location, cmdHandler.getOptionValue(Constants.FILE_ID_ARG));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package org.bitrepository.commandline;

import org.apache.commons.cli.Option;
import org.bitrepository.access.AccessComponentFactory;
import org.bitrepository.access.getfileids.GetFileIDsClient;
import org.bitrepository.commandline.clients.PagingGetFileIDsClient;
Expand Down Expand Up @@ -65,6 +66,16 @@ protected GetFileIDsCmd(String... args) {
pagingClient = new PagingGetFileIDsClient(client, getTimeout(), pageSize, outputFormatter, output);
}

@Override
protected void createOptionsForCmdArgumentHandler() {
super.createOptionsForCmdArgumentHandler();

Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT,
"[OPTIONAL] " + Constants.PILLAR_DESC);
pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED);
cmdHandler.addOption(pillarOption);
}

@Override
protected boolean isFileIDArgumentRequired() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.net.URL;

import static org.bitrepository.commandline.Constants.ARGUMENT_IS_NOT_REQUIRED;
import static org.bitrepository.commandline.Constants.ARGUMENT_IS_REQUIRED;
import static org.bitrepository.commandline.Constants.CHECKSUM_ARG;
import static org.bitrepository.commandline.Constants.DELETE_FILE_ARG;
import static org.bitrepository.commandline.Constants.EXIT_ARGUMENT_FAILURE;
Expand Down Expand Up @@ -84,17 +85,26 @@ protected boolean isFileIDArgumentRequired() {
protected void createOptionsForCmdArgumentHandler() {
super.createOptionsForCmdArgumentHandler();

Option checksumOption = new Option(CHECKSUM_ARG, HAS_ARGUMENT, "[OPTIONAL] The checksum of the file to be replaced.");
Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, Constants.PILLAR_DESC);
pillarOption.setRequired(Constants.ARGUMENT_IS_REQUIRED);
cmdHandler.addOption(pillarOption);

Option checksumOption = new Option(CHECKSUM_ARG, HAS_ARGUMENT,
"The checksum of the file to be replaced.");
// Setting can allow -C to be non-required, so set it as so.
checksumOption.setRequired(ARGUMENT_IS_NOT_REQUIRED);
cmdHandler.addOption(checksumOption);

Option fileOption = new Option(FILE_ARG, HAS_ARGUMENT,
"The path to the new file for the replacement. Required unless using the URL argument.");
fileOption.setRequired(ARGUMENT_IS_NOT_REQUIRED);
cmdHandler.addOption(fileOption);

Option urlOption = new Option(URL_ARG, HAS_ARGUMENT,
"The URL for the file to be retrieved. Is required, unless the actual file is given.");
urlOption.setRequired(ARGUMENT_IS_NOT_REQUIRED);
cmdHandler.addOption(urlOption);

Option replaceChecksumOption = new Option(REPLACE_CHECKSUM_ARG, HAS_ARGUMENT,
"The checksum for the file to replace with. Required when using the URL argument.");
replaceChecksumOption.setRequired(ARGUMENT_IS_NOT_REQUIRED);
Expand All @@ -104,8 +114,10 @@ protected void createOptionsForCmdArgumentHandler() {
"[OPTIONAL] The algorithm of checksum to request in the response from the pillars.");
checksumTypeOption.setRequired(ARGUMENT_IS_NOT_REQUIRED);
cmdHandler.addOption(checksumTypeOption);

Option checksumSaltOption = new Option(REQUEST_CHECKSUM_SALT_ARG, HAS_ARGUMENT,
"[OPTIONAL] The salt of checksum to request in the response. Requires the ChecksumType argument.");
"[OPTIONAL] The salt of checksum to request in the response. " +
"Requires the ChecksumType argument.");
checksumSaltOption.setRequired(ARGUMENT_IS_NOT_REQUIRED);
cmdHandler.addOption(checksumSaltOption);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,6 @@ public void missingCollectionArgumentTest() throws Exception {
new PutFileCmd(args);
}

@Test(groups = { "regressiontest" })
public void specificPillarArgumentTest() throws Exception {
addDescription("Test argument for a specific pillar");
String[] args = new String[]{"-s" + SETTINGS_DIR,
"-k" + KEY_FILE,
"-u" + DEFAULT_UPLOAD_FILE_ADDRESS,
"-C" + DEFAULT_CHECKSUM,
"-c" + DEFAULT_COLLECTION_ID,
"-p" + PILLAR1_ID,
"-i" + DEFAULT_FILE_ID};
new PutFileCmd(args);
}

@Test(groups = { "regressiontest" }, expectedExceptions = IllegalArgumentException.class)
public void unknownPillarArgumentTest() throws Exception {
addDescription("Testing against a non-existing pillar id -> Should fail");
String[] args = new String[]{"-s" + SETTINGS_DIR,
"-k" + KEY_FILE,
"-u" + DEFAULT_UPLOAD_FILE_ADDRESS,
"-C" + DEFAULT_CHECKSUM,
"-c" + DEFAULT_COLLECTION_ID,
"-p" + "Random" + (new Date()).getTime() + "pillar",
"-i" + DEFAULT_FILE_ID};
new PutFileCmd(args);
}

@Test(groups = { "regressiontest" }, expectedExceptions = IllegalArgumentException.class)
public void missingFileOrURLArgumentTest() throws Exception {
addDescription("Tests the scenario, where no arguments for file or url is given.");
Expand Down