use of org.apache.maven.scm.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader 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.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader in project maven-scm by apache.
the class LocalScmMetadataUtils method readMetadata.
/**
* Reads metadata file from given directory.
*
* @param dir The directory that should contain the metadata file
* @return LocalScmMetadata or <tt>null</tt> in case of problems
*/
public LocalScmMetadata readMetadata(File dir) {
File metadataFile = new File(dir, FILENAME);
if (!metadataFile.exists()) {
return null;
}
LocalScmMetadata result = null;
Reader reader = null;
try {
reader = ReaderFactory.newXmlReader(metadataFile);
result = new LocalScmMetadataXpp3Reader().read(reader);
} catch (XmlPullParserException e) {
if (logger.isWarnEnabled()) {
logger.warn("Could not interpret .maven-scm-local - ignoring", e);
}
return null;
} catch (IOException e) {
if (logger.isWarnEnabled()) {
logger.warn("Could not Read .maven-scm-local - ignoring", e);
}
} finally {
IOUtil.close(reader);
}
return result;
}
use of org.apache.maven.scm.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader in project maven-scm by apache.
the class LocalCheckOutCommandTckTest method testMetadata.
/**
* Tests that the metadata file .maven-scm-local is written correctly
*/
public void testMetadata() throws Exception {
FileUtils.deleteDirectory(getWorkingCopy());
CheckOutScmResult result = checkOut(getWorkingCopy(), getScmRepository());
assertResultIsSuccess(result);
List<ScmFile> checkedOutFiles = result.getCheckedOutFiles();
assertEquals(4, checkedOutFiles.size());
// ----------------------------------------------------------------------
// Assert metadata file
// ----------------------------------------------------------------------
File metadataFile = new File(getWorkingCopy(), ".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() + "/" + module);
@SuppressWarnings("unchecked") List<String> fileNames = FileUtils.getFileNames(root, "**", null, false);
assertEquals(fileNames, metadata.getRepositoryFileNames());
}
Aggregations