summaryrefslogtreecommitdiff
path: root/plugins/svn4idea/src/org/jetbrains/idea/svn/info/Info.java
blob: 96dbdbbcbc99689963754d41919efa05b4a60118 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.idea.svn.info;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.api.BaseNodeDescription;
import org.jetbrains.idea.svn.api.Depth;
import org.jetbrains.idea.svn.api.NodeKind;
import org.jetbrains.idea.svn.conflict.TreeConflictDescription;
import org.jetbrains.idea.svn.lock.Lock;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.util.SVNDate;
import org.tmatesoft.svn.core.wc.SVNInfo;
import org.tmatesoft.svn.core.wc.SVNRevision;

import java.io.File;
import java.util.Date;

/**
 * @author Konstantin Kolosovsky.
 */
public class Info extends BaseNodeDescription {

  private final File myFile;
  private final String myPath;
  private final SVNURL myURL;
  private final SVNRevision myRevision;
  private final SVNURL myRepositoryRootURL;
  private final String myRepositoryUUID;
  private final SVNRevision myCommittedRevision;
  private final Date myCommittedDate;
  private final String myAuthor;
  @Nullable private final Lock myLock;
  private final boolean myIsRemote;
  private final String mySchedule;
  private final SVNURL myCopyFromURL;
  private final SVNRevision myCopyFromRevision;
  private final File myConflictOldFile;
  private final File myConflictNewFile;
  private final File myConflictWrkFile;
  private final File myPropConflictFile;
  private final Depth myDepth;
  @Nullable private final TreeConflictDescription myTreeConflict;

  @NotNull
  public static Info create(@NotNull SVNInfo info) {
    Info result;

    if (info.isRemote()) {
      result = new Info(info.getPath(), info.getURL(), info.getRevision(), NodeKind.from(info.getKind()), info.getRepositoryUUID(),
                        info.getRepositoryRootURL(), info.getCommittedRevision().getNumber(), info.getCommittedDate(), info.getAuthor(),
                        Lock.create(info.getLock()), Depth.from(info.getDepth()));
    }
    else {
      result =
        new Info(info.getFile(), info.getURL(), info.getRepositoryRootURL(), info.getRevision().getNumber(), NodeKind.from(info.getKind()),
                 info.getRepositoryUUID(), info.getCommittedRevision().getNumber(), toString(info.getCommittedDate()), info.getAuthor(),
                 info.getSchedule(), info.getCopyFromURL(), info.getCopyFromRevision().getNumber(), getPath(info.getConflictOldFile()),
                 getPath(info.getConflictNewFile()), getPath(info.getConflictWrkFile()), getPath(info.getPropConflictFile()),
                 Lock.create(info.getLock()), Depth.from(info.getDepth()), TreeConflictDescription.create(info.getTreeConflict()));
    }

    return result;
  }

  public Info(File file,
              SVNURL url,
              SVNURL rootURL,
              long revision,
              @NotNull NodeKind kind,
              String uuid,
              long committedRevision,
              String committedDate,
              String author,
              String schedule,
              SVNURL copyFromURL,
              long copyFromRevision,
              String conflictOld,
              String conflictNew,
              String conflictWorking,
              String propRejectFile,
              @Nullable Lock lock,
              Depth depth,
              @Nullable TreeConflictDescription treeConflict) {
    super(kind);
    myFile = file;
    myURL = url;
    myRevision = SVNRevision.create(revision);
    myRepositoryUUID = uuid;
    myRepositoryRootURL = rootURL;

    myCommittedRevision = SVNRevision.create(committedRevision);
    myCommittedDate = committedDate != null ? SVNDate.parseDate(committedDate) : null;
    myAuthor = author;

    mySchedule = schedule;

    myCopyFromURL = copyFromURL;
    myCopyFromRevision = SVNRevision.create(copyFromRevision);

    myLock = lock;
    myTreeConflict = treeConflict;

    myConflictOldFile = resolveConflictFile(file, conflictOld);
    myConflictNewFile = resolveConflictFile(file, conflictNew);
    myConflictWrkFile = resolveConflictFile(file, conflictWorking);
    myPropConflictFile = resolveConflictFile(file, propRejectFile);

    myIsRemote = false;
    myDepth = depth;

    myPath = null;
  }

  public Info(String path,
              SVNURL url,
              SVNRevision revision,
              @NotNull NodeKind kind,
              String uuid,
              SVNURL reposRootURL,
              long committedRevision,
              Date date,
              String author,
              @Nullable Lock lock,
              Depth depth) {
    super(kind);
    myIsRemote = true;
    myURL = url;
    myRevision = revision;
    myRepositoryRootURL = reposRootURL;
    myRepositoryUUID = uuid;

    myCommittedDate = date;
    myCommittedRevision = SVNRevision.create(committedRevision);
    myAuthor = author;

    myLock = lock;
    myPath = path;
    myDepth = depth;

    myFile = null;
    mySchedule = null;
    myCopyFromURL = null;
    myCopyFromRevision = null;
    myConflictOldFile = null;
    myConflictNewFile = null;
    myConflictWrkFile = null;
    myPropConflictFile = null;
    myTreeConflict = null;
  }

  public String getAuthor() {
    return myAuthor;
  }

  public Date getCommittedDate() {
    return myCommittedDate;
  }

  public SVNRevision getCommittedRevision() {
    return myCommittedRevision;
  }

  public File getConflictNewFile() {
    return myConflictNewFile;
  }

  public File getConflictOldFile() {
    return myConflictOldFile;
  }

  public File getConflictWrkFile() {
    return myConflictWrkFile;
  }

  @Nullable
  public TreeConflictDescription getTreeConflict() {
    return myTreeConflict;
  }

  public SVNRevision getCopyFromRevision() {
    return myCopyFromRevision;
  }

  public SVNURL getCopyFromURL() {
    return myCopyFromURL;
  }

  public File getFile() {
    return myFile;
  }

  public boolean isRemote() {
    return myIsRemote;
  }

  @NotNull
  public NodeKind getKind() {
    return myKind;
  }

  @Nullable
  public Lock getLock() {
    return myLock;
  }

  public String getPath() {
    return myPath;
  }

  public File getPropConflictFile() {
    return myPropConflictFile;
  }

  public SVNURL getRepositoryRootURL() {
    return myRepositoryRootURL;
  }

  public String getRepositoryUUID() {
    return myRepositoryUUID;
  }

  public SVNRevision getRevision() {
    return myRevision;
  }

  public String getSchedule() {
    return mySchedule;
  }

  public SVNURL getURL() {
    return myURL;
  }

  public Depth getDepth() {
    return myDepth;
  }

  @Nullable
  private static File resolveConflictFile(@Nullable File file, @Nullable String path) {
    return file != null && path != null ? new File(file.getParentFile(), path) : null;
  }

  @Nullable
  private static String getPath(@Nullable File file) {
    return file != null ? file.getPath() : null;
  }

  @Nullable
  private static String toString(@Nullable Date date) {
    return date != null ? date.toString() : null;
  }
}