I talk about file parsing in ${user.home}/.scm/

Wim Deblauwe a écrit :


2005/12/1, Emmanuel Venisse <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>:

    Remove all maven-scm libs from ${continuum}/apps/continuum/lib and
    put in it all new maven-scm libs.

    What do you use for scm file parsing?

    Emmanuel


Euh.. just stringtokenizer, like this:

public class ClearCaseScmProviderRepository
    extends ScmProviderRepository
{
    private String viewName;
    private File configSpec;

    /**
     *
* @param url format is [view_name]:[url_to_configspec] or [view_name]|[url_to_configspec]
     */
    public ClearCaseScmProviderRepository( String url )
        throws ScmRepositoryException
    {
        try
        {
            System.out.println( "url = " + url );
            parseUrl( url );
        }
        catch ( MalformedURLException e )
        {
throw new ScmRepositoryException( "Illegal URL: " + url + "(" + e.getMessage() + ")" );
        }
        catch ( URISyntaxException e )
        {
throw new ScmRepositoryException( "Illegal URL: " + url + "(" + e.getMessage() + ")" );
        }
        catch ( UnknownHostException e )
        {
throw new ScmRepositoryException( "Illegal URL: " + url + "(" + e.getMessage() + ")" );
        }
    }

    private void parseUrl( String url )
throws MalformedURLException, URISyntaxException, UnknownHostException
    {
        if( url.indexOf( '|' ) != -1 )
        {
            StringTokenizer tokenizer = new StringTokenizer( url, "|" );
            fillInProperties( tokenizer );
        }
        else
        {
            StringTokenizer tokenizer = new StringTokenizer( url, ":" );
            fillInProperties( tokenizer );
        }
    }

    private void fillInProperties( StringTokenizer tokenizer )
throws UnknownHostException, URISyntaxException, MalformedURLException
    {
        if( tokenizer.countTokens() == 1 )
        {
           //No view name was given
            viewName = getDefaultViewName();
            String spec = tokenizer.nextToken();
            System.out.println( "spec = " + spec );
            configSpec = createConfigSpecFile( spec );
        }
        else
        {
            viewName = tokenizer.nextToken();
            System.out.println( "viewName = " + viewName );
            String pathname = tokenizer.nextToken();
            System.out.println( "pathname = " + pathname );
            configSpec = createConfigSpecFile( pathname );
        }
    }

    private File createConfigSpecFile( String spec )
        throws URISyntaxException, MalformedURLException
    {
        File result;
        if( spec.indexOf( ':' ) == -1 )
        {
            result = new File( spec );
        }
        else
        {
            result = new File( new URL( spec ).toURI() );
        }
        return result;
    }

    /**
     * Default: ${hostname}-{user.name <http://user.name>}-${artifactId}
     * @return
     */
    private String getDefaultViewName()
        throws UnknownHostException
    {
String username = System.getProperty( "user.name <http://user.name>", "nouser" );
        String hostname = getHostName();
        return username + "-" + hostname + "-maven";
    }

    private String getHostName()
        throws UnknownHostException
    {
        return InetAddress.getLocalHost().getHostName();
    }

    public String getViewName()
    {
        return viewName;
    }

    public File getConfigSpec()
    {
        return configSpec;
    }
}


Reply via email to