Java Code Examples for org.gradle.api.Project#files()

The following examples show how to use org.gradle.api.Project#files() . 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: ForkedGenerateTask.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
private void initClassPath() {
    RuntimeClassLoaderFactory classLoaderFactory = new RuntimeClassLoaderFactory(getProject(), module);

    Set<File> classpath = new HashSet<>();
    classpath.addAll(classLoaderFactory.getProjectLibraries());
    try {
        for (URL pluginUrl : classLoaderFactory.getPluginUrls()) {
            classpath.add(Paths.get(pluginUrl.toURI()).toFile());
        }
    } catch (URISyntaxException e) {
        throw new IllegalStateException(e);
    }

    Project project = getProject();
    ConfigurableFileCollection files = project.files(classpath.toArray());
    setClasspath(files);
}
 
Example 2
Source File: CompileJavaTaskMutatorTest.java    From gradle-modules-plugin with MIT License 5 votes vote down vote up
@Test
void modularizeJavaCompileTask() {
    // given
    Project project = ProjectBuilder.builder().withProjectDir(new File("test-project/")).build();
    project.getPlugins().apply("java");
    JavaCompile compileJava = (JavaCompile) project.getTasks().getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME);

    FileCollection classpath = project.files("dummy dir"); // we need anything on classpath
    compileJava.setClasspath(classpath);

    CompileModuleOptions moduleOptions = compileJava.getExtensions()
            .create("moduleOptions", CompileModuleOptions.class, project);
    project.getExtensions().add("moduleName", getClass().getName());
    project.getExtensions().create("patchModules", PatchModuleExtension.class);
    project.getExtensions().create("modularity", DefaultModularityExtension.class, project);

    CompileJavaTaskMutator mutator = new CompileJavaTaskMutator(project, compileJava.getClasspath(), moduleOptions);

    // when
    mutator.modularizeJavaCompileTask(compileJava);

    // then
    List<String> twoLastArguments = twoLastCompilerArgs(compileJava);
    assertEquals(
            Arrays.asList("--module-path", classpath.getAsPath()),
            twoLastArguments,
            "Two last arguments should be setting module path to the current compileJava task classpath");
}
 
Example 3
Source File: MergeAwbAssets.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
        public void execute(@NonNull MergeAwbAssets mergeAssetsTask) {
            BaseVariantData variantData = scope.getVariantData();
            VariantConfiguration variantConfig = variantData.getVariantConfiguration();
            mergeAssetsTask.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
            mergeAssetsTask.setVariantName(variantConfig.getFullName());
            mergeAssetsTask.setIncrementalFolder(scope.getIncrementalDir(getName()));
            final Project project = scope.getGlobalScope().getProject();

            final Function<SourceProvider, Collection<File>> assetDirFunction =
                    SourceProvider::getAssetsDirectories;
//            mergeAssetsTask.assetSetSupplier =
//                    () -> variantConfig.getSourceFilesAsAssetSets(assetDirFunction);

            mergeAssetsTask.assetSetSupplier = ()-> ImmutableList.of();
            mergeAssetsTask.sourceFolderInputs = () -> ImmutableList.of();
//            mergeAssetsTask.sourceFolderInputs =
//                    TaskInputHelper.bypassFileSupplier(
//                            () -> variantConfig.getSourceFiles(assetDirFunction));

            mergeAssetsTask.shadersOutputDir = project.files(variantContext.getAwbShadersOutputDir(awbBundle));
            if (variantData.copyApkTask != null) {
                mergeAssetsTask.copyApk = project.files(variantData.copyApkTask.getDestinationDir());
            }

            AaptOptions options = scope.getGlobalScope().getExtension().getAaptOptions();
            if (options != null) {
                mergeAssetsTask.ignoreAssets = options.getIgnoreAssets();
            }

            if (!variantConfig.getType().equals(VariantType.LIBRARY)) {
                mergeAssetsTask.libraries = awbBundle.getAndroidLibraries();
            }

            mergeAssetsTask.awbBundle = awbBundle;
            mergeAssetsTask.variantContext = (AppVariantContext) this.variantContext;
            mergeAssetsTask.setOutputDir(outputDir);
        }
 
