org.gradle.api.plugins.ExtraPropertiesExtension Java Examples

The following examples show how to use org.gradle.api.plugins.ExtraPropertiesExtension. 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 vote down vote up
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 Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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: GradleDependencyResolutionHelper.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Get data (identified by the given key) that has been cached on the given Gradle project reference.
 *
 * @param project  the Gradle project reference.
 * @param key      the key used for caching the data.
 * @param supplier the function that needs to be executed in the event of a cache-miss.
 * @param <T>      the type of the data stored on the project.
 * @return data that has been cached on the given Gradle project reference.
 */
@SuppressWarnings("unchecked")
private static <T> T getCachedReference(Project project, String key, Supplier<T> supplier) {
    if (project == null) {
        throw new IllegalArgumentException("Gradle project reference cannot be null.");
    }

    Project rootProject = project.getRootProject();
    ExtraPropertiesExtension ext = rootProject.getExtensions().getExtraProperties();
    T value;
    if (ext.has(key)) {
        value = (T) ext.get(key);
    } else {
        value = supplier.get();
        ext.set(key, value);
    }
    return value;
}
 
Example #5
Source File: ProjectPropertySettingBuildLoader.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 #6
Source File: UpdateIntelliJSdksTaskTest.java    From curiostack with MIT License 6 votes vote down vote up
@BeforeEach
void setUserHome() throws Exception {
  oldUserHome = System.getProperty("user.home");
  testUserHome = GradleTempDirectories.create("home");
  testGradleHome = GradleTempDirectories.create("gradlehome");
  System.setProperty("user.home", testUserHome.toAbsolutePath().toString());

  // Add an unrelated folder to make it look just a little more like a user home.
  Files.writeString(
      Files.createDirectories(testUserHome.resolve("curiotest")).resolve("foo.txt"), "bar");

  var project = ProjectBuilder.builder().withGradleUserHomeDir(testGradleHome.toFile()).build();
  var properties = project.getExtensions().getByType(ExtraPropertiesExtension.class);
  properties.set("org.curioswitch.curiostack.tools.openjdk", "zulu13.28.11-ca-jdk13.0.1");
  properties.set("org.curioswitch.curiostack.tools.openjdk8", "zulu8.42.0.21-ca-jdk8.0.232");

  project.getPlugins().apply(CuriostackRootPlugin.class);
  project.getPlugins().apply(GolangSetupPlugin.class);

  task =
      project
          .getTasks()
          .withType(UpdateIntelliJSdksTask.class)
          .getByName(UpdateIntelliJSdksTask.NAME);
}
 
Example #7
Source File: SassCompile.java    From gradle-plugins with MIT License 5 votes vote down vote up
public SassCompile() {
    include("**/*.scss");
    include("**/*.sass");

    ExtraPropertiesExtension extraProperties = new DslObject(this).getExtensions().getExtraProperties();
    for (OutputStyle value : OutputStyle.values()) {
        extraProperties.set(value.name(), value);
    }
}
 
Example #8
Source File: DownloadTaskPlugin.java    From gradle-download-task with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getExtensions().create("download", DownloadExtension.class, project);
    if (project.getExtensions().findByName("verifyChecksum") == null) {
        project.getExtensions().create("verifyChecksum", VerifyExtension.class, project);
    }

    //register top-level properties 'Download' and 'Verify' for our tasks
    ExtraPropertiesExtension extraProperties =
            project.getExtensions().getExtraProperties();
    extraProperties.set(Download.class.getSimpleName(), Download.class);
    extraProperties.set(Verify.class.getSimpleName(), Verify.class);
}
 
Example #9
Source File: SassCompile.java    From gradle-plugins with MIT License 5 votes vote down vote up
public SassCompile() {
    include("**/*.scss");
    include("**/*.sass");

    ExtraPropertiesExtension extraProperties = new DslObject(this).getExtensions().getExtraProperties();
    for (OutputStyle value : OutputStyle.values()) {
        extraProperties.set(value.name(), value);
    }
}
 
