January 28, 2015

Remove 3rd Party Apps in OSX

Removing apps installed on OSX via App Store is very easy. You just have to go to LaunchPad tap and hold on the icon of the app you want to uninstall until a small cross appears on the top right corner. Click on this cross and you can uninstall the app.

However, for 3rd party apps where you either downloaded a .dmg and installed or however, it is not that straightforward. So in order to do that you can do the following. 

Example : 

Maheekas-MacBook-Pro:~ maheeka$ mdfind -name mackeeper
/Applications/MacKeeper.app
/Users/maheeka/Library/LaunchAgents/com.zeobit.MacKeeper.Helper.plist
/Users/maheeka/Library/Application Support/MacKeeper Helper

This lists down all folders and files in the system with name as "mackeeper". Delete each of these folders and files. 

Local FTP Server on OSX


To start a local FTP server : 
$ sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist

To stop local FTP server : 
$ sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist

To connect to FTP server : 
Maheekas-MacBook-Pro:~ maheeka$ ftp localhost
Trying ::1...
Connected to localhost.
220 ::1 FTP server (tnftpd 20100324+GSSAPI) ready.
Name (localhost:maheeka): maheeka
331 User maheeka accepted, provide password.
Password: 
230 User maheeka logged in.
Remote system type is UNIX.
Using binary mode to transfer files.

ftp> 

Once connected, most of normal file system related commands will work similarly.


ftp> pwd
Remote directory: /Users/maheeka
ftp> mkdir test
257 "test" directory created.
ftp> cd test
250 CWD command successful.
ftp> mkdir newfolder
257 "newfolder" directory created.
ftp> ls
229 Entering Extended Passive Mode (|||50051|)
150 Opening ASCII mode data connection for '/bin/ls'.
total 0
drwxr-xr-x  2 maheeka  staff  68 Feb  1 10:02 newfolder
226 Transfer complete.
ftp> pwd

Remote directory: /Users/maheeka/test

For a complete reference of ftp commands refer : http://krypted.com/commands/ftp-commands/

To access FTP Server from browser :

Type ftp://username:password@localhost/ on address bar.


Reference : 

November 13, 2014

Remote Debugging WSO2 ESB with IntellijIdea and Eclipse

This post assumes you are familiar with debugging concepts. The remote debugging will be explained using WSO2 ESB product.

What happens in remote debugging is that the debugging information of a running application is communicated with an IDE that has the source of the application. The application is not running from the source, and thus the term "remote" debugging. Similar to any normal debug scenario, where you would be running the application in debug mode from the IDE, you can have breakpoints, watch expressions, etc.

Read more about how remote debugging works in JVM at [1].

Let's proceed on how to debug WSO2 ESB.

Setup the Source for Debugging WSO2 ESB

There are a number of components in WSO2 stack that contribute to the complete WSO2-ESB product. Some of these components are : wso2-synapse, carbon-mediation, wso2-axis2-transport, carbon4-kernel, etc. You can download source of all these components at https://github.com/wso2.

Decide on the component(s) you need to debug, and import them to your preferred IDE (Eclipse or IntellijIdea). To do this :
  1. Clone the required component from the git repository : git clone <repository_url>
  2. Build the component : mvn clean install or mvn clean install -Dmaven.test.skip=true (to skip tests)
  3. To setup as an IDE project : mvn idea:idea (for IntellijIdea) or mvn eclipse:eclipse (for Eclipse)
  4. Add breakpoints as needed
  5. If debugging multiple components, 
    • Eclipse : Import as project to the same workspace and add breakpoints
    • Idea : Import as module to the same window and add breakpoints
    • Optionally, at the time of debug, when debugging takes you to the .class files, you can attach the relevant components as sources with "attach source" option and continue.
Note : 
If you want to debug message flow on ESB, add a breakpoint to receive(org.apache.axis2.context.MessageContext mc) method in org.apache.synapse.core.axis2.ProxyServiceMessageReceiver class in wso2-synapse. This is the start point to the message flow on ESB.

