Thursday, September 24, 2015

Jenkins on Mac...


Hi Guys,

Now a days Continuous Integration [CI] has become an eternal part of software development.
This allows user to :
a) Integrate and share their code in a repository
b) Make error checks in builds
c) Automatic generation of builds [includes packaging and signing]
d) Generating artifacts

To enjoy the prospects of CI we are going to use a tool named JENKINS.
Jenkins is a server based system which provide CI services

SCM tools with which Jenkins can be integrated with are:
Git, Mercurial, SVN, CVS etc..


Lets first start with configuring Jenkins on MAC machine.
You can use OSX installer with nice GUI or go ahead with Homebrew

I will prefer to go ahead with Homebrew so here we go

1) Open Terminal and go ahead with below mentioned commands

********** HOMEBREW SETUP **********



swati:~ admin$ 
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin14/rbconfig.rb:213: warning: Insecure world writable dir /usr in PATH, mode 040777

==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew

==> Downloading and installing Homebrew...
remote: Counting objects: 3744, done.
remote: Compressing objects: 100% (3579/3579), done.
remote: Total 3744 (delta 40), reused 567 (delta 28), pack-reused 0
Receiving objects: 100% (3744/3744), 3.14 MiB | 240.00 KiB/s, done.
Resolving deltas: 100% (40/40), done.
From https://github.com/Homebrew/homebrew
 * [new branch]      master     -> origin/master
HEAD is now at 98c28ae gst-plugins-bad: can optionally use srtp

==> Installation successful!

==> Next steps
Run `brew help` to get started

********** JENKINS DOWNLOAD **********


swati:~ admin$ brew install jenkins

After installing Jenkins Homebrew provides you some useful tips as well

==> Downloading https://homebrew.bintray.com/bottles/jenkins-1.629.yosemite.bottle.tar.gz
######################################################################## 100.0%

==> Pouring jenkins-1.629.yosemite.bottle.tar.gz
==> Caveats
Note: When using launchctl the port will be 8080.

To have launchd start jenkins at login:
  ln -sfv /usr/local/opt/jenkins/*.plist ~/Library/LaunchAgents

Then to load jenkins now:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist

Or, if you don't want/need launchctl, you can just run:
  jenkins

==> Summary
🍺  /usr/local/Cellar/jenkins/1.629: 6 files, 61M

********** UPDATE JAVA **********


swati:~ admin$ jenkins @ dev > sudo touch /Library/LaunchDaemons/org.jenkins-ci.plist

Jenkins requires Java7 or later, but you are running 1.6.0_65-b14-466.1-11M4716 from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
java.lang.UnsupportedClassVersionError: 50.0
at Main.main(Main.java:90)

Remember to update your Java to latest to enjoy best features

********** LAUNCH DAEMONS **********


swati:~ admin$ sudo launchctl load -w /Library/LaunchDaemons/org.jenkins-ci.plist
Password:
/Library/LaunchDaemons/org.jenkins-ci.plist: Path had bad ownership/permissions

swati:~ admin$ sudo chmod 600 /Library/LaunchDaemons/org.jenkins-ci.plist
swati:~ admin$ sudo chown root /Library/LaunchDaemons/org.jenkins-ci.plist
swati:~ admin$ sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

********** org.jenkins.plist **********


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>Jenkins</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/bin/java</string>
            <string>-jar</string>
            <string>/usr/local/Cellar/jenkins/1.414/lib/jenkins.war</string>
        </array>
        <key>OnDemand</key>
        <false/>
        <key>RunAtLoad</key>
        <true/>
        <key>UserName</key>
        <string>jenkins</string>
    </dict>
</plist>

If user has a different name remember to add that in plist else it will run via System root


After all this you can reboot your MAC or type below mentioned command in browser
http://localhost:8080

yippieeee.... see how it looks



Now you are ready to go ahead...
Create your jobs , download plugins, integrate SCM, automate builds & Enjoy..

Hope you enjoyed the first step.
Next step will be posted soon
:)













Thursday, September 17, 2015

Pull To Refresh Tutorial


Hi all,

I have heard and seen this feature many a times while browsing through apps.
Liked it very much.

So i decided why not to try out this feature and share my experience with you all.
Hope somebody finds help with this.

Lets start....


1) Create a Project "Single View Application"



2) Set a product name : PullToRefresh


3)  Open the storyboard file and add UITableView to the provided view

Connect TableView Outlets, Delegates and Datasources


4) Under UITableView add UITableViewCell. 

This is a Static cell with Identifier as "CellIdentifier" and with only "Title" property.


5) Now comes the Controller part

5.1) Open ViewController.h and add properties for


@interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>
{
    
}

@property(nonatomic, strong)IBOutlet UITableView   *dataTable;
@property(nonatomic, strong)NSArray                        *fruitsArray;
@property(nonatomic, strong)UIRefreshControl          *refreshControl;

@end


5.2) Open ViewController.m and make dough from ingredients :P


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.fruitsArray = [[NSArray alloc] initWithObjects:
                                 @"Apple", @"Orange", @"Mango" , @"Grapes", @"Banana", nil];
    
    self.refreshControl = [[UIRefreshControl alloc] init];

    [self.refreshControl addTarget:self
                                           action:@selector(refreshControlValueChanged) 
                         forControlEvents:UIControlEventValueChanged];

    self.refreshControl.tintColor = [UIColor redColor];

    [self.dataTable addSubview:self.refreshControl];
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;

}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.fruitsArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    
    cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" 
                                                                   forIndexPath:indexPath];
    
    cell.textLabel.text          = self.fruitsArray[indexPath.row];
    cell.textLabel.textColor = [UIColor blueColor];

    return cell;

}



- (void)refreshControlValueChanged
{
    self.fruitsArray = [self.fruitsArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
    
    [self performSelector:@selector(updateTable)
                     withObject:nil
                      afterDelay:1];
}



- (void)updateTable
{
    [self.dataTable reloadData];
    
    [self.refreshControl endRefreshing];
}


6) Now run your App and see a list of fruits that are not sorted.



7) Drag your table & see the spinning wheel


8) Now see the refreshed data...



Happy Coding....
Enjoy :)