How to find and remove files in Ubuntu.

Hi,

Sometimes we want to find the files that are not needed and remove all of them. But instead of removing one by one, we can do it very easily with one command.

Workflow.

I needed to remove all the .iml files in my project for a deployment. So I executed a find command.

find . -name '*.iml' 

./SenseMe/feature/feature/org.wso2.iot.senseme.feature.iml
./SenseMe/feature/senseme-feature.iml
./SenseMe/senseme.iml
./SenseMe/component/plugin/org.wso2.iot.senseme.plugin.iml
./SenseMe/component/ui/org.wso2.iot.senseme.ui.iml
./SenseMe/component/api/org.wso2.iot.senseme.api.iml
./SenseMe/component/senseme-component.iml
./SenseMe/component/analytics/org.wso2.iot.senseme.analytics.iml'

Now, I want to remove these files.

rm ./SenseMe/feature/feature/org.wso2.iot.senseme.feature.iml

Repeat for all the other files. It’s not a big issue as I have only 8 files. But in real cases where there are 100s of files, it is a real headache.

rm ./SenseMe/feature/senseme-feature.iml
rm ./SenseMe/senseme.iml
rm ./SenseMe/component/plugin/org.wso2.iot.senseme.plugin.iml
rm ./SenseMe/component/ui/org.wso2.iot.senseme.ui.iml
rm ./SenseMe/component/api/org.wso2.iot.senseme.api.iml
rm ./SenseMe/component/senseme-component.iml
rm ./SenseMe/component/analytics/org.wso2.iot.senseme.analytics.iml

But, there is an easy way to do this. How easy is it? Well, you only have to write one line of commands. ūüôā

find . -name '*.iml' -exec rm {} \;

UPDATE : Replaced \ ; with \;
There should be no space between \ and ;.

What is does?

  • find . -name ‘*.iml’ :- ¬†Find in the current directory for files which matches the given pattern.
  • -exec rm {} ¬†\ ¬†;¬† :- ¬†Executes rm command on each of the results from find command.

Note:

You can use standard ways of find and rm commands and -exec does the execution.

Examples:

Find all files in a directory and remove them.

find . -type f -name 'File Name Pattern' -exec rm {} \ ;

Find directories and remove them

find . -name 'File/ Dir Name Pattern' -exec rm -rf {}  \ ;

For more info: please refer command reference for find and rm.

Cheers.

 

 

 

Advertisements

How to specify the web browser manually in selenium testing.

Hay,

In this short article, I would like to show you how to specify a custom web browser when running UI integration tests using selenium.

This extremely necessary when the webDriver does not support the current version of particular web browser.

In situations like this what we normally do is, uninstall the current version of web browser and install the older version. Then we have to use that browser or any other browser for our day-to-day works. It’s annoying sometimes.

So with this method, we do not want to uninstall the current browser that we have.


Here are the steps. (for firefox and maven build)

  • Download the required version of web browser. (in my case it was Mozilla Firefox v31).
  • Extract it.
  • Add the following parameters to your maven build.
     -Dwebdriver.firefox.bin=path_to_firefox/firefox
    Ex:
     mvn clean install  -Dwebdriver.firefox.bin=/home/menaka/firefox/firefox

    Cheers….

How to create a simple XML structure in Java?

Hi guys,

Here I create a simple XML structure in Java.

There are several methods to create an XML file in Java.

  1. Using Java Document builder
  2. Using 3rd party libraries
  3. Serializing Java object to xml  etc.

Here I use Java DocumentBuilder to create the following xml.

<bookstore>  
   <books>      
      <book>
            <name>Book_A</name>
            <author>Author_A</author>
            <isbn>abcdefg123456</isbn>
        </book>
   </books>
</bookstore>

Here is the Java code to create the above XML.