Remote Debugging WSO2-ESB

Step 1 : Start WSO2-ESB in debug mode

$ sh bin/wso2server.sh debug 5005
Please start the remote debugging client to continue...
JAVA_HOME environment variable is set to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
CARBON_HOME environment variable is set to /Users/maheeka/wso2esb-4.8.1
Listening for transport dt_socket at address: 5005

We have started the ESB in debug mode, and it listens now on port 5005 for a remote debugging client. 

Step 2 : Start Remote Debugging Client (IDE)

IntelliJIdea
  1. Run > Edit Configurations
  2. On the left panel, click on "+" and add a new Remote Configurations. Notice the port to be same as you give when starting ESB.
  3. Then Run > Debug 'wso2-synapse' to start the listener
  4. The application will now run as normal and stop at the breakpoints you have added




Eclipse
  1. Run > Debug Configurations
  2. Add a new Remote Java Application Configuration. Notice the port number to be same as you give when starting ESB.
  3. Click on Debug to start debugging 

November 10, 2014

Building WSO2 ESB 4.8.1 from source in OSX

WSO2 products are all built on top of WSO2 Carbon Kernel. This is the common ground for all products. Turing is the platform release name for WSO2 Carbon 4.2.0 and WSO2 ESB 4.8.1 is based on turing. Not all products of the WSO2 platform does not get released at the same time. Therefore, these products are released in chunks. ESB 4.8.1 comes under chunk 7 of the turing platform. Refer the release matrix to get more info on this [2].
Prerequisites : 
1. Install Java 1.6 and Maven 3
       If you have only 1.7 installed, you will have to install 1.6 on OSX. Unfortunately, there is no direct installation for 1.6. But this sorted out for me  since jdk 1.6 was automatically installed when I installed IntellijIdea
       At the moment, all WSO2 products are compiled on Java 1.6 and is supported up to 1.7. This is why we need to build the source on 1.6.
2. Checkout Source (Orbit, Kernel, Platform)

Building the Source : 


Start building in order Orbit > Kernel > Platform (chunk 07) repos respectively.


To build ESB 4.8.1, you need to build wso2carbon-platform/product-releases/chunk-07 as Platform in above.


The distribution will be created in :

wso2carbon-platform/products/esb/4.8.1/modules/distribution/target/(esb.zip)

When building, since it will take a lot of time, and to avoid unit test failures from building the product, skip unit tests when building.


mvn clean install -Dmaven.test.skip=true


Build ESB only :

If you need to build only ESB, build at wso2carbon-platform/products/esb with mvn clean install -Dmaven.test.skip=true


Another option is to comment out other product modules in platform/trunk/pom.xml and rebuilding in Orbit > Kernel > Platform in order.


Encountered Errors : 
  1. WSS4 maven install fails > You need to compile in Java 1.6
  2. [WARNING] Error injecting: org.apache.maven.reporting.exec.DefaultMavenReportExecutor > Set maven-site plugin version to 3.3 in all places [4]
Environment : 

October 26, 2014

Grep - Find a text in file (Unix/Linux)


To find the text files containing a particular string :

grep -l "maheeka" *.txt

Search in current directory :
grep -lr "maheeka" . 

To view the occurrences of the string in the files, use without "-l" option

Reference:
http://hints.macworld.com/article.php?story=20001105214242629

October 15, 2014

Find and Duplicate with Regex in Notepad++

In order to duplicate a text (instead of find and replace, find and duplicate) use regex feature provided with Notepad++ as follows.

Assume the following content in an XML :
 <person firstname="ann" /> 
Now lets convert this to following :
<person firstname="ann" nickname="ann"/>
So to do the above you need to do as below.
  • Go to Find and Replace window
  • In Find text enter : firstname="(.*)"
  • In Replace with text enter : firstname="\1" nickname="\1"


March 2, 2014

Git - Useful Commands

