Пример #1
0
  public void upgradeToCurrentVersion() {
    if (isInitialImport()) {
      initialImports.forEach(InitialImport::performInitialImport);
      versionProvider.writeLastVersion(getCurrentVersion());
    } else if (getLastVersion().get() < getCurrentVersion()) {
      List<VersionUpgrade> upgraders = new ArrayList<>(upgrades);
      Collections.sort(upgraders);

      upgraders
          .stream()
          .filter(upgrader -> upgrader.getVersion() > getLastVersion().get())
          .forEach(
              upgrader -> {
                log.info(
                    "Performing upgrade from version {} to {} using {}",
                    getLastVersion(),
                    upgrader.getVersion(),
                    upgrader.getClass().getSimpleName());
                upgrader.performUpgrade();
              });
      versionProvider.writeLastVersion(getCurrentVersion());
    } else {
      log.debug("no upgrade nessessary");
    }
  }
Пример #2
0
  public static void updateObjStoreByParsingContent(
      List<String> objStore,
      String objStoreContent,
      Collection<KRewriteObj> kObjs,
      ArrayList<SingleVariableDeclaration> formalParams) {
    if (objStoreContent == null || objStore == null) return;

    final String[] inputs = objStoreContent.split(",");
    for (int i = 0; i < inputs.length; i++) {
      String strI = inputs[i];
      final String[] elements = strI.split("=>");
      final String[] lhs = {elements[0]};
      final String[] rhs = {null};
      if (elements.length > 1) rhs[0] = elements[1];

      kObjs.forEach(
          kRewriteObj -> {
            lhs[0] = kRewriteObj.rewrite2KVarIfPossible(lhs[0], true);
          });

      if (formalParams != null && !formalParams.isEmpty()) {
        formalParams.forEach(
            var -> {
              lhs[0] =
                  lhs[0].replaceAll(
                      name2Regex(var.getName().getIdentifier()),
                      TypeMapping.convert2KVar(
                          var.getName().getIdentifier(), var.getType().isPrimitiveType()));
            });
      }

      if (rhs[0] != null) {
        kObjs.forEach(
            kRewriteObj -> {
              rhs[0] = kRewriteObj.rewrite2KVarIfPossible(rhs[0], false);
            });
      }

      String outputI = lhs[0];
      if (rhs[0] != null) {
        outputI += " => " + rhs[0];
      }

      objStore.add(outputI);
    }
  }
