1 package org.apache.maven.scm.provider.cvslib.command.list;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Iterator;
24
25 import org.apache.maven.scm.ScmException;
26 import org.apache.maven.scm.ScmFileSet;
27 import org.apache.maven.scm.ScmVersion;
28 import org.apache.maven.scm.command.list.AbstractListCommand;
29 import org.apache.maven.scm.command.list.ListScmResult;
30 import org.apache.maven.scm.provider.ScmProviderRepository;
31 import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
32 import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
33 import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
34 import org.codehaus.plexus.util.Os;
35 import org.codehaus.plexus.util.StringUtils;
36 import org.codehaus.plexus.util.cli.Commandline;
37
38
39
40
41
42 public abstract class AbstractCvsListCommand
43 extends AbstractListCommand
44 implements CvsCommand
45 {
46
47 protected ListScmResult executeListCommand( ScmProviderRepository repo, ScmFileSet fileSet, boolean recursive,
48 ScmVersion version )
49 throws ScmException
50 {
51 for ( Boolean supD = rlsSUPPORTSD;; supD = Boolean.FALSE )
52 {
53 ListScmResult res = executeListCommand1( repo, fileSet, recursive, version, supD );
54 if ( res.isSuccess() || supD != null )
55 {
56 if ( rlsSUPPORTSD == null && res.isSuccess() )
57 {
58 rlsSUPPORTSD = supD == null ? Boolean.TRUE : supD;
59 }
60 return res;
61 }
62
63
64 }
65 }
66
67
68 private static Boolean rlsSUPPORTSD = Os.isFamily( Os.FAMILY_WINDOWS ) ? null : Boolean.TRUE;
69
70 private ListScmResult executeListCommand1( ScmProviderRepository repo, ScmFileSet fileSet, boolean recursive,
71 ScmVersion version, Boolean supD )
72 throws ScmException
73 {
74 CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
75
76 Commandline cl = CvsCommandUtils.getBaseCommand( "rls", repository, fileSet, "-n" );
77
78 if ( version != null && !StringUtils.isEmpty( version.getName() ) )
79 {
80 cl.createArg().setValue( "-r" );
81 cl.createArg().setValue( version.getName() );
82 }
83
84 if ( supD != Boolean.FALSE )
85 {
86 cl.createArg().setValue( "-d" );
87 }
88 cl.createArg().setValue( "-e" );
89
90 if ( recursive )
91 {
92 cl.createArg().setValue( "-R" );
93 }
94
95 String modulePref = repository.getModule();
96 if ( !StringUtils.isEmpty( modulePref ) )
97 {
98 modulePref += File.separatorChar;
99 }
100 else
101 {
102 modulePref = "";
103 }
104
105 for ( Iterator<File> it = fileSet.getFileList().iterator(); it.hasNext(); )
106 {
107 File target = (File) it.next();
108 String path = target.getPath();
109 if ( path.startsWith( "\\" ) )
110 {
111 path = path.substring( 1 );
112 }
113 path = modulePref + path;
114 cl.createArg().setValue( path );
115 }
116
117 if ( getLogger().isInfoEnabled() )
118 {
119 getLogger().info( "Executing: " + cl );
120 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
121 }
122
123 return executeCvsCommand( cl );
124 }
125
126 protected abstract ListScmResult executeCvsCommand( Commandline cl )
127 throws ScmException;
128 }