/*******************************************************************************
* Copyright (c) 2013, Perforce Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
package com.perforce.p4java.extension.operation;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import com.perforce.p4java.extension.command.PerforceDomain;
import com.perforce.p4java.extension.command.RequestImpl;
import com.perforce.p4java.extension.exception.ServerAccessException;
import com.perforce.p4java.extension.exception.ServerConnectionException;
import com.perforce.p4java.extension.exception.ServerErrorException;
import com.perforce.p4java.extension.path.PathStringFormat;
import com.perforce.p4java.extension.path.PerforcePath;
import com.perforce.p4java.extension.server.Server;
public class FilesCommand {
public static String tagErrorCode = "code0";
public static String tagDepotFile = "depotFile";
public static String tagType = "type";
public static String tagAppleType = "apple";
public static String tagRevision = "rev";
public static String tagAction = "action";
public static String tagChange = "change";
/*
* given a list of files by path, fetch the perforce data for each file
*/
public static Map<String, Object>[] listFilesToMap(
final List<String> escapedPaths, final Server server)
throws ServerConnectionException, ServerAccessException,
ServerErrorException {
return server.execute(new RequestImpl() {
@Override
public String getCommand() {
return PerforceDomain.FILES.getCommand();
}
@Override
public String[] getCommandArgs() {
return escapedPaths.toArray(new String[0]);
}
});
}
public static Map<String, Object>[] getAllRevisions(final String path,
final Server server) throws ServerConnectionException,
ServerAccessException, ServerErrorException {
return server.execute(new RequestImpl() {
@Override
public String getCommand() {
return PerforceDomain.FILES.getCommand();
}
@Override
public String[] getCommandArgs() {
return new String[] { "-a", path };
}
});
}
public static Map<String, Object>[] getFileByPath(final PerforcePath dp,
final Server server) throws ServerConnectionException,
ServerAccessException, ServerErrorException {
return server.execute(new RequestImpl() {
public String getCommand() {
return PerforceDomain.FILES.getCommand();
}
public String[] getCommandArgs() {
String path = dp.asString(EnumSet.of(PathStringFormat.ESCAPE));
path = path + "*"; // DO NOT ENQUOTE
// THIS!!!
String[] args = { path };
return args;
}
});
}
}