package com.perforce.maven.scm.provider.p4.util; import java.util.Arrays; import java.util.HashSet; import org.codehaus.plexus.util.StringUtils; import com.perforce.maven.scm.provider.p4.util.P4ScmUrl; class P4Port { public static final String[] PROTOCOLS = { "tcp", "tcp4", "tcp6", "tcp46", "tcp64", "ssl", "ssl4", "ssl6", "ssl46", "ssl64" }; private String protocol; public String getProtocol() { return protocol; } private String host; public String getHost() { return host; } private int port; public int getPort() { return port; } private String user; public String getUser() { return user; } private String password; public String getPassword() { return password; } private P4Port() { } public String getScm() { StringBuilder buff = new StringBuilder(); if ( protocol != null ) { buff.append( protocol ).append( ":" ); } if ( StringUtils.isNotBlank( user ) ) { if ( StringUtils.isNotBlank( password ) ) { buff.append( password ).append( ":" ); } buff.append( user ).append( "@" ); } buff.append( host ); if ( port > 0 ) { buff.append( ":" ).append( port ); } return buff.toString(); } public String getP4Port() { StringBuilder buff = new StringBuilder(); if ( protocol != null ) { buff.append( protocol ).append( ":" ); } buff.append( host ); if ( port > 0 ) { buff.append( ":" ).append( port ); } return buff.toString(); } public static P4Port parse( String p4Port ) { if ( StringUtils.isBlank( p4Port ) ) { throw new IllegalArgumentException( "P4PORT cannot be blank" ); } String originalP4Port = p4Port; P4Port o = new P4Port(); // extract protocol if matched int i0 = p4Port.indexOf( ":" ); if ( i0 > 0 ) { o.protocol = p4Port.substring( 0, i0 ); HashSet<String> protocols = new HashSet<String>( Arrays.asList( PROTOCOLS ) ); if ( protocols.contains( o.protocol ) ) { p4Port = p4Port.substring( i0 + 1 ); } else { o.protocol = null; } } // extract credential if available String credentialToken = null; String[] tokens = StringUtils.split( p4Port, "@" ); if ( tokens.length == 2 ) { credentialToken = tokens[0]; p4Port = tokens[1]; } else if ( tokens.length > 2 ) { throw new IllegalArgumentException( "Invalid P4PORT: " + originalP4Port ); } if ( credentialToken != null ) { tokens = StringUtils.split( credentialToken, ":" ); o.user = tokens[0]; if ( tokens.length == 2 ) { o.password = tokens[1]; } else if ( tokens.length > 2 ) { throw new IllegalArgumentException( "Invalid P4PORT: " + originalP4Port ); } } else { o.user = System.getenv( P4ScmUrl.P4USER_KEY ); } // extract host info tokens = StringUtils.split( p4Port, ":" ); o.host = tokens[0]; if ( tokens.length == 2 ) { o.port = Integer.parseInt( tokens[1] ); } else if ( tokens.length > 2 ) { throw new IllegalArgumentException( "Invalid P4PORT: " + originalP4Port ); } return o; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 19967 | jkovisto | Pull over numerous changes from @dantran's branch from change 16716. | ||
#1 | 10055 | Matt Attaway | Pull over numerous changes from @dantran's branch. | ||
//guest/dantran/p4maven/p4maven-provider/src/main/java/com/perforce/maven/scm/provider/p4/util/P4Port.java | |||||
#6 | 9628 | dantran | better P4ScmUrl parser | ||
#5 | 9590 | dantran |
- add option to fail tag when it already exist - add P4ScmUrl parser test - cleanup |
||
#4 | 9548 | dantran |
- pickup P4PORT form env and system properties to support multi site using proxy - add development doc - check for error after each action |
||
#3 | 9533 | dantran | source format | ||
#2 | 9528 | dantran | Isolate P2 url parsing task into its own class to be reusable by test | ||
#1 | 9519 | dantran | folder rename to match with its artifactId | ||
//guest/dantran/p4maven/com.perforce.maven/src/main/java/com/perforce/maven/scm/provider/p4/util/P4Port.java | |||||
#1 | 9514 | dantran |
- Remove support to pick up p4port and its credential from ENV and System properties. These setttings has no use since Maven requires user to provide the required URL which has both p4port and credential. Also user can always fall back to settings.xml to store credential - Rewrite URL parser and also support password as part of URL - TCK test now has default URL and its credential is store under settings.xml - User can also issue her how scmTckUrl system properties ( to be doc as part of maven site) |