static MavenSettings parseMavenSettings ( File settingsFile ) throws IOException { MavenSettings settings = new MavenSettings ( ) ; try { DocumentBuilder xmlBuilder = DocumentBuilderFactory . newInstance ( ) . newDocumentBuilder ( ) ; Document xmlDoc = xmlBuilder . parse ( settingsFile ) ; NodeList mirrorList = xmlDoc . getDocumentElement ( ) . getElementsByTagName ( "mirror" ) ; for ( int i = 0 ; i < mirrorList . getLength ( ) ; i ++ ) { Element mirror = ( Element ) mirrorList . item ( i ) ; String url = mirror . getElementsByTagName ( "url" ) . item ( 0 ) . getTextContent ( ) . trim ( ) ; String mirrorOf = mirror . getElementsByTagName ( "mirrorOf" ) . item ( 0 ) . getTextContent ( ) . trim ( ) ; if ( mirrorOf . equals ( "central" ) || mirrorOf . contains ( "*" ) ) settings . mMirrorUrl = url ; } NodeList proxyList = xmlDoc . getDocumentElement ( ) . getElementsByTagName ( "proxy" ) ; for ( int i = 0 ; i < proxyList . getLength ( ) ; i ++ ) { Node proxy = proxyList . item ( i ) ; Node host = null ; Node port = null ; for ( int j = 0 ; j < proxy . getChildNodes ( ) . getLength ( ) ; j ++ ) { Node n = proxy . getChildNodes ( ) . item ( j ) ; if ( n . getNodeName ( ) . equals ( "host" ) ) host = n ; if ( n . getNodeName ( ) . equals ( "port" ) ) port = n ; } if ( host != null ) { settings . mProxyHost = host . getTextContent ( ) . trim ( ) ; if ( port != null ) settings . mProxyPort = Integer . parseInt ( port . getTextContent ( ) . trim ( ) ) ; break ; } } } catch ( Exception e ) { throw new IOException ( e ) ; } return settings ; }
parse maven settings . xml