@Override
public void analyse(Project module, org.sonar.api.batch.SensorContext context) {
- createIssueOnDir(new Directory(""));
- File src = fileSystem.sourceDirs().get(0);
-
for (File f : fileSystem.files(FileQuery.onMain().onLanguage(Xoo.KEY))) {
- String relativePathFromSourceDir = new PathResolver().relativePath(src, f);
- org.sonar.api.resources.File sonarFile = new org.sonar.api.resources.File(relativePathFromSourceDir);
+ String relativePathFromSourceDir = new PathResolver().relativePath(fileSystem.baseDir(), f);
+ org.sonar.api.resources.File sonarFile = org.sonar.api.resources.File.create(relativePathFromSourceDir);
Issuable issuable = perspectives.as(Issuable.class, sonarFile);
issuable.addIssue(issuable.newIssueBuilder()
.ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY))
import java.io.File;
import java.io.IOException;
-import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
return tempDir;
}
- @Override
- public List<File> getExtensions(String dirName, String... suffixes) {
- throw new UnsupportedOperationException();
- }
}
}
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Qualifiers;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
import java.util.Collections;
import java.util.Date;
import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.sonar.api.measures.Metric;
public class MeasureFilter {
public MeasureFilter setResourceQualifiers(@Nullable List<String> list) {
this.resourceQualifiers = sanitize(list);
- if (resourceQualifiers.contains(Qualifiers.FILE)) {
- resourceQualifiers.add(Qualifiers.CLASS);
- }
- if (resourceQualifiers.contains(Qualifiers.DIRECTORY)) {
- resourceQualifiers.add(Qualifiers.PACKAGE);
- }
return this;
}
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
import javax.annotation.CheckForNull;
import org.apache.commons.io.FileUtils;
import org.picocontainer.Startable;
return new File(getDeployDir(), "plugins/index.txt");
}
- /**
- * @deprecated since 4.1
- */
- @Override
- @Deprecated
- public List<File> getExtensions(String dirName, String... suffixes) {
- File dir = new File(getHomeDir(), "extensions/rules/" + dirName);
- if (dir.exists() && dir.isDirectory()) {
- return getFiles(dir, suffixes);
- }
- return Collections.emptyList();
- }
-
- private List<File> getFiles(File dir, String... fileSuffixes) {
- List<File> files = new ArrayList<>();
- if (dir != null && dir.exists()) {
- if (fileSuffixes != null && fileSuffixes.length > 0) {
- files.addAll(FileUtils.listFiles(dir, fileSuffixes, false));
- } else {
- files.addAll(FileUtils.listFiles(dir, null, false));
- }
- }
- return files;
- }
}
*/
package org.sonar.server.ws;
-import static com.google.common.base.Predicates.not;
-import static com.google.common.collect.FluentIterable.from;
-import static com.google.common.collect.Ordering.natural;
-import static java.lang.String.format;
-import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER;
-
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import java.util.Locale;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.server.ws.WebService;
+import static com.google.common.base.Predicates.not;
+import static com.google.common.collect.FluentIterable.from;
+import static com.google.common.collect.Ordering.natural;
+import static java.lang.String.format;
+import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER;
+
public class WsParameterBuilder {
private static final String PARAM_QUALIFIER = "qualifier";
private static final String PARAM_QUALIFIERS = "qualifiers";
- private static final Set<String> DEPRECATED_QUALIFIERS = ImmutableSet.of(
- Qualifiers.CLASS, Qualifiers.PACKAGE, Qualifiers.FIELD, Qualifiers.LIBRARY, Qualifiers.METHOD, Qualifiers.PARAGRAPH);
+ private static final Set<String> DEPRECATED_QUALIFIERS = ImmutableSet.of(Qualifiers.LIBRARY);
private WsParameterBuilder() {
// static methods only
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.server.platform;
-
-import com.google.common.io.Resources;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.platform.ServerFileSystem;
-
-import java.io.File;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultServerFileSystemTest {
-
- private static final String PATH = "org/sonar/server/platform/DefaultServerFileSystemTest/";
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Test
- public void find_checkstyle_extensions() throws Exception {
- ServerFileSystem fs = new DefaultServerFileSystem(
- new File(Resources.getResource(PATH + "shouldFindCheckstyleExtensions").toURI()), temp.newFolder(), null);
-
- List<File> xmls = fs.getExtensions("checkstyle", "xml");
- assertThat(xmls).hasSize(1);
-
- List<File> all = fs.getExtensions("checkstyle");
- assertThat(all).hasSize(3);
- }
-
- @Test
- public void not_fail_if_no_checkstyle_extensions() throws Exception {
- ServerFileSystem fs = new DefaultServerFileSystem(
- new File(Resources.getResource(PATH + "shouldNotFailIfNoCheckstyleExtensions").toURI()), temp.newFolder(), null);
- List<File> xmls = fs.getExtensions("checkstyle", "xml");
- assertThat(xmls).isEmpty();
-
- List<File> jars = fs.getExtensions("checkstyle");
- assertThat(jars).isEmpty();
- }
-}
+++ /dev/null
-asdad
\ No newline at end of file
package org.sonar.core.component;
import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypeTree;
-import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
@ScannerSide
.addType(ResourceType.builder(Qualifiers.DIRECTORY)
.setProperty(SUPPORTS_MEASURE_FILTERS, true)
.build())
- .addType(ResourceType.builder(Qualifiers.PACKAGE)
- .build())
.addType(ResourceType.builder(Qualifiers.FILE)
.hasSourceCode()
.setProperty(SUPPORTS_MEASURE_FILTERS, true)
.build())
- .addType(ResourceType.builder(Qualifiers.CLASS)
- .hasSourceCode()
- .build())
.addType(ResourceType.builder(Qualifiers.UNIT_TEST_FILE)
.hasSourceCode()
.setProperty(SUPPORTS_MEASURE_FILTERS, true)
.build())
.addRelations(Qualifiers.PROJECT, Qualifiers.MODULE)
- .addRelations(Qualifiers.MODULE, Qualifiers.DIRECTORY, Qualifiers.PACKAGE)
+ .addRelations(Qualifiers.MODULE, Qualifiers.DIRECTORY)
.addRelations(Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE)
- .addRelations(Qualifiers.PACKAGE, Qualifiers.CLASS, Qualifiers.UNIT_TEST_FILE)
.build();
}
public void provide_types() {
ResourceTypeTree tree = DefaultResourceTypes.get();
- assertThat(tree.getTypes()).hasSize(7);
+ assertThat(tree.getTypes()).hasSize(5);
assertThat(tree.getChildren(Qualifiers.PROJECT)).containsExactly(Qualifiers.MODULE);
}
// Directories and packages are explicitly excluded.
private static final String[] RENAMABLE_QUALIFIERS = {Qualifiers.PROJECT, Qualifiers.MODULE, Qualifiers.VIEW, Qualifiers.SUBVIEW};
private static final String[] RENAMABLE_SCOPES = {Scopes.PROJECT};
- private static final String[] NOT_RENAMABLE_QUALIFIERS = {Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE, Qualifiers.CLASS};
+ private static final String[] NOT_RENAMABLE_QUALIFIERS = {Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE};
private static final String[] NOT_RENAMABLE_SCOPES = {Scopes.FILE};
public ResourceIndexDao(MyBatis myBatis, System2 system2) {
}
@Test
- public void shouldNotIndexPackages() {
+ public void shouldNotIndexDirectories() {
dbTester.prepareDbUnit(getClass(), "shouldNotIndexPackages.xml");
underTest.indexProject("ABCD");
assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, ASC)).get(0).getId()).isEqualTo(1L);
assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, DESC)).get(0).getId()).isEqualTo(3L);
- assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setScope(Scopes.PROJECT).setQualifier(Qualifiers.PACKAGE))).extracting("id").containsOnly(1L);
- assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setScope(Scopes.DIRECTORY).setQualifier(Qualifiers.PACKAGE))).extracting("id").containsOnly(
+ assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setScope(Scopes.PROJECT).setQualifier(Qualifiers.DIRECTORY))).extracting("id")
+ .containsOnly(1L);
+ assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setScope(Scopes.DIRECTORY).setQualifier(Qualifiers.DIRECTORY))).extracting("id").containsOnly(
2L, 3L, 4L, 5L, 6L);
assertThat(underTest.selectSnapshotsByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD"))).hasSize(3);
<projects long_name="org.struts"
id="3"
scope="DIR"
- qualifier="PAC"
+ qualifier="DIR"
kee="org.struts:struts-core:org.struts"
uuid="CDEF"
uuid_path="NOT_USED"
<projects long_name="org.struts.RequestContext"
id="4"
- scope="CLA"
- qualifier="CLA"
+ scope="FIL"
+ qualifier="FIL"
uuid="DEFG"
uuid_path="NOT_USED"
project_uuid="ABCD"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="equestcontext"
position="1"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="questcontext"
position="2"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="uestcontext"
position="3"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="estcontext"
position="4"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="stcontext"
position="5"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="tcontext"
position="6"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="context"
position="7"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="ontext"
position="8"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="ntext"
position="9"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="text"
position="10"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<resource_index kee="ext"
position="11"
name_size="14"
component_uuid="DEFG"
root_component_uuid="ABCD"
- qualifier="CLA"/>
+ qualifier="FIL"/>
<!-- Struts -->
<resource_index kee="struts"
<projects long_name="org.struts"
id="3"
scope="DIR"
- qualifier="PAC"
+ qualifier="DIR"
kee="org.struts:struts-core:org.struts"
uuid="CDEF"
uuid_path="NOT_USED"
<projects long_name="org.struts.RequestContext"
id="4"
scope="FIL"
- qualifier="CLA"
+ qualifier="FIL"
uuid="DEFG"
uuid_path="NOT_USED"
project_uuid="ABCD"
<projects long_name="org.struts"
id="2"
scope="DIR"
- qualifier="PAC"
+ qualifier="DIR"
kee="org.struts:struts:org.struts"
uuid="BCDE"
uuid_path="NOT_USED"
<projects long_name="org.struts.RequestContext"
id="3"
scope="FIL"
- qualifier="CLA"
+ qualifier="FIL"
kee="org.struts:struts:org.struts.RequestContext"
uuid="CDEF"
uuid_path="NOT_USED"
root_component_uuid="ABCD"
component_uuid="BCDE"
scope="DIR"
- qualifier="PAC"/>
+ qualifier="DIR"/>
<snapshots purge_status="[null]"
id="3"
islast="[true]"
root_component_uuid="ABCD"
component_uuid="CDEF"
scope="FIL"
- qualifier="CLA"/>
+ qualifier="FIL"/>
</dataset>
period5_date="1317160800000"
depth="1"
scope="PRJ"
- qualifier="PAC"
+ qualifier="DIR"
created_at="1228172400001"
build_date="1317247200000"
version="2.0-SNAPSHOT"
period5_date="1317160800000"
depth="1"
scope="DIR"
- qualifier="PAC"
+ qualifier="DIR"
created_at="1228172400002"
build_date="1317247200000"
version="2.1-SNAPSHOT"
period5_date="1317160800000"
depth="1"
scope="DIR"
- qualifier="PAC"
+ qualifier="DIR"
created_at="1228172400003"
build_date="1317247200000"
version="2.2-SNAPSHOT"
period5_date="1317160800000"
depth="1"
scope="DIR"
- qualifier="PAC"
+ qualifier="DIR"
created_at="1228172400000"
build_date="1317247200000"
version="2.1-SNAPSHOT"
period5_date="1317160800000"
depth="1"
scope="DIR"
- qualifier="PAC"
+ qualifier="DIR"
created_at="1228172400000"
build_date="1317247200000"
version="2.1-SNAPSHOT"
period5_date="1317160800000"
depth="1"
scope="DIR"
- qualifier="PAC"
+ qualifier="DIR"
created_at="1228172400000"
build_date="1317247200000"
version="2.1-SNAPSHOT"
return this;
}
- /**
- * Called by views when cloning measures
- * @deprecated since 4.4 not used
- */
- @Deprecated
- public Measure<G> setId(Long id) {
- return this;
- }
-
/**
* @return the first variation value
* @since 2.5
package org.sonar.api.platform;
import java.io.File;
-import java.util.List;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
File getTempDir();
- /**
- * @param suffixes the file suffixes. If null, then return all the files, whatever their suffix
- * @deprecated since 4.1
- */
- @Deprecated
- List<File> getExtensions(String dirName, String... suffixes);
-
}
this.relativePathFromSourceDir = null;
}
- /**
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- public Directory(String relativePathFromSourceDir) {
- this(relativePathFromSourceDir, null);
- }
-
- /**
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- public Directory(String relativePathFromSourceDir, Language language) {
- this.relativePathFromSourceDir = parseKey(relativePathFromSourceDir);
- }
-
/**
* Internal.
*/
*/
package org.sonar.api.resources;
-import java.util.List;
-import javax.annotation.CheckForNull;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
-import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.WildcardPattern;
/**
this.relativePathFromSourceDir = null;
}
- /**
- * @deprecated since 4.2 use {@link FileSystem#inputFile(org.sonar.api.batch.fs.FilePredicate)}
- */
- @Deprecated
- public File(String relativePathFromSourceDir) {
- if (relativePathFromSourceDir == null) {
- throw new IllegalArgumentException("File key is null");
- }
- this.relativePathFromSourceDir = parseKey(relativePathFromSourceDir);
- }
-
- /**
- * @deprecated since 4.2 use {@link FileSystem#inputFile(org.sonar.api.batch.fs.FilePredicate)}
- */
- @Deprecated
- public File(String relativeDirectoryPathFromSourceDir, String filename) {
- this.filename = StringUtils.trim(filename);
- if (StringUtils.isBlank(relativeDirectoryPathFromSourceDir)) {
- this.relativePathFromSourceDir = filename;
- } else {
- this.relativePathFromSourceDir = new StringBuilder().append(Directory.parseKey(relativeDirectoryPathFromSourceDir)).append(Directory.SEPARATOR).append(this.filename)
- .toString();
- }
- }
-
- /**
- * @deprecated since 4.2 use {@link FileSystem#inputFile(org.sonar.api.batch.fs.FilePredicate)}
- */
- @Deprecated
- public File(Language language, String relativePathFromSourceDir) {
- this(relativePathFromSourceDir);
- this.language = language;
- }
-
- /**
- * Creates a File from language, directory and filename
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- public File(Language language, String relativeDirectoryPathFromSourceDir, String filename) {
- this(relativeDirectoryPathFromSourceDir, filename);
- this.language = language;
- }
-
/**
* Internal.
*/
return matcher.match(getKey());
}
- /**
- * Creates a File from an io.file and a list of sources directories
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- @CheckForNull
- public static File fromIOFile(java.io.File file, List<java.io.File> sourceDirs) {
- PathResolver.RelativePath relativePath = new PathResolver().relativePath(sourceDirs, file);
- if (relativePath != null) {
- return new File(relativePath.path());
- }
- return null;
- }
-
- /**
- * Creates a {@link File} from an absolute {@link java.io.File} and a module.
- * The returned {@link File} can be then passed for example to
- * {@link SensorContext#saveMeasure(Resource, org.sonar.api.measures.Measure)}.
- * @param file absolute path to a file
- * @param module
- * @return null if the file is not under module basedir.
- * @deprecated since 4.5 use {@link FileSystem#inputFile(org.sonar.api.batch.fs.FilePredicate)}
- */
- @Deprecated
- @CheckForNull
- public static File fromIOFile(java.io.File file, Project module) {
- String relativePathFromBasedir = new PathResolver().relativePath(module.getBaseDir(), file);
- if (relativePathFromBasedir != null) {
- return File.create(relativePathFromBasedir);
- }
- return null;
- }
-
/**
* {@inheritDoc}
*
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.resources;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-
-/**
- * Java language implementation
- * This class have been moved in the plugin sonar-java
- *
- * @since 1.10
- * @deprecated in 3.6
- */
-@Deprecated
-public class Java extends AbstractLanguage {
-
- public static final Java INSTANCE = new Java();
-
- /**
- * Java key
- */
- public static final String KEY = "java";
-
- /**
- * Java name
- */
- public static final String NAME = "Java";
-
- /**
- * Default package name for classes without package def
- */
- public static final String DEFAULT_PACKAGE_NAME = "[default]";
-
- /**
- * Java files knows suffixes
- */
- public static final String[] SUFFIXES = {".java", ".jav"};
-
- /**
- * Default constructor
- */
- public Java() {
- super(KEY, NAME);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see AbstractLanguage#getFileSuffixes()
- */
- @Override
- public String[] getFileSuffixes() {
- return SUFFIXES;
- }
-
- public static boolean isJavaFile(java.io.File file) {
- String suffix = "." + StringUtils.lowerCase(StringUtils.substringAfterLast(file.getName(), "."));
- return ArrayUtils.contains(SUFFIXES, suffix);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.resources;
-
-import com.google.common.annotations.VisibleForTesting;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * A class that represents a Java class. This class can either be a Test class or source class
- *
- * @since 1.10
- * @deprecated since 4.2 use {@link org.sonar.api.resources.File}. See
- * http://docs.codehaus.org/display/SONAR/API+Changes for more details
- */
-@Deprecated
-public class JavaFile extends Resource {
-
- @VisibleForTesting
- JavaFile() {
- }
-
- public JavaFile(String packageName, String className) {
- throw unsupported();
- }
-
- public JavaFile(String packageKey, String className, boolean unitTest) {
- throw unsupported();
- }
-
- public JavaFile(String deprecatedKey) {
- throw unsupported();
- }
-
- public JavaFile(String deprecatedKey, boolean unitTest) {
- throw unsupported();
- }
-
- @Override
- public JavaPackage getParent() {
- throw unsupported();
- }
-
- @Override
- public String getDescription() {
- throw unsupported();
- }
-
- @Override
- public Language getLanguage() {
- throw unsupported();
- }
-
- @Override
- public String getName() {
- throw unsupported();
- }
-
- @Override
- public String getLongName() {
- throw unsupported();
- }
-
- @Override
- public String getScope() {
- throw unsupported();
- }
-
- @Override
- public String getQualifier() {
- throw unsupported();
- }
-
- public boolean isUnitTest() {
- throw unsupported();
- }
-
- @Override
- public boolean matchFilePattern(String antPattern) {
- throw unsupported();
- }
-
- public static JavaFile fromIOFile(File file, Project module, boolean unitTest) {
- throw unsupported();
- }
-
- public static JavaFile fromRelativePath(String relativePath, boolean unitTest) {
- throw unsupported();
- }
-
- public static JavaFile fromIOFile(File file, List<File> sourceDirs, boolean unitTest) {
- throw unsupported();
- }
-
- public static JavaFile fromAbsolutePath(String path, List<File> sourceDirs, boolean unitTest) {
- throw unsupported();
- }
-
- private static UnsupportedOperationException unsupported() {
- throw new UnsupportedOperationException("Not supported since v4.2. See http://redirect.sonarsource.com/doc/api-changes.html");
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.resources;
-
-/**
- * A class that represents a Java package in Sonar
- *
- * @since 1.10
- * @deprecated since 4.2 use {@link Directory} instead
- */
-@Deprecated
-public class JavaPackage extends Resource {
-
- public static final String DEFAULT_PACKAGE_NAME = "[default]";
-
- public JavaPackage() {
- // For testing
- }
-
- public JavaPackage(String deprecatedKey) {
- throw unsupported();
- }
-
- public boolean isDefault() {
- throw unsupported();
- }
-
- @Override
- public boolean matchFilePattern(String antPattern) {
- throw unsupported();
- }
-
- @Override
- public String getDescription() {
- throw unsupported();
- }
-
- @Override
- public String getScope() {
- throw unsupported();
- }
-
- @Override
- public String getQualifier() {
- throw unsupported();
- }
-
- @Override
- public String getName() {
- throw unsupported();
- }
-
- @Override
- public Resource getParent() {
- throw unsupported();
- }
-
- @Override
- public String getLongName() {
- throw unsupported();
- }
-
- @Override
- public Language getLanguage() {
- throw unsupported();
- }
-
- private static UnsupportedOperationException unsupported() {
- throw new UnsupportedOperationException("Not supported since v4.2. See http://redirect.sonarsource.com/doc/api-changes.html");
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.resources;
-
-/**
- * @deprecated in 4.2. Only file system components are managed by SQ core (files/directories).
- */
-@Deprecated
-public class Method extends Resource {
-
- public static final String SCOPE = Scopes.BLOCK_UNIT;
-
- protected String qualifier;
- protected Language language;
-
- protected Method(String key, String qualifier, Language language) {
- setKey(key);
- this.qualifier = qualifier;
- this.language = language;
- }
-
- @Override
- public String getName() {
- return getKey();
- }
-
- @Override
- public String getLongName() {
- return getKey();
- }
-
- @Override
- public String getDescription() {
- return null;
- }
-
- @Override
- public final Language getLanguage() {
- return language;
- }
-
- @Override
- public final String getScope() {
- return SCOPE;
- }
-
- @Override
- public final String getQualifier() {
- return qualifier;
- }
-
- @Override
- public Resource getParent() {
- return null;
- }
-
- @Override
- public final boolean matchFilePattern(String antPattern) {
- return false;
- }
-
- @Override
- public final boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof Method)) {
- return false;
- }
- Method method = (Method) o;
- if (!getKey().equals(method.getKey())) {
- return false;
- }
- if (!qualifier.equals(method.qualifier)) {
- return false;
- }
- return true;
- }
-
- @Override
- public final int hashCode() {
- int result = super.hashCode();
- result = 31 * result + qualifier.hashCode();
- result = 31 * result + getKey().hashCode();
- return result;
- }
-
- public static Method createMethod(String key, Language language) {
- return new Method(key, Qualifiers.METHOD, language);
- }
-}
public static final String SCOPE = Scopes.PROJECT;
- /**
- * Enumerates the type of possible analysis
- * @deprecated since 4.4 Since 4.3 SQ will no more run tests. So basically it's always reuse report.
- */
- @Deprecated
- public enum AnalysisType {
- STATIC, DYNAMIC, REUSE_REPORTS;
-
- /**
- * @param includeReuseReportMode whether to count report reuse as dynamic or not
- * @return whether this a dynamic analysis
- */
- public boolean isDynamic(boolean includeReuseReportMode) {
- return equals(Project.AnalysisType.DYNAMIC) ||
- (equals(Project.AnalysisType.REUSE_REPORTS) && includeReuseReportMode);
- }
- }
-
private String branch;
private String name;
private String description;
private Language language;
private Date analysisDate;
- private AnalysisType analysisType;
private String analysisVersion;
private Settings settings;
return this;
}
+ @Override
+ public Language getLanguage() {
+ return null;
+ }
+
/**
* For internal use only.
*/
return !isRoot();
}
- /**
- * @deprecated since 4.4 Since 4.3 SQ will no more run tests. So basically it's always reuse report.
- */
- @Deprecated
- public AnalysisType getAnalysisType() {
- return analysisType;
- }
-
- /**
- * @deprecated since 4.4 Since 4.3 SQ will no more run tests. So basically it's always reuse report.
- */
- @Deprecated
- public Project setAnalysisType(AnalysisType at) {
- this.analysisType = at;
- return this;
- }
-
- /**
- * whether it's the latest analysis done on this project (displayed in sonar dashboard) or an analysis on a past revision.
- *
- * @since 2.0
- * @deprecated in 3.6. The analysis is now always the latest one (past analysis must be done in a chronological order). See http://jira.sonarsource.com/browse/SONAR-4334
- */
- @Deprecated
- public boolean isLatestAnalysis() {
- return true;
- }
-
/**
* For internal use only.
*
}
/**
- * @return the project language when there is only one language
- * @deprecated since 4.2 use {@link org.sonar.api.batch.fs.FileSystem#languages()}
- */
- @Deprecated
- @Override
- public Language getLanguage() {
- return language;
- }
-
- /**
- * Internal use
- */
- public Project setLanguage(Language language) {
- this.language = language;
- return this;
- }
-
- /**
- * @return the language key or empty if no language is specified
- * @deprecated since 4.2 use {@link org.sonar.api.batch.fs.FileSystem#languages()}
- */
+ * @return the language key or empty if no language is specified
+ * @deprecated since 4.2 use {@link org.sonar.api.batch.fs.FileSystem#languages()}
+ */
@Deprecated
public String getLanguageKey() {
if (settings == null) {
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.resources;
-
-import com.google.common.collect.Lists;
-
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @since 1.10
- * @deprecated see method comments
- */
-@Deprecated
-public final class ProjectUtils {
-
- private ProjectUtils() {
- // utility class with only static methods
- }
-
- /**
- * @since 2.7
- * @deprecated in 4.2. Replaced by org.sonar.api.resources.InputFileUtils#toFiles()
- */
- @Deprecated
- public static List<java.io.File> toIoFiles(Collection<InputFile> inputFiles) {
- List<java.io.File> files = Lists.newArrayList();
- for (InputFile inputFile : inputFiles) {
- files.add(inputFile.getFile());
- }
- return files;
- }
-}
*/
public static final String MODULE = "BRC";
- /**
- * @deprecated since 4.2 now packages are considered as regular directories. Use {@link #DIRECTORY} instead.
- */
- @Deprecated
- public static final String PACKAGE = "PAC";
public static final String DIRECTORY = "DIR";
public static final String FILE = "FIL";
- /**
- * @deprecated since 4.2 now java files are considered as regular files. Use {@link #FILE} instead.
- */
- @Deprecated
- public static final String CLASS = "CLA";
- /**
- * @deprecated since 4.2 resources under FILE level will no more be supported.
- */
- @Deprecated
- public static final String PARAGRAPH = "PAR";
- /**
- * @deprecated since 4.2 resources under FILE level will no more be supported.
- */
- @Deprecated
- public static final String METHOD = "MET";
- /**
- * @deprecated since 4.2 resources under FILE level will no more be supported.
- */
- @Deprecated
- public static final String FIELD = "FLD";
// ugly, should be replaced by "natures"
public static final String UNIT_TEST_FILE = "UTS";
return StringUtils.equals(DIRECTORY, resource.getQualifier());
}
- /**
- * @deprecated since 4.2 Package is now a directory. Use {@link #isDirectory(Resource)}
- */
- @Deprecated
- public static boolean isPackage(final Resource resource) {
- return StringUtils.equals(PACKAGE, resource.getQualifier()) || isDirectory(resource);
- }
-
/**
* @param resource not nullable
*/
public static boolean isFile(final Resource resource) {
return StringUtils.equals(FILE, resource.getQualifier());
}
-
- /**
- * @param resource not nullable
- * @deprecated since 4.2 CLA qualifier is deprecated
- */
- @Deprecated
- public static boolean isClass(final Resource resource) {
- return StringUtils.equals(CLASS, resource.getQualifier()) || isFile(resource);
- }
-
- /**
- * @param resource not nullable
- */
- public static boolean isMethod(final Resource resource) {
- return StringUtils.equals(METHOD, resource.getQualifier());
- }
-
- /**
- * @param resource not nullable
- */
- public static boolean isParagraph(final Resource resource) {
- return StringUtils.equals(PARAGRAPH, resource.getQualifier());
- }
}
@Deprecated
public static final String QUALIFIER_MODULE = Qualifiers.MODULE;
- /**
- * @deprecated since 2.6. Use Qualifiers.PACKAGE.
- */
- @Deprecated
- public static final String QUALIFIER_PACKAGE = Qualifiers.PACKAGE;
-
/**
* @deprecated since 2.6. Use Qualifiers.DIRECTORY.
*/
@Deprecated
public static final String QUALIFIER_FILE = Qualifiers.FILE;
- /**
- * @deprecated since 2.6. Use Qualifiers.CLASS.
- */
- @Deprecated
- public static final String QUALIFIER_CLASS = Qualifiers.CLASS;
-
- /**
- * @deprecated since 2.6. Use Qualifiers.FIELD.
- */
- @Deprecated
- public static final String QUALIFIER_FIELD = Qualifiers.FIELD;
-
- /**
- * @deprecated since 2.6. Use Qualifiers.METHOD.
- */
- @Deprecated
- public static final String QUALIFIER_METHOD = Qualifiers.METHOD;
-
- /**
- * @deprecated since 2.6. Use Qualifiers.UNIT_TEST_FILE.
- */
- @Deprecated
- public static final String QUALIFIER_UNIT_TEST_CLASS = Qualifiers.UNIT_TEST_FILE;
-
private Integer id;
private String key;
return Qualifiers.MODULE.equals(resource.getQualifier());
}
- /**
- * @deprecated since 4.2 Package are now directory. Use {@link #isDirectory(Resource)}
- */
- @Deprecated
- public static boolean isPackage(Resource resource) {
- return resource != null && Qualifiers.PACKAGE.equals(resource.getQualifier());
- }
-
/**
* @return whether a resource is a set
*/
/* QUALIFIERS */
- /**
- * @return whether a resource is a class
- * @deprecated since 4.2 CLA qualifier is deprecated
- */
- @Deprecated
- public static boolean isClass(Resource resource) {
- return Qualifiers.CLASS.equals(resource.getQualifier());
- }
-
/**
* @return whether a resource is a unit test class
* @deprecated since 5.1 use {@link #isUnitTestFile(Resource)}
.options("de", "en")
.description("desc")
.type(PropertyType.FLOAT)
- .onlyOnQualifiers(Qualifiers.FILE, Qualifiers.CLASS)
+ .onlyOnQualifiers(Qualifiers.FILE)
.multiValues(true)
.propertySetKey("set")
.build();
assertThat(def.description()).isEqualTo("desc");
assertThat(def.type()).isEqualTo(PropertyType.FLOAT);
assertThat(def.global()).isFalse();
- assertThat(def.qualifiers()).containsOnly(Qualifiers.FILE, Qualifiers.CLASS);
+ assertThat(def.qualifiers()).containsOnly(Qualifiers.FILE);
assertThat(def.multiValues()).isTrue();
assertThat(def.propertySetKey()).isEqualTo("set");
assertThat(def.fields()).isEmpty();
.name("Hello")
.fields(
PropertyFieldDefinition.build("first").name("First").description("Description").options("A", "B").build(),
- PropertyFieldDefinition.build("second").name("Second").type(PropertyType.INTEGER).indicativeSize(5).build()
- )
+ PropertyFieldDefinition.build("second").name("Second").type(PropertyType.INTEGER).indicativeSize(5).build())
.build();
assertThat(def.fields()).hasSize(2);
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import java.io.IOException;
-
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public class FileTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- @Test
- public void createFromIoFileShouldComputeCorrectKey() throws IOException {
- java.io.File baseDir = temp.newFolder();
- Project project = mock(Project.class);
- when(project.getBaseDir()).thenReturn(baseDir);
- Resource file = File.fromIOFile(new java.io.File(baseDir, "src/foo/bar/toto.sql"), project);
- assertThat(file.getKey()).isEqualTo("src/foo/bar/toto.sql");
- }
-
@Test
public void trimKeyAndName() {
File file = File.create(" foo/bar/toto.sql ");
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.resources;
-
-import org.junit.Test;
-
-import java.util.List;
-
-public class JavaFileTest {
-
- JavaFile javaFile = new JavaFile();
-
- @Test(expected = UnsupportedOperationException.class)
- public void testConstructor() {
- JavaFile javaClass = new JavaFile("", "");
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testConstructor2() {
- JavaFile javaClass = new JavaFile("", "", true);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testConstructor3() {
- JavaFile javaClass = new JavaFile("");
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testConstructor4() {
- JavaFile javaClass = new JavaFile("", true);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetParent() {
- javaFile.getParent();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetDescription() {
- javaFile.getDescription();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetLanguage() {
- javaFile.getLanguage();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetName() {
- javaFile.getName();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetLongName() {
- javaFile.getLongName();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetScope() {
- javaFile.getScope();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetQualifier() {
- javaFile.getQualifier();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testIsUnitTest() {
- javaFile.isUnitTest();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testMathFilePattern() {
- javaFile.matchFilePattern("");
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void fromIoFile1() {
- JavaFile.fromIOFile(null, (Project) null, true);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void fromIoFile2() {
- JavaFile.fromIOFile(null, (List<java.io.File>) null, true);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void fromRelativePath() {
- JavaFile.fromRelativePath("", false);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void fromAbsolutePath() {
- JavaFile.fromAbsolutePath("", (List<java.io.File>) null, false);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.resources;
-
-import org.junit.Test;
-
-public class JavaPackageTest {
-
- JavaPackage javaPackage = new JavaPackage();
-
- @Test(expected = UnsupportedOperationException.class)
- public void testConstructor() {
- new JavaPackage("");
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetParent() {
- javaPackage.getParent();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetDescription() {
- javaPackage.getDescription();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetLanguage() {
- javaPackage.getLanguage();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetName() {
- javaPackage.getName();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetLongName() {
- javaPackage.getLongName();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetScope() {
- javaPackage.getScope();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetQualifier() {
- javaPackage.getQualifier();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testIsUnitTest() {
- javaPackage.isDefault();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testMathFilePattern() {
- javaPackage.matchFilePattern("");
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.resources;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class JavaTest {
-
- @Test
- public void test() {
- Java language = new Java();
- assertThat(language.getFileSuffixes()).isEqualTo(new String[] {".java", ".jav"});
-
- assertThat(Java.isJavaFile(new java.io.File("Example.java"))).isTrue();
- assertThat(Java.isJavaFile(new java.io.File("Example.JAVA"))).isTrue();
- assertThat(Java.isJavaFile(new java.io.File("Example.jav"))).isTrue();
- assertThat(Java.isJavaFile(new java.io.File("Example.Jav"))).isTrue();
- assertThat(Java.isJavaFile(new java.io.File("Example.notjava"))).isFalse();
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.resources;
-
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class MethodTest {
-
- @Test
- public void shouldAcceptOverridding() {
- Method method = Method.createMethod("Foo.foo()", Java.INSTANCE);
- Method fakeMethod = new FakeMethod("Foo.foo()");
-
- assertThat(method.equals(fakeMethod), is(true));
- assertThat(fakeMethod.equals(method), is(true));
-
- assertThat(method.hashCode(), is(fakeMethod.hashCode()));
- assertThat(fakeMethod.hashCode(), is(method.hashCode()));
- }
-
- static class FakeMethod extends Method {
- protected FakeMethod(String key) {
- super(key, Qualifiers.METHOD, Java.INSTANCE);
- }
- }
-}
@Test
public void checkFile() {
File file = File.create("hello.Foo");
- assertThat(ResourceUtils.isClass(file)).isFalse();
- assertThat(ResourceUtils.isPackage(file)).isFalse();
assertThat(ResourceUtils.isModuleProject(file)).isFalse();
assertThat(ResourceUtils.isSpace(file)).isFalse();
assertThat(ResourceUtils.isEntity(file)).isTrue();
public void checkUnitTest() {
File utFile = File.create("hello.Foo");
utFile.setQualifier(Qualifiers.UNIT_TEST_FILE);
- assertThat(ResourceUtils.isClass(utFile)).isFalse();
- assertThat(ResourceUtils.isPackage(utFile)).isFalse();
assertThat(ResourceUtils.isModuleProject(utFile)).isFalse();
assertThat(ResourceUtils.isSpace(utFile)).isFalse();
assertThat(ResourceUtils.isEntity(utFile)).isTrue();
@Test
public void checkDirectory() {
Directory dir = Directory.create("hello");
- assertThat(ResourceUtils.isClass(dir)).isFalse();
- assertThat(ResourceUtils.isPackage(dir)).isFalse();
assertThat(ResourceUtils.isModuleProject(dir)).isFalse();
assertThat(ResourceUtils.isSpace(dir)).isTrue();
assertThat(ResourceUtils.isEntity(dir)).isFalse();
import java.util.Date;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
@ScannerSide
public class ProjectConfigurator {
- private static final Logger LOG = LoggerFactory.getLogger(ProjectConfigurator.class);
private final System2 system2;
private Settings settings;
relativePathFromSourceDir = "";
}
}
- if (relativePathFromSourceDir != null) {
- // Resolve using deprecated key
- List<String> dirs;
- ProjectDefinition projectDef = projectTree.getProjectDefinition(getProject());
- if (isTest) {
- dirs = projectDef.tests();
- } else {
- dirs = projectDef.sources();
- }
- for (String src : dirs) {
- java.io.File dirOrFile = pathResolver.relativeFile(projectDef.getBaseDir(), src);
- java.io.File abs = new java.io.File(dirOrFile, relativePathFromSourceDir);
- Bucket b = getBucket(isDir ? Directory.fromIOFile(abs, getProject()) : File.fromIOFile(abs, getProject()));
- if (b != null) {
- return b;
- }
- }
-
- }
return null;
}
private final SensorsExecutor sensorsExecutor;
private final SensorContext sensorContext;
private final DefaultIndex index;
- private final ProjectInitializer pi;
private final FileSystemLogger fsLogger;
private final DefaultModuleFileSystem fs;
private final QProfileVerifier profileVerifier;
public AbstractPhaseExecutor(InitializersExecutor initializersExecutor, PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
SensorContext sensorContext, DefaultIndex index,
- EventBus eventBus, ProjectInitializer pi,
- FileSystemLogger fsLogger, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier,
+ EventBus eventBus, FileSystemLogger fsLogger, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier,
IssueExclusionsLoader issueExclusionsLoader) {
this.postJobsExecutor = postJobsExecutor;
this.initializersExecutor = initializersExecutor;
this.sensorContext = sensorContext;
this.index = index;
this.eventBus = eventBus;
- this.pi = pi;
this.fsLogger = fsLogger;
this.fs = fs;
this.profileVerifier = profileVerifier;
* Executed on each module
*/
public final void execute(Project module) {
- pi.execute(module);
-
eventBus.fireEvent(new ProjectAnalysisEvent(module, true));
executeInitializersPhase();
private final IssueCallback issueCallback;
public IssuesPhaseExecutor(InitializersExecutor initializersExecutor, PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, SensorContext sensorContext,
- DefaultIndex index, EventBus eventBus, ProjectInitializer pi, FileSystemLogger fsLogger, IssuesReports jsonReport, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier,
+ DefaultIndex index, EventBus eventBus, FileSystemLogger fsLogger, IssuesReports jsonReport, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier,
IssueExclusionsLoader issueExclusionsLoader, IssueTransition localIssueTracking, IssueCallback issueCallback) {
- super(initializersExecutor, postJobsExecutor, sensorsExecutor, sensorContext, index, eventBus, pi, fsLogger, fs, profileVerifier, issueExclusionsLoader);
+ super(initializersExecutor, postJobsExecutor, sensorsExecutor, sensorContext, index, eventBus, fsLogger, fs, profileVerifier, issueExclusionsLoader);
this.eventBus = eventBus;
this.issuesReport = jsonReport;
this.localIssueTracking = localIssueTracking;
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.phases;
-
-import org.sonar.api.batch.ScannerSide;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Languages;
-import org.sonar.api.resources.Project;
-import org.sonar.api.utils.MessageException;
-
-/**
- * Should be dropped when org.sonar.api.resources.Project is fully refactored.
- */
-@ScannerSide
-public class ProjectInitializer {
-
- private Languages languages;
- private Settings settings;
-
- public ProjectInitializer(Settings settings, Languages languages) {
- this.settings = settings;
- this.languages = languages;
- }
-
- public void execute(Project project) {
- if (project.getLanguage() == null) {
- initDeprecatedLanguage(project);
- }
- }
-
- private void initDeprecatedLanguage(Project project) {
- String languageKey = settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY);
- if (StringUtils.isNotBlank(languageKey)) {
- Language language = languages.get(languageKey);
- if (language == null) {
- throw MessageException.of("Language with key '" + languageKey + "' not found");
- }
- project.setLanguage(language);
- } else {
- project.setLanguage(Project.NONE_LANGUAGE);
- }
- }
-}
private final CpdExecutor cpdExecutor;
public PublishPhaseExecutor(InitializersExecutor initializersExecutor, PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, SensorContext sensorContext,
- DefaultIndex index, EventBus eventBus, ReportPublisher reportPublisher, ProjectInitializer pi, FileSystemLogger fsLogger, DefaultModuleFileSystem fs,
+ DefaultIndex index, EventBus eventBus, ReportPublisher reportPublisher, FileSystemLogger fsLogger, DefaultModuleFileSystem fs,
QProfileVerifier profileVerifier, IssueExclusionsLoader issueExclusionsLoader, CpdExecutor cpdExecutor) {
- super(initializersExecutor, postJobsExecutor, sensorsExecutor, sensorContext, index, eventBus, pi, fsLogger, fs, profileVerifier, issueExclusionsLoader);
+ super(initializersExecutor, postJobsExecutor, sensorsExecutor, sensorContext, index, eventBus, fsLogger, fs, profileVerifier, issueExclusionsLoader);
this.eventBus = eventBus;
this.reportPublisher = reportPublisher;
this.cpdExecutor = cpdExecutor;
import org.sonar.batch.phases.InitializersExecutor;
import org.sonar.batch.phases.IssuesPhaseExecutor;
import org.sonar.batch.phases.PostJobsExecutor;
-import org.sonar.batch.phases.ProjectInitializer;
import org.sonar.batch.phases.PublishPhaseExecutor;
import org.sonar.batch.phases.SensorsExecutor;
import org.sonar.batch.postjob.DefaultPostJobContext;
PostJobsExecutor.class,
SensorsExecutor.class,
InitializersExecutor.class,
- ProjectInitializer.class,
// file system
ModuleInputFileCache.class,
--- /dev/null
+/*\r
+ * SonarQube\r
+ * Copyright (C) 2009-2016 SonarSource SA\r
+ * mailto:contact AT sonarsource DOT com\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 3 of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with this program; if not, write to the Free Software Foundation,\r
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
+ */\r
+package org.sonar.batch;\r
+\r
+import org.sonar.api.resources.AbstractLanguage;\r
+\r
+public class FakeJava extends AbstractLanguage {\r
+\r
+ public static final String KEY = "java";\r
+ public static final FakeJava INSTANCE = new FakeJava();\r
+\r
+ public FakeJava() {\r
+ super(KEY, "Java");\r
+ }\r
+\r
+ @Override\r
+ public String[] getFileSuffixes() {\r
+ return new String[] {".java", ".jav"};\r
+ }\r
+\r
+}\r
new ProjectConfigurator(configuration, system2).configure(project);
}
- @Test
- public void default_analysis_type_is_dynamic() {
- Project project = new Project("key");
- new ProjectConfigurator(new Settings(), system2).configure(project);
- assertThat(project.getAnalysisType()).isEqualTo(Project.AnalysisType.DYNAMIC);
- }
-
- @Test
- public void is_dynamic_analysis() {
- assertThat(Project.AnalysisType.DYNAMIC.isDynamic(false)).isTrue();
- assertThat(Project.AnalysisType.DYNAMIC.isDynamic(true)).isTrue();
-
- assertThat(Project.AnalysisType.STATIC.isDynamic(false)).isFalse();
- assertThat(Project.AnalysisType.STATIC.isDynamic(true)).isFalse();
-
- assertThat(Project.AnalysisType.REUSE_REPORTS.isDynamic(false)).isFalse();
- assertThat(Project.AnalysisType.REUSE_REPORTS.isDynamic(true)).isTrue();
- }
-
}
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Java;
+import org.sonar.batch.FakeJava;
import org.sonar.batch.cpd.CpdComponents;
import static org.assertj.core.api.Assertions.assertThat;
@Test
public void test_global_skip() {
settings.setProperty("sonar.cpd.skip", true);
- assertThat(sensor.isSkipped(Java.KEY)).isTrue();
+ assertThat(sensor.isSkipped(FakeJava.KEY)).isTrue();
}
@Test
public void should_not_skip_by_default() {
- assertThat(sensor.isSkipped(Java.KEY)).isFalse();
+ assertThat(sensor.isSkipped(FakeJava.KEY)).isFalse();
}
@Test
settings.setProperty("sonar.cpd.php.skip", true);
assertThat(sensor.isSkipped("php")).isTrue();
- assertThat(sensor.isSkipped(Java.KEY)).isFalse();
+ assertThat(sensor.isSkipped(FakeJava.KEY)).isFalse();
}
@Test
public void test_engine() {
- assertThat(sensor.getBlockIndexer(Java.KEY)).isSameAs(sonarEngine);
+ assertThat(sensor.getBlockIndexer(FakeJava.KEY)).isSameAs(sonarEngine);
assertThat(sensor.getBlockIndexer("PHP")).isSameAs(sonarBridgeEngine);
}
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.batch.DefaultProjectTree;
+import org.sonar.batch.FakeJava;
import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.sensor.DefaultSensorStorage;
@Test
public void shouldIndexTreeOfResources() {
Directory directory = Directory.create("src/org/foo");
- File file = File.create("src/org/foo/Bar.java", Java.INSTANCE, false);
+ File file = File.create("src/org/foo/Bar.java", FakeJava.INSTANCE, false);
assertThat(index.index(directory)).isTrue();
assertThat(index.index(file, directory)).isTrue();
@Test
public void shouldGetSource() throws Exception {
Directory directory = Directory.create("src/org/foo");
- File file = File.create("src/org/foo/Bar.java", Java.INSTANCE, false);
+ File file = File.create("src/org/foo/Bar.java", FakeJava.INSTANCE, false);
FileUtils.write(new java.io.File(baseDir, "src/org/foo/Bar.java"), "Foo bar");
assertThat(index.index(directory)).isTrue();
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.DateUtils;
+import org.sonar.batch.FakeJava;
import org.sonar.batch.index.BatchComponentCache;
import org.sonar.batch.scan.ImmutableProjectReactor;
import org.sonar.scanner.protocol.output.FileStructure;
dir.setId(3).setUuid("DIR_UUID");
resourceCache.add(dir, module1).setInputComponent(new DefaultInputDir("foo", "src"));
- org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false);
+ org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", FakeJava.INSTANCE, false);
file.setEffectiveKey("module1:src/Foo.java");
file.setId(4).setUuid("FILE_UUID");
resourceCache.add(file, dir).setInputComponent(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
fileWithoutLang.setId(5).setUuid("FILE_WITHOUT_LANG_UUID");
resourceCache.add(fileWithoutLang, dir).setInputComponent(new DefaultInputFile("module1", "src/make").setLines(10));
- org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", Java.INSTANCE, true);
+ org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", FakeJava.INSTANCE, true);
testFile.setEffectiveKey("module1:test/FooTest.java");
testFile.setId(6).setUuid("TEST_FILE_UUID");
resourceCache.add(testFile, dir).setInputComponent(new DefaultInputFile("module1", "test/FooTest.java").setLines(4));
dir.setId(3).setUuid("DIR_UUID");
resourceCache.add(dir, module1).setInputComponent(new DefaultInputDir("foo", "src"));
- org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false);
+ org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", FakeJava.INSTANCE, false);
file.setEffectiveKey("module1:my_branch:my_branch:src/Foo.java");
file.setId(4).setUuid("FILE_UUID");
resourceCache.add(file, dir).setInputComponent(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Java;
import org.sonar.api.resources.Languages;
import org.sonar.api.utils.MessageException;
+import org.sonar.batch.FakeJava;
import org.sonar.batch.repository.language.DefaultLanguagesRepository;
import org.sonar.batch.repository.language.LanguagesRepository;
public ExpectedException thrown = ExpectedException.none();
private Settings settings = new Settings();
- private LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(Java.INSTANCE));
+ private LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(FakeJava.INSTANCE));
private DefaultFileSystem fs;
@Before
verifier.stop();
}
-
+
@Test
public void language_is_empty() {
settings.setProperty("sonar.language", "");
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.resources.AbstractLanguage;
import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.Java;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
+import org.sonar.batch.FakeJava;
import org.sonar.batch.analysis.DefaultAnalysisMode;
import org.sonar.batch.index.BatchComponent;
import org.sonar.batch.index.BatchComponentCache;
@Test
public void should_index_java_files() throws IOException {
- Languages languages = new Languages(Java.INSTANCE);
+ Languages languages = new Languages(FakeJava.INSTANCE);
ComponentIndexer indexer = createIndexer(languages);
DefaultModuleFileSystem fs = new DefaultModuleFileSystem(project, null, mock(FileIndexer.class), initializer, indexer, mode);
fs.add(newInputFile("src/main/java/foo/bar/Foo.java", "", "foo/bar/Foo.java", "java", false, Status.ADDED));
fs.index();
- verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", Java.INSTANCE, false));
- verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java2/foo/bar/Foo.java", Java.INSTANCE, false));
+ verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", FakeJava.INSTANCE, false));
+ verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java2/foo/bar/Foo.java", FakeJava.INSTANCE, false));
verify(sonarIndex).index(argThat(new ArgumentMatcher<org.sonar.api.resources.File>() {
@Override
public boolean matches(Object arg0) {
import org.junit.Test;
import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Java;
import org.sonar.api.resources.Languages;
+import org.sonar.batch.FakeJava;
import org.sonar.batch.repository.language.DefaultLanguagesRepository;
import org.sonar.batch.repository.language.LanguagesRepository;
public class LanguageDetectionFactoryTest {
@Test
public void testCreate() throws Exception {
- LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(Java.INSTANCE));
+ LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(FakeJava.INSTANCE));
LanguageDetectionFactory factory = new LanguageDetectionFactory(new Settings(), languages);
LanguageDetection languageDetection = factory.create();
assertThat(languageDetection).isNotNull();