Java Code Examples for org.gradle.api.internal.project.ProjectInternal

The following examples show how to use org.gradle.api.internal.project.ProjectInternal. 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 Set<ResolvedDependency> doResolve(final Collection<ArtifactSpec> deps) {
    final Configuration config = this.project.getConfigurations().detachedConfiguration();
    final DependencySet dependencySet = config.getDependencies();

    deps.stream()
            .forEach(spec -> {
                if (projects.containsKey(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version())) {
                    dependencySet.add(new DefaultProjectDependency((ProjectInternal) projects.get(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version()), new DefaultProjectAccessListener(), false));
                } else {
                    final DefaultExternalModuleDependency d =
                            new DefaultExternalModuleDependency(spec.groupId(), spec.artifactId(), spec.version());
                    final DefaultDependencyArtifact da =
                            new DefaultDependencyArtifact(spec.artifactId(), spec.type(), spec.type(), spec.classifier(), null);
                    d.addArtifact(da);
                    d.getExcludeRules().add(new DefaultExcludeRule());
                    dependencySet.add(d);
                }
            });

    return config.getResolvedConfiguration().getFirstLevelModuleDependencies();
}
 
Example 2
private OsgiManifest createDefaultOsgiManifest(final ProjectInternal project) {
    OsgiManifest osgiManifest = project.getServices().get(Instantiator.class).newInstance(DefaultOsgiManifest.class, project.getFileResolver());
    ConventionMapping mapping = ((IConventionAware) osgiManifest).getConventionMapping();
    final OsgiHelper osgiHelper = new OsgiHelper();

    mapping.map("version", new Callable<Object>() {
        public Object call() throws Exception {
            return osgiHelper.getVersion(project.getVersion().toString());
        }
    });
    mapping.map("name", new Callable<Object>() {
        public Object call() throws Exception {
            return project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName();
        }
    });
    mapping.map("symbolicName", new Callable<Object>() {
        public Object call() throws Exception {
            return osgiHelper.getBundleSymbolicName(project);
        }
    });

    return osgiManifest;
}
 
Example 3
ArtifactDependencyResolver createArtifactDependencyResolver(ResolveIvyFactory resolveIvyFactory, LocalComponentFactory publishModuleDescriptorConverter, DependencyDescriptorFactory dependencyDescriptorFactory,
                                                            CacheLockingManager cacheLockingManager, IvyContextManager ivyContextManager, ResolutionResultsStoreFactory resolutionResultsStoreFactory,
                                                            LatestStrategy latestStrategy, ProjectRegistry<ProjectInternal> projectRegistry, ComponentIdentifierFactory componentIdentifierFactory) {
    ArtifactDependencyResolver resolver = new DefaultDependencyResolver(
            resolveIvyFactory,
            publishModuleDescriptorConverter,
            dependencyDescriptorFactory,
            new DefaultProjectComponentRegistry(
                    publishModuleDescriptorConverter,
                    projectRegistry),
            cacheLockingManager,
            ivyContextManager,
            resolutionResultsStoreFactory,
            latestStrategy);
    return new ErrorHandlingArtifactDependencyResolver(
            new ShortcircuitEmptyConfigsArtifactDependencyResolver(
                    new SelfResolvingDependencyResolver(
                            new CacheLockingArtifactDependencyResolver(
                                    cacheLockingManager,
                                    resolver)),
                    componentIdentifierFactory));
}
 
Example 4
public void apply(Project project) {
    project.getPlugins().apply(BasePlugin.class);
    project.getPlugins().apply(ReportingBasePlugin.class);
    project.getPlugins().apply(JavaLanguagePlugin.class);

    JavaPluginConvention javaConvention = new JavaPluginConvention((ProjectInternal) project, instantiator);
    project.getConvention().getPlugins().put("java", javaConvention);

    configureCompileDefaults(project, javaConvention);
    configureSourceSetDefaults(javaConvention);

    configureJavaDoc(project, javaConvention);
    configureTest(project, javaConvention);
    configureCheck(project);
    configureBuild(project);
    configureBuildNeeded(project);
    configureBuildDependents(project);
}
 
