Java Code Examples for org.gradle.api.Project#hasProperty()
The following examples show how to use
org.gradle.api.Project#hasProperty() .
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: MetricsPlugin.java From gradle-metrics-plugin with Apache License 2.0 | 6 votes |
@Override public void apply(Project project) { if(isOfflineMode(project.getGradle())) { createMetricsExtension(project); project.getLogger().warn("Build is running offline. Metrics will not be collected."); return; } if (project.hasProperty(METRICS_ENABLED_PROPERTY) && "false".equals(project.property(METRICS_ENABLED_PROPERTY))) { createMetricsExtension(project); project.getLogger().warn("Metrics have been disabled for this build."); return; } BuildMetrics buildMetrics = initializeBuildMetrics(project.getGradle()); createAndRegisterGradleBuildMetricsCollector(project.getGradle(), buildMetrics); configureProject(project); }
Example 2
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 3
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 4
Source File: ReleasePlugin.java From curiostack with MIT License | 6 votes |
@Override public void apply(Project project) { if (project.getParent() != null) { throw new IllegalStateException( "gradle-release-plugin can only be applied to the root project."); } if (!project.hasProperty("version") || "unspecified".equals(project.findProperty("version"))) { String version = determineVersion(project); project.setProperty("version", version); project.subprojects( proj -> { if (!proj.hasProperty("version") || "unspecified".equals(proj.findProperty("version"))) { proj.setProperty("version", version); } }); project.getLogger().quiet("Automatically determined version: " + version); } }
Example 5
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 6
Source File: ShipkitConfigurationPlugin.java From shipkit with MIT License | 6 votes |
public void apply(final Project project) { if (project.getParent() == null) { //root project, add the extension project.getPlugins().apply(InitPlugin.class); project.getPlugins().apply(VersioningPlugin.class); VersionInfo info = project.getExtensions().getByType(VersionInfo.class); conf = project.getRootProject().getExtensions() .create("shipkit", ShipkitConfiguration.class); loadConfigFromFile(project.getRootProject(), getShipkitFile(project), conf); if (project.hasProperty(DRY_RUN_PROPERTY)) { conf.setDryRun(true); //TODO (maybe) we can actually implement it so that we automatically preconfigure everything by command line parameters //e.g. shipkit.gitHub.repository is also a property } conf.setPreviousReleaseVersion(info.getPreviousVersion()); } else { //not root project, get extension from root project conf = project.getRootProject().getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration(); } }
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: CycloneDxTask.java From cyclonedx-gradle-plugin with Apache License 2.0 | 5 votes |
private boolean getBooleanParameter(String parameter, boolean defaultValue) { final Project project = super.getProject(); if (project.hasProperty(parameter)) { final Object o = project.getProperties().get(parameter); if (o instanceof String) { return Boolean.valueOf((String)o); } } return defaultValue; }
Example 9
Source File: CycloneDxTask.java From cyclonedx-gradle-plugin with Apache License 2.0 | 5 votes |
/** * Resolves the CycloneDX schema the mojo has been requested to use. * @return the CycloneDX schema to use */ private CycloneDxSchema.Version schemaVersion() { final Project project = super.getProject(); if (project.hasProperty("cyclonedx.schemaVersion")) { final String s = (String)project.getProperties().get("cyclonedx.schemaVersion"); if ("1.0".equals(s)) { return CycloneDxSchema.Version.VERSION_10; } } return CycloneDxSchema.Version.VERSION_11; }
Example 10
Source File: AddLocalJarTask.java From atlas with Apache License 2.0 | 5 votes |
private boolean isLocalJarEnabled(Project project) { boolean localJarEnabled = AtlasBuildContext.sBuilderAdapter.localJarEnabled; if (project.hasProperty("localJarEnabled")) { localJarEnabled = "true".equals(project.property("localJarEnabled")); } return localJarEnabled; }
Example 11
Source File: AndroidGradleOptions.java From javaide with GNU General Public License v3.0 | 5 votes |
private static boolean getBoolean( @NonNull Project project, @NonNull String propertyName) { if (project.hasProperty(propertyName)) { Object value = project.getProperties().get(propertyName); if (value instanceof String) { return Boolean.parseBoolean((String) value); } } return false; }
Example 12
Source File: ReleasePlugin.java From curiostack with MIT License | 5 votes |
private static String determineVersion(Project project) { String revisionId; if (project.hasProperty("curiostack.revisionId")) { revisionId = (String) project.property("curiostack.revisionId"); } else if (System.getenv().containsKey("REVISION_ID")) { revisionId = System.getenv("REVISION_ID"); } else if (!Strings.isNullOrEmpty(System.getenv().get("TAG_NAME"))) { revisionId = System.getenv("TAG_NAME"); } else if (!Strings.isNullOrEmpty(System.getenv().get("BRANCH_NAME"))) { revisionId = System.getenv("BRANCH_NAME"); } else { try (Git git = Git.open(project.getRootDir())) { revisionId = git.getRepository().resolve(Constants.HEAD).getName().substring(0, 12); } catch (IOException e) { revisionId = "unknown"; } } checkNotNull(revisionId); boolean isRelease = "true".equals(project.findProperty("curiostack.release")); if (isRelease) { return revisionId; } else { return "0.0.0-" + TIMESTAMP_FORMATTER.format(LocalDateTime.now(ZoneOffset.UTC)) + "-" + revisionId; } }
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: AbstractMetricsPlugin.java From gradle-metrics-plugin with Apache License 2.0 | 4 votes |
protected void configureProject(Project project) { checkNotNull(project); checkState(project == project.getRootProject(), "The metrics plugin may only be applied to the root project"); final MetricsPluginExtension extension = createMetricsExtension(project); if (project.hasProperty(METRICS_ENABLED_PROPERTY) && "false".equals(project.property(METRICS_ENABLED_PROPERTY))) { dispatcher = new NoopMetricsDispatcher(extension); project.getLogger().warn("Metrics have been disabled for this build."); return; } project.afterEvaluate(gradleProject -> { if (dispatcher instanceof UninitializedMetricsDispatcher) { switch (extension.getDispatcherType()) { case ES_HTTP: { dispatcher = new HttpESMetricsDispatcher(extension); break; } case SPLUNK: { dispatcher = new SplunkMetricsDispatcher(extension); break; } case REST: { dispatcher = new RestMetricsDispatcher(extension); break; } case NOOP: { dispatcher = new NoopMetricsDispatcher(extension); break; } case CUSTOM: { if(dispatcher instanceof UninitializedMetricsDispatcher) { throw new GradleException("setDispatcher should be called to set dispatcher when CUSTOM is selected as type"); } break; } } } configureProjectCollectors(gradleProject); }); }
Example 15
Source File: GradleProjectUtilities.java From steady with Apache License 2.0 | 4 votes |
protected static String getMandatoryProjectProperty(Project project, GradleGavProperty property, Logger logger) { final String propertyName=property.name(); logger.debug("Looking for property [{}] in project", propertyName); String propertyValue = null; if(project.hasProperty(propertyName)) { propertyValue = project.getProperties().get(propertyName).toString(); } if (propertyValue == null || propertyValue.isEmpty() || propertyValue.equals("undefined")) { logger.error("Property [{}] is not defined, please define it!", propertyName); throw new GradleException(); } logger.debug("Property found: {}={}", propertyName, propertyValue); return propertyValue; }
Example 16
Source File: TransportPluginConfig.java From transport with BSD 2-Clause "Simplified" License | 4 votes |
/** * Retrieve a string property from a gradle project if it has been set, a default value otherwise. */ private String getPropertyOrDefault(Project project, String propertyName, String defaultValue) { return project.hasProperty(propertyName) ? project.property(propertyName).toString() : defaultValue; }
Example 17
Source File: FirebaseLibraryExtension.java From firebase-android-sdk with Apache License 2.0 | 4 votes |
private Set<String> projectsFromProperty(Project project, String propertyName) { if (!project.hasProperty(propertyName)) { return Collections.emptySet(); } return ImmutableSet.copyOf(project.property(propertyName).toString().split(",", -1)); }