Search in sources :

Example 1 with EclipseJdt

use of org.gradle.plugins.ide.eclipse.model.EclipseJdt in project gradle by gradle.

the class GenerateEclipseJdt method configure.

@SuppressWarnings("unchecked")
protected void configure(Jdt jdtContent) {
    EclipseJdt jdtModel = getJdt();
    jdtModel.getFile().getBeforeMerged().execute(jdtContent);
    jdtContent.setSourceCompatibility(jdtModel.getSourceCompatibility());
    jdtContent.setTargetCompatibility(jdtModel.getTargetCompatibility());
    jdtModel.getFile().getWhenMerged().execute(jdtContent);
}
Also used : EclipseJdt(org.gradle.plugins.ide.eclipse.model.EclipseJdt)

Example 2 with EclipseJdt

use of org.gradle.plugins.ide.eclipse.model.EclipseJdt in project gradle by gradle.

the class EclipsePlugin method configureEclipseJdt.

private void configureEclipseJdt(final Project project, final EclipseModel model) {
    final EclipsePlugin eclipsePlugin = this;
    project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {

        @Override
        public void execute(JavaBasePlugin javaBasePlugin) {
            maybeAddTask(project, eclipsePlugin, ECLIPSE_JDT_TASK_NAME, GenerateEclipseJdt.class, new Action<GenerateEclipseJdt>() {

                @Override
                public void execute(GenerateEclipseJdt task) {
                    // task properties:
                    task.setDescription("Generates the Eclipse JDT settings file.");
                    task.setOutputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
                    task.setInputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
                    // model properties:
                    EclipseJdt jdt = task.getJdt();
                    model.setJdt(jdt);
                    ConventionMapping conventionMapping = ((IConventionAware) jdt).getConventionMapping();
                    conventionMapping.map("sourceCompatibility", new Callable<JavaVersion>() {

                        @Override
                        public JavaVersion call() {
                            return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility();
                        }
                    });
                    conventionMapping.map("targetCompatibility", new Callable<JavaVersion>() {

                        @Override
                        public JavaVersion call() {
                            return project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility();
                        }
                    });
                    conventionMapping.map("javaRuntimeName", new Callable<String>() {

                        @Override
                        public String call() {
                            return eclipseJavaRuntimeNameFor(project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility());
                        }
                    });
                }
            });
        }
    });
}
Also used : EclipseJdt(org.gradle.plugins.ide.eclipse.model.EclipseJdt) Action(org.gradle.api.Action) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) IConventionAware(org.gradle.api.internal.IConventionAware)

Example 3 with EclipseJdt

use of org.gradle.plugins.ide.eclipse.model.EclipseJdt in project gradle by gradle.

the class EclipseModelBuilder method populate.