Example 5
public void execute(ProjectInternal project) {
    ProjectSourceSet projectSourceSet = project.getExtensions().getByType(ProjectSourceSet.class);
    for (FunctionalSourceSet functionalSourceSet : projectSourceSet) {
        for (LanguageSourceSet languageSourceSet : functionalSourceSet) {
            // Only apply default locations when none explicitly configured
            if (languageSourceSet.getSource().getSrcDirs().isEmpty()) {
                languageSourceSet.getSource().srcDir(String.format("src/%s/%s", functionalSourceSet.getName(), languageSourceSet.getName()));
            }
        }
        for (HeaderExportingSourceSet headerSourceSet : functionalSourceSet.withType(HeaderExportingSourceSet.class)) {
            // Only apply default locations when none explicitly configured
            if (headerSourceSet.getExportedHeaders().getSrcDirs().isEmpty()) {
                headerSourceSet.getExportedHeaders().srcDir(String.format("src/%s/headers", functionalSourceSet.getName()));
            }

            headerSourceSet.getImplicitHeaders().setSrcDirs(headerSourceSet.getSource().getSrcDirs());
            headerSourceSet.getImplicitHeaders().include("**/*.h");
        }
    }
}
 
Example 6
private TaskInternal createTaskObject(ProjectInternal project, final Class<? extends TaskInternal> type, String name, boolean generateGetters) {
    if (!Task.class.isAssignableFrom(type)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create task of type '%s' as it does not implement the Task interface.",
                type.getSimpleName()));
    }

    final Class<? extends TaskInternal> generatedType;
    if (generateGetters) {
        generatedType = generator.generate(type);
    } else {
        generatedType = type;
    }

    return AbstractTask.injectIntoNewInstance(project, name, new Callable<TaskInternal>() {
        public TaskInternal call() throws Exception {
            try {
                return instantiator.newInstance(generatedType);
            } catch (ObjectInstantiationException e) {
                throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", type.getSimpleName()),
                        e.getCause());
            }
        }
    });
}
 
Example 7
TaskFactory(ClassGenerator generator, ProjectInternal project, Instantiator instantiator) {
    this.generator = generator;
    this.project = project;
    this.instantiator = instantiator;


    validTaskArguments = new HashSet<String>();
    validTaskArguments.add(Task.TASK_ACTION);
    validTaskArguments.add(Task.TASK_DEPENDS_ON);
    validTaskArguments.add(Task.TASK_DESCRIPTION);
    validTaskArguments.add(Task.TASK_GROUP);
    validTaskArguments.add(Task.TASK_NAME);
    validTaskArguments.add(Task.TASK_OVERWRITE);
    validTaskArguments.add(Task.TASK_TYPE);

}
 
Example 8
public Task findByPath(String path) {
    if (!GUtil.isTrue(path)) {
        throw new InvalidUserDataException("A path must be specified!");
    }
    if (!path.contains(Project.PATH_SEPARATOR)) {
        return findByName(path);
    }

    String projectPath = StringUtils.substringBeforeLast(path, Project.PATH_SEPARATOR);
    ProjectInternal project = this.project.findProject(!GUtil.isTrue(projectPath) ? Project.PATH_SEPARATOR : projectPath);
    if (project == null) {
        return null;
    }
    projectAccessListener.beforeRequestingTaskByPath(project);

    return project.getTasks().findByName(StringUtils.substringAfterLast(path, Project.PATH_SEPARATOR));
}
 
Example 9
public Task findByPath(String path) {
    if (!GUtil.isTrue(path)) {
        throw new InvalidUserDataException("A path must be specified!");
    }
    if (!path.contains(Project.PATH_SEPARATOR)) {
        return findByName(path);
    }

    String projectPath = StringUtils.substringBeforeLast(path, Project.PATH_SEPARATOR);
    ProjectInternal project = this.project.findProject(!GUtil.isTrue(projectPath) ? Project.PATH_SEPARATOR : projectPath);
    if (project == null) {
        return null;
    }
    projectAccessListener.beforeRequestingTaskByPath(project);

    return project.getTasks().findByName(StringUtils.substringAfterLast(path, Project.PATH_SEPARATOR));
}
 
Example 10
public ReportingExtension(Project project) {
    this.project = (ProjectInternal)project;
    this.baseDir = new Callable<File>() {
        public File call() throws Exception {
            return ReportingExtension.this.project.getServices().
                    get(FileLookup.class).getFileResolver(ReportingExtension.this.project.getBuildDir()).
                    resolve(DEFAULT_REPORTS_DIR_NAME);
        }
    };
}
 
