Ejemplo n.º 1
0
def update_backcompat_tests(types, index_version, current_version):
    print('  adding new indexes to backcompat tests...', end='', flush=True)
    module = 'lucene/backward-codecs'
    filename = '%s/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java' % module
    matcher = re.compile(r'final static String\[\] oldNames = {|};'
                         if current_version.is_back_compat_with(index_version)
                         else r'final String\[\] unsupportedNames = {|};')

    def find_version(x):
        x = x.strip()
        end = x.index("-")
        return scriptutil.Version.parse(x[1:end])

    class Edit(object):
        start = None

        def __call__(self, buffer, match, line):
            if self.start:
                # find where this version should exist
                i = len(buffer) - 1
                v = find_version(buffer[i])
                while i >= self.start and v.on_or_after(index_version):
                    i -= 1
                    v = find_version(buffer[i])
                i += 1  # readjust since we skipped past by 1

                # unfortunately python doesn't have a range remove from list...
                # here we want to remove any previous references to the version we are adding
                while i < len(buffer) and index_version.on_or_after(
                        find_version(buffer[i])):
                    buffer.pop(i)

                if i == len(buffer) and not buffer[-1].strip().endswith(","):
                    # add comma
                    buffer[-1] = buffer[-1].rstrip() + ",\n"

                last = buffer[-1]
                spaces = ' ' * (len(last) - len(last.lstrip()))
                for (j, t) in enumerate(types):
                    newline = spaces + ('"%s-%s"' % (index_version, t))
                    if j < len(types) - 1 or i < len(buffer):
                        newline += ','
                    buffer.insert(i, newline + '\n')
                    i += 1

                buffer.append(line)
                return True

            if 'Names = {' in line:
                self.start = len(buffer)  # location of first index name
            buffer.append(line)
            return False

    changed = scriptutil.update_file(filename, matcher, Edit())
    print('done' if changed else 'uptodate')
Ejemplo n.º 2
0
def update_build_version(new_version):
  print('  changing version.base...', end='', flush=True)
  filename = 'lucene/version.properties'
  def edit(buffer, match, line):
    if new_version.dot in line:
      return None
    buffer.append('version.base=' + new_version.dot + '\n')
    return True 

  changed = scriptutil.update_file(filename, version_prop_re, edit)
  print('done' if changed else 'uptodate')
Ejemplo n.º 3
0
def add_constant(new_version, deprecate):
  filename = 'lucene/core/src/java/org/apache/lucene/util/Version.java'
  print('  adding constant %s...' % new_version.constant, end='', flush=True)
  constant_prefix = 'public static final Version LUCENE_'
  matcher = re.compile(constant_prefix)
  prev_matcher = new_version.make_previous_matcher(prefix=constant_prefix, sep='_')

  def ensure_deprecated(buffer):
    last = buffer[-1]
    if last.strip() != '@Deprecated':
      spaces = ' ' * (len(last) - len(last.lstrip()) - 1)
      buffer[-1] = spaces + (' * @deprecated (%s) Use latest\n' % new_version)
      buffer.append(spaces + ' */\n')
      buffer.append(spaces + '@Deprecated\n')

  def buffer_constant(buffer, line):
    spaces = ' ' * (len(line) - len(line.lstrip()))
    buffer.append('\n' + spaces + '/**\n')
    buffer.append(spaces + ' * Match settings and bugs in Lucene\'s %s release.\n' % new_version)
    if deprecate:
      buffer.append(spaces + ' * @deprecated Use latest\n')
    buffer.append(spaces + ' */\n')
    if deprecate:
      buffer.append(spaces + '@Deprecated\n')
    buffer.append(spaces + 'public static final Version %s = new Version(%d, %d, %d);\n' %
                  (new_version.constant, new_version.major, new_version.minor, new_version.bugfix))
  
  class Edit(object):
    found = -1
    def __call__(self, buffer, match, line):
      if new_version.constant in line:
        return None # constant already exists
      # outter match is just to find lines declaring version constants
      match = prev_matcher.search(line)
      if match is not None:
        ensure_deprecated(buffer) # old version should be deprecated
        self.found = len(buffer) + 1 # extra 1 for buffering current line below
      elif self.found != -1:
        # we didn't match, but we previously had a match, so insert new version here
        # first find where to insert (first empty line before current constant)
        c = []
        buffer_constant(c, line)
        tmp = buffer[self.found:]
        buffer[self.found:] = c
        buffer.extend(tmp)
        buffer.append(line)
        return True

      buffer.append(line)
      return False
  
  changed = scriptutil.update_file(filename, matcher, Edit())
  print('done' if changed else 'uptodate')
