View Javadoc
1   
2   package com.simpligility.maven.plugins.android.configuration;
3   
4   import org.codehaus.plexus.util.SelectorUtils;
5   
6   import java.util.ArrayList;
7   import java.util.Arrays;
8   import java.util.List;
9   
10  /**
11   * POJO to specify META-INF include and exclude patterns.
12   * 
13   * @author Pappy STÄ‚NESCU - pappy.stanescu@gmail.com
14   */
15  public class MetaInf
16  {
17  
18      private List<String> includes;
19  
20      private List<String> excludes;
21  
22      @Override
23      public boolean equals( Object obj )
24      {
25          if ( this == obj )
26          {
27              return true;
28          }
29          if ( obj == null )
30          {
31              return false;
32          }
33          if ( getClass() != obj.getClass() )
34          {
35              return false;
36          }
37  
38          final MetaInf that = (MetaInf) obj;
39  
40          if ( this.includes == null )
41          {
42              if ( that.includes != null )
43              {
44                  return false;
45              }
46          }
47          else if ( !this.includes.equals( that.includes ) )
48          {
49              return false;
50          }
51  
52          if ( this.excludes == null )
53          {
54              if ( that.excludes != null )
55              {
56                  return false;
57              }
58          }
59          else if ( !this.excludes.equals( that.excludes ) )
60          {
61              return false;
62          }
63  
64          return true;
65      }
66  
67      public MetaInf exclude( String... excludes )
68      {
69          getExcludes().addAll( Arrays.asList( excludes ) );
70  
71          return this;
72      }
73  
74      public List<String> getExcludes()
75      {
76          if ( this.excludes == null )
77          {
78              this.excludes = new ArrayList<String>();
79          }
80  
81          return this.excludes;
82      }
83  
84      public List<String> getIncludes()
85      {
86          if ( this.includes == null )
87          {
88              this.includes = new ArrayList<String>();
89          }
90  
91          return this.includes;
92      }
93  
94      @Override
95      public int hashCode()
96      {
97          final int prime = 31;
98          int result = 1;
99          result = ( prime * result ) + ( ( this.excludes == null ) ? 0 : this.excludes.hashCode() );
100         result = ( prime * result ) + ( ( this.includes == null ) ? 0 : this.includes.hashCode() );
101         return result;
102     }
103 
104     public MetaInf include( String... includes )
105     {
106         getIncludes().addAll( Arrays.asList( includes ) );
107 
108         return this;
109     }
110 
111     public boolean isIncluded( String name )
112     {
113         boolean included = this.includes == null;
114 
115         if ( this.includes != null )
116         {
117             for ( final String x : this.includes )
118             {
119                 if ( SelectorUtils.matchPath( "META-INF/" + x, name ) )
120                 {
121                     included = true;
122 
123                     break;
124                 }
125             }
126         }
127 
128         if ( included && ( this.excludes != null ) )
129         {
130             for ( final String x : this.excludes )
131             {
132                 if ( SelectorUtils.matchPath( "META-INF/" + x, name ) )
133                 {
134                     included = false;
135 
136                     break;
137                 }
138             }
139         }
140 
141         return included;
142     }
143 }