CPD Results

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

Duplications

FileLine
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInConsumer.java104
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutConsumer.java103
org/apache/maven/scm/provider/vss/commands/tag/VssTagConsumer.java103
    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;
    }

}
FileLine
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInCommand.java152
org/apache/maven/scm/provider/vss/commands/edit/VssEditCommand.java150
                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 );
FileLine
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutCommand.java89
org/apache/maven/scm/provider/vss/commands/update/VssUpdateCommand.java93
        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 );
FileLine
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInConsumer.java131
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutConsumer.java130
org/apache/maven/scm/provider/vss/commands/tag/VssTagConsumer.java130
org/apache/maven/scm/provider/vss/commands/update/VssUpdateConsumer.java131
                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 )
FileLine
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInCommand.java112
org/apache/maven/scm/provider/vss/commands/edit/VssEditCommand.java111
    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 );
FileLine
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutCommand.java56
org/apache/maven/scm/provider/vss/commands/tag/VssTagCommand.java68
org/apache/maven/scm/provider/vss/commands/update/VssUpdateCommand.java59
        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 );
FileLine
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInCommand.java78
org/apache/maven/scm/provider/vss/commands/edit/VssEditCommand.java71
        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 );
FileLine
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutCommand.java56
org/apache/maven/scm/provider/vss/commands/status/VssStatusCommand.java55
org/apache/maven/scm/provider/vss/commands/tag/VssTagCommand.java68
org/apache/maven/scm/provider/vss/commands/update/VssUpdateCommand.java59
        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 + "]" );
            }
FileLine
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInCommand.java82
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutCommand.java63
org/apache/maven/scm/provider/vss/commands/edit/VssEditCommand.java76
org/apache/maven/scm/provider/vss/commands/tag/VssTagCommand.java75
org/apache/maven/scm/provider/vss/commands/update/VssUpdateCommand.java67
            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 );
FileLine
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInConsumer.java178
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutConsumer.java177
org/apache/maven/scm/provider/vss/commands/tag/VssTagConsumer.java177
org/apache/maven/scm/provider/vss/commands/update/VssUpdateConsumer.java193
    }

    /**
     * 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;
    }

}
FileLine
org/apache/maven/scm/provider/vss/commands/checkin/VssCheckInConsumer.java39
org/apache/maven/scm/provider/vss/commands/checkout/VssCheckOutConsumer.java38
org/apache/maven/scm/provider/vss/commands/tag/VssTagConsumer.java38
org/apache/maven/scm/provider/vss/commands/update/VssUpdateConsumer.java38
    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 )
FileLine
org/apache/maven/scm/provider/vss/commands/add/VssAddCommand.java73
org/apache/maven/scm/provider/vss/commands/status/VssStatusCommand.java79
        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 );