org.gradle.api.file.Directory Java Examples

The following examples show how to use org.gradle.api.file.Directory. 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: HybrisPlatform.java    From commerce-gradle-plugin with Apache License 2.0 6 votes vote down vote up
private String readVersion() {
        Directory orNull = platformDir.getOrNull();

        if (orNull == null) {
            return "NONE";
        }
        Path buildFile = orNull.file("build.number").getAsFile().toPath();
        Properties properties = new Properties();

        try (BufferedReader br = new BufferedReader(new FileReader(buildFile.toFile()))) {
            properties.load(br);
        } catch (IOException e) {
            LOG.debug("could not open build.number", e);
        }
        String bootstrappedVersion = properties.getProperty("version", "NONE");
//        LOG.lifecycle("found hybris platform version: {}", bootstrappedVersion);
        return bootstrappedVersion;
    }
 
Example #2
Source File: AvroPlugin.java    From gradle-avro-plugin with Apache License 2.0 5 votes vote down vote up
private static void configureIntelliJ(final Project project) {
    project.getPlugins().withType(IdeaPlugin.class).configureEach(ideaPlugin -> {
        SourceSet mainSourceSet = getMainSourceSet(project);
        SourceSet testSourceSet = getTestSourceSet(project);
        IdeaModule module = ideaPlugin.getModel().getModule();
        module.setSourceDirs(new SetBuilder<File>()
            .addAll(module.getSourceDirs())
            .add(getAvroSourceDir(project, mainSourceSet))
            .add(getGeneratedOutputDir(project, mainSourceSet, JAVA_EXTENSION).map(Directory::getAsFile).get())
            .build());
        module.setTestSourceDirs(new SetBuilder<File>()
            .addAll(module.getTestSourceDirs())
            .add(getAvroSourceDir(project, testSourceSet))
            .add(getGeneratedOutputDir(project, testSourceSet, JAVA_EXTENSION).map(Directory::getAsFile).get())
            .build());
        // IntelliJ doesn't allow source directories beneath an excluded directory.
        // Thus, we remove the build directory exclude and add all non-generated sub-directories as excludes.
        SetBuilder<File> excludeDirs = new SetBuilder<>();
        excludeDirs.addAll(module.getExcludeDirs()).remove(project.getBuildDir());
        File buildDir = project.getBuildDir();
        if (buildDir.isDirectory()) {
            excludeDirs.addAll(project.getBuildDir().listFiles(new NonGeneratedDirectoryFileFilter()));
        }
        module.setExcludeDirs(excludeDirs.build());
    });
    project.getTasks().withType(GenerateIdeaModule.class).configureEach(generateIdeaModule ->
        generateIdeaModule.doFirst(task ->
            project.getTasks().withType(GenerateAvroJavaTask.class, generateAvroJavaTask ->
                project.mkdir(generateAvroJavaTask.getOutputDir().get()))));
}
 
Example #3
Source File: JdkDownloadPlugin.java    From crate with Apache License 2.0 5 votes vote down vote up
private static TaskProvider<?> createExtractTask(
    String taskName,
    Project rootProject,
    boolean isWindows,
    Provider<Directory> extractPath,
    Supplier<File> jdkBundle) {
    if (isWindows) {
        Action<CopySpec> removeRootDir = copy -> {
            // remove extra unnecessary directory levels
            copy.eachFile(details -> {
                Path newPathSegments = trimArchiveExtractPath(details.getRelativePath().getPathString());
                String[] segments = StreamSupport.stream(newPathSegments.spliterator(), false)
                    .map(Path::toString)
                    .toArray(String[]::new);
                details.setRelativePath(new RelativePath(true, segments));
            });
            copy.setIncludeEmptyDirs(false);
        };

        return rootProject.getTasks().register(taskName, Copy.class, copyTask -> {
            copyTask.doFirst(t -> rootProject.delete(extractPath));
            copyTask.into(extractPath);
            Callable<FileTree> fileGetter = () -> rootProject.zipTree(jdkBundle.get());
            copyTask.from(fileGetter, removeRootDir);
        });
    } else {
        /*
         * Gradle TarFileTree does not resolve symlinks, so we have to manually
         * extract and preserve the symlinks. cf. https://github.com/gradle/gradle/issues/3982
         * and https://discuss.gradle.org/t/tar-and-untar-losing-symbolic-links/2039
         */
        return rootProject.getTasks().register(taskName, SymbolicLinkPreservingUntarTask.class, task -> {
            task.getTarFile().fileProvider(rootProject.provider(jdkBundle::get));
            task.getExtractPath().set(extractPath);
            task.setTransform(JdkDownloadPlugin::trimArchiveExtractPath);
        });
    }
}
 
Example #4
Source File: HybrisPlatform.java    From commerce-gradle-plugin with Apache License 2.0 4 votes vote down vote up
public Provider<Directory> getPlatformHome() {
    return platformDir;
}
 
Example #5
Source File: HybrisPlatform.java    From commerce-gradle-plugin with Apache License 2.0 4 votes vote down vote up
public Provider<Directory> getAntHome() {
    return antHome;
}
 
Example #6
Source File: PlayGeneratedSourcePlugin.java    From playframework with Apache License 2.0 4 votes vote down vote up
default Provider<Directory> getOutputDir(Project project, SourceDirectorySet sourceDirectorySet) {
    DirectoryProperty buildDir = project.getLayout().getBuildDirectory();
    return buildDir.dir(GENERATED_SOURCE_ROOT_DIR_PATH + "/" + sourceDirectorySet.getName());
}
 
Example #7
Source File: AvroPlugin.java    From gradle-avro-plugin with Apache License 2.0 4 votes vote down vote up
private static Provider<Directory> getGeneratedOutputDir(Project project, SourceSet sourceSet, String extension) {
    String generatedOutputDirName = String.format("generated-%s-avro-%s", sourceSet.getName(), extension);
    return project.getLayout().getBuildDirectory().dir(generatedOutputDirName);
}
 
Example #8
Source File: TwirlCompile.java    From playframework with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the directory to generate the parser source files into.
 *
 * @return The output directory.
 */
@OutputDirectory
public Property<Directory> getOutputDirectory() {
    return outputDirectory;
}
 
Example #9
Source File: JavaScriptMinify.java    From playframework with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the output directory that processed JavaScript is written to.
 *
 * @return The output directory.
 */
@OutputDirectory
public Property<Directory> getDestinationDir() {
    return destinationDir;
}
 
Example #10
Source File: RoutesCompile.java    From playframework with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the directory to generate the parser source files into.
 *
 * @return The output directory.
 */
@OutputDirectory
public Property<Directory> getOutputDirectory() {
    return outputDirectory;
}