+++ /dev/null
-/*\r
- *\r
- * Copyright 2004 The Ant-Contrib project\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package net.sf.antcontrib.cpptasks;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.tools.ant.types.DataType;\r
-\r
-/**\r
- * Local to remote filename mapping (Experimental).\r
- *\r
- */\r
-public final class DistributerMap\r
- extends DataType {\r
- /**\r
- * if property.\r
- */\r
- private String ifCond;\r
-\r
- /**\r
- * unless property.\r
- */\r
- private String unlessCond;\r
-\r
- /**\r
- * local directory name.\r
- *\r
- */\r
- private File localName;\r
-\r
- /**\r
- * Canonical local file name.\r
- */\r
- private String canonicalPath;\r
-\r
- /**\r
- * remote name.\r
- *\r
- */\r
- private String remoteName;\r
-\r
- /**\r
- * Separator (/ or \) character on remote system.\r
- */\r
- private char remoteSeparator = File.separatorChar;\r
-\r
- /**\r
- * hosts that for which this map is valid.\r
- *\r
- */\r
- private String hosts;\r
-\r
- /**\r
- * Constructor.\r
- *\r
- */\r
- public DistributerMap() {\r
- }\r
-\r
- /**\r
- * Required by documentation generator.\r
- */\r
- public void execute() {\r
- throw new org.apache.tools.ant.BuildException(\r
- "Not an actual task, but looks like one for documentation purposes");\r
- }\r
-\r
- /**\r
- * Returns true if the if and unless conditions (if any) are\r
- * satisfied.\r
- *\r
- * @return true if this object is active.\r
- */\r
- public boolean isActive() {\r
- return CUtil.isActive(getProject(), ifCond, unlessCond);\r
- }\r
-\r
- /**\r
- * Sets the property name for the 'if' condition.\r
- *\r
- * This object will be ignored unless the property is defined.\r
- *\r
- * The value of the property is insignificant, but values that would imply\r
- * misinterpretation ("false", "no") will throw an exception when\r
- * evaluated.\r
- *\r
- * @param propName\r
- * property name\r
- */\r
- public void setIf(final String propName) {\r
- ifCond = propName;\r
- }\r
-\r
- /**\r
- * Set the property name for the 'unless' condition.\r
- *\r
- * If named property is set, the define will be ignored.\r
- *\r
- * The value of the property is insignificant, but values that would imply\r
- * misinterpretation ("false", "no") of the behavior will throw an\r
- * exception when evaluated.\r
- *\r
- * @param propName\r
- * name of property\r
- */\r
- public void setUnless(final String propName) {\r
- unlessCond = propName;\r
- }\r
-\r
- /**\r
- * Gets local directory.\r
- * @return local directory, may be null.\r
- *\r
- */\r
- public File getLocal() {\r
- return localName;\r
- }\r
-\r
- /**\r
- * Gets remote name for directory.\r
- * @return remote name, may be null.\r
- *\r
- */\r
- public String getRemote() {\r
- return remoteName;\r
- }\r
-\r
- /**\r
- * Converts the local file name to the remote name for the same file.\r
- *\r
- * @param host host\r
- * @param localFile local file\r
- * @return remote name for local file, null if unknown.\r
- */\r
- public String toRemote(final String host, final File localFile) {\r
- if (remoteName != null\r
- && (hosts == null || hosts.indexOf(host) >= 0)) {\r
- try {\r
- String canonical = localFile.getCanonicalPath();\r
- if (canonical.startsWith(canonicalPath)) {\r
- if (isActive()) {\r
- return remoteName\r
- + canonical.substring(canonicalPath.length()).replace(File.\r
- separatorChar, remoteSeparator);\r
- }\r
- }\r
- } catch (IOException ex) {\r
- return null;\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- /**\r
- * Sets local directory for base of mapping.\r
- *\r
- * @param value value\r
- */\r
- public void setLocal(final File value) {\r
- if (value == null) {\r
- throw new NullPointerException("value");\r
- }\r
- if (value.exists() && !value.isDirectory()) {\r
- throw new BuildException("local should be a directory");\r
- }\r
- localName = value;\r
- try {\r
- canonicalPath = localName.getCanonicalPath();\r
- } catch (IOException ex) {\r
- throw new BuildException(ex);\r
- }\r
- }\r
-\r
- /**\r
- * Sets remote name for directory.\r
- * @param value remote name for directory\r
- */\r
- public void setRemote(final String value) {\r
- remoteName = value;\r
- }\r
-\r
- /**\r
- * Sets the separator character (/ or \) for the remote system.\r
- * @param value separator character\r
- */\r
- public void setRemoteSeparator(final String value) {\r
- if (value != null && value.length() != 1) {\r
- throw new BuildException("remote separator must be a single character");\r
- }\r
- remoteSeparator = value.charAt(0);\r
- }\r
-\r
- /**\r
- * Sets hosts for which this mapping is valid.\r
- *\r
- * @param value hosts\r
- */\r
- public void setHosts(final String value) {\r
- hosts = value;\r
- }\r
-\r
-}\r