CPD Results

The following document contains the results of PMD's CPD 5.3.5.

Duplications

File Line
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInConsumer.java 104
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutConsumer.java 103
org/apache/maven/scm/provider/vss/commands/tag/VssTagConsumer.java 103
    public VssCheckInConsumer( VssScmProviderRepository repo, ScmLogger logger )
    {
        super( logger );
        this.repo = repo;
    }

    /** {@inheritDoc} */
    public void consumeLine( String line )
    {
        if ( getLogger().isDebugEnabled() )
        {
            getLogger().debug( line );
        }

        switch ( getLineStatus( line ) )
        {
            case GET_FILE_PATH:
                processGetFilePath( line );
                break;
            case GET_FILE:
                processGetFile( line );
                break;
            case REPLACE_FILE:
                processReplaceFile( line );
                break;
            case IS_WRITABLE_COPY:
                // will be overwritten and uses REPLACE_FILE
                break;
            case SET_WORKING_FOLDER:
                // to trash
                break;
            default:
                break;
        }
    }

    /**
     * Process the current input line in the Get File state.
     * 
     * @param line a line of text from the VSS log output
     */
    private void processGetFile( String line )
    {
        String[] fileLine = line.split( " " );
        updatedFiles.add( new ScmFile( currentPath + "/" + fileLine[1], ScmFileStatus.UPDATED ) );
        if ( getLogger().isInfoEnabled() )
        {
            getLogger().info( fileLine[0] + ": " + currentPath + "/" + fileLine[1] );
        }
    }

    /**
     * Process the current input line in the Replace File state.
     * 
     * @param line a line of text from the VSS log output
     */
    private void processReplaceFile( String line )
    {
        updatedFiles.add( new ScmFile( currentPath + "/" + line.substring( START_REPLACING.length() ),
                                       ScmFileStatus.UPDATED ) );
        if ( getLogger().isInfoEnabled() )
        {
            getLogger().info( START_REPLACING + currentPath + "/" + line.substring( START_REPLACING.length() ) );
        }
    }

    /**
     * Process the current input line in the Get File Path state.
     * 
     * @param line a line of text from the VSS log output
     */
    private void processGetFilePath( String line )
    {
        currentPath = line.substring( ( VssConstants.PROJECT_PREFIX + repo.getProject() ).length(), line.length() - 1 );
    }

    /**
     * Identify the status of a vss get line
     * 
     * @param line The line to process
     * @return status
     */
    private int getLineStatus( String line )
    {
        int argument = GET_UNKNOWN;
        if ( line.startsWith( START_FILE_PATH ) )
        {
            argument = GET_FILE_PATH;
        }
        else if ( line.startsWith( START_GETTING ) )
        {
            argument = GET_FILE;
        }
        else if ( line.startsWith( START_REPLACING ) )
        {
            argument = REPLACE_FILE;
        }
        else if ( line.startsWith( START_WRITABLE_COPY ) )
        {
            argument = IS_WRITABLE_COPY;
        }
        else if ( line.indexOf( CONTAINS_SET_DEFAULT_WORKING_FOLDER ) != -1 )
        {
            argument = SET_WORKING_FOLDER;
        }

        return argument;
    }

    public List<ScmFile> getUpdatedFiles()
    {
        return updatedFiles;
    }

}
File Line
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInCommand.java 152
org/apache/maven/scm/provider/vss/commands/edit/VssEditCommand.java 150
                command.createArg().setValue( VssConstants.COMMAND_CHECKIN );

                String absolute;
                try
                {
                    absolute = file.getCanonicalPath();
                    String relative;
                    int index = absolute.indexOf( base );
                    if ( index >= 0 )
                    {
                        relative = absolute.substring( index + base.length() );
                    }
                    else
                    {
                        relative = file.getPath();
                    }

                    relative = relative.replace( '\\', '/' );

                    if ( !relative.startsWith( "/" ) )
                    {
                        relative = '/' + relative;
                    }

                    String relativeFolder = relative.substring( 0, relative.lastIndexOf( '/' ) );

                    command.setWorkingDirectory( new File( fileSet.getBasedir().getAbsolutePath() + File.separatorChar
                        + relativeFolder ).getCanonicalPath() );

                    command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() + relative );
                }
                catch ( IOException e )
                {
                    throw new ScmException( "Invalid canonical path", e );
                }

                //User identification to get access to vss repository
                if ( repo.getUserPassword() != null )
                {
                    command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
                }

                // Ignore: Do not ask for input under any circumstances.
                command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
