Coverage Report - com.jcabi.mysql.maven.plugin.ClassifyMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassifyMojo
70%
14/20
16%
2/12
2.333
 
 1  
 /**
 2  
  * Copyright (c) 2012-2014, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.mysql.maven.plugin;
 31  
 
 32  
 import com.jcabi.log.Logger;
 33  
 import java.util.Locale;
 34  
 import lombok.EqualsAndHashCode;
 35  
 import lombok.ToString;
 36  
 import org.apache.maven.plugin.AbstractMojo;
 37  
 import org.apache.maven.plugin.MojoFailureException;
 38  
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 39  
 import org.apache.maven.plugins.annotations.Mojo;
 40  
 import org.apache.maven.plugins.annotations.Parameter;
 41  
 import org.apache.maven.project.MavenProject;
 42  
 
 43  
 /**
 44  
  * Classify current platform.
 45  
  *
 46  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 47  
  * @version $Id$
 48  
  * @since 0.1
 49  
  */
 50  0
 @ToString
 51  0
 @EqualsAndHashCode(callSuper = false)
 52  
 @Mojo(
 53  
     threadSafe = true, name = "classify",
 54  
     defaultPhase = LifecyclePhase.INITIALIZE
 55  
 )
 56  1
 public final class ClassifyMojo extends AbstractMojo {
 57  
 
 58  
     /**
 59  
      * Maven project.
 60  
      */
 61  
     @Parameter(
 62  
         defaultValue = "${project}",
 63  
         required = true,
 64  
         readonly = true
 65  
     )
 66  
     private transient MavenProject project;
 67  
 
 68  
     /**
 69  
      * Classifier to set.
 70  
      */
 71  
     @Parameter(
 72  
         defaultValue = "mysql.classifier",
 73  
         required = true,
 74  
         readonly = false
 75  
     )
 76  
     private transient String classifier;
 77  
 
 78  
     @Override
 79  
     public void execute() throws MojoFailureException {
 80  1
         final String[] words = System.getProperty("os.name").split(" ");
 81  1
         String arch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
 82  1
         if ("i386".equals(arch)) {
 83  0
             arch = "x86";
 84  
         }
 85  1
         final String value = String.format(
 86  
             "%s-%s", words[0].toLowerCase(Locale.ENGLISH), arch
 87  
         );
 88  1
         final String existing = this.project.getProperties()
 89  
             .getProperty(this.classifier);
 90  1
         if (existing == null) {
 91  1
             this.project.getProperties().setProperty(this.classifier, value);
 92  1
             Logger.info(this, "${%s} set to \"%s\"", this.classifier, value);
 93  0
         } else if (existing.equals(value)) {
 94  0
             Logger.info(
 95  
                 this, "${%s} already set to \"%s\"",
 96  
                 this.classifier, value
 97  
             );
 98  
         } else {
 99  0
             throw new MojoFailureException(
 100  
                 String.format(
 101  
                     // @checkstyle LineLength (1 line)
 102  
                     "Maven property ${%s} already set to \"%s\", can't change to \"%s\"",
 103  
                     this.classifier, existing, value
 104  
                 )
 105  
             );
 106  
         }
 107  1
     }
 108  
 
 109  
     /**
 110  
      * Set project.
 111  
      * @param prj Project to set
 112  
      */
 113  
     public void setProject(final MavenProject prj) {
 114  1
         this.project = prj;
 115  1
     }
 116  
 
 117  
     /**
 118  
      * Set classifier.
 119  
      * @param name Name of property
 120  
      */
 121  
     public void setClassifier(final String name) {
 122  1
         this.classifier = name;
 123  1
     }
 124  
 
 125  
 }