Java Code Examples for org.gradle.api.project#file()
The following examples show how to use
org.gradle.api.project#file() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenerateDocsTask.java From synopsys-detect with Apache License 2.0 | 6 votes |
@TaskAction public void generateDocs() throws IOException, TemplateException, IntegrationException { final Project project = getProject(); final File file = new File("synopsys-detect-" + project.getVersion() + "-help.json"); final Reader reader = new FileReader(file); final HelpJsonData helpJson = new Gson().fromJson(reader, HelpJsonData.class); final File outputDir = project.file("docs/generated"); final File troubleshootingDir = new File(outputDir, "advanced/troubleshooting"); FileUtils.deleteDirectory(outputDir); troubleshootingDir.mkdirs(); final TemplateProvider templateProvider = new TemplateProvider(project.file("docs/templates"), project.getVersion().toString()); createFromFreemarker(templateProvider, troubleshootingDir, "exit-codes", new ExitCodePage(helpJson.getExitCodes())); handleDetectors(templateProvider, outputDir, helpJson); handleProperties(templateProvider, outputDir, helpJson); handleContent(outputDir, templateProvider); }
Example 2
Source File: ModularCreateStartScripts.java From gradle-modules-plugin with MIT License | 6 votes |
private static void configure(ModularCreateStartScripts startScriptsTask, Project project) { var appConvention = project.getConvention().findPlugin(ApplicationPluginConvention.class); if (appConvention != null) { var distDir = project.file(project.getBuildDir() + "/install/" + appConvention.getApplicationName()); startScriptsTask.setOutputDir(new File(distDir, appConvention.getExecutableDir())); } ModularJavaExec runTask = startScriptsTask.getRunTask(); if (runTask == null) throw new GradleException("runTask not set for task " + startScriptsTask.getName()); var runJvmArgs = runTask.getOwnJvmArgs(); if (!runJvmArgs.isEmpty()) { var defaultJvmOpts = new ArrayList<>(runJvmArgs); startScriptsTask.getDefaultJvmOpts().forEach(defaultJvmOpts::add); startScriptsTask.setDefaultJvmOpts(defaultJvmOpts); } var mutator = new StartScriptsMutator(runTask, project); mutator.updateStartScriptsTask(startScriptsTask); mutator.movePatchedLibs(); }
Example 3
Source File: SdkUtil.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
public static File getSdkDir(Project project) { Properties properties = new Properties(); File localProperties = project.getRootProject().file("local.properties"); if (localProperties.exists()) { try (FileInputStream fis = new FileInputStream(localProperties)) { properties.load(fis); } catch (IOException ex) { throw new GradleException("Could not load local.properties", ex); } } String sdkDir = properties.getProperty("sdk.dir"); if (sdkDir != null) { return project.file(sdkDir); } String androidHome = System.getenv("ANDROID_HOME"); if (androidHome == null) { throw new GradleException("No sdk.dir or ANDROID_HOME set."); } return project.file(androidHome); }
Example 4
Source File: VersionPlugin.java From pygradle with Apache License 2.0 | 6 votes |
@Override public void apply(Project target) { if (target.getRootProject() != target) { throw new GradleException("Cannot apply dependency plugin to a non-root project"); } File versionProperties = target.file("version.properties"); Version version = VersionFile.getVersion(versionProperties); if (!target.hasProperty("release") || !Boolean.parseBoolean((String) target.property("release"))) { version = version.asSnapshot(); } logger.lifecycle("Building using version {}", version); target.allprojects(new VersionAction(version)); }
Example 5
Source File: VersioningPlugin.java From shipkit with MIT License | 6 votes |
public void apply(final Project project) { LocalSnapshotPlugin snapshotPlugin = project.getPlugins().apply(LocalSnapshotPlugin.class); final File versionFile = project.file(VERSION_FILE_NAME); final VersionInfo versionInfo = new VersionInfoFactory().createVersionInfo(versionFile, project.getVersion(), snapshotPlugin.isSnapshot()); project.getExtensions().add(VersionInfo.class.getName(), versionInfo); final String version = versionInfo.getVersion(); project.allprojects(project1 -> project1.setVersion(version)); TaskMaker.task(project, BUMP_VERSION_FILE_TASK, BumpVersionFileTask.class, t -> { t.setDescription("Increments version number in " + versionFile.getName()); t.setVersionFile(versionFile); String versionChangeMessage = formatVersionInformationInCommitMessage(version, versionInfo.getPreviousVersion()); GitPlugin.registerChangesForCommitIfApplied(singletonList(versionFile), versionChangeMessage, t); }); }
Example 6
Source File: CloudV2Plugin.java From commerce-gradle-plugin with Apache License 2.0 | 5 votes |
@Override public void apply(Project project) { File manifestFile = project.file(MANIFEST_PATH); if (!manifestFile.exists()) { throw new InvalidUserDataException(MANIFEST_PATH + " not found!"); } JsonSlurper slurper = new JsonSlurper(); Map parsed = (Map) slurper.parse(manifestFile); Manifest manifest = Manifest.fromMap(parsed); extension = project.getExtensions().create("CCV2", CCv2Extension.class, project, manifest); extension.getGeneratedConfiguration().set(project.file("generated-configuration")); extension.getCloudExtensionPackFolder().set(project.file("cloud-extension-pack")); final Configuration extensionPack = project.getConfigurations().create(EXTENSION_PACK); extensionPack.defaultDependencies(deps -> { //de/hybris/platform/hybris-cloud-extension-pack/1905.06/ String commerceSuiteVersion = manifest.commerceSuiteVersion; String cepVersion = commerceSuiteVersion.replaceAll("(.+)(\\.\\d\\d)?", "$1.+"); deps.add(project.getDependencies().create("de.hybris.platform:hybris-cloud-extension-pack:" + cepVersion + "@zip")); }); project.getPlugins().withType(HybrisPlugin.class, hybrisPlugin -> { Object byName = project.getExtensions().getByName(HybrisPlugin.HYBRIS_EXTENSION); if (byName instanceof HybrisPluginExtension) { ((HybrisPluginExtension) byName).getVersion().set(project.provider(() -> manifest.commerceSuiteVersion)); configureAddonInstall(project, manifest.storefrontAddons); configureTests(project, manifest.tests); configureWebTests(project, manifest.webTests); configureCloudExtensionPackBootstrap(project, manifest.useCloudExtensionPack); } }); configurePropertyFileGeneration(project, manifest); configureExtensionGeneration(project, manifest); }
Example 7
Source File: TransportPluginConfig.java From transport with BSD 2-Clause "Simplified" License | 5 votes |
/** * Create a config object from the gradle {@link Project}. * * On creation, we attempt to populate config values using gradle properties or set to default values. */ public TransportPluginConfig(Project project) { mainSourceSetName = getPropertyOrDefault(project, MAIN_SOURCE_SET_NAME_PROP, "main"); testSourceSetName = getPropertyOrDefault(project, TEST_SOURCE_SET_NAME_PROP, "test"); outputDirFile = project.hasProperty(OUTPUT_DIR_PROP) ? project.file(project.property(OUTPUT_DIR_PROP).toString()) : project.getBuildDir(); // Build dir by default }
Example 8
Source File: FetchLogTask.java From gradle-plugins with Apache License 2.0 | 5 votes |
@TaskAction public void run() throws IOException { Project project = getProject(); KubectlExtension extension = project.getExtensions().getByType(KubectlExtension.class); String namespace = namespaceSupplier.get(); KubectlExecSpec execSpec = new KubectlExecSpec(); execSpec.setCommandLine(String.format("kubectl get deployment,statefulset -o name --namespace=%s", namespace)); execSpec.setOutputFormat(OutputFormat.TEXT); ExecResult result = extension.exec(execSpec); for (String component : result.getText().trim().split("\n")) { KubectlExecSpec execSpecComp = new KubectlExecSpec(); execSpecComp.setCommandLine( String.format("kubectl logs %s --namespace=%s --since=5m --all-containers=true", component, namespace) ); execSpecComp.setOutputFormat(OutputFormat.TEXT); ExecResult resultComp = extension.exec(execSpecComp); File logFile = project.file("build/logs/" + namespace + "/" + component + ".log"); logFile.getParentFile().mkdirs(); try (FileWriter writer = new FileWriter(logFile)) { writer.write(resultComp.getText()); } } }
Example 9
Source File: TerraformPlanTask.java From gradle-plugins with Apache License 2.0 | 5 votes |
@TaskAction public void exec() { setAddVariables(true); Project project = getProject(); File planDir = project.file("build/terraform/plan"); planDir.getParentFile().mkdirs(); commandLine("plan -out=" + CONTAINER_PLAN_FILE); super.exec(); }
Example 10
Source File: NoHttpCheckstylePlugin.java From nohttp with Apache License 2.0 | 4 votes |
@Override public void apply(Project project) { this.project = project; this.extension = this.project.getExtensions().create(NOHTTP_EXTENSION_NAME, NoHttpExtension.class); this.extension.setToolVersion(NOHTTP_VERSION); this.extension.setSource(project.fileTree(project.getProjectDir(), new Action<ConfigurableFileTree>() { @Override public void execute(ConfigurableFileTree files) { String projectDir = project.getProjectDir().getAbsolutePath(); files.exclude(createBuildExclusion(projectDir, project)); project.subprojects(new Action<Project>() { @Override public void execute(Project p) { files.exclude(createBuildExclusion(projectDir, p)); } }); files.exclude(".git/**"); files.exclude(".gradle/**"); files.exclude("buildSrc/.gradle/**"); files.exclude(".idea/**"); files.exclude("**/*.class"); files.exclude("**/*.hprof"); files.exclude("**/*.jar"); files.exclude("**/*.jpg"); files.exclude("**/*.jks"); files.exclude("**/spring.handlers"); files.exclude("**/spring.schemas"); files.exclude("**/spring.tooling"); } })); File legacyWhiteListFile = project.file(LEGACY_WHITELIST_FILE_PATH); if (legacyWhiteListFile.exists()) { this.extension.setAllowlistFile(legacyWhiteListFile); } File defaultWhiteListFile = project.file(DEFAULT_WHITELIST_FILE_PATH); if (defaultWhiteListFile.exists()) { this.extension.setAllowlistFile(defaultWhiteListFile); } File allowlistFile = this.project.file(DEFAULT_ALLOWLIST_FILE_PATH); if (allowlistFile.exists()) { this.extension.setAllowlistFile(allowlistFile); } project.getPluginManager().apply(CheckstylePlugin.class); Configuration checkstyleConfiguration = project.getConfigurations().getByName(CHECKSTYLE_CONFIGURATION_NAME); Configuration noHttpConfiguration = project.getConfigurations().create(DEFAULT_CONFIGURATION_NAME); checkstyleConfiguration.extendsFrom(noHttpConfiguration); configureDefaultDependenciesForProject(noHttpConfiguration); createCheckstyleTaskForProject(checkstyleConfiguration); configureCheckTask(); }
Example 11
Source File: FirebaseLibraryPlugin.java From firebase-android-sdk with Apache License 2.0 | 4 votes |
private static void setupApiInformationAnalysis(Project project, LibraryExtension android) { File metalavaOutputJarFile = new File(project.getRootProject().getBuildDir(), "metalava.jar"); AndroidSourceSet mainSourceSet = android.getSourceSets().getByName("main"); File outputFile = project .getRootProject() .file( Paths.get( project.getRootProject().getBuildDir().getPath(), "apiinfo", project.getPath().substring(1).replace(":", "_"))); File outputApiFile = new File(outputFile.getAbsolutePath() + "_api.txt"); project .getTasks() .register( "getMetalavaJar", GetMetalavaJarTask.class, task -> { task.setOutputFile(metalavaOutputJarFile); }); File apiTxt = project.file("api.txt").exists() ? project.file("api.txt") : project.file(project.getRootDir() + "/empty-api.txt"); TaskProvider<ApiInformationTask> apiInfo = project .getTasks() .register( "apiInformation", ApiInformationTask.class, task -> { task.setApiTxt(apiTxt); task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath()); task.setSourceSet(mainSourceSet); task.setOutputFile(outputFile); task.setBaselineFile(project.file("baseline.txt")); task.setOutputApiFile(outputApiFile); if (project.hasProperty("updateBaseline")) { task.setUpdateBaseline(true); } else { task.setUpdateBaseline(false); } task.dependsOn("getMetalavaJar"); }); TaskProvider<GenerateApiTxtFileTask> generateApiTxt = project .getTasks() .register( "generateApiTxtFile", GenerateApiTxtFileTask.class, task -> { task.setApiTxt(project.file("api.txt")); task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath()); task.setSourceSet(mainSourceSet); task.setBaselineFile(project.file("baseline.txt")); task.setUpdateBaseline(project.hasProperty("updateBaseline")); task.dependsOn("getMetalavaJar"); }); TaskProvider<GenerateStubsTask> docStubs = project .getTasks() .register( "docStubs", GenerateStubsTask.class, task -> { task.setMetalavaJarPath(metalavaOutputJarFile.getAbsolutePath()); task.setOutputDir(new File(project.getBuildDir(), "doc-stubs")); task.dependsOn("getMetalavaJar"); task.setSourceSet(mainSourceSet); }); project.getTasks().getByName("check").dependsOn(docStubs); android .getLibraryVariants() .all( v -> { if (v.getName().equals("release")) { FileCollection jars = v.getCompileConfiguration() .getIncoming() .artifactView( config -> config.attributes( container -> container.attribute( Attribute.of("artifactType", String.class), "jar"))) .getArtifacts() .getArtifactFiles(); apiInfo.configure(t -> t.setClassPath(jars)); generateApiTxt.configure(t -> t.setClassPath(jars)); docStubs.configure(t -> t.setClassPath(jars)); } }); }
Example 12
Source File: Utils.java From Injector with Apache License 2.0 | 4 votes |
public static File getWorkingDir(Project project) { return project.file(project.getBuildDir() + "/exploded-aar/"); }
Example 13
Source File: AwbGenerator.java From atlas with Apache License 2.0 | 4 votes |
public AwbBundle createAwbBundle(LibVariantContext libVariantContext) throws IOException { String variantName = libVariantContext.getVariantName(); AtlasDependencyTree libDependencyTree = AtlasBuildContext.libDependencyTrees.get(variantName); //TODO 2.3 if (null == libDependencyTree) { libDependencyTree = new AtlasDepTreeParser(libVariantContext.getProject(), new ExtraModelInfo(new ProjectOptions(libVariantContext.getProject()),null), new HashSet<>()) .parseDependencyTree(libVariantContext.getVariantDependency()); AtlasBuildContext.libDependencyTrees.put(variantName, libDependencyTree); } Project project = libVariantContext.getProject(); String groupName = (String)project.getGroup(); String name = ""; String version = (String)project.getVersion(); if (project.hasProperty("archivesBaseName")) { name = (String)project.getProperties().get("archivesBaseName"); } else { name = project.getName(); } File explodedDir = project.file( project.getBuildDir().getAbsolutePath() + "/" + FD_INTERMEDIATES + "/exploded-awb/" + computeArtifactPath( groupName, name, version)); FileUtils.deleteDirectory(explodedDir); MavenCoordinates mavenCoordinates = new MavenCoordinatesImpl(groupName, name, version, "awb", ""); ResolvedDependencyInfo resolvedDependencyInfo = new ResolvedDependencyInfo(groupName, name, version, "awb"); resolvedDependencyInfo.setVariantName(libVariantContext.getVariantName()); AwbBundle awbBundle = new AwbBundle(resolvedDependencyInfo, DependencyConvertUtils .toAndroidLibrary(mavenCoordinates, libVariantContext.getBundleTask().getArchivePath(), explodedDir)); awbBundle.getSoLibraries().addAll(libDependencyTree.getMainBundle().getSoLibraries()); awbBundle.getAndroidLibraries().addAll(libDependencyTree.getMainBundle().getAndroidLibraries()); awbBundle.getJavaLibraries().addAll(libDependencyTree.getMainBundle().getJavaLibraries()); return awbBundle; }
Example 14
Source File: DexSplitTools.java From DexKnifePlugin with Apache License 2.0 | 4 votes |
/** * generate the main dex list */ private static boolean genMainDexList(Project project, boolean minifyEnabled, File mappingFile, File jarMergingOutputFile, File adtMainDexList, DexKnifeConfig dexKnifeConfig) throws Exception { System.out.println(":" + project.getName() + ":genMainDexList"); // 1.get the recommend adt's maindexlist Map<String, Boolean> recommendMainClasses = null; if (dexKnifeConfig.useSuggest && adtMainDexList != null && adtMainDexList.exists()) { PatternSet patternSet = dexKnifeConfig.suggestPatternSet; if (dexKnifeConfig.filterSuggest && patternSet == null) { patternSet = dexKnifeConfig.patternSet; } System.out.println("DexKnife: use suggest"); recommendMainClasses = getRecommendMainDexClasses(adtMainDexList, patternSet, dexKnifeConfig.logFilterSuggest); } File keepFile = project.file(MAINDEXLIST_TXT); keepFile.delete(); // 2.process the global filter List<String> mainClasses = null; if (dexKnifeConfig.patternSet == null || isPatternSetEmpty(dexKnifeConfig.patternSet)) { // only filter the suggest list if (recommendMainClasses != null && recommendMainClasses.size() > 0) { mainClasses = new ArrayList<>(); Set<Map.Entry<String, Boolean>> entries = recommendMainClasses.entrySet(); for (Map.Entry<String, Boolean> entry : entries) { if (entry.getValue()) { mainClasses.add(entry.getKey()); } } } } else { if (minifyEnabled) { System.err.println("DexKnife: From Mapping"); // get classes from mapping mainClasses = getMainClassesFromMapping(mappingFile, dexKnifeConfig.patternSet, recommendMainClasses, dexKnifeConfig.logFilter); } else { System.out.println("DexKnife: From MergedJar: " + jarMergingOutputFile); if (jarMergingOutputFile != null) { // get classes from merged jar mainClasses = getMainClassesFromJar(jarMergingOutputFile, dexKnifeConfig.patternSet, recommendMainClasses, dexKnifeConfig.logFilter); } else { System.err.println("DexKnife: The Merged Jar is not exist! Can't be processed!"); } } } // 3.create the miandexlist if (mainClasses != null && mainClasses.size() > 0) { BufferedWriter writer = new BufferedWriter(new FileWriter(keepFile)); for (String mainClass : mainClasses) { writer.write(mainClass); writer.newLine(); if (dexKnifeConfig.logMainList) { System.out.println(mainClass); } } writer.close(); return true; } throw new Exception("DexKnife Warning: Main dex is EMPTY ! Check your config and project!"); }
Example 15
Source File: AvroPlugin.java From gradle-avro-plugin with Apache License 2.0 | 4 votes |
private static File getAvroSourceDir(Project project, SourceSet sourceSet) { return project.file(String.format("src/%s/avro", sourceSet.getName())); }