Java Code Examples for org.gradle.testfixtures.ProjectBuilder

The following examples show how to use org.gradle.testfixtures.ProjectBuilder. These examples are extracted from open source projects. 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 Project: scaffold-clean-architecture   Author: bancolombia   File: ModuleBuilderTest.java    License: MIT License 6 votes vote down vote up
@Before
public void init() throws IOException, CleanException {
    File projectDir = new File("build/unitTest");
    Files.createDirectories(projectDir.toPath());
    writeString(new File(projectDir, "build.gradle"),
            "plugins {" +
                    "  id('co.com.bancolombia.cleanArchitecture')" +
                    "}");

    Project project = ProjectBuilder.builder().withName("cleanArchitecture")
            .withProjectDir(new File("build/unitTest")).build();

    project.getTasks().create("testStructure", GenerateStructureTask.class);
    GenerateStructureTask taskStructure = (GenerateStructureTask) project.getTasks().getByName("testStructure");
    taskStructure.generateStructureTask();

    builder = new ModuleBuilder(project);
}
 
Example #2
Source Project: scaffold-clean-architecture   Author: bancolombia   File: GenerateEntryPointTaskTest.java    License: MIT License 6 votes vote down vote up
@Before
public void setup() throws IOException, CleanException {
    Project project = ProjectBuilder.builder().withProjectDir(new File("build/unitTest")).build();
    project.getTasks().create("ca", GenerateStructureTask.class);
    GenerateStructureTask caTask = (GenerateStructureTask) project.getTasks().getByName("ca");
    caTask.generateStructureTask();

    ProjectBuilder.builder()
            .withProjectDir(new File("build/unitTest/applications/app-service"))
            .withName("app-service")
            .withParent(project)
            .build();

    project.getTasks().create("test", GenerateEntryPointTask.class);
    task = (GenerateEntryPointTask) project.getTasks().getByName("test");
}
 
Example #3
Source Project: scaffold-clean-architecture   Author: bancolombia   File: GeneratePipelineTaskTest.java    License: MIT License 6 votes vote down vote up
@Before
public void init() throws IOException, CleanException {
    File projectDir = new File("build/unitTest");
    Files.createDirectories(projectDir.toPath());
    writeString(new File(projectDir, "build.gradle"),
            "plugins {" +
                    "  id('co.com.bancolombia.cleanArchitecture')" +
                    "}");

    Project project = ProjectBuilder.builder().withName("cleanArchitecture")
            .withProjectDir(new File("build/unitTest")).build();

    project.getTasks().create("testStructure", GenerateStructureTask.class);
    GenerateStructureTask taskStructure = (GenerateStructureTask) project.getTasks().getByName("testStructure");
    taskStructure.generateStructureTask();

    project.getTasks().create("test", GeneratePipelineTask.class);
    task = (GeneratePipelineTask) project.getTasks().getByName("test");
}
 
Example #4
Source Project: scaffold-clean-architecture   Author: bancolombia   File: ValidateStructureTaskTest.java    License: MIT License 6 votes vote down vote up
@Before
public void init() throws IOException, CleanException {
    File projectDir = new File("build/unitTest");
    Files.createDirectories(projectDir.toPath());
    writeString(new File(projectDir, "settings.gradle"), "");
    writeString(new File(projectDir, "build.gradle"),
            "plugins {" +
                    "  id('co.com.bancolombia.cleanArchitecture')" +
                    "}");

    Project project = ProjectBuilder.builder().withProjectDir(new File("build/unitTest")).build();
    project.getTasks().create("testStructure", GenerateStructureTask.class);

    GenerateStructureTask taskStructure = (GenerateStructureTask) project.getTasks().getByName("testStructure");
    taskStructure.generateStructureTask();

    project.getTasks().create("test", ValidateStructureTask.class);
    task = (ValidateStructureTask) project.getTasks().getByName("test");
}
 
