Coverage Report - com.btmatthews.maven.plugins.ldap.mojos.AbstractLDAPMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractLDAPMojo
67%
8/12
N/A
2.5
 
 1  
 /*
 2  
  * Copyright 2008 Brian Thomas Matthews
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package com.btmatthews.maven.plugins.ldap.mojos;
 18  
 
 19  
 import org.apache.maven.plugin.AbstractMojo;
 20  
 import org.apache.maven.plugin.MojoExecutionException;
 21  
 
 22  
 import netscape.ldap.LDAPConnection;
 23  
 import netscape.ldap.LDAPException;
 24  
 
 25  
 /**
 26  
  * This is the abstract base class for all Mojos in this the ldap-maven-plugin
 27  
  * plugin. It defines the properties for the LDAP directory server connection
 28  
  * and provides a method to connect to the LDAP directory server.
 29  
  * 
 30  
  * @author <a href="mailto:brian@btmatthews.com">Brian Matthews</a>
 31  
  * @version 1.0
 32  
  */
 33  
 public abstract class AbstractLDAPMojo
 34  
     extends AbstractMojo
 35  
 {
 36  
     /**
 37  
      * The default LDAP protocol version.
 38  
      */
 39  
     private static final int DEFAULT_VERSION = 3;
 40  
 
 41  
     /**
 42  
      * The default host name.
 43  
      */
 44  
     private static final String DEFAULT_HOST = "localhost";
 45  
 
 46  
     /**
 47  
      * The default port number for LDAP servers.
 48  
      */
 49  
     private static final int DEFAULT_PORT = 389;
 50  
 
 51  
     /**
 52  
      * The LDAP protocol version. Defaults to 3.
 53  
      * 
 54  
      * @parameter default-value="3"
 55  
      */
 56  6
     private int version = AbstractLDAPMojo.DEFAULT_VERSION;
 57  
 
 58  
     /**
 59  
      * The host name of the LDAP server. Defaults to localhost.
 60  
      * 
 61  
      * @parameter default-value="localhost"
 62  
      */
 63  6
     private String host = AbstractLDAPMojo.DEFAULT_HOST;
 64  
 
 65  
     /**
 66  
      * The port number of the LDAP server. Defaults to 389.
 67  
      * 
 68  
      * @parameter default-value="389"
 69  
      */
 70  6
     private int port = AbstractLDAPMojo.DEFAULT_PORT;
 71  
 
 72  
     /**
 73  
      * The distinguished name used if authentication is required.
 74  
      * 
 75  
      * @parameter
 76  
      */
 77  
     private String authDn;
 78  
 
 79  
     /**
 80  
      * The password used if authentication is required.
 81  
      * 
 82  
      * @parameter
 83  
      */
 84  
     private String passwd;
 85  
 
 86  
     /**
 87  
      * The default constructor.
 88  
      */
 89  
     public AbstractLDAPMojo()
 90  6
     {
 91  6
     }
 92  
 
 93  
     /**
 94  
      * Connect to the LDAP directory server.
 95  
      * 
 96  
      * @return The connection object.
 97  
      * @throws MojoExecutionException
 98  
      *             If the connection to the LDAP directory server failed.
 99  
      */
 100  
     protected final LDAPConnection connect()
 101  
         throws MojoExecutionException
 102  
     {
 103  
         try
 104  
         {
 105  6
             final LDAPConnection connection = new LDAPConnection();
 106  6
             connection.connect(this.version, this.host, this.port, this.authDn,
 107  
                 this.passwd);
 108  6
             return connection;
 109  
         }
 110  0
         catch (LDAPException e)
 111  
         {
 112  0
             final String message = "Could not connect to LDAP Server ("
 113  
                 + this.host + ":" + this.port + ")";
 114  0
             this.getLog().error(message, e);
 115  0
             throw new MojoExecutionException(message, e);
 116  
         }
 117  
     }
 118  
 }