org.sonar.api.resources.Project.getEffectiveKey()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中org.sonar.api.resources.Project.getEffectiveKey()方法的一些代码示例,展示了Project.getEffectiveKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Project.getEffectiveKey()方法的具体详情如下:
包路径:org.sonar.api.resources.Project
类名称:Project
方法名:getEffectiveKey

Project.getEffectiveKey介绍

暂无

代码示例

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

@Override
public String projectKey() {
 return project.getEffectiveKey();
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

@Override
public String projectKey() {
 return project.getEffectiveKey();
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

public void checkIfMigrationNeeded(Project rootProject) {
 ResourceModel model = session.getSingleResult(ResourceModel.class, "key", rootProject.getEffectiveKey());
 if (model != null && StringUtils.isBlank(model.getDeprecatedKey())) {
  this.migrationNeeded = true;
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.dotnet/sonar-dotnet-plugin

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;
}

代码示例来源:origin: SonarQubeCommunity/sonar-pdf-report

String sonarProjectId = project.getEffectiveKey();
String path = fs.workDir().getAbsolutePath() + "/" + sonarProjectId.replace(':', '-') + ".pdf";

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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);

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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();
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

@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");
}

代码示例来源:origin: SonarQubeCommunity/sonar-pdf-report

@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.");
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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;
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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();
   }

  }
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

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);
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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);
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

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);
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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();
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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");

代码示例来源:origin: org.codehaus.sonar/sonar-batch

/**
 * 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;
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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);
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

if (parent != null) {
 parentSnapshot = resourceCache.get(parent.getEffectiveKey()).snapshot();
 model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId()));
} else {

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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();
}

相关文章