001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.maven;
018    
019    import java.util.ArrayList;
020    import java.util.HashSet;
021    import java.util.Iterator;
022    import java.util.List;
023    import java.util.Properties;
024    import java.util.Set;
025    
026    import org.apache.activemq.tool.JmsConsumerSystem;
027    import org.apache.maven.plugin.AbstractMojo;
028    import org.apache.maven.plugin.MojoExecutionException;
029    
030    /**
031     * Goal which touches a timestamp file.
032     * 
033     * @goal consumer
034     * @phase process-sources
035     */
036    public class ConsumerMojo extends AbstractMojo {
037    
038        private String[] validPrefix = {
039            "sysTest.", "factory.", "consumer.", "tpSampler.", "cpuSampler."
040        };
041    
042        public void execute() throws MojoExecutionException {
043            JmsConsumerSystem.main(createArgument());
044        }
045    
046        protected String[] createArgument() {
047            List args = new ArrayList();
048            Properties sysProps = System.getProperties();
049            Set keys = new HashSet(sysProps.keySet());
050    
051            for (Iterator i = keys.iterator(); i.hasNext();) {
052                String key = (String)i.next();
053                if (isRecognizedProperty(key)) {
054                    args.add(key + "=" + sysProps.remove(key));
055                }
056            }
057            return (String[])args.toArray(new String[0]);
058        }
059    
060        protected boolean isRecognizedProperty(String key) {
061            for (int j = 0; j < validPrefix.length; j++) {
062                if (key.startsWith(validPrefix[j])) {
063                    return true;
064                }
065            }
066            return false;
067        }
068    }