View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with 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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.geronimo.genesis.plugins.script;
21  
22  import java.net.URL;
23  import java.io.File;
24  
25  import org.apache.maven.plugin.MojoExecutionException;
26  
27  /**
28   * Configuration for a scripts code source.
29   *
30   * @version $Rev: 463140 $ $Date: 2006-10-11 23:24:07 -0700 (Wed, 11 Oct 2006) $
31   */
32  public class CodeSource
33  {
34      private URL url = null;
35  
36      private File file = null;
37  
38      private String body = null;
39  
40      public String toString() {
41          return "{ url: " + url +
42                 ", file: " + file +
43                 ", body: " + body +
44                 " }";
45      }
46  
47      public URL getUrl() {
48          return url;
49      }
50  
51      public File getFile() {
52          return file;
53      }
54  
55      public String getBody() {
56          return body;
57      }
58  
59      public void validate() throws MojoExecutionException {
60          if (url == null && file == null && (body == null || body.trim().length() == 0)) {
61              throw new MojoExecutionException("Must specify one of: file, url or body");
62          }
63  
64          int count = 0;
65          if (url != null) {
66              count++;
67          }
68          if (file != null) {
69              count++;
70          }
71          if (body != null) {
72              count++;
73          }
74  
75          if (count != 1) {
76              throw new MojoExecutionException("Can only specify one of: file, url or body");
77          }
78      }
79  }