org.gradle.api.invocation.Gradle Java Examples

The following examples show how to use org.gradle.api.invocation.Gradle. 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: DefaultCacheScopeMapping.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public File getBaseDirectory(Object scope, String key, CacheBuilder.VersionStrategy versionStrategy) {
    if (key.equalsIgnoreCase("projects") || key.equalsIgnoreCase("tasks") || !key.matches("\\p{Alpha}+[-//.\\w]*")) {
        throw new IllegalArgumentException(String.format("Unsupported cache key '%s'.", key));
    }
    if (scope == null) {
        return getCacheDir(globalCacheDir, versionStrategy, key);
    }
    if (scope instanceof Gradle) {
        Gradle gradle = (Gradle) scope;
        return getCacheDir(getBuildCacheDir(gradle.getRootProject()), versionStrategy, key);
    }
    if (scope instanceof Project) {
        Project project = (Project) scope;
        return getCacheDir(getBuildCacheDir(project.getRootProject()), versionStrategy, String.format("projects/%s/%s", project.getPath().replace(':', '_'), key));
    }
    if (scope instanceof Task) {
        Task task = (Task) scope;
        return getCacheDir(getBuildCacheDir(task.getProject().getRootProject()), versionStrategy, String.format("tasks/%s/%s", task.getPath().replace(':', '_'), key));
    }
    throw new IllegalArgumentException(String.format("Don't know how to determine the cache directory for scope of type %s.", scope.getClass().getSimpleName()));
}
 
Example #2
Source File: StackdriverMetrics.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
private void ensureStackdriver(Gradle gradle) {
  // make sure we only initialize stackdriver once as gradle daemon is not guaranteed to restart
  // across gradle invocations.
  if (!STACKDRIVER_INITIALIZED.compareAndSet(false, true)) {
    logger.lifecycle("Stackdriver exporter already initialized.");
    return;
  }
  logger.lifecycle("Initializing Stackdriver exporter.");

  try {
    StackdriverStatsExporter.createAndRegister(
        StackdriverStatsConfiguration.builder()
            .setExportInterval(Duration.fromMillis(STACKDRIVER_UPLOAD_PERIOD_MS))
            .build());

    // make sure gradle does not exit before metrics get uploaded to stackdriver.
    gradle.addBuildListener(new DrainingBuildListener(STACKDRIVER_UPLOAD_PERIOD_MS, logger));
  } catch (IOException e) {
    throw new GradleException("Could not configure metrics exporter", e);
  }
}
 
Example #3
Source File: DefaultGradle.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DefaultGradle(Gradle parent, StartParameter startParameter, ServiceRegistryFactory parentRegistry) {
    this.parent = parent;
    this.startParameter = startParameter;
    this.services = parentRegistry.createFor(this);
    this.listenerManager = services.get(ListenerManager.class);
    taskGraph = services.get(TaskGraphExecuter.class);
    distributionLocator = services.get(GradleDistributionLocator.class);
    classLoaderScope = services.get(ClassLoaderScope.class);
    pluginContainer = services.get(PluginContainer.class);
    fileResolver = services.get(FileResolver.class);
    scriptPluginFactory = services.get(ScriptPluginFactory.class);
    scriptHandlerFactory = services.get(ScriptHandlerFactory.class);
    buildListenerBroadcast = listenerManager.createAnonymousBroadcaster(BuildListener.class);
    projectEvaluationListenerBroadcast = listenerManager.createAnonymousBroadcaster(ProjectEvaluationListener.class);
    buildListenerBroadcast.add(new BuildAdapter() {
        @Override
        public void projectsLoaded(Gradle gradle) {
            rootProjectActions.execute(rootProject);
            rootProjectActions = null;
        }
    });
}
 
Example #4
Source File: AbstractMetricsPlugin.java    From gradle-metrics-plugin with Apache License 2.0 6 votes vote down vote up
public void applyToGradle(Gradle gradle) {
    if(isOfflineMode(gradle)) {
        gradle.rootProject(project -> {
            createMetricsExtension(project);
            project.getLogger().warn("Build is running offline. Metrics will not be collected.");
        });
        return;
    }
    if(isMetricsDisabled(gradle)) {
        gradle.rootProject(project -> {
            createMetricsExtension(project);
            project.getLogger().warn("Metrics have been disabled for this build.");
        });
        return;
    }
    BuildMetrics buildMetrics = initializeBuildMetrics(gradle);
    createAndRegisterGradleBuildMetricsCollector(gradle, buildMetrics);
    gradle.rootProject(this::configureProject);
}
 
