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 */ 016package org.vafer.jdeb.ant; 017 018import java.io.File; 019import java.io.FileInputStream; 020import java.io.IOException; 021 022import org.vafer.jdeb.mapping.LsMapper; 023import org.vafer.jdeb.mapping.PermMapper; 024 025/** 026 * Ant "mapper" element acting as factory for the entry mapper. 027 * Supported types: ls, perm 028 */ 029public final class Mapper { 030 031 private String mapperType = "perm"; 032 private File src; 033 034 private String prefix; 035 private int strip; 036 private int uid = -1; 037 private int gid = -1; 038 private String user; 039 private String group; 040 private String fileMode; 041 private String dirMode; 042 043 public void setType( final String pType ) { 044 mapperType = pType; 045 } 046 047 public void setSrc( final File pSrc ) { 048 src = pSrc; 049 } 050 051 052 public void setPrefix( final String pPrefix ) { 053 prefix = pPrefix; 054 } 055 056 public void setStrip( final int pStrip ) { 057 strip = pStrip; 058 } 059 060 061 public void setUid( final int pUid ) { 062 uid = pUid; 063 } 064 065 public void setGid( final int pGid ) { 066 gid = pGid; 067 } 068 069 public void setUser( final String pUser ) { 070 user = pUser; 071 } 072 073 public void setGroup( final String pGroup ) { 074 group = pGroup; 075 } 076 077 public void setFileMode( final String pFileMode ) { 078 fileMode = pFileMode; 079 } 080 081 public void setDirMode( final String pDirMode ) { 082 dirMode = pDirMode; 083 } 084 085 public org.vafer.jdeb.mapping.Mapper createMapper() throws IOException { 086 087 if ("perm".equalsIgnoreCase(mapperType)) { 088 return new PermMapper(uid, gid, user, group, fileMode, dirMode, strip, prefix); 089 } 090 091 if ("ls".equalsIgnoreCase(mapperType)) { 092 try { 093 return new LsMapper(new FileInputStream(src)); 094 } catch (Exception e) { 095 e.printStackTrace(); 096 } 097 } 098 099 throw new IOException("Unknown mapper type '" + mapperType + "'"); 100 } 101 102}