-copy fileset **\*.java

本文介绍如何使用Apache Ant工具实现文件的自动化备份。通过配置XML文件指定源文件夹、目标文件夹及文件过滤条件,实现首次运行时文件完整备份,后续运行时仅更新已更改文件的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?xml version="1.0" encoding="UTF-8"?> 

<!--copy fileset **\*.java--> 
<project name="fileset" default="copyFile" basedir="..\">
	
	<description>拷贝文件到指定的文件夹</description>
	
	<fileset dir="src" includes="**\*.java" id="source.fileset" description="src文件夹及其子文件夹所有以java结尾的文件"></fileset>
	
	<target name="copyFile" description="拷贝文件">
		<copy todir="backup" description="若无此文件夹,自动创建">
			<fileset refid="source.fileset"></fileset>
		</copy>
	</target>
	
</project>

<!--
第一次执行ant

Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: D:\Workspaces\AntTest\src\build.xml
parsing buildfile D:\Workspaces\AntTest\src\build.xml with URI = file:/D:/Workspaces/AntTest/src/build.xml
Project base dir set to: D:\Workspaces\AntTest
parsing buildfile jar:file:/E:/JavaEE/Data/Ant/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/E:/JavaEE/Data/Ant/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `copyFile' is [copyFile]
Complete build sequence is [copyFile, ]
copyFile:
     [copy] Test2.java added as Test2.java doesn't exist.
     [copy] com\ankangqiao\HelloWorld.java added as com\ankangqiao\HelloWorld.java doesn't exist.
     [copy] com\bjpowernode\test\Test.java added as com\bjpowernode\test\Test.java doesn't exist.
     [copy] com\shengsiyuan\ant\custom\ApplicationException.java added as com\shengsiyuan\ant\custom\ApplicationException.java doesn't exist.
     [copy] com\shengsiyuan\ant\custom\FileSorter.java added as com\shengsiyuan\ant\custom\FileSorter.java doesn't exist.
     [copy] No sources found.
     [copy] Copying 5 files to D:\Workspaces\AntTest\backup
     [copy] Copying D:\Workspaces\AntTest\src\Test2.java to D:\Workspaces\AntTest\backup\Test2.java
     [copy] Copying D:\Workspaces\AntTest\src\com\ankangqiao\HelloWorld.java to D:\Workspaces\AntTest\backup\com\ankangqiao\HelloWorld.java
     [copy] Copying D:\Workspaces\AntTest\src\com\bjpowernode\test\Test.java to D:\Workspaces\AntTest\backup\com\bjpowernode\test\Test.java
     [copy] Copying D:\Workspaces\AntTest\src\com\shengsiyuan\ant\custom\ApplicationException.java to D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\ApplicationException.java
     [copy] Copying D:\Workspaces\AntTest\src\com\shengsiyuan\ant\custom\FileSorter.java to D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\FileSorter.java
BUILD SUCCESSFUL
Total time: 731 milliseconds




在没有任何改动的情况下,第二次执行ant

Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: D:\Workspaces\AntTest\src\build.xml
parsing buildfile D:\Workspaces\AntTest\src\build.xml with URI = file:/D:/Workspaces/AntTest/src/build.xml
Project base dir set to: D:\Workspaces\AntTest
parsing buildfile jar:file:/E:/JavaEE/Data/Ant/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/E:/JavaEE/Data/Ant/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `copyFile' is [copyFile]
Complete build sequence is [copyFile, ]
copyFile:
     [copy] Test2.java omitted as D:\Workspaces\AntTest\backup\Test2.java is up to date.
     [copy] com\ankangqiao\HelloWorld.java omitted as D:\Workspaces\AntTest\backup\com\ankangqiao\HelloWorld.java is up to date.
     [copy] com\bjpowernode\test\Test.java omitted as D:\Workspaces\AntTest\backup\com\bjpowernode\test\Test.java is up to date.
     [copy] com\shengsiyuan\ant\custom\ApplicationException.java omitted as D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\ApplicationException.java is up to date.
     [copy] com\shengsiyuan\ant\custom\FileSorter.java omitted as D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\FileSorter.java is up to date.
     [copy] No sources found.
BUILD SUCCESSFUL
Total time: 395 milliseconds
 
因为文件夹中的文件跟要拷贝的源文件的内容和名字完全一致,所以任务不再执行