Пример #3
0
  @Override
  public OntrackSVNIssueInfo getIssueInfo(String configurationName, String issueKey) {
    // Repository
    SVNRepository repository = svnService.getRepository(configurationName);
    // Issue service
    ConfiguredIssueService configuredIssueService = repository.getConfiguredIssueService();
    if (configuredIssueService == null) {
      // No issue service configured
      return OntrackSVNIssueInfo.empty(repository.getConfiguration());
    }
    // Gets the details about the issue
    Issue issue = configuredIssueService.getIssue(issueKey);

    // For each configured branch
    Map<String, BranchRevision> branchRevisions = new HashMap<>();
    svnService.forEachConfiguredBranch(
        config -> Objects.equals(configurationName, config.getConfiguration().getName()),
        (branch, branchConfig) -> {
          String branchPath = branchConfig.getCuredBranchPath();
          // List of linked issues
          Collection<String> linkedIssues =
              configuredIssueService
                  .getLinkedIssues(branch.getProject(), issue)
                  .stream()
                  .map(Issue::getKey)
                  .collect(Collectors.toList());
          // Gets the last raw revision on this branch
          issueRevisionDao
              .findLastRevisionByIssuesAndBranch(repository.getId(), linkedIssues, branchPath)
              .ifPresent(
                  revision ->
                      branchRevisions.put(
                          branchPath, new BranchRevision(branchPath, revision, false)));
        });

    // Until all revisions are complete in respect of their merges...
    while (!BranchRevision.areComplete(branchRevisions.values())) {
      // Gets the incomplete revisions
      Collection<BranchRevision> incompleteRevisions =
          branchRevisions
              .values()
              .stream()
              .filter(br -> !br.isComplete())
              .collect(Collectors.toList());
      // For each of them, gets the list of revisions it was merged to
      incompleteRevisions.forEach(
          br -> {
            List<Long> merges =
                revisionDao.getMergesForRevision(repository.getId(), br.getRevision());
            // Marks the current revision as complete
            branchRevisions.put(br.getPath(), br.complete());
            // Gets the revision info for each merged revision
            List<TRevision> revisions =
                merges
                    .stream()
                    .map(r -> revisionDao.get(repository.getId(), r))
                    .collect(Collectors.toList());
            // For each revision path, compares with current stored revision
            revisions.forEach(
                t -> {
                  String branch = t.getBranch();
                  // Existing branch revision?
                  BranchRevision existingBranchRevision = branchRevisions.get(branch);
                  if (existingBranchRevision == null
                      || t.getRevision() > existingBranchRevision.getRevision()) {
                    branchRevisions.put(branch, new BranchRevision(branch, t.getRevision(), true));
                  }
                });
          });
    }

    // We now have the last revision for this issue on each branch...
    List<OntrackSVNIssueRevisionInfo> issueRevisionInfos = new ArrayList<>();
    branchRevisions
        .values()
        .forEach(
            br -> {
              // Loads the revision info
              SVNRevisionInfo basicInfo = svnService.getRevisionInfo(repository, br.getRevision());
              SVNChangeLogRevision changeLogRevision =
                  svnService.createChangeLogRevision(repository, basicInfo);
              // Info to collect
              OntrackSVNIssueRevisionInfo issueRevisionInfo =
                  OntrackSVNIssueRevisionInfo.of(changeLogRevision);
              // Gets the branch from the branch path
              AtomicReference<Branch> rBranch = new AtomicReference<>();
              svnService.forEachConfiguredBranch(
                  config -> Objects.equals(configurationName, config.getConfiguration().getName()),
                  (candidate, branchConfig) -> {
                    String branchPath = branchConfig.getCuredBranchPath();
                    if (Objects.equals(br.getPath(), branchPath)) {
                      rBranch.set(candidate);
                    }
                  });
              Branch branch = rBranch.get();
              if (branch != null) {
                // Collects branch info
                SCMIssueCommitBranchInfo branchInfo = SCMIssueCommitBranchInfo.of(branch);
                // Gets the first copy event on this path after this revision
                SVNLocation firstCopy =
                    svnService.getFirstCopyAfter(repository, basicInfo.toLocation());
                // Identifies a possible build given the path/revision and the first copy
                Optional<Build> buildAfterCommit =
                    lookupBuild(basicInfo.toLocation(), firstCopy, branch);
                if (buildAfterCommit.isPresent()) {
                  Build build = buildAfterCommit.get();
                  // Gets the build view
                  BuildView buildView = structureService.getBuildView(build);
                  // Adds it to the list
                  branchInfo = branchInfo.withBuildView(buildView);
                  // Collects the promotions for the branch
                  branchInfo =
                      branchInfo.withBranchStatusView(
                          structureService.getEarliestPromotionsAfterBuild(build));
                }
                // OK
                issueRevisionInfo.add(branchInfo);
              }
              // OK
              issueRevisionInfos.add(issueRevisionInfo);
            });

    // Gets the list of revisions & their basic info (order from latest to oldest)
    List<SVNChangeLogRevision> revisions =
        svnService
            .getRevisionsForIssueKey(repository, issueKey)
            .stream()
            .map(
                revision ->
                    svnService.createChangeLogRevision(
                        repository, svnService.getRevisionInfo(repository, revision)))
            .collect(Collectors.toList());

    // OK
    return new OntrackSVNIssueInfo(
        repository.getConfiguration(),
        repository.getConfiguredIssueService().getIssueServiceConfigurationRepresentation(),
        issue,
        issueRevisionInfos,
        revisions);
  }
  /**
   * A helper to add an entire subtree to a given dependency tree.
   *
   * @param toModify The tree to add the subtree to.
   * @param root The root of the tree where we should be adding the subtree.
   * @param rel The relation to add the subtree with.
   * @param originalTree The orignal tree (i.e., {@link ClauseSplitterSearchProblem#tree}).
   * @param subject The root of the clause to add.
   * @param ignoredEdges The edges to ignore adding when adding this subtree.
   */
  private static void addSubtree(
      SemanticGraph toModify,
      IndexedWord root,
      String rel,
      SemanticGraph originalTree,
      IndexedWord subject,
      Collection<SemanticGraphEdge> ignoredEdges) {
    if (toModify.containsVertex(subject)) {
      return; // This subtree already exists.
    }
    Queue<IndexedWord> fringe = new LinkedList<>();
    Collection<IndexedWord> wordsToAdd = new ArrayList<>();
    Collection<SemanticGraphEdge> edgesToAdd = new ArrayList<>();
    // Search for subtree to add
    for (SemanticGraphEdge edge : originalTree.outgoingEdgeIterable(subject)) {
      if (!ignoredEdges.contains(edge)) {
        if (toModify.containsVertex(edge.getDependent())) {
          // Case: we're adding a subtree that's not disjoint from toModify. This is bad news.
          return;
        }
        edgesToAdd.add(edge);
        fringe.add(edge.getDependent());
      }
    }
    while (!fringe.isEmpty()) {
      IndexedWord node = fringe.poll();
      wordsToAdd.add(node);
      for (SemanticGraphEdge edge : originalTree.outgoingEdgeIterable(node)) {
        if (!ignoredEdges.contains(edge)) {
          if (toModify.containsVertex(edge.getDependent())) {
            // Case: we're adding a subtree that's not disjoint from toModify. This is bad news.
            return;
          }
          edgesToAdd.add(edge);
          fringe.add(edge.getDependent());
        }
      }
    }
    // Add subtree
    // (add subject)
    toModify.addVertex(subject);
    toModify.addEdge(
        root,
        subject,
        GrammaticalRelation.valueOf(Language.English, rel),
        Double.NEGATIVE_INFINITY,
        false);

    // (add nodes)
    wordsToAdd.forEach(toModify::addVertex);
    // (add edges)
    for (SemanticGraphEdge edge : edgesToAdd) {
      assert !toModify.incomingEdgeIterator(edge.getDependent()).hasNext();
      toModify.addEdge(
          edge.getGovernor(),
          edge.getDependent(),
          edge.getRelation(),
          edge.getWeight(),
          edge.isExtra());
    }
  }