本文整理汇总了Java中org.apache.tools.ant.ProjectHelper.addLocationToBuildException方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectHelper.addLocationToBuildException方法的具体用法?Java ProjectHelper.addLocationToBuildException怎么用?Java ProjectHelper.addLocationToBuildException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.ant.ProjectHelper
的用法示例。
在下文中一共展示了ProjectHelper.addLocationToBuildException方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadAntlib
import org.apache.tools.ant.ProjectHelper; //导入方法依赖的package包/类
/**
* Load an antlib from a URL.
*
* @param classLoader the classloader to use.
* @param url the url to load the definitions from.
*/
private void loadAntlib(ClassLoader classLoader, URL url) {
try {
Antlib antlib = Antlib.createAntlib(getProject(), url, getURI());
antlib.setClassLoader(classLoader);
antlib.setURI(getURI());
antlib.execute();
} catch (BuildException ex) {
throw ProjectHelper.addLocationToBuildException(
ex, getLocation());
}
}
示例2: execute
import org.apache.tools.ant.ProjectHelper; //导入方法依赖的package包/类
/**
* Execute the templates instance.
* Copies the unknown element, substitutes the attributes,
* and calls perform on the unknown element.
*
*/
@Override
public void execute() {
presentElements = new HashMap<>();
getNsElements();
processTasks();
localAttributes = new Hashtable<>();
Set<String> copyKeys = new HashSet<>(map.keySet());
for (Attribute attribute : macroDef.getAttributes()) {
String value = map.get(attribute.getName());
if (value == null && "description".equals(attribute.getName())) {
value = getDescription();
}
if (value == null) {
value = attribute.getDefault();
value = macroSubs(value, localAttributes);
}
if (value == null) {
throw new BuildException("required attribute %s not set",
attribute.getName());
}
localAttributes.put(attribute.getName(), value);
copyKeys.remove(attribute.getName());
}
copyKeys.remove("id");
if (macroDef.getText() != null) {
if (text == null) {
String defaultText = macroDef.getText().getDefault();
if (!macroDef.getText().getOptional() && defaultText == null) {
throw new BuildException("required text missing");
}
text = defaultText == null ? "" : defaultText;
}
if (macroDef.getText().getTrim()) {
text = text.trim();
}
localAttributes.put(macroDef.getText().getName(), text);
} else if (!(text == null || text.trim().isEmpty())) {
throw new BuildException(
"The \"%s\" macro does not support nested text data.",
getTaskName());
}
if (!copyKeys.isEmpty()) {
throw new BuildException("Unknown attribute"
+ (copyKeys.size() > 1 ? "s " : " ") + copyKeys);
}
// need to set the project on unknown element
UnknownElement c = copy(macroDef.getNestedTask(), false);
c.init();
LocalProperties localProperties = LocalProperties.get(getProject());
localProperties.enterScope();
try {
c.perform();
} catch (BuildException ex) {
if (macroDef.getBackTrace()) {
throw ProjectHelper.addLocationToBuildException(
ex, getLocation());
} else {
ex.setLocation(getLocation());
throw ex;
}
} finally {
presentElements = null;
localAttributes = null;
localProperties.exitScope();
}
}
示例3: importResource
import org.apache.tools.ant.ProjectHelper; //导入方法依赖的package包/类
private void importResource(ProjectHelper helper,
Resource importedResource) {
getProject().log("Importing file " + importedResource + " from "
+ getLocation().getFileName(), Project.MSG_VERBOSE);
if (!importedResource.isExists()) {
String message =
"Cannot find " + importedResource + " imported from "
+ getLocation().getFileName();
if (optional) {
getProject().log(message, Project.MSG_VERBOSE);
return;
}
throw new BuildException(message);
}
if (!isInIncludeMode() && hasAlreadyBeenImported(importedResource,
helper.getImportStack())) {
getProject().log(
"Skipped already imported file:\n "
+ importedResource + "\n", Project.MSG_VERBOSE);
return;
}
// nested invocations are possible like an imported file
// importing another one
String oldPrefix = ProjectHelper.getCurrentTargetPrefix();
boolean oldIncludeMode = ProjectHelper.isInIncludeMode();
String oldSep = ProjectHelper.getCurrentPrefixSeparator();
try {
String prefix;
if (isInIncludeMode() && oldPrefix != null
&& targetPrefix != null) {
prefix = oldPrefix + oldSep + targetPrefix;
} else if (isInIncludeMode()) {
prefix = targetPrefix;
} else if (ProjectHelper.USE_PROJECT_NAME_AS_TARGET_PREFIX.equals(targetPrefix)) {
prefix = oldPrefix;
} else {
prefix = targetPrefix;
}
setProjectHelperProps(prefix, prefixSeparator,
isInIncludeMode());
ProjectHelper subHelper = ProjectHelperRepository.getInstance().getProjectHelperForBuildFile(
importedResource);
// push current stacks into the sub helper
subHelper.getImportStack().addAll(helper.getImportStack());
subHelper.getExtensionStack().addAll(helper.getExtensionStack());
getProject().addReference(ProjectHelper.PROJECTHELPER_REFERENCE, subHelper);
subHelper.parse(getProject(), importedResource);
// push back the stack from the sub helper to the main one
getProject().addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
helper.getImportStack().clear();
helper.getImportStack().addAll(subHelper.getImportStack());
helper.getExtensionStack().clear();
helper.getExtensionStack().addAll(subHelper.getExtensionStack());
} catch (BuildException ex) {
throw ProjectHelper.addLocationToBuildException(
ex, getLocation());
} finally {
setProjectHelperProps(oldPrefix, oldSep, oldIncludeMode);
}
}