mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix line breaks in html notification
Let MultiRootMessage support <br/> line breaks. Actually use "<br/>\n" as html separator to make message look nicer even when not rendered (e.g. in tests).
This commit is contained in:
@@ -22,9 +22,10 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.vcsUtil.VcsImplUtil.getShortVcsRootName
|
||||
|
||||
class MultiRootMessage(private val myProject: Project, private val myAllRoots: Collection<VirtualFile>) {
|
||||
class MultiRootMessage(private val myProject: Project, private val myAllRoots: Collection<VirtualFile>, html: Boolean) {
|
||||
private val LOG = Logger.getInstance(MultiRootMessage::class.java)
|
||||
private val myMessages = ContainerUtil.newLinkedHashMap<VirtualFile, String>()
|
||||
private val myLineSeparator = if (html) "<br/>\n" else "\n"
|
||||
|
||||
fun append(root: VirtualFile, message: String): MultiRootMessage {
|
||||
if (!myAllRoots.contains(root)) {
|
||||
@@ -47,7 +48,7 @@ class MultiRootMessage(private val myProject: Project, private val myAllRoots: C
|
||||
}
|
||||
val grouped = myMessages.keys.groupBy { myMessages[it]!!.trim() }
|
||||
if (grouped.size == 1 && myAllRoots.size == myMessages.size) return myMessages.values.first()
|
||||
return grouped.keys.joinToString("\n") {
|
||||
return grouped.keys.joinToString(myLineSeparator) {
|
||||
val shortRootNames = grouped[it]!!.map { getShortVcsRootName(myProject, it) }
|
||||
"$it in ${joinWithAnd(shortRootNames, 5)}" }
|
||||
}
|
||||
|
||||
@@ -39,14 +39,14 @@ class MultiRootMessageTest {
|
||||
@Test
|
||||
fun `test empty message`() {
|
||||
val root = myProject.baseDir
|
||||
val multiRootMessage = MultiRootMessage(myProject, setOf(root))
|
||||
val multiRootMessage = multiRootMessage(root)
|
||||
assertTrue(multiRootMessage.asString().isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test single repository`() {
|
||||
val root = myProject.baseDir
|
||||
val multiRootMessage = MultiRootMessage(myProject, setOf(root))
|
||||
val multiRootMessage = multiRootMessage(root)
|
||||
multiRootMessage.append(root, "Pruned obsolete remote references: origin/fix1, origin/fix2")
|
||||
assertEquals("Pruned obsolete remote references: origin/fix1, origin/fix2", multiRootMessage.asString())
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class MultiRootMessageTest {
|
||||
val idea = myProject.baseDir
|
||||
val community = createSubDir(idea, "community")
|
||||
|
||||
val multiRootMessage = MultiRootMessage(myProject, setOf(idea, community))
|
||||
val multiRootMessage = multiRootMessage(idea, community)
|
||||
multiRootMessage.append(idea, "Pruned obsolete remote references: origin/fix1, origin/fix2")
|
||||
assertEquals("Pruned obsolete remote references: origin/fix1, origin/fix2 in idea", multiRootMessage.asString())
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class MultiRootMessageTest {
|
||||
val idea = myProject.baseDir
|
||||
val community = createSubDir(idea, "community")
|
||||
|
||||
val multiRootMessage = MultiRootMessage(myProject, setOf(idea, community))
|
||||
val multiRootMessage = multiRootMessage(idea, community)
|
||||
multiRootMessage.append(idea, "Pruned obsolete remote references: origin/fix1, origin/fix2")
|
||||
multiRootMessage.append(community, "Pruned obsolete remote references: origin/fix1, origin/fix2")
|
||||
assertEquals("Pruned obsolete remote references: origin/fix1, origin/fix2", multiRootMessage.asString())
|
||||
@@ -77,7 +77,7 @@ class MultiRootMessageTest {
|
||||
val idea = myProject.baseDir
|
||||
val community = createSubDir(idea, "community")
|
||||
|
||||
val multiRootMessage = MultiRootMessage(myProject, setOf(idea, community))
|
||||
val multiRootMessage = multiRootMessage(idea, community)
|
||||
multiRootMessage.append(idea, "Pruned obsolete remote references: origin/fix1, origin/fix2")
|
||||
multiRootMessage.append(community, "Pruned obsolete remote references: origin/fix3")
|
||||
assertEquals(
|
||||
@@ -88,24 +88,26 @@ class MultiRootMessageTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test three roots with same message, and one root with another`() {
|
||||
fun `test html message for three roots with same message, and one root with another`() {
|
||||
val idea = myProject.baseDir
|
||||
val community = createSubDir(idea, "community")
|
||||
val contrib = createSubDir(idea, "contrib")
|
||||
val android = createSubDir(community, "android")
|
||||
|
||||
val multiRootMessage = MultiRootMessage(myProject, setOf(idea, community, contrib, android))
|
||||
val multiRootMessage = MultiRootMessage(myProject, setOf(idea, community, contrib, android), true)
|
||||
multiRootMessage.append(idea, "Pruned obsolete remote references: origin/fix1, origin/fix2")
|
||||
multiRootMessage.append(community, "Pruned obsolete remote references: origin/fix3")
|
||||
multiRootMessage.append(contrib, "Pruned obsolete remote references: origin/fix3")
|
||||
multiRootMessage.append(android, "Pruned obsolete remote references: origin/fix3")
|
||||
assertEquals(
|
||||
"""
|
||||
Pruned obsolete remote references: origin/fix1, origin/fix2 in idea
|
||||
Pruned obsolete remote references: origin/fix1, origin/fix2 in idea<br/>
|
||||
Pruned obsolete remote references: origin/fix3 in community, contrib and community${File.separator}android
|
||||
""".trimIndent(), multiRootMessage.asString())
|
||||
}
|
||||
|
||||
private fun multiRootMessage(vararg roots : VirtualFile) = MultiRootMessage(myProject, roots.asList(), false)
|
||||
|
||||
private fun createSubDir(parent: VirtualFile, name: String): VirtualFile {
|
||||
val vf = MockVirtualFile(true, name)
|
||||
vf.parent = parent
|
||||
|
||||
@@ -256,7 +256,7 @@ public class GitFetcher {
|
||||
*/
|
||||
public boolean fetchRootsAndNotify(@NotNull Collection<GitRepository> roots,
|
||||
@Nullable String errorNotificationTitle, boolean notifySuccess) {
|
||||
MultiRootMessage additionalInfo = new MultiRootMessage(myProject, GitUtil.getRootsFromRepositories(roots));
|
||||
MultiRootMessage additionalInfo = new MultiRootMessage(myProject, GitUtil.getRootsFromRepositories(roots), true);
|
||||
for (GitRepository repository : roots) {
|
||||
LOG.info("fetching " + repository);
|
||||
GitFetchResult result = fetch(repository);
|
||||
|
||||
Reference in New Issue
Block a user