use of org.eclipse.core.resources.IProject in project che by eclipse.
the class WorkspaceTest method testUpdateProjectThatHasDependencyInWorkspace.
@Test
public void testUpdateProjectThatHasDependencyInWorkspace() throws Exception {
String pom = "<groupId>test</groupId>" + "<artifactId>testArtifact</artifactId>" + "<version>42</version>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.12</version>" + " </dependency>" + "</dependencies>";
createTestProject("test1", pom);
String pom2 = "<groupId>test2</groupId>" + "<artifactId>testArtifact2</artifactId>" + "<version>2</version>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.12</version>" + " </dependency>" + " <dependency>" + " <groupId>test</groupId>" + " <artifactId>testArtifact</artifactId>" + " <version>42</version>" + " </dependency>" + "</dependencies>";
createTestProject("test2", pom2);
IProject project1 = ResourcesPlugin.getWorkspace().getRoot().getProject("test1");
IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject("test2");
mavenWorkspace.update(Arrays.asList(project1, project2));
mavenWorkspace.waitForUpdate();
MavenProject mavenProject = mavenProjectManager.findMavenProject(project2);
List<MavenArtifact> dependencies = mavenProject.getDependencies();
assertThat(dependencies).isNotNull().hasSize(3);
assertThat(dependencies).onProperty("artifactId").contains("junit", "hamcrest-core", "testArtifact");
assertThat(dependencies).onProperty("groupId").contains("junit", "org.hamcrest", "test");
assertThat(dependencies).onProperty("version").contains("4.12", "1.3", "42");
List<File> depFiles = dependencies.stream().map(MavenArtifact::getFile).collect(Collectors.toList());
List<String> paths = depFiles.stream().map(File::getAbsolutePath).collect(Collectors.toList());
assertThat(paths).contains(new java.io.File(root, "test1/pom.xml").getAbsolutePath());
}
use of org.eclipse.core.resources.IProject in project che by eclipse.
the class WorkspaceTest method testShouldContainsCustomTestSourceDirectory.
@Test
public void testShouldContainsCustomTestSourceDirectory() throws Exception {
String pom = "<groupId>test</groupId>" + "<artifactId>testArtifact</artifactId>" + "<version>42</version>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.12</version>" + " </dependency>" + "</dependencies>" + "<build>" + "<testSourceDirectory>/mytest</testSourceDirectory>" + "</build>";
createTestProject("test", pom);
IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
mavenWorkspace.update(Collections.singletonList(test));
mavenWorkspace.waitForUpdate();
JavaProject javaProject = (JavaProject) JavaCore.create(test);
IClasspathEntry[] classpath = javaProject.getResolvedClasspath();
assertThat(classpath).onProperty("path").is(new Condition<Object[]>() {
@Override
public boolean matches(Object[] value) {
return Stream.of(value).filter(o -> {
if (o instanceof IPath) {
return ((IPath) o).toOSString().endsWith("test");
}
return false;
}).findFirst().isPresent();
}
});
}
use of org.eclipse.core.resources.IProject in project che by eclipse.
the class WorkspaceTest method testWsShouldAddSourceFolderFromBuildHelperPlugin.
@Test
public void testWsShouldAddSourceFolderFromBuildHelperPlugin() throws Exception {
String pom = "<groupId>test</groupId>\n" + "<artifactId>testArtifact</artifactId>\n" + "<version>42</version>\n" + "<properties>\n" + " <dto-generator-out-directory>${project.build.directory}/generated-sources/dto/</dto-generator-out-directory>\n" + "</properties>\n" + "<dependencies>\n" + " <dependency>\n" + " <groupId>junit</groupId>\n" + " <artifactId>junit</artifactId>\n" + " <version>4.12</version>\n" + " </dependency>\n" + "</dependencies>\n" + "<build>\n" + " <plugins>\n" + " <plugin>\n" + " <groupId>org.codehaus.mojo</groupId>\n" + " <artifactId>build-helper-maven-plugin</artifactId>\n" + " <executions>\n" + " <execution>\n" + " <id>add-source</id>\n" + " <phase>process-sources</phase>\n" + " <goals>\n" + " <goal>add-source</goal>\n" + " </goals>\n" + " <configuration>\n" + " <sources>\n" + " <source>${dto-generator-out-directory}</source>\n" + " </sources>\n" + " </configuration>\n" + " </execution>\n" + " <execution>\n" + " <id>add-test-source</id>\n" + " <phase>generate-sources</phase>\n" + " <goals>\n" + " <goal>add-test-source</goal>\n" + " </goals>\n" + " <configuration>\n" + " <sources>\n" + " <source>${dto-generator-out-directory}src-gen/test/java</source>\n" + " </sources>\n" + " </configuration>\n" + " </execution>" + " </executions>\n" + " </plugin>\n" + " </plugins>\n" + "</build>";
createTestProject("test", pom);
IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
mavenWorkspace.update(Collections.singletonList(test));
mavenWorkspace.waitForUpdate();
IJavaProject javaProject = JavaCore.create(test);
IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
assertThat(rawClasspath).onProperty("path").contains(new Path("/test/target/generated-sources/dto/"));
//attributes should be updated
List<String> sourceFolders = projectRegistry.getProject("test").getAttributes().get(Constants.SOURCE_FOLDER);
List<String> testSourceFolders = projectRegistry.getProject("test").getAttributes().get(TEST_SOURCE_FOLDER);
assertEquals(2, sourceFolders.size());
assertThat(sourceFolders, hasItems("src/main/java", "target/generated-sources/dto/"));
assertEquals(2, testSourceFolders.size());
assertThat(testSourceFolders, hasItems("src/test/java", "target/generated-sources/dto/src-gen/test/java"));
}
use of org.eclipse.core.resources.IProject in project che by eclipse.
the class WorkspaceTest method testProjectWithParent.
@Test
public void testProjectWithParent() throws Exception {
String pom = "<parent>" + " <groupId>testParent</groupId>" + " <artifactId>testParentArtifact</artifactId>" + " <version>42</version>" + "</parent>" + "<artifactId>testArtifact</artifactId>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.12</version>" + " </dependency>" + "</dependencies>";
createTestProject("test", pom);
IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
mavenWorkspace.update(Collections.singletonList(test));
mavenWorkspace.waitForUpdate();
MavenProject mavenProject = mavenProjectManager.findMavenProject(test);
MavenKey mavenKey = mavenProject.getMavenKey();
assertThat(mavenKey.getArtifactId()).isEqualTo("testArtifact");
assertThat(mavenKey.getGroupId()).isEqualTo("testParent");
assertThat(mavenKey.getVersion()).isEqualTo("42");
}
use of org.eclipse.core.resources.IProject in project che by eclipse.
the class WorkspaceTest method testAddingNewModule.
@Test
public void testAddingNewModule() throws Exception {
String pom = "<groupId>test</groupId>" + "<artifactId>testArtifact</artifactId>" + "<version>42</version>" + "<modules>" + " <module>module1</module>" + "</modules>";
FolderEntry parentFolder = createTestProject("parent", pom);
String pomModule1 = "<groupId>test</groupId>" + "<artifactId>testModule1</artifactId>" + "<version>1</version>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.12</version>" + " </dependency>" + "</dependencies>";
createTestProject("parent/module1", pomModule1);
IProject parent = ResourcesPlugin.getWorkspace().getRoot().getProject("parent");
mavenWorkspace.update(Collections.singletonList(parent));
mavenWorkspace.waitForUpdate();
assertThat(projectRegistry.getProjects()).hasSize(2).onProperty("path").containsOnly("/parent", "/parent/module1");
VirtualFile parentPom = parentFolder.getChild("pom.xml").getVirtualFile();
Model model = Model.readFrom(parentPom);
List<String> modules = new ArrayList<>(model.getModules());
modules.add("module2");
model.setModules(modules);
model.writeTo(parentPom);
String pomModule2 = "<groupId>module2</groupId>" + "<artifactId>testModule2</artifactId>" + "<version>2</version>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.12</version>" + " </dependency>" + "</dependencies>";
createTestProject("parent/module2", pomModule2);
mavenWorkspace.update(Collections.singletonList(parent));
mavenWorkspace.waitForUpdate();
assertThat(projectRegistry.getProjects()).hasSize(3).onProperty("path").containsOnly("/parent", "/parent/module1", "/parent/module2");
}
Aggregations