Example #5
Source Project: scaffold-clean-architecture   Author: bancolombia   File: GenerateDrivenAdapterTaskTest.java    License: MIT License 6 votes vote down vote up
private void setup(GenerateStructureTask.ProjectType type) throws IOException, CleanException {
    Project project = ProjectBuilder.builder().withProjectDir(new File("build/unitTest")).build();

    ProjectBuilder.builder()
            .withName("app-service")
            .withProjectDir(new File("build/unitTest/applications/app-service"))
            .withParent(project)
            .build();

    project.getTasks().create("ca", GenerateStructureTask.class);
    GenerateStructureTask taskStructure = (GenerateStructureTask) project.getTasks().getByName("ca");
    taskStructure.setType(type);
    taskStructure.generateStructureTask();

    project.getTasks().create("test", GenerateDrivenAdapterTask.class);
    task = (GenerateDrivenAdapterTask) project.getTasks().getByName("test");
}
 
Example #6
Source Project: crnk-framework   Author: crnk-project   File: RuntimeClassoaderFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
	// TODO address dependency resolution issues
	GeneratorPlugin.APPLY_DOCLET_BY_DEFAULT = false;

	testProjectDir.newFolder("src", "main", "java");

	File outputDir = testProjectDir.getRoot();

	Project project = ProjectBuilder.builder().withName("crnk-gen-typescript-test").withProjectDir(outputDir).build();
	project.setVersion("0.0.1");

	project.getPluginManager().apply(JavaPlugin.class);
	project.getPluginManager().apply(GeneratorPlugin.class);

	GeneratorExtension config = project.getExtensions().getByType(GeneratorExtension.class);
	config.getRuntime().setConfiguration("test");

	TSGeneratorModule module = new TSGeneratorModule();

	factory = new RuntimeClassLoaderFactory(project, module);
	ClassLoader parentClassLoader = getClass().getClassLoader();
	classLoader = factory.createClassLoader(parentClassLoader, true);
	sharedClassLoader = (RuntimeClassLoaderFactory.SharedClassLoader) classLoader.getParent();

}
 
Example #7
Source Project: curiostack   Author: curioswitch   File: UpdateIntelliJSdksTaskTest.java    License: MIT License 6 votes vote down vote up
@BeforeEach
void setUserHome() throws Exception {
  oldUserHome = System.getProperty("user.home");
  testUserHome = GradleTempDirectories.create("home");
  testGradleHome = GradleTempDirectories.create("gradlehome");
  System.setProperty("user.home", testUserHome.toAbsolutePath().toString());

  // Add an unrelated folder to make it look just a little more like a user home.
  Files.writeString(
      Files.createDirectories(testUserHome.resolve("curiotest")).resolve("foo.txt"), "bar");

  var project = ProjectBuilder.builder().withGradleUserHomeDir(testGradleHome.toFile()).build();
  var properties = project.getExtensions().getByType(ExtraPropertiesExtension.class);
  properties.set("org.curioswitch.curiostack.tools.openjdk", "zulu13.28.11-ca-jdk13.0.1");
  properties.set("org.curioswitch.curiostack.tools.openjdk8", "zulu8.42.0.21-ca-jdk8.0.232");

  project.getPlugins().apply(CuriostackRootPlugin.class);
  project.getPlugins().apply(GolangSetupPlugin.class);

  task =
      project
          .getTasks()
          .withType(UpdateIntelliJSdksTask.class)
          .getByName(UpdateIntelliJSdksTask.NAME);
}
 
Example #8
Source Project: minikube-build-tools-for-java   Author: GoogleContainerTools   File: MinikubeTaskTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildCommand() {
  Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build();
  MinikubeTask testTask =
      project
          .getTasks()
          .create(
              "minikubeTestTask",
              MinikubeTask.class,
              minikubeTask -> {
                minikubeTask.setMinikube("/test/path/to/minikube");
                minikubeTask.setCommand("testCommand");
                minikubeTask.setFlags(new String[] {"testFlag1", "testFlag2"});
              });

  Assert.assertEquals(
      Arrays.asList("/test/path/to/minikube", "testCommand", "testFlag1", "testFlag2"),
      testTask.buildMinikubeCommand());
}
 
Example #9
Source Project: minikube-build-tools-for-java   Author: GoogleContainerTools   File: MinikubePluginTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMinikubeExtensionSetProperties() {
  Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build();
  project.getPluginManager().apply(MinikubePlugin.class);
  MinikubeExtension ex = (MinikubeExtension) project.getExtensions().getByName("minikube");
  ex.setMinikube("/custom/minikube/path");

  TaskContainer t = project.getTasks();
  TaskCollection<MinikubeTask> tc = t.withType(MinikubeTask.class);

  Assert.assertEquals(3, tc.size());

  tc.forEach(
      minikubeTask -> {
        Assert.assertEquals(minikubeTask.getMinikube(), "/custom/minikube/path");
      });
}
 
