Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, July 1, 2012

Resolve dependencies in Apache Ant using Apache Ivy

Most of you have experience that we can use Apache Maven to automate build processes. Also we can use Apache Ant forthe same process. But when we use Maven we can resolve our dependencies of the project easily. The only thing required is adding your dependencies to the pom.xml as given bellow.

<dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>compile</scope>
        </dependency>
</dependencies>

But when use Apache Ant, we have to do some specifics tasks to resolve dependencies in a intelligent manner. Why I say in a intelligent manner
means if we know all the dependencies exactly, we can use following command to download all the jar files needed to our project.
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true"/>
But if don't know all the dependency tree, we are in trouble. So in that case we can use Apache Ivy to resolve all the dependencies. Please look at the given Apache Ant build.xml file.
<project default="compile-all" xmlns:ivy="antlib:org.apache.ivy.ant">
    <property name="classes" value="classes"/>
    <property name="src" value="src"/>
    <property name="ivy.install.version" value="2.0.0-beta1" />
    <property name="ivy.jar.dir" value="${basedir}/ivy" />
    <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
    <path id="class.path">
        <pathelement path="${java.class.path}"/>
        <fileset dir="./lib">
            <include name="**"/>
        </fileset>
    </path>
    <target name="clean">
        <delete dir="${classes}"/>
    <delete dir="${lib}"/>
    <delete dir="${ivy}"/>
    </target>
    <target name="init" depends="clean">
        <mkdir dir="${classes}"/>
    </target>
    <!-- #######Downloading and Installing Apache Ivy#######-->
    <target name="download-ivy" unless="skip.download" depends="init">
        <mkdir dir="${ivy.jar.dir}"/>
        <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true"/>
    </target>
    <target name="install-ivy" depends="download-ivy" >
        <path id="ivy.lib.path">
            <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
    </target>    
    <!-- ######################################-->
    <!-- ###########Resolving Dependencies Using Ivy######-->
    <target name="getDependency" depends="install-ivy">
        <ivy:retrieve />
    </target> 
    <!-- ######################################-->
    <target name="compile-all" depends="getDependency">
        <javac debug="on" destdir="${classes}">
            <src path="${src}"/>
            <classpath refid="class.path"/>
        </javac>
    </target>       
</project>  
Here in this project we need, Junit and Spring Framework for compile and run the project. To get those jars to our project we use Ivy. First of all we have to get Ivy downloaded. After downloading Ivy we can retrieve our dependencies. Those dependencies have to be specified in file called ivy.xml which exists in the working directory. For this project this is the ivy.xml,
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organization="andunslg" module="my_project"/>
    <dependencies>
        <dependency org="junit" name="junit" rev="4.0" transitive="false"/> 
        <dependency org="org.springframework" name="spring-context" rev="3.0.7.RELEASE" transitive="false"/>
        <dependency org="org.springframework" name="spring-core" rev="3.0.7.RELEASE" transitive="false"/>
        <dependency org="org.springframework" name="spring-beans" rev="3.0.7.RELEASE" transitive="false"/>         
    </dependencies>
</ivy-module>
Here you can see that dependencies are specified in our manner ,
<dependency org="junit" name="junit" rev="4.0" transitive="false"/> 
In that org, name, version are very important. Because Ivy use those details to download the jars from the public repo. Also in default Ivy download all the transitive dependencies of the jars. We can stop that by saying transitive="false". Ivy will download all the jars to a called lib in the working directory. After that we can use that in our class path. If you need to find org, name, version of your jars, pleas use this link. http://mvnrepository.com/ In that details are given in this way,
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>3.0.7.RELEASE</version>
</dependency>
Here groupId=org, artifactId=name. So you can create your ivy.xml using those details. Hope this helps you.Contact me for further clarifications. The follwoing shell output show how this build.xml works,

andunslg@andunslg-Dell-System-Vostro-3450:~/temp$ ant
Buildfile: /home/andunslg/temp/build.xml

clean:
   [delete] Deleting directory /home/andunslg/temp/classes

init:
    [mkdir] Created dir: /home/andunslg/temp/classes

download-ivy:
      [get] Getting: http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.0.0-beta1/ivy-2.0.0-beta1.jar
      [get] To: /home/andunslg/temp/ivy/ivy.jar
      [get] Not modified - so not downloaded

install-ivy:

