001 /* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2014 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * SonarQube is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020 package org.sonar.api.batch.fs.internal; 021 022 import org.sonar.api.utils.PathUtils; 023 024 import java.io.BufferedInputStream; 025 import java.io.File; 026 import java.io.FileInputStream; 027 import java.io.FileNotFoundException; 028 import java.io.InputStream; 029 030 /** 031 * @since 4.2 032 */ 033 public class DeprecatedDefaultInputFile extends DefaultInputFile implements org.sonar.api.resources.InputFile { 034 035 private String basedir; 036 private String deprecatedKey; 037 private String sourceDirAbsolutePath; 038 private String pathRelativeToSourceDir; 039 040 public DeprecatedDefaultInputFile(String moduleKey, String relativePath) { 041 super(moduleKey, relativePath); 042 } 043 044 /** 045 * @deprecated in 4.2. Replaced by {@link org.sonar.api.batch.fs.FileSystem#baseDir()} 046 */ 047 @Deprecated 048 @Override 049 public File getFileBaseDir() { 050 return new File(basedir); 051 } 052 053 public DeprecatedDefaultInputFile setBasedir(File basedir) { 054 this.basedir = PathUtils.sanitize(basedir.getAbsolutePath()); 055 return this; 056 } 057 058 /** 059 * @deprecated in 4.2. Use {@link #file()} 060 */ 061 @Deprecated 062 @Override 063 public File getFile() { 064 return file(); 065 } 066 067 /** 068 * @deprecated in 4.2. Use {@link #relativePath()} 069 */ 070 @Deprecated 071 @Override 072 public String getRelativePath() { 073 return pathRelativeToSourceDir; 074 } 075 076 /** 077 * Key used before version 4.2. It can be different than {@link #key} on Java files. 078 */ 079 public String deprecatedKey() { 080 return deprecatedKey; 081 } 082 083 public DeprecatedDefaultInputFile setDeprecatedKey(String s) { 084 this.deprecatedKey = s; 085 return this; 086 } 087 088 /** 089 * Used only for backward-compatibility. Meaningless since version 4.2. 090 */ 091 public String sourceDirAbsolutePath() { 092 return sourceDirAbsolutePath; 093 } 094 095 public DeprecatedDefaultInputFile setSourceDirAbsolutePath(String s) { 096 this.sourceDirAbsolutePath = PathUtils.sanitize(s); 097 return this; 098 } 099 100 /** 101 * Used only for backward-compatibility. Meaningless since version 4.2. 102 */ 103 104 public String pathRelativeToSourceDir() { 105 return pathRelativeToSourceDir; 106 } 107 108 public DeprecatedDefaultInputFile setPathRelativeToSourceDir(String s) { 109 this.pathRelativeToSourceDir = PathUtils.sanitize(s); 110 return this; 111 } 112 113 @Override 114 public InputStream getInputStream() throws FileNotFoundException { 115 return new BufferedInputStream(new FileInputStream(file())); 116 } 117 }