Example 11
public void apply(ProjectInternal project) {
    Convention convention = project.getConvention();
    ReportingExtension extension = project.getExtensions().create(ReportingExtension.NAME, ReportingExtension.class, project);

    // This convention is deprecated
    convention.getPlugins().put("reportingBase", new ReportingBasePluginConvention(project, extension));
}
 
Example 12
public void execute(ProjectInternal project) {
    ProjectSourceSet projectSourceSet = project.getExtensions().getByType(ProjectSourceSet.class);
    for (FunctionalSourceSet functionalSourceSet : projectSourceSet) {
        for (LanguageSourceSetInternal languageSourceSet : functionalSourceSet.withType(LanguageSourceSetInternal.class)) {
            Task generatorTask = languageSourceSet.getGeneratorTask();
            if (generatorTask != null) {
                languageSourceSet.builtBy(generatorTask);
                maybeSetSourceDir(languageSourceSet.getSource(), generatorTask, "sourceDir");
                if (languageSourceSet instanceof HeaderExportingSourceSet) {
                    maybeSetSourceDir(((HeaderExportingSourceSet) languageSourceSet).getExportedHeaders(), generatorTask, "headerDir");
                }
            }
        }
    }
}
 
Example 13
public ReportingExtension(Project project) {
    this.project = (ProjectInternal)project;
    this.baseDir = new Callable<File>() {
        public File call() throws Exception {
            return ReportingExtension.this.project.getServices().
                    get(FileLookup.class).getFileResolver(ReportingExtension.this.project.getBuildDir()).
                    resolve(DEFAULT_REPORTS_DIR_NAME);
        }
    };
}
 
Example 14
ServiceRegistryFactory createServiceRegistryFactory(final ServiceRegistry services) {
    return new ServiceRegistryFactory() {
        public ServiceRegistry createFor(Object domainObject) {
            if (domainObject instanceof ProjectInternal) {
                ProjectScopeServices projectScopeServices = new ProjectScopeServices(services, (ProjectInternal) domainObject);
                registries.add(projectScopeServices);
                return projectScopeServices;
            }
            throw new UnsupportedOperationException();
        }
    };
}
 
Example 15
public void execute(final ProjectInternal projectInternal) {
    if (projectInternal.getParent() == null) {
        projectInternal.getTasks().addPlaceholderAction("init", new Runnable() {
            public void run() {
                projectInternal.getPlugins().apply("build-init");
            }
        });
    }
}
 
Example 16
public void execute(ProjectInternal project) {
    ToolingModelBuilderRegistry modelBuilderRegistry = project.getServices().get(ToolingModelBuilderRegistry.class);
    ProjectPublicationRegistry projectPublicationRegistry = project.getServices().get(ProjectPublicationRegistry.class);
    ProjectTaskLister taskLister = project.getServices().get(ProjectTaskLister.class);

    GradleProjectBuilder gradleProjectBuilder  = new GradleProjectBuilder();
    IdeaModelBuilder ideaModelBuilder = new IdeaModelBuilder(gradleProjectBuilder);
    modelBuilderRegistry.register(new EclipseModelBuilder(gradleProjectBuilder));
    modelBuilderRegistry.register(ideaModelBuilder);
    modelBuilderRegistry.register(gradleProjectBuilder);
    modelBuilderRegistry.register(new GradleBuildBuilder());
    modelBuilderRegistry.register(new BasicIdeaModelBuilder(ideaModelBuilder));
    modelBuilderRegistry.register(new BuildInvocationsBuilder(taskLister));
    modelBuilderRegistry.register(new PublicationsBuilder(projectPublicationRegistry));
}
 
Example 17
ServiceRegistryFactory createServiceRegistryFactory(final ServiceRegistry services) {
    return new ServiceRegistryFactory() {
        public ServiceRegistry createFor(Object domainObject) {
            if (domainObject instanceof ProjectInternal) {
                ProjectScopeServices projectScopeServices = new ProjectScopeServices(services, (ProjectInternal) domainObject);
                registries.add(projectScopeServices);
                return projectScopeServices;
            }
            throw new UnsupportedOperationException();
        }
    };
}
 
Example 18
public void configureHierarchy(ProjectInternal project) {
    if (cancellationToken.isCancellationRequested()) {
        throw new BuildCancelledException();
    }
    project.evaluate();
    for (Project sub : project.getSubprojects()) {
        if (cancellationToken.isCancellationRequested()) {
            throw new BuildCancelledException();
        }
        ((ProjectInternal) sub).evaluate();
    }
}
 
