001    /*
002     * Copyright 2010 The Apache Software Foundation.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.vafer.jdeb.maven;
017    
018    import java.io.File;
019    import java.io.FileInputStream;
020    
021    import org.vafer.jdeb.mapping.LsMapper;
022    import org.vafer.jdeb.mapping.NullMapper;
023    import org.vafer.jdeb.mapping.PermMapper;
024    import org.vafer.jdeb.mapping.PrefixMapper;
025    
026    /**
027     * Maven "mapper" element acting as factory for the entry mapper.
028     * Supported types: ls, prefix, perm
029     * 
030     * @author Bryan Sant <bryan.sant@gmail.com>
031     */
032    public final class Mapper {
033    
034        /**
035         * @parameter
036         * @required
037         */
038        private String type;
039        
040        /**
041         * @parameter
042         */
043        private int uid = -1;
044        
045        /**
046         * @parameter
047         */
048        private int gid = -1;
049    
050        /**
051         * @parameter
052         */
053        private String user;
054    
055        /**
056         * @parameter
057         */
058        private String group;
059    
060        /**
061         * @parameter
062         */
063        private String filemode;
064    
065        /**
066         * @parameter
067         */
068        private String dirmode;
069    
070        /**
071         * @parameter
072         */
073        private String prefix;
074    
075        /**
076         * @parameter
077         */
078        private int strip;
079    
080        /**
081         * @parameter
082         */
083        private File src;
084    
085    
086        public org.vafer.jdeb.mapping.Mapper createMapper() {
087            
088            if ("perm".equalsIgnoreCase(type)) {
089                return new PermMapper(uid, gid, user, group, filemode, dirmode, strip, prefix);
090            }
091    
092            if ("prefix".equalsIgnoreCase(type)) {
093                return new PrefixMapper(strip, prefix);
094            }
095            
096            if ("ls".equalsIgnoreCase(type)) {
097                try {
098                    return new LsMapper(new FileInputStream(src));
099                } catch (Exception e) {
100                    e.printStackTrace();
101                }
102            }
103            
104            return new NullMapper();
105        }
106        
107    }