Search in sources :

Example 51 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute in project xtext-eclipse by eclipse.

the class JavaProjectFactory method enhanceProject.

@Override
protected void enhanceProject(IProject project, SubMonitor monitor, Shell shell) throws CoreException {
    super.enhanceProject(project, monitor, shell);
    if (builderIds.contains(JavaCore.BUILDER_ID)) {
        SubMonitor subMonitor = SubMonitor.convert(monitor, 10);
        try {
            subMonitor.subTask(Messages.JavaProjectFactory_ConfigureJavaProject + projectName);
            IJavaProject javaProject = JavaCore.create(project);
            List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
            for (final IProject referencedProject : project.getReferencedProjects()) {
                final IClasspathEntry referencedProjectClasspathEntry = JavaCore.newProjectEntry(referencedProject.getFullPath());
                classpathEntries.add(referencedProjectClasspathEntry);
            }
            for (final String folderName : getFolders()) {
                final IFolder sourceFolder = project.getFolder(folderName);
                String outputFolderName = sourceFolderOutputs.get(folderName);
                final IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(sourceFolder.getFullPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, outputFolderName == null ? null : project.getFolder(outputFolderName).getFullPath(), testSourceFolders.contains(folderName) ? new IClasspathAttribute[] { JavaCore.newClasspathAttribute("test", "true") } : new IClasspathAttribute[0]);
                classpathEntries.add(srcClasspathEntry);
            }
            classpathEntries.addAll(extraClasspathEntries);
            IClasspathEntry defaultJREContainerEntry = getJreContainerEntry();
            classpathEntries.add(defaultJREContainerEntry);
            addMoreClasspathEntriesTo(classpathEntries);
            javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), subMonitor.newChild(1));
            javaProject.setOutputLocation(new Path("/" + project.getName() + "/" + defaultOutput), subMonitor.newChild(1));
            String executionEnvironmentId = JavaRuntime.getExecutionEnvironmentId(defaultJREContainerEntry.getPath());
            if (executionEnvironmentId != null) {
                BuildPathSupport.setEEComplianceOptions(javaProject, executionEnvironmentId, null);
            }
        } catch (JavaModelException e) {
            logger.error(e.getMessage(), e);
        }
    }
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) SubMonitor(org.eclipse.core.runtime.SubMonitor) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 52 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute in project xtext-eclipse by eclipse.

the class XtextProjectCreator method configureJavaProject.

private void configureJavaProject(ProjectDescriptor descriptor, JavaProjectFactory factory) {
    configurePlainProject(descriptor, factory);
    factory.addProjectNatures(XtextProjectHelper.NATURE_ID);
    factory.addBuilderIds(XtextProjectHelper.BUILDER_ID);
    factory.addProjectNatures(JavaCore.NATURE_ID);
    factory.addBuilderIds(JavaCore.BUILDER_ID);
    for (SourceFolderDescriptor sourceFolder : descriptor.getSourceFolders()) {
        String output = sourceFolder.isTest() ? (needsM2eIntegration(descriptor) ? "target/test-classes" : "test-bin") : null;
        factory.addSourceFolder(sourceFolder.getPath(), output, sourceFolder.isTest());
    }
    factory.setJreContainerEntry(JREContainerProvider.getJREContainerEntry(descriptor.getBree()));
    if (needsM2eIntegration(descriptor)) {
        factory.setDefaultOutput("target/classes");
        if (!descriptor.isEclipsePluginProject()) {
            factory.addClasspathEntries(JavaCore.newContainerEntry(new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER")));
        }
    }
    if (needsBuildshipIntegration(descriptor) && !descriptor.isEclipsePluginProject()) {
        factory.addClasspathEntries(JavaCore.newContainerEntry(new Path("org.eclipse.buildship.core.gradleclasspathcontainer")));
    }
    if (requiresJUnitLibContainer(descriptor)) {
        JUnitVersion junitVersion = descriptor.getConfig().getJunitVersion();
        factory.addClasspathEntries(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.junit.JUNIT_CONTAINER").append(Integer.toString(junitVersion.getVersion())), new IAccessRule[0], new IClasspathAttribute[] { JavaCore.newClasspathAttribute("test", "true") }, false));
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) SourceFolderDescriptor(org.eclipse.xtext.xtext.wizard.SourceFolderDescriptor) JUnitVersion(org.eclipse.xtext.util.JUnitVersion) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Aggregations

IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)52 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)37 IPath (org.eclipse.core.runtime.IPath)26 ArrayList (java.util.ArrayList)17 IJavaProject (org.eclipse.jdt.core.IJavaProject)16 Path (org.eclipse.core.runtime.Path)11 HashMap (java.util.HashMap)9 CoreException (org.eclipse.core.runtime.CoreException)9 IAccessRule (org.eclipse.jdt.core.IAccessRule)9 File (java.io.File)6 LinkedHashMap (java.util.LinkedHashMap)6 IProject (org.eclipse.core.resources.IProject)6 Map (java.util.Map)5 IFolder (org.eclipse.core.resources.IFolder)5 Bundle (org.osgi.framework.Bundle)5 Iterator (java.util.Iterator)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 URL (java.net.URL)3 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)3