--- /dev/null
+/*
+ * Copyright 2000-2016 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;
+
+import com.intellij.openapi.vcs.FilePath;
+import com.intellij.openapi.vcs.changes.ContentRevision;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class SvnBaseContentRevision implements ContentRevision {
+
+ @NotNull protected final SvnVcs myVcs;
+ @NotNull protected final FilePath myFile;
+
+ protected SvnBaseContentRevision(@NotNull SvnVcs vcs, @NotNull FilePath file) {
+ myVcs = vcs;
+ myFile = file;
+ }
+
+ @NotNull
+ @Override
+ public FilePath getFile() {
+ return myFile;
+ }
+}
package org.jetbrains.idea.svn;
import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.util.Throwable2Computable;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.VcsKey;
import java.io.File;
import java.io.IOException;
-/**
- * @author yole
-*/
-public class SvnContentRevision implements ByteBackedContentRevision, MarkerVcsContentRevision {
+public class SvnContentRevision extends SvnBaseContentRevision implements ByteBackedContentRevision, MarkerVcsContentRevision {
- @NotNull private final SvnVcs myVcs;
- @NotNull protected final FilePath myFile;
@NotNull private final SVNRevision myRevision;
/**
* this flag is necessary since SVN would not do remote request only if constant SVNRevision.BASE
private final boolean myUseBaseRevision;
protected SvnContentRevision(@NotNull SvnVcs vcs, @NotNull FilePath file, @NotNull SVNRevision revision, boolean useBaseRevision) {
- myVcs = vcs;
+ super(vcs, file);
myRevision = revision;
myUseBaseRevision = useBaseRevision;
- myFile = file;
}
@NotNull
}).getSecond();
} else {
return ContentRevisionCache.getOrLoadAsBytes(myVcs.getProject(), myFile, getRevisionNumber(), myVcs.getKeyInstanceMethod(),
- ContentRevisionCache.UniqueType.REPOSITORY_CONTENT,
- new Throwable2Computable<byte[], VcsException, IOException>() {
- @Override
- public byte[] compute() throws VcsException, IOException {
- return getUpToDateBinaryContent();
- }
- });
+ ContentRevisionCache.UniqueType.REPOSITORY_CONTENT, () -> getUpToDateBinaryContent());
}
}
catch (IOException e) {
}
@NotNull
- public FilePath getFile() {
- return myFile;
- }
-
- @NotNull
public VcsRevisionNumber getRevisionNumber() {
return new SvnRevisionNumber(myRevision);
}
private SvnLazyPropertyContentRevision createPropertyRevision(@NotNull FilePath filePath,
@Nullable ContentRevision revision,
@NotNull SVNURL url) {
- return revision == null ? null : new SvnLazyPropertyContentRevision(filePath, revision.getRevisionNumber(), myVcs.getProject(), url);
+ return revision == null ? null : new SvnLazyPropertyContentRevision(myVcs, filePath, revision.getRevisionNumber(), url);
}
@NotNull
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressManager;
-import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.VcsKey;
-import com.intellij.openapi.vcs.changes.ContentRevision;
import com.intellij.openapi.vcs.changes.MarkerVcsContentRevision;
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.jetbrains.idea.svn.SvnBaseContentRevision;
import org.jetbrains.idea.svn.SvnBundle;
import org.jetbrains.idea.svn.SvnRevisionNumber;
import org.jetbrains.idea.svn.SvnVcs;
import java.util.List;
-/**
- * Created with IntelliJ IDEA.
- * User: Irina.Chernushina
- * Date: 2/22/12
- * Time: 10:28 AM
- */
-public class SvnLazyPropertyContentRevision implements ContentRevision, MarkerVcsContentRevision, PropertyRevision {
- private final FilePath myPath;
+public class SvnLazyPropertyContentRevision extends SvnBaseContentRevision implements MarkerVcsContentRevision, PropertyRevision {
private final VcsRevisionNumber myNumber;
- private final Project myProject;
private final SVNURL myUrl;
private List<PropertyData> myContent;
- public SvnLazyPropertyContentRevision(FilePath path, VcsRevisionNumber number, Project project, SVNURL url) {
- myPath = path;
+ public SvnLazyPropertyContentRevision(@NotNull SvnVcs vcs, @NotNull FilePath file, VcsRevisionNumber number, SVNURL url) {
+ super(vcs, file);
myNumber = number;
- myProject = project;
myUrl = url;
}
}
private List<PropertyData> loadContent() throws VcsException {
- final SvnVcs vcs = SvnVcs.getInstance(myProject);
final Ref<List<PropertyData>> ref = new Ref<>();
final Ref<VcsException> exceptionRef = new Ref<>();
- final Runnable runnable = new Runnable() {
- @Override
- public void run() {
- try {
- ref.set(AbstractShowPropertiesDiffAction.getPropertyList(vcs, myUrl, ((SvnRevisionNumber)myNumber).getRevision()));
- }
- catch (VcsException e) {
- exceptionRef.set(e);
- }
+ final Runnable runnable = () -> {
+ try {
+ ref.set(AbstractShowPropertiesDiffAction.getPropertyList(myVcs, myUrl, ((SvnRevisionNumber)myNumber).getRevision()));
+ }
+ catch (VcsException e) {
+ exceptionRef.set(e);
}
};
if (ApplicationManager.getApplication().isDispatchThread()) {
- final boolean completed = ProgressManager.getInstance()
- .runProcessWithProgressSynchronously(runnable, SvnBundle.message("progress.title.loading.file.properties"), true, myProject);
+ boolean completed = ProgressManager.getInstance()
+ .runProcessWithProgressSynchronously(runnable, SvnBundle.message("progress.title.loading.file.properties"), true,
+ myVcs.getProject());
if (!completed) {
throw new VcsException("Properties load for revision " + getRevisionNumber().asString() + " was canceled.");
}
@NotNull
@Override
- public FilePath getFile() {
- return myPath;
- }
-
- @NotNull
- @Override
public VcsRevisionNumber getRevisionNumber() {
return myNumber;
}
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
-import com.intellij.openapi.util.Throwable2Computable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.vcsUtil.VcsUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.idea.svn.SvnBundle;
-import org.jetbrains.idea.svn.SvnRevisionNumber;
-import org.jetbrains.idea.svn.SvnUtil;
-import org.jetbrains.idea.svn.SvnVcs;
+import org.jetbrains.idea.svn.*;
import org.jetbrains.idea.svn.commandLine.SvnBindException;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc2.SvnTarget;
import java.io.IOException;
import java.io.OutputStream;
-public class SvnRepositoryContentRevision implements ByteBackedContentRevision, MarkerVcsContentRevision {
+import static com.intellij.util.ObjectUtils.notNull;
+
+public class SvnRepositoryContentRevision extends SvnBaseContentRevision implements ByteBackedContentRevision, MarkerVcsContentRevision {
- @NotNull private final SvnVcs myVcs;
@NotNull private final String myPath;
- @NotNull private final FilePath myFilePath;
private final long myRevision;
public SvnRepositoryContentRevision(@NotNull SvnVcs vcs, @NotNull FilePath remotePath, @Nullable FilePath localPath, long revision) {
- myVcs = vcs;
+ super(vcs, notNull(localPath, remotePath));
myPath = FileUtil.toSystemIndependentName(remotePath.getPath());
- myFilePath = localPath != null ? localPath : remotePath;
myRevision = revision;
}
@NotNull
public String getContent() throws VcsException {
- return ContentRevisionCache.getAsString(getContentAsBytes(), myFilePath, null);
+ return ContentRevisionCache.getAsString(getContentAsBytes(), myFile, null);
}
@NotNull
@Override
public byte[] getContentAsBytes() throws VcsException {
try {
- if (myFilePath.getVirtualFile() == null) {
- LocalFileSystem.getInstance().refreshAndFindFileByPath(myFilePath.getPath());
+ if (myFile.getVirtualFile() == null) {
+ LocalFileSystem.getInstance().refreshAndFindFileByPath(myFile.getPath());
}
- return ContentRevisionCache.getOrLoadAsBytes(myVcs.getProject(), myFilePath, getRevisionNumber(), myVcs.getKeyInstanceMethod(),
- ContentRevisionCache.UniqueType.REPOSITORY_CONTENT,
- new Throwable2Computable<byte[], VcsException, IOException>() {
- @Override
- public byte[] compute() throws VcsException, IOException {
- return loadContent().toByteArray();
- }
- });
+ return ContentRevisionCache.getOrLoadAsBytes(myVcs.getProject(), myFile, getRevisionNumber(), myVcs.getKeyInstanceMethod(),
+ ContentRevisionCache.UniqueType.REPOSITORY_CONTENT, () -> loadContent().toByteArray());
}
catch (IOException e) {
throw new VcsException(e);
}
@NotNull
- public FilePath getFile() {
- return myFilePath;
- }
-
- @NotNull
public SvnRevisionNumber getRevisionNumber() {
return new SvnRevisionNumber(SVNRevision.create(myRevision));
}
@Override
public String toString() {
- return myFilePath.getIOFile() + "#" + myRevision;
+ return myFile.getIOFile() + "#" + myRevision;
}
private class ContentLoader implements Runnable {