1 | |
package org.apache.maven.scm.provider.cvslib.command; |
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.ScmException; |
23 | |
import org.apache.maven.scm.ScmFileSet; |
24 | |
import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository; |
25 | |
import org.apache.maven.scm.provider.cvslib.util.CvsUtil; |
26 | |
import org.apache.maven.scm.providers.cvslib.settings.Settings; |
27 | |
import org.codehaus.plexus.util.StringUtils; |
28 | |
import org.codehaus.plexus.util.cli.CommandLineException; |
29 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
30 | |
import org.codehaus.plexus.util.cli.Commandline; |
31 | |
|
32 | |
import java.io.File; |
33 | |
import java.util.Enumeration; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class CvsCommandUtils |
40 | |
{ |
41 | |
private CvsCommandUtils() |
42 | 0 | { |
43 | |
|
44 | 0 | } |
45 | |
|
46 | |
public static boolean isCvsNT() |
47 | |
throws ScmException |
48 | |
{ |
49 | 0 | Commandline cl = new Commandline(); |
50 | |
|
51 | 0 | cl.setExecutable( "cvs" ); |
52 | |
|
53 | 0 | cl.createArg().setValue( "-v" ); |
54 | |
|
55 | 0 | CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); |
56 | |
|
57 | 0 | CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
58 | |
|
59 | |
try |
60 | |
{ |
61 | 0 | CommandLineUtils.executeCommandLine( cl, stdout, stderr ); |
62 | |
} |
63 | 0 | catch ( CommandLineException e ) |
64 | |
{ |
65 | 0 | throw new ScmException( "Error while executing command.", e ); |
66 | 0 | } |
67 | |
|
68 | 0 | return stdout.getOutput().indexOf( "CVSNT" ) >= 0; |
69 | |
} |
70 | |
|
71 | |
public static Commandline getBaseCommand( String commandName, CvsScmProviderRepository repo, ScmFileSet fileSet ) |
72 | |
{ |
73 | 0 | return getBaseCommand( commandName, repo, fileSet, null, true ); |
74 | |
} |
75 | |
|
76 | |
public static Commandline getBaseCommand( String commandName, CvsScmProviderRepository repo, ScmFileSet fileSet, |
77 | |
boolean addCvsRoot ) |
78 | |
{ |
79 | 0 | return getBaseCommand( commandName, repo, fileSet, null, addCvsRoot ); |
80 | |
} |
81 | |
|
82 | |
public static Commandline getBaseCommand( String commandName, CvsScmProviderRepository repo, ScmFileSet fileSet, |
83 | |
String options ) |
84 | |
{ |
85 | 0 | return getBaseCommand( commandName, repo, fileSet, options, true ); |
86 | |
} |
87 | |
|
88 | |
public static Commandline getBaseCommand( String commandName, CvsScmProviderRepository repo, ScmFileSet fileSet, |
89 | |
String options, boolean addCvsRoot ) |
90 | |
{ |
91 | 0 | Settings settings = CvsUtil.getSettings(); |
92 | |
|
93 | 0 | Commandline cl = new Commandline(); |
94 | |
|
95 | 0 | cl.setExecutable( "cvs" ); |
96 | |
|
97 | 0 | cl.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() ); |
98 | |
|
99 | 0 | if ( Boolean.getBoolean( "maven.scm.cvs.use_compression" ) ) |
100 | |
{ |
101 | 0 | cl.createArg().setValue( "-z" + System.getProperty( "maven.scm.cvs.compression_level", "3" ) ); |
102 | |
} |
103 | 0 | else if ( settings.getCompressionLevel() > 0 ) |
104 | |
{ |
105 | 0 | cl.createArg().setValue( "-z" + settings.getCompressionLevel() ); |
106 | |
} |
107 | |
|
108 | 0 | if ( !settings.isUseCvsrc() ) |
109 | |
{ |
110 | 0 | cl.createArg().setValue( "-f" ); |
111 | |
} |
112 | |
|
113 | 0 | if ( settings.isTraceCvsCommand() ) |
114 | |
{ |
115 | 0 | cl.createArg().setValue( "-t" ); |
116 | |
} |
117 | |
|
118 | 0 | if ( !StringUtils.isEmpty( settings.getTemporaryFilesDirectory() ) ) |
119 | |
{ |
120 | 0 | File tempDir = new File( settings.getTemporaryFilesDirectory() ); |
121 | |
|
122 | 0 | if ( !tempDir.exists() ) |
123 | |
{ |
124 | 0 | tempDir.mkdirs(); |
125 | |
} |
126 | |
|
127 | 0 | cl.createArg().setValue( "-T" ); |
128 | |
|
129 | 0 | cl.createArg().setValue( tempDir.getAbsolutePath() ); |
130 | |
} |
131 | |
|
132 | 0 | if ( settings.getCvsVariables().size() > 0 ) |
133 | |
{ |
134 | 0 | for ( Enumeration<?> e = settings.getCvsVariables().propertyNames(); e.hasMoreElements(); ) |
135 | |
{ |
136 | 0 | String key = (String) e.nextElement(); |
137 | 0 | String value = settings.getCvsVariables().getProperty( key ); |
138 | 0 | cl.createArg().setValue( "-s" ); |
139 | 0 | cl.createArg().setValue( key + "=" + value ); |
140 | 0 | } |
141 | |
} |
142 | |
|
143 | 0 | if ( addCvsRoot ) |
144 | |
{ |
145 | 0 | cl.createArg().setValue( "-d" ); |
146 | |
|
147 | 0 | cl.createArg().setValue( repo.getCvsRoot() ); |
148 | |
} |
149 | |
|
150 | 0 | cl.createArg().setLine( options ); |
151 | |
|
152 | 0 | cl.createArg().setValue( "-q" ); |
153 | |
|
154 | 0 | cl.createArg().setValue( commandName ); |
155 | |
|
156 | 0 | return cl; |
157 | |
} |
158 | |
} |