Example #5
Source File: DefaultGradle.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DefaultGradle(Gradle parent, StartParameter startParameter, ServiceRegistryFactory parentRegistry) {
    this.parent = parent;
    this.startParameter = startParameter;
    this.services = parentRegistry.createFor(this);
    this.listenerManager = services.get(ListenerManager.class);
    taskGraph = services.get(TaskGraphExecuter.class);
    distributionLocator = services.get(GradleDistributionLocator.class);
    classLoaderScope = services.get(ClassLoaderScopeRegistry.class).getCoreAndPluginsScope();
    pluginContainer = services.get(PluginContainer.class);
    fileResolver = services.get(FileResolver.class);
    scriptPluginFactory = services.get(ScriptPluginFactory.class);
    scriptHandlerFactory = services.get(ScriptHandlerFactory.class);
    buildListenerBroadcast = listenerManager.createAnonymousBroadcaster(BuildListener.class);
    projectEvaluationListenerBroadcast = listenerManager.createAnonymousBroadcaster(ProjectEvaluationListener.class);
    buildListenerBroadcast.add(new BuildAdapter() {
        @Override
        public void projectsLoaded(Gradle gradle) {
            rootProjectActions.execute(rootProject);
            rootProjectActions = null;
        }
    });
}
 
Example #6
Source File: AbstractMetricsPlugin.java    From gradle-metrics-plugin with Apache License 2.0 6 votes vote down vote up
protected boolean isMetricsDisabled(Gradle gradle) {
    String metricsEnabledParameter = gradle.getStartParameter().getProjectProperties().get(METRICS_ENABLED_PROPERTY);
    boolean metricsDisabled = metricsEnabledParameter != null && metricsEnabledParameter.equals("false");
    if(metricsDisabled) {
        return true;
    }
    File gradleProperties = new File(gradle.getStartParameter().getProjectDir(), "gradle.properties");
    if(gradleProperties.exists()) {
        try (Stream<String> stream = Files.lines(gradleProperties.toPath())) {
            return stream.anyMatch(line ->
                    line.contains(METRICS_ENABLED_PROPERTY) && line.contains("false"));
        } catch (IOException e) {
            return false;
        }
    }
    return false;
}
 
Example #7
Source File: DefaultCacheScopeMapping.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public File getBaseDirectory(Object scope, String key, CacheBuilder.VersionStrategy versionStrategy) {
    if (key.equalsIgnoreCase("projects") || key.equalsIgnoreCase("tasks") || !key.matches("\\p{Alpha}+[-//.\\w]*")) {
        throw new IllegalArgumentException(String.format("Unsupported cache key '%s'.", key));
    }
    if (scope == null) {
        return getCacheDir(globalCacheDir, versionStrategy, key);
    }
    if (scope instanceof Gradle) {
        Gradle gradle = (Gradle) scope;
        return getCacheDir(getBuildCacheDir(gradle.getRootProject()), versionStrategy, key);
    }
    if (scope instanceof Project) {
        Project project = (Project) scope;
        return getCacheDir(getBuildCacheDir(project.getRootProject()), versionStrategy, String.format("projects/%s/%s", project.getPath().replace(':', '_'), key));
    }
    if (scope instanceof Task) {
        Task task = (Task) scope;
        return getCacheDir(getBuildCacheDir(task.getProject().getRootProject()), versionStrategy, String.format("tasks/%s/%s", task.getPath().replace(':', '_'), key));
    }
    throw new IllegalArgumentException(String.format("Don't know how to determine the cache directory for scope of type %s.", scope.getClass().getSimpleName()));
}
 
Example #8
Source File: DefaultCacheScopeMapping.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public File getBaseDirectory(Object scope, String key, CacheBuilder.VersionStrategy versionStrategy) {
    if (key.equalsIgnoreCase("projects") || key.equalsIgnoreCase("tasks") || !key.matches("\\p{Alpha}+[-//.\\w]*")) {
        throw new IllegalArgumentException(String.format("Unsupported cache key '%s'.", key));
    }
    if (scope == null) {
        return getCacheDir(globalCacheDir, versionStrategy, key);
    }
    if (scope instanceof Gradle) {
        Gradle gradle = (Gradle) scope;
        return getCacheDir(getBuildCacheDir(gradle.getRootProject()), versionStrategy, key);
    }
    if (scope instanceof Project) {
        Project project = (Project) scope;
        return getCacheDir(getBuildCacheDir(project.getRootProject()), versionStrategy, String.format("projects/%s/%s", project.getPath().replace(':', '_'), key));
    }
    if (scope instanceof Task) {
        Task task = (Task) scope;
        return getCacheDir(getBuildCacheDir(task.getProject().getRootProject()), versionStrategy, String.format("tasks/%s/%s", task.getPath().replace(':', '_'), key));
    }
    throw new IllegalArgumentException(String.format("Don't know how to determine the cache directory for scope of type %s.", scope.getClass().getSimpleName()));
}
 
