I'm trying to understand how to use the .gitattributes from JGit. But I'm unable to find any tutorial which best demonstrates it.
Is it that JGit hasn't support for it. But git client has this support. Why not JGit?
JGit has basic support for .gitattributes. See bug 342372 and related bugs for the current state of development.
The JGit test suite may help you understanding how .gitattributes are implemented in JGit. See this article for how to work with the JGit sources.
If you would like to try libgi2, there is a jni bindings that allows you to access most recent libgit2 attributes apis
Following are some examples:
Repository testRepo = Repository.open("path-to-your-repo");
// load macros from .gitattributes file
Attr.addMacro(testRepo, "binary", "-diff -crlf");
// Loop through all attributes
Map<String, String> attributes = new HashMap<>();
Attr.foreach(
testRepo,
EnumSet.of(CHECK_INDEX_THEN_FILE),
".",
new Attr.ForeachCb() {
#Override
public int accept(String name, String value) {
attributes.put(name, value);
return 0;
}
});
You can find the test case about these apis here
Related
The VSCode extension API provides a means of creating a new SourceControl. Is there any way to ask for an existing SourceControl for the WorkspaceFolder? I'd like to be able to learn about scm file status from an extension without having to recreate existing version control plugins; instead, I'd like to be able to asking the existing plugins.
Very late answer by as I had the same question a while ago I thought I should share what I found.
At that time, I was trying to build an extension to get the remote URL for the current file opened in the editor, so I used the default Git integration for VSCode after some research as the documentation doesn't make this very easy to find.
Here's a little snippet of how you can use it to extract information about the current repository:
const gitExtension = vscode.extensions.getExtension<GitExtension>('vscode.git').exports;
const git = gitExtension.getAPI(1);
const repository = git.getRepository('current-workspace-path');
const { remotes, HEAD } = repository.state;
for (const remote of remotes) {
const { fetchUrl } = remote;
}
You can get the current workspace path using the workspace (there might be a better way though):
const workspaceRootUris = vscode.window.workspaceFolders.map(ws => ws.uri);
I'm currently writing a jenkins plug-in that has multiple builders. I wanted to share the fields in the descriptor/global.jelly across all builders. How can I share this information? Can I use inheritance or encapsulation?
A good place to start is to search the Jenkins github repository
The code you want is
Jenkins.getInstance().getDescriptor( MyPluginWithGlobalConfig.class )
Which will give you the descriptor back you want (as there is only one instance of the descriptor)
Here is one I used in a plugin (in groovy) which fetches a descriptor then calls a method on it source file
#Override
public List<String> rebuild(List<String> list){
SeleniumDynamicCapability.DescriptorImpl sdcd = Jenkins.getInstance().getDescriptor(SeleniumDynamicCapability.class)
List<SeleniumCapabilityRO> sc = sdcd.loadDefaultItems()
if (sc.size() == 0)
throw(new SeleniumException("No selenium capabilities detected"))
setSeleniumCapabilities(sc)
sc.each{list.add(it.toString())}
return list;
}
I am very new to developing eclipse plugins. The biggest hurdle I am facing right now is where/how to get at the data from various other plugins. I am having a real hard time finding documentation for this. For instance the Team Provider plugin....
How do I read the svn revision of a file? Lets say I have an IResourceChangeListener and I want to keep track of the svn revision number of a file (if the user did an update for example).
If I want to ask svn if there are pending updates for a project, how do I talk to the eclipse team provider?
I am not sure where to start...
Thanks!
I eventually discovered what I was looking for after many hours of searching. Unfortunately since I have less than 100 rep. I have been unable to post until now....
I am making a little progress on this. I randomly stumbled upon this while pouring through eclipse source code.
The following code snippet monitors everything that goes on with regard to an svn enabled project. If you save a file, to an update, revert etc. Anything that touches the files or meta data of the files. I just print out the file/direcory name and its revision number.
Subversive version:
final Subscriber subscriber = UpdateSubscriber.instance();
subscriber.addListener(new ISubscriberChangeListener() {
#Override
public void subscriberResourceChanged(ISubscriberChangeEvent[] events) {
for(ISubscriberChangeEvent event : events) {
UpdateSyncInfo info = (UpdateSyncInfo) subscriber.getSyncInfo(event.getResource());
System.out.println(event.getResource().getName()+" revision: "+uInfo.getLocalResource().getRevision());
}
}
});
The real trick was figuring out the entry point to get at this information: UpdateSubscriber. It would be nice if there was a good resource for finding out this sort of information.
Subclipse version:
private static final Subscriber subscriber = SVNWorkspaceSubscriber.getInstance();
private static final ISubscriberChangeListener subsciberListener = new ISubscriberChangeListener() {
#Override
public void subscriberResourceChanged(ISubscriberChangeEvent[] events) {
try {
for (ISubscriberChangeEvent event : events) {
SVNStatusSyncInfo info = (SVNStatusSyncInfo) subscriber.getSyncInfo(event.getResource());
System.out.println(event.getResource().getName() + " revision: " + info.getRepositoryRevision());
}
} catch (TeamException e) {
}
}
};
#Override
public void start(BundleContext context) throws Exception {
super.start(context);
subscriber.addListener(subsciberListener);
}
#Override
public void stop(BundleContext context) throws Exception {
subscriber.removeListener(subsciberListener);
super.stop(context);
}
For general information on the Team API in the Eclipse platform, review the documentation in the help system.
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/team.htm
(If you're working with the Subscriber stuff, it appears that's mentioned under the "Synchronization Support" -> "Beyond the Basics" topic.)
The Java doc for the team packages also helps:
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/team/core/package-summary.html
If you're trying to integrate with or otherwise extend the Subclipse or Subversive team providers, you may have better luck asking your question in their forums:
http://subclipse.tigris.org/ds/viewForums.do
http://www.eclipse.org/subversive/newsgroup.php
One starting point would be to explore the sources of subversive to see how they did their implementation of the features you are describing.
The sources for eclipse.team (the common module for all VCS plugins) are available in a Git repo.
The sources for EGit, another VCS plugin (for Git) can also be instructive.
My question is quite simple and with the SharpSvn Api, it should be easy as well. Here what I did:
path = "c:\project";
using (SvnLookClient client = new SvnLookClient())
{
SvnLookOrigin o = new SvnLookOrigin(path);
Collection<SvnChangedEventArgs> changeList;
client.GetChanged(o, out changeList); // <-- Exception
}
and when I call the GetChanged, I get an exception:
Can't open file 'c:\project\format': The system cannot find the file specified.
So, Maybe there is something I'm missing? Or maybe it's not the right way to do find out the list of files and folders that were modified in the local repository?
Thanks in advance.
The SvnLookClient class in SharpSvn is the equivalent to the 'svnlook' console application. It is a low level tool that enables repository hooks to look into specific transactions of a repository using direct file access.
You probably want to use the SvnClient class to look at a WorkingCopy and most likely its Status() or in some cases simpler GetStatus() function to see what changed.
The path that the SvnLookOrigin constructor wants is actually:
path = "c:\project\.svn\";
That is, it wants that special ".svn" directory not just the root of where the source is checked out to.
Although you probably do want to listen to Bert and do something like:
path = "c:\project";
using (SvnLookClient client = new SvnLookClient())
{
SvnLookOrigin o = new SvnLookOrigin(path);
Collection<SvnChangedEventArgs> changeList;
client.GetStatus(o, out changeList); // Should now return the differences between this working copy and the remote status.
}
I want to use the default XML editor (org.eclipse.wst.xml.ui) of Eclipse in an RCP application. I need to read the DOM of the xml file currently open. The plugin doesn't offer any extension point, so I'm trying to access the internal classes. I am aware that the I should not access the internal classes, but I don't have another option.
My approach is to create a fragment and an extension point to be able to read data from the plugin. I'm trying not to recompile the plugin, that's why I thought that a fragment was necessary. I just want to load it and extract the data at runtime.
So, my question is: is there another way to access the classes of a plugin? if yes, how?
Any tutorial, doc page or useful link for any of the methods is welcome.
Since nobody answered my question and I found the answer after long searches, I will post the answer for others to use if they bump into this problem.
To access a plugin at runtime you must create and extension point and an extension attached to it into the plugin that you are trying to access.
Adding classes to a plugin using a fragment is not recommended if you want to access those classes from outside of the plugin.
So, the best solution for this is to get the plugin source from the CVS Repository and make the modifications directly into the source of the plugin. Add extension points, extensions and the code for functionality.
Tutorials:
Getting the plugin from the CVS Repository:
http://www.eclipse.org/webtools/community/tutorials/DevelopingWTP/DevelopingWTP.html
Creating extensions and extension points and accessing them:
http://www.vogella.de/articles/EclipseExtensionPoint/article.html
http://www.eclipsezone.com/eclipse/forums/t97608.rhtml
I ended up extending XMLMultiPageEditorPart like this:
public class MultiPageEditor extends XMLMultiPageEditorPart implements
IResourceChangeListener {
#Override
public void resourceChanged(IResourceChangeEvent event) {
// TODO Auto-generated method stub
setActivePage(3);
}
public Document getDOM() {
int activePageIndex = getActivePage();
setActivePage(1);
StructuredTextEditor fTextEditor = (StructuredTextEditor) getSelectedPage();
IDocument document = fTextEditor.getDocumentProvider().getDocument(
fTextEditor.getEditorInput());
IStructuredModel model = StructuredModelManager.getModelManager()
.getExistingModelForRead(document);
Document modelDocument = null;
try {
if (model instanceof IDOMModel) {
// cast the structured model to a DOM Model
modelDocument = (Document) (((IDOMModel) model).getDocument());
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
setActivePage(activePageIndex);
return modelDocument;
}
}
This is not a clean implementation, but it gets the job done.