maven2 で plugin を作ってみる

こんなpomで

<project 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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>cc.aileron</groupId>
	<artifactId>samplemojo</artifactId>
	<packaging>maven-plugin</packaging>
	<version>0.0.1</version>
	<name>samplemojo Maven Mojo</name>
	<url>http://maven.apache.org</url>

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<encoding>UTF-8</encoding>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.3</version>
			</plugin>
		</plugins>
	</build>

    <dependencies>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

こんな java

public class MyMojo extends AbstractMojo
{
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException
    {
        final Console console = System.console();
        while (true)
        {
            final String line = console.readLine("q:");
            System.out.println("a:" + line);

            if (line.equals("quit"))
            {
                break;
            }
        }
    }
}

mvn install して
mvn cc.aileron:samplemojo:sample

すると、ちゃんと対話型インタフェースで作れるよ!!!