Showing posts with label Plugin. Show all posts
Showing posts with label Plugin. Show all posts

Saturday, November 27, 2010

用maven来运行一个main方法或者启动Server

在maven项目的pom.xml文件的plugins中加入"exec-maven-plugin"这个插件,这个在运行"mvn package"时,会在当前的mvn进程中直接执行指定的class文件的main方法,也可以配置其他的参数,让此main在另一个java进程中启动。如果其中将phase的内容改为"test",就会在运行"mvn test"时执行main方法,也可以在命令行里直接用mvn运行,如下注释说明。
更详细的信息和配置方法,可参考http://mojo.codehaus.org/exec-maven-plugin/usage.html说明。

<!-- commandline: mvn exec:java -Dexec.mainClass="org.phpfirefly.test.Server" -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.phpfirefly.test.Server</mainClass>
</configuration>
</plugin>

Monday, August 30, 2010

maven:install在命令行构建成功而m2eclipse中构建失败

在命令行中用
$> mvn package
能构建成功,但在eclipse中用m2eclipse插件则构建失败,提示信息摘录部分如下:
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] dependenciesInfo : dependenciesInfo
---- Debugging information ----
message : dependenciesInfo : dependenciesInfo
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : dependenciesInfo : dependenciesInfo
class : org.apache.maven.plugin.war.util.WebappStructure
required-type : org.apache.maven.plugin.war.util.WebappStructure
path : /webapp-structure/dependenciesInfo

在网上查了一些资料,主要参考: http://jira.codehaus.org/browse/MWAR-187
之所以命令行能成功,而插件不成功,主要原因是二者的maven版本不一样造成的,因为2eclipse使用embedded Maven 3 (Maven Embedder 3.0.-SNAPSHOT),可以通过window->perferences->Maven->Installations查看到。

解决这个问题的方法在上文链接中也有提到:
1、Maven版本降级
2、最快捷的方式是禁用缓存(webapp-cache.xml)

<configuration>
<useCache>false</useCache>
</configuration>

3、在eclipse中用m2eclipse插,先运行mvn clean后(这样会删除target目录),再运行mvn install

References: http://jira.codehaus.org/browse/MWAR-187

Thursday, July 31, 2008

Rails Plugins 相关命令

$> script/plugin -h


Usage: plugin [OPTIONS] command
Rails plugin manager.

GENERAL OPTIONS
-r, --root=DIR Set an explicit rails app directory.
Default: /Users/yu/Sites/docbox
-s, --source=URL1,URL2 Use the specified plugin repositories instead of the defaults.
-v, --verbose Turn on verbose output.
-h, --help Show this help message.

COMMANDS
discover Discover plugin repositories.
list List available plugins.
install Install plugin(s) from known repositories or URLs.
update Update installed plugins.
remove Uninstall plugins.
source Add a plugin source repository.
unsource Remove a plugin repository.
sources List currently configured plugin repositories.

EXAMPLES
Install a plugin:
plugin install continuous_builder

Install a plugin from a subversion URL:
plugin install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder

Install a plugin from a git URL:
plugin install git://github.com/SomeGuy/my_awesome_plugin.git

Install a plugin and add a svn:externals entry to vendor/plugins
plugin install -x continuous_builder

List all available plugins:
plugin list

List plugins in the specified repository:
plugin list --source=http://dev.rubyonrails.com/svn/rails/plugins/

Discover and prompt to add new repositories:
plugin discover

Discover new repositories but just list them, don't add anything:
plugin discover -l

Add a new repository to the source list:
plugin source http://dev.rubyonrails.com/svn/rails/plugins/

Remove a repository from the source list:
plugin unsource http://dev.rubyonrails.com/svn/rails/plugins/

Show currently configured repositories:
plugin sources

Saturday, February 02, 2008

gem unpack usage and example

E:\workspace\>gem help unpack
Usage: gem unpack GEMNAME [options]

Options:
--target target directory for unpacking
-v, --version VERSION Specify version of gem to unpack

Common Options:
-h, --help Get help on this command
-V, --[no-]verbose Set the verbose level of output
-q, --quiet Silence commands
--config-file FILE Use this config file instead of default
--backtrace Show stack backtrace on errors
--debug Turn on Ruby debugging


Arguments:
GEMNAME name of gem to unpack

Summary:
Unpack an installed gem to the current directory

Defaults:
--version '>= 0'

Example:
$> gem install mofo
$> cd rails_app/vendor/plugins
$> gem unpack mofo

Tuesday, September 25, 2007

Rails migration plugins from Mr.err

sexy db migration:


class UpdateYourFamily < ActiveRecord::Migration
create_table :updates do |t|
t.column :user_id, :integer
t.column :group_id, :integer
t.column :body, :text
t.column :type, :string

t.column :created_at, :datetime
t.column :updated_at, :datetime
end

def self.down
drop_table :updates
end
end

Into this:

class UpdateYourFamily < ActiveRecord::Migration
create_table :updates do
foreign_key :user
foreign_key :group

text :body
string :type

timestamps!
end

def self.down
drop_table :updates
end
end

Using this:
SVN:
$ ./script/plugin install \ svn://errtheblog.com/svn/plugins/sexy_migrations

auto db migration, change this:

ActiveRecord::Schema.define(:version => 1) do
create_table :posts do |t|
t.string :title
t.text :body
end
end

