Gradleを使ってEclipse本体とEclipseプラグイン(フィーチャー)をインストールするためのbuild.gradleは、以下の通り。なお、動作確認はWindows上で行っているが、適宜書き換えればUnix系のOSでも動くはず。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project.ext.tempDir = 'tmp' | |
project.ext.targetEclipseDir = 'd:/eclipse' | |
ant.condition(property: "os", value: "windows") { os(family: "windows") } | |
ant.condition(property: "os", value: "unix" ) { os(family: "unix") } | |
task clean << { delete 'tmp' } | |
task installEclipse << { | |
new File(tempDir).mkdirs() | |
ant.get(dest:tempDir, skipexisting:true){ | |
url(url:"http://ftp.jaist.ac.jp/pub/eclipse/technology/epp/downloads/release/juno/SR2/eclipse-rcp-juno-SR2-win32.zip") | |
} | |
ant.unzip(dest:tempDir, overwrite:"false"){ | |
fileset(dir: project.tempDir){ include (name:'*.zip')} | |
} | |
ant.move(toDir: project.targetEclipseDir){ | |
fileset(dir: "${tempDir}/eclipse") | |
} | |
ant.copy(file:'files/eclipse.ini', toDir: targetEclipseDir) | |
} | |
def getCommandList(String command){ | |
def commandList = [ | |
"${targetEclipseDir}/eclipse", | |
"-application", | |
"org.eclipse.equinox.p2.director", | |
"-noSplash" | |
]+ | |
command.replaceAll(/,[^\\]\n/, ',').replaceAll(/[^\\]\n/, ' ').split(/\s+/) + | |
[ | |
"-vmargs", | |
"-Dlogback.configurationFile=logback.xml" | |
] | |
if(ant.properties.os == 'windows'){ | |
commandList = ['cmd', '/c']+ commandList | |
} | |
commandList.flatten() | |
} | |
task installPlugins(type:Exec) { | |
ext.command = """\ | |
-repository http://dist.springsource.org/release/GRECLIPSE/e4.2/,^ | |
http://dist.springsource.com/release/TOOLS/gradle^ | |
-installIUs org.codehaus.groovy.eclipse.feature.feature.group,^ | |
org.springsource.ide.eclipse.gradle.feature.feature.group^ | |
-d ${targetEclipseDir}""" | |
commandLine getCommandList(command) | |
} | |
installPlugins.mustRunAfter installEclipse | |
task wrapper(type: Wrapper) { gradleVersion = '1.6' } |
2行目で、Eclipseのインストール先ディレクトリを指定している。
Eclipse本体のインストールは、
installEclise
タスク(9行目)で行っている。単にEclipseのダウンロードサイトにあるアーカイブをダウンロード(11行目)して解凍しているだけ。必要なら、インストールしたいEclipseのバージョンや対象プラットフォームに合わせて適宜書き換える。eclipse.iniの置き換え(20行目)はお好みで。Eclipseプラグインのインストールには、上記でダウンロードしたEclipse本体に含まれるp2 director (
org.eclipse.equinox.p2.director
) を利用する(27行目)。プラグインをインストールする際に、やたら細かいDebugログが出力されるのを抑止するために、logbackの設定ファイルを指定している(33行目)。インストールするEclipseプラグインは、p2 directorのコマンドオプションとして指定する。p2 directorを使ったEclipseプラグインのインストールについては、下記リンクを参照。
installPlugins
タスク(42行目)で、インストールに必要な更新サイトをp2 directorのrepositoryオプション(44, 45行目)に、インストール対象のプラグイン(フィーチャー)をinstallIUsオプション(46, 47行目)に指定している。repositoryオプションおよびinstallIUsオプションでは、複数の更新サイト、プラグインをカンマ区切りで指定できるが、途中にスペースを入れると実行時エラーとなる点に注意。なお、インストールするプラグインがひとつの場合は、installIUsの代わりにinstallIUオプションを使用する。オプションの詳細については、下記を参照(ただし、installIUsについては記載がない)。
上記のbuild.gradleや関連するファイル(eclipse.iniやlogback.xml)を、任意のディレクトリに以下のように配置する。
build.gradle logback.xml │ └─files └─eclipse.inibuild.gradleが含まれるディレクトリで以下のコマンドを実行すれば、build.gradleで指定したEclipse本体とEclipseプラグイン(上記の例では、Groovy-EclipseとGradle IDE)がインストールされるはず。
gradle installEclipse installPluginsなお、mustRunAfter(53行目)は、タスクを直列実行するためにGradle 1.6から追加された機能なので、Gradle 1.5以前で実行する場合は、depandsOnなどに書き換える。
上記ファイルをgradlewとともにgitリポジトリなどに公開しておけば、幸せになれそう。
0 件のコメント:
コメントを投稿