use of org.eclipse.che.maven.data.MavenKey in project che by eclipse.
the class MavenServerManagerTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
workspaceCache = new MavenWorkspaceCache();
workspaceCache.put(new MavenKey("org.eclipse.che", "che-ide-subModule", "1.0.0-TEST-SNAPSHOT"), new File(MavenServerManagerTest.class.getResource("/multimoduleProject/subModule/pom.xml").getFile()));
mavenServer = manager.createMavenServer();
mavenServer.customize(workspaceCache, new MyMavenTerminal(), new MyMavenServerProgressNotifier(), true, false);
}
use of org.eclipse.che.maven.data.MavenKey in project che by eclipse.
the class MavenProjectManagerTest method testNotValidResolveProject.
@Test
public void testNotValidResolveProject() throws Exception {
when(project.getFile(MavenConstants.POM_FILE_NAME)).thenReturn(pom);
when(pom.getLocation()).thenReturn(new Path(MavenProjectManagerTest.class.getResource("/BadProject/pom.xml").getFile()));
when(pom.getFullPath()).thenReturn(new Path("/BadProject/pom.xml"));
when(project.getFullPath()).thenReturn(new Path("/BadProject"));
projectManager.addListener(listener);
MavenProject mavenProject = new MavenProject(project, workspace);
mavenProject.read(project, manager);
MavenKey mavenKey = mavenProject.getMavenKey();
assertThat(mavenKey).isNotNull();
projectManager.resolveMavenProject(project, mavenProject);
verify(listener).projectResolved(any(), any());
assertThat(mavenProject.getProblems()).isNotNull().isNotEmpty();
mavenProject.getProblems().forEach(System.out::println);
}
use of org.eclipse.che.maven.data.MavenKey in project che by eclipse.
the class MavenModelReader method doRead.
private ModelReadingResult doRead(File pom) {
List<MavenProjectProblem> problems = new ArrayList<>();
Set<String> enabledProfiles = new HashSet<>();
MavenModel result = new MavenModel();
fillModelByDefaults(result);
Model model = null;
try {
model = Model.readFrom(pom);
} catch (IOException e) {
problems.add(MavenProjectProblem.newProblem(pom.getPath(), e.getMessage(), MavenProblemType.SYNTAX));
}
if (model == null) {
return new ModelReadingResult(result, problems, enabledProfiles);
}
final MavenKey parentKey;
if (model.getParent() == null) {
parentKey = result.getParent().getMavenKey();
} else {
Parent modelParent = model.getParent();
parentKey = new MavenKey(modelParent.getGroupId(), modelParent.getArtifactId(), modelParent.getVersion());
MavenParent parent = new MavenParent(parentKey, modelParent.getRelativePath());
result.setParent(parent);
}
final MavenKey mavenKey = new MavenKey(getNotNull(model.getGroupId(), parentKey.getGroupId()), model.getArtifactId(), getNotNull(model.getVersion(), parentKey.getVersion()));
result.setMavenKey(mavenKey);
if (model.getPackaging() != null) {
result.setPackaging(model.getPackaging());
}
result.setName(model.getName());
final List<String> modules = model.getModules();
if (modules != null) {
result.setModules(new ArrayList<>(model.getModules()));
}
Map<String, String> properties = model.getProperties();
Properties prop = new Properties();
if (properties != null) {
prop.putAll(properties);
}
result.setProperties(prop);
final Build build = model.getBuild();
if (build != null) {
final String sourceDirectory = build.getSourceDirectory();
if (sourceDirectory != null) {
result.getBuild().setSources(singletonList(sourceDirectory));
}
final String testSourceDirectory = build.getTestSourceDirectory();
if (testSourceDirectory != null) {
result.getBuild().setTestSources(singletonList(testSourceDirectory));
}
result.getBuild().setResources(convertResources(build.getResources()));
}
//TODO add profiles
return new ModelReadingResult(result, problems, enabledProfiles);
}
use of org.eclipse.che.maven.data.MavenKey in project che by eclipse.
the class MavenProjectManager method clearMavenKeyMap.
private void clearMavenKeyMap(MavenProject mavenProject) {
MavenKey mavenKey = mavenProject.getMavenKey();
mavenWorkspaceCache.invalidate(mavenKey);
keyToProjectMap.remove(mavenKey);
}
use of org.eclipse.che.maven.data.MavenKey in project che by eclipse.
the class MavenProjectManager method findDependentProjects.
public List<MavenProject> findDependentProjects(List<MavenProject> projects) {
readLock.lock();
try {
List<MavenProject> result = new ArrayList<>();
Set<MavenKey> mavenKeys = projects.stream().map(MavenProject::getMavenKey).collect(Collectors.toSet());
Set<String> paths = projects.stream().map(project -> project.getProject().getFullPath().toOSString()).collect(Collectors.toSet());
for (MavenProject project : projectToMavenProjectMap.values()) {
boolean isAdd = false;
for (String path : project.getModulesPath()) {
if (paths.contains(path)) {
isAdd = true;
break;
}
}
if (!isAdd) {
for (MavenArtifact artifact : project.getDependencies()) {
if (contains(mavenKeys, artifact.getArtifactId(), artifact.getGroupId(), artifact.getVersion())) {
isAdd = true;
break;
}
}
}
if (isAdd) {
result.add(project);
}
}
return result;
} finally {
readLock.unlock();
}
}
Aggregations