View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.provider.svn.svnexe;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import java.io.File;
25  
26  import org.apache.maven.scm.CommandParameters;
27  import org.apache.maven.scm.ScmException;
28  import org.apache.maven.scm.ScmFileSet;
29  import org.apache.maven.scm.command.info.InfoScmResult;
30  import org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult;
31  import org.apache.maven.scm.provider.ScmProviderRepository;
32  import org.apache.maven.scm.provider.svn.AbstractSvnScmProvider;
33  import org.apache.maven.scm.provider.svn.command.SvnCommand;
34  import org.apache.maven.scm.provider.svn.svnexe.command.add.SvnAddCommand;
35  import org.apache.maven.scm.provider.svn.svnexe.command.blame.SvnBlameCommand;
36  import org.apache.maven.scm.provider.svn.svnexe.command.branch.SvnBranchCommand;
37  import org.apache.maven.scm.provider.svn.svnexe.command.changelog.SvnChangeLogCommand;
38  import org.apache.maven.scm.provider.svn.svnexe.command.checkin.SvnCheckInCommand;
39  import org.apache.maven.scm.provider.svn.svnexe.command.checkout.SvnCheckOutCommand;
40  import org.apache.maven.scm.provider.svn.svnexe.command.diff.SvnDiffCommand;
41  import org.apache.maven.scm.provider.svn.svnexe.command.export.SvnExeExportCommand;
42  import org.apache.maven.scm.provider.svn.svnexe.command.info.SvnInfoCommand;
43  import org.apache.maven.scm.provider.svn.svnexe.command.list.SvnListCommand;
44  import org.apache.maven.scm.provider.svn.svnexe.command.mkdir.SvnMkdirCommand;
45  import org.apache.maven.scm.provider.svn.svnexe.command.remoteinfo.SvnRemoteInfoCommand;
46  import org.apache.maven.scm.provider.svn.svnexe.command.remove.SvnRemoveCommand;
47  import org.apache.maven.scm.provider.svn.svnexe.command.status.SvnStatusCommand;
48  import org.apache.maven.scm.provider.svn.svnexe.command.tag.SvnTagCommand;
49  import org.apache.maven.scm.provider.svn.svnexe.command.untag.SvnUntagCommand;
50  import org.apache.maven.scm.provider.svn.svnexe.command.update.SvnUpdateCommand;
51  import org.apache.maven.scm.repository.ScmRepositoryException;
52  
53  /**
54   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
55   */
56  @Singleton
57  @Named("svn")
58  public class SvnExeScmProvider extends AbstractSvnScmProvider {
59      /**
60       * {@inheritDoc}
61       */
62      @Override
63      protected SvnCommand getAddCommand() {
64          return new SvnAddCommand();
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      protected SvnCommand getBranchCommand() {
72          return new SvnBranchCommand();
73      }
74  
75      /**
76       * {@inheritDoc}
77       */
78      @Override
79      protected SvnCommand getChangeLogCommand() {
80          return new SvnChangeLogCommand();
81      }
82  
83      /**
84       * {@inheritDoc}
85       */
86      @Override
87      protected SvnCommand getCheckInCommand() {
88          return new SvnCheckInCommand();
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      @Override
95      protected SvnCommand getCheckOutCommand() {
96          return new SvnCheckOutCommand();
97      }
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     protected SvnCommand getDiffCommand() {
104         return new SvnDiffCommand();
105     }
106 
107     /**
108      * {@inheritDoc}
109      */
110     @Override
111     protected SvnCommand getExportCommand() {
112         return new SvnExeExportCommand();
113     }
114 
115     /**
116      * {@inheritDoc}
117      */
118     @Override
119     protected SvnCommand getRemoveCommand() {
120         return new SvnRemoveCommand();
121     }
122 
123     /**
124      * {@inheritDoc}
125      */
126     @Override
127     protected SvnCommand getStatusCommand() {
128         return new SvnStatusCommand();
129     }
130 
131     /**
132      * {@inheritDoc}
133      */
134     @Override
135     protected SvnCommand getTagCommand() {
136         return new SvnTagCommand();
137     }
138 
139     /**
140      * {@inheritDoc}
141      */
142     @Override
143     protected SvnCommand getUntagCommand() {
144         return new SvnUntagCommand();
145     }
146 
147     /**
148      * {@inheritDoc}
149      */
150     @Override
151     protected SvnCommand getUpdateCommand() {
152         return new SvnUpdateCommand();
153     }
154 
155     /**
156      * {@inheritDoc}
157      */
158     @Override
159     protected SvnCommand getListCommand() {
160         return new SvnListCommand();
161     }
162 
163     @Override
164     public SvnCommand getInfoCommand() {
165         return new SvnInfoCommand();
166     }
167 
168     /**
169      * {@inheritDoc}
170      */
171     @Override
172     protected SvnCommand getBlameCommand() {
173         return new SvnBlameCommand();
174     }
175 
176     /**
177      * {@inheritDoc}
178      */
179     @Override
180     protected SvnCommand getMkdirCommand() {
181         return new SvnMkdirCommand();
182     }
183 
184     /**
185      * {@inheritDoc}
186      */
187     @Override
188     protected String getRepositoryURL(File path) throws ScmException {
189         // Note: I need to supply just 1 absolute path, but ScmFileSet won't let me without
190         // a basedir (which isn't used here anyway), so use a dummy file.
191         SvnInfoCommand infoCmd = (SvnInfoCommand) getInfoCommand();
192 
193         InfoScmResult result = infoCmd.executeInfoCommand(null, new ScmFileSet(new File(""), path), null, false, null);
194 
195         if (result.getInfoItems().size() != 1) {
196             throw new ScmRepositoryException("Cannot find URL: "
197                     + (result.getInfoItems().size() == 0 ? "no" : "multiple") + " items returned by the info command");
198         }
199 
200         return result.getInfoItems().get(0).getURL();
201     }
202 
203     @Override
204     public RemoteInfoScmResult remoteInfo(
205             ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
206         SvnRemoteInfoCommand svnRemoteInfoCommand = new SvnRemoteInfoCommand();
207         return svnRemoteInfoCommand.executeRemoteInfoCommand(repository, fileSet, parameters);
208     }
209 
210     @Override
211     public boolean remoteUrlExist(ScmProviderRepository repository, CommandParameters parameters) throws ScmException {
212         SvnRemoteInfoCommand svnRemoteInfoCommand = new SvnRemoteInfoCommand();
213         return svnRemoteInfoCommand.remoteUrlExist(repository, parameters);
214     }
215 }