How to hijack files from clearcase from eclipse plugin - eclipse

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.

Related

FlexUnitApplication.html and FlexUnitApplication.swf not generated

Context
I have
a project Flex-Java in Eclipse Indigo service Release 2, (a web application)
and i use the plugin Flash-builder to work on it.
I use sdk 4.5.1
What i try to do
1) I try to make a simple test case with FlexUnit4. When i create a new Test Case) : New > Test Case Class, Eclipse by Default create :
package flexUnitTests + with my new Test case : (for example :
TestDoc.as)
package byDefault with one file : FlexUnitCompilerApplication.mxml
a html a swf file for FlexUnitCompilerApplication is auto-generated in bin-debug folder.
Till this point all seems to be good, so I try to execute the unit test :
2) I want to execute the unit test :
A FlexUnitApplication.mxml is created in the default package
The problem :
The compilator doesn't generate the files : FlexUnitApplication.hmtl and FlexUnitApplication.swf in bin-debug folder...
And there is an error written in the "error screen" :
description Impossible to resolve all the ressources "FlexUnitTestRunner"
place or Localisation : Unknown
sorry i try to translate the description from a French version
Other informations
I succeeded doing this in other projects... the FlexUnitApplication files are auto-generated.
Question(s)
It seems that, it is bound with something in this particular project. Maybe something is hindering the process to autogenerate these files ?? I cannot figure it out why??
Is it Possible to force the compilator doing these files (html and swf) ??
I am really lost.. and i tried things, i looked in the properties, in the metadata's ... i really don't understand.
Somebody maybe has an idea for that, what could i do, what could i check ?
Thank you in advance
I always have troubles with unit tests in eclips+FB plugin as well.
After the FlexUnitApplication.mxml is created goto your project settings and update the following:
remove the dynamic {locale} compiler flag and add a specific '-locale=en_US' only.
if you have custom locale files add those to the source path manually
in the library path find the entry that points to the dynamic locale library '..sdk/../{locale} and copy the path. click on add SWC to library path. Paste the copied path and replace '{locale}' with 'en_US'
Generally this turns out favorable for me.

Using ISVNClientAdapter for svn operations in eclipse plugin

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.

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();

When creating an Eclipse-based Product, how can I set the default workspace?

I've built an eclipse-based product, and I want to set the default workspace used by the Product. Currently, when the "Workspace Launcher" pops up for the first time, the default workspace location is just in the same directory as the Eclipse Product executable. I'd like to change to something like USER_HOME/myworkspace.
I can't seem to find a setting for this, but I'm guessing / hoping its a setting in my product_configuration.ini.
Cheers!
here is a more easy way
Once you have Eclipse up and running you can open Window-->Preferences-->Editors-->Startup and Shutdown. Click the first box that says Prompt for workspace on startup.
Or In your config.ini file ull've this line (or look in configuration.settings\org.eclipse.ui.ide.prefs)
//The default workspace location
Osgi.instance.area.default=#user.home/workspace
try changing this
Here is what needs to be done.
Wherever eclipse is installed go to the "configuration" directory and open the config.ini file in there.
Windows paths normally look like this:
C:\Users\Wilbert\Documents\Installers\Eclipse\eclipse
You will probably find something like this in the config.ini file:
osgi.instance.area.default=#user.home/workingspace
You need to change that to[Getting rid of the "#" and using forward slashes instead of back slash]:
osgi.instance.area.default=C:/Users/Wilbert/Documents/Programs/CS111B(Java)/Practice Programs/Projects
I just did it and it worked.
In your product (.product), go to the "Configuration" tab. Under the "Properties" section, add the property 'osgi.instance.area.default' with a value of '#user.home/myworkspace'. When you export your product, this property will be automatically added to your product's configuration file (just as ayush and Wilbert Sequeira were manually doing).
Note that only an exported product will use that configuration. When running your product in the Eclipse IDE, the workspace location will be overridden by your IDE's configurations.
The now-defunct Symbian WRT product did this. Looking through the sources, it seems to be done by a p2.inf file in the product package. See the screenshot below:
The first yellow arrow is for Windows and the second for Mac and Linux
In your .product file you can specify this as part of the programArgs element.
<programArgs>-data #user.home/MyWorkspace</programArgs>
Note that you can customize config.ini for individual platforms in the product descriptor (*.product) editor. But it never worked for me - hence that hack using P2. It may be working now as I was working with either 3.5 or early 3.6 when I last tried it.
Have a look at the following tutorial: http://hexapixel.com/2009/01/12/rcp-workspaces.
You said in your comment to the question "I just want to prepopulate the selector window with a certain default location".
You can do just that in PickWorkspaceDialog's (from the tutorial) getWorkspacePathSuggestion() method:
private String getWorkspacePathSuggestion() {
StringBuffer buf = new StringBuffer();
String uHome = System.getProperty("user.home");
if (uHome == null) {
uHome = "c:" + File.separator + "temp";
}
buf.append(uHome);
buf.append(File.separator);
buf.append("My App Name");
buf.append("_Workspace");
return buf.toString();
}
For this to work, you do have to create your own dialog though, and I can't tell if that's an option from your question...
In your .product file within the block add:
<property name="osgi.instance.area.default" value="#user.home/workspace" />
And when you build your product, the default config.ini will have this property set.
Details are in the Eclipse docs regarding the various variables.
To set the workspace location programmatically, use:
Platform.getInstanceLocation().set(new URL(...));

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.