MINA开发者指南


检出代码

你需要从我们的源码库里用Git检出源码,并构建源码。下面的实例展示了怎么构建当前稳定分支(2.0.9)。

$ git clone http://git-wip-us.apache.org/repos/asf/mina.git mina
$ cd mina
$ mvn -Pserial clean install             # Build packages (JARs) for the core API and other 
                                         # extensions and install them to the local Maven repository.
$ mvn -Pserial site                      # Generate reports (JavaDoc and JXR)
$ mvn -Pserial package assembly:assembly # Generate a tarball (package goal needed to fix an assembly plugin bug)
$ mvn -Pserial eclipse:eclipse           # Generate Eclipse project files if you want

Eclipse用户:不要忘了声明一个classpath变量M2_REPO,指向~/.m2/repository,否则许多连接的jars会断开。你可以在Eclipse的Windows -> Perferences -> selecting Java -> BuildPath -> Classpath Variables中声明新变量。

还有其他你可能感兴趣的分支:  

  • trunk:每天都有更新

如果你想检出之前的发布源码,你必须选择你要检出的分支:

$ git clone http://git-wip-us.apache.org/repos/asf/mina.git mina $ git checkout

例如,要从事正在进行的2.0版本主干,只需要做:

$ git clone http://git-wip-us.apache.org/repos/asf/mina.git mina $ git checkout 2.0

编码规范

我们遵照标准Java编码规范章节,我们总是用空格代表制表符。请在修改代码之前下载Eclipse Java格式化设置文件

这个文件还可以在/resources目录里找到。

类头

类头,我们使用:

