Winse Blog

走走停停都是风景, 熙熙攘攘都向最好, 忙忙碌碌都为明朝, 何畏之.

Jekyll页面实现上/下一篇文章导航

在博客页面在内容会有上一遍和下一遍文章的链接。 在jekyll的page对象包含上下篇的引用 Template Data Api ,只需要在页面进行展示即可。

默认主题中jekyll-bootstrap的twitter主题中包含上下篇文章的实现如下:

<hr>
<div class="pagination">
  <ul>
  {% if page.previous %}
    <li class="prev"><a href="{{ BASE_PATH }}{{ page.previous.url }}" title="{{ page.previous.title }}">&larr; Previous</a></li>
  {% else %}
    <li class="prev disabled"><a>&larr; Previous</a></li>
  {% endif %}
    <li><a href="{{ BASE_PATH }}{{ site.JB.archive_path }}">Archive</a></li>
  {% if page.next %}
    <li class="next"><a href="{{ BASE_PATH }}{{ page.next.url }}" title="{{ page.next.title }}">Next &rarr;</a></li>
  {% else %}
    <li class="next disabled"><a>Next &rarr;</a>
  {% endif %}
  </ul>
</div>
<hr>

注意点

1
2
3
4
{ % highlight % }{ % endhighlight % }

# 用于直接输出liquid标签源码,但是raw不能嵌套使用
{ % raw % } { % endraw % }

参考

–END

在windows操作系统安装jekyll服务

如果windows安装了cygwin,那就不要折腾了,参考本文最后,按照类似linux的安装是最方便简单的了!

参考文档:

我首先把安装过程中参考的链接放上来,下面的操作其实是对他们的一个梳理。

下载 & 安装包

  • MsysGit Git-1.8.3-preview20130601.exe
  • ruby rubyinstaller-1.9.3-p392.exe
  • rubydev DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

安装的路径根据自己的需要进行选择即可。我这里选择的是:

  • C:\Program Files\Git
  • C:\Ruby193
  • C:\rubydev

设置环境变量,并初始化安装rubydev

打开git命令窗口(bash命令行),操作如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Winseliu@WINSE ~
$ export PATH=/c/Ruby193/bin:/c/rubydev/bin:$PATH

Winseliu@WINSE ~
$ cd /c/rubydev/

Winseliu@WINSE /c/rubydev
$ ruby dk.rb  init
[INFO] found RubyInstaller v1.9.3 at C:/Ruby193

Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

