001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.geronimo.genesis.plugins.script;
021
022 import java.net.URL;
023 import java.io.File;
024
025 import org.apache.maven.plugin.MojoExecutionException;
026
027 /**
028 * Configuration for a scripts code source.
029 *
030 * @version $Rev: 463140 $ $Date: 2006-10-11 23:24:07 -0700 (Wed, 11 Oct 2006) $
031 */
032 public class CodeSource
033 {
034 private URL url = null;
035
036 private File file = null;
037
038 private String body = null;
039
040 public String toString() {
041 return "{ url: " + url +
042 ", file: " + file +
043 ", body: " + body +
044 " }";
045 }
046
047 public URL getUrl() {
048 return url;
049 }
050
051 public File getFile() {
052 return file;
053 }
054
055 public String getBody() {
056 return body;
057 }
058
059 public void validate() throws MojoExecutionException {
060 if (url == null && file == null && (body == null || body.trim().length() == 0)) {
061 throw new MojoExecutionException("Must specify one of: file, url or body");
062 }
063
064 int count = 0;
065 if (url != null) {
066 count++;
067 }
068 if (file != null) {
069 count++;
070 }
071 if (body != null) {
072 count++;
073 }
074
075 if (count != 1) {
076 throw new MojoExecutionException("Can only specify one of: file, url or body");
077 }
078 }
079 }