Doxia/SwizzleMacro

HomePage | Doxia | RecentChanges | Preferences

In maven/site/pom.xml :

  <build>
  <plugins>
  <plugin>
  <artifactId>maven-site-plugin</artifactId>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven.doxia</groupId>
      <artifactId>doxia-core</artifactId>
      <version>1.0-alpha-9-SNAPSHOT</version>
    </dependency>
  </dependencies>
  </plugin>
  </plugins>
  </build>

In doxia-core,


package org.apache.maven.doxia.macro.swizzle;

/*
 * Copyright 2006 The Apache Software Foundation.
 *
 * Licensed 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.maven.doxia.macro.AbstractMacro;
import org.apache.maven.doxia.macro.MacroExecutionException;
import org.apache.maven.doxia.macro.MacroRequest;
import org.apache.maven.doxia.sink.Sink;
import org.codehaus.swizzle.jira.Version;
import org.codehaus.swizzle.jira.Jira;

import java.util.*;

/**
 * apt usage: %{swizzle|project=STR}
 * @plexus.component role="org.apache.maven.doxia.macro.Macro"
 * role-hint="swizzle"
 */
public class SwizzleMacro
        extends AbstractMacro {

    public void execute(Sink sink, MacroRequest request)
            throws MacroExecutionException {
        String project = (String) request.getParameter("project");

        System.out.println( "******************* SWIZZLE MACRO **********************" );

        required(project, "project");

        StringBuffer response = new StringBuffer();

        try {
            Jira jira = new Jira("http://issues.apache.org/struts/rpc/xmlrpc");
            jira.login("user", "pass");
            List versions = jira.getVersions(project);
            response.append("The latest release is ");
            response.append(getLatest(getReleasedVersions(versions)).getName());
        } catch (Exception ex) {
            throw new MacroExecutionException(ex.toString());
        }

        sink.verbatim(true);

        sink.text(response.toString());

        sink.verbatim_();
    }

    private void required(String id, String param) {
        if (id == null || "".equals(id)) {
            throw new IllegalArgumentException(param + " is a required parameter");
        }
    }

    private List getReleasedVersions(List list) {
        List newlist = new ArrayList();
        Iterator iter = list.iterator();
        while (iter.hasNext()) {
            Version v = (Version) iter.next();
            if (v.getReleased()) {
                newlist.add(v);
            }
        }
        return newlist;
    }

    private Version getLatest(List list) {

        Collections.sort(list);
        System.out.println("last release is " + list.get(list.size() - 1));
        return (Version) list.get(list.size() - 1);
    }

}


HomePage | Doxia | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited November 24, 2006 5:23 pm by WendySmoak (diff)
Search: