Search in sources :

Example 1 with BuildCommand

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

the class EclipsePlugin method configureEclipseProject.

private void configureEclipseProject(final Project project, final EclipseModel model) {
    maybeAddTask(project, this, ECLIPSE_PROJECT_TASK_NAME, GenerateEclipseProject.class, new Action<GenerateEclipseProject>() {

        @Override
        public void execute(GenerateEclipseProject task) {
            final EclipseProject projectModel = task.getProjectModel();
            //task properties:
            task.setDescription("Generates the Eclipse project file.");
            task.setInputFile(project.file(".project"));
            task.setOutputFile(project.file(".project"));
            //model:
            model.setProject(projectModel);
            projectModel.setName(project.getName());
            final ConventionMapping convention = ((IConventionAware) projectModel).getConventionMapping();
            convention.map("comment", new Callable<String>() {

                @Override
                public String call() {
                    return project.getDescription();
                }
            });
            project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {

                @Override
                public void execute(JavaBasePlugin javaBasePlugin) {
                    if (!project.getPlugins().hasPlugin(EarPlugin.class)) {
                        projectModel.buildCommand("org.eclipse.jdt.core.javabuilder");
                    }
                    projectModel.natures("org.eclipse.jdt.core.javanature");
                    convention.map("linkedResources", new Callable<Set<Link>>() {

                        @Override
                        public Set<Link> call() {
                            return new LinkedResourcesCreator().links(project);
                        }
                    });
                }
            });
            project.getPlugins().withType(GroovyBasePlugin.class, new Action<GroovyBasePlugin>() {

                @Override
                public void execute(GroovyBasePlugin groovyBasePlugin) {
                    projectModel.getNatures().add(projectModel.getNatures().indexOf("org.eclipse.jdt.core.javanature"), "org.eclipse.jdt.groovy.core.groovyNature");
                }
            });
            project.getPlugins().withType(ScalaBasePlugin.class, new Action<ScalaBasePlugin>() {

                @Override
                public void execute(ScalaBasePlugin scalaBasePlugin) {
                    projectModel.getBuildCommands().set(Iterables.indexOf(projectModel.getBuildCommands(), new Predicate<BuildCommand>() {

                        @Override
                        public boolean apply(BuildCommand buildCommand) {
                            return buildCommand.getName().equals("org.eclipse.jdt.core.javabuilder");
                        }
                    }), new BuildCommand("org.scala-ide.sdt.core.scalabuilder"));
                    projectModel.getNatures().add(projectModel.getNatures().indexOf("org.eclipse.jdt.core.javanature"), "org.scala-ide.sdt.core.scalanature");
                }
            });
        }
    });
}
Also used : EclipseProject(org.gradle.plugins.ide.eclipse.model.EclipseProject) Action(org.gradle.api.Action) Set(java.util.Set) ScalaBasePlugin(org.gradle.api.plugins.scala.ScalaBasePlugin) ConventionMapping(org.gradle.api.internal.ConventionMapping) Callable(java.util.concurrent.Callable) Predicate(com.google.common.base.Predicate) LinkedResourcesCreator(org.gradle.plugins.ide.eclipse.internal.LinkedResourcesCreator) GroovyBasePlugin(org.gradle.api.plugins.GroovyBasePlugin) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) BuildCommand(org.gradle.plugins.ide.eclipse.model.BuildCommand) EarPlugin(org.gradle.plugins.ear.EarPlugin)

Example 2 with BuildCommand

use of org.gradle.plugins.ide.eclipse.model.BuildCommand 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) DefaultEclipseClasspathContainer(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseClasspathContainer) Container(org.gradle.plugins.ide.eclipse.model.Container) 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) ClasspathEntry(org.gradle.plugins.ide.eclipse.model.ClasspathEntry) AbstractClasspathEntry(org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) 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

BuildCommand (org.gradle.plugins.ide.eclipse.model.BuildCommand)2 Predicate (com.google.common.base.Predicate)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Action (org.gradle.api.Action)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 GroovyBasePlugin (org.gradle.api.plugins.GroovyBasePlugin)1 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)1 ScalaBasePlugin (org.gradle.api.plugins.scala.ScalaBasePlugin)1 EarPlugin (org.gradle.plugins.ear.EarPlugin)1 LinkedResourcesCreator (org.gradle.plugins.ide.eclipse.internal.LinkedResourcesCreator)1 AbstractClasspathEntry (org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry)1 AbstractLibrary (org.gradle.plugins.ide.eclipse.model.AbstractLibrary)1 Classpath (org.gradle.plugins.ide.eclipse.model.Classpath)1