Fix multibyte character problem

Fixed problem that causes a UnicodeEncodeError when use multi-byte characters in the job.yml.

Change-Id: Ie715c827a794e73fae11cdca079ea80cfb8c280d
This commit is contained in:
Kei YAMAZAKI 2013-12-29 01:45:38 +09:00
parent 777a29aa8a
commit 604d39305b
42 changed files with 61 additions and 40 deletions

View File

@ -381,7 +381,7 @@ class XmlJob(object):
def output(self): def output(self):
out = minidom.parseString(XML.tostring(self.xml)) out = minidom.parseString(XML.tostring(self.xml))
out = out.toprettyxml(indent=' ') out = out.toprettyxml(indent=' ', encoding='utf-8')
return self.pretty_text_re.sub('>\g<1></', out) return self.pretty_text_re.sub('>\g<1></', out)

View File

@ -17,6 +17,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import codecs
import os import os
import re import re
import doctest import doctest
@ -61,7 +62,7 @@ class BaseTestCase(object):
def __read_content(self): def __read_content(self):
# Read XML content, assuming it is unicode encoded # Read XML content, assuming it is unicode encoded
xml_filepath = os.path.join(self.fixtures_path, self.xml_filename) xml_filepath = os.path.join(self.fixtures_path, self.xml_filename)
xml_content = u"%s" % open(xml_filepath, 'r').read() xml_content = u"%s" % codecs.open(xml_filepath, 'r', 'utf-8').read()
yaml_filepath = os.path.join(self.fixtures_path, self.yaml_filename) yaml_filepath = os.path.join(self.fixtures_path, self.yaml_filename)
with file(yaml_filepath, 'r') as yaml_file: with file(yaml_filepath, 'r') as yaml_file:
@ -83,7 +84,8 @@ class BaseTestCase(object):
pub.gen_xml(parser, xml_project, yaml_content) pub.gen_xml(parser, xml_project, yaml_content)
# Prettify generated XML # Prettify generated XML
pretty_xml = XmlJob(xml_project, 'fixturejob').output() pretty_xml = unicode(XmlJob(xml_project, 'fixturejob').output(),
'utf-8')
self.assertThat( self.assertThat(
pretty_xml, pretty_xml,

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<builders> <builders>
<hudson.tasks.Maven> <hudson.tasks.Maven>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<builders> <builders>
<hudson.tasks.Maven> <hudson.tasks.Maven>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<builders> <builders>
<hudson.plugins.parameterizedtrigger.TriggerBuilder> <hudson.plugins.parameterizedtrigger.TriggerBuilder>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<actions/> <actions/>
<keepDependencies>false</keepDependencies> <keepDependencies>false</keepDependencies>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<actions/> <actions/>
<keepDependencies>false</keepDependencies> <keepDependencies>false</keepDependencies>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<properties> <properties>
<com.tikal.hudson.plugins.notification.HudsonNotificationProperty> <com.tikal.hudson.plugins.notification.HudsonNotificationProperty>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<properties> <properties>
<hudson.model.ParametersDefinitionProperty> <hudson.model.ParametersDefinitionProperty>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<properties> <properties>
<hudson.plugins.batch__task.BatchTaskProperty> <hudson.plugins.batch__task.BatchTaskProperty>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<properties> <properties>
<hudson.plugins.throttleconcurrents.ThrottleJobProperty> <hudson.plugins.throttleconcurrents.ThrottleJobProperty>

View File

@ -10,5 +10,5 @@ Each yaml file MUST have a corresponding xml file.
Once the YAML file has been parsed, it is prettify using python minidom Once the YAML file has been parsed, it is prettify using python minidom
which also means that: which also means that:
- your XML file must start with: <?xml version="1.0" ?> - your XML file must start with: <?xml version="1.0" encoding="utf-8"?>
- self closing elements do not contains space eg: <element/> - self closing elements do not contains space eg: <element/>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<hudson.tasks.ArtifactArchiver> <hudson.tasks.ArtifactArchiver>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<hudson.plugins.blame__upstream__commiters.BlameUpstreamCommitersPublisher/> <hudson.plugins.blame__upstream__commiters.BlameUpstreamCommitersPublisher/>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<hudson.plugins.build__publisher.BuildPublisher> <hudson.plugins.build__publisher.BuildPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<org.jenkinsci.plugins.cloverphp.CloverPHPPublisher> <org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<org.jenkinsci.plugins.cloverphp.CloverPHPPublisher> <org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<org.jenkinsci.plugins.cloverphp.CloverPHPPublisher> <org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<hudson.plugins.descriptionsetter.DescriptionSetterPublisher> <hudson.plugins.descriptionsetter.DescriptionSetterPublisher>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.descriptionsetter.DescriptionSetterPublisher>
<regexp>.*(&lt;a href=.*a&gt;)</regexp>
<regexpForFailed>.*(&lt;a href=.*a&gt;)</regexpForFailed>
<description>こんにちは</description>
<descriptionForFailed>さようなら</descriptionForFailed>
<setForMatrix>true</setForMatrix>
</hudson.plugins.descriptionsetter.DescriptionSetterPublisher>
</publishers>
</project>

View File

@ -0,0 +1,7 @@
publishers:
- description-setter:
regexp: ".*(<a href=.*a>)"
regexp-for-failed: ".*(<a href=.*a>)"
description: "こんにちは"
description-for-failed: "さようなら"
set-for-matrix: true

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<org.jenkinsci.plugins.emotional__jenkins.EmotionalJenkinsPublisher/> <org.jenkinsci.plugins.emotional__jenkins.EmotionalJenkinsPublisher/>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<hudson.plugins.git.GitPublisher> <hudson.plugins.git.GitPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<com.cloudbees.jenkins.GitHubCommitNotifier/> <com.cloudbees.jenkins.GitHubCommitNotifier/>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<hudson.maven.RedeployPublisher> <hudson.maven.RedeployPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger> <au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger> <au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<hudson.plugins.plot.PlotPublisher> <hudson.plugins.plot.PlotPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<hudson.plugins.plot.PlotPublisher> <hudson.plugins.plot.PlotPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<hudson.plugins.plot.PlotPublisher> <hudson.plugins.plot.PlotPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<be.certipost.hudson.plugin.SCPRepositoryPublisher> <be.certipost.hudson.plugin.SCPRepositoryPublisher>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<org.jenkinsci.plugins.stashNotifier.StashNotifier> <org.jenkinsci.plugins.stashNotifier.StashNotifier>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<publishers> <publishers>
<xunit> <xunit>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<scm class="hudson.plugins.git.GitSCM"> <scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion> <configVersion>2</configVersion>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<scm class="hudson.plugins.git.GitSCM"> <scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion> <configVersion>2</configVersion>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<scm class="hudson.plugins.git.GitSCM"> <scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion> <configVersion>2</configVersion>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<scm class="hudson.plugins.git.GitSCM"> <scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion> <configVersion>2</configVersion>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<scm class="hudson.plugins.repo.RepoScm"> <scm class="hudson.plugins.repo.RepoScm">
<manifestRepositoryUrl>https://example.com/project/</manifestRepositoryUrl> <manifestRepositoryUrl>https://example.com/project/</manifestRepositoryUrl>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<triggers class="vector"> <triggers class="vector">
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger> <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<triggers class="vector"> <triggers class="vector">
<org.jenkinsci.plugins.ghprb.GhprbTrigger> <org.jenkinsci.plugins.ghprb.GhprbTrigger>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="utf-8"?>
<project> <project>
<buildWrappers> <buildWrappers>
<hudson.plugins.envfile.EnvFileBuildWrapper> <hudson.plugins.envfile.EnvFileBuildWrapper>