Search in sources :

Example 1 with SourceFile

use of org.gradle.integtests.fixtures.SourceFile in project gradle by gradle.

the class IncrementalCppElement method rename.

protected static Transform rename(final CppSourceFileElement beforeElement, String renamePrefix) {
    SourceFile beforeFile = beforeElement.getSource().getSourceFile();
    final SourceFile afterFile = new SourceFile(beforeFile.getPath(), renamePrefix + beforeFile.getName(), beforeFile.getContent());
    return new AbstractRenameTransform(beforeFile, afterFile, beforeElement) {

        @Override
        public List<SourceFile> getAfterFiles() {
            List<SourceFile> result = new ArrayList<SourceFile>();
            result.addAll(beforeElement.getHeaders().getFiles());
            result.add(afterFile);
            return result;
        }
    };
}
Also used : ArrayList(java.util.ArrayList) SourceFile(org.gradle.integtests.fixtures.SourceFile)

Example 2 with SourceFile

use of org.gradle.integtests.fixtures.SourceFile in project gradle by gradle.

the class IncrementalElement method delete.

/**
 * Returns a transform that delete the before element.
 */
protected static Transform delete(final SourceElement beforeElement) {
    final String sourceSetName = beforeElement.getSourceSetName();
    final List<SourceFile> beforeFiles = beforeElement.getFiles();
    return new Transform() {

        @Override
        public void applyChangesToProject(TestFile projectDir) {
            for (SourceFile beforeFile : beforeFiles) {
                TestFile file = projectDir.file(beforeFile.withPath("src/" + sourceSetName));
                file.assertExists();
                file.delete();
            }
        }

        @Override
        public List<SourceFile> getBeforeFiles() {
            return beforeElement.getFiles();
        }

        @Override
        public List<SourceFile> getAfterFiles() {
            return Collections.emptyList();
        }
    };
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) SourceFile(org.gradle.integtests.fixtures.SourceFile)

Example 3 with SourceFile

use of org.gradle.integtests.fixtures.SourceFile in project gradle by gradle.

the class IncrementalSwiftElement method modify.

/**
 * Returns a transform that replace the content of the before element with the content of the after element.
 * Both elements must have the same location.
 */
protected static Transform modify(final SourceFileElement beforeElement, SourceFileElement afterElement) {
    assert beforeElement.getFiles().size() == 1;
    assert afterElement.getFiles().size() == 1;
    assert beforeElement.getSourceSetName().equals(afterElement.getSourceSetName());
    final String sourceSetName = beforeElement.getSourceSetName();
    final SourceFile beforeFile = beforeElement.getSourceFile();
    final SourceFile afterFile = afterElement.getSourceFile();
    assert beforeFile.getPath().equals(afterFile.getPath());
    assert beforeFile.getName().equals(afterFile.getName());
    assert !beforeFile.getContent().equals(afterFile.getContent());
    return new Transform() {

        @Override
        public void applyChangesToProject(TestFile projectDir) {
            TestFile file = projectDir.file(beforeFile.withPath("src/" + sourceSetName));
            file.assertExists();
            file.write(afterFile.getContent());
        }

        @Override
        public List<SourceFile> getBeforeFiles() {
            return Arrays.asList(beforeFile);
        }

        @Override
        public List<SourceFile> getAfterFiles() {
            return Arrays.asList(afterFile);
        }
    };
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) SourceFile(org.gradle.integtests.fixtures.SourceFile)

Example 4 with SourceFile

use of org.gradle.integtests.fixtures.SourceFile in project gradle by gradle.

the class IncrementalSwiftElement method rename.

protected static Transform rename(SourceFileElement beforeElement, String renamePrefix) {
    assert beforeElement.getFiles().size() == 1;
    SourceFile beforeFile = beforeElement.getSourceFile();
    final SourceFile afterFile = new SourceFile(beforeFile.getPath(), renamePrefix + beforeFile.getName(), beforeFile.getContent());
    return new AbstractRenameTransform(beforeFile, afterFile, beforeElement) {

        @Override
        public List<SourceFile> getAfterFiles() {
            return Arrays.asList(afterFile);
        }
    };
}
Also used : SourceFile(org.gradle.integtests.fixtures.SourceFile)

Aggregations

SourceFile (org.gradle.integtests.fixtures.SourceFile)4 TestFile (org.gradle.test.fixtures.file.TestFile)2 ArrayList (java.util.ArrayList)1