首先让我们踏着欢快的脚步去Github创建一个新库,这里取名 composer-car,又欢快的将它克隆到本地:

git clone https://github.com/GeHou/composer-car.git

cd composer-car

这个composer-car文件夹就是你的包的root目录了,你只需要记住composer.json在包的哪个目录下面,一般那就是包的root目录了。什么?做包子的工作台?这么理解呢也是可以的,不过同学能先收收你的口水么。

现在我们还没有composer.json文件,你可以根据composer文档生成并编辑它,当然composer贴心的为我们准备了命令行,look:

-> composer init

Welcome to the Composer config generator

This command will guide you through creating your composer.json config.

Package name (<vendor>/<name>) [hou/composer-car]: 这里填写<包提供者>/<包名>的信息
Description []: 包的描述
Author [GeHou <***@gmail.com>]: 作者信息
Minimum Stability []: 最低稳定版本
License []: 授权协议

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? no
Would you like to define your dev dependencies (require-dev) interactively [yes]? no

{
    "name": "hou/composer-car",
    "description": "In order to study composer",
    "license": "MIT",
    "authors": [
        {
            "name": "GeHou",
            "email": "***@gmail.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {

    }
}

Do you confirm generation [yes]? yes
Would you like the vendor directory added to your .gitignore [yes]? yes

虽然经过以上的一番挣扎生成了composer.json文件,不过我们还得往里面加点东西。使用你熟悉的编辑器打开composer.json文件修改至如下:

{
    "name": "hou/composer-car",
    "description": "In order to study composer",
    "license": "MIT",
    "authors": [
        {
            "name": "GeHou",
            "email": "***@gmail.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {
        "php": ">=5.3.0"
    },
    "autoload": {
        "psr-4": {
            "Ford\\Escape\\": "src/Ford/Escape",
            "Ford\\Fusion\\": "src/Ford/Fusion",
            "Ford\\Focus\\": "src/Ford/Focus",
            "Ford\\Fiesta\\": "src/Ford/Fiesta"
        }
    }   
}

细心的小伙伴可能已经认出了福特的商标(Ford),这说明我们都是同道中人,你一定也很喜欢汽车,对吧对吧? 🙂

我们登陆一下福特的网站看看都有哪些热销车型,嗯嗯分别有ESCAPE、FUSION、FOCUS、FIESTA,中文名称分别是翼虎、蒙迪欧、福克斯、嘉年华,嘉年华ST我的梦想啊~~~ 好了好了,那位看官放下你手里的板砖,我承认一说到汽车就会滔滔不绝,下面我们把水分挤出去继续讲解。

根据上面的命名空间和目录的映射关系,包的结构现在应该是下面这个样子:

composer-car
- src
- - Ford
- - - Escape
- - - - Escape2013.php
- - - Fiesta
- - - - Fiesta2013.php
- - - Focus
- - - - Focus2013.php
- - - Fusion
- - - - Fusion2013.php
- .gitignore
- composer.json
- README.md

Escape2013.php:

<?php

namespace Ford\Escape;

class Escape2013
{
    public static function info()
    {
        echo "This is Ford Escape2013!<br />";
    }
}

Fiesta2013.php:

<?php

namespace Ford\Fiesta;

class Fiesta2013
{
    public static function info()
    {
        echo "This is Ford Fiesta2013!<br />";
    }
}

Focus2013.php:

<?php

namespace Ford\Focus;

class Focus2013
{
    public static function info()
    {
        echo "This is Ford Focus2013!<br />";
    }
}

Fusion2013.php:

<?php

namespace Ford\Fusion;

class Fusion2013
{
    public static function info()
    {
        echo "This is Ford Fusion2013!<br />";
    }
}

以上都梳理完毕后,需要安装composer来测试我们的包是否可以正常工作,安装它很简单在包的root目录下install即可:

composer install

闪过几行神秘的提示之后即安装完毕,此时会在vendor/composer/autoload_psr4.php中生成命名空间和目录的映射关系,被包在一个数组中:

<?php

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'Ford\\Fusion\\' => array($baseDir . '/src/Ford/Fusion'),
    'Ford\\Focus\\' => array($baseDir . '/src/Ford/Focus'),
    'Ford\\Fiesta\\' => array($baseDir . '/src/Ford/Fiesta'),
    'Ford\\Escape\\' => array($baseDir . '/src/Ford/Escape'),
);

如果发布成packagist包然后进行安装的话,到时候这里就不是$baseDir了而是$vendorDir。

然后我们新建一个测试文件show.php,用以下内容填充它:

<?php

require 'vendor/autoload.php';

use Ford\Escape as Escape;
use Ford\Fiesta as Fiesta;
use Ford\Focus as Focus;
use Ford\Fusion as Fusion;

echo Escape\Escape2013::info();
echo Fiesta\Fiesta2013::info();
echo Focus\Focus2013::info();
echo Fusion\Fusion2013::info();

打开浏览器敲入 http://foo.com/composer-car/show.php (foo.com是我的本地测试域名,请替换成小伙伴自己的)。

浏览器上依次输出了:

This is Ford Escape2013!
This is Ford Fiesta2013!
This is Ford Focus2013!
This is Ford Fusion2013!

是不是有点小激动呢?别急,别一副作鸟兽散的样子,还有发布的流程呢?不过你要是真的急着wc或者觉得教程too simple,侯哥是不会让你捡肥皂的。

首先作为调试代码的部分我们是不需要push到github上的,所以将show.php打入冷宫,编辑.gitignore文件,在末尾加入show.php。这个时候有些小伙伴可能会疑惑了,为什么上面还有个/vendor/,记得我们init包的时候回答过一个问题么?

Would you like the vendor directory added to your .gitignore [yes]? yes

嗯嗯,你懂了吧?

废话少说,经过职业玩家的一番噼里啪啦的敲击之后,代码被push到github上了,噼里啪啦的内容如下:

$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .gitignore
#   composer.json
#   src/
nothing added to commit but untracked files present (use "git add" to track)

$ git add .
$ git commit -m "gogogo"
$ git push

接下来需要将github上的代码同步到https://packagist.org/上,去[Packagist的网站](https://packagist.org/](https://packagist.org/)注册一个账号(Login with github是个不错的选择)。登录,然后点击的大大的绿色背景按钮 Submit a Package,在 Repository URL (Git/Svn/Hg) 处输入包在github上的地址,这里就是:

https://github.com/GeHou/composer-car 

now,点击 Check,如果一切顺利,会返回项目的名称,确认后点击 Submit 完成抓取操作。

默认情况下Packagist是不会自动更新你在github上commit的代码的,在刚才导入的项目页面中点击 Force Update,Packagist会抓取github上对应库的内容进行更新,但这还不是自动化的,幸运的是我们可以在Github库的设置中进行配置来消除手动更新的麻烦。

进入Github库的 Settings 页面,找到 Webhooks & Services 选项,点击 Configure services 按钮,在出现的列表中找到 Packagist,猛击它!这里需要填写一些信息,在Packagist网站的profile页面可以找到它们:

  • User : Packagist上的用户名
  • Token : Packagist的授权令牌
  • Domain : http://packagist.org

补全后点击 Update settings,如果列表中显示绿剪头就表示OK了。

真的OK了吗?还是有点担心?大不了我们再测试下嘛!

先跳出root目录,在测试环境下新建一个文件夹:

mkdir test-auto-update
cd test-auto-update
vim composer.json

这次我们不使用init命令,只往composer.json里填充一些简单内容:

{
    "require": {
        "php": ">=5.3.0",
        "hou/composer-car": "dev-master"
    },
    "minimum-stability": "dev"
}

然后:

composer install

安装完后扫一眼test-auto-update/src/Ford/Fiesta目录看下是否只有2013款的Fiesta,然后暂时就不需要理会此目录下的内容了,让我们回到composer-car目录。

注:这时test-auto-update/vendor下面的hou/composer-car对应建立项目时的( / ) [hou/composer-car]。

听说2014款的嘉年华出了,赶紧追加新的车款吧:

composer-car/src/Ford/Fiesta 目录下新建文件Fiesta2014.php,填充它:

<?php

namespace Ford\Fiesta;

class Fiesta2014
{
    public static function info()
    {
        echo "This is Ford Fiesta2014!<br />";
    }
}

修改show.php,在最后追加:

echo Fiesta\Fiesta2014::info();

访问测试页,看看是否出现了:

This is Ford Fiesta2014!

ok,再次提交代码:

git add .
git commit -m "test auto update"
git push

接着回到 test-auto-update 目录,这次要换一个命令耍耍,因为install命令之后root目录下会生成一个composer.lock文件,已经安装过的依赖是不能通过install命令进行更新的,所以这次需要使用composer update命令,试试这个命令,看看会发生什么:

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
       - Updating hou/composer-car dev-master (91bceb0 => 01550b4)
    Checking out 01550b4eeaa85513573ce7406ca7d46ee30c6978

Writing lock file
Generating autoload files

类似这样的神秘信息又在屏幕上一闪而过,实际上因为网络的缘故,有时候得闪好久~

不管怎么闪,更新成功后你就应该在 test-auto-update/vendor/hou/composer-car/src/Ford/Fiesta/ 文件夹下中找到新的 Fiesta2014.php 文件了。不过这里需要注意一点,有时候Packagist与Github之间的同步可能会出现延迟,这时不妨喝杯咖啡、找妹子聊会、扣扣鼻孔之类的噼里啪啦一会再回来试试更新操作。

好吧我们在 test-auto-update 根目录下新建一个 index.php 文件看看是否能跑起来,文件内容其实跟前面的show.php差不了多少:

<?php

require 'vendor/autoload.php';

use Ford\Fiesta as Fiesta;

echo Fiesta\Fiesta2014::info();

不错的话,运行index.php文件后浏览器会输出:

This is Ford Fiesta2014!

至此更新操作也被证实是OK了,同志赶紧自己动手试试吧。

参考资料

中文文档 http://composer.golaravel.com/

PSR-4规范 https://github.com/php-fig/fig-standards/blob/master/proposed/psr-4-autoloader/psr-4-autoloader.md

本文示例

https://github.com/GeHou/composer-car

https://packagist.org/packages/hou/composer-car

link: http://my.oschina.net/houlive/blog/206832

使用aapt    //aapt是sdk自带的一个工具,在sdk\builds-tools\目录下

1.以微信为例,命令行中切换到aapt.exe目录执行:aapt dump badging E:\android\weixin531android460.apk
2.运行后的结果如下(仅截取部分):
package: name=’com.tencent.mm’ versionCode=’542′ versionName=’6.1.0.105_r1085424′
uses-permission:’com.tencent.mm.plugin.permission.READ’
uses-permission:’com.tencent.mm.plugin.permission.WRITE’
uses-permission:’com.tencent.mm.plugin.permission.SEND’
uses-permission:’com.tencent.mm.permission.MM_MESSAGE’
sdkVersion:’10’
targetSdkVersion:’16’

我们可以看到关于微信的很多信息,其中就包括包名,微信的包名为:com.tencent.mm

然后启动代码:

  1. try {
  2.     PackageManager packageManager = getPackageManager();
  3.     Intent intent=new Intent();
  4.     intent = packageManager.getLaunchIntentForPackage(“com.tencent.mm”);
  5.     startActivity(intent);
  6. catch (Exception e) {
  7.     e.printStackTrace();
  8.     Intent viewIntent = new
  9.     Intent(“android.intent.action.VIEW”,Uri.parse(“http://weixin.qq.com/”));
  10.     startActivity(viewIntent);
  11. }

如果手机上安装了微信,就打开微信的主界面,如果没有安装就打开一个浏览器去下载!!!

link: http://blog.csdn.net/lovexieyuan520/article/details/44301753

 

最近因为需要用到Android的自动化测试,于是找到了uiautomator和espresso这两个框架(这里以uiautomator为例).由于在Android Studio(以下简称AS)中使用uiautomator这方面的资料很少,国内这方面的博客基本没有,国外的资料也都很少.可能是因为比较新的原因吧.虽然Android官网有教程,但最终还是折腾了好久才解决.写这篇博客一方面希望大家能够少走一些弯路,另一方面也算是我自己的学习笔记吧.

说明:我的AS版本是1.2.1.1

关于什么是uiautomator和espresso,这里就不做介绍了.

使用之前首先得保证你的Android Support Repository已经成功安装

安装成功后,根据Android官网给出的教程,首先第一步是在build.gradle中添加依赖:

dependencies {
        androidTestCompile 'com.android.support.test:runner:0.2'
        androidTestCompile 'com.android.support.test:rules:0.2'
        androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.0'
}

然后添加

defaultConfig {
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

添加完依赖后Sync Project with Gradle Files,但是同步后我发现上面相关的库文件并没有被添加进来.对比很多资料后,我很确信不是我在写法的问题.就是这个问题折腾了我好几天的!

最后的解决办法是先把androidTestCompile换成compile,同步一下,此时会发现库文件已经被添加进来了.

最后再将compile换回androidTestCompile,解决~

突然就觉得自己被坑了,也不知道这算不算是AS的一个BUG…

如果同步之后发现诸如此类的错误:

 Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.1.1) and test app (22.0.0) differ.

先在项目的根目录用./gradlew -q app:dependencies查看项目依赖关系(Windows用户请使用gradlew.bat -q app:dependencies), 然后修改build.gradle,否则在后面运行测试时可能会报依赖关系的错误.
可能需要为gradlew加上可执行权限.

说明:我这里会报这个警告是因为新建项目的时候AS帮我自动添加了compile 'com.android.support:appcompat-v7:22.1.1'依赖,将22.1.1改为22.0.0即可.

然后还要在build.gradle中添加:

packagingOptions {
    exclude 'LICENSE.txt'
}

不添加的话运行时候还是会报错的.

最后,确保此时有android设备在运行(虚拟器或手机都可以,要求是系统版本要18或18以上),然后在项目的根目录下输入命令:

./gradlew cC

如无意外的话,应该可以看到BUILD SUCCESS了!

如果不想用命令行的话,也可以Edit Configurations,然后点击+ –> Android Test,然后选择对应的Module,然后在下面的Specific Instrumentation Runner选择

android.support.test.runner.AndroidJUnitRunner

选择OK,然后点击启动按钮.如无意外的话,应该可以看到一条绿色的进度条了!

关于另外一个自动化测试框架Espresso,导入方法和uiautomator一样,不同的只是依赖而已.

dependencies {
    androidTestCompile 'com.android.support.test:runner:0.2'
    androidTestCompile 'com.android.support.test:rules:0.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
}

关于测试框架的导入就先说这么多了,有关这些框架的使用网上的资料应该也是比较多的了,只不过有一些API已经被弃用了.等我熟悉了这两大框架的使用再来写相关的博客吧.

 

link: http://blog.csdn.net/u011504118/article/details/46318693

Git Protocol

A guide for programming within version control.

Maintain a Repo

  • Avoid including files in source control that are specific to your development machine or process.
  • Delete local and remote feature branches after merging.
  • Perform work in a feature branch.
  • Rebase frequently to incorporate upstream changes.
  • Use a pull request for code reviews.

Write a Feature

Create a local feature branch based off master.

git checkout master
git pull
git checkout -b <branch-name>

Rebase frequently to incorporate upstream changes.

git fetch origin
git rebase origin/master

Resolve conflicts. When feature is complete and tests pass, stage the changes.

git add --all

When you’ve staged the changes, commit them.

git status
git commit --verbose

Write a good commit message. Example format:

Present-tense summary under 50 characters

* More information about commit (under 72 characters).
* More information about commit (under 72 characters).

http://project.management-system.com/ticket/123

If you’ve created more than one commit, use a rebase to squash them into cohesive commits with good messages:

git rebase -i origin/master

Share your branch.

git push origin <branch-name>

Submit a GitHub pull request.

Ask for a code review in the project’s chat room.

Review Code

A team member other than the author reviews the pull request. They follow Code Review guidelines to avoid miscommunication.

They make comments and ask questions directly on lines of code in the GitHub web interface or in the project’s chat room.

For changes which they can make themselves, they check out the branch.

git checkout <branch-name>
./bin/setup
git diff staging/master..HEAD

They make small changes right in the branch, test the feature on their machine, run tests, commit, and push.

When satisfied, they comment on the pull request Ready to merge.

Merge

Rebase interactively. Squash commits like “Fix whitespace” into one or a small number of valuable commit(s). Edit commit messages to reveal intent. Run tests.

git fetch origin
git rebase -i origin/master

Force push your branch. This allows GitHub to automatically close your pull request and mark it as merged when your commit(s) are pushed to master. It also makes it possible to find the pull request that brought in your changes.

git push --force origin <branch-name>

View a list of new commits. View changed files. Merge branch into master.

git log origin/master..<branch-name>
git diff --stat origin/master
git checkout master
git merge <branch-name> --ff-only
git push

Delete your remote feature branch.

git push origin --delete <branch-name>

Delete your local feature branch.

git branch --delete <branch-name>

link: https://github.com/thoughtbot/guides/tree/master/protocol/git