/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.apache.maven.dotnet.plugin.install;

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

import java.io.File;

import org.apache.maven.dotnet.artifact.ArtifactContext;
import org.apache.maven.artifact.installer.ArtifactInstallationException;

/**
 * @goal install-file
 * @requiresProject false
 * @requiresDirectInvocation true
 */

public class FileInstallerMojo
    extends AbstractMojo
{

    /**
     * The maven project.
     *
     * @parameter expression="${project}"
     * @required
     */
    private MavenProject project;

    /**
     * @parameter expression="${settings.localRepository}"
     * @required
     */
    private File localRepository;

    /**
     * @parameter expression = "${file}
     * @required
     */
    private File artifactFile;

    /**
     * @parameter expression = "${pomFile}
     */
    private File pomFile;

    /**
     * @parameter expression = "${groupId}
     * @required
     */
    private String groupId;

    /**
     * @parameter expression = "${artifactId}
     * @required
     */
    private String artifactId;

    /**
     * @parameter expression = "${artifactVersion}
     * @required
     */
    private String version;

    /**
     * @parameter expression = "${packaging}
     * @required
     */
    private String packaging;

    /**
     * @parameter expression = "${generatePom}" default-value = "true"
     */
    private boolean generatePom;

    /**
     * @component
     */
    private ArtifactContext artifactContext;

    /**
     * @component
     */
    private org.apache.maven.dotnet.NMavenRepositoryRegistry nmavenRegistry;

    public void execute()
        throws MojoExecutionException
    {
        artifactContext.init( project, project.getRemoteArtifactRepositories(), localRepository );
        if ( pomFile != null && !pomFile.exists() )
        {
            throw new MojoExecutionException(
                "NMAVEN-1000-002: Pom  File is missing: File = " + pomFile.getAbsolutePath() );
        }
        else if ( generatePom &&  pomFile == null  )
        {
            try
            {

                artifactContext.getArtifactInstaller().installFileWithGeneratedPom( groupId, artifactId, version,
                                                                                    packaging, artifactFile );
            }
            catch ( org.apache.maven.artifact.installer.ArtifactInstallationException e )
            {
                throw new MojoExecutionException( "NMAVEN-1000-000: Failed to install artifact file", e );
            }
        }
        else if(pomFile != null)
        {
            try
            {
                artifactContext.getArtifactInstaller().installArtifact( project.getArtifact(), pomFile);
            }
            catch ( ArtifactInstallationException e )
            {
               throw new MojoExecutionException( "NMAVEN-1000-003: Failed to install artifact file", e );
            }
        }
        else
        {
            try
            {
                artifactContext.getArtifactInstaller().installFileWithNoPom( groupId, artifactId, version,
                                                                             artifactFile );
            }
            catch ( org.apache.maven.artifact.installer.ArtifactInstallationException e )
            {
                throw new MojoExecutionException( "NMAVEN-1000-001: Failed to install artifact file", e );
            }
        }
    }
}

@@ -1149,16 +1149,117 @@
 ception;
+%0Aimport org.apache.maven.artifact.Artifact;%0Aimport org.apache.maven.artifact.factory.ArtifactFactory;
 %0A%0A/**%0A *
@@ -2610,24 +2610,188 @@
 nRegistry;%0A%0A
+    /**%0A     * The artifact factory component, which is used for creating artifacts.%0A     *%0A     * @component%0A     */%0A    private ArtifactFactory artifactFactory;%0A%0A
     public v
@@ -3193,17 +3193,16 @@
 tePom &&
- 
  pomFile
@@ -3210,17 +3210,16 @@
 == null 
- 
 )%0A      
@@ -3252,16 +3252,107 @@
       %7B%0A
+                this.getLog().info( %22NMAVEN-xxx-000: Installing file with generated pom%22 );
 %0A       
@@ -3833,17 +3833,19 @@
  else if
-(
+ ( 
 pomFile 
@@ -3851,16 +3851,17 @@
  != null
+ 
 )%0A      
@@ -3856,32 +3856,312 @@
 ull )%0A        %7B%0A
+            Artifact sourceArtifact =%0A                artifactFactory.createArtifact( groupId, artifactId, version, %22compile%22, packaging );%0A            sourceArtifact.setFile( artifactFile );%0A            this.getLog().info( %22NMAVEN-xxx-000: Installing file with specified pom%22 );%0A
             try%0A
@@ -4250,27 +4250,22 @@
 ct( 
-project.get
+source
 Artifact
 (), 
@@ -4260,18 +4260,16 @@
 Artifact
-()
 , pomFil
@@ -4269,16 +4269,17 @@
  pomFile
+ 
 );%0A     
@@ -4347,32 +4347,33 @@
 )%0A            %7B%0A
+ 
                t
@@ -4531,32 +4531,117 @@
 y%0A            %7B%0A
+                this.getLog().info( %22NMAVEN-xxx-000: Installing file with no pom%22 );%0A
                 

Fix for NMAVEN-81