KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > maven > ProducerMojo


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.maven;
19
20 import org.apache.activemq.tool.JmsProducerSystem;
21 import org.apache.maven.plugin.AbstractMojo;
22 import org.apache.maven.plugin.MojoExecutionException;
23
24 import java.util.List JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Properties JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Set JavaDoc;
29 import java.util.HashSet JavaDoc;
30
31 /**
32  * Goal which touches a timestamp file.
33  *
34  * @goal producer
35  * @phase process
36  */

37 public class ProducerMojo extends AbstractMojo {
38
39     private String JavaDoc[] validPrefix = {
40         "sysTest.",
41         "factory.",
42         "producer.",
43         "tpSampler.",
44         "cpuSampler."
45     };
46
47     public void execute() throws MojoExecutionException {
48         JmsProducerSystem.main(createArgument());
49     }
50
51     protected String JavaDoc[] createArgument() {
52         List JavaDoc args = new ArrayList JavaDoc();
53         Properties JavaDoc sysProps = System.getProperties();
54         Set JavaDoc keys = new HashSet JavaDoc(sysProps.keySet());
55
56         for (Iterator JavaDoc i=keys.iterator(); i.hasNext();) {
57             String JavaDoc key = (String JavaDoc)i.next();
58             if (isRecognizedProperty(key)) {
59                 args.add(key + "=" + sysProps.remove(key));
60             }
61         }
62         return (String JavaDoc[])args.toArray(new String JavaDoc[0]);
63     }
64
65     protected boolean isRecognizedProperty(String JavaDoc key) {
66         for (int j=0; j<validPrefix.length; j++) {
67             if (key.startsWith(validPrefix[j])) {
68                 return true;
69             }
70         }
71         return false;
72     }
73 }
74
Popular Tags