--- /dev/null
+package org.apache.archiva.web.tags;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.archiva.web.util.ContextUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * CopyPasteSnippetTag
+ *
+ * @version $Id$
+ */
+public class CopyPasteSnippetTag
+ extends TagSupport
+{
+ private Logger log = LoggerFactory.getLogger( CopyPasteSnippetTag.class );
+
+ private Object object;
+
+ private String wrapper = PRE;
+
+ public static final String PRE = "pre";
+
+ public static final String TOGGLE = "toggle";
+
+ @Override
+ public void release()
+ {
+ object = null;
+ super.release();
+ }
+
+ @Override
+ public int doEndTag()
+ throws JspException
+ {
+ StringBuilder prefix = new StringBuilder();
+ StringBuilder buf = new StringBuilder();
+ StringBuilder suffix = new StringBuilder();
+
+ if ( object == null )
+ {
+ buf.append( "Error generating snippet." );
+ log.error( "Unable to generate snippet for null object." );
+ }
+ else if ( object instanceof ManagedRepositoryConfiguration )
+ {
+ ManagedRepositoryConfiguration repo = (ManagedRepositoryConfiguration) object;
+
+ if ( TOGGLE.equals( wrapper ) )
+ {
+ prefix.append( "<a href=\"#\" class=\"expand\">Show POM Snippet</a><br/>" );
+ prefix.append( "<pre class=\"pom\"><code>" );
+
+ suffix.append( "</code></pre>" );
+ }
+ else if ( PRE.equals( wrapper ) )
+ {
+ prefix.append( "<pre>" );
+ suffix.append( "</pre>" );
+ }
+
+ createSnippet( buf, repo, pageContext );
+ }
+ else
+ {
+ buf.append( "Unable to generate snippet for object " ).append( object.getClass().getName() );
+ }
+
+ try
+ {
+ JspWriter out = pageContext.getOut();
+
+ out.write( prefix.toString() );
+ out.write( StringEscapeUtils.escapeXml( buf.toString() ) );
+ out.write( suffix.toString() );
+
+ out.flush();
+ }
+ catch ( IOException e )
+ {
+ throw new JspException( "Unable to write snippet to output: " + e.getMessage(), e );
+ }
+
+ return super.doEndTag();
+ }
+
+ public void setObject( Object object )
+ {
+ this.object = object;
+ }
+
+ public void setWrapper( String wrapper )
+ {
+ this.wrapper = wrapper;
+ }
+
+ private void createSnippet( StringBuilder snippet, ManagedRepositoryConfiguration repo, PageContext pageContext )
+ {
+ snippet.append( "<project>\n" );
+ snippet.append( " ...\n" );
+ snippet.append( " <distributionManagement>\n" );
+
+ String distRepoName = "repository";
+ if ( repo.isSnapshots() )
+ {
+ distRepoName = "snapshotRepository";
+ }
+
+ snippet.append( " <" ).append( distRepoName ).append( ">\n" );
+ snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" );
+ snippet.append( " <url>" ).append( ContextUtils.getBaseURL( pageContext, "repository" ) );
+ snippet.append( "/" ).append( repo.getId() ).append( "/" ).append( "</url>\n" );
+
+ if ( !"default".equals( repo.getLayout() ) )
+ {
+ snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>" );
+ }
+
+ snippet.append( " </" ).append( distRepoName ).append( ">\n" );
+ snippet.append( " </distributionManagement>\n" );
+ snippet.append( "\n" );
+
+ snippet.append( " <repositories>\n" );
+ snippet.append( " <repository>\n" );
+ snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" );
+ snippet.append( " <name>" ).append( repo.getName() ).append( "</name>\n" );
+
+ snippet.append( " <url>" );
+ snippet.append( ContextUtils.getBaseURL( pageContext, "repository" ) );
+ snippet.append( "/" ).append( repo.getId() ).append( "/" );
+
+ snippet.append( "</url>\n" );
+
+ if ( !"default".equals( repo.getLayout() ) )
+ {
+ snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" );
+ }
+
+ snippet.append( " <releases>\n" );
+ snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append( "</enabled>\n" );
+ snippet.append( " </releases>\n" );
+ snippet.append( " <snapshots>\n" );
+ snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append( "</enabled>\n" );
+ snippet.append( " </snapshots>\n" );
+ snippet.append( " </repository>\n" );
+ snippet.append( " </repositories>\n" );
+
+ snippet.append( " ...\n" );
+ snippet.append( "</project>\n" );
+ }
+}
--- /dev/null
+package org.apache.archiva.web.tags;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.opensymphony.xwork2.ActionContext;
+import org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.maven.archiva.model.Keys;
+import org.apache.maven.archiva.security.ArchivaXworkUser;
+import org.apache.maven.archiva.security.UserRepositories;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * DependencyTree
+ *
+ * @version $Id$
+ * plexus.component role="org.apache.archiva.web.tags.DependencyTree"
+ */
+@Service( "dependencyTree" )
+public class DependencyTree
+{
+ private Logger log = LoggerFactory.getLogger( DependencyTree.class );
+
+ /**
+ * plexus.requirement role-hint="maven2"
+ */
+ @Inject
+ private DependencyTreeBuilder dependencyTreeBuilder;
+
+ /**
+ * plexus.requirement
+ */
+ @Inject
+ private UserRepositories userRepositories;
+
+ public static class TreeEntry
+ {
+ private String pre = "";
+
+ private String post = "";
+
+ private Artifact artifact;
+
+ public void setArtifact( Artifact artifact )
+ {
+ this.artifact = artifact;
+ }
+
+ public Artifact getArtifact()
+ {
+ return artifact;
+ }
+
+ public String getPost()
+ {
+ return post;
+ }
+
+ public String getPre()
+ {
+ return pre;
+ }
+
+ public void appendPre( String string )
+ {
+ this.pre += string;
+ }
+
+ public void appendPost( String string )
+ {
+ this.post += string;
+ }
+ }
+
+ public List<TreeEntry> gatherTreeList( String groupId, String artifactId, String modelVersion )
+ throws ArchivaException
+ {
+ if ( StringUtils.isBlank( groupId ) )
+ {
+ String emsg = "Error generating dependency tree [" + Keys.toKey( groupId, artifactId, modelVersion )
+ + "]: groupId is blank.";
+ log.error( emsg );
+ throw new ArchivaException( emsg );
+ }
+
+ if ( StringUtils.isBlank( artifactId ) )
+ {
+ String emsg = "Error generating dependency tree [" + Keys.toKey( groupId, artifactId, modelVersion )
+ + "]: artifactId is blank.";
+ log.error( emsg );
+ throw new ArchivaException( emsg );
+ }
+
+ if ( StringUtils.isBlank( modelVersion ) )
+ {
+ String emsg = "Error generating dependency tree [" + Keys.toKey( groupId, artifactId, modelVersion )
+ + "]: version is blank.";
+ log.error( emsg );
+ throw new ArchivaException( emsg );
+ }
+
+ // TODO Cache the results to disk, in XML format, in the same place as the artifact is located.
+
+ TreeListVisitor visitor = new TreeListVisitor();
+ try
+ {
+ dependencyTreeBuilder.buildDependencyTree( userRepositories.getObservableRepositoryIds( getPrincipal() ),
+ groupId, artifactId, modelVersion, visitor );
+ }
+ catch ( DependencyTreeBuilderException e )
+ {
+ throw new ArchivaException( "Unable to build dependency tree: " + e.getMessage(), e );
+ }
+
+ return visitor.getList();
+ }
+
+ private String getPrincipal()
+ {
+ return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
+ }
+
+ private static class TreeListVisitor
+ implements DependencyNodeVisitor
+ {
+ private List<TreeEntry> list;
+
+ private TreeEntry currentEntry;
+
+ boolean firstChild = true;
+
+ private DependencyNode firstNode;
+
+ public TreeListVisitor()
+ {
+ this.list = new ArrayList<TreeEntry>();
+ }
+
+ public List<TreeEntry> getList()
+ {
+ return this.list;
+ }
+
+ public boolean visit( DependencyNode node )
+ {
+ if ( firstNode == null )
+ {
+ firstNode = node;
+ }
+
+ currentEntry = new TreeEntry();
+
+ if ( firstChild )
+ {
+ currentEntry.appendPre( "<ul>" );
+ }
+
+ currentEntry.appendPre( "<li>" );
+ currentEntry.setArtifact( node.getArtifact() );
+ currentEntry.appendPost( "</li>" );
+ this.list.add( currentEntry );
+
+ if ( !node.getChildren().isEmpty() )
+ {
+ firstChild = true;
+ }
+
+ return true;
+ }
+
+ public boolean endVisit( DependencyNode node )
+ {
+ firstChild = false;
+
+ if ( !node.getChildren().isEmpty() )
+ {
+ currentEntry.appendPost( "</ul>" );
+ }
+
+ if ( node == firstNode )
+ {
+ currentEntry.appendPost( "</ul>" );
+ }
+
+ return true;
+ }
+ }
+}
--- /dev/null
+package org.apache.archiva.web.tags;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.archiva.web.tags.DependencyTree.TreeEntry;
+import org.springframework.beans.BeansException;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.IterationTag;
+import javax.servlet.jsp.tagext.TagSupport;
+import javax.servlet.jsp.tagext.TryCatchFinally;
+
+/**
+ * DependencyTreeTag - just here to output the dependency tree to the browser.
+ * It was easier to do it this way, vs accessing the dependency graph via a JSP.
+ *
+ * <pre>
+ * <archiva:dependency-tree groupId="org.apache.maven.archiva"
+ * artifactId="archiva-common"
+ * version="1.0"
+ * nodevar="node">
+ * <b>${node.groupId}</b>:<b>${node.artifactId}</b>:<b>${node.version}</b> (${node.scope})
+ * </archiva:dependency-tree>
+ * </pre>
+ *
+ * @version $Id$
+ */
+public class DependencyTreeTag
+ extends TagSupport
+ implements IterationTag, TryCatchFinally
+{
+ private String groupId;
+
+ private String artifactId;
+
+ @SuppressWarnings("unused")
+ private String version;
+
+ private String nodevar;
+
+ private Iterator<TreeEntry> treeIterator;
+
+ private List<TreeEntry> tree;
+
+ private TreeEntry currentTreeEntry;
+
+ private String modelVersion;
+
+ public int doAfterBody()
+ throws JspException
+ {
+ if ( currentTreeEntry != null )
+ {
+ out( currentTreeEntry.getPost() );
+ }
+
+ if ( treeIterator.hasNext() )
+ {
+ currentTreeEntry = treeIterator.next();
+ out( currentTreeEntry.getPre() );
+ exposeVariables();
+ return EVAL_BODY_AGAIN;
+ }
+
+ out( "\n</div><!-- end of dependency-graph -->" );
+
+ return SKIP_BODY;
+ }
+
+ public void doCatch( Throwable t )
+ throws Throwable
+ {
+ throw t;
+ }
+
+ public void doFinally()
+ {
+ unExposeVariables();
+ }
+
+ @SuppressWarnings("unchecked")
+ public int doStartTag()
+ throws JspException
+ {
+ DependencyTree deptree;
+ try
+ {
+ WebApplicationContext webApplicationContext =
+ WebApplicationContextUtils.getRequiredWebApplicationContext( pageContext.getServletContext() );
+
+ deptree = webApplicationContext.getBean( "dependencyTree", DependencyTree.class );
+ }
+ catch ( BeansException e )
+ {
+ throw new JspException( "Unable to lookup DependencyTree: " + e.getMessage(), e );
+ }
+
+ if ( deptree == null )
+ {
+ throw new JspException( "Unable to process dependency tree. Component not found." );
+ }
+
+ if ( StringUtils.isBlank( nodevar ) )
+ {
+ nodevar = "node";
+ }
+
+ out( "<div class=\"dependency-graph\">" );
+ try
+ {
+ this.tree = deptree.gatherTreeList( groupId, artifactId, modelVersion );
+
+ if ( CollectionUtils.isEmpty( this.tree ) )
+ {
+ return SKIP_BODY;
+ }
+
+ treeIterator = tree.iterator();
+
+ currentTreeEntry = treeIterator.next();
+ out( currentTreeEntry.getPre() );
+ exposeVariables();
+ }
+ catch ( ArchivaException e )
+ {
+ treeIterator = IteratorUtils.EMPTY_LIST_ITERATOR;
+
+ out("<pre>");
+ e.printStackTrace( new PrintWriter( pageContext.getOut() ) );
+ out("</pre>");
+ }
+
+ return EVAL_BODY_INCLUDE;
+ }
+
+ public void release()
+ {
+ groupId = "";
+ artifactId = "";
+ version = "";
+ nodevar = "";
+ tree = null;
+ treeIterator = null;
+ super.release();
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ public void setNodevar( String nodevar )
+ {
+ this.nodevar = nodevar;
+ }
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+
+ public void setModelVersion( String modelVersion )
+ {
+ this.modelVersion = modelVersion;
+ }
+
+ private void exposeVariables()
+ throws JspException
+ {
+ if ( currentTreeEntry == null )
+ {
+ pageContext.removeAttribute( nodevar, PageContext.PAGE_SCOPE );
+ }
+ else
+ {
+ pageContext.setAttribute( nodevar, currentTreeEntry.getArtifact() );
+ }
+ }
+
+ private void out( String msg )
+ throws JspException
+ {
+ try
+ {
+ pageContext.getOut().print( msg );
+ }
+ catch ( IOException e )
+ {
+ throw new JspException( "Unable to output to jsp page context." );
+ }
+ }
+
+ private void unExposeVariables()
+ {
+ pageContext.removeAttribute( nodevar, PageContext.PAGE_SCOPE );
+ }
+}
--- /dev/null
+package org.apache.archiva.web.tags;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
+import org.apache.taglibs.standard.tag.el.core.ExpressionUtil;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.Tag;
+
+/**
+ * ExpressionTool
+ *
+ * @version $Id$
+ */
+public class ExpressionTool
+{
+ private PageContext pageContext;
+
+ private Tag tag;
+
+ private String tagName;
+
+ public ExpressionTool( PageContext pageContext, Tag tag, String tagName )
+ {
+ this.pageContext = pageContext;
+ this.tag = tag;
+ this.tagName = tagName;
+ }
+
+ public boolean optionalBoolean( String propertyName, String expression, boolean defaultValue )
+ throws JspException
+ {
+ try
+ {
+ Boolean ret = (Boolean) ExpressionUtil.evalNotNull( this.tagName, propertyName, expression, Boolean.class,
+ this.tag, this.pageContext );
+
+ if ( ret == null )
+ {
+ return defaultValue;
+ }
+
+ return ret.booleanValue();
+ }
+ catch ( NullAttributeException e )
+ {
+ return defaultValue;
+ }
+ }
+
+ public String optionalString( String propertyName, String expression, String defaultValue )
+ throws JspException
+ {
+ try
+ {
+ String ret = (String) ExpressionUtil.evalNotNull( this.tagName, propertyName, expression, String.class,
+ this.tag, this.pageContext );
+
+ if ( ret == null )
+ {
+ return defaultValue;
+ }
+
+ return ret;
+ }
+ catch ( NullAttributeException e )
+ {
+ return defaultValue;
+ }
+ }
+
+ public String requiredString( String propertyName, String expression )
+ throws JspException
+ {
+ try
+ {
+ String ret = (String) ExpressionUtil.evalNotNull( this.tagName, propertyName, expression, String.class,
+ this.tag, this.pageContext );
+ return ret;
+ }
+ catch ( NullAttributeException e )
+ {
+ String emsg = "Required " + this.tagName + " property [" + propertyName + "] is null!";
+
+ log( emsg, e );
+ throw new JspException( emsg );
+ }
+ }
+
+ private void log( String msg, Throwable t )
+ {
+ pageContext.getServletContext().log( msg, t );
+ }
+}
--- /dev/null
+package org.apache.archiva.web.tags;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.struts2.StrutsException;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.StringTokenizer;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * GroupIdLink
+ *
+ * @version $Id$
+ */
+public class GroupIdLink
+ extends Component
+{
+ private static final String ACTION = "browseGroup";
+
+ private static final String NAMESPACE = "/";
+
+ private static final boolean includeContext = true;
+
+ private static final boolean encode = true;
+
+ private static final String method = null;
+
+ private HttpServletRequest req;
+
+ private HttpServletResponse res;
+
+ private String groupId;
+
+ private boolean includeTop = false;
+
+ public GroupIdLink( ValueStack stack, HttpServletRequest req, HttpServletResponse res )
+ {
+ super( stack );
+ this.req = req;
+ this.res = res;
+ }
+
+ @Override
+ public boolean end( Writer writer, String body )
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "<span class=\"groupId\">" );
+
+ if ( includeTop )
+ {
+ sb.append( "<a href=\"" );
+ sb.append( determineBrowseActionUrl() );
+ sb.append( "\">[top]</a> / " ); // TODO: i18n
+ }
+
+ StringTokenizer tok = new StringTokenizer( groupId, "." );
+ String cumulativeGroup = null;
+
+ while ( tok.hasMoreTokens() )
+ {
+ String token = tok.nextToken();
+
+ if ( cumulativeGroup == null )
+ {
+ cumulativeGroup = token;
+ }
+ else
+ {
+ cumulativeGroup += "." + token;
+ }
+ sb.append( "<a href=\"" );
+ sb.append( determineBrowseGroupActionUrl( cumulativeGroup ) );
+ sb.append( "\">" ).append( token ).append( "</a> / " );
+ }
+
+ sb.append( "</span>" );
+
+ try
+ {
+ writer.write( sb.toString() );
+ }
+ catch ( IOException e )
+ {
+ throw new StrutsException( "IOError: " + e.getMessage(), e );
+ }
+
+ return super.end( writer, body );
+ }
+
+ private String determineBrowseActionUrl()
+ {
+ return determineActionURL( "browse", NAMESPACE, method, req, res, parameters, req.getScheme(), includeContext, encode, false, false );
+ }
+
+ @SuppressWarnings("unchecked")
+ private String determineBrowseGroupActionUrl( String gid )
+ {
+ parameters.put( "groupId", gid );
+
+ return determineActionURL( ACTION, NAMESPACE, method, req, res, parameters, req.getScheme(), includeContext, encode, false, false );
+ }
+
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ public boolean isIncludeTop()
+ {
+ return includeTop;
+ }
+
+ public void setIncludeTop( boolean includeTop )
+ {
+ this.includeTop = includeTop;
+ }
+
+}
--- /dev/null
+package org.apache.archiva.web.tags;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.opensymphony.xwork2.util.ValueStack;
+import org.apache.struts2.components.Component;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+import org.apache.struts2.views.jsp.ComponentTagSupport;
+
+/**
+ * GroupIdLink
+ *
+ * @version $Id$
+ */
+public class GroupIdLinkTag
+ extends ComponentTagSupport
+{
+ private String var_; // stores EL-based property
+
+ private String var; // stores the evaluated object.
+
+ private boolean includeTop = false;
+
+ @Override
+ public Component getBean(ValueStack valueStack, HttpServletRequest request, HttpServletResponse response) {
+ return new GroupIdLink( valueStack, request, response );
+ }
+
+ @Override
+ public void release()
+ {
+ var_ = null;
+ var = null;
+ includeTop = false;
+
+ super.release();
+ }
+
+ @Override
+ public int doEndTag()
+ throws JspException
+ {
+ evaluateExpressions();
+
+ GroupIdLink groupIdLink = (GroupIdLink)component;
+
+ groupIdLink.setGroupId( var );
+ groupIdLink.setIncludeTop( includeTop );
+
+ return super.doEndTag();
+ }
+
+ private void evaluateExpressions()
+ throws JspException
+ {
+ ExpressionTool exprTool = new ExpressionTool( pageContext, this, "groupIdLink" );
+
+ var = exprTool.optionalString( "var", var_, "" );
+ }
+
+ public void setVar( String value )
+ {
+ this.var_ = value;
+ }
+
+ public void setIncludeTop( boolean includeTop )
+ {
+ this.includeTop = includeTop;
+ }
+}
+++ /dev/null
-package org.apache.maven.archiva.web.tags;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.IOException;
-
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.JspWriter;
-import javax.servlet.jsp.PageContext;
-import javax.servlet.jsp.tagext.TagSupport;
-
-import org.apache.commons.lang.StringEscapeUtils;
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.archiva.web.util.ContextUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * CopyPasteSnippetTag
- *
- * @version $Id$
- */
-public class CopyPasteSnippetTag
- extends TagSupport
-{
- private Logger log = LoggerFactory.getLogger( CopyPasteSnippetTag.class );
-
- private Object object;
-
- private String wrapper = PRE;
-
- public static final String PRE = "pre";
-
- public static final String TOGGLE = "toggle";
-
- @Override
- public void release()
- {
- object = null;
- super.release();
- }
-
- @Override
- public int doEndTag()
- throws JspException
- {
- StringBuilder prefix = new StringBuilder();
- StringBuilder buf = new StringBuilder();
- StringBuilder suffix = new StringBuilder();
-
- if ( object == null )
- {
- buf.append( "Error generating snippet." );
- log.error( "Unable to generate snippet for null object." );
- }
- else if ( object instanceof ManagedRepositoryConfiguration )
- {
- ManagedRepositoryConfiguration repo = (ManagedRepositoryConfiguration) object;
-
- if ( TOGGLE.equals( wrapper ) )
- {
- prefix.append( "<a href=\"#\" class=\"expand\">Show POM Snippet</a><br/>" );
- prefix.append( "<pre class=\"pom\"><code>" );
-
- suffix.append( "</code></pre>" );
- }
- else if ( PRE.equals( wrapper ) )
- {
- prefix.append( "<pre>" );
- suffix.append( "</pre>" );
- }
-
- createSnippet( buf, repo, pageContext );
- }
- else
- {
- buf.append( "Unable to generate snippet for object " ).append( object.getClass().getName() );
- }
-
- try
- {
- JspWriter out = pageContext.getOut();
-
- out.write( prefix.toString() );
- out.write( StringEscapeUtils.escapeXml( buf.toString() ) );
- out.write( suffix.toString() );
-
- out.flush();
- }
- catch ( IOException e )
- {
- throw new JspException( "Unable to write snippet to output: " + e.getMessage(), e );
- }
-
- return super.doEndTag();
- }
-
- public void setObject( Object object )
- {
- this.object = object;
- }
-
- public void setWrapper( String wrapper )
- {
- this.wrapper = wrapper;
- }
-
- private void createSnippet( StringBuilder snippet, ManagedRepositoryConfiguration repo, PageContext pageContext )
- {
- snippet.append( "<project>\n" );
- snippet.append( " ...\n" );
- snippet.append( " <distributionManagement>\n" );
-
- String distRepoName = "repository";
- if ( repo.isSnapshots() )
- {
- distRepoName = "snapshotRepository";
- }
-
- snippet.append( " <" ).append( distRepoName ).append( ">\n" );
- snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" );
- snippet.append( " <url>" ).append( ContextUtils.getBaseURL( pageContext, "repository" ) );
- snippet.append( "/" ).append( repo.getId() ).append( "/" ).append( "</url>\n" );
-
- if ( !"default".equals( repo.getLayout() ) )
- {
- snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>" );
- }
-
- snippet.append( " </" ).append( distRepoName ).append( ">\n" );
- snippet.append( " </distributionManagement>\n" );
- snippet.append( "\n" );
-
- snippet.append( " <repositories>\n" );
- snippet.append( " <repository>\n" );
- snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" );
- snippet.append( " <name>" ).append( repo.getName() ).append( "</name>\n" );
-
- snippet.append( " <url>" );
- snippet.append( ContextUtils.getBaseURL( pageContext, "repository" ) );
- snippet.append( "/" ).append( repo.getId() ).append( "/" );
-
- snippet.append( "</url>\n" );
-
- if ( !"default".equals( repo.getLayout() ) )
- {
- snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" );
- }
-
- snippet.append( " <releases>\n" );
- snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append( "</enabled>\n" );
- snippet.append( " </releases>\n" );
- snippet.append( " <snapshots>\n" );
- snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append( "</enabled>\n" );
- snippet.append( " </snapshots>\n" );
- snippet.append( " </repository>\n" );
- snippet.append( " </repositories>\n" );
-
- snippet.append( " ...\n" );
- snippet.append( "</project>\n" );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.web.tags;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import com.opensymphony.xwork2.ActionContext;
-import org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder;
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.ArchivaException;
-import org.apache.maven.archiva.model.Keys;
-import org.apache.maven.archiva.security.ArchivaXworkUser;
-import org.apache.maven.archiva.security.UserRepositories;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.shared.dependency.tree.DependencyNode;
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
-import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-
-import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * DependencyTree
- *
- * @version $Id$
- * plexus.component role="org.apache.maven.archiva.web.tags.DependencyTree"
- */
-@Service( "dependencyTree" )
-public class DependencyTree
-{
- private Logger log = LoggerFactory.getLogger( DependencyTree.class );
-
- /**
- * plexus.requirement role-hint="maven2"
- */
- @Inject
- private DependencyTreeBuilder dependencyTreeBuilder;
-
- /**
- * plexus.requirement
- */
- @Inject
- private UserRepositories userRepositories;
-
- public static class TreeEntry
- {
- private String pre = "";
-
- private String post = "";
-
- private Artifact artifact;
-
- public void setArtifact( Artifact artifact )
- {
- this.artifact = artifact;
- }
-
- public Artifact getArtifact()
- {
- return artifact;
- }
-
- public String getPost()
- {
- return post;
- }
-
- public String getPre()
- {
- return pre;
- }
-
- public void appendPre( String string )
- {
- this.pre += string;
- }
-
- public void appendPost( String string )
- {
- this.post += string;
- }
- }
-
- public List<TreeEntry> gatherTreeList( String groupId, String artifactId, String modelVersion )
- throws ArchivaException
- {
- if ( StringUtils.isBlank( groupId ) )
- {
- String emsg = "Error generating dependency tree [" + Keys.toKey( groupId, artifactId, modelVersion )
- + "]: groupId is blank.";
- log.error( emsg );
- throw new ArchivaException( emsg );
- }
-
- if ( StringUtils.isBlank( artifactId ) )
- {
- String emsg = "Error generating dependency tree [" + Keys.toKey( groupId, artifactId, modelVersion )
- + "]: artifactId is blank.";
- log.error( emsg );
- throw new ArchivaException( emsg );
- }
-
- if ( StringUtils.isBlank( modelVersion ) )
- {
- String emsg = "Error generating dependency tree [" + Keys.toKey( groupId, artifactId, modelVersion )
- + "]: version is blank.";
- log.error( emsg );
- throw new ArchivaException( emsg );
- }
-
- // TODO Cache the results to disk, in XML format, in the same place as the artifact is located.
-
- TreeListVisitor visitor = new TreeListVisitor();
- try
- {
- dependencyTreeBuilder.buildDependencyTree( userRepositories.getObservableRepositoryIds( getPrincipal() ),
- groupId, artifactId, modelVersion, visitor );
- }
- catch ( DependencyTreeBuilderException e )
- {
- throw new ArchivaException( "Unable to build dependency tree: " + e.getMessage(), e );
- }
-
- return visitor.getList();
- }
-
- private String getPrincipal()
- {
- return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
- }
-
- private static class TreeListVisitor
- implements DependencyNodeVisitor
- {
- private List<TreeEntry> list;
-
- private TreeEntry currentEntry;
-
- boolean firstChild = true;
-
- private DependencyNode firstNode;
-
- public TreeListVisitor()
- {
- this.list = new ArrayList<TreeEntry>();
- }
-
- public List<TreeEntry> getList()
- {
- return this.list;
- }
-
- public boolean visit( DependencyNode node )
- {
- if ( firstNode == null )
- {
- firstNode = node;
- }
-
- currentEntry = new TreeEntry();
-
- if ( firstChild )
- {
- currentEntry.appendPre( "<ul>" );
- }
-
- currentEntry.appendPre( "<li>" );
- currentEntry.setArtifact( node.getArtifact() );
- currentEntry.appendPost( "</li>" );
- this.list.add( currentEntry );
-
- if ( !node.getChildren().isEmpty() )
- {
- firstChild = true;
- }
-
- return true;
- }
-
- public boolean endVisit( DependencyNode node )
- {
- firstChild = false;
-
- if ( !node.getChildren().isEmpty() )
- {
- currentEntry.appendPost( "</ul>" );
- }
-
- if ( node == firstNode )
- {
- currentEntry.appendPost( "</ul>" );
- }
-
- return true;
- }
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.web.tags;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.IteratorUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.common.ArchivaException;
-import org.apache.maven.archiva.web.tags.DependencyTree.TreeEntry;
-import org.springframework.beans.BeansException;
-import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.support.WebApplicationContextUtils;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.PageContext;
-import javax.servlet.jsp.tagext.IterationTag;
-import javax.servlet.jsp.tagext.TagSupport;
-import javax.servlet.jsp.tagext.TryCatchFinally;
-
-/**
- * DependencyTreeTag - just here to output the dependency tree to the browser.
- * It was easier to do it this way, vs accessing the dependency graph via a JSP.
- *
- * <pre>
- * <archiva:dependency-tree groupId="org.apache.maven.archiva"
- * artifactId="archiva-common"
- * version="1.0"
- * nodevar="node">
- * <b>${node.groupId}</b>:<b>${node.artifactId}</b>:<b>${node.version}</b> (${node.scope})
- * </archiva:dependency-tree>
- * </pre>
- *
- * @version $Id$
- */
-public class DependencyTreeTag
- extends TagSupport
- implements IterationTag, TryCatchFinally
-{
- private String groupId;
-
- private String artifactId;
-
- @SuppressWarnings("unused")
- private String version;
-
- private String nodevar;
-
- private Iterator<TreeEntry> treeIterator;
-
- private List<TreeEntry> tree;
-
- private TreeEntry currentTreeEntry;
-
- private String modelVersion;
-
- public int doAfterBody()
- throws JspException
- {
- if ( currentTreeEntry != null )
- {
- out( currentTreeEntry.getPost() );
- }
-
- if ( treeIterator.hasNext() )
- {
- currentTreeEntry = treeIterator.next();
- out( currentTreeEntry.getPre() );
- exposeVariables();
- return EVAL_BODY_AGAIN;
- }
-
- out( "\n</div><!-- end of dependency-graph -->" );
-
- return SKIP_BODY;
- }
-
- public void doCatch( Throwable t )
- throws Throwable
- {
- throw t;
- }
-
- public void doFinally()
- {
- unExposeVariables();
- }
-
- @SuppressWarnings("unchecked")
- public int doStartTag()
- throws JspException
- {
- DependencyTree deptree;
- try
- {
- WebApplicationContext webApplicationContext =
- WebApplicationContextUtils.getRequiredWebApplicationContext( pageContext.getServletContext() );
-
- deptree = webApplicationContext.getBean( "dependencyTree", DependencyTree.class );
- }
- catch ( BeansException e )
- {
- throw new JspException( "Unable to lookup DependencyTree: " + e.getMessage(), e );
- }
-
- if ( deptree == null )
- {
- throw new JspException( "Unable to process dependency tree. Component not found." );
- }
-
- if ( StringUtils.isBlank( nodevar ) )
- {
- nodevar = "node";
- }
-
- out( "<div class=\"dependency-graph\">" );
- try
- {
- this.tree = deptree.gatherTreeList( groupId, artifactId, modelVersion );
-
- if ( CollectionUtils.isEmpty( this.tree ) )
- {
- return SKIP_BODY;
- }
-
- treeIterator = tree.iterator();
-
- currentTreeEntry = treeIterator.next();
- out( currentTreeEntry.getPre() );
- exposeVariables();
- }
- catch ( ArchivaException e )
- {
- treeIterator = IteratorUtils.EMPTY_LIST_ITERATOR;
-
- out("<pre>");
- e.printStackTrace( new PrintWriter( pageContext.getOut() ) );
- out("</pre>");
- }
-
- return EVAL_BODY_INCLUDE;
- }
-
- public void release()
- {
- groupId = "";
- artifactId = "";
- version = "";
- nodevar = "";
- tree = null;
- treeIterator = null;
- super.release();
- }
-
- public void setArtifactId( String artifactId )
- {
- this.artifactId = artifactId;
- }
-
- public void setGroupId( String groupId )
- {
- this.groupId = groupId;
- }
-
- public void setNodevar( String nodevar )
- {
- this.nodevar = nodevar;
- }
-
- public void setVersion( String version )
- {
- this.version = version;
- }
-
- public void setModelVersion( String modelVersion )
- {
- this.modelVersion = modelVersion;
- }
-
- private void exposeVariables()
- throws JspException
- {
- if ( currentTreeEntry == null )
- {
- pageContext.removeAttribute( nodevar, PageContext.PAGE_SCOPE );
- }
- else
- {
- pageContext.setAttribute( nodevar, currentTreeEntry.getArtifact() );
- }
- }
-
- private void out( String msg )
- throws JspException
- {
- try
- {
- pageContext.getOut().print( msg );
- }
- catch ( IOException e )
- {
- throw new JspException( "Unable to output to jsp page context." );
- }
- }
-
- private void unExposeVariables()
- {
- pageContext.removeAttribute( nodevar, PageContext.PAGE_SCOPE );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.web.tags;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
-import org.apache.taglibs.standard.tag.el.core.ExpressionUtil;
-
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.PageContext;
-import javax.servlet.jsp.tagext.Tag;
-
-/**
- * ExpressionTool
- *
- * @version $Id$
- */
-public class ExpressionTool
-{
- private PageContext pageContext;
-
- private Tag tag;
-
- private String tagName;
-
- public ExpressionTool( PageContext pageContext, Tag tag, String tagName )
- {
- this.pageContext = pageContext;
- this.tag = tag;
- this.tagName = tagName;
- }
-
- public boolean optionalBoolean( String propertyName, String expression, boolean defaultValue )
- throws JspException
- {
- try
- {
- Boolean ret = (Boolean) ExpressionUtil.evalNotNull( this.tagName, propertyName, expression, Boolean.class,
- this.tag, this.pageContext );
-
- if ( ret == null )
- {
- return defaultValue;
- }
-
- return ret.booleanValue();
- }
- catch ( NullAttributeException e )
- {
- return defaultValue;
- }
- }
-
- public String optionalString( String propertyName, String expression, String defaultValue )
- throws JspException
- {
- try
- {
- String ret = (String) ExpressionUtil.evalNotNull( this.tagName, propertyName, expression, String.class,
- this.tag, this.pageContext );
-
- if ( ret == null )
- {
- return defaultValue;
- }
-
- return ret;
- }
- catch ( NullAttributeException e )
- {
- return defaultValue;
- }
- }
-
- public String requiredString( String propertyName, String expression )
- throws JspException
- {
- try
- {
- String ret = (String) ExpressionUtil.evalNotNull( this.tagName, propertyName, expression, String.class,
- this.tag, this.pageContext );
- return ret;
- }
- catch ( NullAttributeException e )
- {
- String emsg = "Required " + this.tagName + " property [" + propertyName + "] is null!";
-
- log( emsg, e );
- throw new JspException( emsg );
- }
- }
-
- private void log( String msg, Throwable t )
- {
- pageContext.getServletContext().log( msg, t );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.web.tags;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.struts2.StrutsException;
-import org.apache.struts2.components.Component;
-
-import com.opensymphony.xwork2.util.ValueStack;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.StringTokenizer;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * GroupIdLink
- *
- * @version $Id$
- */
-public class GroupIdLink
- extends Component
-{
- private static final String ACTION = "browseGroup";
-
- private static final String NAMESPACE = "/";
-
- private static final boolean includeContext = true;
-
- private static final boolean encode = true;
-
- private static final String method = null;
-
- private HttpServletRequest req;
-
- private HttpServletResponse res;
-
- private String groupId;
-
- private boolean includeTop = false;
-
- public GroupIdLink( ValueStack stack, HttpServletRequest req, HttpServletResponse res )
- {
- super( stack );
- this.req = req;
- this.res = res;
- }
-
- @Override
- public boolean end( Writer writer, String body )
- {
- StringBuilder sb = new StringBuilder();
-
- sb.append( "<span class=\"groupId\">" );
-
- if ( includeTop )
- {
- sb.append( "<a href=\"" );
- sb.append( determineBrowseActionUrl() );
- sb.append( "\">[top]</a> / " ); // TODO: i18n
- }
-
- StringTokenizer tok = new StringTokenizer( groupId, "." );
- String cumulativeGroup = null;
-
- while ( tok.hasMoreTokens() )
- {
- String token = tok.nextToken();
-
- if ( cumulativeGroup == null )
- {
- cumulativeGroup = token;
- }
- else
- {
- cumulativeGroup += "." + token;
- }
- sb.append( "<a href=\"" );
- sb.append( determineBrowseGroupActionUrl( cumulativeGroup ) );
- sb.append( "\">" ).append( token ).append( "</a> / " );
- }
-
- sb.append( "</span>" );
-
- try
- {
- writer.write( sb.toString() );
- }
- catch ( IOException e )
- {
- throw new StrutsException( "IOError: " + e.getMessage(), e );
- }
-
- return super.end( writer, body );
- }
-
- private String determineBrowseActionUrl()
- {
- return determineActionURL( "browse", NAMESPACE, method, req, res, parameters, req.getScheme(), includeContext, encode, false, false );
- }
-
- @SuppressWarnings("unchecked")
- private String determineBrowseGroupActionUrl( String gid )
- {
- parameters.put( "groupId", gid );
-
- return determineActionURL( ACTION, NAMESPACE, method, req, res, parameters, req.getScheme(), includeContext, encode, false, false );
- }
-
- public String getGroupId()
- {
- return groupId;
- }
-
- public void setGroupId( String groupId )
- {
- this.groupId = groupId;
- }
-
- public boolean isIncludeTop()
- {
- return includeTop;
- }
-
- public void setIncludeTop( boolean includeTop )
- {
- this.includeTop = includeTop;
- }
-
-}
+++ /dev/null
-package org.apache.maven.archiva.web.tags;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import com.opensymphony.xwork2.util.ValueStack;
-import org.apache.struts2.components.Component;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.jsp.JspException;
-import org.apache.struts2.views.jsp.ComponentTagSupport;
-
-/**
- * GroupIdLink
- *
- * @version $Id$
- */
-public class GroupIdLinkTag
- extends ComponentTagSupport
-{
- private String var_; // stores EL-based property
-
- private String var; // stores the evaluated object.
-
- private boolean includeTop = false;
-
- @Override
- public Component getBean(ValueStack valueStack, HttpServletRequest request, HttpServletResponse response) {
- return new GroupIdLink( valueStack, request, response );
- }
-
- @Override
- public void release()
- {
- var_ = null;
- var = null;
- includeTop = false;
-
- super.release();
- }
-
- @Override
- public int doEndTag()
- throws JspException
- {
- evaluateExpressions();
-
- GroupIdLink groupIdLink = (GroupIdLink)component;
-
- groupIdLink.setGroupId( var );
- groupIdLink.setIncludeTop( includeTop );
-
- return super.doEndTag();
- }
-
- private void evaluateExpressions()
- throws JspException
- {
- ExpressionTool exprTool = new ExpressionTool( pageContext, this, "groupIdLink" );
-
- var = exprTool.optionalString( "var", var_, "" );
- }
-
- public void setVar( String value )
- {
- this.var_ = value;
- }
-
- public void setIncludeTop( boolean includeTop )
- {
- this.includeTop = includeTop;
- }
-}
<tag>
<name>groupIdLink</name>
- <tag-class>org.apache.maven.archiva.web.tags.GroupIdLinkTag</tag-class>
+ <tag-class>org.apache.archiva.web.tags.GroupIdLinkTag</tag-class>
<body-content>empty</body-content>
<description><![CDATA[Render a groupId as a set of Links]]></description>
<tag>
<name>copy-paste-snippet</name>
- <tag-class>org.apache.maven.archiva.web.tags.CopyPasteSnippetTag</tag-class>
+ <tag-class>org.apache.archiva.web.tags.CopyPasteSnippetTag</tag-class>
<body-content>empty</body-content>
<description><![CDATA[Render a copy paste snippet for the provided object]]></description>
<tag>
<name>dependency-tree</name>
- <tag-class>org.apache.maven.archiva.web.tags.DependencyTreeTag</tag-class>
+ <tag-class>org.apache.archiva.web.tags.DependencyTreeTag</tag-class>
<body-content>JSP</body-content>
<description><![CDATA[Render a dependency tree for the provided project.]]></description>
--- /dev/null
+package org.apache.archiva.web.tags;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.ValueStackFactory;
+import junit.framework.TestCase;
+import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
+import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
+import org.apache.maven.archiva.common.ArchivaException;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.List;
+import javax.inject.Inject;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml",
+ "classpath:/spring-context-DependencyTreeTest.xml"} )
+public class DependencyTreeTest
+ extends TestCase
+{
+ @Inject
+ private DependencyTree tree;
+
+ @Inject
+ private PlexusSisuBridge plexusSisuBridge;
+
+ @Inject
+ private ApplicationContext applicationContext;
+
+ private ArtifactFactory artifactFactory;
+
+ private static final String TEST_VERSION = "version";
+
+ private static final String TEST_REPO_ID = "test-repo";
+
+ private static final String TEST_GROUP_ID = "groupId";
+
+ private static final String TEST_ARTIFACT_ID = "artifactId";
+
+
+ @Override
+ @Before
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ConfigurationManager configurationManager = new ConfigurationManager();
+ configurationManager.addContainerProvider( new XWorkConfigurationProvider() );
+ com.opensymphony.xwork2.config.Configuration config = configurationManager.getConfiguration();
+ Container container = config.getContainer();
+
+ ValueStack stack = container.getInstance( ValueStackFactory.class ).createValueStack();
+ stack.getContext().put( ActionContext.CONTAINER, container );
+ ActionContext.setContext( new ActionContext( stack.getContext() ) );
+
+ assertNotNull( ActionContext.getContext() );
+
+ Configuration configuration = new Configuration();
+ ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
+ repoConfig.setId( TEST_REPO_ID );
+ repoConfig.setLocation( "src/test/repositories/test" );
+ configuration.addManagedRepository( repoConfig );
+
+ ArchivaConfiguration archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class );
+ archivaConfiguration.save( configuration );
+
+ artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
+
+ TestMetadataResolver metadataResolver = applicationContext.getBean( TestMetadataResolver.class );
+ ProjectVersionMetadata metadata = new ProjectVersionMetadata();
+ metadata.setId( TEST_VERSION );
+ metadataResolver.setProjectVersion( TEST_REPO_ID, TEST_GROUP_ID, TEST_ARTIFACT_ID, metadata );
+
+ RepositorySession repositorySession = mock( RepositorySession.class );
+ when( repositorySession.getResolver() ).thenReturn( metadataResolver );
+ TestRepositorySessionFactory repositorySessionFactory =
+ applicationContext.getBean( TestRepositorySessionFactory.class );
+ repositorySessionFactory.setRepositorySession( repositorySession );
+ }
+
+ @Test
+ public void testTree()
+ throws ArchivaException
+ {
+ List<DependencyTree.TreeEntry> entries = tree.gatherTreeList( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
+ assertEquals( 8, entries.size() );
+
+ DependencyTree.TreeEntry artifactId = entries.get( 0 );
+ assertEquals( "<ul><li>", artifactId.getPre() );
+ assertEquals( createPomArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ), artifactId.getArtifact() );
+ assertEquals( "</li>", artifactId.getPost() );
+
+ DependencyTree.TreeEntry child1 = entries.get( 1 );
+ assertEquals( "<ul><li>", child1.getPre() );
+ assertEquals( createArtifact( TEST_GROUP_ID, "child1", "1.0" ), child1.getArtifact() );
+ assertEquals( "</li>", child1.getPost() );
+
+ DependencyTree.TreeEntry grandchild = entries.get( 2 );
+ assertEquals( "<ul><li>", grandchild.getPre() );
+ assertEquals( createArtifact( TEST_GROUP_ID, "grandchild1", "2.0" ), grandchild.getArtifact() );
+ assertEquals( "</li>", grandchild.getPost() );
+
+ DependencyTree.TreeEntry greatGrandchild = entries.get( 3 );
+ assertEquals( "<ul><li>", greatGrandchild.getPre() );
+ assertEquals( createArtifact( TEST_GROUP_ID, "great-grandchild", "3.0" ), greatGrandchild.getArtifact() );
+ assertEquals( "</li></ul></ul>", greatGrandchild.getPost() );
+
+ DependencyTree.TreeEntry child2 = entries.get( 4 );
+ assertEquals( "<li>", child2.getPre() );
+ assertEquals( createArtifact( TEST_GROUP_ID, "child2", "1.0" ), child2.getArtifact() );
+ assertEquals( "</li>", child2.getPost() );
+
+ DependencyTree.TreeEntry grandchild2 = entries.get( 5 );
+ assertEquals( "<ul><li>", grandchild2.getPre() );
+ assertEquals( createArtifact( TEST_GROUP_ID, "grandchild2", "2.0" ), grandchild2.getArtifact() );
+ assertEquals( "</li>", grandchild2.getPost() );
+
+ DependencyTree.TreeEntry grandchild3 = entries.get( 6 );
+ assertEquals( "<li>", grandchild3.getPre() );
+ assertEquals( createArtifact( TEST_GROUP_ID, "grandchild3", "2.0" ), grandchild3.getArtifact() );
+ assertEquals( "</li></ul>", grandchild3.getPost() );
+
+ DependencyTree.TreeEntry child3 = entries.get( 7 );
+ assertEquals( "<li>", child3.getPre() );
+ assertEquals( createArtifact( TEST_GROUP_ID, "child3", "1.0" ), child3.getArtifact() );
+ assertEquals( "</li></ul></ul>", child3.getPost() );
+ }
+
+ private Artifact createPomArtifact( String groupId, String artifactId, String version )
+ {
+ return artifactFactory.createProjectArtifact( groupId, artifactId, version );
+ }
+
+ private Artifact createArtifact( String groupId, String artifactId, String version )
+ {
+ return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );
+ }
+}
+++ /dev/null
-package org.apache.maven.archiva.web.tags;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.config.ConfigurationManager;
-import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
-import com.opensymphony.xwork2.inject.Container;
-import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.ValueStackFactory;
-import junit.framework.TestCase;
-import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
-import org.apache.archiva.metadata.model.ProjectVersionMetadata;
-import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
-import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
-import org.apache.maven.archiva.common.ArchivaException;
-import org.apache.maven.archiva.configuration.ArchivaConfiguration;
-import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.context.ApplicationContext;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import java.util.List;
-import javax.inject.Inject;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml",
- "classpath:/spring-context-DependencyTreeTest.xml"} )
-public class DependencyTreeTest
- extends TestCase
-{
- @Inject
- private DependencyTree tree;
-
- @Inject
- private PlexusSisuBridge plexusSisuBridge;
-
- @Inject
- private ApplicationContext applicationContext;
-
- private ArtifactFactory artifactFactory;
-
- private static final String TEST_VERSION = "version";
-
- private static final String TEST_REPO_ID = "test-repo";
-
- private static final String TEST_GROUP_ID = "groupId";
-
- private static final String TEST_ARTIFACT_ID = "artifactId";
-
-
- @Override
- @Before
- public void setUp()
- throws Exception
- {
- super.setUp();
-
- ConfigurationManager configurationManager = new ConfigurationManager();
- configurationManager.addContainerProvider( new XWorkConfigurationProvider() );
- com.opensymphony.xwork2.config.Configuration config = configurationManager.getConfiguration();
- Container container = config.getContainer();
-
- ValueStack stack = container.getInstance( ValueStackFactory.class ).createValueStack();
- stack.getContext().put( ActionContext.CONTAINER, container );
- ActionContext.setContext( new ActionContext( stack.getContext() ) );
-
- assertNotNull( ActionContext.getContext() );
-
- Configuration configuration = new Configuration();
- ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
- repoConfig.setId( TEST_REPO_ID );
- repoConfig.setLocation( "src/test/repositories/test" );
- configuration.addManagedRepository( repoConfig );
-
- ArchivaConfiguration archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class );
- archivaConfiguration.save( configuration );
-
- artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
-
- TestMetadataResolver metadataResolver = applicationContext.getBean( TestMetadataResolver.class );
- ProjectVersionMetadata metadata = new ProjectVersionMetadata();
- metadata.setId( TEST_VERSION );
- metadataResolver.setProjectVersion( TEST_REPO_ID, TEST_GROUP_ID, TEST_ARTIFACT_ID, metadata );
-
- RepositorySession repositorySession = mock( RepositorySession.class );
- when( repositorySession.getResolver() ).thenReturn( metadataResolver );
- TestRepositorySessionFactory repositorySessionFactory =
- applicationContext.getBean( TestRepositorySessionFactory.class );
- repositorySessionFactory.setRepositorySession( repositorySession );
- }
-
- @Test
- public void testTree()
- throws ArchivaException
- {
- List<DependencyTree.TreeEntry> entries = tree.gatherTreeList( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
- assertEquals( 8, entries.size() );
-
- DependencyTree.TreeEntry artifactId = entries.get( 0 );
- assertEquals( "<ul><li>", artifactId.getPre() );
- assertEquals( createPomArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ), artifactId.getArtifact() );
- assertEquals( "</li>", artifactId.getPost() );
-
- DependencyTree.TreeEntry child1 = entries.get( 1 );
- assertEquals( "<ul><li>", child1.getPre() );
- assertEquals( createArtifact( TEST_GROUP_ID, "child1", "1.0" ), child1.getArtifact() );
- assertEquals( "</li>", child1.getPost() );
-
- DependencyTree.TreeEntry grandchild = entries.get( 2 );
- assertEquals( "<ul><li>", grandchild.getPre() );
- assertEquals( createArtifact( TEST_GROUP_ID, "grandchild1", "2.0" ), grandchild.getArtifact() );
- assertEquals( "</li>", grandchild.getPost() );
-
- DependencyTree.TreeEntry greatGrandchild = entries.get( 3 );
- assertEquals( "<ul><li>", greatGrandchild.getPre() );
- assertEquals( createArtifact( TEST_GROUP_ID, "great-grandchild", "3.0" ), greatGrandchild.getArtifact() );
- assertEquals( "</li></ul></ul>", greatGrandchild.getPost() );
-
- DependencyTree.TreeEntry child2 = entries.get( 4 );
- assertEquals( "<li>", child2.getPre() );
- assertEquals( createArtifact( TEST_GROUP_ID, "child2", "1.0" ), child2.getArtifact() );
- assertEquals( "</li>", child2.getPost() );
-
- DependencyTree.TreeEntry grandchild2 = entries.get( 5 );
- assertEquals( "<ul><li>", grandchild2.getPre() );
- assertEquals( createArtifact( TEST_GROUP_ID, "grandchild2", "2.0" ), grandchild2.getArtifact() );
- assertEquals( "</li>", grandchild2.getPost() );
-
- DependencyTree.TreeEntry grandchild3 = entries.get( 6 );
- assertEquals( "<li>", grandchild3.getPre() );
- assertEquals( createArtifact( TEST_GROUP_ID, "grandchild3", "2.0" ), grandchild3.getArtifact() );
- assertEquals( "</li></ul>", grandchild3.getPost() );
-
- DependencyTree.TreeEntry child3 = entries.get( 7 );
- assertEquals( "<li>", child3.getPre() );
- assertEquals( createArtifact( TEST_GROUP_ID, "child3", "1.0" ), child3.getArtifact() );
- assertEquals( "</li></ul></ul>", child3.getPost() );
- }
-
- private Artifact createPomArtifact( String groupId, String artifactId, String version )
- {
- return artifactFactory.createProjectArtifact( groupId, artifactId, version );
- }
-
- private Artifact createArtifact( String groupId, String artifactId, String version )
- {
- return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );
- }
-}