From 399f02f4d88a08d3e14f0b437ce6a6f4f81b6b77 Mon Sep 17 00:00:00 2001 From: aheritier Date: Sun, 9 May 2004 20:58:49 +0000 Subject: [PATCH] Fix checkstyle errors git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115207 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/DependencyDescriberBean.java | 200 +++++----- .../org/apache/maven/DescribedDependency.java | 341 +++++++++++------- xdoc/src/main/org/apache/maven/NavBean.java | 284 +++++++++------ .../test/org/apache/maven/NavBeanTest.java | 243 +++++++++---- 4 files changed, 669 insertions(+), 399 deletions(-) diff --git a/xdoc/src/main/org/apache/maven/DependencyDescriberBean.java b/xdoc/src/main/org/apache/maven/DependencyDescriberBean.java index 67f7f097..5975af36 100644 --- a/xdoc/src/main/org/apache/maven/DependencyDescriberBean.java +++ b/xdoc/src/main/org/apache/maven/DependencyDescriberBean.java @@ -16,111 +16,135 @@ package org.apache.maven; * limitations under the License. * ==================================================================== */ +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.apache.maven.project.Dependency; +import org.apache.maven.project.Project; import java.io.File; + import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.maven.project.Dependency; -import org.apache.maven.project.Project; /** - * @author Michal Maczka - * @version $Id: DependencyDescriberBean.java,v 1.3 2004/03/02 15:36:14 evenisse Exp $ + * Retreive descriptions for project's dependencies. + * + * @author Michal Maczka + * @version $Id: DependencyDescriberBean.java,v 1.4 2004/05/09 20:58:49 aheritier Exp $ */ public class DependencyDescriberBean { - /** for debug output */ - private Log log = LogFactory.getLog(DependencyDescriberBean.class); - - /** */ - private List dependencies = new ArrayList(); - private Project project; + //~ Instance fields ------------------------------------------------ - /** - * @return - */ - public List getDependencies() + /** dependencies list */ + private List dependencies = new ArrayList(); + + /** for debug output */ + private Log log = LogFactory.getLog(DependencyDescriberBean.class); + + /** project reference */ + private Project project; + + //~ Methods -------------------------------------------------------- + + /** + * The list of described dependencies. + * + * @return list of described dependencies + * + * @see DescribedDependency + */ + public List getDependencies() + { + return dependencies; + } + + /** + * Project provides context/session related information. e.g where + * maven repo local is + * + * @param projectValue project to scan + */ + public void build(Project projectValue) + { + this.project = projectValue; + + for (Iterator iter = project.getDependencies().iterator(); + iter.hasNext();) { - return dependencies; + Dependency dependency = (Dependency) iter.next(); + DescribedDependency describedDependency = + new DescribedDependency(dependency); + dependencies.add(describedDependency); + + Project resolvedProject = resolveProject(dependency); + + if (resolvedProject != null) + { + log.debug("POM URL:" + resolvedProject.getUrl()); + describedDependency.setUrl(resolvedProject.getUrl()); + describedDependency.setDescription( + resolvedProject.getDescription()); + } } - /** - * Project provides context/session related information. - * e.g where maven repo local is - * @param project - */ - public void build(Project project) - { - this.project = project; - for (Iterator iter = project.getDependencies().iterator(); - iter.hasNext(); - ) - { - Dependency dependency = (Dependency) iter.next(); - DescribedDependency describedDependency = - new DescribedDependency(dependency); - dependencies.add(describedDependency); - Project resolvedProject = resolveProject(dependency); - if (resolvedProject != null) - { - log.debug("POM URL:" + resolvedProject.getUrl()); - describedDependency.setUrl(resolvedProject.getUrl()); - describedDependency.setDescription( - resolvedProject.getDescription()); - } - } - Collections.sort(dependencies); - } - /** - * @param dependency - * @return - * @throws Exception - */ - private Project resolveProject(Dependency dependency) - { + Collections.sort(dependencies); + } - File projectFile = null; - if ("pom".equals(dependency.getType())) - { - projectFile = - new File( - project.getContext().getMavenRepoLocal(), - dependency.getArtifact()); - } - else - { - projectFile = - new File( - project.getContext().getMavenRepoLocal(), - dependency.getArtifactDirectory() - + "/poms/" - + dependency.getArtifactId() - + "-" - + dependency.getVersion() - + ".pom"); - } - try - { - if (projectFile.exists() && projectFile.canRead()) - { + /** + * Returns the project for a given dependency. + * + * @param dependency The dependency for which the project is + * searched. + * + * @return The project associated to this dependency. + */ + private Project resolveProject(Dependency dependency) + { + File projectFile = null; - return MavenUtils.getProject(projectFile, null, false); - } - else - { - log.debug("Failed to read POM:" + projectFile); - return null; - } - } - catch (Exception e) - { - log.debug("Failed to read POM:" + projectFile); - return null; - } + if ("pom".equals(dependency.getType())) + { + projectFile = + new File( + project.getContext().getMavenRepoLocal(), + dependency.getArtifact()); } + else + { + projectFile = + new File( + project.getContext().getMavenRepoLocal(), + dependency.getArtifactDirectory() + "/poms/" + + dependency.getArtifactId() + "-" + + dependency.getVersion() + ".pom"); + } + + try + { + if (projectFile.exists() && projectFile.canRead()) + { + return MavenUtils.getProject( + projectFile, + null, + false); + } + else + { + log.debug("Failed to read POM:" + projectFile); + + return null; + } + } + catch (Exception e) + { + log.debug("Failed to read POM:" + projectFile); + + return null; + } + } } diff --git a/xdoc/src/main/org/apache/maven/DescribedDependency.java b/xdoc/src/main/org/apache/maven/DescribedDependency.java index c510b57d..ce68ce2f 100644 --- a/xdoc/src/main/org/apache/maven/DescribedDependency.java +++ b/xdoc/src/main/org/apache/maven/DescribedDependency.java @@ -16,157 +16,222 @@ package org.apache.maven; * limitations under the License. * ==================================================================== */ - import org.apache.maven.project.Dependency; + /** - * - * @author Michal Maczka - * @version $Id: DescribedDependency.java,v 1.2 2004/03/02 15:36:14 evenisse Exp $ + * Dependency wrapper. Adds an url to download and a description. + * + * @author Michal Maczka + * @version $Id: DescribedDependency.java,v 1.3 2004/05/09 20:58:49 aheritier Exp $ */ public class DescribedDependency implements Comparable { - private Dependency dependency; + //~ Instance fields ---------------------------------------------------------- - private String description = null; + /** Original dependency. */ + private Dependency dependency; - private String url = null; + /** Dependency description. */ + private String description = null; - public DescribedDependency(Dependency dependency) + /** Dependency Url. */ + private String url = null; + + //~ Constructors ------------------------------------------------------------- + + /** + * Creates a new DescribedDependency object. + * + * @param dependencyToWrap Original dependency. + */ + public DescribedDependency(Dependency dependencyToWrap) + { + this.dependency = dependencyToWrap; + } + + //~ Methods ------------------------------------------------------------------ + + /** + * Dependency's artifact property getter. + * + * @return dependency's artifact. + * + * @see Dependency#getArtifact() + */ + public String getArtifact() + { + return dependency.getArtifact(); + } + + /** + * Dependency's artifactDirectory property getter. + * + * @return dependency's artifactDirectory. + * + * @see Dependency#getArtifactDirectory() + */ + public String getArtifactDirectory() + { + return dependency.getArtifactDirectory(); + } + + /** + * Dependency's artifactId property getter. + * + * @return dependency's artifactId. + * + * @see Dependency#getArtifactId() + */ + public String getArtifactId() + { + return dependency.getArtifactId(); + } + + /** + * Property setter. + * + * @param newDescription new description for the dependency. + * + */ + public void setDescription(String newDescription) + { + this.description = newDescription; + } + + /** + * Property getter. + * + * @return the dependency's description. + * + */ + public String getDescription() + { + return description; + } + + /** + * Dependency's extension property getter. + * + * @return dependency's extension. + * + * @see Dependency#getExtension() + */ + public String getExtension() + { + return dependency.getExtension(); + } + + /** + * Dependency's groupId property getter. + * + * @return dependency's groupId. + * + * @see Dependency#getGroupId() + */ + public String getGroupId() + { + return dependency.getGroupId(); + } + + /** + * Dependency's id property getter. + * + * @return dependency's id. + * + * @see Dependency#getId() + */ + public String getId() + { + return dependency.getId(); + } + + /** + * Dependency's jar property getter. + * + * @return dependency's jar. + * + * @see Dependency#getJar() + */ + public String getJar() + { + return dependency.getJar(); + } + + /** + * Dependency's name property getter. + * + * @return dependency's name. + * + * @see Dependency#getName() + */ + public String getName() + { + return dependency.getName(); + } + + /** + * Dependency's type property getter. + * + * @return dependency's type. + * + * @see Dependency#getType() + */ + public String getType() + { + return dependency.getType(); + } + + /** + * Property setter. + * + * @param newUrl the new dependency's url. + */ + public void setUrl(String newUrl) + { + this.url = newUrl; + } + + /** + * Property getter. + * + * @return the dependency's url. + */ + public String getUrl() + { + String retValue = null; + + if ((dependency.getUrl() != null) && (dependency.getUrl().length() > 0)) { - this.dependency = dependency; + retValue = dependency.getUrl(); + } + else + { + return retValue = url; } - /** - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - public int compareTo(Object obj) - { - DescribedDependency other = (DescribedDependency) obj; - return this.getId().compareTo(other.getId()); - } - /** - * @return - */ - public String getArtifact() - { - return dependency.getArtifact(); - } + return retValue; + } - /** - * @return - */ - public String getArtifactDirectory() - { - return dependency.getArtifactDirectory(); - } + /** + * Dependency's version property getter. + * + * @return dependency's version. + * + * @see Dependency#getVersion() + */ + public String getVersion() + { + return dependency.getVersion(); + } - /** - * @return - */ - public String getArtifactId() - { - return dependency.getArtifactId(); - } - - /** - * @return - */ - public String getExtension() - { - return dependency.getExtension(); - } - - /** - * @return - */ - public String getGroupId() - { - return dependency.getGroupId(); - } - - /** - * @return - */ - public String getId() - { - return dependency.getId(); - } - - /** - * @return - */ - public String getJar() - { - return dependency.getJar(); - } - - /** - * @return - */ - public String getName() - { - return dependency.getName(); - } - - /** - * @return - */ - public String getType() - { - return dependency.getType(); - } - - /** - * - * @param url - */ - public void setUrl(String url) - { - this.url = url; - } - - /** - * @return - */ - public String getUrl() - { - String retValue = null; - if (dependency.getUrl() != null && dependency.getUrl().length()>0) - { - retValue = dependency.getUrl(); - } - else - { - - return retValue = url; - } - return retValue; - } - - /** - * @return - */ - public String getVersion() - { - return dependency.getVersion(); - } - - /** - /** - * @return - */ - public String getDescription() - { - return description; - } - - /** - * @param description - */ - public void setDescription(String description) - { - this.description = description; - } + /** + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object obj) + { + DescribedDependency other = (DescribedDependency) obj; + return this.getId().compareTo(other.getId()); + } } diff --git a/xdoc/src/main/org/apache/maven/NavBean.java b/xdoc/src/main/org/apache/maven/NavBean.java index 4c2d28d8..30f468e3 100644 --- a/xdoc/src/main/org/apache/maven/NavBean.java +++ b/xdoc/src/main/org/apache/maven/NavBean.java @@ -16,141 +16,205 @@ package org.apache.maven; * limitations under the License. * ==================================================================== */ +import org.dom4j.Attribute; +import org.dom4j.Node; + +import org.dom4j.tree.DefaultElement; import java.util.List; -import org.dom4j.Attribute; -import org.dom4j.Node; -import org.dom4j.tree.DefaultElement; /** - * @author Ben Walding - * @version $Id: NavBean.java,v 1.7 2004/03/02 15:36:14 evenisse Exp $ + * Navigation Bean. + * + * @author Ben Walding + * @version $Id: NavBean.java,v 1.8 2004/05/09 20:58:49 aheritier Exp $ */ public class NavBean { - private String location; - private Node document; + //~ Instance fields ---------------------------------------------------------- - public void setDocument(Object o) + /** The current document. */ + private Node document; + + /** The current location. */ + private String location; + + //~ Methods ------------------------------------------------------------------ + + /** + * Determines if the given node is collapsed. If a parent of this node is + * collapsed, this will give spurious results. + * + * @param o the node to test + * + * @return boolean + */ + public boolean isCollapsed(Object o) + { + //If we don't know where we are, collapse it - something outside of our knowledge + if (location == null) { - document = (Node) o; + return true; } - private static String getAttribute(DefaultElement elem, String attribute, String defaultValue) + if (!(o instanceof DefaultElement)) { - Attribute attr = elem.attribute(attribute); - if (attr == null) - { - return defaultValue; - } + System.out.println(o.getClass().getName()); - return attr.getStringValue(); + return false; } - private static boolean getCollapseAttribute(DefaultElement elem) + DefaultElement elem = (DefaultElement) o; + + boolean collapsed = getCollapseAttribute(elem); + + if (!collapsed) { - return Boolean.valueOf(getAttribute(elem, "collapse", "false")).booleanValue(); - } - private static String getHREFAttribute(DefaultElement elem) - { - return getAttribute(elem, "href", null); - } - - /** - * Determines if the given node is collapsed. If a parent of this node is - * collapsed, this will give spurious results. - * @param o - * @return boolean - */ - public boolean isCollapsed(Object o) - { - //If we don't know where we are, collapse it - something outside of our knowledge - if (location == null) - { - return true; - } - - if (!(o instanceof DefaultElement)) - { - System.out.println(o.getClass().getName()); - return false; - } - DefaultElement elem = (DefaultElement) o; - - boolean collapsed = getCollapseAttribute(elem); - if (!collapsed) - { - return false; - } - - if (isSelected(o)) - { - return false; - } - - //System.out.println(elem.asXML()); - String xpath; - if (location.startsWith("/") || location.startsWith(".")) { - xpath = ".//item[@href='" + location + "']"; - - } else { - xpath = ".//item[@href='/" + location + "']"; - - } - - - List l = elem.selectNodes(xpath); - - if (l.size() != 0) - { - return false; - } - - return true; + return false; } - /** - * Determines if a given item node is the selected node - * @param o - * @return boolean - */ - public boolean isSelected(Object o) + if (isSelected(o)) { - if (location == null) - { - return false; - } - - DefaultElement elem = (DefaultElement) o; - if (location.equals(getHREFAttribute(elem))) - { - return true; - } - - return false; + return false; } - /** - * Sets the location. - * @param location The location to set - */ - public void setLocation(String location) + //System.out.println(elem.asXML()); + String xpath; + + if (location.startsWith("/") || location.startsWith(".")) { - if (!location.startsWith("/")) - location = "/" + location; - - this.location = location; + xpath = ".//item[@href='" + location + "']"; + } + else + { + xpath = ".//item[@href='/" + location + "']"; } - /** - * Find the first item with a given href - * @param href - * @return DefaultElement - */ - public DefaultElement getFirstNodeByHREF(String href) + List l = elem.selectNodes(xpath); + + if (l.size() != 0) { - String xpath = "//item[@href='" + href + "']"; - return (DefaultElement) document.selectSingleNode(xpath); + return false; } + + return true; + } + + /** + * Setter. + * + * @param o The new document. + */ + public void setDocument(Object o) + { + document = (Node) o; + } + + /** + * Find the first item with a given href + * + * @param href the href to find. + * + * @return DefaultElement + */ + public DefaultElement getFirstNodeByHREF(String href) + { + String xpath = "//item[@href='" + href + "']"; + + return (DefaultElement) document.selectSingleNode(xpath); + } + + /** + * Sets the location. + * + * @param newLocation The location to set + */ + public void setLocation(String newLocation) + { + if (!newLocation.startsWith("/")) + { + newLocation = "/" + newLocation; + } + + this.location = newLocation; + } + + /** + * Determines if a given item node is the selected node + * + * @param o the item to test + * + * @return true if the item is currently selected. + */ + public boolean isSelected(Object o) + { + if (location == null) + { + return false; + } + + DefaultElement elem = (DefaultElement) o; + + if (location.equals(getHREFAttribute(elem))) + { + return true; + } + + return false; + } + + /** + * Return the attribute's value for an element. + * + * @param elem The element to read + * @param attribute The attribute's name to get. + * @param defaultValue A default value to return. + * + * @return The attribute's value for the given element. + */ + private static String getAttribute( + DefaultElement elem, + String attribute, + String defaultValue) + { + Attribute attr = elem.attribute(attribute); + + if (attr == null) + { + return defaultValue; + } + + return attr.getStringValue(); + } + + /** + * Test if the element is collapsed. + * + * @param elem The element to test + * + * @return true if the element has a collapse attribute with the value true. + */ + private static boolean getCollapseAttribute(DefaultElement elem) + { + return Boolean.valueOf(getAttribute( + elem, + "collapse", + "false")).booleanValue(); + } + + /** + * Return href attribute. + * + * @param elem element. + * + * @return href value. + */ + private static String getHREFAttribute(DefaultElement elem) + { + return getAttribute( + elem, + "href", + null); + } } diff --git a/xdoc/src/test/org/apache/maven/NavBeanTest.java b/xdoc/src/test/org/apache/maven/NavBeanTest.java index 4b517bde..cc716895 100644 --- a/xdoc/src/test/org/apache/maven/NavBeanTest.java +++ b/xdoc/src/test/org/apache/maven/NavBeanTest.java @@ -16,81 +16,198 @@ package org.apache.maven; * limitations under the License. * ==================================================================== */ - -import java.io.File; -import java.io.FileInputStream; - import junit.framework.TestCase; import org.dom4j.Document; import org.dom4j.Node; + import org.dom4j.io.SAXReader; +import java.io.File; +import java.io.FileInputStream; + + /** - * @author Ben Walding - * @version $Id: NavBeanTest.java,v 1.5 2004/03/02 15:36:15 evenisse Exp $ + * NavBean Tests class. + * + * @author Ben Walding + * @version $Id: NavBeanTest.java,v 1.6 2004/05/09 20:58:49 aheritier Exp $ */ public class NavBeanTest extends TestCase { + //~ Instance fields ---------------------------------------------------------- - private File testResources; - NavBean nb; + /** Test resources file. */ + private File testResources; - public void setUp() throws Exception + /** NavBean instance to test */ + private NavBean nb; + + //~ Methods ------------------------------------------------------------------ + + /** + * Tests settings. + * + * @throws Exception If a problem occurs + */ + public void setUp() + throws Exception + { + testResources = + new File(System.getProperty("basedir") + "/src/test-resources"); + nb = new NavBean(); + nb.setDocument(getTestDocument()); + } + + /** + * Test. + * + * @param href href + * @param location location + * @param expected Result expected + */ + public void testCollapsed( + String href, + String location, + boolean expected) + { + nb.setLocation(location); + + Node node = nb.getFirstNodeByHREF(href); + assertNotNull(node); + + String s = + "At location " + location + ", looking to generate link to " + href + + ", expecting collapse = " + expected; + assertEquals( + s, + expected, + nb.isCollapsed(node)); + } + + /** + * tests suite. + * + * @throws Exception DOCUMENT ME! + */ + public void testCollapsed() + throws Exception + { + testCollapsed( + "/alpha/index.html", + "/alpha/index.html", + false); + testCollapsed( + "/alpha/one/index.html", + "/alpha/index.html", + false); + testCollapsed( + "/alpha/two/index.html", + "/alpha/index.html", + false); + testCollapsed( + "/beta/index.html", + "/alpha/index.html", + true); + + testCollapsed( + "/alpha/index.html", + "/beta/index.html", + false); + testCollapsed( + "/alpha/one/index.html", + "/beta/index.html", + false); + testCollapsed( + "/alpha/two/index.html", + "/beta/index.html", + false); + testCollapsed( + "/beta/index.html", + "/beta/index.html", + false); + testCollapsed( + "/beta/one/index.html", + "/beta/index.html", + true); + testCollapsed( + "/beta/two/index.html", + "/beta/index.html", + true); + + testCollapsed( + "/alpha/index.html", + "beta/index.html", + false); + testCollapsed( + "/alpha/one/index.html", + "beta/index.html", + false); + testCollapsed( + "/alpha/two/index.html", + "beta/index.html", + false); + testCollapsed( + "/beta/index.html", + "beta/index.html", + false); + testCollapsed( + "/beta/one/index.html", + "beta/index.html", + true); + testCollapsed( + "/beta/two/index.html", + "beta/index.html", + true); + } + + /** + * Get the navigation.xml to test. + * + * @return XML Document + * + * @throws Exception If a problem occurs. + */ + protected Document getTestDocument() + throws Exception + { + SAXReader reader = new SAXReader(); + + return reader.read( + new FileInputStream(new File( + testResources, + "navigation.xml"))); + } + + //~ Inner Classes ------------------------------------------------------------ + + /** + * Test + */ + class Test + { + //~ Instance fields -------------------------------------------------------- + + /** Href. */ + private String href; + + /** Collapsed. */ + private boolean collapsed; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new Test object. + * + * @param newHref HREF. + * @param newCollapsed Status. + */ + public Test( + String newHref, + boolean newCollapsed) { - testResources = new File(System.getProperty("basedir") + "/src/test-resources"); - nb = new NavBean(); - nb.setDocument(getTestDocument()); - } - - class Test - { - String href; - boolean collapsed; - public Test(String href, boolean collapsed) - { - this.href = href; - this.collapsed = collapsed; - } - } - - - protected Document getTestDocument() throws Exception - { - SAXReader reader = new SAXReader(); - return reader.read(new FileInputStream(new File(testResources, "navigation.xml"))); - } - - public void testCollapsed() throws Exception - { - testCollapsed("/alpha/index.html", "/alpha/index.html", false); - testCollapsed("/alpha/one/index.html", "/alpha/index.html", false); - testCollapsed("/alpha/two/index.html", "/alpha/index.html", false); - testCollapsed("/beta/index.html", "/alpha/index.html", true); - - testCollapsed("/alpha/index.html", "/beta/index.html", false); - testCollapsed("/alpha/one/index.html", "/beta/index.html", false); - testCollapsed("/alpha/two/index.html", "/beta/index.html", false); - testCollapsed("/beta/index.html", "/beta/index.html", false); - testCollapsed("/beta/one/index.html", "/beta/index.html", true); - testCollapsed("/beta/two/index.html", "/beta/index.html", true); - - testCollapsed("/alpha/index.html", "beta/index.html", false); - testCollapsed("/alpha/one/index.html", "beta/index.html", false); - testCollapsed("/alpha/two/index.html", "beta/index.html", false); - testCollapsed("/beta/index.html", "beta/index.html", false); - testCollapsed("/beta/one/index.html", "beta/index.html", true); - testCollapsed("/beta/two/index.html", "beta/index.html", true); - } - - public void testCollapsed(String href, String location, boolean expected) - { - nb.setLocation(location); - - Node node = nb.getFirstNodeByHREF(href); - assertNotNull(node); - - String s = "At location " + location + ", looking to generate link to " + href + ", expecting collapse = " + expected; - assertEquals(s, expected, nb.isCollapsed(node)); + this.href = newHref; + this.collapsed = newCollapsed; } + } }