File Line
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutCommand.java 89
org/apache/maven/scm/provider/vss/commands/update/VssUpdateCommand.java 93
        return new CheckOutScmResult( cl.toString(), consumer.getUpdatedFiles() );
    }

    public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
        throws ScmException
    {

        Commandline command = new Commandline();

        command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );

        try
        {
            command.addSystemEnvironment();
        }
        catch ( Exception e )
        {
            throw new ScmException( "Can't add system environment.", e );
        }

        command.addEnvironment( "SSDIR", repo.getVssdir() );

        String ssDir = VssCommandLineUtils.getSsDir();

        command.setExecutable( ssDir + VssConstants.SS_EXE );

        command.createArg().setValue( VssConstants.COMMAND_GET );

        command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );

        //User identification to get access to vss repository
        if ( repo.getUserPassword() != null )
        {
            command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
        }

        //Display the history of an entire project list
        command.createArg().setValue( VssConstants.FLAG_RECURSION );

        //Ignore: Do not ask for input under any circumstances.
        command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );

        //Ignore: Do not touch local writable files.
        command.createArg().setValue( VssConstants.FLAG_REPLACE_WRITABLE );
File Line
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInConsumer.java 131
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutConsumer.java 130
org/apache/maven/scm/provider/vss/commands/tag/VssTagConsumer.java 130
org/apache/maven/scm/provider/vss/commands/update/VssUpdateConsumer.java 131
                break;
            case SET_WORKING_FOLDER:
                // to trash
                break;
            default:
                break;
        }
    }

    /**
     * Process the current input line in the Get File state.
     * 
     * @param line a line of text from the VSS log output
     */
    private void processGetFile( String line )
    {
        String[] fileLine = line.split( " " );
        updatedFiles.add( new ScmFile( currentPath + "/" + fileLine[1], ScmFileStatus.UPDATED ) );
        if ( getLogger().isInfoEnabled() )
        {
            getLogger().info( fileLine[0] + ": " + currentPath + "/" + fileLine[1] );
        }
    }

    /**
     * Process the current input line in the Replace File state.
     * 
     * @param line a line of text from the VSS log output
     */
    private void processReplaceFile( String line )
    {
        updatedFiles.add( new ScmFile( currentPath + "/" + line.substring( START_REPLACING.length() ),
                                       ScmFileStatus.UPDATED ) );
        if ( getLogger().isInfoEnabled() )
        {
            getLogger().info( START_REPLACING + currentPath + "/" + line.substring( START_REPLACING.length() ) );
        }
    }

    /**
     * Process the current input line in the Get File Path state.
     * 
     * @param line a line of text from the VSS log output
     */
    private void processGetFilePath( String line )
    {
        currentPath = line.substring( ( VssConstants.PROJECT_PREFIX + repo.getProject() ).length(), line.length() - 1 );
    }

    /**
     * Identify the status of a vss get line
     * 
     * @param line The line to process
     * @return status
     */
    private int getLineStatus( String line )