第三次执行ant(对Test2.java做了修改)

Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: D:\Workspaces\AntTest\src\build.xml
parsing buildfile D:\Workspaces\AntTest\src\build.xml with URI = file:/D:/Workspaces/AntTest/src/build.xml
Project base dir set to: D:\Workspaces\AntTest
parsing buildfile jar:file:/E:/JavaEE/Data/Ant/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/E:/JavaEE/Data/Ant/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `copyFile' is [copyFile]
Complete build sequence is [copyFile, ]
copyFile:
     [copy] Test2.java added as Test2.java is outdated.
     [copy] com\ankangqiao\HelloWorld.java omitted as D:\Workspaces\AntTest\backup\com\ankangqiao\HelloWorld.java is up to date.
     [copy] com\bjpowernode\test\Test.java omitted as D:\Workspaces\AntTest\backup\com\bjpowernode\test\Test.java is up to date.
     [copy] com\shengsiyuan\ant\custom\ApplicationException.java omitted as D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\ApplicationException.java is up to date.
     [copy] com\shengsiyuan\ant\custom\FileSorter.java omitted as D:\Workspaces\AntTest\backup\com\shengsiyuan\ant\custom\FileSorter.java is up to date.
     [copy] No sources found.
     [copy] Copying 1 file to D:\Workspaces\AntTest\backup
     [copy] Copying D:\Workspaces\AntTest\src\Test2.java to D:\Workspaces\AntTest\backup\Test2.java
BUILD SUCCESSFUL
Total time: 411 milliseconds

虽然Test2.java在目标文件夹中已经存在,但是源文件已经做了修改,ant认为目标文件夹中得文件已经过时,需要覆盖掉,所以拷贝覆盖
-->


android / platform / frameworks / support / 4d53400eca9f3ac90c3a3f6cffcbc5bf492ec536 / . / window / window / src / main / java / androidx / window / embedding / RuleController.kt blob: 192f3ecb19e01e80afab7ef3ec7fc0c21b2bea64 [file] [log] [blame] /* * Copyright 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package androidx.window.embedding import android.content.Context import androidx.annotation.XmlRes import androidx.window.embedding.RuleController.Companion.parseRules /** * The controller to manage [EmbeddingRule]s. It supports: * - [addRule] * - [removeRule] * - [setRules] * - [parseRules] * - [clearRules] * * **Note** that this class is recommended to be configured in [androidx.startup.Initializer] or * [android.app.Application.onCreate], so that the rules are applied early in the application * startup before any activities complete initialization. The rule updates only apply to future * [android.app.Activity] launches and do not apply to already running activities. */ class RuleController internal constructor(private val embeddingBackend: EmbeddingBackend) { // TODO(b/258356512): Make this API a make this a coroutine API that returns // Flow<Set<EmbeddingRule>>. /** * Returns a copy of the currently registered rules. */ fun getRules(): Set<EmbeddingRule> { return embeddingBackend.getRules() } /** * Registers a new rule, or updates an existing rule if the [tag][EmbeddingRule.tag] has been * registered with [RuleController]. Will be cleared automatically when the process is stopped. * * Registering a `SplitRule` may fail if the [SplitController.splitSupportStatus] * returns `false`. If not supported, it could be either because * [androidx.window.WindowProperties.PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED] not enabled * in AndroidManifest or the feature not available on the device. * * Note that registering a new rule or updating the existing rule will **not** be applied to any * existing split activity container, and will only be used for new split containers created * with future activity launches. * * @param rule new [EmbeddingRule] to register. */ fun addRule(rule: EmbeddingRule) { embeddingBackend.addRule(rule) } /** * Unregisters a rule that was previously registered via [addRule] or [setRules]. * * @param rule the previously registered [EmbeddingRule] to unregister. */ fun removeRule(rule: EmbeddingRule) { embeddingBackend.removeRule(rule) } /** * Sets a set of [EmbeddingRule]s, which replace all rules registered by [addRule] * or [setRules]. * * It's recommended to set the rules via an [androidx.startup.Initializer], or * [android.app.Application.onCreate], so that they are applied early in the application * startup before any activities appear. * * The [EmbeddingRule]s can be parsed from [parseRules] or built with rule Builders, which are: * - [SplitPairRule.Builder] * - [SplitPlaceholderRule.Builder] * - [ActivityRule.Builder] * * Registering `SplitRule`s may fail if the [SplitController.splitSupportStatus] * returns `false`. If not supported, it could be either because * [androidx.window.WindowProperties.PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED] not enabled * in AndroidManifest or the feature not available on the device. * * Note that updating the existing rules will **not** be applied to any existing split activity * container, and will only be used for new split containers created with future activity * launches. * * @param rules The [EmbeddingRule]s to set * @throws IllegalArgumentException if [rules] contains two [EmbeddingRule]s with the same * [EmbeddingRule.tag]. */ fun setRules(rules: Set<EmbeddingRule>) { embeddingBackend.setRules(rules) } /** Clears the rules previously registered by [addRule] or [setRules]. */ fun clearRules() { embeddingBackend.setRules(emptySet()) } companion object { /** * Obtains an instance of [RuleController]. * * @param context the [Context] to initialize the controller with */ @JvmStatic fun getInstance(context: Context): RuleController { val applicationContext = context.applicationContext val backend = EmbeddingBackend.getInstance(applicationContext) return RuleController(backend) } /** * Parses [EmbeddingRule]s from XML rule definitions. * * The [EmbeddingRule]s can then set by [setRules]. * * @param context the context that contains the XML rule definition resources * @param staticRuleResourceId the resource containing the static split rules. * @throws IllegalArgumentException if any of the rules in the XML are malformed. */ @JvmStatic fun parseRules(context: Context, @XmlRes staticRuleResourceId: Int): Set<EmbeddingRule> = RuleParser.parseRules(context.applicationContext, staticRuleResourceId) ?: emptySet() } } 将这个kotlin文件转为java文件
最新发布
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值