001    /*
002     * ----------------------------------------------------------------------
003     * Copyright (C) 2009 Enrique Lara (k957@68k.org)
004     *
005     * TinLizard is free software; you can redistribute it and/or
006     * modify it under the terms of the GNU Lesser General Public License
007     * as published by the Free Software Foundation; either version 3.0
008     * of the License, or (at your option) any later version.
009     *
010     * TinLizard is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013     * GNU Lesser General Public License for more details.
014     *
015     * You should have received a copy of the GNU Lesser General Public License
016     * along with TinLizard. If not, see http://www.gnu.org/licenses/.
017     * ----------------------------------------------------------------------
018     */
019    package tinlizard.web;
020    
021    import tinlizard.model.Dependency;
022    
023    import tinlizard.util.Messages;
024    
025    import org.codehaus.plexus.util.StringUtils;
026    
027    import org.kohsuke.stapler.StaplerRequest;
028    import org.kohsuke.stapler.StaplerResponse;
029    
030    /**
031     * Decorate Artifact for Stapler.
032     */
033    public final class ArtifactWeb extends DependencyWeb {
034        public ArtifactWeb(final Dependency c) {
035            super(c);
036    
037            if (StringUtils.isBlank(c.getGroupId())) {
038                throw new IllegalStateException(Messages.error_1020());
039            }
040    
041            if (StringUtils.isBlank(c.getArtifactId())) {
042                throw new IllegalStateException(Messages.error_1021());
043            }
044        }
045    
046        public String getName() {
047            return getArtifactId();
048        }
049    
050        public String getVersion() {
051            return null;
052        }
053    
054        public Object getDynamic(final String token, final StaplerRequest req, final StaplerResponse rsp) {
055            if (StringUtils.isNotBlank(token)) {
056                Dependency dependency = new Dependency();
057                dependency.setGroupId(subject.getGroupId());
058                dependency.setArtifactId(subject.getArtifactId());
059                dependency.setVersion(token);
060    
061                return new DependencyWeb(dependency);
062            }
063    
064            return null;
065        }
066    }