Search in sources :

Example 11 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class LocalListCommand method executeListCommand.

/**
 * {@inheritDoc}
 */
protected ListScmResult executeListCommand(ScmProviderRepository repo, ScmFileSet fileSet, boolean recursive, ScmVersion version) throws ScmException {
    if (version != null) {
        throw new ScmException("The local scm doesn't support tags.");
    }
    LocalScmProviderRepository repository = (LocalScmProviderRepository) repo;
    File root = new File(repository.getRoot());
    String module = repository.getModule();
    File source = new File(root, module);
    if (!root.exists()) {
        throw new ScmException("The base directory doesn't exist (" + root.getAbsolutePath() + ").");
    }
    if (!source.exists()) {
        throw new ScmException("The module directory doesn't exist (" + source.getAbsolutePath() + ").");
    }
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Listing files of '" + source.getAbsolutePath() + "'.");
    }
    try {
        if (fileSet.getFileList() == null || fileSet.getFileList().isEmpty()) {
            return new LocalListScmResult(null, getFiles(source, source, recursive));
        } else {
            List<ScmFile> files = new ArrayList<ScmFile>();
            Iterator<File> it = fileSet.getFileList().iterator();
            while (it.hasNext()) {
                File file = (File) it.next();
                files.addAll(getFiles(source, new File(source, file.getPath()), recursive));
            }
            return new LocalListScmResult(null, files);
        }
    } catch (Exception e) {
        return new ListScmResult(null, "The svn command failed.", e.getMessage(), false);
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) LocalScmProviderRepository(org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository) ArrayList(java.util.ArrayList) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmException(org.apache.maven.scm.ScmException) ScmFile(org.apache.maven.scm.ScmFile)

Example 12 with ScmFile

use of org.apache.maven.scm.ScmFile 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());
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) LocalScmMetadata(org.apache.maven.scm.provider.local.metadata.LocalScmMetadata) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) Reader(java.io.Reader) FileReader(java.io.FileReader) LocalScmMetadataXpp3Reader(org.apache.maven.scm.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader) Date(java.util.Date) ScmFile(org.apache.maven.scm.ScmFile) LocalScmMetadataXpp3Reader(org.apache.maven.scm.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader) ScmManager(org.apache.maven.scm.manager.ScmManager) FileReader(java.io.FileReader) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 13 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class PerforceCheckOutConsumer method consumeLine.

/*
     * Client mperham-mikeperham-dt-maven saved.
     */
/*
     * //depot/modules/cordoba/runtime-ear/.j2ee#1 - deleted as
     * d:\perforce\depot\modules\cordoba\runtime-ear\.j2ee
     * //depot/modules/cordoba/runtime-ear/.project#1 - deleted as
     * d:\perforce\depot\modules\cordoba\runtime-ear\.project
     * //depot/modules/cordoba/runtime-ear/.runtime#1 - deleted as
     * d:\perforce\depot\modules\cordoba\runtime-ear\.runtime
     * //depot/modules/cordoba/runtime-ear/Foo.java#1 - deleted as
     * d:\perforce\depot\modules\cordoba\runtime-ear\Foo.java
     * //depot/modules/cordoba/runtime-ear/META-INF/.modulemaps#1 - deleted as
     * d:\perforce\depot\modules\cordoba\runtime-ear\META-INF\.modulemaps
     * //depot/modules/cordoba/runtime-ear/META-INF/application.xml#1 - deleted
     * as d:\perforce\depot\modules\cordoba\runtime-ear\META-INF\application.xml
     * //depot/modules/cordoba/runtime-ear/pom.xml#4 - deleted as
     * d:\perforce\depot\modules\cordoba\runtime-ear\pom.xml
     */
/*
     * Invalid changelist/client/label/date '@somelabel'.
     */
/**
 * {@inheritDoc}
 */
public void consumeLine(String line) {
    if (currentState == STATE_CLIENTSPEC && (line.startsWith("Client " + specname + " saved.") || line.startsWith("Client " + specname + " not changed."))) {
        currentState = STATE_NORMAL;
        return;
    }
    // Handle case where the clientspec is current
    if (currentState == STATE_NORMAL && line.indexOf("ile(s) up-to-date") != -1) {
        return;
    }
    Matcher matcher;
    if (currentState != STATE_ERROR && (matcher = fileRegexp.matcher(line)).find()) {
        String location = matcher.group(1);
        if (location.startsWith(repo)) {
            location = location.substring(repo.length() + 1);
        }
        ScmFileStatus status = PerforceVerbMapper.toStatus(matcher.group(2));
        if (status != null) {
            // there are cases where Perforce prints out something but the file did not
            // actually change (especially when force syncing).  Those files will have
            // a null status.
            checkedout.add(new ScmFile(location, status));
        }
        return;
    }
    error(line);
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) Matcher(java.util.regex.Matcher) ScmFile(org.apache.maven.scm.ScmFile)

Example 14 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class PerforceRemoveConsumer method consumeLine.

/**
 * {@inheritDoc}
 */
public void consumeLine(String line) {
    if (line.startsWith("... ")) {
        return;
    }
    if (!line.startsWith(FILE_BEGIN_TOKEN)) {
        error(line);
    }
    Matcher matcher = REVISION_PATTERN.matcher(line);
    if (!matcher.matches()) {
        error(line);
    }
    removals.add(new ScmFile(matcher.group(1), ScmFileStatus.DELETED));
}
Also used : Matcher(java.util.regex.Matcher) ScmFile(org.apache.maven.scm.ScmFile)

Example 15 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class PerforceCheckOutConsumerTest method testGoodParse.

public void testGoodParse() throws Exception {
    File testFile = getTestFile("src/test/resources/perforce/checkout_good.txt");
    PerforceCheckOutConsumer consumer = new PerforceCheckOutConsumer("test-test-maven", "//depot/modules");
    consumer.consumeLine("Client test-test-maven saved.");
    assertEquals("", consumer.getOutput());
    assertTrue(consumer.isSuccess());
    FileInputStream fis = new FileInputStream(testFile);
    BufferedReader in = new BufferedReader(new InputStreamReader(fis));
    String s = in.readLine();
    while (s != null) {
        consumer.consumeLine(s);
        s = in.readLine();
    }
    assertTrue(consumer.getOutput(), consumer.isSuccess());
    assertEquals("", consumer.getOutput());
    assertEquals(4, consumer.getCheckedout().size());
    ScmFile file = (ScmFile) consumer.getCheckedout().get(0);
    assertEquals("cordoba/runtime-ear/.j2ee", file.getPath());
    assertEquals(ScmFileStatus.DELETED, file.getStatus());
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) FileInputStream(java.io.FileInputStream) ScmFile(org.apache.maven.scm.ScmFile)

Aggregations

ScmFile (org.apache.maven.scm.ScmFile)198 File (java.io.File)102 ArrayList (java.util.ArrayList)51 ScmException (org.apache.maven.scm.ScmException)34 BufferedReader (java.io.BufferedReader)21 DefaultLog (org.apache.maven.scm.log.DefaultLog)20 ScmFileStatus (org.apache.maven.scm.ScmFileStatus)19 ScmFileSet (org.apache.maven.scm.ScmFileSet)17 InputStreamReader (java.io.InputStreamReader)16 ScmResult (org.apache.maven.scm.ScmResult)15 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)15 IOException (java.io.IOException)14 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)13 Matcher (java.util.regex.Matcher)11 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)11 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)10 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)10 Commandline (org.codehaus.plexus.util.cli.Commandline)10 SynergyScmProviderRepository (org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository)9 FileInputStream (java.io.FileInputStream)8