/**
* Class desciption here.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/

头部修正版本标记已经移除。

部署快照(只有提交者)

运行Maven部署artifacts之前,请确定umask是否配置正确。除非正确配置,其他提交者将会有'权限拒绝'错误。如果你的默认shell是bash,请更新你的~/.bashr文件的umask设置,通过添加下面的行:

umask 002

请注意你必须编辑正确的shrc文件。如果你使用csh,然后你必须要编辑~/.cshrc文件。

现在你准备好了部署artifacts,如果你正确的配置了umask。

$ git clone http://git-wip-us.apache.org/repos/asf/mina.git mina
$ cd mina
$ mvn -Pserial clean deploy site site:deploy    # Make sure to run 'clean' goal first to prevent side effects from your IDE.

请仔细检查部署的artifacts的模式,否则你会浪费别人的事件。

发布一个发布点(只有提交者)

准备发布投票

开始之前确定在你的PATH下右java和mvn命令。在linux上你可以通过下面的命令检查:

$ type mvn
mvn is hashed (/opt/maven-2.2.1/bin/mvn)
$ type java
java is hashed (/usr/bin/java)

Step 0:构建MINA

也许这听起来有些奇怪,对于一些不知道的原因,我们不能仅仅运行发布而不在之前构建所有项目。使用下面的命令执行:

$ mvn clean install -Pserial

Step 1:标记和部署

首先你需要配置maven,使用好的用户名执行scp和操作。

在~/.m2/settings.xml里,你需要下面的内容:

<settings xmlns="http://maven.apache.org/POM/4.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                     http://maven.apache.org/xsd/settings-1.0.0.xsd">
 <!-- SERVER SETTINGS -->
 <servers>
   <!-- To publish a snapshot of some part of Maven -->
   <server>
     <id>apache.snapshots.https</id>
     <username>elecharny</username>
     <password>-----Your password here-----</password>
   </server>
   <!-- To publish a website of some part of Maven -->
   <server>
     <id>apache.websites</id>
     <username>elecharny</username>
     <filePermissions>664</filePermissions>
     <directoryPermissions>775</directoryPermissions>
   </server>
   <!-- To stage a release of some part of Maven -->
   <server>
     <id>apache.releases.https</id>
     <username>elecharny</username>
     <password>-----Your password here-----</password>
   </server>
   <!-- To stage a website of some part of Maven -->
   <server>
     <id>stagingSite</id> <!-- must match hard-coded repository identifier in site:stage-deploy -->
     <username>elecharny</username>
     <filePermissions>664</filePermissions>
     <directoryPermissions>775</directoryPermissions>
   </server>
 </servers>
 <!-- PROFILE SETTINGS -->
 <profiles>
   <profile>
     <id>apache-release</id>
     <properties>
       <!-- Configuration for artifacts signature -->
       <gpg.passphrase>-----Your passphrase here-----</gpg.passphrase>
     </properties>
   </profile>
 </profiles>
</settings>

Step2:Dry run处理

检出主干之后,构建(查看step 0),

$ git clone http://git-wip-us.apache.org/repos/asf/mina.git mina
$ cd mina
$ mvn clean install -Pserial

运行下面的命令:

$ mvn -Pserial,apache-release -DdryRun=true release:prepare    # Dry-run first.

回答maven问题:

"What is the release version for "Apache MINA"? (org.apache.mina:mina-parent) 2.0.7-<version>: :"
<either use the default version as suggested, or type in the version you@qot;d like to be used>
[..]

然后还有其他关于使用下个版本的其他问题。默认值就应该是好的。

Step 3:真正的发布处理

try run成功后,你就可以运行下面的命令了:

$ mvn -Pserial,apache-release release:clean      # Clean up the temporary files created by the dry-run.
$ mvn -Pserial,apache-release release:prepare    # Copy to tags directory.

第一步会清空本地源码,第二步真正的发布。就像在try run步骤里,会问相同的问题。

某种情况下,它会要求你输入密码。输入就可以了。

会生成三个邮件,并发送至commits@mina.apache.org:

git commit: [maven-release-plugin] prepare release 2.0.9
Git Push Summary
git commit: [maven-release-plugin] prepare for next development iteration

第一封邮件会告诉你SNAPSHOT已经移动到主干的发布版本,第二封邮件告诉你这个版本已经做了标记,左后一封邮件告诉你主干已经移动到下一个版本。

Step 4:执行发布

发起投票之前的最后一步是推送潜在的发布到Nexus,以便于每个用户可以测试创建的包。执行下面的动作:

$ mvn clean install -Pserial -DskipTests
...
$ mvn -Pserial,apache-release release:perform
...
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Reactor Summary:
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Apache MINA ........................................... SUCCESS [1:05.896s]
[INFO] [INFO] Apache MINA Legal ..................................... SUCCESS [30.708s]
[INFO] [INFO] Apache MINA Core ...................................... SUCCESS [4:44.973s]
[INFO] [INFO] Apache MINA APR Transport ............................. SUCCESS [46.082s]
[INFO] [INFO] Apache MINA Compression Filter ........................ SUCCESS [40.230s]
[INFO] [INFO] Apache MINA State Machine ............................. SUCCESS [52.718s]
[INFO] [INFO] Apache MINA JavaBeans Integration ..................... SUCCESS [46.358s]
[INFO] [INFO] Apache MINA XBean Integration ......................... SUCCESS [1:21.054s]
[INFO] [INFO] Apache MINA OGNL Integration .......................... SUCCESS [40.740s]
[INFO] [INFO] Apache MINA JMX Integration ........................... SUCCESS [40.482s]
[INFO] [INFO] Apache MINA Examples .................................. SUCCESS [1:13.837s]
[INFO] [INFO] Apache MINA Serial Communication support .............. SUCCESS [41.684s]
[INFO] [INFO] Apache MINA Distribution .............................. SUCCESS [12:39.542s]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD SUCCESSFUL
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 26 minutes 46 seconds
[INFO] [INFO] Finished at: Mon Sep 13 16:45:14 CEST 2010
[INFO] [INFO] Final Memory: 98M/299M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] Cleaning up after release...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27 minutes 5 seconds
[INFO] Finished at: Mon Sep 13 16:45:18 CEST 2010
[INFO] Final Memory: 28M/81M
[INFO] ------------------------------------------------------------------------

完成!

Step 5:在nexus上关闭并暂存发布

现在,你必须关闭nexus上的暂存项目。以便于你必须输出你的PGP key到一个PGP公共服务器。查看

连接到Nexus服务,登陆,并选择你刚刚创建的MINA 暂存仓库,然后点击'close'按钮。

Step 6:构建站点

你会需要修改pom.xml文件,能够运行mvn站点命令。事实上,你必须在maven-site-plugin配置里,为maven JXF查件填写executions部分:

<plugin>
 <artifactId>maven-jxr-plugin</artifactId>
 <configuration>
   <aggregate>true</aggregate>
 </configuration>
 <!--executions>
   <execution>
     <phase>install</phase>
     <goals>
       <goal>jxr</goal>
       <goal>test-jxr</goal>
     </goals>
   </execution>
 </executions -->
</plugin>
$ cd target/checkout
$ mvn -Pserial site

这就创建了站点了。

Step 7:签署包

现在,你必须在target/checkout/distribution/target里签署二进制包。

你可以通过输入一下命令,得到keys:

gpg --list-keys

你会看到类似于下面的东西:

localhost:target elecharny$ gpg --list-keys
/Users/elecharny/.gnupg/pubring.gpg
-----------------------------------
pub   2048D/xxxxxxxx 2009-12-03
uid                  Emmanuel Lecharny <elecharny@nextury.com>
sub   2048g/yyyyyyyy 2009-12-03
pub   4096R/zzzzzzzz 2010-09-13
uid                  Emmanuel Lecharny (CODE SIGNING KEY) <elecharny@apache.org>
sub   4096R/tttttttt 2010-09-13
...

你4096位key的一部分。

使用一个shell脚本签署存储在target/checkout/distribution/target里的包。你首先必须删除创建的.asc文件:

localhost:target elecharny$ rm *.asc
localhost:target elecharny$ ~/sign.sh
PGP Key ID:
<your PGP key>
PGP Key Password:
<Your PGP passphrase>
-n Signing: ./apache-mina-2.0.9-bin.tar.bz2 ...
 - Generated './apache-mina-2.0.9-bin.tar.bz2.md5'
 - Generated './apache-mina-2.0.9-bin.tar.bz2.sha1'
 - Generated './apache-mina-2.0.9-bin.tar.bz2.asc'
-n Signing: ./apache-mina-2.0.9-bin.tar.gz ...
 - Generated './apache-mina-2.0.9-bin.tar.gz.md5'
 - Generated './apache-mina-2.0.9-bin.tar.gz.sha1'
 - Generated './apache-mina-2.0.9-bin.tar.gz.asc'
...

下面是你可以使用的sign.sh脚本:

#!/bin/sh
echo "PGP Key ID: "
read DEFAULT_KEY
echo "PGP Key Password: "
stty -echo
read PASSWORD
stty echo
echo ""
for FILE in $(find . -maxdepth 1 -not '(' -name "sign.sh" -or -name ".*" -or -name "*.md5" -or -name "*.sha1" -or -name "*.asc" ')' -and -type f) ; do
   if [ -f "$FILE.asc" ]; then
       echo "Skipping: $FILE"
       continue
   fi
   echo -n "Signing: $FILE ... "
   # MD5
   if [ ! -f "$FILE.md5" ];
   then
       openssl md5 < "$FILE" | cut "-d " -f2 > "$FILE.md5"
       echo "  - Generated '$FILE.md5'"
   else
       echo "  - Skipped '$FILE.md5' (file already existing)"
   fi
   # SHA1
   if [ ! -f "$FILE.sha1" ];
   then
       gpg -v --default-key "$DEFAULT_KEY" --print-md SHA1 "$FILE" > "$FILE".sha1
       echo "  - Generated '$FILE.sha1'"
   else
       echo "  - Skipped '$FILE.sha1' (file already existing)"
   fi
   # ASC
   if [ ! -f "$FILE.asc" ];
   then
       echo "$PASSWORD" | gpg --default-key "$DEFAULT_KEY" --detach-sign --armor --no-tty --yes --passphrase-fd 0 "$FILE"
       echo "  - Generated '$FILE.asc'"
   else
       echo "  - Skipped '$FILE.asc' (file already existing)"
   fi
done

Step 8:发布源码和二级制发布包

首先,在people.apache.org/public_html创建一个新目录,存储包:

$ ssh people.apache.org
$ mkdir public_html/mina-<version>
$ exit

然后复制包:

$ cd target/checkout/distributions/target
$ scp apache-mina-<version>-* people.apache.org:public_html/mina-<version>/

在people.apach.org/public_html上更新index.html文件,使包可见。下面是内容实例:

<h2>Last MINA 2.0.9 tarballs</h2>
 <h3>Sources</h3>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.tar.gz">apache-mina-2.0.9-src.tar.gz</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.tar.gz.asc">apache-mina-2.0.9-src.tar.gz.asc</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.tar.gz.asc">apache-mina-2.0.9-src.tar.gz.md5</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.tar.gz.asc">apache-mina-2.0.9-src.tar.gz.sha1</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.tar.bz2">apache-mina-2.0.9-src.tar.bz2</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.tar.bz2.asc">apache-mina-2.0.9-src.tar.bz2.asc</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.tar.bz2.asc">apache-mina-2.0.9-src.tar.bz2.md5</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.tar.bz2.asc">apache-mina-2.0.9-src.tar.bz2.sha1</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.zip">apache-mina-2.0.9-src.zip</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.zip.asc">apache-mina-2.0.9-src.zip.asc</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.zip.asc">apache-mina-2.0.9-src.zip.md5</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-src.zip.asc">apache-mina-2.0.9-src.zip.sha1</a><br/>
 <h3>Binaries</h3>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.tar.gz">apache-mina-2.0.9-bin.tar.gz</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.tar.gz.asc">apache-mina-2.0.9-bin.tar.gz.asc</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.tar.gz.asc">apache-mina-2.0.9-bin.tar.gz.md5</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.tar.gz.asc">apache-mina-2.0.9-bin.tar.gz.sha1</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.tar.bz2">apache-mina-2.0.9-bin.tar.bz2</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.tar.bz2.asc">apache-mina-2.0.9-bin.tar.bz2.asc</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.tar.bz2.asc">apache-mina-2.0.9-bin.tar.bz2.md5</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.tar.bz2.asc">apache-mina-2.0.9-bin.tar.bz2.sha1</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.zip">apache-mina-2.0.9-bin.zip</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.zip.asc">apache-mina-2.0.9-bin.zip.asc</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.zip.asc">apache-mina-2.0.9-bin.zip.md5</a><br/>
   <img src="/icons/compressed.gif" alt="[   ]"><a href="mina-2.0.9/apache-mina-2.0.9-bin.zip.asc">apache-mina-2.0.9-bin.zip.sha1</a><br/>

Step 9:利用FtpServer、Sshd和Vysper测试新版本

在FtpServer/pom.xml里,修改property,构建FtpServer。它应该无错误构建。在Sshd和Vysper里做相同的事情。

是时候该发起投票了!

Step10:投票发布

一旦创建了tarballs,并且在Nexus里二进制文件可用,就可以发起一个投票了。简单的在dev@maina.apache.org邮件列表里发送一个邮件,描述新的发布就可以了。

下面是怎么在dev邮件列表里发送投票邮件:

Hi,
<blah blah blah>
Here is the list of fixed issues :
  * [DIRMINA-803 <https://issues.apache.org/jira/browse/DIRMINA-803>]
    - ProtocolCodecFilter.filterWrite() is no longer thread-safe
  * ...
Here's the Jira link for this version if you'd like to review issues in more details:
https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=10670&styleName=Html&version=12313702
A temporary tag has been created (it can be removed if the vote is not approved)
The newly approved Nexus has been used for the preparation of this release and all final artifacts are stored
in a staging repository:
https://repository.apache.org/content/repositories/orgapachemina-002/
The distributions are available for download on :
https://repository.apache.org/content/repositories/orgapachemina-004/org/apache/mina/mina-parent/2.0.1/
Let us vote :
[ ] +1 | Release MINA 2.0.1
[ ] +/- | Abstain
[ ] -1 | Do *NOT*  release MINA 2.0.1
Thanks !

投票会开发72小时。一旦延迟到期,收集投票结果,并计算绑定+1/-1。如果投票是正数,就可以发布了。

Step11:关闭投票

你现在可以正式的关闭投票。要通过一些步骤:

  • Nexus服务上发布项目。
  • 在people.apache.org/www/www.apache.org/dist/mina里拷贝tarballs和继承人签名。

这可以在people.apache.org里完成:

$ ssh people.apache.org
# svn co https://dist.apache.org/repos/dist/release/mina/mina/ mina-dist
# cd mina-dist
# mkdir <version>
# cp ../public_html/mina-<version>/* <version>
# svn add <version>
# svn ci <version>
...
# exit
$

Step12:部署网络报告(JavaDoc和JXR)

javadoc和xref文件已经在step6里生成了,现在是时候将他们推进生产站点了。在下面的目录里生成:

target/checkout/target/site

我们将拷贝两个目录:

apidocs
xref

暂存或生产?

首先,你必须检出两个CMS存储:staging和production。

$ svn co https://svn.apache.org/repos/infra/websites/staging/mina/trunk staging
...
$ svn co https://svn.apache.org/repos/infra/websites/production/mina production
...

然后拷贝生产的docs:

$ cp -r ~/mina/target/checkout/target/site/apidocs production/content/mina-project/
$ cp -r ~/mina/target/checkout/target/site/testapidocs production/content/mina-project/
$ cp -r ~/mina/target/checkout/target/site/xref production/content/mina-project/
$ cp -r ~/mina/target/checkout/target/site/xref-test production/content/mina-project/
$

你必须检入到这些目录:

$ svn add apidocs
$ svn add testapidocs
$ svn add xref
$ svn add xref-test
$ svn ci apidocs testapidocs xref xref-test -m "Injected MINA <version> javadocs"

现在,你必须更新staging站点extpaths.txt

这个文件列出了生产站点上的文件。它必须要更新:

$ cd ~/mina/staging/content/
$ vi extpaths.txt

应该出现下面的输出行。如果不是,添加他们并提交文件:

mina-project/apidocs
mina-project/testapidocs
mina-project/xref
mina-project/xref-test
...

Step13:等待24小时

在获取任何声明之前,对于所有镜像检索更新的文件,我们至少要等待24小时。我建议你等待48小时,因为一些镜像可能会滞后。

Step14:更新网站中的连接

在下载页面更新连接到最新的发布。

Step15:等待另一个24小时

我们需要等待直到所有的修改进入网站以及元数据文件上线。

Step16:通告新的发布

公告信息可以发送的[maito:announce@apache.org]、[mailto:announce@apachenews.org]、[mailto:users@mina.apache.org]和[mailto:dev@mina.apache.org]。请注意,除非你的邮件地址是以@apache.org结尾,否则公告信息会被拒绝。此外,你不要忘了在MINA主页上发布一条新闻。

原创文章,转载请注明出处:转载自小马过河 - MINA开发者指南


Jbone

Spring Cloud实战项目jbone正在开发中, jbone功能包括服务管理、单点登录、系统管理平台、内容管理平台、电商平台、支付平台、工作流平台等子系统。欢迎关注!

GitHub 码云
马军伟
关于作者 马军伟
写的不错,支持一下

先给自己定个小目标,日更一新。