View Javadoc
1   /*
2    * (C) Copyright 2006-2015 Nuxeo SA (http://nuxeo.com/) and contributors.
3    *
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the GNU Lesser General Public License
6    * (LGPL) version 2.1 which accompanies this distribution, and is available at
7    * http://www.gnu.org/licenses/lgpl-2.1.html
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * Contributors:
15   *     bstefanescu, jcarsique
16   */
17  package org.nuxeo.build.ant.artifact;
18  
19  import org.apache.tools.ant.types.DataType;
20  import org.eclipse.aether.util.artifact.JavaScopes;
21  
22  import org.nuxeo.build.maven.filter.AncestorFilter;
23  import org.nuxeo.build.maven.filter.AndFilter;
24  import org.nuxeo.build.maven.filter.ArtifactIdFilter;
25  import org.nuxeo.build.maven.filter.ClassifierFilter;
26  import org.nuxeo.build.maven.filter.GroupIdFilter;
27  import org.nuxeo.build.maven.filter.IsOptionalFilter;
28  import org.nuxeo.build.maven.filter.ManifestBundleCategoryFilter;
29  import org.nuxeo.build.maven.filter.NotFilter;
30  import org.nuxeo.build.maven.filter.ScopeFilter;
31  import org.nuxeo.build.maven.filter.TypeFilter;
32  import org.nuxeo.build.maven.filter.VersionFilter;
33  
34  /**
35   * TODO NXBT-258
36   */
37  @SuppressWarnings("deprecation")
38  public class ArtifactPattern extends DataType {
39  
40      private AndFilter filter = new AndFilter();
41  
42      protected String category = null;
43  
44      protected String groupId = null;
45  
46      protected String artifactId = null;
47  
48      protected String version = null;
49  
50      protected String classifier = null;
51  
52      protected String type = null;
53  
54      protected String scope = "!test";
55  
56      protected boolean isOptional = false;
57  
58      protected String pattern = null;
59  
60      protected String ancestor = null;
61  
62      protected boolean isDependsOnCategory = true;
63  
64      @Deprecated
65      private ManifestBundleCategoryFilter categoryFilter = null;
66  
67      private boolean scopeTest = false;
68  
69      private boolean scopeProvided = false;
70  
71      public AndFilter getFilter() {
72          if (!scopeTest) {
73              filter.addFilter(new NotFilter(new ScopeFilter(JavaScopes.TEST)));
74              scopeTest = true; // to avoid loop
75          }
76          if (!scopeProvided) {
77              filter.addFilter(new NotFilter(new ScopeFilter(JavaScopes.PROVIDED)));
78              scopeProvided = true; // to avoid loop
79          }
80          return filter;
81      }
82  
83      public void setGroupId(String groupId) {
84          this.groupId = groupId;
85          filter.addFilter(GroupIdFilter.class, groupId);
86      }
87  
88      public void setArtifactId(String artifactId) {
89          this.artifactId = artifactId;
90          filter.addFilter(ArtifactIdFilter.class, artifactId);
91      }
92  
93      public void setVersion(String version) {
94          this.version = version;
95          filter.addFilter(VersionFilter.class, version);
96      }
97  
98      public void setClassifier(String classifier) {
99          this.classifier = classifier;
100         filter.addFilter(ClassifierFilter.class, classifier);
101     }
102 
103     public void setType(String type) {
104         this.type = type;
105         filter.addFilter(TypeFilter.class, type);
106     }
107 
108     public void setScope(String scope) {
109         this.scope = scope;
110         // Exclude test and provided scopes by default
111         scopeTest = JavaScopes.TEST.equals(scope) || "*".equals(scope);
112         scopeProvided = JavaScopes.PROVIDED.equals(scope) || "*".equals(scope);
113         filter.addFilter(ScopeFilter.class, scope);
114     }
115 
116     public void setOptional(boolean isOptional) {
117         this.isOptional = isOptional;
118         if (isOptional) {
119             filter.addFilter(new IsOptionalFilter(isOptional));
120         }
121     }
122 
123     public void setPattern(String pattern) {
124         this.pattern = pattern;
125         filter.addFiltersFromPattern(pattern);
126     }
127 
128     public void setAncestor(String ancestor) {
129         this.ancestor = ancestor;
130         filter.addFilter(AncestorFilter.class, ancestor);
131     }
132 
133     /**
134      * @deprecated since 2.0
135      */
136     @Deprecated
137     public void setCategory(String category) {
138         this.category = category;
139         categoryFilter = new ManifestBundleCategoryFilter(category, isDependsOnCategory);
140         filter.addFilter(categoryFilter);
141     }
142 
143     /**
144      * @deprecated since 2.0
145      */
146     @Deprecated
147     public void setDependsOnCategory(boolean isDependsOnCategory) {
148         this.isDependsOnCategory = isDependsOnCategory;
149         // in case category has been set before isDependsOnCategory and
150         // isDependsOnCategory==false
151         if (categoryFilter != null && !isDependsOnCategory) {
152             categoryFilter.setDependsOnCategory(false);
153         }
154     }
155 
156 }