コード例 #1
0
  /**
   * Processes the specified file. This is an extension point to allow updating a file external to
   * the reactor.
   *
   * @param outFile The file to process.
   * @throws MojoExecutionException If things go wrong.
   * @throws MojoFailureException If things go wrong.
   * @since 1.0-alpha-1
   */
  protected void process(File outFile) throws MojoExecutionException, MojoFailureException {
    try {
      StringBuilder input = PomHelper.readXmlFile(outFile);
      ModifiedPomXMLEventReader newPom = newModifiedPomXER(input);

      update(newPom);

      if (newPom.isModified()) {
        if (Boolean.FALSE.equals(generateBackupPoms)) {
          getLog().debug("Skipping generation of backup file");
        } else {
          File backupFile =
              new File(outFile.getParentFile(), outFile.getName() + ".versionsBackup");
          if (!backupFile.exists()) {
            getLog().debug("Backing up " + outFile + " to " + backupFile);
            FileUtils.copyFile(outFile, backupFile);
          } else {
            getLog().debug("Leaving existing backup " + backupFile + " unmodified");
          }
        }
        writeFile(outFile, input);
      }
    } catch (IOException e) {
      getLog().error(e);
    } catch (XMLStreamException e) {
      getLog().error(e);
    } catch (ArtifactMetadataRetrievalException e) {
      throw new MojoExecutionException(e.getMessage(), e);
    }
  }
コード例 #2
0
  private void useLatestSnapshots(ModifiedPomXMLEventReader pom, Collection dependencies)
      throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException {
    int segment =
        determineUnchangedSegment(allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates);

    Iterator i = dependencies.iterator();

    while (i.hasNext()) {
      Dependency dep = (Dependency) i.next();

      if (isExcludeReactor() && isProducedByReactor(dep)) {
        getLog().info("Ignoring reactor dependency: " + toString(dep));
        continue;
      }

      String version = dep.getVersion();
      Matcher versionMatcher = matchSnapshotRegex.matcher(version);
      if (!versionMatcher.matches()) {
        getLog().debug("Looking for latest snapshot of " + toString(dep));
        Artifact artifact = this.toArtifact(dep);
        if (!isIncluded(artifact)) {
          continue;
        }

        ArtifactVersions versions = getHelper().lookupArtifactVersions(artifact, false);
        final VersionComparator versionComparator = versions.getVersionComparator();
        final DefaultArtifactVersion lowerBound = new DefaultArtifactVersion(version);
        if (segment + 1 > versionComparator.getSegmentCount(lowerBound)) {
          getLog().info("Ignoring " + toString(dep) + " as the version number is too short");
          continue;
        }
        ArtifactVersion upperBound =
            segment >= 0 ? versionComparator.incrementSegment(lowerBound, segment) : null;
        getLog().info("Upper bound: " + (upperBound == null ? "none" : upperBound.toString()));
        ArtifactVersion[] newer = versions.getVersions(lowerBound, upperBound, true, false, false);
        getLog().debug("Candidate versions " + Arrays.asList(newer));
        String latestVersion = null;
        for (int j = 0; j < newer.length; j++) {
          String newVersion = newer[j].toString();
          if (matchSnapshotRegex.matcher(newVersion).matches()) {
            latestVersion = newVersion;
          }
        }
        if (latestVersion != null) {
          if (PomHelper.setDependencyVersion(
              pom, dep.getGroupId(), dep.getArtifactId(), version, latestVersion)) {
            getLog().info("Updated " + toString(dep) + " to version " + latestVersion);
          }
        }
      }
    }
  }
コード例 #3
0
  protected void updatePropertyToNewestVersion(
      ModifiedPomXMLEventReader pom,
      Property property,
      PropertyVersions version,
      String currentVersion)
      throws MojoExecutionException, XMLStreamException {
    ArtifactVersion winner =
        version.getNewestVersion(
            currentVersion, property, this.allowSnapshots, this.reactorProjects, this.getHelper());

    if (winner == null || currentVersion.equals(winner.toString())) {
      getLog()
          .info("Property ${" + property.getName() + "}: Leaving unchanged as " + currentVersion);
    } else if (PomHelper.setPropertyVersion(
        pom, version.getProfileId(), property.getName(), winner.toString())) {
      getLog()
          .info("Updated ${" + property.getName() + "} from " + currentVersion + " to " + winner);
    }
  }