Using ISVNClientAdapter for svn operations in eclipse plugin - eclipse

I am trying to use ISVNClientAdapter from org.tigris.subversion.svnclientadapter to invoke svn operations from my eclipse plugin. It seems to offer support for various operations, but it is unclear to me how to use them, starting from a project given as IProject or an SVNTeamProvider.
Can anyone give me a short example how to apply operations (like commit or getStatus)?

One way to go seems to be (If project is the object of type IProject):
ISVNClientAdapter adapter = SVNProviderPlugin.getPlugin().getSVNClient();
File file = new File(project.getLocation().toString());
ISVNStatus[] status = adapter.getStatus(file, true, false);
Together with the absolute path stored in file, adapter can perform different operations on the svn.

Related

How do I ignore certain classifiers when performing gavc search on Artifactory through REST?

I am writing a REST Client application which needs to perform a gavc search on our Enterprise Artifactory and list out the builds currently retained for specific version.
My REST URI looks like following:
/artifactory/api/search/gavc?g=com.abc&a=xyz&v=1.0-SNAPSHOT&repos=libs-release
As expected, this will return the applicable search results including jar files, pom files, sources jars and javadoc jars
Eg:
../com/abc/xyz/1.0-SNAPSHOT/xyz-1.0-1111.jar
../com/abc/xyz/1.0-SNAPSHOT/xyz-1.0-1111-sources.jar
../com/abc/xyz/1.0-SNAPSHOT/xyz-1.0-1111-javadoc.jar
../com/abc/xyz/1.0-SNAPSHOT/xyz-1.0-1111.pom
../com/abc/xyz/1.0-SNAPSHOT/xyz-1.0-1234.jar
../com/abc/xyz/1.0-SNAPSHOT/xyz-1.0-2222-sources.jar
../com/abc/xyz/1.0-SNAPSHOT/xyz-1.0-2222.pom
../com/abc/xyz/1.0-SNAPSHOT/xyz-1.0-3.jar
../com/abc/xyz/1.0-SNAPSHOT/xyz-1.0-45.pom etc
In the URI, if I specify c=sources or c=javadoc, I can get only those paths.
How do I get only the regular jar files like xyz-1.0-1111.jar, xyz-1.0-3.jar etc?
I already tried
/artifactory/api/search/gavc?g=com.abc&a=xyz&v=1.0-SNAPSHOT&repos=libs-release&c=null
/artifactory/api/search/gavc?g=com.abc&a=xyz&v=1.0-SNAPSHOT&repos=libs-release&c=''
/artifactory/api/search/gavc?g=com.abc&a=xyz&v=1.0-SNAPSHOT&repos=libs-release&c=
The first two calls doesn't produce any results, while the third produces the same results as the initial query.
Thanks in advance.

Eclipse Plugin Development: Adding items to a working set with the path of the item?

Hello,
I'm an eclipse plugin development newbie looking for pointers to get me started on a particular project.
I am trying to build an eclipse plugin that will automatically construct a working set from a text file that simply consists of a list of file path names. The files/items need not share any parent directories. The rough idea is represented in the following diagram:
I am not asking for the solution to this task. That's the over-arching goal. To achieve that goal, I want to conquer some smaller goals first.
With that in mind, here's the smaller goal I'm currently trying to tackle:
In Eclipse, how can I prompt the user for a single file's path, and then add that file to an existing working set?
I'm not sure where to start. Should I work directly off of the existing org.eclipse.ui.workingSets extension point? Or should I use a collection of other extension points? How do I convert strings into something that can be added to a working set? Do I write code that directly modifies the workingsets.xml file?
Even with a much simpler goal, I still feel quite overwhelmed with the vastness of eclipse extension options. There are probably many ways to go about implementing something like this, but I just need one to get started.
Thanks a bunch!
To manipulate working sets you use the working set manager interface IWorkingSetManager. Get this with:
IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
From this you can get a particular working by name with:
IWorkingSet workingSet = manager.getWorkingSet("name");
The contents of a working set is an array of IAdaptable objects:
IAdaptable [] contents = workingSet.getElements();
You add to the contents by adding to this array and setting the contents:
IAdaptable [] newContents
.... get new array with old contents + new contents
workingSet.setElements(newContents);
A lot of Eclipse objects implement IAdaptable, for a file in the workspace you would use IFile. You can use dialogs such as ResourceSelectionDialog to select resources from the workspace.

How to specify and read properties in an Eclipse plugin

I have an Eclipse product which uses my own plugins. I want to read some properties based on user inputs. I want to persist these properties on some user action, and read those properties back when required. Can this be achieved using some Eclipse API?
A more elaborate description of the above problem:
Say I have a property abc=xyz in a config file myconfig.ini. This property is read by the perspective during the bootstrapping process. During use of the perspective, some action sets this property to a new value xyz=def. Now, I should be able to save the new value in myconfig.ini. So next time the bootstrapping happens, the value of xyz is read as def instead of abc. However, I can also choose to manually set it to abc by editing the myconfig.ini file.
How would I manage myconfig.ini? Where should it exist within my eclipse product project?
What is the best API to manage reading, writing and updating properties in myconfig.ini?
You can use resource markers mechanism:
IMarker marker = file.createMarker(IMarker.MARKER);
marker.setAttribute(IMarker.MESSAGE, "blabla");
marker.setAttribute("attr", 5);
You can search for markers by using the findMarkers methods on IResource.
See FAQ also
You should consider using the apache configurations API http://commons.apache.org/proper/commons-configuration/
It can read and write INI files and if you want to change the configuration file type or add more configuration options you can simply configure it.
I would add a hidden directory to the workspace root e.g. ${WORKSPACE}/.productName/product.ini
and add an ISaveParticipant that ensures the ini file gets updated on shutdown.
You can get the Workspace using the ResourcesPlugin
IWorkspace workspace = ResourcesPlugin.getWorkspace();
and resolve it to an absolute path
IWorkspaceRoot wsRoot = workspace.getRoot();
IPath wsPath = wsRoot.getRawLocation();
IPath absoluteWsPath = wsPath.makeAbsolute();