Winseliu@WINSE /c/rubydev
$ ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/Ruby193'
[INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/devkit.rb'

安装jekyll

安装的过程并非一路顺风,rubygems的官网好像被禁了。需要更新源。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Winseliu@WINSE /c
$ gem install jekyll
ERROR:  Could not find a valid gem 'jekyll' (>= 0) in any repository
ERROR:  Possible alternatives: jekyll

Winseliu@WINSE /c
$ gem sources --remove http://rubygems.org/
http://rubygems.org/ removed from sources

Winseliu@WINSE /c
$ gem sources -a http://ruby.taobao.org/
http://ruby.taobao.org/ added to sources

Winseliu@WINSE /c
$ gem sources -l
*** CURRENT SOURCES ***

http://ruby.taobao.org/

Winseliu@WINSE /c
$ gem install rack
Fetching: rack-1.5.2.gem (100%)
Successfully installed rack-1.5.2
1 gem installed
Installing ri documentation for rack-1.5.2...
Installing RDoc documentation for rack-1.5.2...

真正安装jekyll

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Winseliu@WINSE /c/rubydev
$ gem install jekyll
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Fetching: classifier-1.3.3.gem (100%)
Fetching: directory_watcher-1.4.1.gem (100%)
Fetching: syntax-1.0.0.gem (100%)
Fetching: maruku-0.6.1.gem (100%)
Fetching: kramdown-1.0.2.gem (100%)
Fetching: yajl-ruby-1.1.0-x86-mingw32.gem (100%)
Fetching: posix-spawn-0.3.6.gem (100%)
Building native extensions.  This could take a while...
Fetching: pygments.rb-0.5.1.gem (100%)
Fetching: highline-1.6.19.gem (100%)
Fetching: commander-4.1.3.gem (100%)
Fetching: safe_yaml-0.7.1.gem (100%)
Fetching: colorator-0.1.gem (100%)
Fetching: jekyll-1.0.3.gem (100%)
Successfully installed fast-stemmer-1.0.2
Successfully installed classifier-1.3.3
Successfully installed directory_watcher-1.4.1
Successfully installed syntax-1.0.0
Successfully installed maruku-0.6.1
Successfully installed kramdown-1.0.2
Successfully installed yajl-ruby-1.1.0-x86-mingw32
Successfully installed posix-spawn-0.3.6
Successfully installed pygments.rb-0.5.1
Successfully installed highline-1.6.19
Successfully installed commander-4.1.3
Successfully installed safe_yaml-0.7.1
Successfully installed colorator-0.1
Successfully installed jekyll-1.0.3
14 gems installed
Installing ri documentation for fast-stemmer-1.0.2...
Installing ri documentation for classifier-1.3.3...
Installing ri documentation for directory_watcher-1.4.1...
Installing ri documentation for syntax-1.0.0...
Installing ri documentation for maruku-0.6.1...
Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb
Installing ri documentation for kramdown-1.0.2...
Installing ri documentation for yajl-ruby-1.1.0-x86-mingw32...
Installing ri documentation for posix-spawn-0.3.6...
Installing ri documentation for pygments.rb-0.5.1...
Installing ri documentation for highline-1.6.19...
Installing ri documentation for commander-4.1.3...
Installing ri documentation for safe_yaml-0.7.1...
Installing ri documentation for colorator-0.1...
Installing ri documentation for jekyll-1.0.3...
Installing RDoc documentation for fast-stemmer-1.0.2...
Installing RDoc documentation for classifier-1.3.3...
Installing RDoc documentation for directory_watcher-1.4.1...
Installing RDoc documentation for syntax-1.0.0...
Installing RDoc documentation for maruku-0.6.1...
Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb
Installing RDoc documentation for kramdown-1.0.2...
Installing RDoc documentation for yajl-ruby-1.1.0-x86-mingw32...
Installing RDoc documentation for posix-spawn-0.3.6...
Installing RDoc documentation for pygments.rb-0.5.1...
Installing RDoc documentation for highline-1.6.19...
Installing RDoc documentation for commander-4.1.3...
Installing RDoc documentation for safe_yaml-0.7.1...
Installing RDoc documentation for colorator-0.1...
Installing RDoc documentation for jekyll-1.0.3...

创建新博客

(2014年3月19日更新 Cygwin)

建立新的本地测试文件夹

1
2
3
4
5
6
7
8
9
Administrator@winseliu /cygdrive/c/Users/Administrator/target
$ rm -rf export

Administrator@winseliu /cygdrive/c/Users/Administrator/target
$ jekyll new export
New jekyll site installed in /cygdrive/c/Users/Administrator/target/export.

Administrator@winseliu /cygdrive/c/Users/Administrator/target
$ cd export/

修改配置_config.yml

1
2
3
name: Your New Jekyll Site
markdown: rdiscount
pygments: false

启动服务

1
2
3
4
5
6
7
8
9
10
11
12
Administrator@winseliu /cygdrive/c/Users/Administrator/target/export
$ jekyll serve --trace -w -P 8000
Configuration file: /cygdrive/c/Users/Administrator/target/export/_config.yml
            Source: /cygdrive/c/Users/Administrator/target/export
       Destination: /cygdrive/c/Users/Administrator/target/export/_site
      Generating... done.
 Auto-regeneration: enabled
[Listen warning]:
  Listen will be polling for changes. Learn more at https://github.com/guard/listen#polling-fallback.

    Server address: http://0.0.0.0:8000
  Server running... press ctrl-c to stop.

注意点

出现编码问题

参考:http://www.duzengqiang.com/blog/post/979.html

文件在对应的文件夹下: C:\Ruby193\lib\ruby\gems\1.9.1\gems\jekyll-1.0.3\lib\jekyll\convertible.rb

1
2
-        self.content = File.read(File.join(base, name))
+        self.content = File.read(File.join(base, name), :encoding=>"utf-8")

(2014-3-13更新)重装系统后,jekyll-1.3.1版本的代码不同了,修改如下:

1
2
def read_yaml(base, name, opts = {:encoding=>"utf-8"})
  begin

OR

http://www.dewen.org/q/5893

要指定文件的编码格式 在文件开头加上 # -*- coding:utf-8 -*-

指定运行环境的编码 使用 ruby --encoding=utf-8

启动

1
2
3
4
5
Winseliu@WINSE ~
$ cd /c/Users/Winseliu/Documents/GitHub/winse.github.com/

Winseliu@WINSE ~/Documents/GitHub/winse.github.com (master)
$ jekyll serve --trace -w

然后访问 http://localhost:4000 即可。

本地调试

  • ruby使用puts输出,可以用来打印调试!
  • 在本地免不了要写一些中文名的文件,可以直接增加try-catch(post.rb#self.valid, cleaner.rb#existing_files)!但网上有讲ruby2.0可以处理中文文件名了!
  • 当然本地调试可以通过修改_config.xml的exclude排除掉,修改好需要发布时再修改为英文文件名即可!

post.rb

1
2
3
4
5
6
7
8
def self.valid?(name)
begin
  name =~ MATCHER
rescue => err
  puts err
  puts name
end
end

编写文件头需要注意的地方;

诡异的jekyll空格

忽然想起之前看过的一篇博客,这篇文章中说起“YAML格局默认是:参数+:+空格,若是忘怀写空格描画编译报错。”。
在这里,恰是因为忘怀了空格导致了HTML文件无法生成的题目。

maruku的不足

使用rdiscount ( gem install rdiscount ) 替换。

参考


WINDOW直接在cygwin中安装jekyll

  1. 使用cygwin setup.exe安装ruby1.9(安装2.0的报编码的错),以及libyaml,最好也把git安装一下。配置环境变量。
  2. 使用gem install jekyll安装。
  3. 安装依赖gem install rdiscount
  4. 启动jekyll serve --trace -w

由于cygwin下默认是utf8编码,并且已经有了linux的各种命令,安装起来很简单。


win10预览版-cygwin32部署octopress(更新于2015-04-18)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
winse@Lenovo-PC ~
$ ruby -v
ruby 2.0.0p598 (2014-11-13) [i386-cygwin]

LC_CTYPE=C.BINARY gem sources -a https://ruby.taobao.org/
LC_CTYPE=C.BINARY gem install bundler
LC_CTYPE=C.BINARY gem install rdiscount

cd winsegit/octopress/
bundle install
rake preview

#去掉watch功能,ruby我不懂啊,实时更新也不是很需要
vi Rakefile
#  jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch")
#  compassPid = Process.spawn("compass watch")
  jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build ")

(更新2017-7-8,通过setup.exe更新了cygwin)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Ruby安装后运行失败:
winse@Lenovo-PC ~
$ ruby -v
C:/cygwin/bin/ruby.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

winse@Lenovo-PC ~
$ cygcheck /bin/ruby
C:\cygwin\bin\ruby.exe
  C:\cygwin\bin\cygruby220.dll
    C:\cygwin\bin\cygwin1.dll
      C:\Windows\system32\KERNEL32.dll
        C:\Windows\system32\ntdll.dll
        C:\Windows\system32\KERNELBASE.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-handle-l1-1-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-synch-l1-2-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-timezone-l1-1-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-string-l1-1-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-util-l1-1-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-profile-l1-1-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-console-l1-1-0.dll
    C:\cygwin\bin\cyggmp-10.dll
    C:\cygwin\bin\cyggcc_s-1.dll
    C:\cygwin\bin\cygssp-0.dll
    C:\Windows\system32\USER32.dll
      C:\Windows\system32\GDI32.dll
cygcheck: track_down: could not find cygcrypt-0.dll

winse@Lenovo-PC ~
$ cygcheck.exe -c | grep Incomplete
libcrypt0                            1.4-1                        Incomplete
...

通过setup.exe重新安装libcrypt0, ruby-devel, rake 10.4.2

winse@Lenovo-PC ~
$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 9808) [i386-cygwin]
last_commit=ruby 2.2.6

$ gem install bigdecimal

winse@Lenovo-PC ~/winsegit/octopress
$ bundle install
Fetching gem metadata from https://ruby.taobao.org/..........

2017-10-29 11:07:45 (win10-2017-appx-ubuntu)

不要复用cygwin的用户目录了,权限和软链的方式都不同了。很麻烦,不如另起炉灶!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
用powershell管理员权限,修改就旧系统的文件属性:
PS E:\winsegit\octopress> cacls *.* /T /G Everyone:F

sudo apt-get update
sudo apt-get install ruby-bundler
sudo apt-get install ruby-dev
sudo apt-get install make
sudo apt-get install gcc
bundle install

sudo gem update
sudo gem uninstall rake
sudo gem install rake -v 10.5.0
sudo apt-get install nodejs
   
rake preview

winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ rake preview
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
Starting to watch source with Jekyll and Compass. Starting Rack on port 4000
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
/var/lib/gems/2.3.0/gems/liquid-2.6.1/lib/liquid/htmltags.rb:43: warning: key "index0" is duplicated and overwritten on line 46
[2017-10-29 22:48:09] INFO  WEBrick 1.3.1
[2017-10-29 22:48:09] INFO  ruby 2.3.1 (2016-04-26) [x86_64-linux-gnu]
[2017-10-29 22:48:09] INFO  WEBrick::HTTPServer#start: pid=39 port=4000
Configuration file: /mnt/e/winsegit/octopress/_config.yml
            Source: source
       Destination: public
      Generating...
                    done.

–END

[Windows运行]快速打开程序

问题/需求描述

由于种种原因,一直都在Windows下进行编程,eclipse/Office/QQ等等这些拖住了切换平台的决心!

在使用windows的时刻,常使用 WIN + r 来快速打开一些系统自带的应用,如regedit/notepad/mspaint/magnify/cmd等。

自己用的软件也希望拥有这种快速打开的能力,如 Git Shell / Cygwin Terminal 。但是能直接在 运行 窗口输入的命令得包含在 PATH 路径下。

  • 快捷方式

如果把需要快速打开应用所有路径全部加入到 PATH 又挺麻烦的(一些要添加启动参数的程序,还得建立快捷方式文件),如下:

1
2
3
4
5
6
C:\Users\Administrator\AppData\Local\GitHub\GitHub.appref-ms --open-shell

C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -

"C:\Program Files\Vim\vim74\vim.exe"
"C:\Program Files\Vim\vim74\gvim.exe"
  • 命令行别名

在命令行窗口情况下,可以通过定义 alias (别名)来实现。具体请参考

1
2
3
4
5
6
7
C:\Users\Administrator>doskey cygwin=C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -

C:\Users\Administrator>doskey /MACROS
cygwin=C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -

# 执行上面的命令
C:\Users\Administrator>cygwin

通过别名可以简化命令,但是必须在已经打开命令行窗口的情况下!!

  • 建立统一的目录管理

解决办法: 最后妥协了,定义一个路径 D:\local\bin ,加入到 PATH 环境变量。把需要使用通过 运行 打开的程序在 bin 目录下建立一个快键指向。使用 mklink 是一个软链接(当然也可以创建个快捷方式,然后改名称)。

1
2
3
4
5
cd D:\local\bin 

mklink git.lnk "C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\GitHub, Inc\Git Shell.lnk"
mklink cygwin.lnk "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Cygwin\Cygwin Terminal.lnk"
mklink vim.lnk "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Vim 7.4\Vim.lnk"

建立指向后的效果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
D:\local\bin>dir
 驱动器 D 中的卷是 Software
 卷的序列号是 C83F-14A7

 D:\local\bin 的目录

2014/02/01  01:57    <DIR>          .
2014/02/01  01:57    <DIR>          ..
2014/02/01  01:56    <SYMLINK>      cygwin.lnk [C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Cygwin\Cygwin Terminal.lnk]
2014/02/01  01:55    <SYMLINK>      git.lnk [C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\GitHub, Inc\Git Shell.lnk]
2014/02/01  01:57    <SYMLINK>      vim.lnk [C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Vim 7.4\Vim.lnk]
               3 个文件              0 字节
               2 个目录  9,673,441,280 可用字节

按照上面的操作[解决办法],就可以通过 WIN + r 然后输入 git 打开Git Shell

本文所处理的问题,在Windows下有现成的工具Launcher可以查找指定路径下的所有程序/文档。

其他快键

通过 WIN + ↑ 可以最大化当前窗口。

参考


【原文地址】

–END

Maven合并打包依赖的git项目

JD的云引擎可以提供一个网站搭建的Java编译发布环境。但是所有源码都要放在下面。 我只是想把JD提供的环境作为一个门面,来展现内容。自己的东西自己管理。(网上解决是使用submodule,强烈推荐看看.

我建了一个源码库flickrUpload在Github上,如果我想把它放到JD的云引擎上运行,需要复制代码然后再提交一次到jd-code。但不想源码版本库分支混乱,并且JD云上仅仅是为了展示,不进行修改。最终实现使用Maven来检出依赖项目,再进行编译打包实现在JD的展示功能。

本地环境使用scm和antrun插件,实现先更新依赖源码再打包

检出依赖源码库

由于对Maven不太熟悉,首先想到的是额外执行系统的命令。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<project>
    <profiles>
        <profile>
            <id>win</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <os>
                    <family>Windows</family>
                </os>
            </activation>
            <properties>
                <flickrUploader>uploader-git-clone.bat</flickrUploader>
            </properties>
        </profile>
        <profile>
            <id>linux</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <os>
                    <family>Linux</family>
                </os>
            </activation>
            <properties>
                <flickrUploader>uploader-git-clone.sh</flickrUploader>
            </properties>
        </profile>
    </profiles>

    <build>
        <finalName>product</finalName>

        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>dist</directory>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.1.1</version>
                <executions>
                    <execution>
                        <id>some-execution</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>${basedir}/script/${flickrUploader}</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>

根据profile来配置来判断环境,执行特定的命令(bat/sh)。

  • Windows脚本
1
2
3
4
# uploader-git-clone.bat
del /s /q /f dist\Hello-World
rmdir /s /q dist\Hello-World
"C:\Program Files\Git\bin\git.exe" clone https://github.com/octocat/Hello-World.git dist\Hello-World
  • Linux脚本
1
2
3
# uploader-git-clone.sh
rm -rf dist/Hello-World
git clone https://github.com/octocat/Hello-World.git dist/Hello-World

测试在本地window已经能实现自己的要求,能把checkout项目的内容放在了发布包的根目录下面。

执行mvn package后的target目录结构如下:

源码库路径重定位

发布时把源码库文件放置到war的根目录下面,有考虑过COPY:如Copy-maven-plugin,还有如下outputDirectory的形式(参考):

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
              <resources>          
                <resource>
                  <directory>src/non-packaged-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

最终实现

上面就要解决两个问题:源码检出和资源重定位。

后面发现war可以包含特定目录的资源,资源重定位实现就用war的webResources实现了。 同时为了把检出源码的清理工作提取到clean任务下,添加使用antrun插件。同时发现scm插件就实现了检出源码的功能maven-scm-plugin

使用antrun和scm完全使用Maven实现,最终的插件配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<project>
    <build>
        <finalName>product</finalName>

        <plugins>

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>clean</phase>
                        <configuration>
                            <tasks>
                                <delete includeEmptyDirs="true">
                                    <fileset dir="${scm-dist}" />
                                </delete>

                                <mkdir dir="${scm-dist}" />
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-scm-plugin</artifactId>
                <version>1.9</version>
                <configuration>
                    <skipCheckoutIfExists>true</skipCheckoutIfExists>
                    <checkoutDirectory>${scm-dist}/flikr</checkoutDirectory>
                    <connectionUrl>scm:git:https://github.com/octocat/Hello-World.git</connectionUrl>
                </configuration>
                <executions>
                    <execution>
                        <phase>clean</phase>
                        <goals>
                            <goal>checkout</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>${scm-dist}</directory>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <properties>
        <!-- for scm -->
        <scm-dist>dist</scm-dist>
    </properties>

现在使用mvn clean package就可以实现先checkout项目再打包发布了。最终效果全部使用maven实现,无需额外考虑平台之间的差异处理。

JD的云引擎Maven编译不支持scm插件

不支持的插件:’maven-scm-plugin’ 在pom文件中被发现,编译将终止,请检查并更新代码!

然后部署到云引擎的时刻,发现antrun和scm的插件都不行,exec也不行! 也尝试过submodule,但是邮件JD的回复说是云上引用内部的才有效!

发布到云引擎最终还是用最土的方法,先删除旧的版本库,然后检出,在提交到云引擎的版本库中。

1
2
3
4
5
# flickr-upload-commit.sh
rm -rf src/main/webapp/flickr
git clone git@github.com:winse/flickr-uploader.git src/main/webapp/flickr
rm -rf src/main/webapp/flickr/.git
git add -A && git commit -m "update uploader, please see https://github.com/winse/flickr-uploader" && git push

其他

  • 子模块基本操作命令

$ git submodule add git@github.com:josephj/javascript-platform-yui.git static/platform
$ git add .gitmodules static/platform $ git submodule init

$ cd static/platform
$ git pull origin master
$ cd ../../
$ git add static/platform
$ git commit -m “static/platform submodule updated”

$ git submodule init
$ git submodule update

$ cd static/platform
$ vim README # 做些修改
$ git add README
$ git commit -m “Add comments”
$ git push
$ git add static/platform
$ git commit -m ‘Submodule updated
$ git push

$ git rm –cached [欲移除的目錄]
$ rm -rf [欲移除的目錄]
$ vim .gitmodules
$ vim .git/config
$ git add .gitmodules
$ git commit -m “Remove a submodule”
$ git submodule sync

参考


【原文地址】

–END

Cygwin兼容配置

换了新电脑后,以及hadoop2/hbase/zookeeper都提供了基于windows的命令。使用cygwin的驱动力弱化了。现在主要用于git/jekyll/sed/awk/find等基础工具的使用。同时多窗口运行需求比较少。当前主要使用自带的mintty。

.vimrc

默认Vim的insert模式下使用上下方向键使用会变成其他的输入(方向键变成ABCD),操作很麻烦。需要对vim进行一些设置。

1
2
3
4
5
Winseliu@WINSE ~
$ cat .vimrc 
set nocompatible 
set backspace=indent,eol,start 
set bs=2 

参考http://ruby-china.org/topics/4866 第19楼的回复

/etc/fstab 文件权限

1
none /cygdrive cygdrive binary,noacl,posix=0,user 0 0    

打开windows窗口

1
explorer '/select,' "$(cygpath -C ANSI -w "$XPATH")"

参考http://oldratlee.com/post/2012-12-22/stunning-cygwin

SecureCRT

java查找文件路径

1
2
3
Winseliu@WINSE /cygdrive/d/winsegit
$ antlr4
Error: Unable to access jarfile /cygdrive/d/winsegit/lib/antlr-4.1-complete.jar

由于java在window环境下需要的路径是c:\,需要通过cygpath进行转换。

1
2
alias antlr4='java -jar `cygpath -w $WINSE_HOME/lib/antlr-*-complete.jar`'
export CLASSPATH=".;`cygpath -w $WINSE_HOME/lib/antlr-*-complete.jar`;$CLASSPATH"

字符集

Linux和window不同,Linux默认的字符集是UTF8,而Windows为GBK。 为了统一两个环境的字符,需要对Cygwin的字符集进行设置。

1
2
3
#.bashrc
export LANG="zh_CN.GB2312"
export OUTPUT_CHARSET="GB2312"

还需要把连接工具的编码也改成gb2312。

参考http://www.cygwin.cn/site/info/show.php?IID=1006

参考

–END