Search in sources :

Example 26 with TestFile

use of org.gradle.test.fixtures.file.TestFile in project gradle by gradle.

the class MSBuildVersionLocator method getMSBuildInstall.

public File getMSBuildInstall(AvailableToolChains.InstalledToolChain toolChain) {
    VersionNumber vsVersion;
    if (toolChain instanceof AvailableToolChains.InstalledVisualCpp) {
        AvailableToolChains.InstalledVisualCpp visualCpp = (AvailableToolChains.InstalledVisualCpp) toolChain;
        vsVersion = visualCpp.getVersion();
    } else {
        vsVersion = VersionNumber.version(15);
    }
    File vswhere = vswhereLocator.getVswhereInstall();
    if (vswhere == null) {
        throw new IllegalStateException("vswhere tool is required to be installed");
    }
    ExecOutput vsWhereOutput = new TestFile(vswhere).exec("-version", String.format("[%s.0,%s.0)", vsVersion.getMajor(), vsVersion.getMajor() + 1), "-products", "*", "-requires", "Microsoft.Component.MSBuild", "-property", "installationPath");
    if (!vsWhereOutput.getError().trim().isEmpty()) {
        throw new IllegalStateException(String.format("Could not determine the location of MSBuild %s: %s", vsVersion.getMajor(), vsWhereOutput.getError()));
    }
    String location = vsWhereOutput.getOut().trim();
    TestFile msbuild;
    if (!location.isEmpty()) {
        msbuild = new TestFile(location).file("MSBuild/" + vsVersion.getMajor() + ".0/Bin/MSBuild.exe");
    } else if (vsVersion.getMajor() == 11) {
        msbuild = new TestFile("C:/Windows/Microsoft.Net/Framework/v4.0.30319/MSBuild.exe");
    } else {
        msbuild = new TestFile("C:/program files (x86)/MSBuild/" + vsVersion.getMajor() + ".0/Bin/MSBuild.exe");
    }
    if (!msbuild.exists()) {
        throw new IllegalStateException(String.format("This test requires MSBuild %s to be installed. Expected it to be installed at %s.", vsVersion.getMajor(), msbuild));
    }
    return msbuild;
}
Also used : AvailableToolChains(org.gradle.nativeplatform.fixtures.AvailableToolChains) ExecOutput(org.gradle.test.fixtures.file.ExecOutput) TestFile(org.gradle.test.fixtures.file.TestFile) TestFile(org.gradle.test.fixtures.file.TestFile) File(java.io.File) VersionNumber(org.gradle.util.VersionNumber)

Example 27 with TestFile

use of org.gradle.test.fixtures.file.TestFile in project gradle by gradle.

the class XcodebuildExecutor method findXcodeBuild.

private TestFile findXcodeBuild() {
    TestFile xcodebuild = new TestFile("/usr/bin/xcodebuild");
    assertTrue("This test requires xcode to be installed in " + xcodebuild.getAbsolutePath(), xcodebuild.exists());
    return xcodebuild;
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile)

Example 28 with TestFile

use of org.gradle.test.fixtures.file.TestFile 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 29 with TestFile

use of org.gradle.test.fixtures.file.TestFile 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 30 with TestFile

use of org.gradle.test.fixtures.file.TestFile in project gradle by gradle.

the class UriScriptSourceTest method createJar.

private URI createJar() throws URISyntaxException {
    TestFile jarFile = tmpDir.getTestDirectory().file("test.jar");
    testDir.file("ignoreme").write("content");
    testDir.zipTo(jarFile);
    return new URI(String.format("jar:%s!/build.script", jarFile.toURI()));
}
Also used : TestFile(org.gradle.test.fixtures.file.TestFile) URI(java.net.URI)

Aggregations

TestFile (org.gradle.test.fixtures.file.TestFile)53 Test (org.junit.Test)33 AbstractIntegrationTest (org.gradle.integtests.fixtures.AbstractIntegrationTest)25 File (java.io.File)5 ExecutionFailure (org.gradle.integtests.fixtures.executer.ExecutionFailure)4 OutputStream (java.io.OutputStream)2 URI (java.net.URI)2 MaybeCompressedFileResource (org.gradle.api.internal.file.MaybeCompressedFileResource)2 LocalResourceAdapter (org.gradle.api.resources.internal.LocalResourceAdapter)2 SourceFile (org.gradle.integtests.fixtures.SourceFile)2 DefaultExecHandleBuilder (org.gradle.process.internal.DefaultExecHandleBuilder)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ExecutionResult (org.gradle.integtests.fixtures.executer.ExecutionResult)1 IntegrationTestBuildContext (org.gradle.integtests.fixtures.executer.IntegrationTestBuildContext)1 AvailableToolChains (org.gradle.nativeplatform.fixtures.AvailableToolChains)1 ExecOutput (org.gradle.test.fixtures.file.ExecOutput)1