How to hijack files from clearcase from eclipse plugin

I am developing a component which generates code based on templates inside java class. The project use clearcase as SCM. After the code update, the files are in read-only state. If i am adding anything to any java class, i have to make it hijack and paste the source code templates inside the class. Let's suppose the jAutoDoc plugin which is used for adding comment. If user select a class, click on generate comment. The comment will not paste if the file is not in write mode.
Clearcase Plugin Vendor : IBM Rational.
Eclipse Version : 3.5
Please help. Is there any way to do hijack a file from java code?
Thanks in advance..
Thanks VonC.
For making a java file in write mode through eclipse JDT API. This method will set the preference "read only" of the resource to "false".
private static void setCompilationUnitWriteMode(ICompilationUnit cu) throws CoreException {
ResourceAttributes resourceAttributes = cu.getResource().getResourceAttributes();
if (resourceAttributes != null) {
// Setting Writemode true
resourceAttributes.setReadOnly(false);
cu.getResource().setResourceAttributes(resourceAttributes);
}
}
For Non Java Resource
First create the IFile object, set the preference "read only" of the resource to "false".
IFile file = path.getFile()
file.getFile().getResourceAttributes();
if (resourceAttributes != null) {
resourceAttributes.setReadOnly(false);
file.setResourceAttributes(resourceAttributes);
}
Hijacking files only means making them read - write through an OS-based operation. (for snapshot view only, not dynamic ones)
The question is though: do you need to version your classes completed by your plugin?
Because in that case, a cleartool checkout is more appropriate.
Otherwise, read write is enough, changing file attribute through java.

OnSave actions in NetBeans 6.9

Is there any way to tell NetBeans to execute a specific action when saving a file? e.g. removing unused imports while saving a source file?
This was an interesting question... as I believe you would have to write a custom NetBeans plugin to do what you're wanting (the functionality isn't available out-of-the-box), and I've been looking for an excuse to explore NetBeans plugin development.
However, after spending a couple of hours reading tutorials and crawling through the javadocs... it's become clear that this subject is quite a big bite to chew, and probably way more involved than you're wanting.
I think the BEST suggestion is forget about removing unused imports at save-time, and instead perform this step at build-time. NetBeans offers great integration with Ant and/or Maven (for build purposes it's basically just a GUI wrapper around those tools), and there are a number of Ant tasks out there that can do what you're wanting. See:
http://ant.apache.org/external.html
(look for the "CleanImports" and "Importscrubber" tasks)
If your NetBeans project(s) are Maven-based, then you can always plug in one of these Ant tasks there using the AntRun plugin for Maven.
If you're not used to dealing with Ant or Maven directly in NetBeans, then just switch to the "Files" tab and look at your project's root directory. If its a Maven project, the build script will be named pom.xml. Otherwise, your project will generally be Ant-based and the build script will be named build.xml. The documentation for these items above should make it fairly clear how to move forward from there.
I notice that those two Ant tasks haven't been updated in awhile, so if you run into issues you might want to check out the very popular and up-to-date PMD system, which has its own documentation for integrating with NetBeans. However, the issue there is PMD is primarily for generating reports... I don't know if it can be used to actually take action and change source files.
Not exactly an answer to your question, but note that NB 7.1 lets you fix imports on the whole project at once: http://wiki.netbeans.org/NewAndNoteworthyNB71#Organize_Imports_Hint
This is not a good practice and NetBeans does not support it.
I resurrect this topic.
Well this code code is tested with Netbeans 7.4.
here I'm overriding the default save action in the actionPerformed method.
If you choose to do this by yourself create a new Action using the wizard then call the save action inside actionPerformed method.
package yourpackage;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle.Messages;
#ActionID(
category = "File",
id = "BZ.SaveAction"
)
#ActionRegistration(
iconBase = "BZ/Save.png",
displayName = "#CTL_SaveAction"
)
#ActionReferences({
#ActionReference(path = "Menu/File", position = 750),
#ActionReference(path = "Toolbars/File", position = 0),
#ActionReference(path = "Shortcuts", name = "D-S")
})
#Messages("CTL_SaveAction=Save")
public final class SaveAction implements ActionListener {
org.openide.actions.SaveAction sa = org.openide.util.actions.CallbackSystemAction.get(org.openide.actions.SaveAction.class);
#Override
public void actionPerformed(ActionEvent e) {
// custom code
JOptionPane.showMessageDialog(null, "custum message ");
sa.performAction();
}
}
Goto Tools-> Options select Editor there select On Save Tab now select Java from drop down menu. So, now select Organize Imports option. Hope this will help you.