Ejemplo n.º 4
0
def update_latest_constant(new_version):
  print('  changing Version.LATEST to %s...' % new_version.constant, end='', flush=True)
  filename = 'lucene/core/src/java/org/apache/lucene/util/Version.java'
  matcher = re.compile('public static final Version LATEST')
  def edit(buffer, match, line):
    if new_version.constant in line:
      return None
    buffer.append(line.rpartition('=')[0] + ('= %s;\n' % new_version.constant))
    return True

  changed = scriptutil.update_file(filename, matcher, edit)
  print('done' if changed else 'uptodate')
def update_backcompat_tests(types, index_version, current_version):
  print('  adding new indexes to backcompat tests...', end='', flush=True)
  module = 'lucene/backward-codecs'
  filename = '%s/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java' % module
  matcher = re.compile(r'final static String\[\] oldNames = {|};' if current_version.is_back_compat_with(index_version)
                       else r'final String\[\] unsupportedNames = {|};')

  def find_version(x):
    x = x.strip()
    end = x.index("-")
    return scriptutil.Version.parse(x[1:end])

  class Edit(object):
    start = None
    def __call__(self, buffer, match, line):
      if self.start:
        # find where this version should exist
        i = len(buffer) - 1 
        v = find_version(buffer[i])
        while i >= self.start and v.on_or_after(index_version):
          i -= 1
          v = find_version(buffer[i])
        i += 1 # readjust since we skipped past by 1

        # unfortunately python doesn't have a range remove from list...
        # here we want to remove any previous references to the version we are adding
        while i < len(buffer) and index_version.on_or_after(find_version(buffer[i])):
          buffer.pop(i)

        if i == len(buffer) and not buffer[-1].strip().endswith(","):
          # add comma
          buffer[-1] = buffer[-1].rstrip() + ",\n" 

        last = buffer[-1]
        spaces = ' ' * (len(last) - len(last.lstrip()))
        for (j, t) in enumerate(types):
          newline = spaces + ('"%s-%s"' % (index_version, t))
          if j < len(types) - 1 or i < len(buffer):
            newline += ','
          buffer.insert(i, newline + '\n')
          i += 1

        buffer.append(line)
        return True

      if 'Names = {' in line:
        self.start = len(buffer) # location of first index name
      buffer.append(line)
      return False
        
  changed = scriptutil.update_file(filename, matcher, Edit())
  print('done' if changed else 'uptodate')
Ejemplo n.º 6
0
def update_solrconfig(filename, matcher, new_version):
  print('    %s...' % filename, end='', flush=True)
  def edit(buffer, match, line):
    if new_version.dot in line:
      return None
    match = new_version.previous_dot_matcher.search(line)
    if match is None:
      return False
    buffer.append(line.replace(match.group(1), new_version.dot))
    return True

  changed = scriptutil.update_file(filename, matcher, edit)
  print('done' if changed else 'uptodate')
Ejemplo n.º 7
0
def update_changes(filename, new_version):
  print('  adding new section to %s...' % filename, end='', flush=True)
  matcher = re.compile(r'\d+\.\d+\.\d+\s+===')
  def edit(buffer, match, line):
    if new_version.dot in line:
      return None
    match = new_version.previous_dot_matcher.search(line)
    if match is not None:
      buffer.append(line.replace(match.group(0), new_version.dot))
      buffer.append('(No Changes)\n\n')
    buffer.append(line)
    return match is not None
     
  changed = scriptutil.update_file(filename, matcher, edit)
  print('done' if changed else 'uptodate')