Заголовок HTTP-запроса: переменная UserAgent

Этот небольшой скрипт python «исправляет» созданные M2E файлы .classpath и добавляет требуемый тег XML во все исходные папки, начиная с target/generated-sources. Вы можете просто запустить его из корневой папки проекта. Очевидно, вам нужно повторно запустить его, когда информация о проекте Eclipse будет повторно сгенерирована из M2E. И все на свой страх и риск, очевидно; -)

#!/usr/bin/env python
from xml.dom.minidom import parse
import glob
import os

print('Reading .classpath files...')
for root, dirs, files in os.walk('.'):
    for name in files:
        if (name == '.classpath'):
            classpathFile = os.path.join(root, name)
            print('Patching file:' + classpathFile)
            classpathDOM = parse(classpathFile)
            classPathEntries = classpathDOM.getElementsByTagName('classpathentry')
            for classPathEntry in classPathEntries:
                if classPathEntry.attributes["path"].value.startswith('target/generated-sources'):
                    # ensure that the <attributes> tag exists
                    attributesNode = None;
                    for attributes in classPathEntry.childNodes:
                            if (attributes.nodeName == 'attributes'):
                                attributesNode = attributes

                    if (attributesNode == None):
                        attributesNode = classpathDOM.createElement('attributes')
                        classPathEntry.appendChild(attributesNode)

                    # search if the 'ignore_optional_problems' entry exists
                    hasBeenSet = 0
                    for node in attributesNode.childNodes:
                        if (node.nodeName == 'attribute' and node.getAttribute('name') == 'ignore_optional_problems'):
                            # it exists, make sure its value is true
                            node.setAttribute('value','true')
                            #print(node.getAttribute('name'))
                            hasBeenSet = 1

                    if (not(hasBeenSet)):
                        # it does not exist, add it
                        x = classpathDOM.createElement("attribute")
                        x.setAttribute('name','ignore_optional_problems')
                        x.setAttribute('value','true')
                        attributesNode.appendChild(x)

            try:
                f = open(classpathFile, "w") 
                classpathDOM.writexml(f)
                print('Writing file:' + classpathFile)
            finally:
                f.close()
print('Done.')
23
задан PoeHaH 25 February 2013 в 14:41
поделиться