Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-1230: return default test source dir if not set other #1362

Merged
merged 2 commits into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.che.maven.data.MavenResource;
import org.eclipse.che.maven.server.MavenProjectInfo;
import org.eclipse.che.maven.server.MavenServerResult;
import org.eclipse.che.plugin.maven.shared.MavenAttributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,6 +40,11 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.eclipse.che.plugin.maven.shared.MavenAttributes.DEFAULT_RESOURCES_FOLDER;
import static org.eclipse.che.plugin.maven.shared.MavenAttributes.DEFAULT_SOURCE_FOLDER;
import static org.eclipse.che.plugin.maven.shared.MavenAttributes.DEFAULT_TEST_RESOURCES_FOLDER;
import static org.eclipse.che.plugin.maven.shared.MavenAttributes.DEFAULT_TEST_SOURCE_FOLDER;

/**
* @author Evgen Vidolob
*/
Expand Down Expand Up @@ -145,22 +151,24 @@ private ModelReadingResult doRead(File pom) {

Build build = model.getBuild();
if (build == null) {
result.getBuild().setSources(Collections.singletonList("src/main/java"));
result.getBuild().setTestSources(Collections.singletonList("src/test/java"));
result.getBuild().setSources(Collections.singletonList(DEFAULT_SOURCE_FOLDER));
result.getBuild().setTestSources(Collections.singletonList(DEFAULT_TEST_SOURCE_FOLDER));
result.getBuild().setResources(Collections.singletonList(
new MavenResource("src/main/resources", false, null, Collections.emptyList(), Collections.emptyList())));
new MavenResource(DEFAULT_RESOURCES_FOLDER, false, null, Collections.emptyList(), Collections.emptyList())));
result.getBuild().setTestResources(Collections.singletonList(
new MavenResource("src/test/resources", false, null, Collections.emptyList(), Collections.emptyList())));
new MavenResource(DEFAULT_TEST_RESOURCES_FOLDER, false, null, Collections.emptyList(), Collections.emptyList())));
} else {
String sourceDirectory = build.getSourceDirectory();
if (sourceDirectory == null) {
sourceDirectory = "src/main/java";
sourceDirectory = DEFAULT_SOURCE_FOLDER;
}
String testSourceDirectory = build.getTestSourceDirectory();
if (testSourceDirectory == null) {
testSourceDirectory = DEFAULT_TEST_SOURCE_FOLDER;
}
result.getBuild().setSources(Collections.singletonList(sourceDirectory));
result.getBuild().setTestSources(Collections.singletonList(build.getTestSourceDirectory()));
result.getBuild().setTestSources(Collections.singletonList(testSourceDirectory));
result.getBuild().setResources(convertResources(build.getResources()));
//TODO add test sources
// result.getBuild().setTestSources(convertResources(build.getPlugins()));
}
//TODO add profiles
return new ModelReadingResult(result, problems, enabledProfiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,79 @@ public boolean matches(Object[] value) {
});
}

@Test
public void testShouldContainsDefaultTestSourceDirectory() 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>" +
"</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("src/test/java");
}
return false;
}).findFirst().isPresent();
}
});
}

@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();
}
});
}

@Test
public void testUpdateProjectThatHasDependencyInWorkspace() throws Exception {
String pom = "<groupId>test</groupId>" +
Expand Down