Example #10
Source Project: minikube-build-tools-for-java   Author: GoogleContainerTools   File: MinikubeExtensionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  Project project = ProjectBuilder.builder().build();

  // Mocks the CommandExecutor.
  commandExecutorMock = mock(CommandExecutor.class);
  commandExecutorFactoryMock = mock(CommandExecutorFactory.class);
  when(commandExecutorFactoryMock.newCommandExecutor()).thenReturn(commandExecutorMock);

  // Creates an extension to test on.
  minikube = new MinikubeExtension(project, commandExecutorFactoryMock);
  minikube.setMinikube("/test/path/to/minikube");

  expectedCommand =
      new ArrayList<>(Arrays.asList("/test/path/to/minikube", "docker-env", "--shell=none"));
}
 
Example #11
Source Project: app-gradle-plugin   Author: GoogleCloudPlatform   File: AppEngineStandardExtensionTest.java    License: Apache License 2.0 6 votes vote down vote up
private Project setUpTestProject(String buildFileName) throws IOException {
  Path buildFile = testProjectDir.getRoot().toPath().resolve("build.gradle");
  InputStream buildFileContent =
      getClass()
          .getClassLoader()
          .getResourceAsStream(
              "projects/AppEnginePluginTest/Extension/" + buildFileName + ".gradle");
  Files.copy(buildFileContent, buildFile);

  Path webInf = testProjectDir.getRoot().toPath().resolve("src/main/webapp/WEB-INF");
  Files.createDirectories(webInf);
  File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile();
  Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8));

  Project p = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build();
  p.getPluginManager().apply(JavaPlugin.class);
  p.getPluginManager().apply(WarPlugin.class);
  p.getPluginManager().apply(AppEngineStandardPlugin.class);
  ((ProjectInternal) p).evaluate();

  return p;
}
 
Example #12
Source Project: app-gradle-plugin   Author: GoogleCloudPlatform   File: TestProject.java    License: Apache License 2.0 6 votes vote down vote up
private Project applyProjectBuilder(Class<?>... plugins) {
  Project p = ProjectBuilder.builder().withProjectDir(projectRoot).build();
  for (Class<?> clazz : plugins) {
    p.getPluginManager().apply(clazz);
  }

  Object appengineExt = p.getExtensions().getByName(APPENGINE_EXTENSION);
  DeployExtension deploy =
      ((ExtensionAware) appengineExt).getExtensions().getByType(DeployExtension.class);
  deploy.setProjectId("test-project");
  deploy.setVersion("test-version");

  ((ProjectInternal) p).evaluate();

  return p;
}
 
Example #13
Source Project: app-gradle-plugin   Author: GoogleCloudPlatform   File: MultiModuleTestProject.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Build and evaluate multi-module project.
 *
 * @return root project
 */
public Project build() throws IOException {
  Project rootProject = ProjectBuilder.builder().withProjectDir(projectRoot).build();
  for (String module : modules) {
    Project p = ProjectBuilder.builder().withName(module).withParent(rootProject).build();

    // Create an appengine-web.xml for each module
    Path webInf = p.getProjectDir().toPath().resolve("src/main/webapp/WEB-INF");
    Files.createDirectories(webInf);
    File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile();
    Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8));

    p.getPluginManager().apply(JavaPlugin.class);
    p.getPluginManager().apply(WarPlugin.class);
    p.getPluginManager().apply(AppEngineStandardPlugin.class);

    DeployExtension deploy =
        p.getExtensions().getByType(AppEngineStandardExtension.class).getDeploy();
    deploy.setProjectId("project");
    deploy.setVersion("version");
  }
  ((ProjectInternal) rootProject).evaluate();
  return rootProject;
}
 
