View Javadoc

1   /*
2    * ----------------------------------------------------------------------
3    * Copyright (C) 2009 Enrique Lara (k957@68k.org)
4    *
5    * TinLizard is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public License
7    * as published by the Free Software Foundation; either version 3.0
8    * of the License, or (at your option) any later version.
9    *
10   * TinLizard is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with TinLizard. If not, see http://www.gnu.org/licenses/.
17   * ----------------------------------------------------------------------
18   */
19  package tinlizard.web;
20  
21  import tinlizard.model.Dependency;
22  
23  import tinlizard.util.Messages;
24  
25  import org.codehaus.plexus.util.StringUtils;
26  
27  import org.kohsuke.stapler.StaplerRequest;
28  import org.kohsuke.stapler.StaplerResponse;
29  
30  /***
31   * Decorate Artifact for Stapler.
32   */
33  public final class ArtifactWeb extends DependencyWeb {
34      public ArtifactWeb(final Dependency c) {
35          super(c);
36  
37          if (StringUtils.isBlank(c.getGroupId())) {
38              throw new IllegalStateException(Messages.error_1020());
39          }
40  
41          if (StringUtils.isBlank(c.getArtifactId())) {
42              throw new IllegalStateException(Messages.error_1021());
43          }
44      }
45  
46      public String getName() {
47          return getArtifactId();
48      }
49  
50      public String getVersion() {
51          return null;
52      }
53  
54      public Object getDynamic(final String token, final StaplerRequest req, final StaplerResponse rsp) {
55          if (StringUtils.isNotBlank(token)) {
56              Dependency dependency = new Dependency();
57              dependency.setGroupId(subject.getGroupId());
58              dependency.setArtifactId(subject.getArtifactId());
59              dependency.setVersion(token);
60  
61              return new DependencyWeb(dependency);
62          }
63  
64          return null;
65      }
66  }