Example 19
@Override
protected void generate(Project project) throws IOException {
    BuildClientMetaData metaData = getClientMetaData();

    StyledTextOutput textOutput = getRenderer().getTextOutput();

    render(project, new GraphRenderer(textOutput), true, textOutput);
    if (project.getChildProjects().isEmpty()) {
        textOutput.withStyle(Info).text("No sub-projects");
        textOutput.println();
    }

    textOutput.println();
    textOutput.text("To see a list of the tasks of a project, run ");
    metaData.describeCommand(textOutput.withStyle(UserInput), String.format("<project-path>:%s",
            ProjectInternal.TASKS_TASK));
    textOutput.println();

    textOutput.text("For example, try running ");
    Project exampleProject = project.getChildProjects().isEmpty() ? project : getChildren(project).get(0);
    metaData.describeCommand(textOutput.withStyle(UserInput), exampleProject.absoluteProjectPath(
            ProjectInternal.TASKS_TASK));
    textOutput.println();

    if (project != project.getRootProject()) {
        textOutput.println();
        textOutput.text("To see a list of all the projects in this build, run ");
        metaData.describeCommand(textOutput.withStyle(UserInput), project.getRootProject().absoluteProjectPath(
                ProjectInternal.PROJECTS_TASK));
        textOutput.println();
    }
}
 
Example 20
public void apply(ProjectInternal project) {
    this.project = project;
    JavaBasePlugin javaBasePlugin = project.getPlugins().apply(JavaBasePlugin.class);

    configureConfigurations(project);
    configureGroovyRuntimeExtension();
    configureCompileDefaults();
    configureSourceSetDefaults(javaBasePlugin);

    configureGroovydoc();
}
 
Example 21
public DefaultProjectDependency(ProjectInternal dependencyProject, String configuration,
                                ProjectAccessListener projectAccessListener, boolean buildProjectDependencies) {
    super(configuration);
    this.dependencyProject = dependencyProject;
    this.projectAccessListener = projectAccessListener;
    this.buildProjectDependencies = buildProjectDependencies;
}
 
Example 22
public void execute(ProjectInternal project) {
    LOGGER.info(String.format("Evaluating %s using %s.", project, project.getBuildScriptSource().getDisplayName()));
    Clock clock = new Clock();
    try {
        ScriptPlugin configurer = configurerFactory.create(project.getBuildScriptSource(), project.getBuildscript(), project.getClassLoaderScope(), project.getBaseClassLoaderScope(), "buildscript", ProjectScript.class, true);
        configurer.apply(project);
    } finally {
        LOGGER.debug("Timing: Running the build script took " + clock.getTime());
    }
}
 
Example 23
public void execute(final ProjectInternal projectInternal) {
    if (projectInternal.getParent() == null) {
        projectInternal.getTasks().addPlaceholderAction("init", new Runnable() {
            public void run() {
                projectInternal.getPlugins().apply("build-init");
            }
        });
    }
}
 
Example 24
public ProjectScopeServices(final ServiceRegistry parent, final ProjectInternal project) {
    super(parent);
    this.project = project;
    register(new Action<ServiceRegistration>() {
        public void execute(ServiceRegistration registration) {
            registration.add(DomainObjectContext.class, project);
            parent.get(DependencyManagementServices.class).addDslServices(registration);
            for (PluginServiceRegistry pluginServiceRegistry : parent.getAll(PluginServiceRegistry.class)) {
                pluginServiceRegistry.registerProjectServices(registration);
            }
        }
    });
}
 
