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 java.io.File;
20  
21  import org.apache.tools.ant.types.resources.FileResource;
22  
23  import org.nuxeo.build.maven.AntBuildMojo;
24  import org.nuxeo.build.maven.ArtifactDescriptor;
25  import org.nuxeo.build.maven.graph.Graph;
26  import org.nuxeo.build.maven.graph.Node;
27  
28  /**
29   * TODO NXBT-258
30   */
31  public class ArtifactFile extends FileResource {
32  
33      protected Graph graph = AntBuildMojo.getInstance().getGraph();
34  
35      protected Node node;
36  
37      public String key;
38  
39      public ArtifactDescriptor ad = new ArtifactDescriptor();
40  
41      public void setKey(String key) {
42          this.key = key;
43          ad = ArtifactDescriptor.parseQuietly(key);
44      }
45  
46      public void setArtifactId(String artifactId) {
47          ad.setArtifactId(artifactId);
48      }
49  
50      public void setGroupId(String groupId) {
51          ad.setGroupId(groupId);
52      }
53  
54      public void setType(String type) {
55          ad.setType(type);
56      }
57  
58      public void setVersion(String version) {
59          ad.setVersion(version);
60      }
61  
62      public void setClassifier(String classifier) {
63          ad.setClassifier(classifier);
64      }
65  
66      public Node getNode() {
67          if (node == null) {
68              node = graph.findNode(key, ad);
69          }
70          return node;
71      }
72  
73      @Override
74      public File getFile() {
75          if (isReference()) {
76              return ((FileResource) getCheckedRef()).getFile();
77          }
78          return getNode().getFile();
79      }
80  
81      @Override
82      public File getBaseDir() {
83          return isReference() ? ((FileResource) getCheckedRef()).getBaseDir() : getFile().getParentFile();
84      }
85  
86  }