diff --git a/pmd/tools/pom.xml b/pmd/tools/pom.xml
index cab316b27d..5a79fe3de5 100644
--- a/pmd/tools/pom.xml
+++ b/pmd/tools/pom.xml
@@ -38,9 +38,15 @@ only if you modify the java code.
${basedir}
- xslt/**.*.xsl
+ xslt/**/*.xsl
+
+ ${basedir}/src
+
+ **/*.properties
+
+
diff --git a/pmd/tools/src/config.properties b/pmd/tools/src/config.properties
new file mode 100644
index 0000000000..b66aa53940
--- /dev/null
+++ b/pmd/tools/src/config.properties
@@ -0,0 +1,6 @@
+pmd.build.config.xsl.rulesetToDocs=tools/xslt/rule-format.xsl
+pmd.build.config.xsl.mergeRuleset=tools/xslt/merge-rulesets.xsl
+pmd.build.config.xsl.rulesIndex=tools/xslt/rules-index.xsl
+pmd.build.config.xsl.generatejdk4pom=tools/xslt/generate-pom-jdk4.xsl
+pmd.build.config.index.filename=index.xml
+pmd.build.config.mergedRuleset.filename=mergedruleset.xml
diff --git a/pmd/tools/src/net/sourceforge/pmd/ant/PmdBuildTask.java b/pmd/tools/src/net/sourceforge/pmd/ant/PmdBuildTask.java
index 4019545a85..4664a45334 100644
--- a/pmd/tools/src/net/sourceforge/pmd/ant/PmdBuildTask.java
+++ b/pmd/tools/src/net/sourceforge/pmd/ant/PmdBuildTask.java
@@ -21,7 +21,31 @@ public class PmdBuildTask extends Task {
private String rulesDirectory;
private String target;
+ private String rulesetToDocs;
+ private String mergeRuleset;
+ private String rulesIndex;
+ private String indexFilename;
+ private String mergedRulesetFilename;
+ private boolean shouldGenerateJavaFourPom = true;
+
/**
+ *
+ * @return
+ */
+
+ /**
+ * @return the shouldGenerateJavaFourPom
+ */
+ public boolean isShouldGenerateJavaFourPom() {
+ return shouldGenerateJavaFourPom;
+ }
+ /**
+ * @param shouldGenerateJavaFourPom the shouldGenerateJavaFourPom to set
+ */
+ public void setShouldGenerateJavaFourPom(boolean shouldGenerateJavaFourPom) {
+ this.shouldGenerateJavaFourPom = shouldGenerateJavaFourPom;
+ }
+ /**
* @return the rulesDirectory
*/
public String getRulesDirectory() {
@@ -47,27 +71,102 @@ public class PmdBuildTask extends Task {
}
public void execute() throws BuildException {
- PmdBuildTools tool = new RuleSetToDocs();
- validate();
- tool.setTargetDirectory(this.target);
- tool.setRulesDirectory(this.rulesDirectory);
-
- try {
- tool.convertRulesets();
- tool.generateRulesIndex();
- tool.createPomForJava4("pom.xml","pmd-jdk14-pom.xml");
- }
- catch ( PmdBuildException e) {
- throw new BuildException(e);
- } catch (TransformerException e) {
- throw new BuildException(e);
- }
+ PmdBuildTools tool = validate(new RuleSetToDocs());
+ tool.setTargetDirectory(this.target);
+ tool.setRulesDirectory(this.rulesDirectory);
+
+ try {
+ tool.convertRulesets();
+ tool.generateRulesIndex();
+ if ( this.shouldGenerateJavaFourPom ) {
+ tool.createPomForJava4("pom.xml","pmd-jdk14-pom.xml");
+ }
+ }
+ catch ( PmdBuildException e) {
+ throw new BuildException(e);
+ } catch (TransformerException e) {
+ throw new BuildException(e);
+ }
}
- private void validate() throws BuildException {
- if ( this.target == null || "".equals(target) )
- throw new BuildException("Attribute targetDirectory is not optionnal");
- if ( this.rulesDirectory == null || "".equals(this.rulesDirectory) )
- throw new BuildException("Attribute rulesDirectory is not optionnal");
+ private PmdBuildTools validate(RuleSetToDocs tool) throws BuildException {
+ // Mandatory attributes
+ if ( this.target == null || "".equals(target) )
+ throw new BuildException("Attribute targetDirectory is not optionnal");
+ if ( this.rulesDirectory == null || "".equals(this.rulesDirectory) )
+ throw new BuildException("Attribute rulesDirectory is not optionnal");
+ // Optionnal Attributes
+ if ( this.mergedRulesetFilename != null && ! "".equals(this.mergedRulesetFilename) )
+ tool.setMergedRulesetFilename(this.mergedRulesetFilename);
+ if ( this.rulesIndex != null && ! "".equals(this.rulesIndex) )
+ tool.setGenerateIndexXsl(this.rulesIndex);
+ if ( this.rulesetToDocs != null && ! "".equals(this.rulesetToDocs) )
+ tool.setRulesetToDocsXsl(this.rulesetToDocs);
+ if ( this.mergeRuleset != null && ! "".equals(this.mergeRuleset) )
+ tool.setMergeRulesetXsl(this.mergeRuleset);
+ return tool;
}
+
+
+ /**
+ * @return the rulesetToDocs
+ */
+ public String getRulesetToDocs() {
+ return rulesetToDocs;
+ }
+ /**
+ * @param rulesetToDocs the rulesetToDocs to set
+ */
+ public void setRulesetToDocs(String rulesetToDocs) {
+ this.rulesetToDocs = rulesetToDocs;
+ }
+ /**
+ * @return the mergeRuleset
+ */
+ public String getMergeRuleset() {
+ return mergeRuleset;
+ }
+ /**
+ * @param mergeRuleset the mergeRuleset to set
+ */
+ public void setMergeRuleset(String mergeRuleset) {
+ this.mergeRuleset = mergeRuleset;
+ }
+ /**
+ * @return the rulesIndex
+ */
+ public String getRulesIndex() {
+ return rulesIndex;
+ }
+ /**
+ * @param rulesIndex the rulesIndex to set
+ */
+ public void setRulesIndex(String rulesIndex) {
+ this.rulesIndex = rulesIndex;
+ }
+
+ /**
+ * @return the indexFilename
+ */
+ public String getIndexFilename() {
+ return indexFilename;
+ }
+ /**
+ * @param indexFilename the indexFilename to set
+ */
+ public void setIndexFilename(String indexFilename) {
+ this.indexFilename = indexFilename;
+ }
+ /**
+ * @return the mergedRulesetFilename
+ */
+ public String getMergedRulesetFilename() {
+ return mergedRulesetFilename;
+ }
+ /**
+ * @param mergedRulesetFilename the mergedRulesetFilename to set
+ */
+ public void setMergedRulesetFilename(String mergedRulesetFilename) {
+ this.mergedRulesetFilename = mergedRulesetFilename;
+ }
}
diff --git a/pmd/tools/src/net/sourceforge/pmd/build/Config.java b/pmd/tools/src/net/sourceforge/pmd/build/Config.java
new file mode 100644
index 0000000000..c1f0136b10
--- /dev/null
+++ b/pmd/tools/src/net/sourceforge/pmd/build/Config.java
@@ -0,0 +1,22 @@
+package net.sourceforge.pmd.build;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Config {
+ private static final String BUNDLE_NAME = "config"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ private Config() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/pmd/tools/src/net/sourceforge/pmd/build/RuleSetToDocs.java b/pmd/tools/src/net/sourceforge/pmd/build/RuleSetToDocs.java
index b9a0c567cd..92e6dca193 100644
--- a/pmd/tools/src/net/sourceforge/pmd/build/RuleSetToDocs.java
+++ b/pmd/tools/src/net/sourceforge/pmd/build/RuleSetToDocs.java
@@ -37,256 +37,349 @@ import org.xml.sax.SAXException;
*/
public class RuleSetToDocs implements PmdBuildTools {
- private static final String RULESET_TO_DOC = "tools/xslt/rule-format.xsl";
- private static final String MERGE_RULESET = "tools/xslt/merge-rulesets.xsl";
- private static final String GENERATE_INDEX = "tools/xslt/rules-index.xsl";
- private static final String POM4JAVA4 = "tools/xslt/generate-pom-jdk4.xsl";
+ private String rulesetToDocsXsl = Config.getString("pmd.build.config.xsl.rulesetToDocs");
+ private String mergeRulesetXsl = Config.getString("pmd.build.config.xsl.mergeRuleset");
+ private String generateIndexXsl = Config.getString("pmd.build.config.xsl.rulesIndex");
+ private String pomForjavaFourXsl = Config.getString("pmd.build.config.xsl.generatejdk4pom");
- private static final String INDEX_RULESET_FILE = "index.xml";
- private static final String MERGED_RULESET_FILE = "mergedruleset.xml";
+ private String indexRuleSetFilename = Config.getString("pmd.build.config.index.filename");
+ private String mergedRuleSetFilename = Config.getString("pmd.build.config.mergedRuleset.filename");
- private String rulesDirectory;
- private String targetDirectory;
+ private String rulesDirectory;
+ private String targetDirectory;
- Transformer transformer;
- private File target;
+ private Transformer transformer;
+ private File target;
- /**
- * Default (empty) constructor:
- */
- public RuleSetToDocs() {
- }
- /* (non-Javadoc)
- * @see net.sourceforge.pmd.build.PmdBuildTools#getRulesDirectory()
- */
- public String getRulesDirectory() {
- return rulesDirectory;
- }
+ /**
+ * Default (empty) constructor:
+ */
+ public RuleSetToDocs() {
+ }
- /* (non-Javadoc)
- * @see net.sourceforge.pmd.build.PmdBuildTools#setRulesDirectory(java.lang.String)
- */
- public void setRulesDirectory(String rulesDirectory) {
- this.rulesDirectory = rulesDirectory;
- }
+ /* (non-Javadoc)
+ * @see net.sourceforge.pmd.build.PmdBuildTools#getRulesDirectory()
+ */
+ public String getRulesDirectory() {
+ return rulesDirectory;
+ }
- /* (non-Javadoc)
- * @see net.sourceforge.pmd.build.PmdBuildTools#convertRulesets()
- */
- public void convertRulesets() throws PmdBuildException {
- init();
- File rulesDir = new File(rulesDirectory);
- if ( rulesDir.exists() && rulesDir.isDirectory() ) {
- File[] rulesets = rulesDir.listFiles(new RulesetFilenameFilter());
- for (int fileIterator = 0; fileIterator < rulesets.length; fileIterator++ )
- {
- File ruleset = rulesets[fileIterator];
- System.out.println("Processing file " + ruleset);
- try {
- convertRuleSet(ruleset);
- } catch (ParserConfigurationException e) {
- throw new PmdBuildException(e);
- } catch (SAXException e) {
- throw new PmdBuildException(e);
- } catch (IOException e) {
- throw new PmdBuildException(e);
- } catch (TransformerException e) {
- throw new PmdBuildException(e);
+ /* (non-Javadoc)
+ * @see net.sourceforge.pmd.build.PmdBuildTools#setRulesDirectory(java.lang.String)
+ */
+ public void setRulesDirectory(String rulesDirectory) {
+ this.rulesDirectory = rulesDirectory;
+ }
+
+
+
+ /**
+ * @return the rulesetToDocsXsl
+ */
+ public String getRulesetToDocsXsl() {
+ return rulesetToDocsXsl;
+ }
+
+ /**
+ * @param rulesetToDocsXsl the rulesetToDocsXsl to set
+ */
+ public void setRulesetToDocsXsl(String rulesetToDocsXsl) {
+ this.rulesetToDocsXsl = rulesetToDocsXsl;
+ }
+
+ /**
+ * @return the mergeRulesetXsl
+ */
+ public String getMergeRulesetXsl() {
+ return mergeRulesetXsl;
+ }
+
+ /**
+ * @param mergeRulesetXsl the mergeRulesetXsl to set
+ */
+ public void setMergeRulesetXsl(String mergeRulesetXsl) {
+ this.mergeRulesetXsl = mergeRulesetXsl;
+ }
+
+ /**
+ * @return the generateIndexXsl
+ */
+ public String getGenerateIndexXsl() {
+ return generateIndexXsl;
+ }
+
+ /**
+ * @param generateIndexXsl the generateIndexXsl to set
+ */
+ public void setGenerateIndexXsl(String generateIndexXsl) {
+ this.generateIndexXsl = generateIndexXsl;
+ }
+
+ /**
+ * @return the pomForjavaFourXsl
+ */
+ public String getPomForjavaFourXsl() {
+ return pomForjavaFourXsl;
+ }
+
+ /**
+ * @param pomForjavaFourXsl the pomForjavaFourXsl to set
+ */
+ public void setPomForjavaFourXsl(String pomForjavaFourXsl) {
+ this.pomForjavaFourXsl = pomForjavaFourXsl;
+ }
+
+ /**
+ * @return the indexRuleSetFilename
+ */
+ public String getIndexRuleSetFilename() {
+ return indexRuleSetFilename;
+ }
+
+ /**
+ * @param indexRuleSetFilename the indexRuleSetFilename to set
+ */
+ public void setIndexRuleSetFilename(String indexRuleSetFilename) {
+ this.indexRuleSetFilename = indexRuleSetFilename;
+ }
+
+ /**
+ * @return the mergedRuleSetFilename
+ */
+ public String getMergedRuleSetFilename() {
+ return mergedRuleSetFilename;
+ }
+
+ /**
+ * @param mergedRuleSetFilename the mergedRuleSetFilename to set
+ */
+ public void setMergedRuleSetFilename(String mergedRuleSetFilename) {
+ this.mergedRuleSetFilename = mergedRuleSetFilename;
+ }
+
+ /* (non-Javadoc)
+ * @see net.sourceforge.pmd.build.PmdBuildTools#convertRulesets()
+ */
+ public void convertRulesets() throws PmdBuildException {
+ init();
+ File rulesDir = new File(rulesDirectory);
+ if ( rulesDir.exists() && rulesDir.isDirectory() ) {
+ File[] rulesets = rulesDir.listFiles(new RulesetFilenameFilter());
+ for (int fileIterator = 0; fileIterator < rulesets.length; fileIterator++ )
+ {
+ File ruleset = rulesets[fileIterator];
+ String targetName = this.targetDirectory + File.separator + ruleset.getName();
+ System.out.println("Processing file " + ruleset + " into " + targetName); //$NON-NLS-1$
+ try {
+ convertRuleSet(ruleset,new File(targetName));
+ } catch (ParserConfigurationException e) {
+ throw new PmdBuildException(e);
+ } catch (SAXException e) {
+ throw new PmdBuildException(e);
+ } catch (IOException e) {
+ throw new PmdBuildException(e);
+ } catch (TransformerException e) {
+ throw new PmdBuildException(e);
+ }
+ }
+ }
+ else if ( ! rulesDir.exists() ) {
+ throw new PmdBuildException("The rulesets directory specified '" + rulesDirectory + "' does not exist"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else if ( ! rulesDir.isDirectory() ) {
+ throw new PmdBuildException("The rulesets directory '" + rulesDirectory + "' provided is not a directory !"); //$NON-NLS-1$ //$NON-NLS-2$
}
- }
}
- else if ( ! rulesDir.exists() ) {
- throw new PmdBuildException("The rulesets directory specified '" + rulesDirectory + "' does not exist");
+
+ /*
+ *
+ * - Initialize the xml factory,
+ * - Check if target exist (or try to create it).
+ *
+ */
+ private void init() throws PmdBuildException {
+ // Create transformer
+ System.out.println("Merge xsl:" + rulesetToDocsXsl);
+ transformer = this.createTransformer(rulesetToDocsXsl);
+ target = new File(targetDirectory);
+ if ( (! target.exists() && ! target.mkdir()) ) {// no directory, creating it
+ throw new PmdBuildException("Target directory '" + target.getAbsolutePath() + "' does not exist and can't be created"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else if ( target.exists() && target.isFile() ) {
+ throw new PmdBuildException("Target directory '" + target.getAbsolutePath() + "' already exist and is a file."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
- else if ( ! rulesDir.isDirectory() ) {
- throw new PmdBuildException("The rulesets directory '" + rulesDirectory + "' provided is not a directory !");
+
+ /*
+ *
+ */
+ private void convertRuleSet(File ruleset,File target) throws ParserConfigurationException, SAXException, IOException, TransformerException {
+ // Loading Ruleset file
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document document = parser.parse(ruleset);
+ DOMSource xml = new DOMSource(document);
+ // Generating the result
+ StreamResult fileResult= new StreamResult(target);
+ // Transforming and Writing the ruleset, xdoc fmt, on file
+ this.transformer.transform(xml,fileResult);
}
- }
- /*
- *
- * - Initialize the xml factory,
- * - Check if target exist (or try to create it).
- *
- */
- private void init() throws PmdBuildException {
- // Create transformer
- transformer = this.createTransformer(RULESET_TO_DOC);
- target = new File(targetDirectory);
- if ( (! target.exists() && ! target.mkdir()) ) {// no directory, creating it
- throw new PmdBuildException("Target directory '" + targetDirectory + "' does not exist and can't be created");
+ /* (non-Javadoc)
+ * @see net.sourceforge.pmd.build.PmdBuildTools#generateRulesIndex()
+ */
+ public void generateRulesIndex() throws PmdBuildException, TransformerException {
+ // Merge ruleset
+ System.out.println("Merging all rules into " + this.mergedRuleSetFilename); //$NON-NLS-1$
+ File mergedFile = new File(this.targetDirectory + File.separator + ".." + File.separator + mergedRuleSetFilename); //$NON-NLS-1$
+ this.transformer = createTransformer(mergeRulesetXsl);
+ StreamResult fileResult= new StreamResult(mergedFile);
+ DOMSource xml = createXmlBackbone();
+ this.transformer.transform(xml,fileResult);
+ // Fix, removing the xmlns field of each ruleset in the generated xml file.
+ correctXmlMergeFile(mergedFile);
+ System.out.println("Creating index file:" + this.indexRuleSetFilename); //$NON-NLS-1$
+ this.transformer = createTransformer(generateIndexXsl);
+ // Create index from ruleset merge
+ StreamSource src = new StreamSource(mergedFile);
+ fileResult = new StreamResult(new File(this.targetDirectory + File.separator + indexRuleSetFilename));
+ this.transformer.transform(src,fileResult);
+
}
- else if ( target.exists() && target.isFile() ) {
- throw new PmdBuildException("Target directory '" + targetDirectory + "' already exist and is a file.");
+
+ private DOMSource createXmlBackbone() throws PmdBuildException {
+ Document doc = null;
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ doc = parser.newDocument();
+ } catch (ParserConfigurationException e) {
+ throw new PmdBuildException(e);
+ }
+ Element root = doc.createElement("root"); //$NON-NLS-1$
+ doc = addingEachRuleset(doc,root);
+ doc.appendChild(root);
+ return new DOMSource(doc);
}
- }
- /*
- *
- */
- private void convertRuleSet(File ruleset) throws ParserConfigurationException, SAXException, IOException, TransformerException {
- // Loading Ruleset file
- DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document document = parser.parse(ruleset);
- DOMSource xml = new DOMSource(document);
- // Generating the result
- StreamResult fileResult= new StreamResult(new File(this.targetDirectory + File.separator + ruleset.getName()));
- // Transforming and Writing the ruleset, xdoc fmt, on file
- this.transformer.transform(xml,fileResult);
- }
-
- /* (non-Javadoc)
- * @see net.sourceforge.pmd.build.PmdBuildTools#generateRulesIndex()
- */
- public void generateRulesIndex() throws PmdBuildException, TransformerException {
- // Merge ruleset
- System.out.println("Merging all rules into " + RuleSetToDocs.MERGED_RULESET_FILE);
- File mergedFile = new File(this.targetDirectory + File.separator + ".." + File.separator + MERGED_RULESET_FILE);
- this.transformer = createTransformer(MERGE_RULESET);
- StreamResult fileResult= new StreamResult(mergedFile);
- DOMSource xml = createXmlBackbone();
- this.transformer.transform(xml,fileResult);
- // Fix, removing the xmlns field of each ruleset in the generated xml file.
- correctXmlMergeFile(mergedFile);
- System.out.println("Creating index file:" + RuleSetToDocs.INDEX_RULESET_FILE);
- this.transformer = createTransformer(GENERATE_INDEX);
- // Create index from ruleset merge
- StreamSource src = new StreamSource(mergedFile);
- fileResult = new StreamResult(new File(this.targetDirectory + File.separator + INDEX_RULESET_FILE));
- this.transformer.transform(src,fileResult);
-
- }
-
- private DOMSource createXmlBackbone() throws PmdBuildException {
- Document doc = null;
- try {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder parser = factory.newDocumentBuilder();
- doc = parser.newDocument();
- } catch (ParserConfigurationException e) {
- throw new PmdBuildException(e);
+ private Document addingEachRuleset(Document doc,Element root) {
+ File rulesDir = new File(rulesDirectory);
+ if ( rulesDir.exists() && rulesDir.isDirectory() ) {
+ File[] rulesets = rulesDir.listFiles(new RulesetFilenameFilter());
+ for (int fileIterator = 0; fileIterator < rulesets.length; fileIterator++ ) {
+ File ruleset = rulesets[fileIterator];
+ //create child element
+ Element rulesetElement = doc.createElement("ruleset"); //$NON-NLS-1$
+ //Add the atribute to the child
+ rulesetElement.setAttribute("file",ruleset.getAbsolutePath()); //$NON-NLS-1$
+ root.appendChild(rulesetElement);
+ }
+ }
+ return doc;
}
- Element root = doc.createElement("root");
- doc = addingEachRuleset(doc,root);
- doc.appendChild(root);
- return new DOMSource(doc);
- }
- private Document addingEachRuleset(Document doc,Element root) {
- File rulesDir = new File(rulesDirectory);
- if ( rulesDir.exists() && rulesDir.isDirectory() ) {
- File[] rulesets = rulesDir.listFiles(new RulesetFilenameFilter());
- for (int fileIterator = 0; fileIterator < rulesets.length; fileIterator++ ) {
- File ruleset = rulesets[fileIterator];
- //create child element
- Element rulesetElement = doc.createElement("ruleset");
- //Add the atribute to the child
- rulesetElement.setAttribute("file",ruleset.getAbsolutePath());
- root.appendChild(rulesetElement);
- }
+ private Transformer createTransformer(String xsl) throws PmdBuildException {
+ try {
+ TransformerFactory factory = TransformerFactory.newInstance();
+ StreamSource src = new StreamSource(xsl);
+ return factory.newTransformer(src);
+ } catch (TransformerConfigurationException e) {
+ throw new PmdBuildException(e);
+ }
}
- return doc;
- }
- private Transformer createTransformer(String xsl) throws PmdBuildException {
- try {
- TransformerFactory factory = TransformerFactory.newInstance();
- StreamSource src = new StreamSource(xsl);
- return factory.newTransformer(src);
- } catch (TransformerConfigurationException e) {
- throw new PmdBuildException(e);
+
+ /* (non-Javadoc)
+ * @see net.sourceforge.pmd.build.PmdBuildTools#getTargetDirectory()
+ */
+ public String getTargetDirectory() {
+ return targetDirectory;
}
- }
-
- /* (non-Javadoc)
- * @see net.sourceforge.pmd.build.PmdBuildTools#getTargetDirectory()
- */
- public String getTargetDirectory() {
- return targetDirectory;
- }
-
- /* (non-Javadoc)
- * @see net.sourceforge.pmd.build.PmdBuildTools#setTargetDirectory(java.lang.String)
- */
- public void setTargetDirectory(String targetDirectory) {
- this.targetDirectory = targetDirectory;
- }
-
- public static void deleteFile(File file) {
- if ( ! file.isDirectory() ) {
- file.delete();
+ /* (non-Javadoc)
+ * @see net.sourceforge.pmd.build.PmdBuildTools#setTargetDirectory(java.lang.String)
+ */
+ public void setTargetDirectory(String targetDirectory) {
+ this.targetDirectory = targetDirectory;
}
- else {
- File[] files = file.listFiles();
- for (int nbFile = 0; nbFile < files.length; nbFile++ )
- RuleSetToDocs.deleteFile(files[nbFile]);
- file.delete();
+
+ public static void deleteFile(File file) {
+ if ( ! file.isDirectory() ) {
+ file.delete();
+ }
+ else {
+ File[] files = file.listFiles();
+ for (int nbFile = 0; nbFile < files.length; nbFile++ )
+ RuleSetToDocs.deleteFile(files[nbFile]);
+ file.delete();
+ }
}
- }
- private void correctXmlMergeFile(File file) {
+ private void correctXmlMergeFile(File file) {
- File tmp = new File(file + ".tmp");
- try {
- String line;
- FileWriter fw = new FileWriter(tmp);
- FileReader fr = new FileReader(file);
- BufferedWriter bw = new BufferedWriter(fw);
- BufferedReader br = new BufferedReader(fr);
- while (br.ready()) {
- line = br.readLine();
- line = line.replaceAll("xmlns=\"http://pmd.sf.net/ruleset/1.0.0\"", "");
- bw.write(line);
- }
- fr.close();
- bw.flush();
- fw.close();
- // Copy , and suppress tmp file
- copy(tmp, file);
- tmp.delete();
+ File tmp = new File(file + ".tmp"); //$NON-NLS-1$
+ try {
+ String line;
+ FileWriter fw = new FileWriter(tmp);
+ FileReader fr = new FileReader(file);
+ BufferedWriter bw = new BufferedWriter(fw);
+ BufferedReader br = new BufferedReader(fr);
+ while (br.ready()) {
+ line = br.readLine();
+ line = line.replaceAll("xmlns=\"http://pmd.sf.net/ruleset/1.0.0\"", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ bw.write(line);
+ }
+ fr.close();
+ bw.flush();
+ fw.close();
+ // Copy , and suppress tmp file
+ copy(tmp, file);
+ tmp.delete();
+ }
+ // Catches any error conditions
+ catch (IOException e) {
+ e.printStackTrace();
+ }
}
- // Catches any error conditions
- catch (IOException e) {
- e.printStackTrace();
+
+ private void copy(File src, File dst) throws IOException
+ {
+ InputStream in = new FileInputStream(src);
+ OutputStream out = new FileOutputStream(dst);
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0)
+ out.write(buf, 0, len);
+ in.close();
+ out.close();
}
- }
- private void copy(File src, File dst) throws IOException
- {
- InputStream in = new FileInputStream(src);
- OutputStream out = new FileOutputStream(dst);
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0)
- out.write(buf, 0, len);
- in.close();
- out.close();
- }
-
- /* (non-Javadoc)
- * @see net.sourceforge.pmd.build.PmdBuildTools#createPomForJava4(java.lang.String, java.lang.String)
- */
- public void createPomForJava4(String pom,String pom4java4) throws PmdBuildException {
- try {
- Transformer transformer = this.createTransformer(POM4JAVA4);
- StreamResult result = new StreamResult(new File(pom4java4));
- // Loading pom file
- DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document document = parser.parse(pom);
- transformer.transform(new DOMSource(document),result);
- } catch (PmdBuildException e) {
- throw new PmdBuildException(e);
- } catch (SAXException e) {
- throw new PmdBuildException(e);
- } catch (IOException e) {
- throw new PmdBuildException(e);
- } catch (TransformerException e) {
- throw new PmdBuildException(e);
- } catch (ParserConfigurationException e) {
- throw new PmdBuildException(e);
+ /* (non-Javadoc)
+ * @see net.sourceforge.pmd.build.PmdBuildTools#createPomForJava4(java.lang.String, java.lang.String)
+ */
+ public void createPomForJava4(String pom,String pom4java4) throws PmdBuildException {
+ try {
+ Transformer transformer = this.createTransformer(pomForjavaFourXsl);
+ StreamResult result = new StreamResult(new File(pom4java4));
+ // Loading pom file
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document document = parser.parse(pom);
+ transformer.transform(new DOMSource(document),result);
+ } catch (PmdBuildException e) {
+ throw new PmdBuildException(e);
+ } catch (SAXException e) {
+ throw new PmdBuildException(e);
+ } catch (IOException e) {
+ throw new PmdBuildException(e);
+ } catch (TransformerException e) {
+ throw new PmdBuildException(e);
+ } catch (ParserConfigurationException e) {
+ throw new PmdBuildException(e);
+ }
}
- }
+ public void setMergedRulesetFilename(String mergedRulesetFilename) {
+ //this.mergedRulesetFilename = mergedRulesetFilename;
+
+ }
}