File Line
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInCommand.java 112
org/apache/maven/scm/provider/vss/commands/edit/VssEditCommand.java 111
    public List<Commandline> buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
        throws ScmException
    {

        List<File> files = fileSet.getFileList();
        List<Commandline> commands = new ArrayList<Commandline>();

        if ( files.size() > 0 )
        {

            String base;
            try
            {
                base = fileSet.getBasedir().getCanonicalPath();
            }
            catch ( IOException e )
            {
                throw new ScmException( "Invalid canonical path", e );
            }

            for ( File file : files )
            {

                Commandline command = new Commandline();

                try
                {
                    command.addSystemEnvironment();
                }
                catch ( Exception e )
                {
                    throw new ScmException( "Can't add system environment.", e );
                }

                command.addEnvironment( "SSDIR", repo.getVssdir() );

                String ssDir = VssCommandLineUtils.getSsDir();

                command.setExecutable( ssDir + VssConstants.SS_EXE );

                command.createArg().setValue( VssConstants.COMMAND_CHECKIN );
File Line
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutCommand.java 56
org/apache/maven/scm/provider/vss/commands/tag/VssTagCommand.java 68
org/apache/maven/scm/provider/vss/commands/update/VssUpdateCommand.java 59
        VssCheckOutConsumer consumer = new VssCheckOutConsumer( repo, getLogger() );

        //      TODO handle deleted files from VSS
        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

        int exitCode;

        if ( getLogger().isDebugEnabled() )
        {
            getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
        }

        exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );

        if ( exitCode != 0 )
        {
            String error = stderr.getOutput();

            if ( getLogger().isDebugEnabled() )
            {
                getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
            }
            if ( error.indexOf( "A writable copy of" ) < 0 )
            {
                return new CheckOutScmResult( cl.toString(), "The vss command failed.", error, false );
File Line
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInCommand.java 78
org/apache/maven/scm/provider/vss/commands/edit/VssEditCommand.java 71
        StringBuilder sb = new StringBuilder();
        for ( Commandline cl : commandLines )
        {

            if ( getLogger().isDebugEnabled() )
            {
                getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
            }

            exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );

            if ( exitCode != 0 )
            {
                String error = stderr.getOutput();

                if ( getLogger().isDebugEnabled() )
                {
                    getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
                }
                if ( error.indexOf( "A writable copy of" ) < 0 )
                {
                    return new CheckInScmResult( cl.toString(), "The vss command failed.", error, false );
File Line
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInCommand.java 82
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutCommand.java 63
org/apache/maven/scm/provider/vss/commands/edit/VssEditCommand.java 76
org/apache/maven/scm/provider/vss/commands/tag/VssTagCommand.java 75
org/apache/maven/scm/provider/vss/commands/update/VssUpdateCommand.java 67
            if ( getLogger().isDebugEnabled() )
            {
                getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
            }

            exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );

            if ( exitCode != 0 )
            {
                String error = stderr.getOutput();

                if ( getLogger().isDebugEnabled() )
                {
                    getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
                }
                if ( error.indexOf( "A writable copy of" ) < 0 )
                {
                    return new CheckInScmResult( cl.toString(), "The vss command failed.", error, false );
File Line
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutCommand.java 56
org/apache/maven/scm/provider/vss/commands/status/VssStatusCommand.java 55
org/apache/maven/scm/provider/vss/commands/tag/VssTagCommand.java 68
org/apache/maven/scm/provider/vss/commands/update/VssUpdateCommand.java 59
        VssCheckOutConsumer consumer = new VssCheckOutConsumer( repo, getLogger() );

        //      TODO handle deleted files from VSS
        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

        int exitCode;

        if ( getLogger().isDebugEnabled() )
        {
            getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
        }

        exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );

        if ( exitCode != 0 )
        {
            String error = stderr.getOutput();

            if ( getLogger().isDebugEnabled() )
            {
                getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
            }
File Line
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInConsumer.java 178
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutConsumer.java 177
org/apache/maven/scm/provider/vss/commands/tag/VssTagConsumer.java 177
org/apache/maven/scm/provider/vss/commands/update/VssUpdateConsumer.java 193
    }

    /**
     * Identify the status of a vss get line
     * 
     * @param line The line to process
     * @return status
     */
    private int getLineStatus( String line )
    {
        int argument = GET_UNKNOWN;
        if ( line.startsWith( START_FILE_PATH ) )
        {
            argument = GET_FILE_PATH;
        }
        else if ( line.startsWith( START_GETTING ) )
        {
            argument = GET_FILE;
        }
        else if ( line.startsWith( START_REPLACING ) )
        {
            argument = REPLACE_FILE;
        }
        else if ( line.startsWith( START_WRITABLE_COPY ) )
        {
            argument = IS_WRITABLE_COPY;
        }
        else if ( line.indexOf( CONTAINS_SET_DEFAULT_WORKING_FOLDER ) != -1 )
        {
            argument = SET_WORKING_FOLDER;
        }

        return argument;
    }

    public List<ScmFile> getUpdatedFiles()
    {
        return updatedFiles;
    }

}
File Line
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInConsumer.java 39
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutConsumer.java 38
org/apache/maven/scm/provider/vss/commands/tag/VssTagConsumer.java 38
org/apache/maven/scm/provider/vss/commands/update/VssUpdateConsumer.java 38
    extends AbstractConsumer
    implements StreamConsumer
{

    /**
     * expecting file information
     */
    private static final int GET_UNKNOWN = 0;

    /**
     * expecting file information
     */
    private static final int GET_FILE = 1;

    /**
     * expecting file information
     */
    private static final int REPLACE_FILE = 2;

    /**
     * expecting file path information
     */
    private static final int GET_FILE_PATH = 3;

    /**
     * expecting writable copy
     */
    private static final int IS_WRITABLE_COPY = 4;

    /**
     * expecting working folder
     */
    private static final int SET_WORKING_FOLDER = 5;

    /**
     * Marks start of file data
     */
    private static final String START_FILE_PATH = "$/";

    /**
     * Marks getting a new File
     */
    private static final String START_GETTING = "Getting";

    /**
     * Marks replacing a old File
     */
    private static final String START_REPLACING = "Replacing local copy of ";

    /**
     * Marks a writable copy of a File / maybe a conflict
     */
    private static final String START_WRITABLE_COPY = "A writable ";

    /**
     * Marks "Set the default folder for project" question
     */
    private static final String CONTAINS_SET_DEFAULT_WORKING_FOLDER = "as the default folder for project";

    private String currentPath = "";

    private List<ScmFile> updatedFiles = new ArrayList<ScmFile>();

    private VssScmProviderRepository repo;

    public VssCheckInConsumer( VssScmProviderRepository repo, ScmLogger logger )
File Line
org/apache/maven/scm/provider/vss/commands/add/VssAddCommand.java 73
org/apache/maven/scm/provider/vss/commands/status/VssStatusCommand.java 79
        return new AddScmResult( cl.toString(), consumer.getAddedFiles() );
    }

    public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet )
        throws ScmException
    {
        Commandline command = new Commandline();

        command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );

        try
        {
            command.addSystemEnvironment();
        }
        catch ( Exception e )
        {
            throw new ScmException( "Can't add system environment.", e );
        }

        command.addEnvironment( "SSDIR", repo.getVssdir() );

        String ssDir = VssCommandLineUtils.getSsDir();

        command.setExecutable( ssDir + VssConstants.SS_EXE );

        command.createArg().setValue( VssConstants.COMMAND_ADD );