Search in sources :

Example 1 with SourceFolder

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

the class SourceFoldersCreator method trimAndDedup.

private List<SourceFolder> trimAndDedup(List<SourceFolder> externalSourceFolders, List<String> givenSources) {
    // externals are mapped to linked resources so we just need a name of the resource, without full path
    // non unique folder names are naively deduped by adding parent filename as a prefix till unique
    // since this seems like a rare edge case this simple approach should be enough
    List<SourceFolder> trimmedSourceFolders = Lists.newArrayList();
    for (SourceFolder folder : externalSourceFolders) {
        folder.trim();
        File parentFile = folder.getDir().getParentFile();
        while (givenSources.contains(folder.getName()) && parentFile != null) {
            folder.trim(parentFile.getName());
            parentFile = parentFile.getParentFile();
        }
        givenSources.add(folder.getName());
        trimmedSourceFolders.add(folder);
    }
    return trimmedSourceFolders;
}
Also used : SourceFolder(org.gradle.plugins.ide.eclipse.model.SourceFolder) File(java.io.File)

Example 2 with SourceFolder

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

the class SourceFoldersCreator method basicProjectRelativeFolders.

private List<SourceFolder> basicProjectRelativeFolders(Iterable<SourceSet> sourceSets, Function<File, String> provideRelativePath, File defaultOutputDir) {
    ArrayList<SourceFolder> entries = Lists.newArrayList();
    List<SourceSet> sortedSourceSets = sortSourceSetsAsPerUsualConvention(sourceSets);
    for (SourceSet sourceSet : sortedSourceSets) {
        List<DirectoryTree> sortedSourceDirs = sortSourceDirsAsPerUsualConvention(sourceSet.getAllSource().getSrcDirTrees());
        for (DirectoryTree tree : sortedSourceDirs) {
            File dir = tree.getDir();
            if (dir.isDirectory()) {
                SourceFolder folder = new SourceFolder(provideRelativePath.apply(dir), null);
                folder.setDir(dir);
                folder.setName(dir.getName());
                entries.add(folder);
            }
        }
    }
    return entries;
}
Also used : SourceFolder(org.gradle.plugins.ide.eclipse.model.SourceFolder) SourceSet(org.gradle.api.tasks.SourceSet) DirectoryTree(org.gradle.api.file.DirectoryTree) File(java.io.File)

Example 3 with SourceFolder

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

the class SourceFoldersCreator method trimAndDedup.

private List<SourceFolder> trimAndDedup(Collection<SourceFolder> externalSourceFolders, List<String> givenSources) {
    // externals are mapped to linked resources so we just need a name of the resource, without full path
    // non unique folder names are naively deduped by adding parent filename as a prefix till unique
    // since this seems like a rare edge case this simple approach should be enough
    List<SourceFolder> trimmedSourceFolders = Lists.newArrayList();
    for (SourceFolder folder : externalSourceFolders) {
        folder.trim();
        File parentFile = folder.getDir().getParentFile();
        while (givenSources.contains(folder.getName()) && parentFile != null) {
            folder.trim(parentFile.getName());
            parentFile = parentFile.getParentFile();
        }
        givenSources.add(folder.getName());
        trimmedSourceFolders.add(folder);
    }
    return trimmedSourceFolders;
}
Also used : SourceFolder(org.gradle.plugins.ide.eclipse.model.SourceFolder) File(java.io.File)

Example 4 with SourceFolder

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

the class EclipseModelBuilder method gatherClasspathElements.