getDependency:
No ivy:settings found for the default reference 'ivy.instance'.  A default instance will be used
no settings file found, using default...
[ivy:retrieve] :: Ivy 2.0.0-beta1 - 20071206070608 :: http://ant.apache.org/ivy/ ::
:: loading settings :: url = jar:file:/home/andunslg/temp/ivy/ivy.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:retrieve] :: resolving dependencies :: wso2#spring;working@andunslg-Dell-System-Vostro-3450
[ivy:retrieve]     confs: [default]
[ivy:retrieve]     found junit#junit;4.0 in public
[ivy:retrieve]     found org.springframework#spring-context;3.0.7.RELEASE in public
[ivy:retrieve]     found org.springframework#spring-core;3.0.7.RELEASE in public
[ivy:retrieve]     found org.springframework#spring-beans;3.0.7.RELEASE in public
[ivy:retrieve] :: resolution report :: resolve 1517ms :: artifacts dl 20ms
    ---------------------------------------------------------------------
    |                  |            modules            ||   artifacts   |
    |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
    ---------------------------------------------------------------------
    |      default     |   4   |   0   |   0   |   0   ||   4   |   0   |
    ---------------------------------------------------------------------
[ivy:retrieve] :: retrieving :: wso2#spring
[ivy:retrieve]     confs: [default]
[ivy:retrieve]     0 artifacts copied, 4 already retrieved (0kB/30ms)

compile-all:
    [javac] /home/andunslg/temp/build.xml:39: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 1 source file to /home/andunslg/temp/classes

BUILD SUCCESSFUL
Total time: 12 seconds
           

Friday, January 20, 2012

Hacking JOSH – Operating System Development in Assembly

In this project I was able to develop a simple OS which have kernel and a Shell by configuring a given simple OS. You can find that preliminary OS  by reading this article,


http://asiri.rathnayake.org/articles/hacking-josh-operating-system-tutorial/

I implemented a new command for my operating system which prints hardware information about the computer.To achieve that functionality after some research work over the internet and experts of this area I found several waysto get hardware information using x86 Assembly language.
They were BIOS interrupt calls, CPUID instruction, BIOS data area, SMBIOS – Collection of tables which can provides you hardware information. In these methods I choose interrupt calls, CPUID instruction to display hardware information of the system.
In my function which I add to existing kernel  it can show Processor Brand, Processor Type, Ram Size, system date and time, check the availability of serial ports, floppy drives, printers, co-processors and mouse.
Following articles will explain the steps which I took to develop this operating system, It will explain step by step to develop a OS like that.

http://www.insightforfuture.blogspot.com/2010/11/useful-techniques-in-assembly.html
http://www.insightforfuture.blogspot.com/2010/11/x86-assembly-if-else-control-structures.html
http://www.insightforfuture.blogspot.com/2010/11/bios-interrupt-calls-to-get-hardware.html
http://www.insightforfuture.blogspot.com/2010/11/find-hardware-infodo-you-know-how.html
http://www.insightforfuture.blogspot.com/2010/11/smbios-gives-hardware-specifications.html

Next I will Explain the source code of this new functionality,

This is the shell command which is responsible for run the hardware info;

    hwi:                    ;;;;;;;;This is the place hardware info Procedure Starts
    mov SI,strCmd0               
    mov DI,hw               
    call os_string_strincmp            ;check is the entered command is HW_Info
    jc    hardware_info            ;if it is call the hardware info function
    jmp _cmd_ver                ;else go to next shell command
    else:
    jmp _cmd_done ;;;;;;;;;End of the Hardware info call




This is the code where the original functionality lies, These assembly code are responsible to retrieve hardware info by using interrupt calls.




;;;;;;;;;;;;;;Start of Hardware Info;;;;;;;;;;;;;;

hardware_info:

    mov si,ent   
    call    _disp_str   

    mov si,hwinfo
    call    _disp_str   

    mov si,ent   
    call    _disp_str   