Commit Changes without Staging Stage : 
$ git commit -a -m "committing without staging"

To Push to a Branch : 

Assuming a branch is created and checked out :
git push origin branch

If pushing to a non-default branch, you need to specify the source ref and the target ref :
git push origin branch1:branch2


Fetch from Original Forked Repository or any other Related Repository : 

First you need to add the desired repository as a remote :

$ git remote add upstream https://github.com/wso2/product-esb

This remote will be referred to as 'upstream' now. Then you can fetch from this upstream. You can verify the added remote repositories as below :

$ git remote -v
origin https://github.com/maheeka/product-esb.git (fetch)
origin https://github.com/maheeka/product-esb.git (push)
upstream https://github.com/wso2/product-esb (fetch)
upstream https://github.com/wso2/product-esb (push)

Now merge the changes to the local branch :
$ git merge upstream/master master

upstream/master is the upstream branch that you need to merge from and master is your local branch. If you are merging to another branch use that branch name instead of master.
$ git merge upstream/branch branch

Now push these commits to your repository :
$ git push origin master


Checkout a Branch from Upstream :

Create a branch tracking upstream branch and checkout :
$ git checkout -b branch1 upstream/branch1
Branch branch1 set up to track remote branch branch1 from upstream.
Switched to a new branch 'branch1'

Now you can commit and push as you would for any other branch.

Edit Committed (and Pushed) Commit Message : 
  1. $git commit --amend -m "new commit message"
  2. $git push origin master -f

Adding an Existing Project to git (bitbucket) :
  1. Create a project in bitbucket - you will get "clone url"
  2. Issue the following commands on git bash :

Initialize git repository : 
leo@LEODEN ~ $ git init Initialized empty Git repository in C:/Users/leo/.git/ 

Navigate to the project location
leo@LEODEN ~ (master) $ cd C:/Users/leo/git/timesheetApp/TimeSheet 

Initialize existing git repository
leo@LEODEN ~/git/timesheetApp/TimeSheet (master) $ git init Reinitialized existing Git repository in c:/Users/leo/git/timesheetApp/TimeSheet /.git/

Add(Stage) all files and folders
leo@LEODEN ~/git/timesheetApp/TimeSheet (master) $ git add * 

Check status (optional) which will list down the files to be committed
leo@LEODEN ~/git/timesheetApp/TimeSheet (master) $ git status 
# On branch master # 
# Initial commit # 
# Changes to be committed: 
# (use "git rm --cached <file>..." to unstage) # 
# new file: .classpath 
# new file: .project 
# new file: .settings/org.eclipse.jdt.core.prefs 
# new file: .settings/org.eclipse.jdt.ui.prefs .....

Commit the staged
leo@LEODEN ~/git/timesheetApp/TimeSheet (master) $ git commit -m "first project add" [master (root-commit) 71447ea] 
first project add 56 files changed, 707 insertions(+) 
create mode 100644 .classpath 
create mode 100644 .project ..... 

Check the status (optional) which will show that all are committed
leo@LEODEN ~/git/timesheetApp/TimeSheet (master) $ git status 
# On branch master nothing to commit, working directory clean 

Push the changes to bitbucket repository
leo@LEODEN ~/git/timesheetApp/TimeSheet (master) $ git push -u origin master 
Password for 'https://maheeka@bitbucket.org': 
Counting objects: 90, done. Delta compression using up to 4 threads. 
Compressing objects: 100% (71/71), done. 
Writing objects: 100% (90/90), 1.47 MiB | 14 KiB/s, done. 
Total 90 (delta 5), reused 0 (delta 0) To https://maheeka@bitbucket.org/maheeka/timetracker.git * [new branch] master -> master Branch master set up to track remote branch master from origin.


Reference : 

August 16, 2012

Access outer class members from inner class

The following example shows how to access outer class members from inner class
public class OuterClass{

   public void method() {
      //do something
   }

   class InnerClass {

      public void innerMethod() {
          OuterClass.this.method();
         //do something
      }
   }
}

