여기서는 프로젝트 빌드 시 속성을 로드하는 방법에 대해 살펴보겠습니다.https://docs.gradle.org/current/userguide/userguide.html[gradle]
코드 내에 그것이 존재하지 않더라도.
속성은 ~/.gradle/gradle.properties 폴더의 gradle.properties 파일에 정의됩니다.
~은(는) 세션 사용자 루트를 나타내는 심볼릭 변수 HOME_PATH`의 약어입니다: lehttps://fr.wikipedia.org/wiki/R%C3%A9pertoire_personnel[개인 디렉터리]전문 번역가입니다. 프랑스어에서 한국어로 번역해 드립니다. 모든 백틱 코드 스팬(…​)은 내용, 공백, 위치를 변경하지 않고 그대로 유지하겠습니다. 텍스트가 더 큰 문장의 일부인 경우, 추가 맥락 요청 없이 해당 부분만 번역하겠습니다. 설명, 해설, 서론, 대안, 선택지 없이 번역된 텍스트만 출력하겠습니다.
프로젝트 빌드에서도 마찬가지로https://maven.apache.org/guides/index.html[maven], ~/.m2/settings.xml과 함께 이 스크립트의 목적은 명시된 패턴과 일치하는 파일들을 삭제하는 것입니다.
strCriteria
변수 내에. 이를 위해 저는 다음을 사용하겠습니다https://fr.wikipedia.org/wiki/Fermeture_(informatique)[클로저]: each, findAll, collect
또한 내 기준 문자열을 조각으로 나눌 StringTokenizer 클래스도 함께
문자열 리스트를 가져오기 위해. 정리할 폴더의 파일 중 하나라도 파일 이름에 다음 패턴 중 하나가 포함되어 있다면
그러면 결과 리스트에 추가되어 삭제 대상이 될 것입니다.
그리고 마지막 줄에 작은 …​ 예시가 있습니다.https://en.wikipedia.org/wiki/Elvis_operator[엘비스 연산자]
filemanip.groovy

#!/usr/bin/env groovy
//Mes criteres de selection des fichiers à detruire
String strCriteria = "Dummies Dummie ajax Objective-C Windows blackberry " +
        "wordpress joomla ios c# f# rails ruby flex asp flash Dreamweaver adobe " +
        "CoffeeScript c++ .chm .epub .rar .zip .tar drupal drupals .net php javascript " +
        ".js iphone ipad js _js facebook gwt vaadin linq python py zope window " +
        "3D scala gaming active_directory tomcat jboss glassfish microsoft 2d " +
        "lego blogger blog cocoa dojo dom dotnetnuke eclipse .gz unity sharepoint " +
        ".tgz iwork filemaker .doc .txt"


//repertoire personnel
String userDir = System.getProperty("user.home")
//un separateur de chemin crossplatform
String sep = System.getProperty("file.separator")
//la variable symbolique
String sym_books_vrac_path = "books_vrac_path"

//le chemin de mon fichier gradle.properties hors projet
String propertiesFilePath = userDir
        .concat("${sep}.gradle${sep}gradle.properties")


File propertiesFile = new File(propertiesFilePath)


//je m'aassure que le fichier existe et que ce n'est pas un dossier
assert propertiesFile.exists() && !propertiesFile.directory

Properties gradleProperties = new Properties()

//on boucle avec un inpustream sur le fichier
//gradle.properties pour peupler ma variable gradleProperties
propertiesFile.withInputStream { InputStream it ->
    gradleProperties.load(it)
}

//le chemin du dossier books_vrac est la valeur de notre clé books_vrac_path
String pathVracDir = gradleProperties.get(sym_books_vrac_path)

//j'ai récuperé tous ces livres en tapant cette commande dans le terminal
//wget -m -np -c -R "index.html*" "http://the-eye.eu/public/Books/IT%20Various/"

//on ouvre le dossier dont le chemin est dans la variable pathVracDir
// on s'assure qu'il existe et que c'est un dossier
File vracDir = new File(pathVracDir)
assert vracDir.exists() && vracDir.directory


//separer les élèments de ma liste de critère
StringTokenizer tokenizer = new StringTokenizer(strCriteria)

//la liste de critere
List<String> criteriaList = new ArrayList<>()

//j'itère sur les tokens et je construit ma liste de token,
// mot clef critère de recherche
tokenizer.each { String it ->
    criteriaList.add(it.toLowerCase())
}

//je collect tous les noms de fichier dans le dossier
List<String> fileNameList = vracDir
        .listFiles()
        .collect { File it ->
            it.directory ?: it.name
        }

// je collect les noms de fichier qui contiendraient un des criteres
List<String> resultList = fileNameList.findAll { String name ->
    criteriaList.findAll { String crit ->
        name.toLowerCase().contains(crit)
    }
}

// je parcours ma liste de résultat pour les effacer
resultList.each { String fileName ->
    assert new File(vracDir.path + sep + fileName).delete()
}

println fileNameList.size()
println resultList.size()
resultList.empty ?: println(vracDir.path + sep + resultList.first())

관련 기사