Search in sources :

Example 1 with ClasspathHelper

use of org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper in project che by eclipse.

the class MavenWorkspace method addSourcesFromBuildHelperPlugin.

private void addSourcesFromBuildHelperPlugin(MavenProject project) {
    IJavaProject javaProject = JavaCore.create(project.getProject());
    try {
        ClasspathHelper helper = new ClasspathHelper(javaProject);
        Element pluginConfigurationSource = project.getPluginConfiguration("org.codehaus.mojo", "build-helper-maven-plugin", "add-source");
        Element pluginConfigurationTestSource = project.getPluginConfiguration("org.codehaus.mojo", "build-helper-maven-plugin", "add-test-source");
        IPath projectPath = project.getProject().getFullPath();
        RegisteredProject registeredProject = projectRegistryProvider.get().getProject(projectPath.toOSString());
        if (registeredProject == null) {
            throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CORE_EXCEPTION, "Project " + projectPath.toOSString() + " doesn't exist"));
        }
        List<String> sourceFolders = registeredProject.getAttributes().get(Constants.SOURCE_FOLDER);
        List<String> testSourceFolders = registeredProject.getAttributes().get(MavenAttributes.TEST_SOURCE_FOLDER);
        addSourcePathFromConfiguration(helper, project, pluginConfigurationSource, sourceFolders);
        addSourcePathFromConfiguration(helper, project, pluginConfigurationTestSource, testSourceFolders);
        javaProject.setRawClasspath(helper.getEntries(), null);
    } catch (JavaModelException e) {
        LOG.error("Can't update Java project classpath with Maven build helper plugin configuration", e);
    }
}
Also used : ClasspathHelper(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) Element(org.jdom.Element) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) JavaModelStatus(org.eclipse.jdt.internal.core.JavaModelStatus)

Example 2 with ClasspathHelper

use of org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper in project che by eclipse.

the class MavenWorkspace method updateJavaProject.

private void updateJavaProject(MavenProject project) {
    IJavaProject javaProject = JavaCore.create(project.getProject());
    try {
        ClasspathHelper helper = new ClasspathHelper(javaProject);
        project.getSources().stream().map(s -> project.getProject().getFullPath().append(s)).forEach(helper::addSourceEntry);
        project.getTestSources().stream().map(s -> project.getProject().getFullPath().append(s)).forEach(helper::addSourceEntry);
        //add maven classpath container
        helper.addContainerEntry(new Path(MavenClasspathContainer.CONTAINER_ID));
        //add JRE classpath container
        helper.addContainerEntry(new Path(JREContainerInitializer.JRE_CONTAINER));
        javaProject.setRawClasspath(helper.getEntries(), null);
    } catch (JavaModelException e) {
        LOG.error("Can't update Java project classpath", e);
    }
}
Also used : ClasspathHelper(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper) JavaModelException(org.eclipse.jdt.core.JavaModelException) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) MAVEN_ID(org.eclipse.che.plugin.maven.shared.MavenAttributes.MAVEN_ID) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Constants(org.eclipse.che.ide.ext.java.shared.Constants) JREContainerInitializer(org.eclipse.che.jdt.core.launching.JREContainerInitializer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IProject(org.eclipse.core.resources.IProject) IPath(org.eclipse.core.runtime.IPath) Map(java.util.Map) ConflictException(org.eclipse.che.api.core.ConflictException) ClasspathHelper(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper) EventService(org.eclipse.che.api.core.notification.EventService) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) Logger(org.slf4j.Logger) IJavaProject(org.eclipse.jdt.core.IJavaProject) EventSubscriber(org.eclipse.che.api.core.notification.EventSubscriber) JavaCore(org.eclipse.jdt.core.JavaCore) JavaModelStatus(org.eclipse.jdt.internal.core.JavaModelStatus) ProjectDeletedEvent(org.eclipse.che.api.project.server.ProjectDeletedEvent) MavenAttributes(org.eclipse.che.plugin.maven.shared.MavenAttributes) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) NotFoundException(org.eclipse.che.api.core.NotFoundException) MavenProjectModifications(org.eclipse.che.plugin.maven.server.core.project.MavenProjectModifications) Provider(com.google.inject.Provider) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) Path(org.eclipse.core.runtime.Path) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) IJavaModelStatusConstants(org.eclipse.jdt.core.IJavaModelStatusConstants) Element(org.jdom.Element) Collections(java.util.Collections) Singleton(com.google.inject.Singleton) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject)

Aggregations

RegisteredProject (org.eclipse.che.api.project.server.RegisteredProject)2 ClasspathHelper (org.eclipse.che.plugin.maven.server.core.classpath.ClasspathHelper)2 IPath (org.eclipse.core.runtime.IPath)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 JavaModelStatus (org.eclipse.jdt.internal.core.JavaModelStatus)2 Element (org.jdom.Element)2 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 Singleton (com.google.inject.Singleton)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1