import org.sonar.api.measures.FileLinesContext;
import org.sonar.api.measures.FileLinesContextFactory;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Resource;
import org.sonar.api.scan.filesystem.InputFile;
-import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
public class DefaultFileLinesContextFactory implements FileLinesContextFactory {
@Override
public FileLinesContext createFor(InputFile inputFile) {
- // FIXME remove that once DefaultFileLinesContext accept an InputFile
- String languageKey = inputFile.attribute(InputFile.ATTRIBUTE_LANGUAGE);
- boolean unitTest = InputFile.TYPE_TEST.equals(inputFile.attribute(InputFile.ATTRIBUTE_TYPE));
- Resource sonarFile;
- if (Java.KEY.equals(languageKey)) {
- sonarFile = JavaFile.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), unitTest);
- } else {
- sonarFile = File.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), null, unitTest);
- }
+ File sonarFile = File.create(inputFile.path());
// Reload resource from index
sonarFile = index.getResource(sonarFile);
return new DefaultFileLinesContext(index, sonarFile);
*/
package org.sonar.batch;
-import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
-
-import org.sonar.api.scan.filesystem.InputFile;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.ProjectLink;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
import org.sonar.api.rules.Violation;
+import org.sonar.api.scan.filesystem.InputFile;
import org.sonar.api.utils.SonarException;
import org.sonar.core.measure.MeasurementFilters;
}
private Resource fromInputFile(InputFile inputFile) {
- String languageKey = inputFile.attribute(InputFile.ATTRIBUTE_LANGUAGE);
- boolean unitTest = InputFile.TYPE_TEST.equals(inputFile.attribute(InputFile.ATTRIBUTE_TYPE));
- if (Java.KEY.equals(languageKey)) {
- return JavaFile.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), unitTest);
- } else {
- return File.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), languages.get(languageKey), unitTest);
- }
+ return File.create(inputFile.path());
}
}
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Library;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.ResourceUtils;
+import org.sonar.api.resources.Scopes;
import org.sonar.api.scan.filesystem.InputFile;
-import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
import org.sonar.api.security.ResourcePermissions;
import org.sonar.api.utils.SonarException;
}
private Resource fromInputFile(InputFile inputFile) {
- String languageKey = inputFile.attribute(InputFile.ATTRIBUTE_LANGUAGE);
- boolean unitTest = InputFile.TYPE_TEST.equals(inputFile.attribute(InputFile.ATTRIBUTE_TYPE));
- if (Java.KEY.equals(languageKey)) {
- return JavaFile.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), unitTest);
- } else {
- return File.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), null, unitTest);
- }
+ return File.create(inputFile.path());
}
/**
throw new SonarException("Language with key '" + languageKey + "' not found");
}
project.setLanguage(language);
+ } else {
+ project.setLanguage(Project.NONE_LANGUAGE);
}
}
}
*/
package org.sonar.batch.scan.filesystem;
-import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
+import org.sonar.api.scan.filesystem.InputFile;
import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
import java.util.Collection;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.SonarIndex;
import org.sonar.api.config.Settings;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.Languages;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Resource;
import org.sonar.api.scan.filesystem.FileQuery;
import org.sonar.api.scan.filesystem.InputFile;
import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
} else if (moduleLanguages.keys().size() > 1) {
dto.setLanguage(StringUtils.join(moduleLanguages.keys(), ","));
} else {
- dto.setLanguage("none");
+ dto.setLanguage(Project.NONE_LANGUAGE.getKey());
}
resourceDao.insertOrUpdate(dto);
}
*/
package org.sonar.batch.scan.filesystem;
-import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
+import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
import org.sonar.api.scan.filesystem.*;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
import java.io.File;
*/
package org.sonar.batch.scan.filesystem;
-import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
+import org.sonar.api.scan.filesystem.InputFile;
class ExclusionFilter implements InputFileFilter {
private final PathPattern pattern;
import org.sonar.api.resources.Project;
import org.sonar.api.scan.filesystem.InputDir;
import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.scan.filesystem.internal.DefaultInputDir;
import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
import org.sonar.api.utils.PathUtils;
import org.sonar.api.utils.SonarException;
*/
package org.sonar.batch.scan.filesystem;
-import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
+import org.sonar.api.scan.filesystem.InputFile;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import org.sonar.api.scan.filesystem.FileQuery;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
import org.sonar.batch.bootstrap.AnalysisMode;
import java.util.Collection;
*/
package org.sonar.batch.scan.filesystem;
-import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
+import org.sonar.api.scan.filesystem.InputFile;
class InclusionFilter implements InputFileFilter {
private final PathPattern pattern;
*/
package org.sonar.batch.scan.filesystem;
-import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.InputFileFilter;
+import org.sonar.api.scan.filesystem.InputFile;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.scan.filesystem.FileQuery;
-import org.sonar.api.scan.filesystem.internal.InputFileFilter;
import org.sonar.batch.bootstrap.AnalysisMode;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
* Create a File that is partially initialized. But that's enough to call for example
* {@link SensorContext#saveMeasure(Resource, org.sonar.api.measures.Measure)} when resources are already indexed.
* Internal use only.
+ * @since 4.2
*/
- private static File create(String relativePathFromBasedir) {
+ public static File create(String relativePathFromBasedir) {
File file = new File();
String normalizedPath = normalize(relativePathFromBasedir);
file.setKey(normalizedPath);
*/
public class Project extends Resource implements Component {
+ /**
+ * Internal use
+ */
+ public static final Language NONE_LANGUAGE = new AbstractLanguage("none", "None") {
+ @Override
+ public String[] getFileSuffixes() {
+ return null;
+ }
+ };
+
private static final String MAVEN_KEY_FORMAT = "%s:%s";
private static final String BRANCH_KEY_FORMAT = "%s:%s";
return language;
}
+ /**
+ * Internal use
+ */
public Project setLanguage(Language language) {
this.language = language;
return this;
* </ul>
*
* @since 3.5
+ * @deprecated since 4.2 use {@link InputFileFilter}
*/
+@Deprecated
public interface FileSystemFilter extends BatchExtension {
/**
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.scan.filesystem;
+
+import org.sonar.api.BatchExtension;
+
+/**
+ * Implement this extension to limit the set of files to be analyzed. Global file inclusion/exclusion patterns
+ * are already applied.
+ *
+ * @since 4.2
+ */
+public interface InputFileFilter extends BatchExtension {
+
+ boolean accept(InputFile inputFile);
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.scan.filesystem.internal;
-
-import org.sonar.api.scan.filesystem.InputFile;
-
-import org.sonar.api.BatchExtension;
-
-/**
- * TODO document lifecycle -> executed when initializing project
- *
- * @since 4.0
- */
-public interface InputFileFilter extends BatchExtension {
-
- boolean accept(InputFile inputFile);
-
-}