Search in sources :

Example 11 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project gocd by gocd.

the class GoConfigMigration method getCurrentSchemaVersion.

private int getCurrentSchemaVersion(String content) {
    try {
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(new ByteArrayInputStream(content.getBytes()));
        Element root = document.getRootElement();
        String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0" : root.getAttributeValue(schemaVersion);
        return Integer.parseInt(currentVersion);
    } catch (Exception e) {
        throw bomb(e);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) XmlUtils.buildXmlDocument(com.thoughtworks.go.util.XmlUtils.buildXmlDocument) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException)

Example 12 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project gocd by gocd.

the class SvnCommandTest method shouldParseSvnInfoWithParthDifferentFromUrl.

@Test
public void shouldParseSvnInfoWithParthDifferentFromUrl() throws Exception {
    String output = "<?xml version=\"1.0\"?>\n" + "<info>\n" + "<entry\n" + "   kind=\"dir\"\n" + "   path=\"PurchaseDeliverables\"\n" + "   revision=\"36788\">\n" + "<url>http://svn.somewhere.com/someotherline/bloresvn/TISSIP/branch/DEV/PurchaseDeliverables</url>\n" + "<repository>\n" + "<root>http://svn.somewhere.com/someotherline</root>\n" + "<uuid>f6689194-972b-e749-89bf-11ebdadc4dc5</uuid>\n" + "</repository>\n" + "<commit\n" + "   revision=\"26449\">\n" + "<author>nigelfer</author>\n" + "<date>2009-02-03T15:43:08.059944Z</date>\n" + "</commit>\n" + "</entry>\n" + "</info>";
    SvnCommand.SvnInfo svnInfo = new SvnCommand.SvnInfo();
    svnInfo.parse(output, new SAXBuilder());
    assertThat(svnInfo.getPath(), is("/bloresvn/TISSIP/branch/DEV/PurchaseDeliverables"));
    assertThat(svnInfo.getUrl(), is("http://svn.somewhere.com/someotherline/bloresvn/TISSIP/branch/DEV/PurchaseDeliverables"));
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 13 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project gocd by gocd.

the class SvnCommandTest method shouldParseSvnInfo.

@Test
public void shouldParseSvnInfo() throws Exception {
    String output = "<?xml version=\"1.0\"?>\n" + "<info>\n" + "<entry\n" + "   kind=\"dir\"\n" + "   path=\"someotherline\"\n" + "   revision=\"36788\">\n" + "<url>http://svn.somewhere.com/svn/someotherline</url>\n" + "<repository>\n" + "<root>http://svn.somewhere.com/svn</root>\n" + "<uuid>f6689194-972b-e749-89bf-11ebdadc4dc5</uuid>\n" + "</repository>\n" + "<commit\n" + "   revision=\"36788\">\n" + "<author>csebasti</author>\n" + "<date>2009-05-30T17:47:27.435599Z</date>\n" + "</commit>\n" + "</entry>\n" + "</info>";
    SvnCommand.SvnInfo svnInfo = new SvnCommand.SvnInfo();
    svnInfo.parse(output, new SAXBuilder());
    assertThat(svnInfo.getPath(), is("/someotherline"));
    assertThat(svnInfo.getUrl(), is("http://svn.somewhere.com/svn/someotherline"));
    assertThat(svnInfo.getRoot(), is("http://svn.somewhere.com/svn"));
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 14 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project gocd by gocd.

the class SvnCommand method getAllExternalURLs.

public List<SvnExternal> getAllExternalURLs() {
    CommandLine svnExternalCommand = svn(true).withArgs("propget", "--non-interactive", "svn:externals", "-R").withArg(repositoryUrl);
    ConsoleResult result = executeCommand(svnExternalCommand);
    String svnExternalConsoleOut = result.outputAsString();
    SvnInfo remoteInfo = remoteInfo(new SAXBuilder());
    String repoUrl = remoteInfo.getUrl();
    String repoRoot = remoteInfo.getRoot();
    List<SvnExternal> svnExternalList = null;
    try {
        svnExternalList = new SvnExternalParser().parse(svnExternalConsoleOut, repoUrl, repoRoot);
    } catch (RuntimeException e) {
        throw (RuntimeException) result.smudgedException(e);
    }
    return svnExternalList;
}
Also used : CommandLine.createCommandLine(com.thoughtworks.go.util.command.CommandLine.createCommandLine) SAXBuilder(org.jdom2.input.SAXBuilder)

Example 15 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project gocd by gocd.

the class SvnCommand method getBuilder.

private SAXBuilder getBuilder() {
    SAXBuilder saxBuilder = saxBuilderThreadLocal.get();
    if (saxBuilder == null) {
        saxBuilder = new SAXBuilder();
        saxBuilderThreadLocal.set(saxBuilder);
    }
    return saxBuilder;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder)

Aggregations

SAXBuilder (org.jdom2.input.SAXBuilder)43 Document (org.jdom2.Document)21 Test (org.junit.Test)19 File (java.io.File)9 IOException (java.io.IOException)8 Element (org.jdom2.Element)8 Modification (com.thoughtworks.go.domain.materials.Modification)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 BufferedInputStream (java.io.BufferedInputStream)5 ParseException (java.text.ParseException)5 FileInputStream (java.io.FileInputStream)4 StringReader (java.io.StringReader)4 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)3 InputStream (java.io.InputStream)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 DocType (org.jdom2.DocType)3 JDOMException (org.jdom2.JDOMException)3 XmlUtils.buildXmlDocument (com.thoughtworks.go.util.XmlUtils.buildXmlDocument)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2