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      private boolean interactive = true;
60  
61      @Override
62      public void setInteractive(boolean interactive) {
63          this.interactive = interactive;
64      }
65  
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      protected SvnCommand getAddCommand() {
71          return new SvnAddCommand();
72      }
73  
74      /**
75       * {@inheritDoc}
76       */
77      @Override
78      protected SvnCommand getBranchCommand() {
79          return new SvnBranchCommand(interactive);
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      @Override
86      protected SvnCommand getChangeLogCommand() {
87          return new SvnChangeLogCommand(interactive);
88      }
89  
90      /**
91       * {@inheritDoc}
92       */
93      @Override
94      protected SvnCommand getCheckInCommand() {
95          return new SvnCheckInCommand(interactive);
96      }
97  
98      /**
99       * {@inheritDoc}
100      */
101     @Override
102     protected SvnCommand getCheckOutCommand() {
103         return new SvnCheckOutCommand(interactive);
104     }
105 
106     /**
107      * {@inheritDoc}
108      */
109     @Override
110     protected SvnCommand getDiffCommand() {
111         return new SvnDiffCommand(interactive);
112     }
113 
114     /**
115      * {@inheritDoc}
116      */
117     @Override
118     protected SvnCommand getExportCommand() {
119         return new SvnExeExportCommand(interactive);
120     }
121 
122     /**
123      * {@inheritDoc}
124      */
125     @Override
126     protected SvnCommand getRemoveCommand() {
127         return new SvnRemoveCommand();
128     }
129 
130     /**
131      * {@inheritDoc}
132      */
133     @Override
134     protected SvnCommand getStatusCommand() {
135         return new SvnStatusCommand(interactive);
136     }
137 
138     /**
139      * {@inheritDoc}
140      */
141     @Override
142     protected SvnCommand getTagCommand() {
143         return new SvnTagCommand(interactive);
144     }
145 
146     /**
147      * {@inheritDoc}
148      */
149     @Override
150     protected SvnCommand getUntagCommand() {
151         return new SvnUntagCommand(interactive);
152     }
153 
154     /**
155      * {@inheritDoc}
156      */
157     @Override
158     protected SvnCommand getUpdateCommand() {
159         return new SvnUpdateCommand(interactive);
160     }
161 
162     /**
163      * {@inheritDoc}
164      */
165     @Override
166     protected SvnCommand getListCommand() {
167         return new SvnListCommand(interactive);
168     }
169 
170     @Override
171     public SvnCommand getInfoCommand() {
172         return new SvnInfoCommand(interactive);
173     }
174 
175     /**
176      * {@inheritDoc}
177      */
178     @Override
179     protected SvnCommand getBlameCommand() {
180         return new SvnBlameCommand(interactive);
181     }
182 
183     /**
184      * {@inheritDoc}
185      */
186     @Override
187     protected SvnCommand getMkdirCommand() {
188         return new SvnMkdirCommand(interactive);
189     }
190 
191     /**
192      * {@inheritDoc}
193      */
194     @Override
195     protected String getRepositoryURL(File path) throws ScmException {
196         // Note: I need to supply just 1 absolute path, but ScmFileSet won't let me without
197         // a basedir (which isn't used here anyway), so use a dummy file.
198         SvnInfoCommand infoCmd = (SvnInfoCommand) getInfoCommand();
199 
200         InfoScmResult result = infoCmd.executeInfoCommand(null, new ScmFileSet(new File(""), path), null, false, null);
201 
202         if (result.getInfoItems().size() != 1) {
203             throw new ScmRepositoryException("Cannot find URL: "
204                     + (result.getInfoItems().size() == 0 ? "no" : "multiple") + " items returned by the info command");
205         }
206 
207         return result.getInfoItems().get(0).getURL();
208     }
209 
210     @Override
211     public RemoteInfoScmResult remoteInfo(
212             ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
213         SvnRemoteInfoCommand svnRemoteInfoCommand = new SvnRemoteInfoCommand(interactive);
214         return svnRemoteInfoCommand.executeRemoteInfoCommand(repository, fileSet, parameters);
215     }
216 
217     @Override
218     public boolean remoteUrlExist(ScmProviderRepository repository, CommandParameters parameters) throws ScmException {
219         SvnRemoteInfoCommand svnRemoteInfoCommand = new SvnRemoteInfoCommand(interactive);
220         return svnRemoteInfoCommand.remoteUrlExist(repository, parameters);
221     }
222 }