Coverage Report - org.apache.maven.plugin.doap.options.ASFExtOptionsUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
ASFExtOptionsUtil
0 %
0/64
0 %
0/76
0
 
 1  
 package org.apache.maven.plugin.doap.options;
 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.net.MalformedURLException;
 23  
 import java.net.URL;
 24  
 import java.util.ArrayList;
 25  
 import java.util.List;
 26  
 
 27  
 import org.apache.maven.model.Developer;
 28  
 import org.apache.maven.project.MavenProject;
 29  
 import org.codehaus.plexus.util.StringUtils;
 30  
 
 31  
 /**
 32  
  * Utility class for {@link ASFExtOptions} class.
 33  
  *
 34  
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
 35  
  * @version $Id: org.apache.maven.plugin.doap.options.ASFExtOptionsUtil.html 815337 2012-05-01 21:52:10Z hboutemy $
 36  
  * @since 1.1
 37  
  */
 38  0
 public class ASFExtOptionsUtil
 39  
 {
 40  
     /** Apache domain name, i.e. apache.org */
 41  
     private static final String APACHE_DOMAIN_NAME = "apache.org";
 42  
 
 43  
     /**
 44  
      * The ASF category resource.
 45  
      *
 46  
      * @see <a href="http://projects.apache.org/guidelines.html">http://projects.apache.org/guidelines.html</a>
 47  
      */
 48  
     public static final String CATEGORY_RESOURCE = "http://projects.apache.org/category/";
 49  
 
 50  
     /** Projects related to building/maintaining source code/websites. */
 51  
     public static final String BUILD_MANAGEMENT_CATEGORY = "build-management";
 52  
 
 53  
     /** Projects related to databases. */
 54  
     public static final String DATABASE_CATEGORY = "database";
 55  
 
 56  
     /** Related to the HyperText Transfer Protocol. */
 57  
     public static final String HTTP_CATEGORY = "http";
 58  
 
 59  
     /** Modules designed for use by the Apache HTTP Server. */
 60  
     public static final String HTTP_MODULES_CATEGORY = "httpd-modules";
 61  
 
 62  
     /** A library meant to be used by other applications. */
 63  
     public static final String LIBRARY_CATEGORY = "library";
 64  
 
 65  
     /** Servers or applications related to internet mail protocols. */
 66  
     public static final String MAIL_CATEGORY = "mail";
 67  
 
 68  
     /** Anything that acts as a client across a network. */
 69  
     public static final String NETWORK_CLIENT_CATEGORY = "network-client";
 70  
 
 71  
     /** Anything that acts as a server across a network. */
 72  
     public static final String NETWORK_SERVER_CATEGORY = "network-server";
 73  
 
 74  
     /** Software designed to test or verify other software. */
 75  
     public static final String TESTING_CATEGORY = "testing";
 76  
 
 77  
     /** Unifying frameworks for website development. */
 78  
     public static final String WEB_FRAMEWORK_CATEGORY = "web-framework";
 79  
 
 80  
     /** Software based on XML technologies. */
 81  
     public static final String XML_CATEGORY = "xml";
 82  
 
 83  
     /** All categories supported by ASF */
 84  0
     public static final String[] CATEGORIES = { BUILD_MANAGEMENT_CATEGORY, DATABASE_CATEGORY, HTTP_CATEGORY,
 85  
         HTTP_MODULES_CATEGORY, LIBRARY_CATEGORY, MAIL_CATEGORY, NETWORK_CLIENT_CATEGORY, NETWORK_SERVER_CATEGORY,
 86  
         TESTING_CATEGORY, WEB_FRAMEWORK_CATEGORY, XML_CATEGORY };
 87  
 
 88  
     /** C or C++ Programming Language. */
 89  
     public static final String C_PROGRAMMING_LANGUAGE = "C";
 90  
 
 91  
     /** Java Programming Language and all its components. */
 92  
     public static final String JAVA_PROGRAMMING_LANGUAGE = "Java";
 93  
 
 94  
     /** Perl Programming Language. */
 95  
     public static final String PERL_PROGRAMMING_LANGUAGE = "Perl";
 96  
 
 97  
     /** Python Programming Language. */
 98  
     public static final String PYTHON_PROGRAMMING_LANGUAGE = "Python";
 99  
 
 100  
     /** Scalable Vector Graphic Programming Language. */
 101  
     public static final String SVG_PROGRAMMING_LANGUAGE = "SVG";
 102  
 
 103  
     /** Tcl Programming Language. */
 104  
     public static final String TCL_PROGRAMMING_LANGUAGE = "Tcl";
 105  
 
 106  
     /** All Programming Languages supported by ASF */
 107  0
     public static final String[] PROGRAMMING_LANGUAGES = { C_PROGRAMMING_LANGUAGE, JAVA_PROGRAMMING_LANGUAGE,
 108  
         PERL_PROGRAMMING_LANGUAGE, PYTHON_PROGRAMMING_LANGUAGE, SVG_PROGRAMMING_LANGUAGE, TCL_PROGRAMMING_LANGUAGE };
 109  
 
 110  
     /**
 111  
      * @param category not null
 112  
      * @return if the given category is supported by ASF (correctly formatted) or <code>null</code> if not found.
 113  
      * @see <a href="http://projects.apache.org/categories.html">http://projects.apache.org/categories.html</a>
 114  
      * @see #CATEGORIES
 115  
      */
 116  
     public static String getCategorySupportedByASF( String category )
 117  
     {
 118  0
         for ( String category_ : CATEGORIES )
 119  
         {
 120  0
             if ( category_.equalsIgnoreCase( category ) )
 121  
             {
 122  0
                 return category_;
 123  
             }
 124  
         }
 125  
 
 126  0
         return null;
 127  
     }
 128  
 
 129  
     /**
 130  
      * @param programmingLanguage not null
 131  
      * @return the given programming language supported by ASF (correctly formatted) or <code>null</code> if not found.
 132  
      * @see <a href="http://projects.apache.org/languages.html">http://projects.apache.org/languages.html</a>
 133  
      * @see #PROGRAMMING_LANGUAGES
 134  
      */
 135  
     public static String getProgrammingLanguageSupportedByASF( String programmingLanguage )
 136  
     {
 137  0
         for ( String programmingLanguage_ : PROGRAMMING_LANGUAGES )
 138  
         {
 139  0
             if ( programmingLanguage_.equalsIgnoreCase( programmingLanguage ) )
 140  
             {
 141  0
                 return programmingLanguage_;
 142  
             }
 143  
         }
 144  
 
 145  0
         return null;
 146  
     }
 147  
 
 148  
     /**
 149  
      * Find the chair man of the project. The role of the developer should contain <code>chair</code>.
 150  
      *
 151  
      * @param developers list of <code>{@link Developer}</code>
 152  
      * @return a Developer or null if not found.
 153  
      */
 154  
     public static Developer findChair( List<Developer> developers )
 155  
     {
 156  0
         if ( developers == null || developers.isEmpty() )
 157  
         {
 158  0
             return null;
 159  
         }
 160  
 
 161  0
         for ( Developer developer : developers )
 162  
         {
 163  0
             List<String> roles = developer.getRoles();
 164  
 
 165  0
             for ( String role : roles )
 166  
             {
 167  0
                 if ( role.toLowerCase().contains( "chair" ) )
 168  
                 {
 169  0
                     return developer;
 170  
                 }
 171  
             }
 172  0
         }
 173  
 
 174  0
         return null;
 175  
     }
 176  
 
 177  
     /**
 178  
      * Find the list of PMC members of the project. The role of each developer should contain <code>pmc</code>.
 179  
      *
 180  
      * @param developers list of <code>{@link Developer}</code>
 181  
      * @return a not null list of Developer.
 182  
      */
 183  
     public static List<Developer> findPMCMembers( List<Developer> developers )
 184  
     {
 185  0
         if ( developers == null || developers.isEmpty() )
 186  
         {
 187  0
             return null;
 188  
         }
 189  
 
 190  0
         List<Developer> pmcs = new ArrayList<Developer>();
 191  0
         for ( Developer developer : developers )
 192  
         {
 193  0
             List<String> roles = developer.getRoles();
 194  
 
 195  0
             for ( String role : roles )
 196  
             {
 197  0
                 if ( role.toLowerCase().contains( "pmc" ) )
 198  
                 {
 199  0
                     pmcs.add( developer );
 200  
                 }
 201  
             }
 202  0
         }
 203  
 
 204  0
         return pmcs;
 205  
     }
 206  
 
 207  
     /**
 208  
      * Try to find if the given project is hosted at Apache.
 209  
      *
 210  
      * @param project not null
 211  
      * @return <code>true</code> if the SCM url, distribution management url, project url or organization url is hosted
 212  
      *         in the Apache domain name, <code>false</code> otherwise.
 213  
      * @see #APACHE_DOMAIN_NAME
 214  
      * @since 1.1
 215  
      */
 216  
     public static boolean isASFProject( MavenProject project )
 217  
     {
 218  0
         if ( project == null )
 219  
         {
 220  0
             throw new IllegalArgumentException( "project is required" );
 221  
         }
 222  
 
 223  
         // check organization name
 224  0
         if ( project.getOrganization() != null && StringUtils.isNotEmpty( project.getOrganization().getName() )
 225  
             && project.getOrganization().getName().trim().equals( "The Apache Software Foundation" ) ) // see
 226  
                                                                                                        // org.apache:apache
 227  
                                                                                                        // artifact
 228  
         {
 229  0
             return true;
 230  
         }
 231  
 
 232  
         // check domain name
 233  0
         if ( project.getOrganization() != null && isHostedAtASF( project.getOrganization().getUrl() ) )
 234  
         {
 235  0
             return true;
 236  
         }
 237  
 
 238  0
         if ( isHostedAtASF( project.getUrl() ) )
 239  
         {
 240  0
             return true;
 241  
         }
 242  
 
 243  0
         if ( project.getScm() != null )
 244  
         {
 245  0
             if ( StringUtils.isNotEmpty( project.getScm().getUrl() )
 246  
                 && project.getScm().getUrl().contains( APACHE_DOMAIN_NAME ) )
 247  
             {
 248  0
                 return true;
 249  
             }
 250  
 
 251  0
             if ( StringUtils.isNotEmpty( project.getScm().getConnection() )
 252  
                 && project.getScm().getConnection().contains( APACHE_DOMAIN_NAME ) )
 253  
             {
 254  0
                 return true;
 255  
             }
 256  
 
 257  0
             if ( StringUtils.isNotEmpty( project.getScm().getDeveloperConnection() )
 258  
                 && project.getScm().getDeveloperConnection().contains( APACHE_DOMAIN_NAME ) )
 259  
             {
 260  0
                 return true;
 261  
             }
 262  
         }
 263  
 
 264  0
         if ( project.getDistributionManagement() != null )
 265  
         {
 266  0
             if ( isHostedAtASF( project.getDistributionManagement().getDownloadUrl() ) )
 267  
             {
 268  0
                 return true;
 269  
             }
 270  
 
 271  0
             if ( project.getDistributionManagement().getRepository() != null
 272  
                 && isHostedAtASF( project.getDistributionManagement().getRepository().getUrl() ) )
 273  
             {
 274  0
                 return true;
 275  
             }
 276  
 
 277  0
             if ( project.getDistributionManagement().getSnapshotRepository() != null
 278  
                 && isHostedAtASF( project.getDistributionManagement().getSnapshotRepository().getUrl() ) )
 279  
             {
 280  0
                 return true;
 281  
             }
 282  
 
 283  0
             if ( project.getDistributionManagement().getSite() != null
 284  
                 && isHostedAtASF( project.getDistributionManagement().getSite().getUrl() ) )
 285  
             {
 286  0
                 return true;
 287  
             }
 288  
         }
 289  
 
 290  0
         return false;
 291  
     }
 292  
 
 293  
     /**
 294  
      * @param str an url could be null
 295  
      * @return <code>true</code> if the str is hosted by ASF.
 296  
      * @see #APACHE_DOMAIN_NAME
 297  
      */
 298  
     private static boolean isHostedAtASF( String str )
 299  
     {
 300  0
         if ( StringUtils.isEmpty( str ) )
 301  
         {
 302  0
             return false;
 303  
         }
 304  
 
 305  0
         str = str.trim();
 306  
         try
 307  
         {
 308  0
             URL url = new URL( str );
 309  0
             if ( url.getHost().endsWith( APACHE_DOMAIN_NAME ) )
 310  
             {
 311  0
                 return true;
 312  
             }
 313  
         }
 314  0
         catch ( MalformedURLException e )
 315  
         {
 316  0
         }
 317  
 
 318  0
         return false;
 319  
     }
 320  
 }