public static ClasspathElements gatherClasspathElements(Map<String, Boolean> projectOpenStatus, EclipseClasspath eclipseClasspath, boolean projectDependenciesOnly) {
    ClasspathElements classpathElements = new ClasspathElements();
    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 Map<String, DefaultEclipseProjectDependency> projectDependencyMap = new HashMap<>();
    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;
            if (entry instanceof UnresolvedLibrary) {
                UnresolvedLibrary unresolvedLibrary = (UnresolvedLibrary) entry;
                dependency = DefaultEclipseExternalDependency.createUnresolved(file, javadoc, source, library.getModuleVersion(), library.isExported(), createAttributes(library), createAccessRules(library), unresolvedLibrary.getAttemptedSelector().getDisplayName());
            } else {
                dependency = DefaultEclipseExternalDependency.createResolved(file, javadoc, source, library.getModuleVersion(), library.isExported(), createAttributes(library), createAccessRules(library));
            }
            classpathElements.getExternalDependencies().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(), "/");
            boolean isProjectOpen = projectOpenStatus.getOrDefault(path, true);
            if (!isProjectOpen) {
                final File source = projectDependency.getPublicationSourcePath() == null ? null : projectDependency.getPublicationSourcePath().getFile();
                final File javadoc = projectDependency.getPublicationJavadocPath() == null ? null : projectDependency.getPublicationJavadocPath().getFile();
                classpathElements.getExternalDependencies().add(DefaultEclipseExternalDependency.createResolved(projectDependency.getPublication().getFile(), javadoc, source, null, projectDependency.isExported(), createAttributes(projectDependency), createAccessRules(projectDependency)));
                classpathElements.getBuildDependencies().add(projectDependency.getBuildDependencies());
            } else {
                projectDependencyMap.put(path, new DefaultEclipseProjectDependency(path, projectDependency.isExported(), createAttributes(projectDependency), createAccessRules(projectDependency)));
            }
        } 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();
            classpathElements.getSourceDirectories().add(new DefaultEclipseSourceDirectory(path, sourceFolder.getDir(), excludes, includes, output, createAttributes(sourceFolder), createAccessRules(sourceFolder)));
        } else if (entry instanceof Container) {
            final Container container = (Container) entry;
            classpathElements.getClasspathContainers().add(new DefaultEclipseClasspathContainer(container.getPath(), container.isExported(), createAttributes(container), createAccessRules(container)));
        } else if (entry instanceof Output) {
            classpathElements.setEclipseOutputLocation(new DefaultEclipseOutputLocation(((Output) entry).getPath()));
        }
    }
    classpathElements.getProjectDependencies().addAll(projectDependencyMap.values());
    return classpathElements;
}
Also used : HashMap(java.util.HashMap) 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) DefaultEclipseSourceDirectory(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseSourceDirectory) SourceFolder(org.gradle.plugins.ide.eclipse.model.SourceFolder) DefaultEclipseProjectDependency(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseProjectDependency) UnresolvedLibrary(org.gradle.plugins.ide.eclipse.model.UnresolvedLibrary) Container(org.gradle.plugins.ide.eclipse.model.Container) DefaultEclipseClasspathContainer(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseClasspathContainer) DefaultEclipseOutputLocation(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseOutputLocation) EclipseClasspath(org.gradle.plugins.ide.eclipse.model.EclipseClasspath) Classpath(org.gradle.plugins.ide.eclipse.model.Classpath) Output(org.gradle.plugins.ide.eclipse.model.Output) AbstractLibrary(org.gradle.plugins.ide.eclipse.model.AbstractLibrary) Library(org.gradle.plugins.ide.eclipse.model.Library) AbstractLibrary(org.gradle.plugins.ide.eclipse.model.AbstractLibrary) UnresolvedLibrary(org.gradle.plugins.ide.eclipse.model.UnresolvedLibrary) AbstractClasspathEntry(org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry) ClasspathEntry(org.gradle.plugins.ide.eclipse.model.ClasspathEntry) File(java.io.File) DefaultEclipseExternalDependency(org.gradle.plugins.ide.internal.tooling.eclipse.DefaultEclipseExternalDependency)

Example 5 with SourceFolder

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

the class SourceFoldersCreator method projectRelativeFolders.

private List<SourceFolder> projectRelativeFolders(Iterable<SourceSet> sourceSets, Function<File, String> provideRelativePath) {
    ArrayList<SourceFolder> entries = Lists.newArrayList();
    List<SourceSet> sortedSourceSets = sortSourceSetsAsPerUsualConvention(sourceSets);
    for (SourceSet sourceSet : sortedSourceSets) {
        List<DirectoryTree> sortedSourceDirs = sortSourceDirsAsPerUsualConvention(sourceSet.getAllSource().getSrcDirTrees());
        for (DirectoryTree tree : sortedSourceDirs) {
            File dir = tree.getDir();
            if (dir.isDirectory()) {
                String relativePath = provideRelativePath.apply(dir);
                SourceFolder folder = new SourceFolder(relativePath, null);
                folder.setDir(dir);
                folder.setName(dir.getName());
                folder.setIncludes(getIncludesForTree(sourceSet, tree));
                folder.setExcludes(getExcludesForTree(sourceSet, tree));
                entries.add(folder);
            }
        }
    }
    return entries;
}
Also used : SourceFolder(org.gradle.plugins.ide.eclipse.model.SourceFolder) SourceSet(org.gradle.api.tasks.SourceSet) DirectoryTree(org.gradle.api.file.DirectoryTree) File(java.io.File)

Aggregations

File (java.io.File)8 SourceFolder (org.gradle.plugins.ide.eclipse.model.SourceFolder)8 DirectoryTree (org.gradle.api.file.DirectoryTree)4 SourceSet (org.gradle.api.tasks.SourceSet)4 EclipseClasspath (org.gradle.plugins.ide.eclipse.model.EclipseClasspath)2 HashMap (java.util.HashMap)1 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)1 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)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 ClasspathEntry (org.gradle.plugins.ide.eclipse.model.ClasspathEntry)1 Container (org.gradle.plugins.ide.eclipse.model.Container)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 UnresolvedLibrary (org.gradle.plugins.ide.eclipse.model.UnresolvedLibrary)1 SourceFoldersCreator (org.gradle.plugins.ide.eclipse.model.internal.SourceFoldersCreator)1