;;;;;;;;;;;;Processor Info Display;;;;;;;;;;;;;;;;   

    mov si,pinfo
    call    _disp_str

    mov eax,0
    cpuid
    mov [vendor_id],ebx            ;getting the cpu brand from ebx,ecx,edx
    mov [vendor_id+4],edx
    mov [vendor_id+8],ecx
    mov si,processor
    call    _disp_str
    mov si,vendor_id
    call    _disp_str

    mov si,ent   
    call    _disp_str

    mov si,processort
    call    _disp_str

    mov eax,80000002h
    cpuid
    mov [processor_type],eax        ;getting the cpu type string  brand from ebx,ecx,edx,eax
    mov [processor_type+4],ebx
    mov [processor_type+8],ecx
    mov [processor_type+12],edx
    mov si,processor_type
    call    _disp_str

    mov eax,80000003h
    cpuid
    mov [processor_type1],eax
    mov [processor_type1+4],ebx
    mov [processor_type1+8],ecx
    mov [processor_type1+12],edx
    mov si,processor_type1
    call    _disp_str       
   
    mov eax,80000004h
    cpuid
    mov [processor_type2],eax
    mov [processor_type2+4],ebx
    mov [processor_type2+8],ecx
    mov [processor_type2+12],edx
    mov si,processor_type2
    call    _disp_str

    mov si,ent   
    call    _disp_str

    ;;;;;;;;;;;;;;;RAM Info Display;;;;;;;;;;;;;;;;;;

    mov si,rinfo
    call    _disp_str
    mov si,ram   
    call    _disp_str

    MOV AX, 0xE801
    INT 0x15                ;calling the intruupt to get ram size in 64kb blocks
    call hex2dec

    mov si,ent   
    call    _disp_str

    ;;;;;;;;;;;;;;;Other Info Display;;;;;;;;;;;;;;;;;
    int 11h                ;calling the intruupt to get pheriperal device info
    mov cx,ax

    mov si,oinfo
    call    _disp_str

    ;;;;;;;;;;;;;;Check for Floppy Drive;;;;;;;;;;;;;;

    and ax,1h
    cmp ax,0h
    jz ifblock0
    jmp elseblock0
    ifblock0:
    mov si, floppyNotPresent
    call    _disp_str
        jmp end0
    elseblock0:
    mov si, floppyPresent
    call    _disp_str
    end0:
    mov ax,cx   
   
    ;;;;;;;;;;;;;;Check for Math Co-Processor;;;;;;;;

    and ax,2h
    cmp ax,0h
    jz ifblock1
    jmp elseblock1
    ifblock1:
    mov si, mathaNotPresent
    call    _disp_str
        jmp end1
    elseblock1:
    mov si, mathaPresent
    call    _disp_str
    end1:
    mov ax,cx   

    ;;;;;;;;;;;;;Check for Joystick;;;;;;;;;;;;;;;;;;

    and ax,800h
    cmp ax,0h
    jz ifblock2
    jmp elseblock2
    ifblock2:
    mov si, joyNotPresent
    call    _disp_str
        jmp end2
    elseblock2:
    mov si, joyPresent
    call    _disp_str
    end2:
    mov ax,cx   

    ;;;;;;;;;;;;;Check for Serial Printer;;;;;;;;;;;;;

    and ax,1000h
    cmp ax,0h
    jz ifblock3
    jmp elseblock3
    ifblock3:
    mov si, printerNotPresent
    call    _disp_str
        jmp end3
    elseblock3:
    mov si, printerPresent
    call    _disp_str
    end3:
    mov ax,cx   

    ;;;;;;;;;;;;Check for Serial Ports;;;;;;;;;;;;;;;;

    and ax,700h

    cmp ax,0h
    jz ifblock4_s0
    ifblock4_s0:
    mov si, s0
    call    _disp_str
        jmp end4 
    
    cmp ax,100h
    jz ifblock4_s1
    ifblock4_s1:
    mov si, s1
    call    _disp_str
        jmp end4

    cmp ax,200h
    jz ifblock4_s2
    ifblock4_s2:
    mov si, s2
    call    _disp_str
        jmp end4
    cmp ax,300h
    jz ifblock4_s3
    ifblock4_s3:
    mov si, s3
    call    _disp_str
        jmp end4
    cmp ax,400h
    jz ifblock4_s4
    ifblock4_s4:
    mov si, s4
    call    _disp_str
        jmp end4
    cmp ax,500h
    jz ifblock4_s5
    ifblock4_s5:
    mov si, s5
    call    _disp_str
        jmp end4
    cmp ax,600h
    jz ifblock4_s6
    ifblock4_s6:
    mov si, s6
    call    _disp_str
        jmp end4

    cmp ax,700h
    jz ifblock4_s7
    ifblock4_s7:
    mov si, s7
    call    _disp_str
        jmp end4
    end4:
    mov ax,cx   

    ;;;;;;;;;;;;;;Check for Mouse;;;;;;;;;;;;;;;;

     int 33h                  ; call interrupt 33h function 0
     cmp ax,0ffffh            ; compare AX and FFFFh (installed)
     jz endmouse              ; it is? Jump to the end!
     mov si, nmouse
     call    _disp_str
     jmp end5
    endmouse:
     mov si, mouse
     call    _disp_str    
    end5:

    ;;;;;;;;;;;;;;Display Date and Time;;;;;;;;;;;;

    call os_get_date_string
    mov si,date_time
    call    _disp_str        
    mov si, BX
    call    _disp_str
    call os_get_time_string
    mov si, space
    call    _disp_str
    mov si, BX
    call    _disp_str

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
jmp else

If you want further info about this please contact me.

Friday, October 15, 2010

Thread Programming In Linux in C++

For CS2012 me did this experimental programming thing. It is not easy to do Thread programming in C++, In Java it is really easy.

In C++ you have to use special library called pthread.h.The Following link gives better description about it. If your Linux c++ dosent have this you have to download it.

Hear is my reference material where I learn threading.

After installing it you can do your programming easily.

After Learning Implemented the Dining Philosopher Problem. If you are interested contact me.