Esempio n. 1
0
 private void checkExecute() throws IOException {
   context.checking(
       new Expectations() {
         {
           one(wrapperScriptGeneratorMock)
               .generate(
                   targetWrapperJarPath + "/" + Wrapper.WRAPPER_JAR,
                   targetWrapperJarPath + "/" + Wrapper.WRAPPER_PROPERTIES,
                   new File(getProject().getProjectDir(), wrapper.getScriptDestinationPath()));
         }
       });
   wrapper.execute();
   TestFile unjarDir = tmpDir.createDir("unjar");
   expectedTargetWrapperJar.unzipTo(unjarDir);
   unjarDir.file(GradleWrapperMain.class.getName().replace(".", "/") + ".class").assertIsFile();
   Properties properties = GUtil.loadProperties(expectedTargetWrapperProperties);
   assertEquals(properties.getProperty(Wrapper.URL_ROOT_PROPERTY), wrapper.getUrlRoot());
   assertEquals(
       properties.getProperty(Wrapper.DISTRIBUTION_BASE_PROPERTY),
       wrapper.getDistributionBase().toString());
   assertEquals(
       properties.getProperty(Wrapper.DISTRIBUTION_PATH_PROPERTY), wrapper.getDistributionPath());
   assertEquals(
       properties.getProperty(Wrapper.DISTRIBUTION_NAME_PROPERTY), wrapper.getArchiveName());
   assertEquals(
       properties.getProperty(Wrapper.DISTRIBUTION_CLASSIFIER_PROPERTY),
       wrapper.getArchiveClassifier());
   assertEquals(
       properties.getProperty(Wrapper.DISTRIBUTION_VERSION_PROPERTY), wrapper.getGradleVersion());
   assertEquals(
       properties.getProperty(Wrapper.ZIP_STORE_BASE_PROPERTY),
       wrapper.getArchiveBase().toString());
   assertEquals(properties.getProperty(Wrapper.ZIP_STORE_PATH_PROPERTY), wrapper.getArchivePath());
 }
  @Test
  public void handlesResourceOnlyProject() throws IOException {
    TestFile buildFile = testFile("resources.gradle");
    buildFile.write("apply plugin: 'java'");
    testFile("src/main/resources/org/gradle/resource.file").write("test resource");

    usingBuildFile(buildFile).withTasks("build").run();
    testFile("build/classes/main/org/gradle/resource.file").assertExists();
  }
  @Test
  public void handlesTestSrcWhichDoesNotContainAnyTestCases() {
    TestFile buildFile = testFile("build.gradle");
    buildFile.writelns("apply plugin: 'java'");
    testFile("src/test/java/org/gradle/NotATest.java")
        .writelns("package org.gradle;", "public class NotATest {}");

    usingBuildFile(buildFile).withTasks("build").run();
  }
  @Test
  public void generatesArtifactsWhenVersionIsEmpty() {
    testFile("settings.gradle").write("rootProject.name = 'empty'");
    TestFile buildFile = testFile("build.gradle");
    buildFile.writelns("apply plugin: 'java'", "version = ''");
    testFile("src/main/resources/org/gradle/resource.file").write("some resource");

    usingBuildFile(buildFile).withTasks("jar").run();
    testFile("build/libs/empty.jar").assertIsFile();
  }
  @Test
  public void javadocGenerationFailureBreaksBuild() throws IOException {
    TestFile buildFile = testFile("javadocs.gradle");
    buildFile.write("apply plugin: 'java'");
    testFile("src/main/java/org/gradle/broken.java").write("class Broken { }");

    ExecutionFailure failure = usingBuildFile(buildFile).withTasks("javadoc").runWithFailure();

    failure.assertHasFileName(String.format("Build file '%s'", buildFile));
    failure.assertHasDescription("Execution failed for task ':javadoc'");
    failure.assertHasCause("Javadoc generation failed.");
  }
  @Test
  public void compilationFailureBreaksBuild() {
    TestFile buildFile = testFile("build.gradle");
    buildFile.writelns("apply plugin: 'java'");
    testFile("src/main/java/org/gradle/broken.java").write("broken");

    ExecutionFailure failure = usingBuildFile(buildFile).withTasks("build").runWithFailure();

    failure.assertHasFileName(String.format("Build file '%s'", buildFile));
    failure.assertHasDescription("Execution failed for task ':compileJava'");
    failure.assertHasCause("Compile failed; see the compiler error output for details.");
  }
  static {
    userHomeDir = file("integTest.gradleUserHomeDir", "intTestHomeDir");

    TestFile workerJar = userHomeDir.file("worker-main-jar-exploded");
    for (Class<?> aClass :
        Arrays.asList(GradleWorkerMain.class, BootstrapClassLoaderWorker.class)) {
      String fileName = aClass.getName().replace('.', '/') + ".class";
      workerJar
          .file(fileName)
          .copyFrom(DistributionIntegrationTestRunner.class.getClassLoader().getResource(fileName));
    }

    System.setProperty("gradle.core.worker.jar", workerJar.getAbsolutePath());
  }
Esempio n. 8
0
 @Test
 public void testExecuteWithExistingWrapperJarParentDirAndExistingWrapperJar() throws IOException {
   File jarDir = new File(getProject().getProjectDir(), "lib");
   jarDir.mkdirs();
   File wrapperJar = new File(getProject().getProjectDir(), targetWrapperJarPath);
   File parentFile = expectedTargetWrapperJar.getParentFile();
   assertTrue(parentFile.isDirectory() || parentFile.mkdirs());
   try {
     assertTrue(expectedTargetWrapperJar.createNewFile());
   } catch (IOException e) {
     throw new RuntimeException(String.format("Could not create %s.", wrapperJar), e);
   }
   checkExecute();
 }
  @Test
  public void copyActionCanFilterContentWhenFileIsCopiedToFile() {
    final FileCopyDetails mappedDetails = expectActionExecutedWhenFileVisited();

    context.checking(
        new Expectations() {
          {
            one(details).open();
            will(returnValue(new ByteArrayInputStream("content".getBytes())));
            one(details).isDirectory();
            will(returnValue(false));
            one(details).getLastModified();
            will(returnValue(90L));
          }
        });

    mappedDetails.filter(HelperUtil.toClosure("{ 'PREFIX: ' + it } "));

    TestFile destDir = tmpDir.getDir().file("test.txt");
    mappedDetails.copyTo(destDir);
    destDir.assertContents(equalTo("PREFIX: content"));
  }