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.kc;
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 KC 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
074    @Component(role = org.kualigan.maven.plugins.api.OverlayHelper.class,
075               hint = "default")
076    private OverlayHelper helper;
077    
078    /**
079     */
080    @Parameter(property = "localRepository", required = true)
081    private ArtifactRepository localRepository;
082    
083    /**
084     */
085    @Parameter(property = "groupId")
086    private String groupId;
087
088    /**
089     */
090    @Parameter(property = "artifactId")
091    private String artifactId;
092
093    /**
094     */
095    @Parameter(property="version", defaultValue="1.0-SNAPSHOT")
096    private String version;
097    
098    @Parameter(property = "kc.prototype.groupId", defaultValue = "org.kuali.kc")
099    protected String prototypeGroupId;
100    
101    @Parameter(property = "kc.prototype.artifactId", defaultValue = "kc")
102    protected String prototypeArtifactId;
103    
104    @Parameter(property = "kc.prototype.version", defaultValue = "5.0")
105    protected String prototypeVersion;
106    
107    @Parameter(property = "archetypeGroupId", defaultValue = "org.kualigan.maven.archetypes")
108    protected String archetypeGroupId;
109    
110    @Parameter(property = "archetypeArtifactId", defaultValue = "kc-archetype")
111    protected String archetypeArtifactId;
112    
113    @Parameter(property = "archetypeVersion", defaultValue = "1.1.1")
114    protected String archetypeVersion;
115    
116    /**
117     * The {@code M2_HOME} parameter to use for forked Maven invocations.
118     *
119     */
120    @Parameter(defaultValue = "${maven.home}")
121    protected File mavenHome;
122
123    /**
124     */
125    @Parameter(property = "project")
126    private MavenProject project;
127
128    /**
129     * Produce an overlay from a given prototype. 
130     */
131    public void execute() throws MojoExecutionException {
132        helper.generateArchetype(getMavenHome(),
133                                 archetypeGroupId,
134                                 archetypeArtifactId,
135                                 archetypeVersion,
136                                 groupId,
137                                 artifactId,
138                                 version,
139                                 prototypeGroupId,
140                                 prototypeArtifactId,
141                                 prototypeVersion);
142    }
143
144    public void setMavenHome(final File mavenHome) {
145        this.mavenHome = mavenHome;
146    }
147    
148    public File getMavenHome() {
149        return this.mavenHome;
150    }
151        
152}