Example #14
Source Project: app-gradle-plugin   Author: GoogleCloudPlatform   File: DeployAllTaskTest.java    License: Apache License 2.0 6 votes vote down vote up
/** Setup DeployAllTaskTest. */
@Before
public void setup() throws IOException {
  Project tempProject = ProjectBuilder.builder().build();
  deployExtension = new DeployExtension(tempProject);
  deployExtension.setDeployTargetResolver(deployTargetResolver);
  deployCapture = ArgumentCaptor.forClass(DeployConfiguration.class);
  stageDir = tempFolder.newFolder("staging");

  deployAllTask = tempProject.getTasks().create("tempDeployAllTask", DeployAllTask.class);
  deployAllTask.setDeployExtension(deployExtension);
  deployAllTask.setGcloud(gcloud);
  deployAllTask.setStageDirectory(stageDir);

  when(gcloud.newDeployment(Mockito.any(ProcessHandler.class))).thenReturn(deploy);
}
 
Example #15
Source Project: app-gradle-plugin   Author: GoogleCloudPlatform   File: ShowConfigurationTaskTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAllFields_NestedExtensions() throws IllegalAccessException {
  String expected =
      ""
          + "root {\n"
          + "  x {\n"
          + "    y {\n"
          + "      (int) yy = 0\n"
          + "      z {\n"
          + "        (String) zz = hello\n"
          + "        (Map<String, List<String>>) zzNested = {a=[a1, a2], b=[b1, b2]}\n"
          + "      }\n"
          + "    }\n"
          + "  }\n"
          + "}\n";
  Project p = ProjectBuilder.builder().build();
  ExtensionAware root = (ExtensionAware) p.getExtensions().create("root", ExtX.class);
  ExtensionAware x = (ExtensionAware) root.getExtensions().create("x", ExtX.class);
  ExtensionAware y = (ExtensionAware) x.getExtensions().create("y", ExtY.class);
  y.getExtensions().create("z", ExtZ.class);

  String result = ShowConfigurationTask.getExtensionData("root", root, 0);
  Assert.assertEquals(expected, result);
}
 
Example #16
Source Project: ya-cf-app-gradle-plugin   Author: vmwarepivotallabs   File: PropertyEnvironmentOverridesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPropertyOverridesForAppName() {
    Project project = ProjectBuilder.builder().build();
    project.getPluginManager().apply("cf-app");
    setPropsInExtension((CfPluginExtension) project.getExtensions().getByName("cfConfig"));
    overrideProjectProperties(project);

    CfPushTask cfPushTask = (CfPushTask) project.getTasks().getAt("cf-push");
    CfProperties props = cfPushTask.getCfProperties();
    assertThat(props.name()).isEqualTo("appName-new");
    assertThat(props.ccHost()).isEqualTo("cchost-new");
    assertThat(props.ccPassword()).isEqualTo("ccpassword-new");
    assertThat(props.org()).isEqualTo("org-new");
    assertThat(props.space()).isEqualTo("space-new");
    assertThat(props.domain()).isEqualTo("domain-new");
    assertThat(props.services()).containsExactlyInAnyOrder("mysql-new", "redis-new");
}
 
Example #17
Source Project: ya-cf-app-gradle-plugin   Author: vmwarepivotallabs   File: PropertyOverridesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPropertyOverridesForAppName() {
    Project project = ProjectBuilder.builder().build();
    project.getPluginManager().apply("cf-app");
    setPropsInExtension((CfPluginExtension) project.getExtensions().getByName("cfConfig"));

    CfPushTask cfPushTask = (CfPushTask) project.getTasks().getAt("cf-push");
    CfProperties props = cfPushTask.getCfProperties();
    assertThat(props.name()).isEqualTo("name-fromplugin");
    assertThat(props.ccHost()).isEqualTo("cchost-fromplugin");
    assertThat(props.ccPassword()).isEqualTo("ccpassword-fromplugin");
    assertThat(props.buildpack()).isEqualTo("buildpack-fromplugin");
    assertThat(props.org()).isEqualTo("org-fromplugin");
    assertThat(props.space()).isEqualTo("space-fromplugin");
    assertThat(props.instances()).isEqualTo(3);
    assertThat(props.memory()).isEqualTo(12);
    assertThat(props.stagingTimeout()).isEqualTo(15);
    assertThat(props.startupTimeout()).isEqualTo(5);
}
 
