001package org.apache.maven.scm.provider.synergy.repository; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.scm.provider.ScmProviderRepository; 023import org.apache.maven.scm.repository.ScmRepositoryException; 024 025import java.net.MalformedURLException; 026import java.net.URISyntaxException; 027import java.net.UnknownHostException; 028import java.util.StringTokenizer; 029 030/** 031 * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a> 032 * 033 */ 034public class SynergyScmProviderRepository 035 extends ScmProviderRepository 036{ 037 038 private String projectSpec; 039 040 private String projectName; 041 042 private String projectVersion; 043 044 private String projectRelease; 045 046 private String projectPurpose; 047 048 private String delimiter; 049 050 private String instance; 051 052 /** 053 * @param url format is 054 * project_name|delimiter|project_version|Release|Purpose|instance 055 */ 056 public SynergyScmProviderRepository( String url ) 057 throws ScmRepositoryException 058 { 059 try 060 { 061 parseUrl( url ); 062 } 063 catch ( MalformedURLException | UnknownHostException | URISyntaxException e ) 064 { 065 throw new ScmRepositoryException( "Illegal URL: " + url + "(" + e.getMessage() + ")" ); 066 } 067 } 068 069 private void parseUrl( String url ) 070 throws MalformedURLException, URISyntaxException, UnknownHostException 071 { 072 if ( url.indexOf( '|' ) != -1 ) 073 { 074 StringTokenizer tokenizer = new StringTokenizer( url, "|" ); 075 fillInProperties( tokenizer ); 076 } 077 else 078 { 079 StringTokenizer tokenizer = new StringTokenizer( url, ":" ); 080 fillInProperties( tokenizer ); 081 } 082 } 083 084 private void fillInProperties( StringTokenizer tokenizer ) 085 throws UnknownHostException, URISyntaxException, MalformedURLException 086 { 087 if ( tokenizer.countTokens() == 5 ) 088 { 089 projectName = tokenizer.nextToken(); 090 delimiter = tokenizer.nextToken(); 091 projectVersion = tokenizer.nextToken(); 092 projectRelease = tokenizer.nextToken(); 093 projectPurpose = tokenizer.nextToken(); 094 instance = "1"; 095 096 projectSpec = projectName + delimiter + projectVersion + ":project:" + instance; 097 098 } 099 else if ( tokenizer.countTokens() == 6 ) 100 { //optional prep project instance also 101 projectName = tokenizer.nextToken(); 102 delimiter = tokenizer.nextToken(); 103 projectVersion = tokenizer.nextToken(); 104 projectRelease = tokenizer.nextToken(); 105 projectPurpose = tokenizer.nextToken(); 106 instance = tokenizer.nextToken(); 107 108 projectSpec = projectName + delimiter + projectVersion + ":project:" + instance; 109 110 } 111 else 112 { 113 throw new MalformedURLException(); 114 } 115 } 116 117 public String getProjectSpec() 118 { 119 return projectSpec; 120 } 121 122 public String getProjectName() 123 { 124 return projectName; 125 } 126 127 public String getProjectVersion() 128 { 129 return projectVersion; 130 } 131 132 /** 133 * @return the project_purpose 134 */ 135 public String getProjectPurpose() 136 { 137 return projectPurpose; 138 } 139 140 /** 141 * @return the project_release 142 */ 143 public String getProjectRelease() 144 { 145 return projectRelease; 146 } 147 148 /** 149 * @return the instance 150 */ 151 public String getInstance() 152 { 153 return instance; 154 } 155 156 157}