001/* 002 * Copyright 2007-2018 The jdeb developers. 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 017package org.vafer.jdeb.maven; 018 019import java.io.File; 020import java.io.FileInputStream; 021import java.io.IOException; 022 023import org.apache.maven.plugins.annotations.Parameter; 024import org.vafer.jdeb.mapping.LsMapper; 025import org.vafer.jdeb.mapping.NullMapper; 026import org.vafer.jdeb.mapping.PermMapper; 027 028/** 029 * Maven "mapper" element acting as factory for the entry mapper. 030 * Supported types: ls, perm 031 */ 032public final class Mapper { 033 034 @Parameter(required = true) 035 private String type; 036 037 @Parameter 038 private int uid = -1; 039 040 @Parameter 041 private int gid = -1; 042 043 @Parameter 044 private String user; 045 046 @Parameter 047 private String group; 048 049 @Parameter 050 private String filemode; 051 052 @Parameter 053 private String dirmode; 054 055 @Parameter 056 private String prefix; 057 058 @Parameter 059 private int strip; 060 061 @Parameter 062 private File src; 063 064 065 public org.vafer.jdeb.mapping.Mapper createMapper() throws IOException { 066 067 if ("ls".equalsIgnoreCase(type)) { 068 try { 069 return new LsMapper(new FileInputStream(src)); 070 } catch (Exception e) { 071 e.printStackTrace(); 072 } 073 } 074 075 if ("perm".equalsIgnoreCase(type)) { 076 return new PermMapper(uid, gid, user, group, filemode, dirmode, strip, prefix); 077 } 078 079 /* NullMapper required for DataProducerPathTemplate */ 080 return NullMapper.INSTANCE; 081 } 082 083}