/*
 * Copyright 2019 OPS4J Contributors
 *
 * 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.
 */
package org.ops4j.ramler.maven;

import java.io.File;

import javax.inject.Inject;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.sonatype.plexus.build.incremental.BuildContext;

/**
 * Base class for Ramler Mojos, taking care of incremental builds with m2e.
 *
 * @author Harald Wellmann
 *
 */
public abstract class AbstractRamlerMojo extends AbstractMojo {

    /** RAML specification file, relative to <code>${project.basedir}</code>. */
    @Parameter(required = true)
    protected String model;

    @Parameter(readonly = true, defaultValue = "${project}")
    protected MavenProject project;

    @Inject
    private BuildContext buildContext;

    @Override
    public void execute() throws MojoFailureException {
        extendProject();
        if (buildContext.hasDelta(model)) {
            generateOutput();
            refreshOutput();
        }
        else {
            getLog().info("Skipping execution, RAML model is unchanged");
        }
    }

    private void refreshOutput() {
        getLog().debug("refreshing " + getOutputDir());
        buildContext.refresh(getOutputDir());
    }

    protected abstract void generateOutput() throws MojoFailureException;

    protected abstract File getOutputDir();

    /**
     * Override to add (test) source directories.
     */
    protected void extendProject() {
        // empty
    }
}

@@ -1484,16 +1484,45 @@
 ption %7B%0A
+        validateModelPath();%0A
         
@@ -1753,24 +1753,283 @@
    %7D%0A    %7D%0A%0A
+    private void validateModelPath() throws MojoFailureException %7B%0A        if (new File(model).isAbsolute()) %7B%0A            throw new MojoFailureException(%0A                %22%3Cmodel%3E must be a relative path with respect to $%7Bproject.basedir%7D%22);%0A        %7D%0A    %7D%0A%0A
     private 

validate that <model> path is relative