Java Code Examples for org.gradle.api.Project#getProjectDir()
The following examples show how to use
org.gradle.api.Project#getProjectDir() .
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: ProjectPropertySettingBuildLoader.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private void addPropertiesToProject(Project project) { Properties projectProperties = new Properties(); File projectPropertiesFile = new File(project.getProjectDir(), Project.GRADLE_PROPERTIES); LOGGER.debug("Looking for project properties from: {}", projectPropertiesFile); if (projectPropertiesFile.isFile()) { projectProperties = GUtil.loadProperties(projectPropertiesFile); LOGGER.debug("Adding project properties (if not overwritten by user properties): {}", projectProperties.keySet()); } else { LOGGER.debug("project property file does not exists. We continue!"); } Map<String, String> mergedProperties = propertiesLoader.mergeProperties(new HashMap(projectProperties)); ExtraPropertiesExtension extraProperties = new DslObject(project).getExtensions().getExtraProperties(); for (Map.Entry<String, String> entry: mergedProperties.entrySet()) { if (project.hasProperty(entry.getKey())) { project.setProperty(entry.getKey(), entry.getValue()); } else { extraProperties.set(entry.getKey(), entry.getValue()); } } }
Example 2
Source File: ProjectPropertySettingBuildLoader.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private void addPropertiesToProject(Project project) { Properties projectProperties = new Properties(); File projectPropertiesFile = new File(project.getProjectDir(), Project.GRADLE_PROPERTIES); LOGGER.debug("Looking for project properties from: {}", projectPropertiesFile); if (projectPropertiesFile.isFile()) { projectProperties = GUtil.loadProperties(projectPropertiesFile); LOGGER.debug("Adding project properties (if not overwritten by user properties): {}", projectProperties.keySet()); } else { LOGGER.debug("project property file does not exists. We continue!"); } Map<String, String> mergedProperties = propertiesLoader.mergeProperties(new HashMap(projectProperties)); ExtraPropertiesExtension extraProperties = new DslObject(project).getExtensions().getExtraProperties(); for (Map.Entry<String, String> entry: mergedProperties.entrySet()) { try { project.setProperty(entry.getKey(), entry.getValue()); } catch (MissingPropertyException e) { if (!entry.getKey().equals(e.getProperty())) { throw e; } // Ignore and define as an extra property extraProperties.set(entry.getKey(), entry.getValue()); } } }
Example 3
Source File: ProjectPropertySettingBuildLoader.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private void addPropertiesToProject(Project project) { Properties projectProperties = new Properties(); File projectPropertiesFile = new File(project.getProjectDir(), Project.GRADLE_PROPERTIES); LOGGER.debug("Looking for project properties from: {}", projectPropertiesFile); if (projectPropertiesFile.isFile()) { projectProperties = GUtil.loadProperties(projectPropertiesFile); LOGGER.debug("Adding project properties (if not overwritten by user properties): {}", projectProperties.keySet()); } else { LOGGER.debug("project property file does not exists. We continue!"); } Map<String, String> mergedProperties = propertiesLoader.mergeProperties(new HashMap(projectProperties)); ExtraPropertiesExtension extraProperties = new DslObject(project).getExtensions().getExtraProperties(); for (Map.Entry<String, String> entry: mergedProperties.entrySet()) { try { project.setProperty(entry.getKey(), entry.getValue()); } catch (MissingPropertyException e) { if (!entry.getKey().equals(e.getProperty())) { throw e; } // Ignore and define as an extra property extraProperties.set(entry.getKey(), entry.getValue()); } } }
Example 4
Source File: ProjectPropertySettingBuildLoader.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private void addPropertiesToProject(Project project) { Properties projectProperties = new Properties(); File projectPropertiesFile = new File(project.getProjectDir(), Project.GRADLE_PROPERTIES); LOGGER.debug("Looking for project properties from: {}", projectPropertiesFile); if (projectPropertiesFile.isFile()) { projectProperties = GUtil.loadProperties(projectPropertiesFile); LOGGER.debug("Adding project properties (if not overwritten by user properties): {}", projectProperties.keySet()); } else { LOGGER.debug("project property file does not exists. We continue!"); } Map<String, String> mergedProperties = propertiesLoader.mergeProperties(new HashMap(projectProperties)); ExtraPropertiesExtension extraProperties = new DslObject(project).getExtensions().getExtraProperties(); for (Map.Entry<String, String> entry: mergedProperties.entrySet()) { if (project.hasProperty(entry.getKey())) { project.setProperty(entry.getKey(), entry.getValue()); } else { extraProperties.set(entry.getKey(), entry.getValue()); } } }
Example 5
Source File: GenerateBootstrapScript.java From gradle-plugins with Apache License 2.0 | 6 votes |
private void patchShellScript(Project project) { File projectDir = project.getProjectDir(); File wrapperFile = new File(projectDir.getAbsoluteFile(), "gradlew"); try { String script = FileUtils.readFileToString(wrapperFile); int sep = script.indexOf("# Determine the Java command to use to start the JVM."); if (sep == -1) { throw new IllegalStateException("unknown gradlew format, failed to find '# Determine the Java command to use to start the JVM.' to setup JDK bootstrapping"); } String bootstrapScript = generateBootstrapScript(); String updatedScript = script.substring(0, sep) + bootstrapScript + '\n' + script.substring(sep); updatedScript = updatedScript.replace("#!/usr/bin/env sh", "#!/bin/bash"); FileUtils.write(wrapperFile, updatedScript); } catch (IOException e) { throw new IllegalStateException(e); } }
Example 6
Source File: CodeGeneratorPlugin.java From gradle-plugins with MIT License | 5 votes |
@Override public void apply(Project project) { CodeGeneratorConfiguration codeGenerator = project.getExtensions().create("codeGenerator", CodeGeneratorConfiguration.class, project.getObjects()); Configuration codeGeneratorConfiguration = project.getConfigurations().create("codeGenerator"); JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class); for (SourceSet sourceSet : plugin.getSourceSets()) { String outputDir = project.getBuildDir() + "/generated-src/generator/" + sourceSet.getName(); File outputDirFile = new File(outputDir); project.getLogger().debug("Using output dir {}", outputDir); File inputDir = new File(project.getProjectDir() + "/src/code-generator/" + sourceSet.getName()); sourceSet.getJava().srcDir(inputDir); sourceSet.getJava().srcDir(outputDirFile); project.getLogger().debug("Using input dir {}", inputDir); String taskName = sourceSet.getTaskName("generate", "Code"); TaskProvider<GenerateCodeTask> generate = project.getTasks().register(taskName, GenerateCodeTask.class, s -> { s.setGroup("generate"); s.getOutputDir().set(outputDirFile); if(inputDir.isDirectory()) { s.getInputDir().set(inputDir); } s.getSourceSet().set(sourceSet.getName()); s.getCodeGeneratorClasspath().from(codeGeneratorConfiguration); s.getConfigurationValues().set(codeGenerator.getConfigurationValues()); s.dependsOn(codeGeneratorConfiguration); }); project.getTasks().named(sourceSet.getCompileJavaTaskName(), t -> t.dependsOn(generate)); } }
Example 7
Source File: ProjectOutcomesModelBuilder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private DefaultProjectOutcomes buildProjectOutput(Project project, ProjectOutcomes parent) { DefaultProjectOutcomes projectOutput = new DefaultProjectOutcomes(project.getName(), project.getPath(), project.getDescription(), project.getProjectDir(), getFileOutcomes(project), parent); for (Project child : project.getChildProjects().values()) { projectOutput.addChild(buildProjectOutput(child, projectOutput)); } return projectOutput; }
Example 8
Source File: GwtSetUpTask.java From putnami-gradle-plugin with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean isEnable(final Project project, final PutnamiExtension extension) { String mainModule = null; if (extension.getModule() != null && extension.getModule().size() > 0) { mainModule = extension.getModule().get(0); } if (mainModule != null) { String moduleFilePath = "src/main/java/" + mainModule.replaceAll("\\.", "/") + ".gwt.xml"; File moduleFile = new File(project.getProjectDir(), moduleFilePath); return !moduleFile.exists(); } return false; }
Example 9
Source File: CodeGeneratorPlugin.java From gradle-plugins with MIT License | 5 votes |
@Override public void apply(Project project) { CodeGeneratorConfiguration codeGenerator = project.getExtensions().create("codeGenerator", CodeGeneratorConfiguration.class, project.getObjects()); Configuration codeGeneratorConfiguration = project.getConfigurations().create("codeGenerator"); JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class); for (SourceSet sourceSet : plugin.getSourceSets()) { String outputDir = project.getBuildDir() + "/generated-src/generator/" + sourceSet.getName(); File outputDirFile = new File(outputDir); project.getLogger().debug("Using output dir {}", outputDir); File inputDir = new File(project.getProjectDir() + "/src/code-generator/" + sourceSet.getName()); sourceSet.getJava().srcDir(inputDir); sourceSet.getJava().srcDir(outputDirFile); project.getLogger().debug("Using input dir {}", inputDir); String taskName = sourceSet.getTaskName("generate", "Code"); TaskProvider<GenerateCodeTask> generate = project.getTasks().register(taskName, GenerateCodeTask.class, s -> { s.setGroup("generate"); s.getOutputDir().set(outputDirFile); if(inputDir.isDirectory()) { s.getInputDir().set(inputDir); } s.getSourceSet().set(sourceSet.getName()); s.getCodeGeneratorClasspath().from(codeGeneratorConfiguration); s.getConfigurationValues().set(codeGenerator.getConfigurationValues()); s.dependsOn(codeGeneratorConfiguration); }); project.getTasks().named(sourceSet.getCompileJavaTaskName(), t -> t.dependsOn(generate)); } }
Example 10
Source File: PythonWheelDistributionPlugin.java From pygradle with Apache License 2.0 | 5 votes |
@Override public void applyTo(final Project project) { // XXX: This needs to be adjusted to work with a build matrix one day. Until // that is ready, we always assume pure Python 2.7 on Linux. String version = project.getVersion().toString().replace("-", "_"); String name = project.getName().replace("-", "_"); final File wheelArtifact = new File(project.getProjectDir(), "/dist/" + name + "-" + version + "-py2-none-any.whl"); /* * Create a Python wheel distribution. */ project.getTasks().create(TASK_PACKAGE_WHEEL, task -> { task.dependsOn(project.getTasks().getByName(StandardTextValues.TASK_INSTALL_PROJECT.getValue())); task.getOutputs().file(wheelArtifact); task.doLast(it -> project.exec(execSpec -> { execSpec.environment(settings.pythonEnvironmentDistgradle); execSpec.commandLine(settings.getDetails().getVirtualEnvInterpreter(), "setup.py", "bdist_wheel"); })); }); LinkedHashMap<String, Object> wheelArtifactInfo = new LinkedHashMap<>(5); wheelArtifactInfo.put("name", name); wheelArtifactInfo.put("classifier", "py2-none-any"); wheelArtifactInfo.put("type", "whl"); wheelArtifactInfo.put("file", wheelArtifact); wheelArtifactInfo.put("builtBy", project.getTasks().getByName(TASK_PACKAGE_WHEEL)); if (!version.contains("SNAPSHOT")) { project.getArtifacts().add(StandardTextValues.CONFIGURATION_WHEEL.getValue(), wheelArtifactInfo); } }
Example 11
Source File: DefaultPythonDetails.java From pygradle with Apache License 2.0 | 5 votes |
public DefaultPythonDetails(Project project, File venvDir) { this.project = project; activateLink = new File(project.getProjectDir(), OperatingSystem.current().getScriptName("activate")); virtualEnvPrompt = String.format("(%s)", project.getName()); searchPath = OperatingSystem.current().getPath(); venvOverride = venvDir; this.virtualEnvironment = new DefaultVirtualEnvironment(this); pythonDefaultVersions = new PythonDefaultVersions(); }
Example 12
Source File: GenerateDocsTask.java From synopsys-detect with Apache License 2.0 | 5 votes |
private void handleContent(final File outputDir, final TemplateProvider templateProvider) throws IOException, TemplateException { final Project project = getProject(); final File templatesDir = new File(project.getProjectDir(), "docs/templates"); final File contentDir = new File(templatesDir, "content"); // TODO: Not sure this method of tree walking actually works. try (final Stream<Path> paths = Files.walk(contentDir.toPath())) { final List<Path> foundFreemarkerFiles = paths.filter(it -> FilenameUtils.isExtension(it.getFileName().toString(), "ftl")) .collect(Collectors.toList()); for (final Path foundFreemarkerFilePath : foundFreemarkerFiles) { createContentMarkdownFromTemplate(templatesDir, contentDir, foundFreemarkerFilePath.toFile(), outputDir, templateProvider); } } }
Example 13
Source File: TerraformPlugin.java From gradle-plugins with Apache License 2.0 | 5 votes |
public void apply(Project project) { project.getPlugins().apply(CliExecPlugin.class); File configDir = new File(project.getProjectDir(), "src/main/terraform"); TerraformExtension extension = project.getExtensions().create("terraform", TerraformExtension.class); extension.setProject(project); extension.setSourceDir(configDir); extension.getCli().setImageName("hashicorp/terraform"); extension.getCli().setImageTag("0.11.7"); // terraform needs to have its files in the local working directory extension.getCli().setWorkingDir("/workdir/src/main/terraform"); TerraformInitTask initTask = project.getTasks().create("terraformInit", TerraformInitTask.class); TerraformValidateTask validateTask = project.getTasks().create("terraformValidate", TerraformValidateTask.class); TerraformRefreshTask refreshTask = project.getTasks().create("terraformRefresh", TerraformRefreshTask.class); TerraformPlanTask planTask = project.getTasks().create("terraformPlan", TerraformPlanTask.class); TerraformApplyTask applyTask = project.getTasks().create("terraformApply", TerraformApplyTask.class); TerraformDestroyTask destroyTask = project.getTasks().create("terraformDestroy", TerraformDestroyTask.class); refreshTask.dependsOn(initTask); validateTask.dependsOn(initTask); planTask.dependsOn(validateTask); applyTask.dependsOn(planTask); destroyTask.dependsOn(planTask); CliExecExtension cliExec = project.getExtensions().getByType(CliExecExtension.class); cliExec.register("terraform", extension.getCli()); project.afterEvaluate(project1 -> { Cli cli = extension.getCli(); File terraformTempDir2 = new File(project.getBuildDir(), ".terraformCache"); cli.getVolumeMappings().put("/.terraform", terraformTempDir2); if (extension.getDebug()) { cli.getEnvironment().put("TF_LOG", "DEBUG"); } }); }
Example 14
Source File: GenerateSchemaTask.java From gradle-plugins with Apache License 2.0 | 5 votes |
@OutputDirectory public File getOutputDirectory() { Project project = getProject(); SchemaGenExtension config = getConfig(); if (config.getOutputDirectory() != null) { return config.getOutputDirectory(); } if (config.isContinuousMode()) { return new File(project.getBuildDir(), "resources/main/"); } return new File(project.getProjectDir(), "src/main/resources"); }
Example 15
Source File: ProjectOutcomesModelBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private DefaultProjectOutcomes buildProjectOutput(Project project, ProjectOutcomes parent) { DefaultProjectOutcomes projectOutput = new DefaultProjectOutcomes(project.getName(), project.getPath(), project.getDescription(), project.getProjectDir(), getFileOutcomes(project), parent); for (Project child : project.getChildProjects().values()) { projectOutput.addChild(buildProjectOutput(child, projectOutput)); } return projectOutput; }
Example 16
Source File: ProjectOutcomesModelBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private DefaultProjectOutcomes buildProjectOutput(Project project, ProjectOutcomes parent) { DefaultProjectOutcomes projectOutput = new DefaultProjectOutcomes(project.getName(), project.getPath(), project.getDescription(), project.getProjectDir(), getFileOutcomes(project), parent); for (Project child : project.getChildProjects().values()) { projectOutput.addChild(buildProjectOutput(child, projectOutput)); } return projectOutput; }
Example 17
Source File: PythonPlugin.java From pygradle with Apache License 2.0 | 4 votes |
@Override public void apply(final Project project) { final PythonExtension settings = project.getExtensions().create("python", PythonExtension.class, project); EditablePythonAbiContainer supportedWheelFormats = ExtensionUtils.maybeCreate(settings, EditablePythonAbiContainer.class.getName(), DefaultPythonAbiContainer.class); project.getTasks().withType(ProvidesVenv.class, it -> it.setEditablePythonAbiContainer(supportedWheelFormats)); project.getPlugins().apply("base"); createConfigurations(project); configureVendedDependencies(project, settings); project.getTasks().withType(SupportsPackageFiltering.class, action -> { action.getOutputs().doNotCacheIf("When package packageFilter is set", task -> ((SupportsPackageFiltering) task).getPackageExcludeFilter() != null); }); DefaultPackageSettings packageSettings = new DefaultPackageSettings(project.getProjectDir()); project.getTasks().withType(SupportsPackageInfoSettings.class, it -> it.setPackageSettings(packageSettings)); /* * To prevent base dependencies, such as setuptools, from installing/reinstalling, we will * pin their versions to values in the extension.forcedVersions map, which will contain known * good versions that satisfy all the requirements. */ final PyGradleDependencyResolveDetails dependencyResolveDetails = new PyGradleDependencyResolveDetails(settings.forcedVersions); project.getConfigurations() .forEach(configuration -> configuration.getResolutionStrategy().eachDependency(dependencyResolveDetails)); /* * Write the direct dependencies into a requirements file as a list of pinned versions. */ final PinRequirementsTask pinRequirementsTask = project.getTasks().create(TASK_PIN_REQUIREMENTS.getValue(), PinRequirementsTask.class); /* * Install virtualenv. * * Install the virtualenv version that we implicitly depend on so that we * can run on systems that don't have virtualenv already installed. */ project.getTasks().create(TASK_VENV_CREATE.getValue(), InstallVirtualEnvironmentTask.class, task -> { task.dependsOn(pinRequirementsTask); task.setPythonDetails(settings.getDetails()); }); // Ensure that ABI container is populated when virtual environment creation task is up-to-date. project.getTasks().create(TASK_GET_PROBED_TAGS.getValue(), GetProbedTagsTask.class, task -> { task.dependsOn(TASK_VENV_CREATE.getValue()); task.setPythonDetails(settings.getDetails()); }); /* * Creates a link so users can activate into the virtual environment. */ project.getTasks().create(TASK_SETUP_LINKS.getValue(), task -> { task.dependsOn(project.getTasks().getByName(TASK_VENV_CREATE.getValue())); task.dependsOn(project.getTasks().getByName(TASK_GET_PROBED_TAGS.getValue())); task.getOutputs().file(settings.getDetails().getActivateLink()); task.doLast(it -> { File activateLinkSource = settings.getDetails().getVirtualEnvironment().getScript("activate"); File activateLink = settings.getDetails().getActivateLink(); FileSystemUtils.makeSymLinkUnchecked(activateLinkSource, activateLink); }); }); /* * task that cleans the project but leaves the venv intact. Helpful for projects on windows that * take a very long time to build the venv. */ project.getTasks().create(TASK_CLEAN_SAVE_VENV.getValue(), CleanSaveVenvTask.class, task -> task.setGroup(BasePlugin.BUILD_GROUP)); project.getTasks().create(TASK_SETUP_PY_WRITER.getValue(), GenerateSetupPyTask.class); project.getPlugins().apply(InstallDependenciesPlugin.class); project.getPlugins().apply(ValidationPlugin.class); project.getPlugins().apply(DocumentationPlugin.class); project.getPlugins().apply(LayeredWheelCachePlugin.class); PyPiRepoUtil.setupPyGradleRepo(project); }
Example 18
Source File: DefaultCacheScopeMapping.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
private File getBuildCacheDir(Project rootProject) { if (buildCacheDir != null) { return buildCacheDir; } return new File(rootProject.getProjectDir(), ".gradle"); }
Example 19
Source File: DefaultCacheScopeMapping.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
private File getBuildCacheDir(Project rootProject) { if (buildCacheDir != null) { return buildCacheDir; } return new File(rootProject.getProjectDir(), ".gradle"); }
Example 20
Source File: DefaultCacheScopeMapping.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
private File getBuildCacheDir(Project rootProject) { if (buildCacheDir != null) { return buildCacheDir; } return new File(rootProject.getProjectDir(), ".gradle"); }