@Test public void check_getters() throws IOException { ProjectDefinition def = ProjectDefinition.create(); def.setKey("moduleKey"); File baseDir = temp.newFolder(); Path src = baseDir.toPath().resolve(FILE_1); Files.createFile(src); Path test = baseDir.toPath().resolve(TEST_1); Files.createFile(test); def.setBaseDir(baseDir); File workDir = temp.newFolder(); def.setWorkDir(workDir); def.setSources(FILE_1); def.setTests(TEST_1); DefaultInputModule module = new DefaultInputModule(def); assertThat(module.key()).isEqualTo("moduleKey"); assertThat(module.definition()).isEqualTo(def); assertThat(module.getBranch()).isNull(); assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath()); assertThat(module.getKeyWithBranch()).isEqualTo("moduleKey"); assertThat(module.getWorkDir()).isEqualTo(workDir.toPath()); assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset()); assertThat(module.getSourceDirsOrFiles()).containsExactlyInAnyOrder(src); assertThat(module.getTestDirsOrFiles()).containsExactlyInAnyOrder(test); assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset()); assertThat(module.isFile()).isFalse(); }
public void put(DefaultInputModule inputModule) { String key = inputModule.key(); String keyWithBranch = inputModule.getKeyWithBranch(); Preconditions.checkNotNull(inputModule); Preconditions.checkState(!inputComponents.containsKey(key), "Module '%s' already indexed", key); Preconditions.checkState(!inputModuleCache.containsKey(keyWithBranch), "Module '%s' already indexed", keyWithBranch); inputComponents.put(key, inputModule); inputModuleCache.put(keyWithBranch, inputModule); }
private static DefaultInputModule createModule(ProjectDefinition def, int scannerComponentId) { LOG.debug(" Init module '{}'", def.getName()); DefaultInputModule module = new DefaultInputModule(def, scannerComponentId); LOG.debug(" Base dir: {}", module.getBaseDir().toAbsolutePath().toString()); LOG.debug(" Working dir: {}", module.getWorkDir().toAbsolutePath().toString()); LOG.debug(" Module global encoding: {}, default locale: {}", module.getEncoding().displayName(), Locale.getDefault()); return module; }
private void writeModulesSettings(BufferedWriter fileWriter) throws IOException { for (DefaultInputModule module : store.allModules()) { if (module.equals(hierarchy.root())) { continue; } Map<String, String> moduleSpecificProps = collectModuleSpecificProps(module); fileWriter.append(String.format("Scanner properties of module: %s", module.key())).append('\n'); writeScannerProps(fileWriter, moduleSpecificProps); } }
public static DefaultInputModule newDefaultInputModule(ProjectDefinition projectDefinition) { return new DefaultInputModule(projectDefinition, TestInputFileBuilder.nextBatchId()); }
return; if (!realAbsoluteFile.startsWith(module.getBaseDir())) { LOG.warn("File '{}' is ignored. It is not located in module basedir '{}'.", realAbsoluteFile.toAbsolutePath(), module.getBaseDir()); return; Path moduleRelativePath = module.getBaseDir().relativize(realAbsoluteFile); boolean included = evaluateInclusionsFilters(moduleExclusionFilters, realAbsoluteFile, projectRelativePath, moduleRelativePath, type); if (!included) { moduleRelativePath.toString(), type, language, scannerComponentIdGenerator.getAsInt(), sensorStrategy); DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> metadataGenerator.setMetadata(module.getKeyWithBranch(), f, module.getEncoding())); if (language != null) { inputFile.setPublished(true); componentStore.put(module.key(), inputFile); issueExclusionsLoader.addMulticriteriaPatterns(inputFile); LOG.debug("'{}' indexed {}with language '{}'", projectRelativePath, type == Type.TEST ? "as test " : "", inputFile.language());
public String relativePathToRoot(DefaultInputModule module) { Path rootBaseDir = root.getBaseDir(); Path moduleBaseDir = module.getBaseDir(); return PathResolver.relativize(rootBaseDir, moduleBaseDir).orElse(null); } }
private void index(DefaultInputModule module, ExclusionCounter exclusionCounter) { // Emulate creation of module level settings ModuleConfiguration moduleConfig = new ModuleConfigurationProvider().provide(globalConfig, module, globalServerSettings, projectServerSettings); ModuleExclusionFilters moduleExclusionFilters = new ModuleExclusionFilters(moduleConfig); ModuleCoverageAndDuplicationExclusions moduleCoverageAndDuplicationExclusions = new ModuleCoverageAndDuplicationExclusions(moduleConfig); if (componentStore.allModules().size() > 1) { LOG.info("Indexing files of module '{}'", module.getName()); LOG.info(" Base dir: {}", module.getBaseDir().toAbsolutePath()); logPaths(" Source paths: ", module.getBaseDir(), module.getSourceDirsOrFiles()); logPaths(" Test paths: ", module.getBaseDir(), module.getTestDirsOrFiles()); moduleExclusionFilters.log(" "); moduleCoverageAndDuplicationExclusions.log(" "); } indexFiles(module, moduleExclusionFilters, moduleCoverageAndDuplicationExclusions, module.getSourceDirsOrFiles(), Type.MAIN, exclusionCounter); indexFiles(module, moduleExclusionFilters, moduleCoverageAndDuplicationExclusions, module.getTestDirsOrFiles(), Type.TEST, exclusionCounter); }
DefaultInputModule mod3 = mock(DefaultInputModule.class); when(root.key()).thenReturn("root"); when(mod1.key()).thenReturn("mod1"); when(mod2.key()).thenReturn("mod2"); when(mod3.key()).thenReturn("mod3"); when(root.getKeyWithBranch()).thenReturn("root"); when(mod1.getKeyWithBranch()).thenReturn("mod1"); when(mod2.getKeyWithBranch()).thenReturn("mod2"); when(mod3.getKeyWithBranch()).thenReturn("mod3"); when(root.definition()).thenReturn(rootDef); when(mod1.definition()).thenReturn(def); when(mod2.definition()).thenReturn(def); when(mod3.definition()).thenReturn(def);
private void setFields(DefaultInputModule module, DefaultAnalysisMode mode, StatusDetection statusDetection) { setWorkDir(module.getWorkDir()); setEncoding(module.getEncoding()); // filter the files sensors have access to if (!mode.scanAllFiles()) { setDefaultPredicate(p -> new SameInputFilePredicate(p, statusDetection, module.definition().getKeyWithBranch())); } }
@Test public void should_save_project_measure() throws IOException { String projectKey = "myProject"; DefaultInputModule module = new DefaultInputModule(ProjectDefinition.create().setKey(projectKey).setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder())); ArgumentCaptor<DefaultMeasure> argumentCaptor = ArgumentCaptor.forClass(DefaultMeasure.class); when(measureCache.put(eq(module.key()), eq(CoreMetrics.NCLOC_KEY), argumentCaptor.capture())).thenReturn(null); underTest.store(new DefaultMeasure() .on(module) .forMetric(CoreMetrics.NCLOC) .withValue(10)); DefaultMeasure m = argumentCaptor.getValue(); assertThat(m.value()).isEqualTo(10); assertThat(m.metric()).isEqualTo(CoreMetrics.NCLOC); }
private void addCoreComponents() { add( module.definition(), module, MutableModuleSettings.class, new ModuleConfigurationProvider(), ModuleSensorsExecutor.class, // file system ModuleInputComponentStore.class, FileExclusions.class, DefaultModuleFileSystem.class, ModuleSensorOptimizer.class, ModuleSensorContext.class, ModuleSensorExtensionDictionnary.class, // Perspectives ScannerPerspectives.class); }
.setMediaType(MediaTypes.PROTOBUF) .setParam("organization", properties.organizationKey().orElse(null)) .setParam("projectKey", moduleHierarchy.root().key()) .setParam("projectName", moduleHierarchy.root().getOriginalName()) .setParam("projectBranch", moduleHierarchy.root().getBranch()) .setPart("report", filePart);
private void mkdirsAllWorkingDirs(DefaultInputModule module) { for (DefaultInputModule sub : moduleHierarchy.children(module)) { mkdirsAllWorkingDirs(sub); } try { Files.createDirectories(module.getWorkDir()); } catch (Exception e) { throw new IllegalStateException("Fail to create working dir: " + module.getWorkDir(), e); } }
@VisibleForTesting void logSuccess(@Nullable String taskId) { if (taskId == null) { LOG.info("ANALYSIS SUCCESSFUL"); } else { Map<String, String> metadata = new LinkedHashMap<>(); String effectiveKey = moduleHierarchy.root().getKeyWithBranch(); properties.organizationKey().ifPresent(org -> metadata.put("organization", org)); metadata.put("projectKey", effectiveKey); metadata.put("serverUrl", server.getPublicRootUrl()); metadata.put("serverVersion", server.getVersion()); properties.branch().ifPresent(branch -> metadata.put("branch", branch)); URL dashboardUrl = buildDashboardUrl(server.getPublicRootUrl(), effectiveKey); metadata.put("dashboardUrl", dashboardUrl.toExternalForm()); URL taskUrl = HttpUrl.parse(server.getPublicRootUrl()).newBuilder() .addPathSegment("api").addPathSegment("ce").addPathSegment("task") .addQueryParameter(ID, taskId) .build() .url(); metadata.put("ceTaskId", taskId); metadata.put("ceTaskUrl", taskUrl.toExternalForm()); LOG.info("ANALYSIS SUCCESSFUL, you can browse {}", dashboardUrl); LOG.info("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report"); LOG.info("More about the report processing at {}", taskUrl); dumpMetadata(metadata); } }
private void addModulesRelativePaths(ScannerReport.Metadata.Builder builder) { LinkedList<DefaultInputModule> queue = new LinkedList<>(); queue.add(moduleHierarchy.root()); while (!queue.isEmpty()) { DefaultInputModule module = queue.removeFirst(); queue.addAll(moduleHierarchy.children(module)); String relativePath = moduleHierarchy.relativePathToRoot(module); if (relativePath != null) { builder.putModulesProjectRelativePathByKey(module.key(), relativePath); } } }
private SensorContextTester(Path moduleBaseDir) { this.settings = new MapSettings(); this.fs = new DefaultFileSystem(moduleBaseDir).setEncoding(Charset.defaultCharset()); this.activeRules = new ActiveRulesBuilder().build(); this.sensorStorage = new InMemorySensorStorage(); this.project = new DefaultInputProject(ProjectDefinition.create().setKey("projectKey").setBaseDir(moduleBaseDir.toFile()).setWorkDir(moduleBaseDir.resolve(".sonar").toFile())); this.module = new DefaultInputModule(ProjectDefinition.create().setKey("projectKey").setBaseDir(moduleBaseDir.toFile()).setWorkDir(moduleBaseDir.resolve(".sonar").toFile())); this.runtime = SonarRuntimeImpl.forSonarQube(ApiVersion.load(System2.INSTANCE), SonarQubeSide.SCANNER); }
private static DefaultInputModule createModule(ProjectDefinition def, int scannerComponentId) { LOG.debug(" Init module '{}'", def.getName()); DefaultInputModule module = new DefaultInputModule(def, scannerComponentId); LOG.debug(" Base dir: {}", module.getBaseDir().toAbsolutePath().toString()); LOG.debug(" Working dir: {}", module.getWorkDir().toAbsolutePath().toString()); LOG.debug(" Module global encoding: {}, default locale: {}", module.getEncoding().displayName(), Locale.getDefault()); return module; }
return; if (!realAbsoluteFile.startsWith(module.getBaseDir())) { LOG.warn("File '{}' is ignored. It is not located in module basedir '{}'.", realAbsoluteFile.toAbsolutePath(), module.getBaseDir()); return; Path moduleRelativePath = module.getBaseDir().relativize(realAbsoluteFile); boolean included = evaluateInclusionsFilters(moduleExclusionFilters, realAbsoluteFile, projectRelativePath, moduleRelativePath, type); if (!included) { moduleRelativePath.toString(), type, language, scannerComponentIdGenerator.getAsInt(), sensorStrategy); DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> metadataGenerator.setMetadata(module.getKeyWithBranch(), f, module.getEncoding())); if (language != null) { inputFile.setPublished(true); componentStore.put(module.key(), inputFile); issueExclusionsLoader.addMulticriteriaPatterns(inputFile); LOG.debug("'{}' indexed {}with language '{}'", projectRelativePath, type == Type.TEST ? "as test " : "", inputFile.language());
public DefaultModuleFileSystem(ModuleInputComponentStore moduleInputFileCache, DefaultInputModule module, DefaultAnalysisMode mode, StatusDetection statusDetection) { super(module.getBaseDir(), moduleInputFileCache); setFields(module, mode, statusDetection); }