Example #10
Source File: JSassExtension.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Inject
public JSassExtension(ObjectFactory objectFactory) {
    indent = objectFactory.property(String.class);
    indent.convention("  ");

    linefeed = objectFactory.property(String.class);
    linefeed.convention(System.lineSeparator());

    omitSourceMapUrl = objectFactory.property(Boolean.class);
    omitSourceMapUrl.convention(false);

    outputStyle = objectFactory.property(OutputStyle.class);
    outputStyle.convention(OutputStyle.NESTED);

    precision = objectFactory.property(Integer.class);
    precision.convention(8);

    sourceComments = objectFactory.property(Boolean.class);
    sourceComments.convention(false);

    sourceMapContents = objectFactory.property(Boolean.class);
    sourceMapContents.convention(false);

    sourceMapEmbed = objectFactory.property(Boolean.class);
    sourceMapEmbed.convention(false);

    sourceMapEnabled = objectFactory.property(Boolean.class);
    sourceMapEnabled.convention(true);

    ExtraPropertiesExtension extraProperties = new DslObject(this).getExtensions().getExtraProperties();
    for (OutputStyle value : OutputStyle.values()) {
        extraProperties.set(value.name(), value);
    }
}
 
Example #11
Source File: JSassExtension.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Inject
public JSassExtension(ObjectFactory objectFactory) {
    indent = objectFactory.property(String.class);
    indent.convention("  ");

    linefeed = objectFactory.property(String.class);
    linefeed.convention(System.lineSeparator());

    omitSourceMapUrl = objectFactory.property(Boolean.class);
    omitSourceMapUrl.convention(false);

    outputStyle = objectFactory.property(OutputStyle.class);
    outputStyle.convention(OutputStyle.NESTED);

    precision = objectFactory.property(Integer.class);
    precision.convention(8);

    sourceComments = objectFactory.property(Boolean.class);
    sourceComments.convention(false);

    sourceMapContents = objectFactory.property(Boolean.class);
    sourceMapContents.convention(false);

    sourceMapEmbed = objectFactory.property(Boolean.class);
    sourceMapEmbed.convention(false);

    sourceMapEnabled = objectFactory.property(Boolean.class);
    sourceMapEnabled.convention(true);

    ExtraPropertiesExtension extraProperties = new DslObject(this).getExtensions().getExtraProperties();
    for (OutputStyle value : OutputStyle.values()) {
        extraProperties.set(value.name(), value);
    }
}
 
Example #12
Source File: GolangSetupPlugin.java    From curiostack with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
  project.getPlugins().apply(CondaBuildEnvPlugin.class);
  project
      .getPlugins()
      .withType(
          ToolDownloaderPlugin.class,
          plugin -> {
            plugin.registerToolIfAbsent(
                "go",
                tool -> {
                  tool.getVersion().set("1.13.1");
                  tool.getBaseUrl().set("https://dl.google.com/go/");
                  tool.getArtifactPattern().set("[artifact][revision].[classifier].[ext]");
                  tool.getPathSubDirs().add("go/bin");
                  tool.getAdditionalCachedDirs().add("gopath");
                });
          });

  project
      .getExtensions()
      .getByType(ExtraPropertiesExtension.class)
      .set(
          "gopath",
          project
              .getGradle()
              .getGradleUserHomeDir()
              .toPath()
              .resolve("curiostack")
              .resolve("gopath"));
}
 
Example #13
Source File: GoExecUtil.java    From curiostack with MIT License 5 votes vote down vote up
public static void goExec(ExecSpec exec, Project project, String command, Iterable<String> args) {
  var toolManager = DownloadedToolManager.get(project);
  exec.executable(toolManager.getBinDir("go").resolve(command));
  exec.args(args);
  exec.environment("GOROOT", toolManager.getToolDir("go").resolve("go"));
  exec.environment(
      "GOPATH", project.getExtensions().getByType(ExtraPropertiesExtension.class).get("gopath"));
  if (!"true"
      .equals(project.getRootProject().findProperty("org.curioswitch.curiostack.goModUpdate"))) {
    exec.environment("GOFLAGS", "-mod=readonly");
  }

  toolManager.addAllToPath(exec);
}
 
Example #14
Source File: CurioGenericCiPlugin.java    From curiostack with MIT License 5 votes vote down vote up
/** Returns the {@link CiState} for this build. */
public static CiState getCiState(Project project) {
  Object state =
      project
          .getRootProject()
          .getExtensions()
          .getByType(ExtraPropertiesExtension.class)
          .get(CI_STATE_PROPERTY);
  checkNotNull(
      state,
      "Could not find CiState. Has gradle-curiostack-plugin or curio-generic-ci-plugin been "
          + "applied to the root project?");
  return (CiState) state;
}
 
