1 package org.apache.maven.scm.provider.accurev.command.login;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.CommandParameters;
23 import org.apache.maven.scm.ScmException;
24 import org.apache.maven.scm.ScmFileSet;
25 import org.apache.maven.scm.ScmResult;
26 import org.apache.maven.scm.command.login.LoginScmResult;
27 import org.apache.maven.scm.log.ScmLogger;
28 import org.apache.maven.scm.provider.ScmProviderRepository;
29 import org.apache.maven.scm.provider.accurev.AccuRev;
30 import org.apache.maven.scm.provider.accurev.AccuRevException;
31 import org.apache.maven.scm.provider.accurev.AccuRevInfo;
32 import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository;
33 import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommand;
34
35
36
37
38 public class AccuRevLoginCommand
39 extends AbstractAccuRevCommand
40 {
41
42 public AccuRevLoginCommand( ScmLogger logger )
43 {
44 super( logger );
45 }
46
47 @Override
48 protected ScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet,
49 CommandParameters parameters )
50 throws ScmException, AccuRevException
51 {
52 boolean result = false;
53 AccuRev accurev = repository.getAccuRev();
54 AccuRevInfo info = accurev.info( null );
55
56 String providerMessage = "";
57 if ( info == null )
58 {
59 providerMessage = "Unable to retrieve accurev info";
60 }
61 else if ( repository.getUser() != null )
62 {
63
64 result = repository.getUser().equals( info.getUser() );
65 if ( result )
66 {
67 providerMessage = "Skipping login - already logged in as " + repository.getUser();
68 }
69 else
70 {
71 result = accurev.login( repository.getUser(), repository.getPassword() );
72 providerMessage = ( result ? "Success" : "Failure" ) + " logging in as " + repository.getUser();
73 }
74 }
75 else
76 {
77 result = info.isLoggedIn();
78 providerMessage = result ? ( "Logged in externally as " + info.getUser() ) : "Not logged in";
79 }
80
81 getLogger().debug( providerMessage );
82 return new LoginScmResult( accurev.getCommandLines(), providerMessage, accurev.getErrorOutput(), result );
83
84 }
85
86 public LoginScmResult login( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
87 throws ScmException
88 {
89 return (LoginScmResult) execute( repository, fileSet, parameters );
90 }
91
92 }