Example 25
public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier) throws BuildExceptionVersion1, InternalUnsupportedModelException {
    BuildCancellationToken cancellationToken = gradle.getServices().get(BuildCancellationToken.class);
    if (cancellationToken.isCancellationRequested()) {
        throw new BuildCancelledException(String.format("Could not build '%s' model. Build cancelled.", modelIdentifier.getName()));
    }
    ToolingModelBuilderRegistry modelBuilderRegistry;
    ProjectInternal project;
    boolean isImplicitProject;
    if (target == null) {
        project = gradle.getDefaultProject();
        isImplicitProject = true;
    } else if (target instanceof GradleProjectIdentity) {
        GradleProjectIdentity gradleProject = (GradleProjectIdentity) target;
        project = gradle.getRootProject().project(gradleProject.getPath());
        isImplicitProject = false;
    } else {
        throw new IllegalArgumentException("Don't know how to build models for " + target);
    }
    modelBuilderRegistry = project.getServices().get(ToolingModelBuilderRegistry.class);

    ToolingModelBuilder builder;
    try {
        builder = modelBuilderRegistry.getBuilder(modelIdentifier.getName());
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException) (new InternalUnsupportedModelException()).initCause(e);
    }
    Object model;
    if (builder instanceof ProjectSensitiveToolingModelBuilder) {
        model = ((ProjectSensitiveToolingModelBuilder) builder).buildAll(modelIdentifier.getName(), project, isImplicitProject);
    } else {
        model = builder.buildAll(modelIdentifier.getName(), project);
    }
    return new ProviderBuildResult<Object>(model);
}
 
Example 26
Source Project: app-gradle-plugin   Source File: SourceContextPluginTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultConfiguration() throws IOException {
  File appengineWebXml =
      new File(testProjectDir.getRoot(), "src/main/webapp/WEB-INF/appengine-web.xml");
  appengineWebXml.getParentFile().mkdirs();
  appengineWebXml.createNewFile();
  Files.write(appengineWebXml.toPath(), "<web-app/>".getBytes());

  Project project = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build();
  project.getPluginManager().apply(JavaPlugin.class);
  project.getPluginManager().apply(WarPlugin.class);
  project.getPluginManager().apply(AppEngineStandardPlugin.class);
  project.getPluginManager().apply(SourceContextPlugin.class);

  DeployExtension deploy =
      project.getExtensions().getByType(AppEngineStandardExtension.class).getDeploy();
  deploy.setProjectId("project");
  deploy.setVersion("version");
  ((ProjectInternal) project).evaluate();

  ExtensionAware ext =
      (ExtensionAware)
          project.getExtensions().getByName(AppEngineCorePluginConfiguration.APPENGINE_EXTENSION);
  GenRepoInfoFileExtension genRepoInfoExt =
      new ExtensionUtil(ext).get(SourceContextPlugin.SOURCE_CONTEXT_EXTENSION);
  Assert.assertEquals(
      new File(project.getBuildDir(), "sourceContext"), genRepoInfoExt.getOutputDirectory());
}
 
Example 27
public GroovyCompilerFactory(ProjectInternal project, IsolatedAntBuilder antBuilder, ClassPathRegistry classPathRegistry, DefaultJavaCompilerFactory javaCompilerFactory,
                             CompilerDaemonManager compilerDaemonManager, InProcessCompilerDaemonFactory inProcessCompilerDaemonFactory) {
    this.project = project;
    this.antBuilder = antBuilder;
    this.classPathRegistry = classPathRegistry;
    this.javaCompilerFactory = javaCompilerFactory;
    this.compilerDaemonManager = compilerDaemonManager;
    this.inProcessCompilerDaemonFactory = inProcessCompilerDaemonFactory;
}
 
Example 28
ServiceRegistryFactory createServiceRegistryFactory(final ServiceRegistry services) {
    return new ServiceRegistryFactory() {
        public ServiceRegistry createFor(Object domainObject) {
            if (domainObject instanceof ProjectInternal) {
                ProjectScopeServices projectScopeServices = new ProjectScopeServices(services, (ProjectInternal) domainObject);
                registries.add(projectScopeServices);
                return projectScopeServices;
            }
            throw new UnsupportedOperationException();
        }
    };
}
 
Example 29
public void execute(ProjectInternal project) {
    LOGGER.info(String.format("Evaluating %s using %s.", project, project.getBuildScriptSource().getDisplayName()));
    Clock clock = new Clock();
    try {
        ScriptPlugin configurer = configurerFactory.create(project.getBuildScriptSource(), project.getBuildscript(), project.getClassLoaderScope(), "buildscript", ProjectScript.class);

        configurer.apply(project);
    } finally {
        LOGGER.debug("Timing: Running the build script took " + clock.getTime());
    }
}
 
Example 30
private void ensureAllProjectsEvaluated(GradleInternal gradle) {
    gradle.getRootProject().allprojects((Action) new Action<ProjectInternal>() {
        public void execute(ProjectInternal projectInternal) {
            projectInternal.evaluate();
        }
    });
}