Esempio n. 1
0
  /**
   * Creates the project.
   *
   * @return The project
   */
  public Project build() {
    if (projectDir == null) {
      try {
        projectDir = GFileUtils.canonicalise(File.createTempFile("gradle", "projectDir"));
        projectDir.delete();
        projectDir.mkdir();
        projectDir.deleteOnExit();
      } catch (IOException e) {
        throw new UncheckedIOException(e);
      }
    }

    final File homeDir = new File(projectDir, "gradleHome");

    StartParameter startParameter = new StartParameter();
    startParameter.setGradleUserHomeDir(new File(projectDir, "userHome"));

    ServiceRegistryFactory topLevelRegistry =
        new TestTopLevelBuildServiceRegistry(startParameter, homeDir);
    GradleInternal gradle = new DefaultGradle(null, startParameter, topLevelRegistry);

    DefaultProjectDescriptor projectDescriptor =
        new DefaultProjectDescriptor(
            null, "test", projectDir, new DefaultProjectDescriptorRegistry());
    ProjectInternal project =
        topLevelRegistry.get(IProjectFactory.class).createProject(projectDescriptor, null, gradle);

    gradle.setRootProject(project);
    gradle.setDefaultProject(project);

    return project;
  }
  private void _forceProjectHierarchyEvaluation(Project project) {
    GradleInternal gradleInternal = (GradleInternal) project.getGradle();

    ServiceRegistry serviceRegistry = gradleInternal.getServices();

    ProjectConfigurer projectConfigurer = serviceRegistry.get(ProjectConfigurer.class);

    projectConfigurer.configureHierarchy((ProjectInternal) project);
  }
  public void execute(BuildExecutionContext context) {
    GradleInternal gradle = context.getGradle();
    TaskGraphExecuter taskGraph = gradle.getTaskGraph();
    if (gradle.getStartParameter().isContinueOnFailure()) {
      taskGraph.useFailureHandler(new ContinueOnFailureHandler());
    }

    taskGraph.addTaskExecutionGraphListener(new BindAllReferencesOfProjectsToExecuteListener());
    taskGraph.execute();
  }
 public void load(
     ProjectDescriptor rootProjectDescriptor,
     GradleInternal gradle,
     ClassLoaderScope classLoaderScope) {
   buildLoader.load(rootProjectDescriptor, gradle, classLoaderScope);
   setProjectProperties(gradle.getRootProject());
 }
 private void createProjects(
     ProjectDescriptor rootProjectDescriptor,
     GradleInternal gradle,
     ClassLoaderScope buildRootClassLoaderScope) {
   ProjectInternal rootProject =
       projectFactory.createProject(
           rootProjectDescriptor,
           null,
           gradle,
           buildRootClassLoaderScope.createChild("root-project"),
           buildRootClassLoaderScope);
   gradle.setRootProject(rootProject);
   addProjects(rootProject, rootProjectDescriptor, gradle, buildRootClassLoaderScope);
 }
Esempio n. 6
0
  public TaskSelection getSelection(String path) {
    SetMultimap<String, Task> tasksByName;
    String baseName;
    String prefix;

    ProjectInternal project = gradle.getDefaultProject();

    if (path.contains(Project.PATH_SEPARATOR)) {
      project = projectFinder.findProject(path, project);
      baseName = StringUtils.substringAfterLast(path, Project.PATH_SEPARATOR);
      prefix = project.getPath() + Project.PATH_SEPARATOR;

      tasksByName = taskNameResolver.select(baseName, project);
    } else {
      baseName = path;
      prefix = "";

      tasksByName = taskNameResolver.selectAll(path, project);
    }

    Set<Task> tasks = tasksByName.get(baseName);
    if (!tasks.isEmpty()) {
      // An exact match
      return new TaskSelection(path, tasks);
    }

    NameMatcher matcher = new NameMatcher();
    String actualName = matcher.find(baseName, tasksByName.keySet());

    if (actualName != null) {
      // A partial match
      return new TaskSelection(prefix + actualName, tasksByName.get(actualName));
    }

    throw new TaskSelectionException(matcher.formatErrorMessage("task", project));
  }
 private void attachDefaultProject(ProjectDescriptor defaultProject, GradleInternal gradle) {
   gradle.setDefaultProject(
       gradle.getRootProject().getProjectRegistry().getProject(defaultProject.getPath()));
 }
  private DefaultGradleLauncher doNewInstance(
      StartParameter startParameter, BuildRequestMetaData requestMetaData) {
    final BuildScopeServices serviceRegistry =
        new BuildScopeServices(sharedServices, startParameter);
    serviceRegistry.add(BuildRequestMetaData.class, requestMetaData);
    serviceRegistry.add(BuildClientMetaData.class, requestMetaData.getClient());
    ListenerManager listenerManager = serviceRegistry.get(ListenerManager.class);
    LoggingManagerInternal loggingManager =
        serviceRegistry.newInstance(LoggingManagerInternal.class);
    loggingManager.setLevel(startParameter.getLogLevel());

    // this hooks up the ListenerManager and LoggingConfigurer so you can call Gradle.addListener()
    // with a StandardOutputListener.
    loggingManager.addStandardOutputListener(
        listenerManager.getBroadcaster(StandardOutputListener.class));
    loggingManager.addStandardErrorListener(
        listenerManager.getBroadcaster(StandardOutputListener.class));

    listenerManager.useLogger(
        new TaskExecutionLogger(serviceRegistry.get(ProgressLoggerFactory.class)));
    if (tracker.getCurrentBuild() == null) {
      listenerManager.useLogger(
          new BuildLogger(
              Logging.getLogger(BuildLogger.class),
              serviceRegistry.get(StyledTextOutputFactory.class),
              startParameter,
              requestMetaData));
    }
    listenerManager.addListener(tracker);
    listenerManager.addListener(new BuildCleanupListener(serviceRegistry));

    listenerManager.addListener(serviceRegistry.get(ProfileEventAdapter.class));
    if (startParameter.isProfile()) {
      listenerManager.addListener(new ReportGeneratingProfileListener());
    }
    ScriptUsageLocationReporter usageLocationReporter = new ScriptUsageLocationReporter();
    listenerManager.addListener(usageLocationReporter);
    DeprecationLogger.useLocationReporter(usageLocationReporter);

    GradleInternal gradle =
        serviceRegistry
            .get(Instantiator.class)
            .newInstance(
                DefaultGradle.class, tracker.getCurrentBuild(), startParameter, serviceRegistry);
    return new DefaultGradleLauncher(
        gradle,
        serviceRegistry.get(InitScriptHandler.class),
        new SettingsHandler(
            new DefaultSettingsFinder(new BuildLayoutFactory()),
            serviceRegistry.get(SettingsProcessor.class),
            new BuildSourceBuilder(
                this,
                serviceRegistry.get(ClassLoaderRegistry.class),
                serviceRegistry.get(CacheRepository.class))),
        serviceRegistry.get(BuildLoader.class),
        serviceRegistry.get(BuildConfigurer.class),
        gradle.getBuildListenerBroadcaster(),
        serviceRegistry.get(ExceptionAnalyser.class),
        loggingManager,
        listenerManager.getBroadcaster(ModelConfigurationListener.class),
        listenerManager.getBroadcaster(TasksCompletionListener.class),
        gradle.getServices().get(BuildExecuter.class));
  }