Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
dickp committed Dec 21, 2010
0 parents commit 7bec35b
Show file tree
Hide file tree
Showing 48 changed files with 2,421 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
target
.classpath
.settings
.project
*.iml
*.ipr
*.iws
23 changes: 23 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

The MIT License

Copyright (c) 2010, Codice Software

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

30 changes: 30 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.343</version><!-- which version of Hudson is this plugin built against? -->
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>com.codicesoftware.plugins.hudson</groupId>
<artifactId>plasticscm</artifactId>
<name>PlasticSCM Plugin</name>
<version>1.0</version>
<packaging>hpi</packaging>

<!-- get every artifact through maven.glassfish.org, which proxies all the artifacts that we need -->
<repositories>
<repository>
<id>m.g.o-public</id>
<url>http://maven.glassfish.org/content/groups/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>m.g.o-public</id>
<url>http://maven.glassfish.org/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.codicesoftware.plugins.hudson;

import com.codicesoftware.plugins.hudson.model.ChangeLogSet;
import com.codicesoftware.plugins.hudson.model.ChangeSet;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.digester.Digester;
import org.apache.commons.io.IOUtils;
import org.xml.sax.SAXException;

import hudson.model.AbstractBuild;
import hudson.scm.ChangeLogParser;
import hudson.util.Digester2;

/**
* Plastic SCM change log reader, based on tfs version.
*
* @author Erik Ramfelt
* @author Dick Porter
*/
public class ChangeSetReader extends ChangeLogParser {

@Override
public ChangeLogSet parse(AbstractBuild build, File changelogFile) throws IOException, SAXException {
FileReader reader = new FileReader(changelogFile);
try {
return parse(build, reader);
} finally {
IOUtils.closeQuietly(reader);
}
}

public ChangeLogSet parse(AbstractBuild<?,?> build, Reader reader) throws IOException, SAXException {
List<ChangeSet> changesetList = new ArrayList<ChangeSet>();
Digester digester = new Digester2();
digester.push(changesetList);

digester.addObjectCreate("*/changeset", ChangeSet.class);
digester.addSetProperties("*/changeset");
digester.addBeanPropertySetter("*/changeset/date", "dateStr");
digester.addBeanPropertySetter("*/changeset/user");
digester.addBeanPropertySetter("*/changeset/comment");
digester.addSetNext("*/changeset", "add");

digester.addObjectCreate("*/changeset/items/item", ChangeSet.Item.class);
digester.addSetProperties("*/changeset/items/item");
digester.addBeanPropertySetter("*/changeset/items/item", "path");
digester.addSetNext("*/changeset/items/item", "add");

digester.parse(reader);

return new ChangeLogSet(build, changesetList);
}
}
109 changes: 109 additions & 0 deletions src/main/java/com/codicesoftware/plugins/hudson/ChangeSetWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.codicesoftware.plugins.hudson;

import com.codicesoftware.plugins.hudson.model.ChangeSet;
import com.codicesoftware.plugins.hudson.util.DateUtil;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.List;

import org.apache.commons.io.IOUtils;

/**
* Plastic SCM change log writer, based on tfs version.
*
* @author Erik Ramfelt
* @author Dick Porter
*/
public class ChangeSetWriter {

/**
* Writes the list of change sets to the file
* @param changeSets list of change sets
* @param changelogFile file to write change sets to
*/
public void write(List<ChangeSet> changeSets, File changelogFile) throws IOException {
FileWriter writer = new FileWriter(changelogFile);
try {
write(changeSets, writer);
} finally {
IOUtils.closeQuietly(writer);
}
}

/**
* Writes the list of change sets to the writer
* @param changeSets list of change sets
* @param output output writer
*/
public void write(List<ChangeSet> changeSets, Writer output) {
PrintWriter writer = new PrintWriter(output);

writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writer.println("<changelog>");

for (ChangeSet changeSet : changeSets) {
writer.println(String.format("\t<changeset version=\"%s\">", changeSet.getVersion()));
write(changeSet, writer);
writer.println("\t</changeset>");
}

writer.println("</changelog>");
writer.flush();
}

private void write(ChangeSet changeSet, PrintWriter writer) {
writer.println(String.format("\t\t<date>%s</date>", DateUtil.PLASTICSCM_DATETIME_FORMATTER.get().format(changeSet.getDate())));
writer.println(String.format("\t\t<user>%s</user>", escapeForXml(changeSet.getUser())));
writer.println(String.format("\t\t<comment>%s</comment>", escapeForXml(changeSet.getComment())));
if (changeSet.getItems().size() > 0) {
writer.println("\t\t<items>");
for (ChangeSet.Item item : changeSet.getItems()) {
writer.println(String.format("\t\t\t<item revno=\"%s\" parentRevno=\"%s\">%s</item>",
escapeForXml(item.getRevno()), escapeForXml(item.getParentRevno()),
escapeForXml(item.getPath(changeSet.getWorkspaceDir()))));
}
writer.println("\t\t</items>");
}
}

/**
*
* Converts the input in the way that it can be written to the XML.
* Special characters are converted to XML understandable way.
*
* @param object The object to be escaped.
* @return Escaped string that can be written to XML.
*/
private String escapeForXml(Object object)
{
if(object == null)
{
return null;
}

//Loop through and replace the special chars.
String string = object.toString();
int size = string.length();
char ch;
StringBuilder escapedString = new StringBuilder(size);
for(int index = 0;index < size;index ++)
{
//Convert special chars.
ch = string.charAt(index);
switch(ch)
{
case '&' : escapedString.append("&amp;"); break;
case '<' : escapedString.append("&lt;"); break;
case '>' : escapedString.append("&gt;"); break;
case '\'' : escapedString.append("&apos;"); break;
case '\"' : escapedString.append("&quot;");break;
default: escapedString.append(ch);
}
}

return escapedString.toString();
}
}
Loading

0 comments on commit 7bec35b

Please sign in to comment.