@Override public String key() { return getKey(); }
private String getSemaphoreKey() { return "batch-" + getProject().getKey(); }
@Override public String toString() { return new ToStringBuilder(this) .append("id", getId()) .append("key", getKey()) .append("qualifier", getQualifier()) .toString(); }
public void start() { Project rootProject = projectTree.getRootProject(); if (StringUtils.isNotBlank(rootProject.getKey())) { doStart(rootProject); } }
public Project(String key, String branch, String name) { if (StringUtils.isNotBlank(branch)) { setKey(String.format(BRANCH_KEY_FORMAT, key, branch)); this.name = String.format("%s %s", name, branch); } else { setKey(key); this.name = name; } setEffectiveKey(getKey()); this.branch = branch; }
public void start() { Project rootProject = projectTree.getRootProject(); if (StringUtils.isNotBlank(rootProject.getKey())) { doStart(rootProject); } }
@VisibleForTesting void logSuccess(Logger logger) { if (analysisMode.isPreview() || analysisMode.isMediumTest()) { logger.info("ANALYSIS SUCCESSFUL"); } else { String baseUrl = settings.getString(CoreProperties.SERVER_BASE_URL); if (baseUrl.equals(settings.getDefaultValue(CoreProperties.SERVER_BASE_URL))) { // If server base URL was not configured in Sonar server then is is better to take URL configured on batch side baseUrl = serverClient.getURL(); } if (!baseUrl.endsWith("/")) { baseUrl += "/"; } String url = baseUrl + "dashboard/index/" + project.getKey(); logger.info("ANALYSIS SUCCESSFUL, you can browse {}", url); logger.info("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report."); } } }
/** * Generate a resource key for the provided file path. * * Using a plugin with some version and Sonar with another version will * result in a null key provided by a {@link File} instance. So we generate * it using the current project key and the relative path to the project. * * @param project * the project that contains the file * @param path * the absolute path to the file * @param possibleParents * a list of directories to search file into ordered by priority * @return the resource key usable by Sonar * @throws KeyException * when the key couldn't be generated */ public static String getKey(Project project, String path, List<java.io.File> possibleParents) throws KeyException { try { return project.getKey() + ":" + FileUtil.getRelativePath(path, possibleParents); } catch(IOException e) { throw new KeyException("failed to generate key for file "+path, e); } }
public void start() { if (!analysisMode.isPreview() && StringUtils.isNotBlank(getProject().getKey())) { Semaphores.Semaphore semaphore = acquire(); if (!semaphore.isLocked()) { LOG.error(getErrorMessage(semaphore)); throw new SonarException("The project is already being analysed."); } } }
void migrateIfNeeded(Project module, Iterable<InputFile> inputFiles, DefaultModuleFileSystem fs) { logger.info("Update component keys"); Map<String, InputFile> deprecatedFileKeyMapper = new HashMap<String, InputFile>(); Map<String, InputFile> deprecatedTestKeyMapper = new HashMap<String, InputFile>(); Map<String, String> deprecatedDirectoryKeyMapper = new HashMap<String, String>(); for (InputFile inputFile : inputFiles) { String deprecatedKey = computeDeprecatedKey(module.getKey(), (DeprecatedDefaultInputFile) inputFile, fs); if (deprecatedKey != null) { if (InputFile.Type.TEST == inputFile.type() && !deprecatedTestKeyMapper.containsKey(deprecatedKey)) { deprecatedTestKeyMapper.put(deprecatedKey, inputFile); } else if (InputFile.Type.MAIN == inputFile.type() && !deprecatedFileKeyMapper.containsKey(deprecatedKey)) { deprecatedFileKeyMapper.put(deprecatedKey, inputFile); } } } ResourceModel moduleModel = session.getSingleResult(ResourceModel.class, "key", module.getEffectiveKey()); int moduleId = moduleModel.getId(); migrateFiles(module, deprecatedFileKeyMapper, deprecatedTestKeyMapper, deprecatedDirectoryKeyMapper, moduleId); migrateDirectories(deprecatedDirectoryKeyMapper, moduleId); session.commit(); }
@Override public IssueBuilder newIssueBuilder() { return new DefaultIssueBuilder().componentKey(component.key()).projectKey(project.getKey()); }
@VisibleForTesting public DefaultModuleFileSystem(Project project, Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer) { super(initializer.baseDir().toPath()); this.componentIndexer = componentIndexer; this.moduleKey = project.getKey(); this.settings = settings; this.indexer = indexer; setWorkDir(initializer.workingDir()); this.buildDir = initializer.buildDir(); this.sourceDirsOrFiles = initializer.sources(); this.testDirsOrFiles = initializer.tests(); this.binaryDirs = initializer.binaryDirs(); }
@Override public void decorate(Resource resource, DecoratorContext context) { double uselessDuplicatedLines = 0; Measure measure = context.getMeasure(CoreMetrics.DUPLICATIONS_DATA); if (MeasureUtils.hasData(measure)) { String resourceKey = new StringBuilder(ResourceModel.KEY_SIZE) .append(context.getProject().getKey()) .append(':') .append(context.getResource().getKey()) .toString(); List<List<Block>> groups = parseDuplicationData(measure.getData()); uselessDuplicatedLines = analyse(groups, resourceKey); } uselessDuplicatedLines += MeasureUtils.sum(true, context.getChildrenMeasures(TrackerMetrics.USELESS_DUPLICATED_LINES)); if (uselessDuplicatedLines > 0) { context.saveMeasure(TrackerMetrics.USELESS_DUPLICATED_LINES, uselessDuplicatedLines); } }
private Snapshot buildProjectSnapshot() { Query query = session .createNativeQuery("select p.id from projects p where p.kee=:resourceKey and p.qualifier<>:lib and p.enabled=:enabled"); query.setParameter("resourceKey", projectTree.getRootProject().getKey()); query.setParameter("lib", Qualifiers.LIBRARY); query.setParameter("enabled", Boolean.TRUE); Snapshot snapshot = null; Number projectId = session.getSingleResult(query, null); if (projectId != null) { snapshot = new Snapshot(); snapshot.setResourceId(projectId.intValue()); snapshot.setCreatedAtMs(dateToLong(projectTree.getRootProject().getAnalysisDate())); snapshot.setBuildDateMs(System.currentTimeMillis()); snapshot.setVersion(projectTree.getRootProject().getAnalysisVersion()); } return snapshot; }
public ProjectConfigurator configure(Project project) { Date analysisDate = loadAnalysisDate(); checkCurrentAnalysisIsTheLatestOne(project.getKey(), analysisDate); project .setAnalysisDate(analysisDate) .setAnalysisVersion(loadAnalysisVersion()) .setAnalysisType(loadAnalysisType()); return this; }
public DefaultModuleFileSystem(ModuleInputFileCache moduleInputFileCache, Project project, Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer) { super(initializer.baseDir(), moduleInputFileCache); this.componentIndexer = componentIndexer; this.moduleKey = project.getKey(); this.settings = settings; this.indexer = indexer; setWorkDir(initializer.workingDir()); this.buildDir = initializer.buildDir(); this.sourceDirsOrFiles = initializer.sources(); this.testDirsOrFiles = initializer.tests(); this.binaryDirs = initializer.binaryDirs(); }
@Override public void store(Issue issue) { Resource r; InputPath inputPath = issue.inputPath(); if (inputPath != null) { if (inputPath instanceof InputDir) { r = Directory.create(inputPath.relativePath()); } else { r = File.create(inputPath.relativePath()); } } else { r = project; } Issuable issuable = perspectives.as(Issuable.class, r); if (issuable == null) { return; } issuable.addIssue(toDefaultIssue(project.getKey(), ComponentKeys.createEffectiveKey(project, r), issue)); }
private void setFields(Project project, Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer, DefaultAnalysisMode mode) { this.componentIndexer = componentIndexer; this.moduleKey = project.getKey(); this.settings = settings; this.indexer = indexer; setWorkDir(initializer.workingDir()); this.buildDir = initializer.buildDir(); this.sourceDirsOrFiles = initializer.sources(); this.testDirsOrFiles = initializer.tests(); this.binaryDirs = initializer.binaryDirs(); // filter the files sensors have access to if (!mode.scanAllFiles()) { setDefaultPredicate(predicates.not(predicates.hasStatus(Status.SAME))); } }
@Override public void onProjectAnalysis(ProjectAnalysisEvent event) { Project module = event.getProject(); if (event.isStart()) { decoratorsProfiler = new DecoratorsProfiler(); currentModuleProfiling = new ModuleProfiling(module, system); } else { currentModuleProfiling.stop(); modulesProfilings.put(module, currentModuleProfiling); long moduleTotalTime = currentModuleProfiling.totalTime(); println(""); println(" -------- Profiling of module " + module.getName() + ": " + TimeUtils.formatDuration(moduleTotalTime) + " --------"); println(""); Properties props = new Properties(); currentModuleProfiling.dump(props); println(""); println(" -------- End of profiling of module " + module.getName() + " --------"); println(""); String fileName = module.getKey() + "-profiler.properties"; dumpToFile(props, BatchUtils.cleanKeyForFilename(fileName)); totalProfiling.merge(currentModuleProfiling); if (module.isRoot() && !module.getModules().isEmpty()) { dumpTotalExecutionSummary(); } } }