use of org.jetbrains.idea.maven.project.MavenEmbeddersManager in project intellij-community by JetBrains.
the class MavenProjectsTreeReadingTest method testOutputPathsAreBasedOnTargetPathWhenResolving.
public void testOutputPathsAreBasedOnTargetPathWhenResolving() throws Exception {
createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<build>" + " <directory>my-target</directory>" + "</build>");
updateAll(myProjectPom);
MavenProject project = myTree.getRootProjects().get(0);
PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target"), project.getBuildDirectory());
PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target/classes"), project.getOutputDirectory());
PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target/test-classes"), project.getTestOutputDirectory());
MavenEmbeddersManager embeddersManager = new MavenEmbeddersManager(myProject);
try {
myTree.resolve(myProject, project, getMavenGeneralSettings(), embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
} finally {
embeddersManager.releaseInTests();
}
PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target"), project.getBuildDirectory());
PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target/classes"), project.getOutputDirectory());
PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target/test-classes"), project.getTestOutputDirectory());
}
use of org.jetbrains.idea.maven.project.MavenEmbeddersManager in project intellij-community by JetBrains.
the class MavenProjectsTreeReadingTest method testSaveLoad.
public void testSaveLoad() throws Exception {
createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>" + "<modules>" + " <module>m1</module>" + " <module>m2</module>" + "</modules>" + // stripping down plugins
"<build>" + " <plugins>" + " <plugin>" + " <groupId>org.apache.maven.plugins</groupId>" + " <artifactId>maven-compiler-plugin</artifactId>" + " <configuration>" + " <source>1.4</source>" + " </configuration>" + " </plugin>" + " </plugins>" + "</build>" + // stripping down Xpp3Dom fields
"<reports>" + " <someTag/>" + "</reports>");
VirtualFile m1 = createModulePom("m1", "<groupId>test</groupId>" + "<artifactId>m1</artifactId>" + "<version>1</version>");
VirtualFile m2 = createModulePom("m2", "<groupId>test</groupId>" + "<artifactId>m2</artifactId>" + "<version>1</version>");
updateAll(myProjectPom);
MavenProject parentProject = myTree.findProject(myProjectPom);
MavenEmbeddersManager embeddersManager = new MavenEmbeddersManager(myProject);
try {
myTree.resolve(myProject, parentProject, getMavenGeneralSettings(), embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
} finally {
embeddersManager.releaseInTests();
}
Path f = myDir.toPath().resolve("tree.dat");
myTree.save(f);
MavenProjectsTree read = MavenProjectsTree.read(myProject, f);
List<MavenProject> roots = read.getRootProjects();
assertEquals(1, roots.size());
MavenProject rootProject = roots.get(0);
assertEquals(myProjectPom, rootProject.getFile());
assertEquals(2, read.getModules(rootProject).size());
assertEquals(m1, read.getModules(rootProject).get(0).getFile());
assertEquals(m2, read.getModules(rootProject).get(1).getFile());
assertNull(read.findAggregator(rootProject));
assertEquals(rootProject, read.findAggregator(read.findProject(m1)));
assertEquals(rootProject, read.findAggregator(read.findProject(m2)));
}
use of org.jetbrains.idea.maven.project.MavenEmbeddersManager in project intellij-community by JetBrains.
the class MavenProjectsTreeReadingTest method testCollectingProfilesFromParentsAfterResolve.
public void testCollectingProfilesFromParentsAfterResolve() throws Exception {
MavenServerManager.getInstance().setUseMaven2(true);
createModulePom("parent1", "<groupId>test</groupId>" + "<artifactId>parent1</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>" + "<profiles>" + " <profile>" + " <id>parent1Profile</id>" + " </profile>" + "</profiles>");
createProfilesXml("parent1", "<profile>" + " <id>parent1ProfileXml</id>" + "</profile>");
createModulePom("parent2", "<groupId>test</groupId>" + "<artifactId>parent2</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>" + "<parent>" + " <groupId>test</groupId>" + " <artifactId>parent1</artifactId>" + " <version>1</version>" + " <relativePath>../parent1/pom.xml</relativePath>" + "</parent>" + "<profiles>" + " <profile>" + " <id>parent2Profile</id>" + " </profile>" + "</profiles>");
createProfilesXml("parent2", "<profile>" + " <id>parent2ProfileXml</id>" + "</profile>");
createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<parent>" + " <groupId>test</groupId>" + " <artifactId>parent2</artifactId>" + " <version>1</version>" + " <relativePath>parent2/pom.xml</relativePath>" + "</parent>" + "<profiles>" + " <profile>" + " <id>projectProfile</id>" + " </profile>" + "</profiles>");
createProfilesXml("<profile>" + " <id>projectProfileXml</id>" + "</profile>");
updateSettingsXml("<profiles>" + " <profile>" + " <id>settings</id>" + " </profile>" + "</profiles>");
updateAll(Arrays.asList("projectProfileXml", "projectProfile", "parent1Profile", "parent1ProfileXml", "parent2Profile", "parent2ProfileXml", "settings", "xxx"), myProjectPom);
MavenProject project = myTree.findProject(myProjectPom);
assertUnorderedElementsAreEqual(project.getActivatedProfilesIds().getEnabledProfiles(), "projectProfileXml", "projectProfile", "parent1Profile", "parent1ProfileXml", "parent2Profile", "parent2ProfileXml", "settings");
MavenEmbeddersManager embeddersManager = new MavenEmbeddersManager(myProject);
try {
myTree.resolve(myProject, project, getMavenGeneralSettings(), embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
} finally {
embeddersManager.releaseInTests();
}
assertUnorderedElementsAreEqual(project.getActivatedProfilesIds().getEnabledProfiles(), "projectProfileXml", "projectProfile", "parent1Profile", "parent1ProfileXml", "parent2Profile", "parent2ProfileXml", "settings");
}
use of org.jetbrains.idea.maven.project.MavenEmbeddersManager in project intellij-community by JetBrains.
the class MavenProjectsTreeReadingTest method testDoNotUpdateChildAfterParentWasResolved.
public void testDoNotUpdateChildAfterParentWasResolved() throws Exception {
createProjectPom("<groupId>test</groupId>" + "<artifactId>parent</artifactId>" + "<version>1</version>");
VirtualFile child = createModulePom("child", "<groupId>test</groupId>" + "<artifactId>child</artifactId>" + "<version>1</version>" + "<parent>" + " <groupId>test</groupId>" + " <artifactId>parent</artifactId>" + " <version>1</version>" + "</parent>");
MyLoggingListener listener = new MyLoggingListener();
myTree.addListener(listener);
updateAll(myProjectPom, child);
MavenProject parentProject = myTree.findProject(myProjectPom);
MavenEmbeddersManager embeddersManager = new MavenEmbeddersManager(myProject);
try {
final NativeMavenProjectHolder[] nativeProject = new NativeMavenProjectHolder[1];
myTree.addListener(new MavenProjectsTree.Listener() {
@Override
public void projectResolved(Pair<MavenProject, MavenProjectChanges> projectWithChanges, NativeMavenProjectHolder nativeMavenProject) {
nativeProject[0] = nativeMavenProject;
}
});
myTree.resolve(myProject, parentProject, getMavenGeneralSettings(), embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
myTree.resolvePlugins(parentProject, nativeProject[0], embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
myTree.resolveFolders(parentProject, getMavenImporterSettings(), embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
} finally {
embeddersManager.releaseInTests();
}
assertEquals("updated: parent child deleted: <none> resolved: parent plugins: parent folders: parent ", listener.log);
myTree.updateAll(false, getMavenGeneralSettings(), EMPTY_MAVEN_PROCESS);
assertEquals("updated: parent child deleted: <none> resolved: parent plugins: parent folders: parent ", listener.log);
}
use of org.jetbrains.idea.maven.project.MavenEmbeddersManager in project intellij-community by JetBrains.
the class MavenVersionsRemoteManager method execute.
@NotNull
@Override
public List<String> execute(@NotNull RepositoryLibraryDescription repositoryLibraryDescription, ProgressIndicator indicator) {
MavenEmbeddersManager manager = MavenProjectsManager.getInstance(myProject).getEmbeddersManager();
MavenEmbedderWrapper embedder = manager.getEmbedder(MavenEmbeddersManager.FOR_GET_VERSIONS, null, null);
embedder.customizeForGetVersions();
try {
List<MavenRemoteRepository> remoteRepositories = convertRepositories(repositoryLibraryDescription.getRemoteRepositories());
List<String> versions = embedder.retrieveVersions(repositoryLibraryDescription.getGroupId(), repositoryLibraryDescription.getArtifactId(), remoteRepositories);
Collections.sort(versions, (o1, o2) -> {
MavenVersionComparable v1 = new MavenVersionComparable(o1);
MavenVersionComparable v2 = new MavenVersionComparable(o2);
return v2.compareTo(v1);
});
return versions;
} catch (MavenProcessCanceledException e) {
return Collections.emptyList();
} finally {
manager.release(embedder);
}
}
Aggregations