use of org.eclipse.che.maven.data.MavenArtifact in project che by eclipse.
the class MavenProject method setModel.
private MavenProjectModifications setModel(MavenModelReaderResult readerResult, boolean clearArtifacts, boolean clearProfiles) {
Info newInfo = info.clone();
newInfo.problems = readerResult.getProblems();
newInfo.activeProfiles = readerResult.getActiveProfiles();
MavenModel model = readerResult.getMavenModel();
newInfo.mavenKey = model.getMavenKey();
if (model.getParent() != null) {
newInfo.parentKey = model.getParent().getMavenKey();
}
newInfo.packaging = model.getPackaging();
newInfo.name = model.getName();
newInfo.sources = model.getBuild().getSources();
newInfo.testSources = model.getBuild().getTestSources();
newInfo.resources = model.getBuild().getResources();
newInfo.testResources = model.getBuild().getTestResources();
newInfo.properties = model.getProperties();
newInfo.filters = model.getBuild().getFilters();
Set<MavenRemoteRepository> remoteRepositories = new HashSet<>();
Set<MavenArtifact> extensions = new HashSet<>();
Set<MavenArtifact> dependencies = new HashSet<>();
Set<MavenPlugin> plugins = new HashSet<>();
Set<MavenKey> unresolvedArtifacts = new HashSet<>();
if (!clearArtifacts) {
if (info.remoteRepositories != null) {
remoteRepositories.addAll(info.remoteRepositories);
}
if (info.extensions != null) {
extensions.addAll(info.extensions);
}
if (info.dependencies != null) {
dependencies.addAll(info.dependencies);
}
if (info.plugins != null) {
plugins.addAll(info.plugins);
}
if (info.unresolvedArtifacts != null) {
unresolvedArtifacts.addAll(info.unresolvedArtifacts);
}
}
remoteRepositories.addAll(model.getRemoteRepositories());
extensions.addAll(model.getExtensions());
dependencies.addAll(model.getDependencies());
plugins.addAll(model.getPlugins());
unresolvedArtifacts.addAll(readerResult.getUnresolvedArtifacts());
newInfo.remoteRepositories = new ArrayList<>(remoteRepositories);
newInfo.extensions = new ArrayList<>(extensions);
newInfo.dependencies = new ArrayList<>(dependencies);
newInfo.plugins = new ArrayList<>(plugins);
newInfo.unresolvedArtifacts = unresolvedArtifacts;
newInfo.modulesNameToPath = collectModulesNameAndPath(model);
return setInfo(newInfo);
}
use of org.eclipse.che.maven.data.MavenArtifact in project che by eclipse.
the class WorkspaceTest method testUpdateProject.
@Test
public void testUpdateProject() 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("test", pom);
IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
mavenWorkspace.update(Collections.singletonList(test));
mavenWorkspace.waitForUpdate();
MavenProject mavenProject = mavenProjectManager.findMavenProject(test);
List<MavenArtifact> dependencies = mavenProject.getDependencies();
assertThat(dependencies).isNotNull().hasSize(2);
assertThat(dependencies).onProperty("artifactId").contains("junit", "hamcrest-core");
assertThat(dependencies).onProperty("groupId").contains("junit", "org.hamcrest");
assertThat(dependencies).onProperty("version").contains("4.12", "1.3");
}
use of org.eclipse.che.maven.data.MavenArtifact 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.che.maven.data.MavenArtifact in project che by eclipse.
the class MavenServerManagerTest method testProjectHasDependencies.
@Test
public void testProjectHasDependencies() throws Exception {
MavenServerResult resolveProject = mavenServer.resolveProject(new File(MavenServerManagerTest.class.getResource("/FirstProject/pom.xml").getFile()), Collections.emptyList(), Collections.emptyList());
assertNotNull(resolveProject);
MavenProjectInfo projectInfo = resolveProject.getProjectInfo();
assertNotNull(projectInfo);
MavenModel mavenModel = projectInfo.getMavenModel();
assertNotNull(mavenModel);
List<MavenArtifact> dependencies = mavenModel.getDependencies();
assertFalse(dependencies.isEmpty());
assertEquals(26, dependencies.size());
}
use of org.eclipse.che.maven.data.MavenArtifact in project che by eclipse.
the class ClasspathManager method getClasspath.
private IClasspathEntry[] getClasspath(MavenProject mavenProject) {
ClasspathHelper helper = new ClasspathHelper(true);
List<MavenArtifact> dependencies = mavenProject.getDependencies();
for (MavenArtifact dependency : dependencies) {
File file = dependency.getFile();
if (file == null) {
continue;
}
ClasspathEntryHelper entry;
if (file.getPath().endsWith("pom.xml")) {
String path = file.getParentFile().getPath();
entry = helper.addProjectEntry(new Path(path.substring(workspacePath.length())));
} else {
entry = helper.addLibraryEntry(new Path(file.getPath()));
}
if (entry != null) {
MavenArtifactKey artifactKey = new MavenArtifactKey(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getExtension(), dependency.getClassifier());
entry.setArtifactKey(artifactKey);
attachSources(entry);
}
}
return helper.getEntries();
}
Aggregations