本文整理汇总了Java中org.apache.tools.ant.MagicNames类的典型用法代码示例。如果您正苦于以下问题:Java MagicNames类的具体用法?Java MagicNames怎么用?Java MagicNames使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MagicNames类属于org.apache.tools.ant包,在下文中一共展示了MagicNames类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNow
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/**
* Return the {@link Date} instance to use as base for DSTAMP, TSTAMP and TODAY.
*
* @return Date
*/
protected Date getNow() {
Optional<Date> now = getNow(
MagicNames.TSTAMP_NOW_ISO,
s -> Date.from(Instant.parse(s)),
(k, v) -> "magic property " + k + " ignored as '" + v + "' is not in valid ISO pattern"
);
if (now.isPresent()) {
return now.get();
}
now = getNow(
MagicNames.TSTAMP_NOW,
s -> new Date(1000 * Long.parseLong(s)),
(k, v) -> "magic property " + k + " ignored as " + v + " is not a valid number"
);
return now.orElseGet(Date::new);
}
示例2: makeResourceFromURI
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/**
* This is where the logic to map from a URI to an antlib resource
* is kept.
* @param uri the xml namespace uri that to convert.
* @return the name of a resource. It may not exist
*/
public static String makeResourceFromURI(String uri) {
String path = uri.substring(MagicNames.ANTLIB_PREFIX.length());
String resource;
if (path.startsWith("//")) {
//handle new style full paths to an antlib, in which
//all but the forward slashes are allowed.
resource = path.substring("//".length());
if (!resource.endsWith(".xml")) {
//if we haven't already named an XML file, it gets antlib.xml
resource = resource + ANTLIB_XML;
}
} else {
//convert from a package to a path
resource = path.replace('.', '/') + ANTLIB_XML;
}
return resource;
}
示例3: newRegexp
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/***
* Create a new regular expression matcher instance.
*
* @param p Project whose ant.regexp.regexpimpl property will be used.
* @return the matcher instance
* @throws BuildException on error
*/
public Regexp newRegexp(Project p) throws BuildException {
String systemDefault;
if (p == null) {
systemDefault = System.getProperty(MagicNames.REGEXP_IMPL);
} else {
systemDefault = p.getProperty(MagicNames.REGEXP_IMPL);
}
if (systemDefault != null) {
return createRegexpInstance(systemDefault);
// TODO should we silently catch possible exceptions and try to
// load a different implementation?
}
return new Jdk14RegexpRegexp();
}
示例4: newRegexpMatcher
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/***
* Create a new regular expression instance.
*
* @param p Project whose ant.regexp.regexpimpl property will be used.
* @return the matcher
* @throws BuildException on error
*/
public RegexpMatcher newRegexpMatcher(Project p) throws BuildException {
String systemDefault;
if (p == null) {
systemDefault = System.getProperty(MagicNames.REGEXP_IMPL);
} else {
systemDefault = p.getProperty(MagicNames.REGEXP_IMPL);
}
if (systemDefault != null) {
return createInstance(systemDefault);
// TODO should we silently catch possible exceptions and try to
// load a different implementation?
}
return new Jdk14RegexpMatcher();
}
示例5: buildStarted
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
public void buildStarted(BuildEvent event) {
// set audit property helper that will help keep track of properties
// being set everywhere.
project = event.getProject();
PropertyHelper helper = new PropertyDebugHelper();
helper.setProject(project);
auditor = new DefaultAuditor();
((PropertyDebugHelper) helper).setAuditor(auditor);
// Is it better to set it as a project helper or as a delegate to the
// helper?
project.addReference(MagicNames.REFID_PROPERTY_HELPER, helper);
commandHandler.setProject(project);
commandHandler.init(getDefaultCommandSupport());
prompt = new DebugPrompt(project, commandHandler);
auditor.setPrompt(prompt);
// this is how the debugging starts
prompt.prompt("Type /? to get any help.");
}
示例6: assertCallTargetState
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
public static void assertCallTargetState(final MockCallTargetTask task, final boolean executed,
final String target, final boolean inheritAll, final boolean inheritRefs,
final Map<String, Object> properties, final Map<String, Object> references)
{
Assert.assertEquals(executed, task.executed);
Assert.assertEquals(target, task.target);
Assert.assertEquals(inheritAll, task.inheritAll);
Assert.assertEquals(inheritRefs, task.inheritRefs);
final Map<?, ?> actualProperties = task.ownProject.getProperties();
actualProperties.remove(MagicNames.PROJECT_BASEDIR);
actualProperties.remove(MagicNames.ANT_FILE);
Assert.assertEquals(properties, actualProperties);
assertReferences(task.ownProject, references);
}
示例7: importBuild
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
public void importBuild(Object antBuildFile, Transformer<? extends String, ? super String> taskNamer) {
File file = gradleProject.file(antBuildFile);
final File baseDir = file.getParentFile();
Set<String> existingAntTargets = new HashSet<String>(getAntProject().getTargets().keySet());
File oldBaseDir = getAntProject().getBaseDir();
getAntProject().setBaseDir(baseDir);
try {
getAntProject().setUserProperty(MagicNames.ANT_FILE, file.getAbsolutePath());
ProjectHelper.configureProject(getAntProject(), file);
} catch (Exception e) {
throw new GradleException("Could not import Ant build file '" + String.valueOf(file) + "'.", e);
} finally {
getAntProject().setBaseDir(oldBaseDir);
}
// Chuck away the implicit target. It has already been executed
getAntProject().getTargets().remove("");
// Add an adapter for each newly added target
Set<String> newAntTargets = new HashSet<String>(getAntProject().getTargets().keySet());
newAntTargets.removeAll(existingAntTargets);
for (String name : newAntTargets) {
final Target target = getAntProject().getTargets().get(name);
String taskName = taskNamer.transform(target.getName());
final AntTarget task = gradleProject.getTasks().create(taskName, AntTarget.class);
configureTask(target, task, baseDir, taskNamer);
}
}
示例8: get
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/**
* Get a localproperties for the given project.
* @param project the project to retrieve the localproperties for.
* @return the localproperties.
*/
public static synchronized LocalProperties get(Project project) {
LocalProperties l =
project.getReference(MagicNames.REFID_LOCAL_PROPERTIES);
if (l == null) {
l = new LocalProperties();
project.addReference(MagicNames.REFID_LOCAL_PROPERTIES, l);
PropertyHelper.getPropertyHelper(project).add(l);
}
return l;
}
示例9: concatSpecialPath
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/**
* Concatenates a class path in the order specified by the
* ${build.sysclasspath} property - using the supplied value if
* ${build.sysclasspath} has not been set.
*/
private Path concatSpecialPath(String defValue, Path p) {
Path result = new Path(getProject());
String order = defValue;
String o = getProject() != null
? getProject().getProperty(MagicNames.BUILD_SYSCLASSPATH)
: System.getProperty(MagicNames.BUILD_SYSCLASSPATH);
if (o != null) {
order = o;
}
if ("only".equals(order)) {
// only: the developer knows what (s)he is doing
result.addExisting(p, true);
} else if ("first".equals(order)) {
// first: developer could use a little help
result.addExisting(p, true);
result.addExisting(this);
} else if ("ignore".equals(order)) {
// ignore: don't trust anyone
result.addExisting(this);
} else {
// last: don't trust the developer
if (!"last".equals(order)) {
log("invalid value for " + MagicNames.BUILD_SYSCLASSPATH
+ ": " + order,
Project.MSG_WARN);
}
result.addExisting(this);
result.addExisting(p, true);
}
return result;
}
示例10: execute
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/**
* Execute the task.
* @throws BuildException on error.
*/
@Override
public void execute() throws BuildException {
if (getProject() == null) {
throw new BuildException("Project instance not set");
}
if (propertyHelper == null && delegates == null) {
throw new BuildException(
"Either a new PropertyHelper or one or more PropertyHelper delegates are required");
}
PropertyHelper ph = propertyHelper;
if (ph == null) {
ph = PropertyHelper.getPropertyHelper(getProject());
} else {
ph = propertyHelper;
}
synchronized (ph) {
if (delegates != null) {
for (Object o : delegates) {
PropertyHelper.Delegate delegate = o instanceof DelegateElement
? ((DelegateElement) o).resolve() : (PropertyHelper.Delegate) o;
log("Adding PropertyHelper delegate " + delegate, Project.MSG_DEBUG);
ph.add(delegate);
}
}
}
if (propertyHelper != null) {
log("Installing PropertyHelper " + propertyHelper, Project.MSG_DEBUG);
// TODO copy existing properties to new PH?
getProject().addReference(MagicNames.REFID_PROPERTY_HELPER, propertyHelper);
}
}
示例11: execute
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/**
* Execute the task.
*
* @throws BuildException if the task fails.
*/
@Override
public void execute() throws BuildException {
validate();
final Manifest manifest = new Manifest();
final Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION);
attributes.putValue(CREATED_BY, "Apache Ant "
+ getProject().getProperty(MagicNames.ANT_VERSION));
appendExtraAttributes(attributes);
if (null != extension) {
Extension.addExtension(extension, attributes);
}
//Add all the dependency data to manifest for dependencies
final List<Extension> depends = toExtensions(dependencies);
appendExtensionList(attributes, Extension.EXTENSION_LIST, "lib", depends.size());
appendLibraryList(attributes, "lib", depends);
// Add all the dependency data to manifest for "optional"
//dependencies
final List<Extension> option = toExtensions(optionals);
appendExtensionList(attributes, Extension.OPTIONAL_EXTENSION_LIST, "opt", option.size());
appendLibraryList(attributes, "opt", option);
try {
log("Generating manifest " + destFile.getAbsoluteFile(), Project.MSG_INFO);
writeManifest(manifest);
} catch (final IOException ioe) {
throw new BuildException(ioe.getMessage(), ioe);
}
}
示例12: lookupScriptRepository
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/**
* Finds or creates the script repository - it is stored in the project.
* This method is synchronized on the project under {@link MagicNames#SCRIPT_REPOSITORY}
* @return the current script repository registered as a reference.
*/
private Map<String, ScriptDef> lookupScriptRepository() {
Map<String, ScriptDef> scriptRepository;
Project p = getProject();
synchronized (p) {
scriptRepository =
p.getReference(MagicNames.SCRIPT_REPOSITORY);
if (scriptRepository == null) {
scriptRepository = new HashMap<>();
p.addReference(MagicNames.SCRIPT_REPOSITORY,
scriptRepository);
}
}
return scriptRepository;
}
示例13: getScript
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
private ScriptDef getScript() {
String name = getTaskType();
Map<String, ScriptDef> scriptRepository =
getProject().getReference(MagicNames.SCRIPT_REPOSITORY);
if (scriptRepository == null) {
throw new BuildException("Script repository not found for " + name);
}
ScriptDef definition = scriptRepository.get(getTaskType());
if (definition == null) {
throw new BuildException("Script definition not found for " + name);
}
return definition;
}
示例14: addAlmostAll
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/**
* Copies all properties from the given table to the new project -
* omitting those that have already been set in the new project as
* well as properties named basedir or ant.file.
* @param props properties <code>Hashtable</code> to copy to the
* new project.
* @param type the type of property to set (a plain Ant property, a
* user property or an inherited property).
* @since Ant 1.8.0
*/
private void addAlmostAll(Map<?, ?> props, PropertyType type) {
props.forEach((k, v) -> {
String key = k.toString();
if (MagicNames.PROJECT_BASEDIR.equals(key)
|| MagicNames.ANT_FILE.equals(key)) {
// basedir and ant.file get special treatment in execute()
return;
}
String value = v.toString();
switch (type) {
case PLAIN:
// don't re-set user properties, avoid the warning message
if (newProject.getProperty(key) == null) {
// no user property
newProject.setNewProperty(key, value);
}
break;
case USER:
newProject.setUserProperty(key, value);
break;
case INHERITED:
newProject.setInheritedProperty(key, value);
break;
}
});
}
示例15: exec
import org.apache.tools.ant.MagicNames; //导入依赖的package包/类
/**
* Launches the given command in a new process, in the given
* working directory.
*
* @param project
* the Ant project.
* @param cmd
* the command line to execute as an array of strings.
* @param env
* the environment to set as an array of strings.
* @param workingDir
* working directory where the command should run.
* @return the created Process.
* @throws IOException
* forwarded from the exec method of the command launcher.
*/
@Override
public Process exec(Project project, String[] cmd, String[] env,
File workingDir) throws IOException {
if (project == null) {
if (workingDir == null) {
return exec(project, cmd, env);
}
throw new IOException(
"Cannot locate antRun script: No project provided");
}
// Locate the auxiliary script
String antHome = project.getProperty(MagicNames.ANT_HOME);
if (antHome == null) {
throw new IOException("Cannot locate antRun script: Property '"
+ MagicNames.ANT_HOME + "' not found");
}
String antRun = FILE_UTILS.resolveFile(project.getBaseDir(),
antHome + File.separator
+ myScript).toString();
// Build the command
File commandDir = workingDir;
if (workingDir == null) {
commandDir = project.getBaseDir();
}
String[] newcmd = new String[cmd.length + 2];
newcmd[0] = antRun;
newcmd[1] = commandDir.getAbsolutePath();
System.arraycopy(cmd, 0, newcmd, 2, cmd.length);
return exec(project, newcmd, env);
}