@Override public String projectKey() { return project.getEffectiveKey(); }
@Override public String projectKey() { return project.getEffectiveKey(); }
public void checkIfMigrationNeeded(Project rootProject) { ResourceModel model = session.getSingleResult(ResourceModel.class, "key", rootProject.getEffectiveKey()); if (model != null && StringUtils.isBlank(model.getDeprecatedKey())) { this.migrationNeeded = true; } }
public boolean isResourceInProject(Resource<?> resource, Project project) { final boolean result; if (resource instanceof Project) { result = resource.getEffectiveKey().equals(project.getEffectiveKey()); } else { Resource<?> parent = sensorContext.getParent(resource); if (parent == null) { // should not happen result = false; } else { result = isResourceInProject(parent, project); } } return result; }
String sonarProjectId = project.getEffectiveKey(); String path = fs.workDir().getAbsolutePath() + "/" + sonarProjectId.replace(':', '-') + ".pdf";
String parentOldKey; if ("java".equals(resourceModel.getLanguageKey())) { parentOldKey = String.format("%s:%s", module.getEffectiveKey(), DeprecatedKeyUtils.getJavaFileParentDeprecatedKey(oldKey)); } else { parentOldKey = String.format("%s:%s", module.getEffectiveKey(), oldParentKey(oldKey)); String parentNewKey = String.format("%s:%s", module.getEffectiveKey(), getParentKey(matchedFile)); if (!deprecatedDirectoryKeyMapper.containsKey(parentOldKey)) { deprecatedDirectoryKeyMapper.put(parentOldKey, parentNewKey);
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(); }
@VisibleForTesting void uploadMultiPartReport(File report) { LOG.debug("Publish results"); long startTime = System.currentTimeMillis(); URL url; try { url = new URL(serverClient.getURL() + "/api/computation/submit_report?projectKey=" + project.getEffectiveKey()); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid URL", e); } HttpRequest request = HttpRequest.post(url); request.trustAllCerts(); request.trustAllHosts(); request.header("User-Agent", String.format("SonarQube %s", server.getVersion())); request.basic(serverClient.getLogin(), serverClient.getPassword()); request.part("report", null, "application/octet-stream", report); if (!request.ok()) { int responseCode = request.code(); if (responseCode == 401) { throw new IllegalStateException(String.format(serverClient.getMessageWhenNotAuthorized(), CoreProperties.LOGIN, CoreProperties.PASSWORD)); } if (responseCode == 403) { // SONAR-4397 Details are in response content throw new IllegalStateException(request.body()); } throw new IllegalStateException(String.format("Fail to execute request [code=%s, url=%s]: %s", responseCode, url, request.body())); } long stopTime = System.currentTimeMillis(); LOG.info("Analysis reports sent to server in " + (stopTime - startTime) + "ms"); }
@Override public void executeOn(final Project project, final SensorContext context) { LOG.info("Executing decorator: PDF Report"); String sonarHostUrl = settings.hasKey(SONAR_HOST_URL) ? settings.getString(SONAR_HOST_URL) : SONAR_HOST_URL_DEFAULT_VALUE; String username = settings.hasKey(USERNAME) ? settings.getString(USERNAME) : USERNAME_DEFAULT_VALUE; String password = settings.hasKey(PASSWORD) ? settings.getString(PASSWORD) : PASSWORD_DEFAULT_VALUE; String reportType = settings.hasKey(REPORT_TYPE) ? settings.getString(REPORT_TYPE) : REPORT_TYPE_DEFAULT_VALUE; PDFGenerator generator = new PDFGenerator(project, fs, sonarHostUrl, username, password, reportType); generator.execute(); String path = fs.workDir().getAbsolutePath() + "/" + project.getEffectiveKey().replace(':', '-') + ".pdf"; File pdf = new File(path); if (pdf.exists()) { FileUploader.upload(pdf, sonarHostUrl + "/pdf_report/store", username, password); } else { LOG.error("PDF file not found in local filesystem. Report could not be sent to server."); } }
public DbDuplicationsIndex(Project currentProject, DuplicationDao dao, String language, DatabaseSession session, ResourceCache resourceCache) { this.dao = dao; this.session = session; this.resourceCache = resourceCache; Snapshot lastSnapshot = getLastSnapshot(currentProject.getId()); this.currentProjectSnapshotId = resourceCache.get(currentProject.getEffectiveKey()).snapshotId(); this.lastSnapshotId = lastSnapshot == null ? null : lastSnapshot.getId(); this.languageKey = language; }
public void deleteLink(Project project, String linkKey) { BatchResource batchResource = resourceCache.get(project.getEffectiveKey()); if (batchResource != null) { ResourceModel model = session.reattach(ResourceModel.class, batchResource.resource().getId()); ProjectLink dbLink = model.getProjectLink(linkKey); if (dbLink != null) { session.remove(dbLink); model.getProjectLinks().remove(dbLink); session.commit(); } } } }
void doStart(Project rootProject) { Bucket bucket = new Bucket(rootProject); addBucket(rootProject, bucket); BatchComponent component = componentCache.add(rootProject, null); component.setInputComponent(new DefaultInputModule(rootProject.getEffectiveKey())); currentProject = rootProject; for (Project module : rootProject.getModules()) { addModule(rootProject, module); } }
private void writeJsonModuleComponents(JsonWriter json, Project module) { json .beginObject() .prop("key", module.getEffectiveKey()) .prop("path", module.getPath()) .endObject(); for (Project subModule : module.getModules()) { writeJsonModuleComponents(json, subModule); } }
private static void writeJsonModuleComponents(JsonWriter json, Project module) { json .beginObject() .prop("key", module.getEffectiveKey()) .prop("path", module.getPath()) .endObject(); for (Project subModule : module.getModules()) { writeJsonModuleComponents(json, subModule); } }
public void saveLink(Project project, ProjectLink link) { BatchResource batchResource = resourceCache.get(project.getEffectiveKey()); ResourceModel projectDao = session.reattach(ResourceModel.class, batchResource.resource().getId()); ProjectLink dbLink = projectDao.getProjectLink(link.getKey()); if (dbLink == null) { link.setResource(projectDao); projectDao.getProjectLinks().add(link); session.save(link); } else { dbLink.copyFieldsFrom(link); session.save(dbLink); } session.commit(); }
if (ResourceUtils.isFile(resource)) { File sonarFile = (File) resource; InputFile file = inputPathCache.getFile(project.getEffectiveKey(), sonarFile.getPath()); if (file == null) { throw new IllegalStateException("File " + resource + " was not found in InputPath cache");
/** * Everything except project and library */ private Snapshot persistFileOrDirectory(Project project, Resource resource, @Nullable Resource parentReference) { BatchResource moduleResource = resourceCache.get(project.getEffectiveKey()); Integer moduleId = moduleResource.resource().getId(); ResourceModel model = findOrCreateModel(resource, parentReference != null ? parentReference : project); model.setRootId(moduleId); model = session.save(model); resource.setId(model.getId()); resource.setUuid(model.getUuid()); Snapshot parentSnapshot; if (parentReference != null) { parentSnapshot = resourceCache.get(parentReference.getEffectiveKey()).snapshot(); } else { parentSnapshot = moduleResource.snapshot(); } Snapshot snapshot = new Snapshot(model, parentSnapshot); snapshot.setBuildDateMs(System.currentTimeMillis()); snapshot = session.save(snapshot); session.commit(); return snapshot; }
public void saveDependency(Project project, Dependency dependency) { BatchResource fromResource = resourceCache.get(dependency.getFrom()); BatchResource toResource = resourceCache.get(dependency.getTo()); BatchResource projectResource = resourceCache.get(project); if (fromResource.isFile() && toResource.isFile()) { dependencyCache.put(project.getEffectiveKey(), new DefaultDependency().setFromKey(fromResource.key()).setToKey(toResource.key()).setWeight(dependency.getWeight())); } if (session != null) { saveInDB(project, dependency, fromResource, toResource, projectResource); } }
if (parent != null) { parentSnapshot = resourceCache.get(parent.getEffectiveKey()).snapshot(); model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId())); } else {
private DefaultIssue newIssue(Violation violation) { return new DefaultIssueBuilder() .componentKey(violation.getResource().getEffectiveKey()) // Project can be null but Violation not used by scan2 .projectKey(project.getRoot().getEffectiveKey()) .ruleKey(RuleKey.of(violation.getRule().getRepositoryKey(), violation.getRule().getKey())) .effortToFix(violation.getCost()) .line(violation.getLineId()) .message(violation.getMessage()) .severity(violation.getSeverity() != null ? violation.getSeverity().name() : null) .build(); }