Mercurial > hg > mercurial
annotate mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ArchiveCommand.java @ 999:1b1cc811e1b6 Jaipur-2018.1.x
Jaipur-2018.1.x branch created
author | pavel.sher |
---|---|
date | Thu, 21 Jun 2018 17:37:32 +0200 |
parents | 7bf4d943d5bb |
children | 10dc26b32c35 |
rev | line source |
---|---|
732
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
1 /* |
976 | 2 * Copyright 2000-2018 JetBrains s.r.o. |
732
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
3 * |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
5 * you may not use this file except in compliance with the License. |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
6 * You may obtain a copy of the License at |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
7 * |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
9 * |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
10 * Unless required by applicable law or agreed to in writing, software |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
13 * See the License for the specific language governing permissions and |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
14 * limitations under the License. |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
15 */ |
31a1aca3305c
Update copyright
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
686
diff
changeset
|
16 |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
17 /* |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
18 * Licensed under the Apache License, Version 2.0 (the "License"); |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
19 * you may not use this file except in compliance with the License. |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
20 * You may obtain a copy of the License at |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
21 * |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
22 * http://www.apache.org/licenses/LICENSE-2.0 |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
23 * |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
24 * Unless required by applicable law or agreed to in writing, software |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
25 * distributed under the License is distributed on an "AS IS" BASIS, |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
26 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
27 * See the License for the specific language governing permissions and |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
28 * limitations under the License. |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
29 */ |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
30 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
31 |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
32 import jetbrains.buildServer.util.FileUtil; |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
33 import jetbrains.buildServer.vcs.VcsException; |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
34 import org.jetbrains.annotations.NotNull; |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
35 |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
36 import java.io.File; |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
37 import java.util.ArrayList; |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
38 import java.util.List; |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
39 |
781
3cd449e58f70
Hg arch and cat commands can require an authentication in case of largefiles
Dmitry Neverov <dmitry.neverov@gmail.com>
parents:
732
diff
changeset
|
40 public class ArchiveCommand extends AuthCommand { |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
41 private File myDestination; |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
42 private String myToId; |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
43 private String myType = "files"; |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
44 private List<String> myIncludeRules = new ArrayList<String>(); |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
45 |
480
efba721f9a1d
TW-23382 agent logs with info, server logs with debug
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
399
diff
changeset
|
46 public ArchiveCommand(@NotNull CommandSettings commandSettings, |
efba721f9a1d
TW-23382 agent logs with info, server logs with debug
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
399
diff
changeset
|
47 @NotNull String hgPath, |
efba721f9a1d
TW-23382 agent logs with info, server logs with debug
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
399
diff
changeset
|
48 @NotNull File workingDir, |
efba721f9a1d
TW-23382 agent logs with info, server logs with debug
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
399
diff
changeset
|
49 @NotNull AuthSettings authSettings) { |
efba721f9a1d
TW-23382 agent logs with info, server logs with debug
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
399
diff
changeset
|
50 super(commandSettings, hgPath, workingDir, authSettings); |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
51 } |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
52 |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
53 public ArchiveCommand destination(@NotNull File destination) { |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
54 myDestination = destination; |
399
45f25ca68312
Support local mirrors for subrepos
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
367
diff
changeset
|
55 return this; |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
56 } |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
57 |
399
45f25ca68312
Support local mirrors for subrepos
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
367
diff
changeset
|
58 public ArchiveCommand revision(@NotNull ChangeSet cset) { |
45f25ca68312
Support local mirrors for subrepos
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
367
diff
changeset
|
59 myToId = cset.getId(); |
45f25ca68312
Support local mirrors for subrepos
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
367
diff
changeset
|
60 return this; |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
61 } |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
62 |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
63 public ArchiveCommand type(@NotNull String type) { |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
64 myType = type; |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
65 return this; |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
66 } |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
67 |
862
24a6ef9166ae
UP-1866 disable patterns in hg archive include rules
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
852
diff
changeset
|
68 public boolean addIncludePathRule(@NotNull String rule) { |
812 | 69 final MercurialCommandLine cmd = createCmd(); |
70 | |
862
24a6ef9166ae
UP-1866 disable patterns in hg archive include rules
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
852
diff
changeset
|
71 String pathRule = "path:" + rule; |
826 | 72 final int cmdSize = cmd.getCommandLineLength(); |
862
24a6ef9166ae
UP-1866 disable patterns in hg archive include rules
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
852
diff
changeset
|
73 if (cmdSize + pathRule.length() + 3 + (myIncludeRules.isEmpty() ? 0 : "-I ".length()) > myCommandSettings.getMaxCommandLineSize()) { |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
74 return false; |
812 | 75 } |
76 | |
862
24a6ef9166ae
UP-1866 disable patterns in hg archive include rules
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
852
diff
changeset
|
77 myIncludeRules.add(pathRule); |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
78 return true; |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
79 } |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
80 |
399
45f25ca68312
Support local mirrors for subrepos
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
367
diff
changeset
|
81 public void call() throws VcsException { |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
82 if (myDestination == null) |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
83 throw new IllegalStateException("Destination dir must be specified"); |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
84 MercurialCommandLine cli = createCmd(); |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
85 |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
86 runCommand(cli, myCommandSettings.setFailWhenStderrNotEmpty(true)); |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
87 deleteHgArchival(); |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
88 } |
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
89 |
810 | 90 @NotNull |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
91 private MercurialCommandLine createCmd() { |
810 | 92 final MercurialCommandLine cli = createCommandLine(); |
93 | |
781
3cd449e58f70
Hg arch and cat commands can require an authentication in case of largefiles
Dmitry Neverov <dmitry.neverov@gmail.com>
parents:
732
diff
changeset
|
94 addHttpAuthParams(cli); |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
95 |
818 | 96 cli.addParameter("archive"); |
97 cli.addParameter("-t"); | |
98 cli.addParameter(myType); | |
99 cli.addParameter("-r"); | |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
100 |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
101 if (myToId != null) { |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
102 cli.addParameter(myToId); |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
103 } else { |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
104 cli.addParameter("tip"); |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
105 } |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
106 |
818 | 107 for (String include : myIncludeRules) { |
108 cli.addParameter("-I"); | |
109 cli.addParameter(include); | |
110 } | |
111 cli.addParameter(myDestination.getAbsolutePath()); | |
112 | |
113 return cli; | |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
114 } |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
115 |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
116 /** |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
117 * hg archive generates .hg_archival.txt, delete it since original repository do not have such file |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
118 */ |
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
119 private void deleteHgArchival() { |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
120 if (myDestination == null) |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
121 throw new IllegalStateException("Destination dir must be specified"); |
686
1efd1846f00a
Add an option for using tar archive for building a full patch
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
480
diff
changeset
|
122 File hg_arhival = new File(myDestination, ".hg_archival.txt"); |
932
448ef0521954
TW-42308 delete file only if it exists to avoid warns in log
Dmitry Neverov <dmitry.neverov@gmail.com>
parents:
890
diff
changeset
|
123 if (hg_arhival.exists()) |
448ef0521954
TW-42308 delete file only if it exists to avoid warns in log
Dmitry Neverov <dmitry.neverov@gmail.com>
parents:
890
diff
changeset
|
124 FileUtil.delete(hg_arhival); |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
125 } |
890
771ae1b2f0b1
More command descriptions
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
862
diff
changeset
|
126 |
771ae1b2f0b1
More command descriptions
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
862
diff
changeset
|
127 @NotNull |
771ae1b2f0b1
More command descriptions
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
862
diff
changeset
|
128 @Override |
771ae1b2f0b1
More command descriptions
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
862
diff
changeset
|
129 protected String getDescription() { |
771ae1b2f0b1
More command descriptions
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
862
diff
changeset
|
130 return "hg archive -r " + (myToId != null ? myToId : "tip"); |
771ae1b2f0b1
More command descriptions
Dmitry Neverov <dmitry.neverov@jetbrains.com>
parents:
862
diff
changeset
|
131 } |
334
01648f900892
TW-16796, TW-16335 use hg archive to build full patch
alex.davies
parents:
diff
changeset
|
132 } |