# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /data/work/src/netbeans-cm # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: versioning/apichanges.xml --- versioning/apichanges.xml Base (BASE) +++ versioning/apichanges.xml Locally Modified (Based On LOCAL) @@ -111,6 +111,20 @@ + Added VCSHistoryProvider.HistoryEntry.getParent() + + + + + + New method VCSHistoryProvider.HistoryEntry.getParent() to provide the + VCSHistoryProvider.HistoryEntry representing the parent of the given revision. + + + + + + Added VCSHistoryProvider Index: versioning/nbproject/project.properties --- versioning/nbproject/project.properties Base (BASE) +++ versioning/nbproject/project.properties Locally Modified (Based On LOCAL) @@ -44,7 +44,7 @@ javac.source=1.6 javadoc.name=Versioning -spec.version.base=1.29.0 +spec.version.base=1.30.0 is.autoload=true javadoc.arch=${basedir}/arch.xml Index: versioning/src/org/netbeans/modules/versioning/Accessor.java --- versioning/src/org/netbeans/modules/versioning/Accessor.java Base (BASE) +++ versioning/src/org/netbeans/modules/versioning/Accessor.java Locally Modified (Based On LOCAL) @@ -45,6 +45,8 @@ import org.netbeans.modules.versioning.spi.VCSContext; import org.netbeans.modules.versioning.spi.VCSHistoryProvider; +import org.netbeans.modules.versioning.spi.VCSHistoryProvider.HistoryEntry; +import org.netbeans.modules.versioning.spi.VCSHistoryProvider.ParentProvider; /** @@ -72,4 +74,5 @@ public abstract VCSHistoryProvider.RevisionProvider getRevisionProvider(VCSHistoryProvider.HistoryEntry entry); public abstract VCSHistoryProvider.MessageEditProvider getMessageEditProvider(VCSHistoryProvider.HistoryEntry entry); + public abstract ParentProvider getParentProvider(HistoryEntry entry); } Index: versioning/src/org/netbeans/modules/versioning/DelegatingVCS.java --- versioning/src/org/netbeans/modules/versioning/DelegatingVCS.java Base (BASE) +++ versioning/src/org/netbeans/modules/versioning/DelegatingVCS.java Locally Modified (Based On LOCAL) @@ -580,8 +580,35 @@ HistoryEntry[] proxyHistory = new HistoryEntry[history.length]; for (int i = 0; i < proxyHistory.length; i++) { final org.netbeans.modules.versioning.spi.VCSHistoryProvider.HistoryEntry he = history[i]; - RevisionProvider rp = new RevisionProvider() { + proxyHistory[i] = delegateHistoryEntry(proxies, he); + } + return proxyHistory; + } + @Override + public Action createShowHistoryAction(VCSFileProxy[] proxies) { + File[] files = toFiles(proxies); + return getDelegate().getVCSHistoryProvider().createShowHistoryAction(files); + } + + private MessageEditProvider delegateMessageEditProvider(final org.netbeans.modules.versioning.spi.VCSHistoryProvider.HistoryEntry he) { + if(he.canEdit()) { + return new MessageEditProvider() { + @Override + public void setMessage(String message) throws IOException { + org.netbeans.modules.versioning.spi.VCSHistoryProvider.MessageEditProvider provider = Accessor.IMPL.getMessageEditProvider(he); + if(provider != null) { + provider.setMessage(message); + } + } + }; + } + return null; + } + + private RevisionProvider delegateRevisionProvider(final org.netbeans.modules.versioning.spi.VCSHistoryProvider.HistoryEntry he) { + return new RevisionProvider() { + @Override public void getRevisionFile(VCSFileProxy originalFile, VCSFileProxy revisionFile) { org.netbeans.modules.versioning.spi.VCSHistoryProvider.RevisionProvider provider = Accessor.IMPL.getRevisionProvider(he); if(provider != null) { @@ -593,20 +620,26 @@ } } }; - MessageEditProvider mep = null; - if(he.canEdit()) { - mep = new MessageEditProvider() { + } + + private ParentProvider delegateParentProvider(final org.netbeans.modules.versioning.spi.VCSHistoryProvider.HistoryEntry he) { + return new ParentProvider() { @Override - public void setMessage(String message) throws IOException { - org.netbeans.modules.versioning.spi.VCSHistoryProvider.MessageEditProvider provider = Accessor.IMPL.getMessageEditProvider(he); + public HistoryEntry getParentEntry(VCSFileProxy file) { + org.netbeans.modules.versioning.spi.VCSHistoryProvider.ParentProvider provider = Accessor.IMPL.getParentProvider(he); if(provider != null) { - provider.setMessage(message); + org.netbeans.modules.versioning.spi.VCSHistoryProvider.HistoryEntry he = provider.getParentEntry(file.toFile()); + if(he != null) { + return delegateHistoryEntry(toProxies(he.getFiles()), he); } } + return null; + } }; } - proxyHistory[i] = - new HistoryEntry( + + private HistoryEntry delegateHistoryEntry(VCSFileProxy[] proxies, final org.netbeans.modules.versioning.spi.VCSHistoryProvider.HistoryEntry he) { + return new HistoryEntry( proxies, he.getDateTime(), he.getMessage(), @@ -615,18 +648,11 @@ he.getRevision(), he.getRevisionShort(), he.getActions(), - rp, - mep); + delegateRevisionProvider(he), + delegateMessageEditProvider(he), + delegateParentProvider(he)); } - return proxyHistory; - } - @Override - public Action createShowHistoryAction(VCSFileProxy[] proxies) { - File[] files = toFiles(proxies); - return getDelegate().getVCSHistoryProvider().createShowHistoryAction(files); - } - private class DelegateChangeListener implements org.netbeans.modules.versioning.spi.VCSHistoryProvider.HistoryChangeListener { private final VCSHistoryProvider.HistoryChangeListener delegate; public DelegateChangeListener(HistoryChangeListener delegate) { Index: versioning/src/org/netbeans/modules/versioning/spi/AccessorImpl.java --- versioning/src/org/netbeans/modules/versioning/spi/AccessorImpl.java Base (BASE) +++ versioning/src/org/netbeans/modules/versioning/spi/AccessorImpl.java Locally Modified (Based On LOCAL) @@ -46,6 +46,7 @@ import org.netbeans.modules.versioning.Accessor; import org.netbeans.modules.versioning.spi.VCSHistoryProvider.HistoryEntry; import org.netbeans.modules.versioning.spi.VCSHistoryProvider.MessageEditProvider; +import org.netbeans.modules.versioning.spi.VCSHistoryProvider.ParentProvider; import org.netbeans.modules.versioning.spi.VCSHistoryProvider.RevisionProvider; /** @@ -70,5 +71,10 @@ return entry.getMessageEditProvider(); } + @Override + public ParentProvider getParentProvider(HistoryEntry entry) { + return entry.getParentProvider(); + } + } Index: versioning/src/org/netbeans/modules/versioning/spi/VCSHistoryProvider.java --- versioning/src/org/netbeans/modules/versioning/spi/VCSHistoryProvider.java Base (BASE) +++ versioning/src/org/netbeans/modules/versioning/spi/VCSHistoryProvider.java Locally Modified (Based On LOCAL) @@ -123,6 +123,7 @@ private Action[] actions; private RevisionProvider revisionProvider; private MessageEditProvider messageEditProvider; + private ParentProvider parentProvider; /** * Creates a new HistoryEntry instance. @@ -198,6 +199,41 @@ } /** + * Creates a new HistoryEntry instance. + * + * @param files involved files + * @param dateTime the date and time when the versioning revision was created + * @param message the message describing the versioning revision + * @param username full description of the user who created the versioning revision + * @param usernameShort short description of the user who created the versioning revision + * @param revision full description of the versioning revision + * @param revisionShort short description of the versioning revision + * @param actions actions which might be called in regard with this revision + * @param revisionProvider a RevisionProvider to get access to a files contents in this revision + * @param messageEditProvider a MessageEditProvider to change a revisions message + * @param parentProvider a ParentProvider to provide this entries parent entry. Not necessary for VCS + * where a revisions parent always is the time nearest previous revision. + * + * @since 1.30 + */ + public HistoryEntry( + File[] files, + Date dateTime, + String message, + String username, + String usernameShort, + String revision, + String revisionShort, + Action[] actions, + RevisionProvider revisionProvider, + MessageEditProvider messageEditProvider, + ParentProvider parentProvider) + { + this(files, dateTime, message, username, usernameShort, revision, revisionShort, actions, revisionProvider, messageEditProvider); + this.parentProvider = parentProvider; + } + + /** * Determines if this HistoryEntry instance supports changes. * * @return true if it is possible to access setter methods in this instance @@ -332,6 +368,21 @@ } /** + * Returns this revisions parent entry or null if not available. + * + * @param file the file for whitch the parent HistoryEntry should be returned + * @return this revisions parent entry + * + * @since 1.30 + */ + public HistoryEntry getParentEntry(File file) { + if(parentProvider != null) { + return parentProvider.getParentEntry(file); + } + return null; + } + + /** * Returns the RevisionProvider * @return the RevisionProvider */ @@ -346,7 +397,15 @@ MessageEditProvider getMessageEditProvider() { return messageEditProvider; } + + /** + * Returns the ParentProvider or null + * @return the ParentProvider + */ + ParentProvider getParentProvider() { + return parentProvider; } + } /** * Adds a listener for history change events. @@ -393,6 +452,24 @@ } /** + * Implement and pass over to a {@link HistoryEntry} in case you want + * {@link HistoryEntry#getParentProvider()} to return relevant values. + * + * @since 1.30 + */ + public interface ParentProvider { + /** + * Return a {@link HistoryEntry} representing the parent of the {@link HistoryEntry} + * configured with this ParentProvider. + * + * @param file the file for whitch the parent HistoryEntry should be returned + * @return the parent HistoryEntry + * @since 1.30 + */ + HistoryEntry getParentEntry(File file); + } + + /** * Implement and pass over to {@link HistoryEntry} in case * {@link HistoryEntry#setMessage(java.lang.String)} * is expected to work. Index: versioning/test/unit/src/org/netbeans/modules/versioning/spi/VCSHistoryTest.java --- versioning/test/unit/src/org/netbeans/modules/versioning/spi/VCSHistoryTest.java Base (BASE) +++ versioning/test/unit/src/org/netbeans/modules/versioning/spi/VCSHistoryTest.java Locally Modified (Based On LOCAL) @@ -56,7 +56,6 @@ import org.netbeans.modules.versioning.spi.testvcs.TestVCSHistoryProvider; import org.openide.util.Lookup; -import org.netbeans.modules.versioning.spi.testvcs.TestVCSInterceptor; /** * Versioning SPI unit tests of VCSInterceptor. @@ -118,6 +117,28 @@ assertTrue(provider.revisionprovided); } + public void testHistoryEntryProvidesParent() throws IOException { + ParentProviderImpl provider = new ParentProviderImpl(); + File file = new File(""); + VCSHistoryProvider.HistoryEntry h = + new VCSHistoryProvider.HistoryEntry( + new File[] {file}, + new Date(System.currentTimeMillis()), + "msg", + "user", + "username", + "12345", + "1234567890", + new Action[0], + null, + null, + provider); + + h = h.getParentEntry(file); + assertNotNull(h); + assertEquals(ParentProviderImpl.PARENT_MSG, h.getMessage()); + } + public void testHistoryGetRevisionIsReallyInvoked() throws IOException { File f = new File(dataRootDir, "workdir/root-test-versioned/" + TestVCSHistoryProvider.FILE_PROVIDES_REVISIONS_SUFFIX); f.createNewFile(); @@ -148,6 +169,35 @@ assertTrue(TestVCSHistoryProvider.instance.revisionProvided); } + public void testHistoryGetParentIsReallyInvoked() throws IOException { + File f = new File(dataRootDir, "workdir/root-test-versioned/" + TestVCSHistoryProvider.FILE_PROVIDES_REVISIONS_SUFFIX); + f.createNewFile(); + VersioningSystem vs = VersioningSupport.getOwner(f); + assertNotNull(vs); + VCSHistoryProvider hp = vs.getVCSHistoryProvider(); + assertNotNull(hp); + + HistoryEntry[] history = hp.getHistory(new File[] {f}, null); + assertNotNull(history); + assertTrue(history.length > 0); + HistoryEntry parentEntry = history[0].getParentEntry(f); + assertNotNull(parentEntry); + assertEquals(TestVCSHistoryProvider.PARENT_MSG, parentEntry.getMessage()); + + // the same test again just to see that VCSSystemProvider.VersioningSystem properly delegates + VCSFileProxy proxy = VCSFileProxy.createFileProxy(f); + VCSSystemProvider.VersioningSystem pvs = Utils.getOwner(proxy); + assertNotNull(pvs); + org.netbeans.modules.versioning.core.spi.VCSHistoryProvider php = pvs.getVCSHistoryProvider(); + assertNotNull(php); + + org.netbeans.modules.versioning.core.spi.VCSHistoryProvider.HistoryEntry[] phistory = php.getHistory(new VCSFileProxy[] {proxy}, null); + assertNotNull(phistory); + assertTrue(phistory.length > 0); + org.netbeans.modules.versioning.core.spi.VCSHistoryProvider.HistoryEntry proxyParentEntry = phistory[0].getParentEntry(proxy); + assertEquals(TestVCSHistoryProvider.PARENT_MSG, proxyParentEntry.getMessage()); + } + public void testHistoryEntryDoesntProvideRevision() throws IOException { RevisionProviderImpl provider = new RevisionProviderImpl(); provider.revisionprovided = false; @@ -166,6 +216,25 @@ // nothing happend } + public void testHistoryEntryDoesntProvideParent() throws IOException { + RevisionProviderImpl provider = new RevisionProviderImpl(); + provider.revisionprovided = false; + final File file = new File(""); + VCSHistoryProvider.HistoryEntry h = + new VCSHistoryProvider.HistoryEntry( + new File[] {file}, + new Date(System.currentTimeMillis()), + "msg", + "user", + "username", + "12345", + "1234567890", + new Action[0], + null); + h.getParentEntry(file); + // nothing happend + } + public void testHistoryEntryEditable() throws IOException { MessageEditProviderImpl provider = new MessageEditProviderImpl(); provider.message = null; @@ -229,6 +298,24 @@ } } + private class ParentProviderImpl implements VCSHistoryProvider.ParentProvider { + static final String PARENT_MSG = "im.the.parent"; + @Override + public HistoryEntry getParentEntry(File file) { + return new VCSHistoryProvider.HistoryEntry( + new File[] {file}, + new Date(System.currentTimeMillis()), + PARENT_MSG, + "user", + "username", + "12345", + "1234567890", + new Action[0], + null, + null); + } + } + private class MessageEditProviderImpl implements VCSHistoryProvider.MessageEditProvider { String message; @Override Index: versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSHistoryProvider.java --- versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSHistoryProvider.java Base (BASE) +++ versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSHistoryProvider.java Locally Modified (Based On LOCAL) @@ -52,11 +52,14 @@ * * @author tomas */ -public class TestVCSHistoryProvider implements VCSHistoryProvider, VCSHistoryProvider.RevisionProvider { +public class TestVCSHistoryProvider implements VCSHistoryProvider, VCSHistoryProvider.RevisionProvider, VCSHistoryProvider.ParentProvider { public static final String FILE_PROVIDES_REVISIONS_SUFFIX = "providesRevisions"; public static TestVCSHistoryProvider instance; + public static String PARENT_MSG = "im.the.parent"; + public boolean revisionProvided = false; + public boolean parentrevisionProvided = false; public static HistoryEntry[] history; public TestVCSHistoryProvider() { @@ -83,6 +86,8 @@ "12345", "1234567890", new Action[0], + this, + null, this)}; } @@ -114,4 +119,20 @@ public void getRevisionFile(File originalFile, File revisionFile) { revisionProvided = true; } + + @Override + public HistoryEntry getParentEntry(File file) { + return new VCSHistoryProvider.HistoryEntry( + new File[] {file}, + new Date(System.currentTimeMillis()), + PARENT_MSG, + "user", + "username", + "12345", + "1234567890", + new Action[0], + this); } + + +}