public static void main(String args[]) {
    try {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

        /**
         * Starts the root element.
         * 
         * 
         * */
        Document doc = docBuilder.newDocument();
        Element root = doc.createElement("bookstore");
        doc.appendChild(root);

        /**
         * Creating books element.
         * */
        Element books_element = doc.createElement("books");
        root.appendChild(books_element);

        /**
         * Create individual book
         * */
        Element book = doc.createElement("book");
        books_element.appendChild(book);

        /**
         * Adding book properties
         * */
        Element title = doc.createElement("name");
        title.appendChild(doc.createTextNode("Book_A"));
        book.appendChild(title);

        Element author = doc.createElement("author");
        author.appendChild(doc.createTextNode("Author_A"));
        book.appendChild(author);

        Element isbn = doc.createElement("isbn");
        isbn.appendChild(doc.createTextNode("abcdefg123456"));
        book.appendChild(isbn);

        /**
         * Writes the content of the doc to a XML file.
         * */
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(new File("bookstore.xml"));
        transformer.transform(source, result);

        /**
         * Writes the result to console. (System.out)
         * */
        StreamResult res = new StreamResult(new OutputStreamWriter(System.out));
        transformer.transform(source, res);

    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    } catch (TransformerException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
}

The result will be written to bookstore.xml.

Spring Boot – How to create a simple Spring Boot project in IntelliJ IDEA?

 

Hi,

There are several ways to create a Spring Boot application.

  1. Through web-based interface
  2. Via Spring Tool Suit
  3. Via IntelliJ IDEA
  4. From Spring Boot CLI

Let’s take a look at how to start creating Spring Boot applications using IntelliJ IDEA. Here I’ll show you some quick and easy steps to do it.

For this you will need IntelliJ IDEA commercial edition as the community edition does not give you these functionalities.

Ok. Let’s get started.

  1. Open New Project dialog box by File -> New -> ProjectScreenshot from 2016-02-04 18:41:19
  2. Choose Spring Initialize from the left and click next
  3. Enter the following information.
    1. Name
    2. Type : There are 4 types. (Here I select Maven Project)
      1. Maven Project
      2. Maven POM
      3. Gradle Project
      4. Gradle Config
    3. Packaging : Whether you want to build a war or a jar file
    4. Java version
    5. Language : Two options (Java and Groovy)
    6. Then give group id, artifact id and version for your Maven project
    7. Give description and package name and click Next.Screenshot from 2016-02-04 18:42:09
  4. In next window you can select the dependencies that you want to use in your project. There is a huge list of dependencies. Go through them and select what you need and click Next.Screenshot from 2016-02-04 18:42:29
  5. In the next dialog give the project name and location and click Finish.Screenshot from 2016-02-04 18:42:47
  6. That’s it. Now IDEA will create a new Spring Boot project for you.Screenshot from 2016-02-04 18:43:02

As this is a Maven project IDEA will download the necessary dependencies and you are ready to go.

Cheers….!!!

For more information:-

Visit Spring official web site.

How to access localhost via Android Emulator?

Some times we need to connect to a server running in our PC’s localhost, via android emulator for several reasons.

But we cannot access it by typing URL like,

http://localhost:portNo

This is impossible because, when ever we call localhost, it refers to the same system itself. So what is the URL that should be entered?

The correct URL is as follows….

http://10.0.2.2:portNo

According to the Android documentation, the ip address 10.0.2.2 is an alias to the loopback address of the host machine.

 

 

Apache Taverna Language Command Line Tool Documentation – Inspection

One of the main functionalities of the Taverna Language is “inspecting workflows”.

A workflow has several features.

There are processors, service types and etc.

The command line tool is capable of listing those features which are in a workflow bundle.

Supported workflow bundle formats :- .t2flow and .wfbundle

Usage

tavlang inspect <--options> <secondary_options> [arguments] input_files

Options

  • – – servicetypes –¬†List the service types used in workflow
  • – -processornames –¬†List a tree of processor names used in workflow

Secondary Options

  • -l, – – log – Save results in a log file

Example 1:

$tavlang inspect --servicetypes helloworld.wfbundle
Service types used in helloworld.wfbundle :

http://ns.taverna.org.uk/2010/activity/constant
**************************************************
$tavlang inspect --processornames helloworld.wfbundle
Processor tree of helloworld.wfbundle 
+ Hello_World
 - hello

Example 2:-

$tavlang inspect --processornames t2flow/as.t2flow
Processor tree of t2flow/as.t2flow 
+ Workflow1
 - Concatenate_two_strings
 - Concatenate_two_strings_2
 - Concatenate_two_strings_3
 - Concatenate_two_strings_4
 - Create_Lots_Of_Strings
 - Echo_List
 - String_constant
 + Workflow19
 - Concatenate_two_strings
 - String_constant
 - string1_value
$tavlang inspect --servicetypes /home/menaka/conv/aaa/workflows/t2flow/helloanyone.t2flow
Service types used in /home/menaka/conv/aaa/workflows/t2flow/helloanyone.t2flow :

http://ns.taverna.org.uk/2010/activity/beanshell
http://ns.taverna.org.uk/2010/activity/constant

**************************************************

Apache Taverna Language Command line tool documentation – Workflow Statistics

A workflow contains several resources.

  • Processors
  • Input ports
  • Output ports
  • Data links
  • Control links

The Taverna Language API (scufl2-api) has several methods to set and retrieve those resources when ever needed.

The command line tool is also capable of listing workflow file resources.

Usage:

$tavlang stats [options] input_files

Options:

  • -l, – – log : Save results in¬†a log file
  • -v, – – verbose : verbose mode

Supported file formats: .t2flow and .wfbundle

Example usage: There are two modes of operations.

Verbose mode:

$tavlang stats -v ../../../helloworld.wfbundle
>>> Statistics of the workflow bundle: helloworld.wfbundle <<<
Name of the workflow = Hello_World
 |--> Number of Processors = 1
 | |--> Processors: 
 |      |--> hello
 |
 |--> Number of Data Links = 1
 | |--> Data Links
 |      |--> DataLink value=>greeting
 |
 |--> Number of Control Links = 0
 |--> Number of Input ports = 0
 |--> Number of Output Ports = 1
 | |--> Output Ports
 |      |--> OutputWorkflowPort "greeting"
$tavlang stats -v ../../../defaultActivitiesTaverna2.wfbundle
>>> Statistics of the workflow bundle: defaultActivitiesTaverna2.wfbundle <<<
Name of the workflow = Workflow1
 |--> Number of Processors = 21
 | |--> Processors: 
 |      |--> Beanshell
 |      |--> Nested_workflow
 |      |--> Rshell
 |      |--> Send_an_Email
 |      |--> SpreadsheetImport
 |      |--> String_constant
 |      |--> TavernaResearchObject
 |      |--> biomart
 |      |--> localWorker
 |      |--> localWorker_bytearray
 |      |--> mobyObject
 |      |--> mobyService
 |      |--> run
 |      |--> run_input
 |      |--> run_output
 |      |--> setWorkflows
 |      |--> soaplab
 |      |--> wsdl_document
 |      |--> wsdl_rpc
 |      |--> wsdl_secured
 |      |--> xmlSplitter
 |
 |--> Number of Data Links = 3
 | |--> Data Links
 |      |--> DataLink parameters=>input
 |      |--> DataLink output=>parameters
 |      |--> DataLink queryStatusOutput=>input
 |
 |--> Number of Control Links = 0
 |--> Number of Input ports = 0
 |--> Number of Output Ports = 0

Name of the workflow = Workflow4
 |--> Number of Processors = 1
 | |--> Processors: 
 |      |--> String_constant
 |
 |--> Number of Data Links = 2
 | |--> Data Links
 |      |--> DataLink value=>out0
 |      |--> DataLink in0=>out0
 |
 |--> Number of Control Links = 0
 |--> Number of Input ports = 1
 | |--> Input Ports
 |      |--> InputWorkflowPort "in0"
 |
 |--> Number of Output Ports = 1
 | |--> Output Ports
 |      |--> OutputWorkflowPort "out0"

Normal mode:

$tavlang stats ../../../helloworld.wfbundle
>>> Statistics of the workflow bundle: helloworld.wfbundle <<<
Name of the workflow = Hello_World
 |--> Number of Processors = 1
 |--> Number of Data Links = 1
 |--> Number of Control Links = 0
 |--> Number of Input ports = 0
 |--> Number of Output Ports = 1
$tavlang stats ../../../defaultActivitiesTaverna2.wfbundle
>>> Statistics of the workflow bundle: defaultActivitiesTaverna2.wfbundle <<<
Name of the workflow = Workflow1
 |--> Number of Processors = 21
 |--> Number of Data Links = 3
 |--> Number of Control Links = 0
 |--> Number of Input ports = 0
 |--> Number of Output Ports = 0

Name of the workflow = Workflow4
 |--> Number of Processors = 1
 |--> Number of Data Links = 2
 |--> Number of Control Links = 0
 |--> Number of Input ports = 1
 |--> Number of Output Ports = 1

Save results in a log file

Example:

$tavlang stats -l ../../results.txt ../../../helloworld.wfbundle
>>> Statistics of the workflow bundle: helloworld.wfbundle <<<
Name of the workflow = Hello_World
 |--> Number of Processors = 1
 |--> Number of Data Links = 1
 |--> Number of Control Links = 0
 |--> Number of Input ports = 0
 |--> Number of Output Ports = 1

Results were saved into ../../results.txt