use of org.apache.maven.scm.command.mkdir.MkdirScmResult in project maven-scm by apache.
the class SvnMkdirCommand method executeMkdirCommand.
/**
* {@inheritDoc}
*/
protected MkdirScmResult executeMkdirCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal) throws ScmException {
File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
try {
FileUtils.fileWrite(messageFile.getAbsolutePath(), message);
} catch (IOException ex) {
return new MkdirScmResult(null, "Error while making a temporary file for the mkdir message: " + ex.getMessage(), null, false);
}
Commandline cl = createCommandLine((SvnScmProviderRepository) repository, fileSet, messageFile, createInLocal);
SvnMkdirConsumer consumer = new SvnMkdirConsumer(getLogger());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
if (getLogger().isInfoEnabled()) {
getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
}
}
int exitCode;
try {
exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
} finally {
try {
FileUtils.forceDelete(messageFile);
} catch (IOException ex) {
// ignore
}
}
if (exitCode != 0) {
return new MkdirScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
if (createInLocal) {
return new MkdirScmResult(cl.toString(), consumer.getCreatedDirs());
} else {
return new MkdirScmResult(cl.toString(), Integer.toString(consumer.getRevision()));
}
}
use of org.apache.maven.scm.command.mkdir.MkdirScmResult in project maven-scm by apache.
the class LocalMkdirCommandTckTest method testMkdirCommandMkdirUrl.
public void testMkdirCommandMkdirUrl() throws Exception {
ScmFileSet fileSet = new ScmFileSet(getWorkingCopy(), new File(getMissingDirectory()));
MkdirScmResult result = getScmManager().mkdir(getScmRepository(), fileSet, "Mkdir message", false);
assertResultIsSuccess(result);
ListScmResult listResult = getScmManager().list(getScmRepository(), fileSet, true, null);
assertTrue("Directory should have been found.", listResult.isSuccess());
}
use of org.apache.maven.scm.command.mkdir.MkdirScmResult in project maven-scm by apache.
the class LocalMkdirCommandTckTest method testMkdirCommandDirAlreadyAdded.
public void testMkdirCommandDirAlreadyAdded() throws Exception {
ScmFileSet fileSet = new ScmFileSet(getWorkingCopy(), new File(getMissingDirectory()));
MkdirScmResult result = getScmManager().mkdir(getScmRepository(), fileSet, "Mkdir message", false);
assertResultIsSuccess(result);
ListScmResult listResult = getScmManager().list(getScmRepository(), fileSet, true, null);
assertTrue("Directory should have been found.", listResult.isSuccess());
// add the directory again
result = getScmManager().mkdir(getScmRepository(), fileSet, "Mkdir message", false);
assertFalse(result.isSuccess());
printOutputError(result);
}
use of org.apache.maven.scm.command.mkdir.MkdirScmResult in project maven-scm by apache.
the class LocalScmProvider method mkdir.
/**
* {@inheritDoc}
*/
protected MkdirScmResult mkdir(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
LocalMkdirCommand command = new LocalMkdirCommand();
command.setLogger(getLogger());
return (MkdirScmResult) command.execute(repository, fileSet, parameters);
}
use of org.apache.maven.scm.command.mkdir.MkdirScmResult in project maven-scm by apache.
the class IntegrityMkdirCommand method executeMkdirCommand.
/**
* Creates a subproject in the Integrity repository.
* <br>However, since the subproject automatically creates a folder in
* the local sandbox, the createInLocal argument will be ignored
*/
@Override
public MkdirScmResult executeMkdirCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal) throws ScmException {
String dirPath = "";
Iterator<File> fit = fileSet.getFileList().iterator();
if (fit.hasNext()) {
dirPath = fit.next().getPath().replace('\\', '/');
}
if (null == dirPath || dirPath.length() == 0) {
throw new ScmException("A relative directory path is required to execute this command!");
}
getLogger().info("Creating subprojects one per directory, as required for " + dirPath);
MkdirScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
try {
Response res = iRepo.getSandbox().createSubproject(dirPath);
String subProject = res.getWorkItems().next().getResult().getField("resultant").getItem().getDisplayId();
List<ScmFile> createdDirs = new ArrayList<ScmFile>();
createdDirs.add(new ScmFile(subProject, ScmFileStatus.ADDED));
int exitCode = res.getExitCode();
boolean success = (exitCode == 0 ? true : false);
getLogger().info("Successfully created subproject " + subProject);
result = new MkdirScmResult(createdDirs, new ScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success));
} catch (APIException aex) {
ExceptionHandler eh = new ExceptionHandler(aex);
getLogger().error("MKS API Exception: " + eh.getMessage());
getLogger().info(eh.getCommand() + " exited with return code " + eh.getExitCode());
result = new MkdirScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
}
return result;
}
Aggregations