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 relativePath) {
041 super(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 void setBasedir(File basedir) {
054 this.basedir = PathUtils.sanitize(basedir.getAbsolutePath());
055 }
056
057 /**
058 * @deprecated in 4.2. Use {@link #file()}
059 */
060 @Deprecated
061 @Override
062 public File getFile() {
063 return file();
064 }
065
066 /**
067 * @deprecated in 4.2. Use {@link #relativePath()}
068 */
069 @Deprecated
070 @Override
071 public String getRelativePath() {
072 return pathRelativeToSourceDir;
073 }
074
075 /**
076 * Key used before version 4.2. It can be different than {@link #key} on Java files.
077 */
078 public String deprecatedKey() {
079 return deprecatedKey;
080 }
081
082 public DeprecatedDefaultInputFile setDeprecatedKey(String s) {
083 this.deprecatedKey = s;
084 return this;
085 }
086
087 /**
088 * Used only for backward-compatibility. Meaningless since version 4.2.
089 */
090 public String sourceDirAbsolutePath() {
091 return sourceDirAbsolutePath;
092 }
093
094 public DeprecatedDefaultInputFile setSourceDirAbsolutePath(String s) {
095 this.sourceDirAbsolutePath = PathUtils.sanitize(s);
096 return this;
097 }
098
099 /**
100 * Used only for backward-compatibility. Meaningless since version 4.2.
101 */
102
103 public String pathRelativeToSourceDir() {
104 return pathRelativeToSourceDir;
105 }
106
107 public DeprecatedDefaultInputFile setPathRelativeToSourceDir(String s) {
108 this.pathRelativeToSourceDir = PathUtils.sanitize(s);
109 return this;
110 }
111
112 @Override
113 public InputStream getInputStream() throws FileNotFoundException {
114 return new BufferedInputStream(new FileInputStream(file()));
115 }
116 }