Search in sources :

Example 6 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiAttachment method getVersionList.

/**
 * Get the list of all versions up to the current. We assume versions go from 1.1 to the current one This allows not
 * to read the full archive file.
 *
 * @return a list of Version from 1.1 to the current version.
 * @throws XWikiException never happens.
 */
public List<Version> getVersionList() throws XWikiException {
    final List<Version> list = new ArrayList<Version>();
    final String currentVersion = this.version.toString();
    Version v = new Version("1.1");
    for (; ; ) {
        list.add(v);
        if (v.toString().equals(currentVersion)) {
            break;
        }
        v = v.next();
    }
    return list;
}
Also used : Version(org.suigeneris.jrcs.rcs.Version) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 7 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiAttachmentArchive method getVersions.

/**
 * @return an array of versions which are available for this attachment, ordered by version number descending.
 */
public Version[] getVersions() {
    final Archive rcsArchive = getRCSArchive();
    Version[] versions;
    if (rcsArchive != null) {
        final Node[] nodes = rcsArchive.changeLog();
        versions = new Version[nodes.length];
        for (int i = 0; i < nodes.length; i++) {
            versions[i] = nodes[i].getVersion();
        }
    } else {
        // No archive means there is no history and only the current version
        versions = new Version[] { this.attachment.getRCSVersion() };
    }
    return versions;
}
Also used : Archive(org.suigeneris.jrcs.rcs.Archive) Version(org.suigeneris.jrcs.rcs.Version) Node(org.suigeneris.jrcs.rcs.impl.Node)

Example 8 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiDocumentArchive method updateArchive.

/**
 * Update history with new document version.
 *
 * @param doc - document for this version
 * @param author - author of version
 * @param date - date of version
 * @param comment - version comment
 * @param version - preferably document version in history
 * @param context - used for loading nodes content
 * @throws XWikiException in any error
 */
public void updateArchive(XWikiDocument doc, String author, Date date, String comment, Version version, XWikiContext context) throws XWikiException {
    Version oldLatestVer = getLatestVersion();
    Version newVer = version;
    if (newVer == null || oldLatestVer != null && newVer.compareVersions(oldLatestVer) <= 0) {
        newVer = createNextVersion(oldLatestVer, doc.isMinorEdit());
    }
    XWikiRCSNodeInfo newNode = new XWikiRCSNodeInfo(new XWikiRCSNodeId(getId(), newVer));
    newNode.setAuthor(author);
    newNode.setComment(comment);
    newNode.setDate(date);
    XWikiRCSNodeContent newContent = makePatch(newNode, doc, context);
    updateNode(newNode);
    this.updatedNodeInfos.add(newNode);
    this.updatedNodeContents.add(newContent);
}
Also used : XWikiRCSNodeContent(com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent) Version(org.suigeneris.jrcs.rcs.Version) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) XWikiRCSNodeId(com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)

Example 9 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiAttachmentArchiveTest method getVersions.

@Test
public void getVersions() throws Exception {
    Archive rcsArchive = new Archive(new Object[] { "line" }, "file.txt", "5.2");
    rcsArchive.addRevision(new Object[] { "line modified" }, "");
    archive.setRCSArchive(rcsArchive);
    assertArrayEquals(new Version[] { new Version(5, 2), new Version(5, 3) }, archive.getVersions());
}
Also used : Archive(org.suigeneris.jrcs.rcs.Archive) Version(org.suigeneris.jrcs.rcs.Version) Test(org.junit.Test)

Example 10 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiAttachmentArchiveTest method getVersionsWhenThereIsNoHistory.

@Test
public void getVersionsWhenThereIsNoHistory() {
    Version version = new Version(3, 4);
    when(attachment.getRCSVersion()).thenReturn(version);
    assertArrayEquals(new Version[] { version }, archive.getVersions());
}
Also used : Version(org.suigeneris.jrcs.rcs.Version) Test(org.junit.Test)

Aggregations

Version (org.suigeneris.jrcs.rcs.Version)24 XWikiException (com.xpn.xwiki.XWikiException)7 ToString (org.suigeneris.jrcs.util.ToString)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 ArrayList (java.util.ArrayList)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)4 Date (java.util.Date)4 Archive (org.suigeneris.jrcs.rcs.Archive)4 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)3 XWikiDocumentArchive (com.xpn.xwiki.doc.XWikiDocumentArchive)3 XWikiRCSNodeContent (com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 Test (org.junit.Test)2 Document (com.xpn.xwiki.api.Document)1 XWikiAttachmentArchive (com.xpn.xwiki.doc.XWikiAttachmentArchive)1 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)1 IOException (java.io.IOException)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1