Java Code Examples for org.gradle.api.plugins.ExtraPropertiesExtension

The following examples show how to use org.gradle.api.plugins.ExtraPropertiesExtension. These examples are extracted from open source projects. 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
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 2
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 Project: curiostack   Source File: UpdateIntelliJSdksTaskTest.java    License: 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 4
/**
 * 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
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 6
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 7
Source Project: curiostack   Source File: CiState.java    License: 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 8
Source Project: curiostack   Source File: CurioGenericCiPlugin.java    License: 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 9
Source Project: curiostack   Source File: GoExecUtil.java    License: 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 10
Source Project: curiostack   Source File: GolangSetupPlugin.java    License: 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 11
Source Project: gradle-plugins   Source File: JSassExtension.java    License: 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 Project: gradle-plugins   Source File: SassCompile.java    License: 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 13
Source Project: gradle-plugins   Source File: JSassExtension.java    License: 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 14
Source Project: gradle-plugins   Source File: SassCompile.java    License: 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 15
Source Project: gradle-download-task   Source File: DownloadTaskPlugin.java    License: 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 16
public ExtraPropertiesExtension getDynamicProperties() {
    return convention.getExtraProperties();
}
 
Example 17
public DefaultConvention(Instantiator instantiator) {
    this.instantiator = instantiator;
    add(ExtraPropertiesExtension.EXTENSION_NAME, extraProperties);
}
 
Example 18
public ExtraPropertiesExtension getExtraProperties() {
    return extraProperties;
}
 
Example 19
public ExtraPropertiesDynamicObjectAdapter(Class<?> delegateType, ExtraPropertiesExtension extension) {
    super(extension);
    this.delegateType = delegateType;
    this.extension = extension;
}
 
Example 20
public void setProperty(String name, Object newValue) {
    if (name.equals("properties")) {
        throw new ReadOnlyPropertyException("name", ExtraPropertiesExtension.class);
    }
    set(name, newValue);
}
 
Example 21
public ExtraPropertiesExtension getDynamicProperties() {
    return convention.getExtraProperties();
}
 
Example 22
public DefaultConvention(Instantiator instantiator) {
    this.instantiator = instantiator;
    add(ExtraPropertiesExtension.EXTENSION_NAME, extraProperties);
}
 
Example 23
public ExtraPropertiesExtension getExtraProperties() {
    return extraProperties;
}
 
Example 24
public ExtraPropertiesDynamicObjectAdapter(Object delegate, DynamicObject dynamicOwner, ExtraPropertiesExtension extension) {
    super(extension);
    this.delegate = delegate;
    this.dynamicOwner = dynamicOwner;
    this.extension = extension;
}
 
Example 25
public void setProperty(String name, Object newValue) {
    if (name.equals("properties")) {
        throw new ReadOnlyPropertyException("name", ExtraPropertiesExtension.class);
    }
    set(name, newValue);
}
 
Example 26
Source Project: curiostack   Source File: ToolDownloaderPlugin.java    License: MIT License 4 votes vote down vote up
@Override
public void apply(Project project) {
  checkState(
      project.getParent() == null,
      "gradle-tool-downloader-plugin can only be applied to the root project.");

  var platformHelper = new PlatformHelper();

  tools =
      project.container(
          ToolDownloaderExtension.class, name -> ToolDownloaderExtension.create(name, project));
  project.getExtensions().add("tools", tools);

  toolManager = new DownloadedToolManager(project, tools);

  project
      .getExtensions()
      .getByType(ExtraPropertiesExtension.class)
      .set("toolManager", toolManager);

  var downloadAll = project.getTasks().register("toolsDownloadAll");
  var setupAll = project.getTasks().register("toolsSetupAll");

  tools.configureEach(
      tool -> {
        var taskSuffix = TaskUtil.toTaskSuffix(tool.getName());
        var task =
            project
                .getTasks()
                .register(
                    "toolsDownload" + taskSuffix,
                    DownloadToolTask.class,
                    tool,
                    platformHelper,
                    toolManager);
        var setup =
            project
                .getTasks()
                .register("toolsSetup" + taskSuffix, SetupTask.class, tool.getName());
        setup.configure(t -> t.dependsOn(task));
        downloadAll.configure(t -> t.dependsOn(task));
        setupAll.configure(t -> t.dependsOn(setup));
      });
}
 
Example 27
public ExtraPropertiesExtension getDynamicProperties() {
    return convention.getExtraProperties();
}
 
Example 28
public DefaultConvention(Instantiator instantiator) {
    this.instantiator = instantiator;
    add(ExtraPropertiesExtension.EXTENSION_NAME, extraProperties);
}
 
Example 29
public ExtraPropertiesExtension getExtraProperties() {
    return extraProperties;
}
 
Example 30
public ExtraPropertiesDynamicObjectAdapter(Class<?> delegateType, ExtraPropertiesExtension extension) {
    super(extension);
    this.delegateType = delegateType;
    this.extension = extension;
}