private void populate(Project project) {
    EclipseModel eclipseModel = project.getExtensions().getByType(EclipseModel.class);
    EclipseClasspath eclipseClasspath = eclipseModel.getClasspath();
    eclipseClasspath.setProjectDependenciesOnly(projectDependenciesOnly);
    List<ClasspathEntry> classpathEntries;
    if (eclipseClasspath.getFile() == null) {
        classpathEntries = eclipseClasspath.resolveDependencies();
    } else {
        Classpath classpath = new Classpath(eclipseClasspath.getFileReferenceFactory());
        eclipseClasspath.mergeXmlClasspath(classpath);
        classpathEntries = classpath.getEntries();
    }
    final List<DefaultEclipseExternalDependency> externalDependencies = new LinkedList<DefaultEclipseExternalDependency>();
    final List<DefaultEclipseProjectDependency> projectDependencies = new LinkedList<DefaultEclipseProjectDependency>();
    final List<DefaultEclipseSourceDirectory> sourceDirectories = new LinkedList<DefaultEclipseSourceDirectory>();
    final List<DefaultEclipseClasspathContainer> classpathContainers = new LinkedList<DefaultEclipseClasspathContainer>();
    DefaultEclipseOutputLocation outputLocation = null;
    for (ClasspathEntry entry : classpathEntries) {
        // and it would probably push us to add support in the tooling api to retrieve the variable mappings.
        if (entry instanceof Library) {
            AbstractLibrary library = (AbstractLibrary) entry;
            final File file = library.getLibrary().getFile();
            final File source = library.getSourcePath() == null ? null : library.getSourcePath().getFile();
            final File javadoc = library.getJavadocPath() == null ? null : library.getJavadocPath().getFile();
            DefaultEclipseExternalDependency dependency = new DefaultEclipseExternalDependency(file, javadoc, source, library.getModuleVersion(), library.isExported(), createAttributes(library), createAccessRules(library));
            externalDependencies.add(dependency);
        } else if (entry instanceof ProjectDependency) {
            final ProjectDependency projectDependency = (ProjectDependency) entry;
            // By removing the leading "/", this is no longer a "path" as defined by Eclipse
            final String path = StringUtils.removeStart(projectDependency.getPath(), "/");
            DefaultEclipseProjectDependency dependency = new DefaultEclipseProjectDependency(path, projectDependency.isExported(), createAttributes(projectDependency), createAccessRules(projectDependency));
            // Find the EclipseProject model, if it's in the same build. May be null for a composite.
            dependency.setTargetProject(findEclipseProjectByName(path));
            projectDependencies.add(dependency);
        } else if (entry instanceof SourceFolder) {
            final SourceFolder sourceFolder = (SourceFolder) entry;
            String path = sourceFolder.getPath();
            List<String> excludes = sourceFolder.getExcludes();
            List<String> includes = sourceFolder.getIncludes();
            String output = sourceFolder.getOutput();
            sourceDirectories.add(new DefaultEclipseSourceDirectory(path, sourceFolder.getDir(), excludes, includes, output, createAttributes(sourceFolder), createAccessRules(sourceFolder)));
        } else if (entry instanceof Container) {
            final Container container = (Container) entry;
            classpathContainers.add(new DefaultEclipseClasspathContainer(container.getPath(), container.isExported(), createAttributes(container), createAccessRules(container)));
        } else if (entry instanceof Output) {
            outputLocation = new DefaultEclipseOutputLocation(((Output) entry).getPath());
        }
    }
    DefaultEclipseProject eclipseProject = findEclipseProject(project);
    eclipseProject.setClasspath(externalDependencies);
    eclipseProject.setProjectDependencies(projectDependencies);
    eclipseProject.setSourceDirectories(sourceDirectories);
    List<DefaultEclipseLinkedResource> linkedResources = new LinkedList<DefaultEclipseLinkedResource>();
    for (Link r : eclipseModel.getProject().getLinkedResources()) {
        linkedResources.add(new DefaultEclipseLinkedResource(r.getName(), r.getType(), r.getLocation(), r.getLocationUri()));
    }
    eclipseProject.setLinkedResources(linkedResources);
    List<DefaultEclipseTask> tasks = new ArrayList<DefaultEclipseTask>();
    for (Task t : tasksFactory.getTasks(project)) {
        tasks.add(new DefaultEclipseTask(eclipseProject, t.getPath(), t.getName(), t.getDescription()));
    }
    eclipseProject.setTasks(tasks);
    List<DefaultEclipseProjectNature> natures = new ArrayList<DefaultEclipseProjectNature>();
    for (String n : eclipseModel.getProject().getNatures()) {
        natures.add(new DefaultEclipseProjectNature(n));
    }
    eclipseProject.setProjectNatures(natures);
    List<DefaultEclipseBuildCommand> buildCommands = new ArrayList<DefaultEclipseBuildCommand>();
    for (BuildCommand b : eclipseModel.getProject().getBuildCommands()) {
        Map<String, String> arguments = Maps.newLinkedHashMap();
        for (Map.Entry<String, String> entry : b.getArguments().entrySet()) {
            arguments.put(convertGString(entry.getKey()), convertGString(entry.getValue()));
        }
        buildCommands.add(new DefaultEclipseBuildCommand(b.getName(), arguments));
    }
    eclipseProject.setBuildCommands(buildCommands);
    EclipseJdt jdt = eclipseModel.getJdt();
    if (jdt != null) {
        eclipseProject.setJavaSourceSettings(new DefaultEclipseJavaSourceSettings().setSourceLanguageLevel(jdt.getSourceCompatibility()).setTargetBytecodeVersion(jdt.getTargetCompatibility()).setJdk(DefaultInstalledJdk.current()));
    }
    eclipseProject.setClasspathContainers(classpathContainers);
    eclipseProject.setOutputLocation(outputLocation != null ? outputLocation : new DefaultEclipseOutputLocation("bin"));
    for (Project childProject : project.getChildProjects().values()) {
        populate(childProject);
    }
}
Also used : DefaultEclipseLinkedResource(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseLinkedResource) EclipseJdt(org.gradle.plugins.ide.eclipse.model.EclipseJdt) Task(org.gradle.api.Task) DefaultEclipseTask(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseTask) ArrayList(java.util.ArrayList) DefaultEclipseSourceDirectory(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseSourceDirectory) DefaultEclipseProjectNature(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseProjectNature) Container(org.gradle.plugins.ide.eclipse.model.Container) DefaultEclipseClasspathContainer(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseClasspathContainer) EclipseClasspath(org.gradle.plugins.ide.eclipse.model.EclipseClasspath) Classpath(org.gradle.plugins.ide.eclipse.model.Classpath) Output(org.gradle.plugins.ide.eclipse.model.Output) DefaultEclipseTask(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseTask) EclipseModel(org.gradle.plugins.ide.eclipse.model.EclipseModel) AbstractLibrary(org.gradle.plugins.ide.eclipse.model.AbstractLibrary) AbstractClasspathEntry(org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) ClasspathEntry(org.gradle.plugins.ide.eclipse.model.ClasspathEntry) DefaultEclipseExternalDependency(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseExternalDependency) EclipseClasspath(org.gradle.plugins.ide.eclipse.model.EclipseClasspath) DefaultEclipseProjectDependency(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseProjectDependency) ProjectDependency(org.gradle.plugins.ide.eclipse.model.ProjectDependency) DefaultEclipseClasspathContainer(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseClasspathContainer) LinkedList(java.util.LinkedList) SourceFolder(org.gradle.plugins.ide.eclipse.model.SourceFolder) DefaultEclipseJavaSourceSettings(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseJavaSourceSettings) DefaultGradleProject(org.gradle.tooling.internal.gradle.DefaultGradleProject) Project(org.gradle.api.Project) DefaultEclipseProject(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseProject) DefaultEclipseProjectDependency(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseProjectDependency) DefaultEclipseOutputLocation(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseOutputLocation) DefaultEclipseBuildCommand(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseBuildCommand) BuildCommand(org.gradle.plugins.ide.eclipse.model.BuildCommand) Library(org.gradle.plugins.ide.eclipse.model.Library) AbstractLibrary(org.gradle.plugins.ide.eclipse.model.AbstractLibrary) DefaultEclipseBuildCommand(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseBuildCommand) File(java.io.File) Map(java.util.Map) DefaultEclipseProject(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseProject) Link(org.gradle.plugins.ide.eclipse.model.Link)

Aggregations

EclipseJdt (org.gradle.plugins.ide.eclipse.model.EclipseJdt)3 File (java.io.File)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Action (org.gradle.api.Action)1 JavaVersion (org.gradle.api.JavaVersion)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 IConventionAware (org.gradle.api.internal.IConventionAware)1 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)1 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)1 AbstractClasspathEntry (org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry)1 AbstractLibrary (org.gradle.plugins.ide.eclipse.model.AbstractLibrary)1 BuildCommand (org.gradle.plugins.ide.eclipse.model.BuildCommand)1 Classpath (org.gradle.plugins.ide.eclipse.model.Classpath)1 ClasspathEntry (org.gradle.plugins.ide.eclipse.model.ClasspathEntry)1 Container (org.gradle.plugins.ide.eclipse.model.Container)1 EclipseClasspath (org.gradle.plugins.ide.eclipse.model.EclipseClasspath)1