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.kuali;
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 rice standalone prototype
065 * 
066 * @author Leo Przybylski (przybyls [at] arizona.edu)
067 */
068 @Mojo(
069     name="create-standalone-overlay",
070     requiresProject = false
071     )
072public class CreateStandaloneOverlayMojo extends AbstractMojo {
073    @Component(role = org.kualigan.maven.plugins.api.OverlayHelper.class)
074    private OverlayHelper helper;
075
076    /**
077     */
078    @Parameter(property = "localRepository", required = true)
079    private ArtifactRepository localRepository;
080    
081    /**
082     */
083    @Parameter(property = "groupId", required = true)
084    private String groupId;
085
086    /**
087     */
088    @Parameter(property = "artifactId", required = true)
089    private String artifactId;
090
091    /**
092     */
093    @Parameter(property="version", defaultValue="1.0-SNAPSHOT")
094    private String version;
095    
096    @Parameter(property = "kr.prototype.groupId", defaultValue = "org.kuali.rice")
097    protected String prototypeGroupId;
098    
099    @Parameter(property = "kr.prototype.artifactId", defaultValue = "rice-standalone")
100    protected String prototypeArtifactId;
101    
102    @Parameter(property = "kr.prototype.version", defaultValue = "2.1.0")
103    protected String prototypeVersion;
104    
105    @Parameter(property = "archetypeGroupId", defaultValue = "org.kualigan.maven.archetypes")
106    protected String archetypeGroupId;
107    
108    @Parameter(property = "archetypeArtifactId", defaultValue = "kr-archetype")
109    protected String archetypeArtifactId;
110    
111    @Parameter(property = "archetypeVersion", defaultValue = "1.1.4")
112    protected String archetypeVersion;
113    
114    /**
115     * The {@code M2_HOME} parameter to use for forked Maven invocations.
116     *
117     */
118    @Parameter(defaultValue = "${maven.home}")
119    protected File mavenHome;
120
121    /**
122     */
123    @Parameter(property = "project")
124    private MavenProject project;
125
126    /**
127     * Produce an overlay from a given prototype. 
128     */
129    public void execute() throws MojoExecutionException {
130        helper.setCaller(this);
131        helper.generateArchetype(getMavenHome(), new Properties() {{
132                        setProperty("archetypeGroupId",      archetypeGroupId);
133                        setProperty("archetypeArtifactId",   archetypeArtifactId);
134                        setProperty("archetypeVersion",      archetypeVersion);
135                        setProperty("groupId",               groupId);
136                        setProperty("artifactId",            artifactId);
137                        setProperty("version",               version);
138                        setProperty("krPrototypeGroupId",    prototypeGroupId);
139                        setProperty("krPrototypeArtifactId", prototypeArtifactId);
140                        setProperty("krPrototypeVersion",    prototypeVersion);
141                    }});
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}