Example #18
Source Project: scaffold-clean-architecture   Author: bancolombia   File: PluginCleanTest.java    License: MIT License 5 votes vote down vote up
@Test
public void pluginRegistersATask() {
    // Arrange
    String taskGroup = "Clean Architecture";
    String descriptionTask1 = "Scaffolding clean architecture project";
    String descriptionTask2 = "Generate model in domain layer";
    String descriptionTask3 = "Generate use case in domain layer";
    String descriptionTask4 = "Generate entry point in infrastructure layer";
    String descriptionTask5 = "Generate driven adapter in infrastructure layer";
    String descriptionTask6 = "Validate that project references are not violated";
    Project project = ProjectBuilder.builder().build();
    project.getPlugins().apply("co.com.bancolombia.cleanArchitecture");

    // Act
    Task task = project.getTasks().findByName("cleanArchitecture");
    Task task2 = project.getTasks().findByName("generateModel");
    Task task3 = project.getTasks().findByName("generateUseCase");
    Task task4 = project.getTasks().findByName("generateEntryPoint");
    Task task5 = project.getTasks().findByName("generateDrivenAdapter");
    Task task6 = project.getTasks().findByName("validateStructure");

    //Assert
    assertEquals(taskGroup, task.getGroup());
    assertEquals(descriptionTask1, task.getDescription());

    assertEquals(taskGroup, task2.getGroup());
    assertEquals(descriptionTask2, task2.getDescription());

    assertEquals(taskGroup, task3.getGroup());
    assertEquals(descriptionTask3, task3.getDescription());

    assertEquals(taskGroup, task4.getGroup());
    assertEquals(descriptionTask4, task4.getDescription());

    assertEquals(taskGroup, task5.getGroup());
    assertEquals(descriptionTask5, task5.getDescription());

    assertEquals(taskGroup, task6.getGroup());
    assertEquals(descriptionTask6, task6.getDescription());
}
 
Example #19
Source Project: scaffold-clean-architecture   Author: bancolombia   File: FileUtilsTest.java    License: MIT License 5 votes vote down vote up
@Test
public void readFile() throws IOException {
    Project project = ProjectBuilder.builder().withProjectDir(new File("src/test/resources")).build();
    String response = FileUtils.readFile(project, "temp.txt").collect(Collectors.joining());

    assertEquals("hello", response);
}
 
Example #20
Source Project: scaffold-clean-architecture   Author: bancolombia   File: FileUtilsTest.java    License: MIT License 5 votes vote down vote up
@Test
public void writeString() throws IOException {
    Project project = ProjectBuilder.builder().withProjectDir(new File("build/tmp")).build();
    FileUtils.writeString(project, "temp.txt", "hello");
    String response = FileUtils.readFile(project, "temp.txt").collect(Collectors.joining());

    assertEquals("hello", response);
}
 
Example #21
Source Project: scaffold-clean-architecture   Author: bancolombia   File: GenerateUseCaseTaskTest.java    License: MIT License 5 votes vote down vote up
@Before
public void setup() {
    Project project = ProjectBuilder.builder().withProjectDir(new File("build/unitTest")).build();
    project.getTasks().create("test", GenerateUseCaseTask.class);

    task = (GenerateUseCaseTask) project.getTasks().getByName("test");
}
 
Example #22
Source Project: scaffold-clean-architecture   Author: bancolombia   File: GenerateModelTaskTest.java    License: MIT License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void generateEntryPointValueUnExistent() throws IOException, ParamNotFoundException {
    Project project = ProjectBuilder.builder().build();
    project.getTasks().create("test", GenerateModelTask.class);

    GenerateModelTask task = (GenerateModelTask) project.getTasks().getByName("test");

    task.generateModelTask();
}
 
Example #23
Source Project: scaffold-clean-architecture   Author: bancolombia   File: GenerateModelTaskTest.java    License: MIT License 5 votes vote down vote up
@Test
public void generateEntryPoint() throws IOException, ParamNotFoundException {
    Project project = ProjectBuilder.builder().withProjectDir(new File("build/unitTest")).build();
    project.getTasks().create("test", GenerateModelTask.class);

    GenerateModelTask task = (GenerateModelTask) project.getTasks().getByName("test");

    task.setName("testModel");
    task.generateModelTask();
    assertTrue(new File("build/unitTest/domain/model/src/main/java/co/com/bancolombia/model/testmodel/gateways/TestModelRepository.java").exists());
    assertTrue(new File("build/unitTest/domain/model/src/main/java/co/com/bancolombia/model/testmodel/TestModel.java").exists());

}
 
