Search in sources :

Example 1 with Container

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

the class ClasspathFactory method createContainers.

private List<ClasspathEntry> createContainers() {
    List<ClasspathEntry> containers = Lists.newArrayList();
    for (String container : classpath.getContainers()) {
        Container entry = new Container(container);
        containers.add(entry);
    }
    return containers;
}
Also used : Container(org.gradle.plugins.ide.eclipse.model.Container) AbstractClasspathEntry(org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) ClasspathEntry(org.gradle.plugins.ide.eclipse.model.ClasspathEntry)

Example 2 with Container

use of org.gradle.plugins.ide.eclipse.model.Container 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

AbstractClasspathEntry (org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry)2 ClasspathEntry (org.gradle.plugins.ide.eclipse.model.ClasspathEntry)2 Container (org.gradle.plugins.ide.eclipse.model.Container)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)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 EclipseClasspath (org.gradle.plugins.ide.eclipse.model.EclipseClasspath)1 EclipseJdt (org.gradle.plugins.ide.eclipse.model.EclipseJdt)1 EclipseModel (org.gradle.plugins.ide.eclipse.model.EclipseModel)1 Library (org.gradle.plugins.ide.eclipse.model.Library)1 Link (org.gradle.plugins.ide.eclipse.model.Link)1 Output (org.gradle.plugins.ide.eclipse.model.Output)1 ProjectDependency (org.gradle.plugins.ide.eclipse.model.ProjectDependency)1 SourceFolder (org.gradle.plugins.ide.eclipse.model.SourceFolder)1