*/
private static final String VALID_PROJECT_KEY_REGEXP = "[^\\p{javaWhitespace}]+";
- private static final String VALID_PROJECT_KEY_ISSUES_MODE_REGEXP = "[\\p{Alnum}\\-_.:/]*[\\p{Alpha}\\-_.:/]+[\\p{Alnum}\\-_.:/]*";
-
/*
* Allowed characters are alphanumeric, '-', '_', '.' and '/'
*/
checkArgument(isValidProjectKey(keyCandidate), "Malformed key for '%s'. %s", keyCandidate, "Project key cannot be empty nor contain whitespaces.");
}
- /**
- * <p>Test if given parameter is valid for a project. Valid format is:</p>
- * <ul>
- * <li>Allowed characters:
- * <ul>
- * <li>Uppercase ASCII letters A-Z</li>
- * <li>Lowercase ASCII letters a-z</li>
- * <li>ASCII digits 0-9</li>
- * <li>Punctuation signs dash '-', underscore '_', period '.', colon ':' and slash '/'</li>
- * </ul>
- * </li>
- * <li>At least one non-digit</li>
- * </ul>
- *
- * @return <code>true</code> if <code>keyCandidate</code> can be used for a project in issues mode
- */
- public static boolean isValidProjectKeyIssuesMode(String keyCandidate) {
- return keyCandidate.matches(VALID_PROJECT_KEY_ISSUES_MODE_REGEXP);
- }
-
/**
* <p>Test if given parameter is valid for a branch. Valid format is:</p>
* <ul>
assertThat(ComponentKeys.isValidProjectKey("ab ")).isFalse();
}
- @Test
- public void isValidModuleKeyIssuesMode() {
- assertThat(ComponentKeys.isValidProjectKeyIssuesMode("")).isFalse();
- assertThat(ComponentKeys.isValidProjectKeyIssuesMode("abc")).isTrue();
- assertThat(ComponentKeys.isValidProjectKeyIssuesMode("0123")).isFalse();
- assertThat(ComponentKeys.isValidProjectKeyIssuesMode("ab 12")).isFalse();
- assertThat(ComponentKeys.isValidProjectKeyIssuesMode("ab_12")).isTrue();
- assertThat(ComponentKeys.isValidProjectKeyIssuesMode("ab/12")).isTrue();
- }
-
@Test
public void isValidBranchKey() {
assertThat(ComponentKeys.isValidLegacyBranch("")).isTrue();
import java.util.TreeSet;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
private static final int MAX_WIDTH = 1000;
private final ScannerPluginRepository pluginRepo;
private final ProjectServerSettings projectServerSettings;
- private final AnalysisMode mode;
private final System2 system;
private final GlobalServerSettings globalServerSettings;
private final InputModuleHierarchy hierarchy;
private final InputComponentStore store;
- public AnalysisContextReportPublisher(ProjectServerSettings projectServerSettings, AnalysisMode mode, ScannerPluginRepository pluginRepo, System2 system,
+ public AnalysisContextReportPublisher(ProjectServerSettings projectServerSettings, ScannerPluginRepository pluginRepo, System2 system,
GlobalServerSettings globalServerSettings, InputModuleHierarchy hierarchy, InputComponentStore store) {
this.projectServerSettings = projectServerSettings;
- this.mode = mode;
this.pluginRepo = pluginRepo;
this.system = system;
this.globalServerSettings = globalServerSettings;
}
public void init(ScannerReportWriter writer) {
- if (mode.isIssues()) {
- return;
- }
File analysisLog = writer.getFileStructure().analysisLog();
try (BufferedWriter fileWriter = Files.newBufferedWriter(analysisLog.toPath(), StandardCharsets.UTF_8)) {
writePlugins(fileWriter);
import java.util.List;
import java.util.stream.Stream;
import javax.annotation.Nullable;
-import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.MessageException;
* @since 3.6
*/
public class ProjectReactorValidator {
- private final AnalysisMode mode;
private final GlobalConfiguration settings;
// null = branch plugin is not available
@Nullable
private final BranchParamsValidator branchParamsValidator;
- public ProjectReactorValidator(AnalysisMode mode, GlobalConfiguration settings, @Nullable BranchParamsValidator branchParamsValidator) {
- this.mode = mode;
+ public ProjectReactorValidator(GlobalConfiguration settings, @Nullable BranchParamsValidator branchParamsValidator) {
this.settings = settings;
this.branchParamsValidator = branchParamsValidator;
}
- public ProjectReactorValidator(AnalysisMode mode, GlobalConfiguration settings) {
- this(mode, settings, null);
+ public ProjectReactorValidator(GlobalConfiguration settings) {
+ this(settings, null);
}
public void validate(ProjectReactor reactor) {
List<String> validationMessages = new ArrayList<>();
for (ProjectDefinition moduleDef : reactor.getProjects()) {
- if (mode.isIssues()) {
- validateModuleIssuesMode(moduleDef, validationMessages);
- } else {
- validateModule(moduleDef, validationMessages);
- }
+ validateModule(moduleDef, validationMessages);
}
String deprecatedBranchName = reactor.getRoot().getBranch();
+ "See %s for more information.", param, BRANCHES_DOC_LINK)));
}
- private static void validateModuleIssuesMode(ProjectDefinition moduleDef, List<String> validationMessages) {
- if (!ComponentKeys.isValidProjectKeyIssuesMode(moduleDef.getKey())) {
- validationMessages.add(format("\"%s\" is not a valid project or module key. "
- + "Allowed characters in issues mode are alphanumeric, '-', '_', '.', '/' and ':', with at least one non-digit.", moduleDef.getKey()));
- }
- }
-
private static void validateModule(ProjectDefinition moduleDef, List<String> validationMessages) {
if (!ComponentKeys.isValidProjectKey(moduleDef.getKey())) {
validationMessages.add(format("\"%s\" is not a valid project or module key. It cannot be empty nor contain whitespaces.", moduleDef.getKey()));
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
private ScannerPluginRepository pluginRepo = mock(ScannerPluginRepository.class);
private AnalysisContextReportPublisher publisher;
- private AnalysisMode analysisMode = mock(AnalysisMode.class);
private System2 system2;
private GlobalServerSettings globalServerSettings;
private InputModuleHierarchy hierarchy;
hierarchy = mock(InputModuleHierarchy.class);
store = mock(InputComponentStore.class);
projectServerSettings = mock(ProjectServerSettings.class);
- publisher = new AnalysisContextReportPublisher(projectServerSettings, analysisMode, pluginRepo, system2, globalServerSettings, hierarchy, store);
+ publisher = new AnalysisContextReportPublisher(projectServerSettings, pluginRepo, system2, globalServerSettings, hierarchy, store);
}
@Test
verifyZeroInteractions(system2);
}
- @Test
- public void shouldNotDumpInIssuesMode() throws Exception {
- when(analysisMode.isIssues()).thenReturn(true);
-
- ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
- publisher.init(writer);
-
- assertThat(writer.getFileStructure().analysisLog()).doesNotExist();
- }
-
@Test
public void dumpServerSideGlobalProps() throws Exception {
logTester.setLevel(LoggerLevel.DEBUG);
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.MessageException;
@Rule
public ExpectedException thrown = ExpectedException.none();
- private AnalysisMode mode = mock(AnalysisMode.class);
private GlobalConfiguration settings = mock(GlobalConfiguration.class);
private ProjectInfo projectInfo = mock(ProjectInfo.class);
- private ProjectReactorValidator underTest = new ProjectReactorValidator(mode, settings);
+ private ProjectReactorValidator underTest = new ProjectReactorValidator(settings);
@Before
public void prepare() {
};
}
- @Test
- public void allow_slash_issues_mode() {
- when(mode.isIssues()).thenReturn(true);
- underTest.validate(createProjectReactor("project/key"));
- }
-
@Test
public void fail_with_invalid_key() {
ProjectReactor reactor = createProjectReactor(" ");