Example #24
Source Project: scaffold-clean-architecture   Author: bancolombia   File: GenerateStructureTaskTest.java    License: MIT License 5 votes vote down vote up
@Before
public void setup() {
    Project project = ProjectBuilder.builder().withProjectDir(new File("build/unitTest")).build();
    project.getTasks().create("test", GenerateStructureTask.class);

    task = (GenerateStructureTask) project.getTasks().getByName("test");
}
 
Example #25
Source Project: scaffold-clean-architecture   Author: bancolombia   File: DeleteModuleTaskTest.java    License: MIT License 5 votes vote down vote up
@Before
public void setup() throws IOException, CleanException {
    Project project = ProjectBuilder.builder()
            .withName("cleanArchitecture")
            .withProjectDir(new File("build/unitTest"))
            .build();

    project.getTasks().create("ca", GenerateStructureTask.class);
    GenerateStructureTask generateStructureTask = (GenerateStructureTask) project.getTasks().getByName("ca");
    generateStructureTask.generateStructureTask();

    ProjectBuilder.builder()
            .withName("app-service")
            .withProjectDir(new File("build/unitTest/applications/app-service"))
            .withParent(project)
            .build();

    project.getTasks().create("gda", GenerateDrivenAdapterTask.class);
    GenerateDrivenAdapterTask generateDriven = (GenerateDrivenAdapterTask) project.getTasks().getByName("gda");
    generateDriven.setType(ModuleFactoryDrivenAdapter.DrivenAdapterType.MONGODB);
    generateDriven.generateDrivenAdapterTask();

    ProjectBuilder.builder()
            .withName("mongo-repository")
            .withProjectDir(new File("build/unitTest/infrastructure/driven-adapters/mongo-repository"))
            .withParent(project)
            .build();

    assertTrue(new File("build/unitTest/infrastructure/driven-adapters/mongo-repository/build.gradle").exists());

    project.getTasks().create("test", DeleteModuleTask.class);
    task = (DeleteModuleTask) project.getTasks().getByName("test");
}
 
Example #26
Source Project: gradle-modules-plugin   Author: java9-modularity   File: CompileJavaTaskMutatorTest.java    License: 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 #27
Source Project: gradle-modules-plugin   Author: java9-modularity   File: ModuleNameTest.java    License: MIT License 5 votes vote down vote up
@Test
void findModuleName_ParentProjectWithNoModules() {
    Project project = ProjectBuilder.builder().withProjectDir(new File("test-project/")).build();
    project.getPlugins().apply("java");
    Optional<String> result = new ModuleName().findModuleName(project);

    assertTrue(result.isEmpty(), "Found a module in the parent project. It doesn't have any modules or java code so it should not find anything.");
}
 
Example #28
Source Project: gradle-modules-plugin   Author: java9-modularity   File: ModuleNameTest.java    License: MIT License 5 votes vote down vote up
@Test
void findModuleName_ParentProjectWithWithJava() {
    Project project = ProjectBuilder.builder().withProjectDir(new File("test-project/")).build();
    project.getPlugins().apply("java");

    Optional<String> result = new ModuleName().findModuleName(project);

    assertTrue(result.isEmpty(), "Found a module in the parent project. It doesn't have any modules or java code so it should not find anything.");
}
 
Example #29
Source Project: gradle-modules-plugin   Author: java9-modularity   File: ModuleNameTest.java    License: MIT License 5 votes vote down vote up
@Test
void findModuleName_ModularSubproject() {
    Project project = ProjectBuilder.builder().withProjectDir(new File("test-project/greeter.api/")).build();
    project.getPlugins().apply("java");

    Optional<String> result = new ModuleName().findModuleName(project);

    assertEquals("greeter.api", result.orElseThrow(), "Unexpected module name or the module is missing");
}
 
Example #30
Source Project: jig   Author: dddjava   File: GradleProjectTest.java    License: Apache License 2.0 5 votes vote down vote up
private static ProjectInternal projectOf(String name, Path tempDir) {
    Project root = ProjectBuilder.builder()
            .withName(name)
            .withProjectDir(tempDir.resolve(name).toFile())
            .build();
    return (ProjectInternal) root;
}