@Mutate void createPlayRunTask(ModelMap<Task> tasks, @Path("binaries") ModelMap<PlayApplicationBinarySpecInternal> playBinaries, final ServiceRegistry serviceRegistry, final PlayPluginConfigurations configurations, ProjectIdentifier projectIdentifier, final PlayToolChainInternal playToolChain) { for (final PlayApplicationBinarySpecInternal binary : playBinaries) { String runTaskName = binary.getTasks().taskName("run"); tasks.create(runTaskName, PlayRun.class, new Action<PlayRun>() { public void execute(PlayRun playRun) { playRun.setDescription("Runs the Play application for local development."); playRun.setGroup(RUN_GROUP); playRun.setHttpPort(DEFAULT_HTTP_PORT); playRun.setPlayToolProvider(playToolChain.select(binary.getTargetPlatform())); playRun.setApplicationJar(binary.getJarFile()); playRun.setAssetsJar(binary.getAssetsJarFile()); playRun.setAssetsDirs(binary.getAssets().getAssetDirs()); playRun.setRuntimeClasspath(configurations.getPlayRun().getNonChangingArtifacts()); playRun.setChangingClasspath(configurations.getPlayRun().getChangingArtifacts()); playRun.dependsOn(binary.getBuildTask()); } }); } }
/** * Create debug tasks * * @param tasks Task container to create new tasks * @param config Project configuration * @param project Current project identifier */ @Mutate public void createDebugTasks(ModelMap<Task> tasks, ProjectConfig config, ProjectIdentifier project) { // Create debug task to dump dependencies if (config.isEnableDebugTasks()) { tasks.create("debugDependencies", Task.class, tt -> { tt.doLast(t -> { PrintStream out = System.out; out.print("Project: "); out.println(project.getName()); for (Configuration configuration : t.getProject().getConfigurations()) { out.print(" Configuration: "); out.println(configuration.getName()); for (Dependency dependency : configuration.getDependencies()) { out.print(" Dependency: "); out.println(formatDependency(dependency)); } } }); }); } }
/** * Initialize the Eclipse configuration * * @param eclipse Eclipse configuration to initialize * @param project Current Gradle project */ @Defaults public void initializeEclipseConfig(EclipseConfig eclipse, ProjectIdentifier project) { try { Map<String, Object> context = new HashMap<>(); context.put("project", project); @NonNull URL resource = Validate .notNull(Resources.getResource(EclipseConfigPlugin.class, "codetemplates.xml")); String templateText = Resources.toString(resource, Charsets.UTF_8); TemplateEngine engine = new SimpleTemplateEngine(); String templates = engine.createTemplate(templateText).make(context).toString(); eclipse.getUi().setCodeTemplates(templates); } catch (Exception e) { throw new RuntimeException("Could not set code templates", e); } }
public <T extends ProjectIdentifier> T selectProject(ProjectRegistry<? extends T> registry) { checkPreconditions(registry); List<T> matches = new ArrayList<T>(); for (T project : registry.getAllProjects()) { if (select(project)) { matches.add(project); } } if (matches.isEmpty()) { throw new InvalidUserDataException(formatNoMatchesMessage()); } if (matches.size() != 1) { throw new InvalidUserDataException(formatMultipleMatchesMessage(matches)); } return matches.get(0); }
@Finalize void applyFallbackSourceConventions(@Each LanguageSourceSet languageSourceSet, ProjectIdentifier projectIdentifier) { // Only apply default locations when none explicitly configured if (languageSourceSet.getSource().getSourceDirectories().isEmpty()) { File baseDir = projectIdentifier.getProjectDir(); String defaultSourceDir = Joiner.on(File.separator).skipNulls().join(baseDir.getPath(), "src", emptyToNull(languageSourceSet.getParentName()), emptyToNull(languageSourceSet.getName())); languageSourceSet.getSource().srcDir(defaultSourceDir); } }
@Model public static VisualStudioExtensionInternal visualStudio(ServiceRegistry serviceRegistry, ProjectIdentifier projectIdentifier) { Instantiator instantiator = serviceRegistry.get(Instantiator.class); ProjectModelResolver projectModelResolver = serviceRegistry.get(ProjectModelResolver.class); FileResolver fileResolver = serviceRegistry.get(FileResolver.class); return instantiator.newInstance(DefaultVisualStudioExtension.class, projectIdentifier, instantiator, projectModelResolver, fileResolver); }
@Mutate public static void includeBuildFileInProject(VisualStudioExtensionInternal visualStudio, final ProjectIdentifier projectIdentifier) { visualStudio.getProjects().all(new Action<VisualStudioProject>() { public void execute(VisualStudioProject project) { if (projectIdentifier.getBuildFile() != null) { ((DefaultVisualStudioProject) project).addSourceFile(projectIdentifier.getBuildFile()); } } }); }
@Mutate void addConfiguredPublicationsToProjectPublicationRegistry(ProjectPublicationRegistry projectPublicationRegistry, PublishingExtension extension, ProjectIdentifier projectIdentifier) { for (Publication publication : extension.getPublications()) { PublicationInternal internalPublication = (PublicationInternal) publication; projectPublicationRegistry.registerPublication(projectIdentifier.getPath(), new DefaultProjectPublication(internalPublication.getCoordinates())); } }
public <T extends ProjectIdentifier> T selectProject(ProjectRegistry<? extends T> registry) { checkPreconditions(registry); List<T> matches = new ArrayList<T>(); select(registry, matches); if (matches.isEmpty()) { throw new InvalidUserDataException(formatNoMatchesMessage()); } if (matches.size() != 1) { throw new InvalidUserDataException(formatMultipleMatchesMessage(matches)); } return matches.get(0); }
@Override protected <T extends ProjectIdentifier> void select(ProjectRegistry<? extends T> candidates, List<? super T> matches) { for (T candidate : candidates.getAllProjects()) { if (candidate.getProjectDir().equals(dir)) { matches.add(candidate); } } }
@Override protected <T extends ProjectIdentifier> void select(ProjectRegistry<? extends T> candidates, List<? super T> matches) { for (T candidate : candidates.getAllProjects()) { if (candidate.getProjectDir().equals(currentDir)) { matches.add(candidate); } } if (useRootWhenNoMatch && matches.isEmpty()) { matches.add(candidates.getProject(":")); } }
@Override protected <T extends ProjectIdentifier> void select(ProjectRegistry<? extends T> candidates, List<? super T> matches) { for (T candidate : candidates.getAllProjects()) { if (candidate.getBuildFile().equals(buildFile)) { matches.add(candidate); } } }
@ComponentBinaries void createBinaries(ModelMap<PlayApplicationBinarySpec> binaries, final PlayApplicationSpecInternal componentSpec, final PlatformResolvers platforms, final PlayToolChainInternal playToolChainInternal, final PlayPluginConfigurations configurations, @Path("buildDir") final File buildDir, final ProjectIdentifier projectIdentifier) { binaries.create("binary", new Action<PlayApplicationBinarySpec>() { public void execute(PlayApplicationBinarySpec playBinary) { PlayApplicationBinarySpecInternal playBinaryInternal = (PlayApplicationBinarySpecInternal) playBinary; final File binaryBuildDir = new File(buildDir, playBinaryInternal.getProjectScopedName()); final PlayPlatform chosenPlatform = resolveTargetPlatform(componentSpec, platforms); initialiseConfigurations(configurations, chosenPlatform); playBinaryInternal.setTargetPlatform(chosenPlatform); playBinaryInternal.setToolChain(playToolChainInternal); File mainJar = new File(binaryBuildDir, "lib/" + projectIdentifier.getName() + ".jar"); File assetsJar = new File(binaryBuildDir, "lib/" + projectIdentifier.getName() + "-assets.jar"); playBinaryInternal.setJarFile(mainJar); playBinaryInternal.setAssetsJarFile(assetsJar); configurations.getPlay().addArtifact(new DefaultPublishArtifact(projectIdentifier.getName(), "jar", "jar", null, new Date(), mainJar, playBinaryInternal)); configurations.getPlay().addArtifact(new DefaultPublishArtifact(projectIdentifier.getName(), "jar", "jar", "assets", new Date(), assetsJar, playBinaryInternal)); JvmAssembly jvmAssembly = ((PlayApplicationBinarySpecInternal) playBinary).getAssembly(); jvmAssembly.getClassDirectories().add(new File(binaryBuildDir, "classes")); jvmAssembly.getResourceDirectories().add(new File(binaryBuildDir, "resources")); PublicAssets assets = playBinary.getAssets(); assets.addAssetDir(new File(projectIdentifier.getProjectDir(), "public")); playBinaryInternal.setClasspath(configurations.getPlay().getAllArtifacts()); } }); }
@Model(ModelConstants.NDK_HANDLER) public NdkHandler ndkHandler( ProjectIdentifier projectId, @Path("android.compileSdkVersion") String compileSdkVersion, @Path("android.ndk") NdkConfig ndkConfig) { while (projectId.getParentIdentifier() != null) { projectId = projectId.getParentIdentifier(); } return new NdkHandler(projectId.getProjectDir(), compileSdkVersion, ndkConfig.getToolchain(), ndkConfig.getToolchainVersion()); }
protected RegisterTypeRule(ModelType<? extends T> type, ModelType<? extends U> implementation, ModelRuleDescriptor descriptor, Action<? super RegistrationContext<T, U>> registerAction) { this.type = type; this.implementation = implementation; this.descriptor = descriptor; this.registerAction = registerAction; subject = ModelReference.of("extensions", ExtensionContainer.class); inputs = ImmutableList.<ModelReference<?>>of(ModelReference.of(ProjectIdentifier.class)); }
public final void mutate(final ExtensionContainer extensionContainer, final Inputs inputs) { RuleContext.inContext(getDescriptor(), new Runnable() { public void run() { RegistrationContext<T, U> context = new RegistrationContext<T, U>(type, implementation, extensionContainer, inputs.get(0, ModelType.of(ProjectIdentifier.class)).getInstance()); registerAction.execute(context); } }); }
private <T extends ComponentSpec, I extends BaseComponentSpec> void doRegister(final ModelType<T> type, final ModelType<I> implementation, final ProjectSourceSet projectSourceSet, ComponentSpecContainer componentSpecs, final ProjectIdentifier projectIdentifier) { componentSpecs.registerFactory(type.getConcreteClass(), new NamedDomainObjectFactory<T>() { public T create(String name) { FunctionalSourceSet componentSourceSet = projectSourceSet.maybeCreate(name); ComponentSpecIdentifier id = new DefaultComponentSpecIdentifier(projectIdentifier.getPath(), name); // safe because we implicitly know that U extends V, but can't express this in the type system @SuppressWarnings("unchecked") T created = (T) BaseComponentSpec.create(implementation.getConcreteClass(), id, componentSourceSet, instantiator); return created; } }); }
public boolean containsProject(ProjectRegistry<?> registry) { checkPreconditions(registry); for (ProjectIdentifier project : registry.getAllProjects()) { if (select(project)) { return true; } } return false; }
@Hidden @Model ComponentSpecFactory componentSpecFactory(ProjectIdentifier projectIdentifier, Instantiator instantiator, ITaskFactory taskFactory, SourceDirectorySetFactory sourceDirectorySetFactory) { return new ComponentSpecFactory(projectIdentifier, instantiator, taskFactory, sourceDirectorySetFactory); }
public ProjectLayout(ProjectIdentifier projectIdentifier, File buildDir) { this.projectIdentifier = projectIdentifier; this.buildDir = buildDir; }
public ProjectIdentifier getProjectIdentifier() { return projectIdentifier; }
@Model public ProjectLayout projectLayout(ProjectIdentifier projectIdentifier, @Path("buildDir") File buildDir) { return new ProjectLayout(projectIdentifier, buildDir); }
public DefaultVisualStudioExtension(ProjectIdentifier projectIdentifier, Instantiator instantiator, ProjectModelResolver projectModelResolver, FileResolver fileResolver) { VisualStudioProjectMapper projectMapper = new VisualStudioProjectMapper(); projectRegistry = new VisualStudioProjectRegistry(projectIdentifier, fileResolver, projectMapper, instantiator); VisualStudioProjectResolver projectResolver = new VisualStudioProjectResolver(projectModelResolver); solutionRegistry = new VisualStudioSolutionRegistry(projectIdentifier, fileResolver, projectResolver, instantiator); }
public VisualStudioProjectRegistry(ProjectIdentifier projectIdentifier, FileResolver fileResolver, VisualStudioProjectMapper projectMapper, Instantiator instantiator) { super(DefaultVisualStudioProject.class, instantiator); this.projectIdentifier = projectIdentifier; this.fileResolver = fileResolver; this.projectMapper = projectMapper; }
public VisualStudioSolutionRegistry(ProjectIdentifier projectIdentifier, FileResolver fileResolver, VisualStudioProjectResolver projectResolver, Instantiator instantiator) { super(DefaultVisualStudioSolution.class, instantiator); this.projectIdentifier = projectIdentifier; this.fileResolver = fileResolver; this.projectResolver = projectResolver; }
public boolean containsProject(ProjectRegistry<? extends ProjectIdentifier> registry) { checkPreconditions(registry); List<ProjectIdentifier> matches = new ArrayList<ProjectIdentifier>(); select(registry, matches); return !matches.isEmpty(); }
protected String formatMultipleMatchesMessage(Iterable<? extends ProjectIdentifier> matches) { return String.format("Multiple projects in this build have project directory '%s': %s", dir, matches); }
public ProjectIdentifier getParentIdentifier() { return parent; }
protected String formatMultipleMatchesMessage(Iterable<? extends ProjectIdentifier> matches) { return String.format("Multiple projects in this build have project directory '%s': %s", currentDir, matches); }
protected String formatMultipleMatchesMessage(Iterable<? extends ProjectIdentifier> matches) { return String.format("Multiple projects in this build have build file '%s': %s", buildFile, matches); }
@Mutate void createTestTasks(ModelMap<Task> tasks, @Path("binaries") ModelMap<PlayApplicationBinarySpecInternal> playBinaries, final PlayPluginConfigurations configurations, final FileResolver fileResolver, final ProjectIdentifier projectIdentifier, @Path("buildDir") final File buildDir) { for (final PlayApplicationBinarySpecInternal binary : playBinaries) { final PlayToolProvider playToolProvider = binary.getToolChain().select(binary.getTargetPlatform()); final FileCollection testCompileClasspath = getTestCompileClasspath(binary, playToolProvider, configurations); final String testCompileTaskName = binary.getTasks().taskName("compile", "tests"); final File testSourceDir = fileResolver.resolve("test"); final FileCollection testSources = new SimpleFileCollection(testSourceDir).getAsFileTree().matching(new PatternSet().include("**/*.scala", "**/*.java")); final File testClassesDir = new File(buildDir, binary.getProjectScopedName() + "/testClasses"); tasks.create(testCompileTaskName, PlatformScalaCompile.class, new Action<PlatformScalaCompile>() { public void execute(PlatformScalaCompile scalaCompile) { scalaCompile.setDescription("Compiles the scala and java test sources for the " + binary.getDisplayName() + "."); scalaCompile.setClasspath(testCompileClasspath); scalaCompile.dependsOn(binary.getBuildTask()); scalaCompile.setPlatform(binary.getTargetPlatform().getScalaPlatform()); scalaCompile.setDestinationDir(testClassesDir); scalaCompile.setSource(testSources); String targetCompatibility = binary.getTargetPlatform().getJavaPlatform().getTargetCompatibility().getMajorVersion(); scalaCompile.setSourceCompatibility(targetCompatibility); scalaCompile.setTargetCompatibility(targetCompatibility); IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions(); incrementalOptions.setAnalysisFile(new File(buildDir, "tmp/scala/compilerAnalysis/" + testCompileTaskName + ".analysis")); } }); final String testTaskName = binary.getTasks().taskName("test"); final File binaryBuildDir = new File(buildDir, binary.getProjectScopedName()); tasks.create(testTaskName, Test.class, new Action<Test>() { public void execute(Test test) { test.setDescription("Runs " + WordUtils.uncapitalize(binary.getDisplayName() + ".")); test.setClasspath(getRuntimeClasspath(testClassesDir, testCompileClasspath)); test.setTestClassesDir(testClassesDir); test.setBinResultsDir(new File(binaryBuildDir, "results/" + testTaskName + "/bin")); test.getReports().getJunitXml().setDestination(new File(binaryBuildDir, "reports/test/xml")); test.getReports().getHtml().setDestination(new File(binaryBuildDir, "reports/test")); test.dependsOn(testCompileTaskName); test.setWorkingDir(projectIdentifier.getProjectDir()); } }); binary.getTasks().add(tasks.get(testTaskName)); } }
public RegistrationContext(ModelType<? extends T> type, ModelType<? extends U> implementation, ExtensionContainer extensions, ProjectIdentifier projectIdentifier) { this.type = type; this.implementation = implementation; this.extensions = extensions; this.projectIdentifier = projectIdentifier; }