Example #15
Source File: CiState.java    From curiostack with MIT License 5 votes vote down vote up
static CiState createAndAdd(Project project) {
  String branch = getCiBranchOrTag();
  String revisionId =
      Strings.nullToEmpty(
          (String) project.getRootProject().findProperty("curiostack.revisionId"));

  boolean isMasterBuild = "true".equals(System.getenv("CI_MASTER"));
  boolean isReleaseBuild = branch.startsWith("RELEASE_");

  var revisionTags = new ImmutableList.Builder<String>();
  if (!revisionId.isEmpty()) {
    revisionTags.add(revisionId);
  }
  if (isReleaseBuild) {
    revisionTags.add(branch);
  }
  if (isMasterBuild) {
    revisionTags.add("latest");
  }

  CiState state =
      ImmutableCiState.builder()
          .isCi("true".equals(System.getenv("CI")) || "true".equals(project.findProperty("ci")))
          .isMasterBuild(isMasterBuild)
          .isReleaseBuild(isReleaseBuild)
          .isLocalBuild(System.getenv("CI") == null)
          .revisionId(revisionId)
          .branch(branch)
          .revisionTags(revisionTags.build())
          .build();

  project.getExtensions().getByType(ExtraPropertiesExtension.class).set(CI_STATE_PROPERTY, state);

  return state;
}
 
Example #16
Source File: ExtraPropertiesDynamicObjectAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExtraPropertiesDynamicObjectAdapter(Class<?> delegateType, ExtraPropertiesExtension extension) {
    super(extension);
    this.delegateType = delegateType;
    this.extension = extension;
}
 
Example #17
Source File: DefaultConvention.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultConvention(Instantiator instantiator) {
    this.instantiator = instantiator;
    add(ExtraPropertiesExtension.EXTENSION_NAME, extraProperties);
}
 
Example #18
Source File: CredentialsPlugin.java    From gradle-credentials-plugin with Apache License 2.0 4 votes vote down vote up
private void setProperty(String key, Object value, ExtensionAware extensionAware) {
    ExtraPropertiesExtension properties = extensionAware.getExtensions().getExtraProperties();
    properties.set(key, value);
}
 
Example #19
Source File: CredentialsPlugin.java    From gradle-credentials-plugin with Apache License 2.0 4 votes vote down vote up
private String getStringProperty(String key, String defaultValue, ExtensionAware extensionAware) {
    ExtraPropertiesExtension properties = extensionAware.getExtensions().getExtraProperties();
    return properties.has(key) ? (String) properties.get(key) : defaultValue;
}
 
Example #20
Source File: DefaultConvention.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExtraPropertiesExtension getExtraProperties() {
    return extraProperties;
}
 
Example #21
Source File: DefaultExtraPropertiesExtension.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setProperty(String name, Object newValue) {
    if (name.equals("properties")) {
        throw new ReadOnlyPropertyException("name", ExtraPropertiesExtension.class);
    }
    set(name, newValue);
}
 
Example #22
Source File: ExtraPropertiesDynamicObjectAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExtraPropertiesDynamicObjectAdapter(Object delegate, DynamicObject dynamicOwner, ExtraPropertiesExtension extension) {
    super(extension);
    this.delegate = delegate;
    this.dynamicOwner = dynamicOwner;
    this.extension = extension;
}
 
Example #23
Source File: DefaultConvention.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExtraPropertiesExtension getExtraProperties() {
    return extraProperties;
}
 
Example #24
Source File: DefaultConvention.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultConvention(Instantiator instantiator) {
    this.instantiator = instantiator;
    add(ExtraPropertiesExtension.EXTENSION_NAME, extraProperties);
}
 
Example #25
Source File: ExtensibleDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExtraPropertiesExtension getDynamicProperties() {
    return convention.getExtraProperties();
}
 
Example #26
Source File: ExtraPropertiesDynamicObjectAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExtraPropertiesDynamicObjectAdapter(Class<?> delegateType, ExtraPropertiesExtension extension) {
    super(extension);
    this.delegateType = delegateType;
    this.extension = extension;
}
 
Example #27
Source File: DefaultExtraPropertiesExtension.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setProperty(String name, Object newValue) {
    if (name.equals("properties")) {
        throw new ReadOnlyPropertyException("name", ExtraPropertiesExtension.class);
    }
    set(name, newValue);
}
 
Example #28
Source File: DefaultConvention.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExtraPropertiesExtension getExtraProperties() {
    return extraProperties;
}
 
Example #29
Source File: DefaultConvention.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultConvention(Instantiator instantiator) {
    this.instantiator = instantiator;
    add(ExtraPropertiesExtension.EXTENSION_NAME, extraProperties);
}
 
Example #30
Source File: ExtensibleDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExtraPropertiesExtension getDynamicProperties() {
    return convention.getExtraProperties();
}