void configureProperty(Project project, String name, Object value) { Class<? extends Project> clazz = project.getClass(); if (clazz != projectClazz) { mutators.clear(); projectClazz = clazz; } PropertyMutator propertyMutator = mutators.get(name); if (propertyMutator != null) { propertyMutator.setValue(project, value); } else { if (!mutators.containsKey(name)) { propertyMutator = JavaReflectionUtil.writeablePropertyIfExists(clazz, name); mutators.put(name, propertyMutator); if (propertyMutator != null) { propertyMutator.setValue(project, value); return; } } ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties(); extraProperties.set(name, value); } }
@TaskAction public void setMainClassNameProperty() { Project project = getProject(); if (!project.hasProperty("mainClassName") || project.property("mainClassName") == null) { String mainClass = findMainClass(); if (project.hasProperty("mainClassName")) { project.setProperty("mainClassName", mainClass); } else { ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) project .getExtensions().getByName("ext"); extraProperties.set("mainClassName", mainClass); } } }
@SuppressWarnings("unchecked") public static <T> T getExtraProperty(Project project, String name, T value, Class<T> returnType) { LOGGER.debug("Getting extra property " + name + " from project " + project.getName()); ExtraPropertiesExtension ext = project.getExtensions().getExtraProperties(); if (ext != null && ext.has(name)) { Object property = ext.get(name); if (property == null) { LOGGER.debug("Extra property {} is null.", name); } else if (!returnType.isInstance(property)) { LOGGER.warn("Extra property {} is not {}. It's value will be ignored!", name, returnType.getName()); } else { return (T) property; } } else { LOGGER.debug("Extra property {} is not set.", name); } return value; }
private void setMainClass(Repackager repackager) { String mainClass; if (getProject().hasProperty("mainClassName")) { mainClass = (String) getProject().property("mainClassName"); } else { ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) getProject() .getExtensions().getByName("ext"); mainClass = (String) extraProperties.get("mainClassName"); } if (RepackageTask.this.mainClass != null) { mainClass = RepackageTask.this.mainClass; } else if (this.extension.getMainClass() != null) { mainClass = this.extension.getMainClass(); } else { Task runTask = getProject().getTasks().findByName("run"); if (runTask != null && runTask.hasProperty("main")) { mainClass = (String) getProject().getTasks().getByName("run") .property("main"); } } getLogger().info("Setting mainClass: " + mainClass); repackager.setMainClass(mainClass); }
@SuppressWarnings("unchecked") private Map<File, File> getOrCreateGlobalAnalysisMap() { ExtraPropertiesExtension extraProperties = getProject().getRootProject().getExtensions().getExtraProperties(); Map<File, File> analysisMap; if (extraProperties.has("scalaCompileAnalysisMap")) { analysisMap = (Map) extraProperties.get("scalaCompileAnalysisMap"); } else { analysisMap = Maps.newHashMap(); for (Project project : getProject().getRootProject().getAllprojects()) { for (ScalaCompile task : project.getTasks().withType(ScalaCompile.class)) { if (task.getScalaCompileOptions().isUseAnt()) { continue; } File publishedCode = task.getScalaCompileOptions().getIncrementalOptions().getPublishedCode(); File analysisFile = task.getScalaCompileOptions().getIncrementalOptions().getAnalysisFile(); analysisMap.put(publishedCode, analysisFile); } } extraProperties.set("scalaCompileAnalysisMap", Collections.unmodifiableMap(analysisMap)); } return analysisMap; }
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()); } } }
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()); } } }
/** * Executes the provided Action after all projects have been evaluated. * Action will only be added once per provided key. Any subsequent calls for the same key will be ignored. * This permits the plugin to be applied in multiple subprojects, with the postprocess action executed once only. */ protected void postProcess(String key, final Action<? super Gradle> action) { Project rootProject = project.getRootProject(); ExtraPropertiesExtension rootExtraProperties = rootProject.getExtensions().getByType(ExtraPropertiesExtension.class); String extraPropertyName = "org.gradle." + key + ".postprocess.applied"; if (!rootExtraProperties.has(extraPropertyName)) { project.getGradle().addBuildListener(new BuildAdapter() { @Override public void projectsEvaluated(Gradle gradle) { action.execute(gradle); } }); rootExtraProperties.set(extraPropertyName, true); } }
@Before public void setUp() { project = mock(Project.class); // project.getExtensions().getExtraProperties().set(passwordProperty, pass); ExtensionContainer extensionContainer = mock(ExtensionContainer.class); when(project.getExtensions()).thenReturn(extensionContainer); extraProperties = mock(ExtraPropertiesExtension.class); when(extensionContainer.getExtraProperties()).thenReturn(extraProperties); }
private String getMainClassNameProperty() { if (getProject().hasProperty("mainClassName")) { return (String) getProject().property("mainClassName"); } ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) getProject() .getExtensions().getByName("ext"); if (extraProperties.has("mainClassName")) { return (String) extraProperties.get("mainClassName"); } return null; }
private void addBootRunTask(final Project project) { final JavaPluginConvention javaConvention = project.getConvention() .getPlugin(JavaPluginConvention.class); BootRunTask run = project.getTasks().create(RUN_APP_TASK_NAME, BootRunTask.class); run.setDescription("Run the project with support for " + "auto-detecting main class and reloading static resources"); run.setGroup("application"); run.setClasspath( javaConvention.getSourceSets().findByName("main").getRuntimeClasspath()); run.getConventionMapping().map("main", new Callable<Object>() { @Override public Object call() throws Exception { if (project.hasProperty("mainClassName") && project.property("mainClassName") != null) { return project.property("mainClassName"); } ExtraPropertiesExtension extraPropertiesExtension = (ExtraPropertiesExtension) project .getExtensions().getByName("ext"); if (extraPropertiesExtension.has("mainClassName") && extraPropertiesExtension.get("mainClassName") != null) { return extraPropertiesExtension.get("mainClassName"); } return null; } }); run.getConventionMapping().map("jvmArgs", new Callable<Object>() { @Override public Object call() throws Exception { if (project.hasProperty("applicationDefaultJvmArgs")) { return project.property("applicationDefaultJvmArgs"); } return Collections.emptyList(); } }); }
private String getMainClassNameProperty() { if (getProject().hasProperty("mainClassName")) { return (String) getProject().property("mainClassName"); } ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) getProject() .getExtensions().getByName("ext"); return (String) extraProperties.get("mainClassName"); }
public static void setExtraProperty(Project project, String name, Object value) { LOGGER.debug("Setting extra property {}={} to project {}", name, value.toString(), project.getName()); ExtraPropertiesExtension ext = project.getExtensions().getExtraProperties(); if (ext != null) { if (ext.has(name)) { LOGGER.warn("Extra property {} is already set it will be overwritten.", name); } ext.set(name, value); } else { LOGGER.debug("Extra properties in project {} are not available.", project.getName()); } }
/** * Read the value of an extra property of the project. * * @param pExtraPropName the reference to the extra property name * @param <T> type of the property value * @return the property's value */ @SuppressWarnings("unchecked") public <T> T getExtraPropertyValue(@Nonnull final ExtProp pExtraPropName) { ExtraPropertiesExtension extraProps = project.getExtensions().getByType(ExtraPropertiesExtension.class); if (extraProps.has(pExtraPropName.getPropertyName())) { return (T) extraProps.get(pExtraPropName.getPropertyName()); } throw new GradleException( "Reference to non-existent project extra property '" + pExtraPropName.getPropertyName() + "'"); }
public ExtraPropertiesExtension getDynamicProperties() { return convention.getExtraProperties(); }
public DefaultConvention(Instantiator instantiator) { this.instantiator = instantiator; add(ExtraPropertiesExtension.EXTENSION_NAME, extraProperties); }
public ExtraPropertiesExtension getExtraProperties() { return extraProperties; }
public ExtraPropertiesDynamicObjectAdapter(Class<?> delegateType, ExtraPropertiesExtension extension) { this.delegateType = delegateType; this.extension = extension; }
public void setProperty(String name, Object newValue) { if (name.equals("properties")) { throw new ReadOnlyPropertyException("name", ExtraPropertiesExtension.class); } set(name, newValue); }
public ExtraPropertiesDynamicObjectAdapter(Class<?> delegateType, ExtraPropertiesExtension extension) { super(extension); this.delegateType = delegateType; this.extension = extension; }
public ExtraPropertiesDynamicObjectAdapter(Object delegate, DynamicObject dynamicOwner, ExtraPropertiesExtension extension) { super(extension); this.delegate = delegate; this.dynamicOwner = dynamicOwner; this.extension = extension; }
public static <T> T getExtraPropertyOrNull(@Nonnull Project project, @Nonnull String name) { ExtraPropertiesExtension properties = project.getExtensions().getExtraProperties(); if (properties.has(name)) return (T) properties.get(name); return null; }
private static ExtraPropertiesExtension ext(Object licenseExt) { val metaClass = ((GroovyObject)licenseExt).getMetaClass(); val conExtPropsProp = metaClass.getMetaProperty("extensions"); val convExtensions = (Convention)conExtPropsProp.getProperty(licenseExt); return convExtensions.getExtraProperties(); }
public PropertiesLoader(final ExtraPropertiesExtension ext) { _ext = requireNonNull(ext, "Properties must not be null."); }