Example 4
Source File: GwtCompileTask.java    From putnami-gradle-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void configure(final Project project, final PutnamiExtension extention) {
	final CompilerOption options = extention.getCompile();
	options.init(project);
	options.setLocalWorkers(evalWorkers(options));

	final ConfigurableFileCollection sources = project.files();
	addSourceSet(sources, project, SourceSet.MAIN_SOURCE_SET_NAME);

	final Configuration compileClasspath = project.getConfigurations().getByName(
		JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
	compileClasspath.getDependencies().withType(ProjectDependency.class, new Action<ProjectDependency>() {
		@Override
		public void execute(ProjectDependency dep) {
			addSourceSet(sources, dep.getDependencyProject(), SourceSet.MAIN_SOURCE_SET_NAME);
		}
	});

	ConventionMapping mapping = ((IConventionAware) this).getConventionMapping();

	mapping.map("modules", new Callable<List<String>>() {
		@Override
		public List<String> call()  {
			return extention.getModule();
		}
	});
	mapping.map("war", new Callable<File>() {
		@Override
		public File call()  {
			return options.getWar();
		}
	});
	mapping.map("src", new Callable<FileCollection>() {
		@Override
		public FileCollection call()  {
			return sources;
		}
	});
}
 
Example 5
Source File: MergeResources.java    From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
        public void execute(MergeResources mergeResourcesTask) {
            final Project project = androidExtension.getProject();

            mergeResourcesTask.setMinSdk(Integer.parseInt(androidExtension.getMinSdkVersion()));
            mergeResourcesTask.buildToolInfo = () -> BuildToolInfo.fromStandardDirectoryLayout(
                    androidExtension.getBuildToolsRevision(), androidExtension.getBuildToolsDir());

            mergeResourcesTask.aaptGeneration = AaptGeneration.AAPT_V1;
            mergeResourcesTask.setAndroidBuilder(androidExtension.getAndroidBuilder());
            mergeResourcesTask.fileCache = androidExtension.getBuildCache();
            mergeResourcesTask.setVariantName("jfx");
            mergeResourcesTask.setIncrementalFolder(androidExtension.getIncrementalDirectory(getName()));
            // Libraries use this task twice, once for compilation (with dependencies),
            // where blame is useful, and once for packaging where it is not.
            if (includeDependencies) {
                mergeResourcesTask.setBlameLogFolder(androidExtension.getResourceBlameLogDirectory());
            }
            mergeResourcesTask.processResources = processResources;
            mergeResourcesTask.crunchPng = true;

            final boolean validateEnabled = true;

            mergeResourcesTask.setValidateEnabled(validateEnabled);

//            if (includeDependencies) {
//                mergeResourcesTask.libraries = scope.getArtifactCollection(
//                        RUNTIME_CLASSPATH, ALL, ANDROID_RES);
//            }

            mergeResourcesTask.resSetSupplier =
                    () -> {
                        ResourceSet mainResourceSet = new ResourceSet(BuilderConstants.MAIN, null, null, validateEnabled);
                        mainResourceSet.addSource(project.file(androidExtension.getResDirectory()));
                        return Collections.singletonList(mainResourceSet);
                    };
            mergeResourcesTask.sourceFolderInputs =
                    TaskInputHelper.bypassFileSupplier(
                            () -> Collections.singletonList(project.file(androidExtension.getResDirectory())));
            mergeResourcesTask.renderscriptResOutputDir = project.files(androidExtension.getRenderscriptResOutputDirectory());
            mergeResourcesTask.generatedResOutputDir = project.files(androidExtension.getGeneratedResOutputDirectory());

            mergeResourcesTask.setOutputDir(outputLocation);
            mergeResourcesTask.setGeneratedPngsOutputDir(androidExtension.getGeneratedPngsOutputDirectory());
        }
 
Example 6
Source File: CheckForbiddenApisExtension.java    From forbidden-apis with Apache License 2.0 4 votes vote down vote up
public CheckForbiddenApisExtension(Project project) {
  signaturesFiles = project.files();
}
 
Example 7
Source File: CodeServerBuilder.java    From putnami-gradle-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void configure(Project project, DevOption devOption, Collection<String> modules) {
	ConfigurationContainer configs = project.getConfigurations();
	Configuration sdmConf = configs.getByName(PwtLibPlugin.CONF_GWT_SDM);

	PutnamiExtension putnami = project.getExtensions().getByType(PutnamiExtension.class);

	SourceSet mainSourceSet = project.getConvention()
		.getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
	FileCollection sources = project.files(mainSourceSet.getAllJava().getSrcDirs());

	configureJavaArgs(devOption);

	addClassPath(mainSourceSet.getOutput().getAsPath());
	addClassPath(mainSourceSet.getAllJava().getSrcDirs());
	addClassPath(mainSourceSet.getCompileClasspath().getAsPath());
	addClassPath(sdmConf.getAsPath());

	addSrc(sources);
	addSrc(listProjectDepsSrcDirs(project));

	addArg("-bindAddress", devOption.getBindAddress());
	addArgIf(devOption.getFailOnError(), "-failOnError", "-nofailOnError");
	addArgIf(devOption.getPrecompile(), "-precompile", "-noprecompile");
	addArg("-port", devOption.getPort());
	addArgIf(devOption.getStrict(), "-strict");
	addArgIf(devOption.getEnforceStrictResources(), "-XenforceStrictResources ", "-XnoenforceStrictResources");
	addArg("-workDir", ResourceUtils.ensureDir(devOption.getWorkDir()));
	addArgIf(devOption.getIncremental(), "-incremental", "-noincremental");
	addArg("-sourceLevel", devOption.getSourceLevel());
	if (!putnami.getGwtVersion().startsWith("2.6")) {
		addArg("-logLevel", devOption.getLogLevel());
	}
	addArg("-XmethodNameDisplayMode", devOption.getMethodNameDisplayMode());
	addArg("-XjsInteropMode", devOption.getJsInteropMode());
	addArgIf(devOption.getGenerateJsInteropExports(), "-generateJsInteropExports");

	if (devOption.getExtraArgs() != null) {
		for (String arg : devOption.getExtraArgs()) {
			if (arg != null && arg.length() > 0) {
				addArg(arg);
			}
		}
	}

	for (String module : modules) {
		addArg(module);
	}
}