From: <jbo...@li...> - 2006-06-29 17:25:46
|
Author: wrzep Date: 2006-06-29 13:25:39 -0400 (Thu, 29 Jun 2006) New Revision: 4872 Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/LastNDaysStatusPlugin.java Removed: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/Tags.java Log: JBLAB-599 Configurable number of days in measuring deltas. Pawel Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/Tags.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/Tags.java 2006-06-29 16:34:35 UTC (rev 4871) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/Tags.java 2006-06-29 17:25:39 UTC (rev 4872) @@ -56,26 +56,29 @@ public static final String METRIC_NAME_ELEMENT = "name"; public static final String METRIC_PLUGIN_ELEMENT = "plugin"; - /* service.xml tags */ + /* service.properties tags */ public static final String SERVICE_REMOTE_ELEMENT = "service.remote"; /* plugins.xml tags */ + + /* plugin element*/ public final static String PLUGIN_ELEMENT = "plugin"; public final static String PLUGIN_ID_ELEMENT = "id"; public final static String PLUGIN_CLASS_ELEMENT = "class"; public final static String PLUGIN_PROPERTIES_ELEMENT = "properties"; + /* kosmos plugins */ public static final String JIRA_SERVICE_PROPERTY = "jira-service"; public static final String SVN_SERVICE_PROPERTY = "svn-service"; public static final String CC_SERVICE_PROPERTY = "cc-service"; public static final String CC_ADRESS_TAG = "cc-address"; + /* other plugins */ public static final String DAYS_TAG = "days"; + public static final String PLUGIN_TAG = "plugin"; - public static final String STATUS_SERVICE_NAME = "status:service=scores"; - /** * This class cannot be instatiated. */ Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java 2006-06-29 16:34:35 UTC (rev 4871) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java 2006-06-29 17:25:39 UTC (rev 4872) @@ -1,91 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - -package org.jboss.forge.status.plugins; - -import java.util.Calendar; -import java.util.Properties; - -import org.jboss.forge.common.projects.Projects; -import org.jboss.forge.status.exceptions.InvalidPluginPropertiesException; -import org.jboss.forge.status.exceptions.GetScoresException; -import org.jboss.forge.status.tools.Plugins; -import org.jboss.forge.status.tools.ScoresManager; - -/** -* @author Pawel Wrzeszcz (paw...@gm...) -* This plugin measures deltas in other plugin scores in a 7 days time. -*/ - -public class Last7DaysStatusPlugin extends Plugin { - - Plugin insidePlugin; - - @Override - public void init(String id, String portalName, Projects projects, - Plugins plugins, Properties properties) - throws InvalidPluginPropertiesException { - - if (properties == null) { - throw new InvalidPluginPropertiesException( - "Missing plugin property."); - } - - String insidePluginId = properties.getProperty("plugin"); - if (insidePluginId == null) { - throw new InvalidPluginPropertiesException( - "Missing \"plugin\" property."); - } - - insidePlugin = plugins.get(insidePluginId); - - if (insidePlugin == null) { - throw new InvalidPluginPropertiesException( - "Plugin " + insidePluginId + " not found."); - } - - super.init(id, portalName, projects, plugins, properties); - } - - @Override - public long getValue(String projectId) { - - long currentValue = insidePlugin.getValue(projectId); - long prevValue = 0; - - Calendar now = Calendar.getInstance(); - - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.DAY_OF_MONTH,-7); - - - try { - prevValue = ScoresManager.getValue( - insidePlugin.getId(), projectId, cal, now); - } catch (GetScoresException e) { - return 0; - } - - - return Math.max(currentValue - prevValue, 0); - } -} Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/LastNDaysStatusPlugin.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/LastNDaysStatusPlugin.java 2006-06-29 16:34:35 UTC (rev 4871) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/LastNDaysStatusPlugin.java 2006-06-29 17:25:39 UTC (rev 4872) @@ -0,0 +1,99 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.forge.status.plugins; + +import java.util.Calendar; +import java.util.Properties; + +import org.jboss.forge.common.projects.Projects; +import org.jboss.forge.status.common.Tags; +import org.jboss.forge.status.exceptions.InvalidPluginPropertiesException; +import org.jboss.forge.status.exceptions.GetScoresException; +import org.jboss.forge.status.tools.Plugins; +import org.jboss.forge.status.tools.ScoresManager; + +/** +* @author Pawel Wrzeszcz (paw...@gm...) +* This plugin measures deltas in other plugin scores in a 7 days time. +*/ + +public class LastNDaysStatusPlugin extends Plugin { + + private Plugin insidePlugin; + private int days; + + @Override + public void init(String id, String portalName, Projects projects, + Plugins plugins, Properties properties) + throws InvalidPluginPropertiesException { + + if (properties == null) { + throw new InvalidPluginPropertiesException( + "Missing plugin property."); + } + + String insidePluginId = properties.getProperty(Tags.PLUGIN_TAG); + if (insidePluginId == null) { + throw new InvalidPluginPropertiesException( + "Missing \"plugin\" property."); + } + + insidePlugin = plugins.get(insidePluginId); + + if (insidePlugin == null) { + throw new InvalidPluginPropertiesException( + "Plugin " + insidePluginId + " not found."); + } + + String daysString = properties.getProperty(Tags.DAYS_TAG); + if (daysString == null) { + throw new InvalidPluginPropertiesException( + "Missing \"days\" property."); + } + days = Integer.parseInt(daysString); + + super.init(id, portalName, projects, plugins, properties); + } + + @Override + public long getValue(String projectId) { + + long currentValue = insidePlugin.getValue(projectId); + long prevValue = 0; + + Calendar now = Calendar.getInstance(); + + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.DAY_OF_MONTH,-days); + + try { + prevValue = ScoresManager.getValue( + insidePlugin.getId(), projectId, cal, now); + } catch (GetScoresException e) { + return 0; + } + + + return Math.max(currentValue - prevValue, 0); + } +} |