package org.mirah.maven;

/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import java.util.ArrayList;
import java.util.List;

import org.mirah.MirahCommand;

/**
 * Goal which compiles Mirah source files
 *
 * @goal compile
 * @phase compile
 * @requiresDependencyResolution compile
 */
public class MirahCompilerMojo extends AbstractMojo {
    /**
     * Classes destination directory
     * @parameter expression="${project.build.outputDirectory}"
     */
    private File outputDirectory;
    /**
     * Classes source directory
     * @parameter expression="src/main/mirah"
     */
    private File sourceDirectory;
    /**
     * Whether produce bytecode or java source
     * @parameter bytecode, default true
     */
    private boolean bytecode = true;
    /**
     * Show log
     * @parameter verbose, default false
     */
    private boolean verbose;

    public void execute() throws MojoExecutionException {
        if ( !outputDirectory.exists() ) {
            outputDirectory.mkdirs();
        }

        List arguments = new ArrayList();
        if (!bytecode)
          arguments.add("--java");
        if (verbose)
          arguments.add("-V");

        arguments.add("-d");
        arguments.add(outputDirectory.getAbsolutePath());

        arguments.add(sourceDirectory.getAbsolutePath());

        try {
            MirahCommand.compile(arguments);
        } catch (Exception e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
}

@@ -23,630 +23,8 @@
 n;%0A%0A
-/*%0A * Copyright 2001-2005 The Apache Software Foundation.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0A
 impo
@@ -110,32 +110,78 @@
 cutionException;
+%0Aimport org.apache.maven.project.MavenProject;
 %0A%0Aimport java.io
@@ -291,24 +291,70 @@
 util.List;%0A%0A
+import org.codehaus.plexus.util.StringUtils;%0A%0A
 import org.m
@@ -489,24 +489,16 @@
 solution
- compile
 %0A */%0Apub
@@ -548,32 +548,158 @@
 tMojo %7B%0A    /**%0A
+     * @parameter expression=%22$%7Bproject%7D%22%0A     * @required%0A     * @readonly%0A     */%0A    private MavenProject project;%0A    /**%0A
      * Classes d
@@ -1580,32 +1580,380 @@
 solutePath());%0A%0A
+        try %7B%0A            List%3CString%3E compileClasspath = project.getCompileClasspathElements();%0A            compileClasspath.addAll(project.getRuntimeClasspathElements());%0A            String classpath = StringUtils.join(compileClasspath.iterator(), File.pathSeparator);%0A%0A            arguments.add(%22-c%22);%0A            arguments.add(classpath);%0A%0A    
         argument
@@ -1991,38 +1991,24 @@
 tePath());%0A%0A
-        try %7B%0A
             

use project classpath to resolve mirah dependencies