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 */ 019package org.apache.commons.weaver.ant; 020 021import org.apache.tools.ant.BuildException; 022import org.apache.tools.ant.Project; 023import org.apache.tools.ant.Task; 024import org.apache.tools.ant.types.Reference; 025 026/** 027 * Abstract weaver Ant task. Manages settings for filesystem-based weaving. 028 */ 029public abstract class AbstractWeaverTask extends Task { 030 private WeaverSettings settings; 031 032 /** 033 * Create a new {@link AbstractWeaverTask} instance. 034 * @param project owner 035 */ 036 protected AbstractWeaverTask(final Project project) { 037 super(); 038 setProject(project); 039 } 040 041 /** 042 * Add a nested {@link WeaverSettings}. 043 * @param settings to add 044 */ 045 public void add(final WeaverSettings settings) { 046 if (this.settings != null) { 047 throw new BuildException("settings already specified"); 048 } 049 this.settings = settings; 050 } 051 052 /** 053 * Get the {@link WeaverSettings} in use. 054 * @return {@link WeaverSettings} 055 */ 056 public WeaverSettings getSettings() { 057 return settings; 058 } 059 060 /** 061 * Set a project reference to a {@link WeaverSettings} object. 062 * @param refid key 063 */ 064 public void setSettingsRef(final String refid) { 065 final WeaverSettings settings = new WeaverSettings(getProject()); 066 settings.setRefid(new Reference(getProject(), refid)); 067 add(settings); 068 } 069 070}