use of org.apache.maven.scm.manager.ScmManager in project maven-scm by apache.
the class LocalUpdateCommandTckTest method testDeletion.
/**
* Tests that a file that has been deleted from repository after checkout will be removed by scm-local. Local
* additions must not be deleted.
*/
public void testDeletion() throws Exception {
FileUtils.deleteDirectory(getUpdatingCopy());
ScmRepository repository = makeScmRepository(getScmUrl());
checkOut(getUpdatingCopy(), repository);
// Check preconditions
File readmeFileLocal = new File(getUpdatingCopy(), "readme.txt");
assertTrue(readmeFileLocal.exists());
File newFileLocal = new File(getUpdatingCopy(), "newfile.xml");
assertTrue(!newFileLocal.exists());
// Delete readme.txt from repository
File readmeFileRepo = new File(getRepositoryRoot(), moduleName + "/readme.txt");
assertTrue(readmeFileRepo.exists());
assertTrue("Could not delete", readmeFileRepo.delete());
assertFalse(readmeFileRepo.exists());
// Make local addition to updating copy - this one must not be touched
ScmTestCase.makeFile(getUpdatingCopy(), "newfile.xml", "added newfile.xml locally");
assertTrue(newFileLocal.exists());
// ----------------------------------------------------------------------
// Update the project
// ----------------------------------------------------------------------
ScmManager scmManager = getScmManager();
Date lastUpdate = new Date(System.currentTimeMillis());
Thread.sleep(1000);
UpdateScmResult result = scmManager.update(repository, new ScmFileSet(getUpdatingCopy()), lastUpdate);
assertNotNull("The command returned a null result.", result);
assertResultIsSuccess(result);
List<ScmFile> updatedFiles = result.getUpdatedFiles();
assertEquals("Expected 1 files in the updated files list " + updatedFiles, 1, updatedFiles.size());
// ----------------------------------------------------------------------
// Assert the files in the updated files list
// ----------------------------------------------------------------------
Iterator<ScmFile> files = new TreeSet<ScmFile>(updatedFiles).iterator();
// readme.txt
ScmFile file = (ScmFile) files.next();
assertPath("/readme.txt", file.getPath());
assertTrue(file.getStatus().isUpdate());
// ----------------------------------------------------------------------
// Assert working directory contents
// ----------------------------------------------------------------------
// readme.txt
assertTrue("Expected local copy of readme.txt to be deleted", !readmeFileLocal.exists());
// newfile.xml
assertTrue("Expected local copy of newfile.xml NOT to be deleted", newFileLocal.exists());
// ----------------------------------------------------------------------
// Assert metadata file
// ----------------------------------------------------------------------
File metadataFile = new File(getUpdatingCopy(), ".maven-scm-local");
assertTrue("Expected metadata file .maven-scm-local does not exist", metadataFile.exists());
Reader reader = new FileReader(metadataFile);
LocalScmMetadata metadata;
try {
metadata = new LocalScmMetadataXpp3Reader().read(reader);
} finally {
IOUtil.close(reader);
}
File root = new File(getRepositoryRoot() + "/" + moduleName);
@SuppressWarnings("unchecked") List<String> fileNames = FileUtils.getFileNames(root, "**", null, false);
assertEquals(fileNames, metadata.getRepositoryFileNames());
}
use of org.apache.maven.scm.manager.ScmManager in project maven-scm by apache.
the class CvsCheckoutCommandTest method testCheckOutWithTag.
/**
* @todo move this test to the TCK - checkout with "revision", then have one for tag as well.
*/
public void testCheckOutWithTag() throws Exception {
if (!isSystemCmd(CvsScmTestUtils.CVS_COMMAND_LINE)) {
System.err.println("'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored " + getName() + ".");
return;
}
ScmManager scmManager = getScmManager();
@SuppressWarnings("deprecation") CheckOutScmResult result = scmManager.getProviderByRepository(getScmRepository()).checkOut(getScmRepository(), getScmFileSet(), "MAVEN_1_0");
if (!result.isSuccess()) {
fail(result.getProviderMessage() + "\n" + result.getCommandOutput());
}
List<ScmFile> files = result.getCheckedOutFiles();
assertNotNull(files);
assertEquals(1, files.size());
File mavenUtils = assertCheckedOutFile(files, 0, "/src/java/org/apache/maven/MavenUtils.java", ScmFileStatus.UPDATED);
assertBetween(38403, 39511, mavenUtils.length());
}
use of org.apache.maven.scm.manager.ScmManager in project maven-scm by apache.
the class CvsChangeLogCommandTest method testChangeLog.
@SuppressWarnings("deprecation")
private void testChangeLog(Date startDate, Date endDate, int changeLogSize, String branch) throws Exception {
if (!isSystemCmd(CvsScmTestUtils.CVS_COMMAND_LINE)) {
System.err.println("'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored " + getName() + ".");
return;
}
ScmManager scmManager = getScmManager();
CvsScmTestUtils.executeCVS(getWorkingDirectory(), "-f -d " + getTestFile("src/test/repository/") + " co " + getModule());
ChangeLogScmResult changeLogResult = scmManager.getProviderByRepository(getScmRepository()).changeLog(getScmRepository(), getScmFileSet(), startDate, endDate, 0, branch);
if (!changeLogResult.isSuccess()) {
fail(changeLogResult.getProviderMessage() + "\n" + changeLogResult.getCommandOutput());
}
ChangeLogSet changeLogSet = changeLogResult.getChangeLog();
assertNotNull(changeLogSet);
assertEquals(changeLogSize, changeLogSet.getChangeSets().size());
}
use of org.apache.maven.scm.manager.ScmManager in project maven-scm by apache.
the class UpdateCommandTckTest method testUpdateCommand.
public void testUpdateCommand() throws Exception {
deleteDirectory(getUpdatingCopy());
assertFalse(getUpdatingCopy().exists());
// deleteDirectory( getWorkingCopy() );
// assertFalse( getUpdatingCopy().exists() );
ScmRepository repository = makeScmRepository(getScmUrl());
checkOut(getUpdatingCopy(), repository);
// ----------------------------------------------------------------------
// Change the files
// ----------------------------------------------------------------------
/*
* readme.txt is changed (changed file in the root directory)
* project.xml is added (added file in the root directory)
* src/test/resources is untouched (a empty directory is left untouched)
* src/test/java is untouched (a non empty directory is left untouched)
* src/test/java/org (a empty directory is added)
* src/main/java/org/Foo.java (a non empty directory is added)
*/
// /readme.txt
this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
// /project.xml
ScmTestCase.makeFile(getWorkingCopy(), "/project.xml", "changed project.xml");
addToWorkingTree(getWorkingCopy(), new File("project.xml"), getScmRepository());
// /src/test/java/org
ScmTestCase.makeDirectory(getWorkingCopy(), "/src/test/java/org");
addToWorkingTree(getWorkingCopy(), new File("src/test/java/org"), getScmRepository());
// /src/main/java/org/Foo.java
ScmTestCase.makeFile(getWorkingCopy(), "/src/main/java/org/Foo.java");
addToWorkingTree(getWorkingCopy(), new File("src/main/java/org"), getScmRepository());
// src/main/java/org/Foo.java
addToWorkingTree(getWorkingCopy(), new File("src/main/java/org/Foo.java"), getScmRepository());
ScmManager scmManager = getScmManager();
Date lastUpdate = new Date(System.currentTimeMillis() - 1000000);
commit(getWorkingCopy(), getScmRepository());
Thread.sleep(5000);
// ----------------------------------------------------------------------
// Update the project
// ----------------------------------------------------------------------
UpdateScmResult result = scmManager.update(repository, new ScmFileSet(getUpdatingCopy()), lastUpdate);
assertNotNull("The command returned a null result.", result);
assertResultIsSuccess(result);
List<ScmFile> updatedFiles = result.getUpdatedFiles();
List<ChangeSet> changedSets = result.getChanges();
assertEquals("Expected 3 files in the updated files list " + updatedFiles, 3, updatedFiles.size());
assertNotNull("The changed files list is null", changedSets);
assertFalse("The changed files list is empty ", changedSets.isEmpty());
for (ChangeSet changeSet : changedSets) {
System.out.println(changeSet.toXML());
}
// ----------------------------------------------------------------------
// Assert the files in the updated files list
// ----------------------------------------------------------------------
Iterator<ScmFile> files = new TreeSet<ScmFile>(updatedFiles).iterator();
// Foo.java
ScmFile file = files.next();
assertPath("/src/main/java/org/Foo.java", file.getPath());
// TODO : Consolidate file status so that we can remove "|| ADDED" term
assertTrue(file.getStatus().isUpdate() || file.getStatus() == ScmFileStatus.ADDED);
// readme.txt
file = files.next();
assertPath("/readme.txt", file.getPath());
assertTrue(file.getStatus().isUpdate());
// project.xml
file = files.next();
assertPath("/project.xml", file.getPath());
// TODO : Consolidate file status so that we can remove "|| ADDED" term
assertTrue(file.getStatus().isUpdate() || file.getStatus() == ScmFileStatus.ADDED);
}
use of org.apache.maven.scm.manager.ScmManager in project maven-scm by apache.
the class StatusCommandTckTest method testStatusCommand.
public void testStatusCommand() throws Exception {
ScmRepository repository = makeScmRepository(getScmUrl());
checkOut(getUpdatingCopy(), repository);
// ----------------------------------------------------------------------
// Change the files
// ----------------------------------------------------------------------
/*
* readme.txt is changed (changed file in the root directory)
* project.xml is added (added file in the root directory)
*/
// /readme.txt
this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
// /project.xml
ScmTestCase.makeFile(getWorkingCopy(), "/project.xml", "changed project.xml");
addToWorkingTree(getWorkingCopy(), new File("project.xml"), getScmRepository());
commit(getWorkingCopy(), getScmRepository());
// /pom.xml
this.edit(getUpdatingCopy(), "pom.xml", null, repository);
ScmTestCase.makeFile(getUpdatingCopy(), "/pom.xml", "changed pom.xml");
// /src/test/java/org
ScmTestCase.makeDirectory(getUpdatingCopy(), "/src/test/java/org");
addToWorkingTree(getUpdatingCopy(), new File("src/test/java/org"), repository);
// /src/main/java/org/Foo.java
ScmTestCase.makeFile(getUpdatingCopy(), "/src/main/java/org/Foo.java");
addToWorkingTree(getUpdatingCopy(), new File("src/main/java/org"), repository);
// src/main/java/org/Foo.java
addToWorkingTree(getUpdatingCopy(), new File("src/main/java/org/Foo.java"), repository);
ScmManager scmManager = getScmManager();
// ----------------------------------------------------------------------
// Check status the project
// src/main/java/org/Foo.java is added
// /pom.xml is modified
// check that readme and project.xml are not updated/created
// ----------------------------------------------------------------------
StatusScmResult result = scmManager.getProviderByUrl(getScmUrl()).status(repository, new ScmFileSet(getUpdatingCopy()));
if (this.commitUpdateCopy()) {
// this is needed for perforce so that teardown can remove its client workspace, no harm for cvs/svn/git
commit(getUpdatingCopy(), repository);
}
assertNotNull("The command returned a null result.", result);
assertResultIsSuccess(result);
List<ScmFile> changedFiles = result.getChangedFiles();
assertEquals("Expected 2 files in the updated files list " + changedFiles, 2, changedFiles.size());
// ----------------------------------------------------------------------
// Assert the files in the updated files list
// ----------------------------------------------------------------------
Iterator<ScmFile> files = new TreeSet<ScmFile>(changedFiles).iterator();
ScmFile file = files.next();
assertPath("/src/main/java/org/Foo.java", file.getPath());
assertEquals(ScmFileStatus.ADDED, file.getStatus());
file = files.next();
assertPath("/pom.xml", file.getPath());
assertEquals(ScmFileStatus.MODIFIED, file.getStatus());
assertFile(getUpdatingCopy(), "/readme.txt");
assertFalse("project.xml created incorrectly", new File(getUpdatingCopy(), "/project.xml").exists());
}
Aggregations