Skip to content

Commit

Permalink
Merge pull request #44 from alpo/unicode-poms
Browse files Browse the repository at this point in the history
encode/decode UTF-8 in POMs
  • Loading branch information
baztian committed Mar 20, 2017
2 parents be3fa74 + abc7dc2 commit 67cb2f5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions jip/cache.py
Expand Up @@ -19,6 +19,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
import codecs

from jip.repository import MavenRepos
from jip.util import get_virtual_home
Expand Down Expand Up @@ -54,7 +55,7 @@ def download_jar(self, artifact, local_path=None):
def download_pom(self, artifact):
path = self.get_artifact_uri(artifact, 'pom')
if os.path.exists(path):
f = open(path, 'r')
f = codecs.open(path, mode='r', encoding='utf-8')
data = f.read()
f.close()
return data
Expand All @@ -63,7 +64,7 @@ def download_pom(self, artifact):

def put_pom(self, artifact, data):
path = self.get_artifact_uri(artifact, 'pom')
f = open(path, 'w')
f = codecs.open(path, mode='w', encoding='utf-8')
f.write(data)
f.close()

Expand Down
2 changes: 1 addition & 1 deletion jip/maven.py
Expand Up @@ -110,7 +110,7 @@ def get_element_tree(self):
## we use this dirty method to remove namesapce attribute so that elementtree will use default empty namespace
pom_string = re.sub(r"<project(.|\s)*?>", '<project>', self.pom_string, 1)
parser = ElementTree.XMLParser(target=WhitespaceNormalizer())
parser.feed(pom_string)
parser.feed(pom_string.encode('utf-8'))
self.eletree = parser.close()
return self.eletree

Expand Down
5 changes: 5 additions & 0 deletions test/install_test.py
Expand Up @@ -18,6 +18,11 @@ def testResolve(self):
artifacts = _resolve_artifacts([junit])
self.assertEqual(len(artifacts), 1)

def testResolveArtifactWithUmlautsInPom(self):
artifact = Artifact('de.l3s.boilerpipe', 'boilerpipe', '1.1.0')
artifacts = _resolve_artifacts([artifact])
self.assertEqual(len(artifacts), 1)

def testExclusion(self):
pig = Artifact('org.apache.pig', 'pig', '0.8.3')
exclusion = [Artifact(*x.split(":")) for x in ['ant:ant', 'junit:junit','org.eclipse.jdt:core']]
Expand Down

0 comments on commit 67cb2f5

Please sign in to comment.