From 4af031a4c423dcc2c9dbce427a5de489229d95ce Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Tue, 18 Feb 2014 18:09:54 +0400 Subject: [PATCH] svn: Refactored SvnCheckinEnvironment - not null, code simplifications, methods extracted, warnings fixes --- .../src/org/jetbrains/idea/svn/SvnUtil.java | 11 ++ .../svn/checkin/SvnCheckinEnvironment.java | 101 ++++++++---------- 2 files changed, 54 insertions(+), 58 deletions(-) diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnUtil.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnUtil.java index acb910880c61..3b8bb4ac57cf 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnUtil.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnUtil.java @@ -39,6 +39,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.wm.impl.status.StatusBarUtil; import com.intellij.util.ArrayUtil; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Convertor; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NonNls; @@ -105,6 +106,16 @@ public class SvnUtil { return info != null; } + public static List toFiles(Iterable paths) { + List result = ContainerUtil.newArrayList(); + + for (String path : paths) { + result.add(new File(path)); + } + + return result; + } + public static Collection crawlWCRoots(final Project project, File path, SvnWCRootCrawler callback, ProgressIndicator progress) { final LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile vf = lfs.findFileByIoFile(path); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java index c296cb25b8b7..6e5f5e2938c9 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java @@ -33,15 +33,13 @@ import com.intellij.openapi.vcs.changes.ChangeList; import com.intellij.openapi.vcs.changes.ChangesUtil; import com.intellij.openapi.vcs.changes.ContentRevision; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; -import com.intellij.openapi.vcs.ui.Refreshable; import com.intellij.openapi.vcs.ui.RefreshableOnComponent; import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; -import com.intellij.util.ArrayUtil; -import com.intellij.util.FunctionUtil; -import com.intellij.util.NullableFunction; -import com.intellij.util.PairConsumer; +import com.intellij.util.*; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Convertor; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NonNls; @@ -60,16 +58,17 @@ import java.util.*; import java.util.List; public class SvnCheckinEnvironment implements CheckinEnvironment { - private static final Logger LOG = Logger.getInstance("#org.jetbrains.idea.svn.checkin.SvnCheckinEnvironment"); - private final SvnVcs mySvnVcs; - public SvnCheckinEnvironment(SvnVcs svnVcs) { + private static final Logger LOG = Logger.getInstance(SvnCheckinEnvironment.class); + @NotNull private final SvnVcs mySvnVcs; + + public SvnCheckinEnvironment(@NotNull SvnVcs svnVcs) { mySvnVcs = svnVcs; } public RefreshableOnComponent createAdditionalOptionsPanel(CheckinProjectPanel panel, PairConsumer additionalDataConsumer) { - return new KeepLocksComponent(panel); + return new KeepLocksComponent(); } @Nullable @@ -83,8 +82,7 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { } - private List commitInt(List paths, final String comment, final boolean force, final boolean recursive, - final Set feedback) { + private List commitInt(List paths, final String comment, final boolean force, final Set feedback) { final List exception = new ArrayList(); final List committables = getCommitables(paths); @@ -143,7 +141,6 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { else if (ApplicationManager.getApplication().isDispatchThread()) { ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { public void run() { - ProgressIndicator p = ProgressManager.getInstance().getProgressIndicator(); doCommit(committables, committer, comment, force, exception, feedback); } }, SvnBundle.message("progress.title.commit"), false, mySvnVcs.getProject()); @@ -163,6 +160,7 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { String comment, boolean force, List exception, final Set feedback) { + //noinspection unchecked final MultiMap,File> map = SvnUtil.splitIntoRepositoriesMap(mySvnVcs, committables, Convertor.SELF); for (Map.Entry, Collection> entry : map.entrySet()) { doCommitOneRepo(entry.getValue(), committer, comment, force, exception, feedback, entry.getKey().getSecond(), entry.getKey().getFirst()); @@ -209,18 +207,17 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { } finally { if (commitPackets != null) { - for (int i = 0; i < commitPackets.length; i++) { - SVNCommitPacket commitPacket = commitPackets[i]; + for (SVNCommitPacket commitPacket : commitPackets) { try { commitPacket.dispose(); } catch (SVNException e) { - // + LOG.info(e); } } } } - final StringBuffer committedRevisions = new StringBuffer(); + final StringBuilder committedRevisions = new StringBuilder(); for (SVNCommitInfo result : results) { if (result.getErrorMessage() != null) { exception.add(new VcsException(result.getErrorMessage().getFullMessage())); @@ -366,7 +363,8 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { } } - private SVNStatus getStatus(File file) { + @Nullable + private SVNStatus getStatus(@NotNull File file) { SVNStatus result = null; WorkingCopyFormat format = mySvnVcs.getWorkingCopyFormat(file); @@ -388,26 +386,22 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { return new SvnCommandLineStatusClient(mySvnVcs).doStatus(file, false); } - private static List collectPaths(final List changes) { + private static List collectPaths(@NotNull List changes) { // case sensitive.. - ArrayList result = new ArrayList(); + Set paths = ContainerUtil.newHashSet(); - final Set pathesSet = new HashSet(); for (Change change : changes) { - final ContentRevision beforeRevision = change.getBeforeRevision(); - final ContentRevision afterRevision = change.getAfterRevision(); - if (beforeRevision != null) { - pathesSet.add(beforeRevision.getFile().getIOFile().getAbsolutePath()); - } - if (afterRevision != null) { - pathesSet.add(afterRevision.getFile().getIOFile().getAbsolutePath()); - } + addPath(paths, change.getBeforeRevision()); + addPath(paths, change.getAfterRevision()); } - for (String s : pathesSet) { - result.add(new File(s)); + return SvnUtil.toFiles(paths); + } + + private static void addPath(@NotNull Collection paths, @Nullable ContentRevision revision) { + if (revision != null) { + paths.add(revision.getFile().getIOFile().getAbsolutePath()); } - return result; } public String getCheckinOperationName() { @@ -418,11 +412,11 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { String preparedComment, @NotNull NullableFunction parametersHolder, Set feedback) { - return commitInt(collectPaths(changes), preparedComment, true, false, feedback); + return commitInt(collectPaths(changes), preparedComment, true, feedback); } public List commit(List changes, String preparedComment) { - return commit(changes, preparedComment, FunctionUtil.nullConstant(), null); + return commit(changes, preparedComment, FunctionUtil.nullConstant(), null); } public List scheduleMissingFileForDeletion(List filePaths) { @@ -452,34 +446,25 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { public static List scheduleUnversionedFilesForAddition(@NotNull SvnVcs vcs, List files, final boolean recursive) { Collections.sort(files, FilePathComparator.getInstance()); - ISVNEventHandler eventHandler = new ISVNEventHandler() { + ISVNEventHandler eventHandler = new SvnProgressCanceller() { @Override public void handleEvent(SVNEvent event, double progress) throws SVNException { - final ProgressManager pm = ProgressManager.getInstance(); - final ProgressIndicator pi = pm.getProgressIndicator(); - // TODO: pi is null here when invoking "Add" action - if (pi != null && event.getFile() != null) { - File file = event.getFile(); - pi.setText(SvnBundle.message("progress.text2.adding", file.getName() + " (" + file.getParent() + ")")); - } - } + // TODO: indicator is null here when invoking "Add" action + ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); + File file = event.getFile(); - @Override - public void checkCancelled() throws SVNCancelException { - final ProgressManager pm = ProgressManager.getInstance(); - final ProgressIndicator pi = pm.getProgressIndicator(); - if (pi != null) { - if (pi.isCanceled()) throw new SVNCancelException(); + if (indicator != null && file != null) { + indicator.setText(SvnBundle.message("progress.text2.adding", file.getName() + " (" + file.getParent() + ")")); } } }; List exceptions = new ArrayList(); + SVNDepth depth = recursive ? SVNDepth.INFINITY : SVNDepth.EMPTY; for (VirtualFile file : files) { try { - File convertedFile = new File(FileUtil.toSystemDependentName(file.getPath())); - SVNDepth depth = recursive ? SVNDepth.INFINITY : SVNDepth.EMPTY; + File convertedFile = VfsUtilCore.virtualToIoFile(file); vcs.getFactory(convertedFile).createAddClient().add(convertedFile, depth, true, false, true, eventHandler); } @@ -501,12 +486,13 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { } private class KeepLocksComponent implements RefreshableOnComponent { - private final JCheckBox myKeepLocksBox; - private boolean myIsKeepLocks; - private final JPanel myPanel; - private final JCheckBox myAutoUpdate; - public KeepLocksComponent(final Refreshable panel) { + @NotNull private final JCheckBox myKeepLocksBox; + private boolean myIsKeepLocks; + @NotNull private final JPanel myPanel; + @NotNull private final JCheckBox myAutoUpdate; + + public KeepLocksComponent() { myPanel = new JPanel(new BorderLayout()); myKeepLocksBox = new JCheckBox(SvnBundle.message("checkbox.chckin.keep.files.locked")); @@ -522,11 +508,11 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { } public boolean isKeepLocks() { - return myKeepLocksBox != null && myKeepLocksBox.isSelected(); + return myKeepLocksBox.isSelected(); } public boolean isAutoUpdate() { - return myAutoUpdate != null && myAutoUpdate.isSelected(); + return myAutoUpdate.isSelected(); } public void refresh() { @@ -544,5 +530,4 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { myAutoUpdate.setSelected(configuration.isAutoUpdateAfterCommit()); } } - }