Example #9
Source File: BuildLogger.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void buildStarted(Gradle gradle) {
    StartParameter startParameter = gradle.getStartParameter();
    logger.info("Starting Build");
    logger.debug("Gradle user home: " + startParameter.getGradleUserHomeDir());
    logger.debug("Current dir: " + startParameter.getCurrentDir());
    logger.debug("Settings file: " + startParameter.getSettingsFile());
    logger.debug("Build file: " + startParameter.getBuildFile());
}
 
Example #10
Source File: IPCUtilities.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This gets the port out of the start parameters. Why? Because this is meant to be run from the init script and the system properties haven't been set yet. That is due to how gradle is run from
 * the bat file/shell script. It has to manually set the java system properties (-D). I don't this is a desired side-effect.
 *
 * @param gradle the gradle object
 * @return an integer or null if we didn't get the port.
 */
private static Integer getPort(Gradle gradle) {
    String portText = gradle.getStartParameter().getSystemPropertiesArgs().get(ProtocolConstants.PORT_NUMBER_SYSTEM_PROPERTY);
    if (portText == null) {
        LOGGER.error("Failed to set " + ProtocolConstants.PORT_NUMBER_SYSTEM_PROPERTY + " system property");
        return null;
    }

    try {
        return Integer.parseInt(portText);
    } catch (NumberFormatException e) {
        LOGGER.error("Invalid " + ProtocolConstants.PORT_NUMBER_SYSTEM_PROPERTY + " system property", e);
        return null;
    }
}
 
Example #11
Source File: TaskExecutionLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getDisplayName(Task task) {
    Gradle build = task.getProject().getGradle();
    if (build.getParent() == null) {
        // The main build, use the task path
        return task.getPath();
    }
    // A nested build, use a discriminator
    return Project.PATH_SEPARATOR + build.getRootProject().getName() + task.getPath();
}
 
Example #12
Source File: BuildLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void buildStarted(Gradle gradle) {
    StartParameter startParameter = gradle.getStartParameter();
    logger.info("Starting Build");
    logger.debug("Gradle user home: " + startParameter.getGradleUserHomeDir());
    logger.debug("Current dir: " + startParameter.getCurrentDir());
    logger.debug("Settings file: " + startParameter.getSettingsFile());
    logger.debug("Build file: " + startParameter.getBuildFile());
}
 
Example #13
Source File: BuildLogger.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void buildStarted(Gradle gradle) {
    StartParameter startParameter = gradle.getStartParameter();
    logger.info("Starting Build");
    logger.debug("Gradle user home: " + startParameter.getGradleUserHomeDir());
    logger.debug("Current dir: " + startParameter.getCurrentDir());
    logger.debug("Settings file: " + startParameter.getSettingsFile());
    logger.debug("Build file: " + startParameter.getBuildFile());
}
 
Example #14
Source File: DefaultTaskArtifactStateCacheAccess.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultTaskArtifactStateCacheAccess(Gradle gradle, CacheRepository cacheRepository, CacheDecorator decorator) {
    this.inMemoryDecorator = decorator;
    cache = cacheRepository
            .cache(gradle, "taskArtifacts")
            .withDisplayName("task history cache")
            .withLockOptions(mode(FileLockManager.LockMode.None)) // Lock on demand
            .open();
}
 
Example #15
Source File: TaskExecutionServices.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
TaskArtifactStateCacheAccess createCacheAccess(Gradle gradle, CacheRepository cacheRepository, InMemoryTaskArtifactCache inMemoryTaskArtifactCache, GradleBuildEnvironment environment) {
    CacheDecorator decorator;
    if (environment.isLongLivingProcess()) {
        decorator = inMemoryTaskArtifactCache;
    } else {
        decorator = new NoOpDecorator();
    }
    return new DefaultTaskArtifactStateCacheAccess(gradle, cacheRepository, decorator);
}
 
Example #16
Source File: TaskExecutionServices.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
TaskArtifactStateCacheAccess createCacheAccess(Gradle gradle, CacheRepository cacheRepository, InMemoryTaskArtifactCache inMemoryTaskArtifactCache, GradleBuildEnvironment environment) {
    CacheDecorator decorator;
    if (environment.isLongLivingProcess()) {
        decorator = inMemoryTaskArtifactCache;
    } else {
        decorator = new NoOpDecorator();
    }
    return new DefaultTaskArtifactStateCacheAccess(gradle, cacheRepository, decorator);
}
 