into

ActiveRecord::Schema.define(:version => 1) do
create_table :posts do |t|
t.string :title
t.text :body
t.integer :published
end

create_table :comments do |t|
t.string :name, :url
t.text :body
t.integer :post_id
end
end

and run:
$ rake db:auto:migrate

it’ll execute the following:

-- add_column("posts", :published, :integer)
-> 0.0096s
-- create_table(:comments)
-> 0.0072s

Pretty slick. Run the task again and nothing will happen, just like regular migrations, but change the file and the plugin will do its best to figure out what you’ve done.
and support index:

ActiveRecord::Schema.define(:version => 1) do
create_table :posts do |t|
t.string :title
t.text :body
t.integer :published
end

add_index :posts, :published

create_table :comments do |t|
t.string :name, :url
t.text :body
t.integer :post_id
end
end

Followed by:

$ rake db:auto:migrate
-- add_index("posts", ["published"])
-> 0.0216s


ActiveRecord::Schema.define(:version => 1) do
create_table :posts do |t|
t.string :title
t.text :body
t.integer :published
end

# add_index :posts, :published

create_table :comments do |t|
t.string :name, :url
t.text :body
t.integer :post_id
end
end

And auto-migrate again:

$ rake db:auto:migrate
-- remove_index("posts", {:name=>"index_posts_on_published"})
-> 0.0187s

Check it Out:
Warehouse: http://plugins.require.errtheblog.com/browser/auto_migrations
SVN: svn://errtheblog.com/svn/plugins/auto_migrations

Friday, August 24, 2007

Rails output compress plugin

source code from: http://blog.craz8.com/files/compress.rb


require 'stringio'
require 'zlib'

class OutputCompressionFilter

def self.filter(controller)
return if controller.response.headers['Content-Encoding'] || controller.request.env['HTTP_ACCEPT_ENCODING'].nil?
begin
controller.request.env['HTTP_ACCEPT_ENCODING'].split(/\s*,\s*/).each do |encoding|
# TODO: use "q" values to determine user agent encoding preferences
case encoding
when /\Agzip\b/
StringIO.open('', 'w') do |strio|
begin
gz = Zlib::GzipWriter.new(strio)
gz.write(controller.response.body)
controller.response.body = strio.string
ensure
gz.close if gz
end
end
when /\Adeflate\b/
controller.response.body = Zlib::Deflate.deflate(controller.response.body, Zlib::BEST_COMPRESSION)
when /\Aidentity\b/
# do nothing for identity
else
next # the encoding is not supported, try the next one
end
controller.logger.info "Response body was encoded with #{encoding}"
controller.response.headers['Content-Encoding'] = encoding
break # the encoding is supported, stop
end
end
controller.response.headers['Content-Length'] = controller.response.body.length
if controller.response.headers['Vary'] != '*'
controller.response.headers['Vary'] =
controller.response.headers['Vary'].to_s.split(',').push('Accept-Encoding').uniq.join(',')
end
end

end

Monday, April 02, 2007

click_track plugin

Quick Start

This quick start guide will get you up and running with the click_track plugin in just a few minutes.
Installing the Plugin

You would normally use the script/plugin utility that comes with Rails to install a plugin. However, that script assumes a repository layout that is different than the one used for the click_track plugin.

Therefore, you can export the plugin from its Subversion repository, check it out, or add it as a svn:externals.

svn export \
https://crookedhideout.com/svn/oss/click_track/branches/rel/0.1/ \
vendor/plugins/click_track

Once you have the click_track plugin installed in your vendor/plugins directory, you’ll want to generate the migration for the database changes:

script/generate click_track add_clicks
rake db:migrate

Tracking a Controller
For each controller you want tracked do this:

class FoobarController < ApplicationController
click_track
end

The click_track call takes the same arguments as a before_filter.

All actions called on this controller will be tracked. Views for this controller can now use click_track(..) in place of link_to(..) for tracking when an external link is followed.
How to Use the Data
Here is the table behind the Click model:

create_table :clicks do |t|
t.column :controller, :string, :null=>false
t.column :action, :string, :null=>false
t.column :param_id, :integer
t.column :ssl, :boolean, :null=>false
t.column :http_method, :string, :null=>false
t.column :remote_ip, :string, :null=>false
t.column :request_uri, :string, :null=>false
t.column :user_agent, :string
t.column :browser, :string
t.column :browser_version, :string
t.column :browser_platform,:string
t.column :created_at, :datetime, :null=>false
end

Here are some examples of how one might use the data. These are taken from the statistics page of the crookedhidout.com site.

class StatisticsController < ApplicationController
def index
@clicks = (Click.in_last(7.days) || [])[0..12]
@popular_clicks = (Click.bucket_simple_uri_in_last(7.days) || [])[0..8]
@fan_clicks = (Click.bucket_remote_ip_in_last(30.days) || [])[0..8]
@last_24_count = Click.total_in_last 24.hours
end
end

This is going to grow my database forever!
Every one in ActionController::ClickTrack.chance times (default is 10,000) the DB will be cleared of all clicks older then ActionController::ClickTrack.oldest_click (default is 90.days). You can change these values in your config/environment.rb file. For example:

ActionController::ClickTrack.chance = 50000
ActionController::ClickTrack.oldest_click = 40.weeks