001/*
002 * Copyright 2007 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 * http://www.opensource.org/licenses/ecl2.php
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kualigan.maven.plugins.kfs;
017
018import org.kualigan.maven.plugins.api.OverlayHelper;
019
020import org.apache.commons.cli.CommandLine;
021import org.apache.commons.cli.OptionBuilder;
022import org.apache.commons.cli.Options;
023import org.apache.commons.cli.PosixParser;
024
025import org.apache.maven.archetype.Archetype;
026import org.apache.maven.artifact.repository.ArtifactRepository;
027import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
028import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
029import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
030
031import org.apache.maven.plugin.AbstractMojo;
032import org.apache.maven.plugin.MojoExecutionException;
033import org.apache.maven.plugins.annotations.Component;
034import org.apache.maven.plugins.annotations.Mojo;
035import org.apache.maven.plugins.annotations.Parameter;
036
037import org.apache.maven.shared.invoker.DefaultInvocationRequest;
038import org.apache.maven.shared.invoker.DefaultInvoker;
039import org.apache.maven.shared.invoker.InvocationOutputHandler;
040import org.apache.maven.shared.invoker.InvocationRequest;
041import org.apache.maven.shared.invoker.InvocationResult;
042import org.apache.maven.shared.invoker.Invoker;
043import org.apache.maven.shared.invoker.InvokerLogger;
044import org.apache.maven.shared.invoker.MavenInvocationException;
045
046import org.apache.maven.project.MavenProject;
047import org.codehaus.plexus.components.interactivity.Prompter;
048import org.codehaus.plexus.util.FileUtils;
049import org.codehaus.plexus.util.IOUtil;
050import org.codehaus.plexus.util.StringUtils;
051import org.codehaus.plexus.util.cli.CommandLineUtils;
052
053import java.io.File;
054import java.io.FileWriter;
055import java.io.InputStream;
056import java.util.ArrayList;
057import java.util.HashMap;
058import java.util.List;
059import java.util.Map;
060import java.util.Properties;
061import java.util.StringTokenizer;
062
063/**
064 * Creates a maven overlay for the given KFS prototype
065 * 
066 * @author Leo Przybylski (przybyls [at] arizona.edu)
067 */
068 @Mojo(
069     name="create-overlay",
070     requiresProject = false
071     )
072public class CreateOverlayMojo extends AbstractMojo {
073    @Component(role = org.kualigan.maven.plugins.api.OverlayHelper.class,
074               hint = "default")
075    private OverlayHelper helper;
076
077    /**
078     */
079    @Parameter(property = "localRepository", required = true)
080    private ArtifactRepository localRepository;
081    
082    /**
083     */
084    @Parameter(property = "groupId")
085    private String groupId;
086
087    /**
088     */
089    @Parameter(property = "artifactId")
090    private String artifactId;
091
092    /**
093     */
094    @Parameter(property="version", defaultValue="1.0-SNAPSHOT")
095    private String version;
096    
097    @Parameter(property = "kfs.prototype.groupId", defaultValue = "org.kuali.kfs")
098    protected String prototypeGroupId;
099    
100    @Parameter(property = "kfs.prototype.artifactId", defaultValue = "kfs")
101    protected String prototypeArtifactId;
102    
103    @Parameter(property = "kfs.prototype.version", defaultValue = "5.0")
104    protected String prototypeVersion;
105    
106    @Parameter(property = "archetypeGroupId", defaultValue = "org.kualigan.maven.archetypes")
107    protected String archetypeGroupId;
108    
109    @Parameter(property = "archetypeArtifactId", defaultValue = "kfs-archetype")
110    protected String archetypeArtifactId;
111    
112    @Parameter(property = "archetypeVersion", defaultValue = "1.1.1")
113    protected String archetypeVersion;
114    
115    /**
116     * The {@code M2_HOME} parameter to use for forked Maven invocations.
117     *
118     */
119    @Parameter(defaultValue = "${maven.home}")
120    protected File mavenHome;
121
122    /**
123     */
124    @Parameter(property = "project")
125    private MavenProject project;
126
127    /**
128     * Produce an overlay from a given prototype. 
129     */
130    public void execute() throws MojoExecutionException {
131        helper.generateArchetype(getMavenHome(),
132                                 archetypeGroupId,
133                                 archetypeArtifactId,
134                                 archetypeVersion,
135                                 groupId,
136                                 artifactId,
137                                 version,
138                                 prototypeGroupId,
139                                 prototypeArtifactId,
140                                 prototypeVersion);
141    }
142    
143    public void setMavenHome(final File mavenHome) {
144        this.mavenHome = mavenHome;
145    }
146    
147    public File getMavenHome() {
148        return this.mavenHome;
149    }
150        
151}