Skip to content

Add type parameter for Command interface #1273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -29,16 +29,17 @@
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @param <T>
*
*/
public abstract class AbstractCommand implements Command {
public abstract class AbstractCommand<T extends ScmResult> implements Command<T> {
protected Logger logger = LoggerFactory.getLogger(getClass());

protected abstract ScmResult executeCommand(
protected abstract T executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException;

/** {@inheritDoc} */
public final ScmResult execute(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
public final T execute(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException {
if (repository == null) {
throw new NullPointerException("repository cannot be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
*
* @param <T> the type of result returned by this command
*/
public interface Command {
public interface Command<T extends ScmResult> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olamy Is this backwards-compatible enough? It won't affect consumers as ScmProvider does not use this. I consider this a SPI only interface (so only https://github.com/olamy/maven-scm-provider-svnjava would be affected).

/** Plexus component key */
String ROLE = Command.class.getName();

Expand All @@ -40,6 +40,5 @@ public interface Command {
* @return the result object
* @throws ScmException if any
*/
ScmResult execute(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException;
T execute(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;

/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
*
*/
public abstract class AbstractAddCommand extends AbstractCommand {
protected abstract ScmResult executeAddCommand(
public abstract class AbstractAddCommand extends AbstractCommand<AddScmResult> {
protected abstract AddScmResult executeAddCommand(
ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary) throws ScmException;

/** {@inheritDoc} */
protected ScmResult executeCommand(
protected AddScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
return executeAddCommand(
repository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;

/**
* @author Evgeny Mandrikov
* @since 1.4
*/
public abstract class AbstractBlameCommand extends AbstractCommand {
public abstract class AbstractBlameCommand extends AbstractCommand<BlameScmResult> {
public abstract BlameScmResult executeBlameCommand(
ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException;

protected ScmResult executeCommand(
protected BlameScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet workingDirectory, CommandParameters parameters)
throws ScmException {
String file = parameters.getString(CommandParameter.FILE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.maven.scm.ScmBranchParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;

Expand All @@ -33,8 +32,8 @@
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
*
*/
public abstract class AbstractBranchCommand extends AbstractCommand {
protected abstract ScmResult executeBranchCommand(
public abstract class AbstractBranchCommand extends AbstractCommand<BranchScmResult> {
protected abstract BranchScmResult executeBranchCommand(
ScmProviderRepository repository, ScmFileSet fileSet, String branchName, String message)
throws ScmException;

Expand All @@ -48,7 +47,7 @@ protected abstract ScmResult executeBranchCommand(
* @return TODO
* @throws ScmException if any
*/
protected ScmResult executeBranchCommand(
protected BranchScmResult executeBranchCommand(
ScmProviderRepository repository,
ScmFileSet fileSet,
String branchName,
Expand All @@ -58,8 +57,8 @@ protected ScmResult executeBranchCommand(
}

/** {@inheritDoc} */
public ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException {
public BranchScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
String branchName = parameters.getString(CommandParameter.BRANCH_NAME);

ScmBranchParameters scmBranchParameters =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.maven.scm.ScmBranch;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.ScmVersion;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;
Expand All @@ -35,7 +34,7 @@
* @author Olivier Lamy
*
*/
public abstract class AbstractChangeLogCommand extends AbstractCommand implements ChangeLogCommand {
public abstract class AbstractChangeLogCommand extends AbstractCommand<ChangeLogScmResult> implements ChangeLogCommand {
@Deprecated
protected abstract ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repository,
Expand Down Expand Up @@ -67,8 +66,8 @@ protected ChangeLogScmResult executeChangeLogCommand(
/**
* {@inheritDoc}
*/
public ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException {
public ChangeLogScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
Date startDate = parameters.getDate(CommandParameter.START_DATE, null);

Date endDate = parameters.getDate(CommandParameter.END_DATE, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.ScmVersion;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;
Expand All @@ -33,15 +32,15 @@
* @author Olivier Lamy
*
*/
public abstract class AbstractCheckInCommand extends AbstractCommand {
public abstract class AbstractCheckInCommand extends AbstractCommand<CheckInScmResult> {
public static final String NAME = "check-in";

protected abstract CheckInScmResult executeCheckInCommand(
ScmProviderRepository repository, ScmFileSet fileSet, String message, ScmVersion scmVersion)
throws ScmException;

public ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException {
public CheckInScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
String message = parameters.getString(CommandParameter.MESSAGE);

ScmVersion scmVersion = parameters.getScmVersion(CommandParameter.SCM_VERSION, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.ScmVersion;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;
Expand All @@ -33,7 +32,7 @@
* @author Olivier Lamy
*
*/
public abstract class AbstractCheckOutCommand extends AbstractCommand {
public abstract class AbstractCheckOutCommand extends AbstractCommand<CheckOutScmResult> {
/**
* Execute Check out command line in a recursive check out way.
*
Expand Down Expand Up @@ -70,8 +69,8 @@ protected abstract CheckOutScmResult executeCheckOutCommand(
throws ScmException;

/** {@inheritDoc} */
public ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException {
public CheckOutScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
ScmVersion scmVersion = parameters.getScmVersion(CommandParameter.SCM_VERSION, null);
boolean recursive = parameters.getBoolean(CommandParameter.RECURSIVE, true);
boolean shallow = parameters.getBoolean(CommandParameter.SHALLOW, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.ScmVersion;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;
Expand All @@ -37,14 +36,14 @@
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*
*/
public abstract class AbstractDiffCommand extends AbstractCommand {
public abstract class AbstractDiffCommand extends AbstractCommand<DiffScmResult> {
protected abstract DiffScmResult executeDiffCommand(
ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision)
throws ScmException;

/** {@inheritDoc} */
public ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException {
public DiffScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
ScmVersion startRevision = parameters.getScmVersion(CommandParameter.START_SCM_VERSION, null);

ScmVersion endRevision = parameters.getScmVersion(CommandParameter.END_SCM_VERSION, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;

/**
*
*/
public abstract class AbstractEditCommand extends AbstractCommand {
public abstract class AbstractEditCommand extends AbstractCommand<EditScmResult> {
/** {@inheritDoc} */
public ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException {
public EditScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
return executeEditCommand(repository, fileSet);
}

protected abstract ScmResult executeEditCommand(ScmProviderRepository repository, ScmFileSet fileSet)
protected abstract EditScmResult executeEditCommand(ScmProviderRepository repository, ScmFileSet fileSet)
throws ScmException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.ScmVersion;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;
Expand All @@ -31,13 +30,13 @@
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
*
*/
public abstract class AbstractExportCommand extends AbstractCommand {
public abstract class AbstractExportCommand extends AbstractCommand<ExportScmResult> {
protected abstract ExportScmResult executeExportCommand(
ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, String outputDirectory)
throws ScmException;

/** {@inheritDoc} */
protected ScmResult executeCommand(
protected ExportScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
ScmVersion scmVersion = parameters.getScmVersion(CommandParameter.SCM_VERSION, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
*
* // TODO: remove this class as it doesn't have any implementation
*/
public abstract class AbstractFileInfoCommand extends AbstractCommand {
public abstract class AbstractFileInfoCommand extends AbstractCommand<ScmResult> {
protected abstract ScmResult executeFileInfoCommand(
ScmProviderRepository repository, File workingDirectory, String filename) throws ScmException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/**
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
* @author Olivier Lamy
* TODO: which command uses this class?
*
*/
public class InfoScmResult extends ScmResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.ScmVersion;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;
Expand All @@ -31,7 +30,7 @@
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
*
*/
public abstract class AbstractListCommand extends AbstractCommand {
public abstract class AbstractListCommand extends AbstractCommand<ListScmResult> {
/**
* List contents of the remote repository
*
Expand All @@ -47,8 +46,8 @@ protected abstract ListScmResult executeListCommand(
throws ScmException;

/** {@inheritDoc} */
public ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
throws ScmException {
public ListScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
if (fileSet.getFileList().isEmpty()) {
throw new IllegalArgumentException("fileSet can not be empty");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;

/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
*
*/
public abstract class AbstractLoginCommand extends AbstractCommand {
public abstract class AbstractLoginCommand extends AbstractCommand<LoginScmResult> {
public abstract LoginScmResult executeLoginCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException;

/** {@inheritDoc} */
protected ScmResult executeCommand(
protected LoginScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
return executeLoginCommand(repository, fileSet, parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;

/**
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
*
*/
public abstract class AbstractMkdirCommand extends AbstractCommand {
public abstract class AbstractMkdirCommand extends AbstractCommand<MkdirScmResult> {
/**
* Creates directories in the remote repository.
*
Expand All @@ -46,7 +45,7 @@ protected abstract MkdirScmResult executeMkdirCommand(
throws ScmException;

/** {@inheritDoc} */
protected ScmResult executeCommand(
protected MkdirScmResult executeCommand(
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
if (fileSet.getFileList().isEmpty()) {
throw new IllegalArgumentException("fileSet can not be empty");
Expand Down
Loading
Loading