KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > jtrac > maven > AntPropsSetenvMojo


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package info.jtrac.maven;
18
19 import java.io.FileInputStream JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import org.apache.maven.plugin.AbstractMojo;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.project.MavenProject;
28
29 /**
30  * @goal setenv
31  * @description load properties files before AntPropsMojo execution
32  */

33 public class AntPropsSetenvMojo extends AbstractMojo {
34     
35     /**
36      * @parameter expression="${project}"
37      */

38     private MavenProject project;
39
40     public void execute() throws MojoExecutionException {
41         getLog().info("executing antprops:setup");
42         InputStream JavaDoc is = null;
43         try {
44             try {
45                 is = new FileInputStream JavaDoc("build.properties");
46                 Properties JavaDoc props = new Properties JavaDoc();
47                 props.load(is);
48                 Properties JavaDoc mavenProps = project.getProperties();
49                 for (Iterator JavaDoc i = props.entrySet().iterator(); i.hasNext(); ) {
50                     Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
51                     mavenProps.put((String JavaDoc) entry.getKey(), (String JavaDoc) entry.getValue());
52                 }
53             } finally {
54                 is.close();
55             }
56         } catch (Exception JavaDoc e) {
57             e.printStackTrace();
58             throw new MojoExecutionException(e.getLocalizedMessage());
59         }
60     }
61
62 }
63
Popular Tags