| 1 | /* |
| 2 | * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. |
| 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 | package net.sf.antcontrib.platform; |
| 17 | |
| 18 | import org.apache.tools.ant.BuildException; |
| 19 | import org.apache.tools.ant.Task; |
| 20 | |
| 21 | /*** |
| 22 | * Task definition for the <code>OsFamily</code> task. |
| 23 | * This task sets the property indicated in the "property" |
| 24 | * attribute with the string representing the operating |
| 25 | * system family. Possible values include "unix", "dos", "mac" |
| 26 | * and "windows". |
| 27 | * |
| 28 | * <pre> |
| 29 | * |
| 30 | * Task Declaration: |
| 31 | * |
| 32 | * <code> |
| 33 | * <taskdef name="osfamily" classname="net.sf.antcontrib.platform.OsFamily" /> |
| 34 | * </code> |
| 35 | * |
| 36 | * Usage: |
| 37 | * <code> |
| 38 | * <osfamily property="propname" /> |
| 39 | * </code> |
| 40 | * |
| 41 | * Attributes: |
| 42 | * property --> The name of the property to set with the OS family name |
| 43 | * |
| 44 | * </pre> |
| 45 | * @author <a href="mailto:[email protected]">Matthew Inger</a> |
| 46 | */ |
| 47 | public class OsFamily extends Task |
| 48 | { |
| 49 | private String property; |
| 50 | |
| 51 | public OsFamily() |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | public void setProperty(String property) |
| 56 | { |
| 57 | this.property = property; |
| 58 | } |
| 59 | |
| 60 | public void execute() |
| 61 | throws BuildException |
| 62 | { |
| 63 | if (property == null) |
| 64 | throw new BuildException("The attribute 'property' is required " + |
| 65 | "for the OsFamily task."); |
| 66 | |
| 67 | String familyStr = Platform.getOsFamilyName(); |
| 68 | if (familyStr != null) |
| 69 | getProject().setProperty(property, familyStr); |
| 70 | } |
| 71 | |
| 72 | } |