View Javadoc
1   package org.apache.maven.scm.provider.synergy.repository;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.scm.provider.ScmProviderRepository;
23  import org.apache.maven.scm.repository.ScmRepositoryException;
24  
25  import java.net.MalformedURLException;
26  import java.net.URISyntaxException;
27  import java.net.UnknownHostException;
28  import java.util.StringTokenizer;
29  
30  /**
31   * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a>
32   *
33   */
34  public class SynergyScmProviderRepository
35      extends ScmProviderRepository
36  {
37  
38      private String projectSpec;
39  
40      private String projectName;
41  
42      private String projectVersion;
43  
44      private String projectRelease;
45  
46      private String projectPurpose;
47  
48      private String delimiter;
49      
50      private String instance;
51  
52      /**
53       * @param url format is
54       *            project_name|delimiter|project_version|Release|Purpose|instance
55       */
56      public SynergyScmProviderRepository( String url )
57          throws ScmRepositoryException
58      {
59          try
60          {
61              parseUrl( url );
62          }
63          catch ( MalformedURLException | UnknownHostException | URISyntaxException e )
64          {
65              throw new ScmRepositoryException( "Illegal URL: " + url + "(" + e.getMessage() + ")" );
66          }
67      }
68  
69      private void parseUrl( String url )
70          throws MalformedURLException, URISyntaxException, UnknownHostException
71      {
72          if ( url.indexOf( '|' ) != -1 )
73          {
74              StringTokenizer tokenizer = new StringTokenizer( url, "|" );
75              fillInProperties( tokenizer );
76          }
77          else
78          {
79              StringTokenizer tokenizer = new StringTokenizer( url, ":" );
80              fillInProperties( tokenizer );
81          }
82      }
83  
84      private void fillInProperties( StringTokenizer tokenizer )
85          throws UnknownHostException, URISyntaxException, MalformedURLException
86      {
87          if ( tokenizer.countTokens() == 5 )
88          {
89              projectName = tokenizer.nextToken();
90              delimiter = tokenizer.nextToken();
91              projectVersion = tokenizer.nextToken();
92              projectRelease = tokenizer.nextToken();
93              projectPurpose = tokenizer.nextToken();
94              instance = "1";
95  
96              projectSpec = projectName + delimiter + projectVersion + ":project:" + instance;
97  
98          }
99          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 }