August 8, 2012

Right align tabs in JTabbedPane

Some useful tips for aligning tabs in JTabbedPane :-

Align tabs to right
pnlMainTabbedPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
Place tabs on right of the JTabbedPane

pnlMainTabbedPane.setTabPlacement(JTabbedPane.RIGHT)

August 7, 2012

Java Swing UI Settings

To set global UI settings in Java Swing, use UIManager and set the properties as needed. All components have their respective keys and default values. For a complete list of properties, refer http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html

These settings should be done before creating the JFrame where all these components are put into.

Example :
UIManager.put("Button.background", Color.RED);
UIManager.put("Button.font", new FontUIResource(new Font("Arial", Font.BOLD, 12)));

July 23, 2012

OLE Exception in Eclipse for MSOffice files






If you have got the above error message when you try to open a MS Office file in eclipse, that means your OLE editor is not working in eclipse. When i googled I found that this is a common problem for Excel files. So I suggest to set the Excel files to open in Excel editor instead of OLE editor. So, do the following ;

  1. Go to Eclipse -> Window -> Preference -> General -> Editors -> File Associations



  2. Add the .xls file type (or any other file type you want)


  3. Choose the Excel WorkBook 97-2003 WorkSheet (or any other file editor you want)



  4. Click OK-> OK

  5. Now the .xls file will opens in Ms Excel

July 4, 2012

JDOM Document to String

XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
String scenarioStr = outputter.outputString(jdomDoc);


Reference : http://cafeconleche.org/books/xmljava/chapters/ch14s04.html

June 29, 2012

Java Varargs - Unlimited parameters to a Java method

When you cannot decide the number of parameters you need for a method, varargs becomes the solution. Earlier, if we couldn't determine such, we had to use a collection as a parameter to help with this scenario. But varargs simplifies this.

Varargs does use an array underneath, but using varargs syntax hides the process.

public static String format(String pattern,
                                Object... arguments);

Example :

If you need to write a file name extension filter for a number of extensions, you can use this method of defining the method.

public FileNameExtensionFilter(String description, String... extensions) {

Read more on varargs at :
http://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html

JFileChooser - Useful Tips

Set Starting Directory
JFileChooser fileSaver = new JFileChooser();
String cpath = "C:/MWork/Test1/script/";
File f1 = new File(cpath);
fileSaver.setCurrentDirectory(f1);

File Filter
FileNameExtensionFilter filter = new FileNameExtensionFilter("eXtensible Markup Language file (*.xml) ", "xml");
fileSaver .setFileFilter(filter);

Default File Save Name
jFileChooser.setSelectedFile(new File("untitled.xml"));

June 22, 2012

Get Frame of a Component


In order to find the frame that contains a component, it is necessary to walk up the component's parents until the frame is encountered. SwingUtilities.getRoot() is a convenience method that finds the frame.

This example implements an action that finds and hides the frame of the component that triggered the action. See also Creating a JButton Component.

// Create an action
Action action = new AbstractAction("Action Label") {
  
    // This method is called when the action is triggered
    public void actionPerformed(ActionEvent evt) {
        
        Component c = (Component)evt.getSource();

        // Get the frame
        Component frame = SwingUtilities.getRoot(c);

        // Hide the frame
        frame.setVisible(false);
    }
};

http://www.exampledepot.com/egs/javax.swing/frame_FrameFind.html

June 21, 2012

XML Editor for Eclipse




Edit:
Make sure you go to Open With -> XML Editor to make XML Editor the default for that XML

June 19, 2012

Focus to newly added JComponent in Frame

int h = (int) pnlPrerequisites.getBounds().getHeight();
Component frame = SwingUtilities.getRoot(pnlPrerequisites);
System.out.println(h + "=" + frame.getHeight());
if (h > frame.getHeight()) {
    scrollPnlPre.setViewportView(p);
    // scrollPnlPre.getViewport().setView(p);
}

Problem : this removes the scroll