Example #17
Source File: GradleBuildComparison.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradleBuildComparison(
        ComparableGradleBuildExecuter sourceBuildExecuter,
        ComparableGradleBuildExecuter targetBuildExecuter,
        Logger logger,
        ProgressLogger progressLogger,
        Gradle gradle) {
    this.sourceBuildExecuter = sourceBuildExecuter;
    this.targetBuildExecuter = targetBuildExecuter;
    this.logger = logger;
    this.progressLogger = progressLogger;
    this.gradle = gradle;
}
 
Example #18
Source File: GradleBuildComparison.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradleBuildComparison(
        ComparableGradleBuildExecuter sourceBuildExecuter,
        ComparableGradleBuildExecuter targetBuildExecuter,
        Logger logger,
        ProgressLogger progressLogger,
        Gradle gradle) {
    this.sourceBuildExecuter = sourceBuildExecuter;
    this.targetBuildExecuter = targetBuildExecuter;
    this.logger = logger;
    this.progressLogger = progressLogger;
    this.gradle = gradle;
}
 
Example #19
Source File: GradleBuildComparison.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradleBuildComparison(
        ComparableGradleBuildExecuter sourceBuildExecuter,
        ComparableGradleBuildExecuter targetBuildExecuter,
        Logger logger,
        ProgressLogger progressLogger,
        Gradle gradle) {
    this.sourceBuildExecuter = sourceBuildExecuter;
    this.targetBuildExecuter = targetBuildExecuter;
    this.logger = logger;
    this.progressLogger = progressLogger;
    this.gradle = gradle;
}
 
Example #20
Source File: DefaultTaskArtifactStateCacheAccess.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultTaskArtifactStateCacheAccess(Gradle gradle, CacheRepository cacheRepository, CacheDecorator decorator) {
    this.inMemoryDecorator = decorator;
    cache = cacheRepository
            .cache(gradle, "taskArtifacts")
            .withDisplayName("task history cache")
            .withLockOptions(mode(FileLockManager.LockMode.None)) // Lock on demand
            .open();
}
 
Example #21
Source File: BuildLogger.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void buildStarted(Gradle gradle) {
    StartParameter startParameter = gradle.getStartParameter();
    logger.info("Starting Build");
    logger.debug("Gradle user home: " + startParameter.getGradleUserHomeDir());
    logger.debug("Current dir: " + startParameter.getCurrentDir());
    logger.debug("Settings file: " + startParameter.getSettingsFile());
    logger.debug("Build file: " + startParameter.getBuildFile());
}
 
Example #22
Source File: TaskExecutionServices.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
TaskArtifactStateCacheAccess createCacheAccess(Gradle gradle, CacheRepository cacheRepository, InMemoryTaskArtifactCache inMemoryTaskArtifactCache, GradleBuildEnvironment environment) {
    CacheDecorator decorator;
    if (environment.isLongLivingProcess()) {
        decorator = inMemoryTaskArtifactCache;
    } else {
        decorator = new NoOpDecorator();
    }
    return new DefaultTaskArtifactStateCacheAccess(gradle, cacheRepository, decorator);
}
 
Example #23
Source File: IPCUtilities.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This starts a gradle client for doing regular execution of a command. It expects the port number to set as a system property. Note: this is using gradle to find the port. See getPort().
 *
 * @param gradle the gradle object.
 */
public static void invokeExecuteGradleClient(Gradle gradle) {
    Integer port = getPort(gradle);
    if (port == null) {
        return;
    }

    ExecuteGradleCommandClientProtocol protocol = new ExecuteGradleCommandClientProtocol(gradle);
    GradleClient client = new GradleClient();
    client.start(protocol, port);
}
 
Example #24
Source File: NestedBuildTracker.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void buildStarted(Gradle gradle) {
    buildStack.add(0, (GradleInternal) gradle);
}
 
Example #25
Source File: ExecuteGradleCommandClientProtocol.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void buildStarted(Gradle build) {
    //we'll never get this message because execution has started before we were instantiated (and before we were able to add our listener).
}
 
Example #26
Source File: BuildResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public BuildResult(Gradle gradle, Throwable failure) {
    this.gradle = gradle;
    this.failure = failure;
}
 
Example #27
Source File: ExecuteGradleCommandClientProtocol.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExecuteGradleCommandClientProtocol(Gradle gradle) {
    this.gradle = gradle;
}
 
Example #28
Source File: BuildAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void projectsLoaded(Gradle gradle) {
}
 
Example #29
Source File: ReportGeneratingProfileListener.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void projectsEvaluated(Gradle gradle) {
    buildDir = gradle.getRootProject().getBuildDir();
}
 
Example #30
Source File: NestedBuildTracker.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void buildStarted(Gradle gradle) {
    buildStack.add(0, (GradleInternal) gradle);
}