21 import java.net.MalformedURLException; |
21 import java.net.MalformedURLException; |
22 import java.net.URL; |
22 import java.net.URL; |
23 import java.util.ArrayList; |
23 import java.util.ArrayList; |
24 import java.util.List; |
24 import java.util.List; |
25 |
25 |
26 import com.nokia.maven.scm.provider.hg.command.log.HgChangeLogCommand; |
|
27 import org.apache.maven.scm.command.changelog.ChangeLogScmResult; |
|
28 |
|
29 import org.apache.log4j.Logger; |
26 import org.apache.log4j.Logger; |
30 import org.apache.maven.scm.CommandParameters; |
27 import org.apache.maven.scm.CommandParameters; |
31 import org.apache.maven.scm.ScmException; |
28 import org.apache.maven.scm.ScmException; |
32 import org.apache.maven.scm.ScmFileSet; |
29 import org.apache.maven.scm.ScmFileSet; |
33 import org.apache.maven.scm.ScmResult; |
30 import org.apache.maven.scm.ScmResult; |
|
31 import org.apache.maven.scm.command.branch.BranchScmResult; |
|
32 import org.apache.maven.scm.command.changelog.ChangeLogScmResult; |
34 import org.apache.maven.scm.command.checkout.CheckOutScmResult; |
33 import org.apache.maven.scm.command.checkout.CheckOutScmResult; |
35 import org.apache.maven.scm.command.export.ExportScmResult; |
34 import org.apache.maven.scm.command.export.ExportScmResult; |
36 import org.apache.maven.scm.command.remove.RemoveScmResult; |
35 import org.apache.maven.scm.command.remove.RemoveScmResult; |
37 import org.apache.maven.scm.command.branch.BranchScmResult; |
36 import org.apache.maven.scm.command.tag.TagScmResult; |
38 import org.apache.maven.scm.command.update.UpdateScmResult; |
37 import org.apache.maven.scm.command.update.UpdateScmResult; |
39 import org.apache.maven.scm.command.tag.TagScmResult; |
|
40 import org.apache.maven.scm.provider.ScmProviderRepository; |
38 import org.apache.maven.scm.provider.ScmProviderRepository; |
41 import org.apache.maven.scm.provider.hg.HgScmProvider; |
39 import org.apache.maven.scm.provider.hg.HgScmProvider; |
42 import org.apache.maven.scm.repository.ScmRepository; |
40 import org.apache.maven.scm.repository.ScmRepository; |
43 import org.apache.maven.scm.repository.ScmRepositoryException; |
41 import org.apache.maven.scm.repository.ScmRepositoryException; |
44 |
42 |
|
43 import com.nokia.maven.scm.command.info.InfoScmResult; |
45 import com.nokia.maven.scm.command.pull.PullScmResult; |
44 import com.nokia.maven.scm.command.pull.PullScmResult; |
46 import com.nokia.maven.scm.command.tags.TagsScmResult; |
45 import com.nokia.maven.scm.command.tags.TagsScmResult; |
47 import com.nokia.maven.scm.command.info.InfoScmResult; |
|
48 import com.nokia.maven.scm.provider.ScmProviderExt; |
46 import com.nokia.maven.scm.provider.ScmProviderExt; |
|
47 import com.nokia.maven.scm.provider.hg.command.branch.HgBranchCommand; |
|
48 import com.nokia.maven.scm.provider.hg.command.checkout.HgCheckOutCommand; |
|
49 import com.nokia.maven.scm.provider.hg.command.export.HgExportCommand; |
|
50 import com.nokia.maven.scm.provider.hg.command.info.HgInfoCommand; |
49 import com.nokia.maven.scm.provider.hg.command.init.HgInitCommand; |
51 import com.nokia.maven.scm.provider.hg.command.init.HgInitCommand; |
|
52 import com.nokia.maven.scm.provider.hg.command.log.HgChangeLogCommand; |
50 import com.nokia.maven.scm.provider.hg.command.pull.HgPullCommand; |
53 import com.nokia.maven.scm.provider.hg.command.pull.HgPullCommand; |
51 import com.nokia.maven.scm.provider.hg.command.remove.HgRemoveCommand; |
54 import com.nokia.maven.scm.provider.hg.command.remove.HgRemoveCommand; |
|
55 import com.nokia.maven.scm.provider.hg.command.tag.HgTagCommand; |
52 import com.nokia.maven.scm.provider.hg.command.tags.HgTagsCommand; |
56 import com.nokia.maven.scm.provider.hg.command.tags.HgTagsCommand; |
53 import com.nokia.maven.scm.provider.hg.command.info.HgInfoCommand; |
|
54 import com.nokia.maven.scm.provider.hg.command.update.HgUpdateCommand; |
57 import com.nokia.maven.scm.provider.hg.command.update.HgUpdateCommand; |
55 import com.nokia.maven.scm.provider.hg.command.checkout.HgCheckOutCommand; |
|
56 import com.nokia.maven.scm.provider.hg.command.export.HgExportCommand; |
|
57 import com.nokia.maven.scm.provider.hg.command.branch.HgBranchCommand; |
|
58 import com.nokia.maven.scm.provider.hg.command.tag.HgTagCommand; |
|
59 import com.nokia.maven.scm.provider.hg.repository.HgScmProviderRepository; |
58 import com.nokia.maven.scm.provider.hg.repository.HgScmProviderRepository; |
60 |
59 |
61 /** |
60 /** |
62 * The SCM provider for Mercurial (hg). |
61 * The SCM provider for Mercurial (hg). |
63 */ |
62 */ |
64 public class HgScmProviderExt extends HgScmProvider implements ScmProviderExt { |
63 public class HgScmProviderExt extends HgScmProvider implements ScmProviderExt { |
65 |
64 |
66 private static Logger log = Logger.getLogger(HgScmProviderExt.class); |
65 private static Logger log = Logger.getLogger(HgScmProviderExt.class); |
67 |
66 |
68 public ScmResult init(ScmRepository repository) throws ScmException { |
67 public ScmResult init(ScmRepository repository) throws ScmException { |
69 log.info("HgScmProviderExt.init()"); |
68 log.info("HgScmProviderExt.init()"); |
70 |
69 |
71 HgInitCommand command = new HgInitCommand(); |
70 HgInitCommand command = new HgInitCommand(); |
72 |
71 |
73 return command.executeInitCommand(repository.getProviderRepository()); |
72 return command.executeInitCommand(repository.getProviderRepository()); |
74 } |
73 } |
75 |
74 |
76 @Override |
75 @Override |
77 public CheckOutScmResult checkout(ScmProviderRepository repository, |
76 public CheckOutScmResult checkout(ScmProviderRepository repository, ScmFileSet fileSet, |
78 ScmFileSet fileSet, CommandParameters parameters) |
77 CommandParameters parameters) throws ScmException { |
79 throws ScmException { |
|
80 |
78 |
81 HgCheckOutCommand command = new HgCheckOutCommand(); |
79 HgCheckOutCommand command = new HgCheckOutCommand(); |
82 command.setLogger(getLogger()); |
80 command.setLogger(getLogger()); |
83 return (CheckOutScmResult) command.executeCommand(repository, fileSet, |
81 return (CheckOutScmResult) command.executeCommand(repository, fileSet, parameters); |
84 parameters); |
82 } |
85 } |
83 |
86 |
84 @Override |
87 @Override |
85 public ChangeLogScmResult changelog(ScmProviderRepository repository, ScmFileSet fileSet, |
88 public ChangeLogScmResult changelog(ScmProviderRepository repository, |
86 CommandParameters parameters) throws ScmException { |
89 ScmFileSet fileSet, CommandParameters parameters) |
|
90 throws ScmException { |
|
91 |
87 |
92 HgChangeLogCommand command = new HgChangeLogCommand(); |
88 HgChangeLogCommand command = new HgChangeLogCommand(); |
93 command.setLogger(getLogger()); |
89 command.setLogger(getLogger()); |
94 return (ChangeLogScmResult) command.executeCommand(repository, fileSet, |
90 return (ChangeLogScmResult) command.executeCommand(repository, fileSet, parameters); |
95 parameters); |
91 } |
96 } |
92 |
97 |
93 public PullScmResult pull(ScmRepository repository, File path) throws ScmException { |
98 public PullScmResult pull(ScmRepository repository, File path) |
|
99 throws ScmException { |
|
100 HgPullCommand command = new HgPullCommand(); |
94 HgPullCommand command = new HgPullCommand(); |
101 command.setLogger(getLogger()); |
95 command.setLogger(getLogger()); |
102 return (PullScmResult) command.executeCommand(repository |
96 return (PullScmResult) command.executeCommand(repository.getProviderRepository(), new ScmFileSet(path), new CommandParameters()); |
103 .getProviderRepository(), new ScmFileSet(path), |
97 } |
104 new CommandParameters()); |
98 |
105 } |
99 @Override |
106 |
100 public UpdateScmResult update(ScmProviderRepository repository, ScmFileSet fileSet, |
107 @Override |
101 CommandParameters parameters) throws ScmException { |
108 public UpdateScmResult update(ScmProviderRepository repository, |
|
109 ScmFileSet fileSet, CommandParameters parameters) |
|
110 throws ScmException { |
|
111 HgUpdateCommand command = new HgUpdateCommand(); |
102 HgUpdateCommand command = new HgUpdateCommand(); |
112 command.setLogger(getLogger()); |
103 command.setLogger(getLogger()); |
113 return (UpdateScmResult) command.executeCommand(repository, fileSet, |
104 return (UpdateScmResult) command.executeCommand(repository, fileSet, parameters); |
114 parameters); |
|
115 } |
105 } |
116 |
106 |
117 public TagsScmResult tags(ScmRepository repository, ScmFileSet fileSet, |
107 public TagsScmResult tags(ScmRepository repository, ScmFileSet fileSet, |
118 CommandParameters parameters) throws ScmException { |
108 CommandParameters parameters) throws ScmException { |
119 HgTagsCommand command = new HgTagsCommand(); |
109 HgTagsCommand command = new HgTagsCommand(); |
120 command.setLogger(getLogger()); |
110 command.setLogger(getLogger()); |
121 return (TagsScmResult) command.executeCommand(repository |
111 return (TagsScmResult) command.executeCommand(repository.getProviderRepository(), fileSet, parameters); |
122 .getProviderRepository(), fileSet, parameters); |
112 } |
123 } |
113 |
124 |
|
125 public InfoScmResult info(ScmRepository repository, ScmFileSet fileSet, |
114 public InfoScmResult info(ScmRepository repository, ScmFileSet fileSet, |
126 CommandParameters parameters) throws ScmException { |
115 CommandParameters parameters) throws ScmException { |
127 HgInfoCommand command = new HgInfoCommand(); |
116 HgInfoCommand command = new HgInfoCommand(); |
128 command.setLogger(getLogger()); |
117 command.setLogger(getLogger()); |
129 return (InfoScmResult) command.executeCommand(repository |
118 return (InfoScmResult) command.executeCommand(repository.getProviderRepository(), fileSet, parameters); |
130 .getProviderRepository(), fileSet, parameters); |
119 } |
131 } |
120 |
132 |
121 @Override |
133 @Override |
122 public RemoveScmResult remove(ScmProviderRepository repository, ScmFileSet fileSet, |
134 public RemoveScmResult remove(ScmProviderRepository repository, |
123 CommandParameters parameters) throws ScmException { |
135 ScmFileSet fileSet, CommandParameters parameters) |
|
136 throws ScmException { |
|
137 HgRemoveCommand command = new HgRemoveCommand(); |
124 HgRemoveCommand command = new HgRemoveCommand(); |
138 command.setLogger(getLogger()); |
125 command.setLogger(getLogger()); |
139 return (RemoveScmResult) command.execute(repository, fileSet, |
126 return (RemoveScmResult) command.execute(repository, fileSet, parameters); |
140 parameters); |
127 } |
141 } |
128 |
142 |
129 protected BranchScmResult branch(ScmProviderRepository repository, ScmFileSet fileSet, |
143 protected BranchScmResult branch(ScmProviderRepository repository, |
130 CommandParameters parameters) throws ScmException { |
144 ScmFileSet fileSet, CommandParameters parameters) |
|
145 throws ScmException { |
|
146 HgBranchCommand command = new HgBranchCommand(); |
131 HgBranchCommand command = new HgBranchCommand(); |
147 command.setLogger(getLogger()); |
132 command.setLogger(getLogger()); |
148 return (BranchScmResult) command.execute(repository, fileSet, |
133 return (BranchScmResult) command.execute(repository, fileSet, parameters); |
149 parameters); |
134 } |
150 } |
135 |
151 |
136 protected ExportScmResult export(ScmProviderRepository repository, ScmFileSet fileSet, |
152 protected ExportScmResult export(ScmProviderRepository repository, |
137 CommandParameters parameters) throws ScmException { |
153 ScmFileSet fileSet, CommandParameters parameters) |
|
154 throws ScmException { |
|
155 HgExportCommand command = new HgExportCommand(); |
138 HgExportCommand command = new HgExportCommand(); |
156 command.setLogger(getLogger()); |
139 command.setLogger(getLogger()); |
157 return (ExportScmResult) command.execute(repository, fileSet, |
140 return (ExportScmResult) command.execute(repository, fileSet, parameters); |
158 parameters); |
141 } |
159 } |
142 |
160 |
143 @Override |
161 @Override |
144 public TagScmResult tag(ScmProviderRepository repository, ScmFileSet fileSet, |
162 public TagScmResult tag(ScmProviderRepository repository, |
145 CommandParameters parameters) throws ScmException { |
163 ScmFileSet fileSet, CommandParameters parameters) |
|
164 throws ScmException { |
|
165 HgTagCommand command = new HgTagCommand(); |
146 HgTagCommand command = new HgTagCommand(); |
166 command.setLogger(getLogger()); |
147 command.setLogger(getLogger()); |
167 return (TagScmResult) command.execute(repository, fileSet, parameters); |
148 return (TagScmResult) command.execute(repository, fileSet, parameters); |
168 } |
149 } |
169 |
150 |
170 /* From official implementation */ |
151 /* From official implementation */ |
171 private final class HgUrlParserResult { |
152 private final class HgUrlParserResult { |
172 private List<String> messages = new ArrayList<String>(); |
153 private List<String> messages = new ArrayList<String>(); |
173 private ScmProviderRepository repository; |
154 private ScmProviderRepository repository; |
174 |
155 |
175 public List<String> getMessages() { |
156 public List<String> getMessages() { |
176 return messages; |
157 return messages; |
177 } |
158 } |
178 |
159 |
179 public void setMessages(List<String> messages) { |
160 public void setMessages(List<String> messages) { |
180 this.messages = messages; |
161 this.messages = messages; |
181 } |
162 } |
182 |
163 |
183 public ScmProviderRepository getRepository() { |
164 public ScmProviderRepository getRepository() { |
184 return repository; |
165 return repository; |
185 } |
166 } |
186 |
167 |
187 public void setRepository(ScmProviderRepository repository) { |
168 public void setRepository(ScmProviderRepository repository) { |
188 this.repository = repository; |
169 this.repository = repository; |
189 } |
170 } |
190 |
171 |
191 } |
172 } |
192 |
173 |
193 private HgUrlParserResult parseScmUrl(String scmSpecificUrl) { |
174 private HgUrlParserResult parseScmUrl(String scmSpecificUrl) { |
194 HgUrlParserResult result = new HgUrlParserResult(); |
175 HgUrlParserResult result = new HgUrlParserResult(); |
195 |
176 |
196 URL url = null; |
177 URL url = null; |
197 log.debug("HgScmProviderExt:parseScmUrl:" + scmSpecificUrl); |
178 log.debug("HgScmProviderExt:parseScmUrl:" + scmSpecificUrl); |
198 // try if it is an URL |
179 // try if it is an URL |
199 try { |
180 try { |
200 url = new URL(scmSpecificUrl); |
181 url = new URL(scmSpecificUrl); |
201 HgScmProviderRepository repo = new HgScmProviderRepository( |
182 HgScmProviderRepository repo = new HgScmProviderRepository("file://localhost/"); |
202 "file://localhost/"); |
|
203 repo.configure(url); |
183 repo.configure(url); |
204 result.repository = repo; |
184 result.repository = repo; |
205 } catch (MalformedURLException e) { |
185 } |
206 log.debug("HgScmProviderExt:parseScmUrl:MalformedURLException:" |
186 catch (MalformedURLException e) { |
207 + e.getMessage()); |
187 log.debug("HgScmProviderExt:parseScmUrl:MalformedURLException:" + e.getMessage()); |
208 // if the url is invalid then try a simple file. |
188 // if the url is invalid then try a simple file. |
209 //try { |
189 // try { |
210 result.setRepository(new HgScmProviderRepository(scmSpecificUrl)); |
190 result.setRepository(new HgScmProviderRepository(scmSpecificUrl)); |
211 /**} catch (Throwable et) { |
191 /** |
212 log.debug("HgScmProviderExt:parseScmUrl:Throwable:" |
192 * } catch (Throwable et) { log.debug("HgScmProviderExt:parseScmUrl:Throwable:" + |
213 + et.getMessage()); |
193 * et.getMessage()); result.getMessages().add("The filename provided is not valid: " + |
214 result.getMessages().add("The filename provided is not valid: " |
194 * et.getMessage()); return result; } |
215 + et.getMessage()); |
195 **/ |
216 return result; |
|
217 }**/ |
|
218 } |
196 } |
219 return result; |
197 return result; |
220 } |
198 } |
221 |
199 |
222 /** |
200 /** |