Coverage Report - org.apache.maven.ant.tasks.AttachArtifactTask
 
Classes in this File Line Coverage Branch Coverage Complexity
AttachArtifactTask
0%
0/30
0%
0/10
2
 
 1  
 package org.apache.maven.ant.tasks;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.File;
 23  
 
 24  
 import org.apache.maven.plugin.antrun.AntRunMojo;
 25  
 import org.apache.maven.project.MavenProject;
 26  
 import org.apache.maven.project.MavenProjectHelper;
 27  
 import org.apache.tools.ant.BuildException;
 28  
 import org.apache.tools.ant.Project;
 29  
 import org.apache.tools.ant.Task;
 30  
 import org.codehaus.plexus.util.FileUtils;
 31  
 
 32  0
 public class AttachArtifactTask
 33  
     extends Task
 34  
 {
 35  
 
 36  
     /**
 37  
      * The refId of the maven project.
 38  
      */
 39  0
     private String mavenProjectRefId = AntRunMojo.DEFAULT_MAVEN_PROJECT_REFID;
 40  
 
 41  
     /**
 42  
      * The refId of the maven project helper component.
 43  
      */
 44  0
     private String mavenProjectHelperRefId = AntRunMojo.DEFAULT_MAVEN_PROJECT_HELPER_REFID;
 45  
 
 46  
     /**
 47  
      * The file to attach.
 48  
      */
 49  
     private File file;
 50  
     
 51  
     /**
 52  
      * The classifier of the artifact to attach
 53  
      */
 54  
     private String classifier;
 55  
     
 56  
     /**
 57  
      * The type of the artifact to attach.  Defaults to file extension.
 58  
      */
 59  
     private String type;
 60  
     
 61  
     public void execute()
 62  
     {
 63  0
         if ( file == null )
 64  
         {
 65  0
             throw new BuildException( "File is a required parameter." );
 66  
         }
 67  
         
 68  0
         if ( !file.exists() )
 69  
         {
 70  0
             throw new BuildException( "File does not exist: " + file );
 71  
         }
 72  
         
 73  0
         if ( this.getProject().getReference( mavenProjectRefId ) == null )
 74  
         {
 75  0
             throw new BuildException( "Maven project reference not found: " + mavenProjectRefId );
 76  
         }
 77  
 
 78  0
         if ( type == null )
 79  
         {
 80  0
             type = FileUtils.getExtension( file.getName() );
 81  
         }
 82  
         
 83  0
         MavenProject mavenProject = (MavenProject) this.getProject().getReference( mavenProjectRefId );
 84  
 
 85  0
         if ( this.getProject().getReference( mavenProjectHelperRefId ) == null )
 86  
         {
 87  0
             throw new BuildException( "Maven project helper reference not found: " + mavenProjectHelperRefId );
 88  
         }
 89  
 
 90  0
         log( "Attaching " + file + " as an attached artifact", Project.MSG_VERBOSE );
 91  0
         MavenProjectHelper projectHelper = (MavenProjectHelper) getProject().getReference( mavenProjectHelperRefId );
 92  0
         projectHelper.attachArtifact( mavenProject, type, classifier, file );
 93  0
     }
 94  
 
 95  
     public File getFile()
 96  
     {
 97  0
         return file;
 98  
     }
 99  
 
 100  
     public void setFile( File file )
 101  
     {
 102  0
         this.file = file;
 103  0
     }
 104  
 
 105  
     public String getMavenProjectRefId()
 106  
     {
 107  0
         return mavenProjectRefId;
 108  
     }
 109  
 
 110  
     public void setMavenProjectRefId( String mavenProjectRefId )
 111  
     {
 112  0
         this.mavenProjectRefId = mavenProjectRefId;
 113  0
     }
 114  
 
 115  
     public String getClassifier()
 116  
     {
 117  0
         return classifier;
 118  
     }
 119  
 
 120  
     public void setClassifier( String classifier )
 121  
     {
 122  0
         this.classifier = classifier;
 123  0
     }
 124  
 
 125  
     public String getType()
 126  
     {
 127  0
         return type;
 128  
     }
 129  
 
 130  
     public void setType( String type )
 131  
     {
 132  0
         this.type = type;
 133  0
     }
 134  
 }