lkishalmi commented on a change in pull request #1077: [NETBEANS-1793] Gradle 
Support
URL: 
https://github.com/apache/incubator-netbeans/pull/1077#discussion_r247305439
 
 

 ##########
 File path: 
groovy/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaSourceSet.java
 ##########
 @@ -0,0 +1,433 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.gradle.java.api;
+
+import org.netbeans.modules.gradle.spi.Utils;
+import java.io.File;
+import java.io.Serializable;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import static org.openide.util.NbBundle.Messages;
+
+public class GradleJavaSourceSet implements Serializable {
+
+    @Messages({
+        "LBL_JAVA=Java",
+        "LBL_GROOVY=Groovy",
+        "LBL_SCALA=Scala",
+        "LBL_RESOURCES=Resources"
+    })
+    public static enum SourceType {
+
+        JAVA, GROOVY, SCALA, RESOURCES;
+
+        @Override
+        public String toString() {
+            switch (this) {
+                case JAVA: return Bundle.LBL_JAVA();
+                case GROOVY: return Bundle.LBL_GROOVY();
+                case SCALA: return Bundle.LBL_SCALA();
+                default: return Bundle.LBL_RESOURCES();
+            }
+        }
+    }
+
+    public static enum ClassPathType {
+
+        COMPILE, RUNTIME
+    }
+
+    public static final String MAIN_SOURCESET_NAME = "main"; //NOI18N
+    public static final String TEST_SOURCESET_NAME = "test"; //NOI18N
+
+    Map<SourceType, Set<File>> sources = new EnumMap<>(SourceType.class);
+    String name;
+    String runtimeConfigurationName;
+    String compileConfigurationName;
+    String sourcesCompatibility = "1.5"; //NOI18N
+    String targetCompatibility = sourcesCompatibility;
+    boolean testSourceSet;
+    Set<File> outputClassDirs;
+    File outputResources;
+    //Add silent support for webapp docroot.
+    File webApp;
+    Set<File> compileClassPath;
+    Set<File> runtimeClassPath;
+    Set<GradleJavaSourceSet> sourceDependencies = Collections.emptySet();
+
+    public GradleJavaSourceSet(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public boolean isTestSourceSet() {
+        return testSourceSet;
+    }
+
+    public String getSourcesCompatibility() {
+        return sourcesCompatibility;
+    }
+
+    public String getTargetCompatibility() {
+        return targetCompatibility;
+    }
+
+    public String getRuntimeConfigurationName() {
+        return runtimeConfigurationName;
+    }
+
+    public String getCompileConfigurationName() {
+        return compileConfigurationName;
+    }
+
+    public Set<File> getSourceDirs(SourceType type) {
+        Set<File> ret = sources.get(type);
+        return ret != null ? ret : Collections.<File>emptySet();
+    }
+
+    public final Set<File> getJavaDirs() {
+        return getSourceDirs(SourceType.JAVA);
+    }
+
+    public final Set<File> getGroovyDirs() {
+        return getSourceDirs(SourceType.GROOVY);
+    }
+
+    public final Set<File> getScalaDirs() {
+        return getSourceDirs(SourceType.SCALA);
+    }
+
+    public final Set<File> getResourcesDirs() {
+        return getSourceDirs(SourceType.RESOURCES);
+    }
+
+    /**
+     * Returns all possible configured source directories regardless
+     * of their existence.
+     *
+     * @param deduplicate 
+     * @return all possible source directories.
+     */
+    public final Collection<File> getAllDirs(boolean deduplicate) {
+        Collection<File> ret = deduplicate ? new HashSet<>() : new 
ArrayList<>();
+        if (sources != null) {
+            for (Set<File> s : sources.values()) {
+                ret.addAll(s);
+            }
+        }
+        return ret;
+    }
+
+    public final Collection<File> getAllDirs() {
+        return getAllDirs(true);
+    }
+
+    /**
+     * Returns all configured and existing source directories.
+     *
+     * @return all existing source directories.
+     */
+    public final Collection<File> getAvailableDirs(boolean deduplicate) {
+        Collection<File> ret = deduplicate ? new HashSet<File>() : new 
ArrayList<File>();
+        if (sources != null) {
+            for (Set<File> s : sources.values()) {
+                for (File f : s) {
+                    if (f.isDirectory()) {
+                        ret.add(f);
+                    }
+                }
+            }
+        }
+        return ret;
+    }
+
+    public final Collection<File> getAvailableDirs() {
+        return getAvailableDirs(true);
+    }
+
+    public Set<File> getCompileClassPath() {
+        return compileClassPath != null ? compileClassPath : 
Collections.<File>emptySet();
+    }
+
+    public Set<File> getRuntimeClassPath() {
+        return runtimeClassPath != null ? runtimeClassPath : 
getCompileClassPath();
+    }
+
+    public SourceType getSourceType(File f) {
+        for (SourceType type : sources.keySet()) {
+            Set<File> dirs = sources.get(type);
+            for (File dir : dirs) {
+                if (parentOrSame(f, dir)) {
+                    return type;
+                }
+            }
+        }
+        return null;
+    }
+
+    public boolean hasOverlappingSourceDirs() {
+        Set<File> check = new HashSet<>();
+        for (SourceType type : SourceType.values()) {
+            for (File f : getSourceDirs(type)) {
+                if (!check.add(f)) return true;
+            }
+        }
+        return false;
+    }
+
+    public Set<SourceType> getSourceTypes(File f) {
+        Set<SourceType> ret = EnumSet.noneOf(SourceType.class);
+        for (SourceType type : sources.keySet()) {
+            Set<File> dirs = sources.get(type);
+            for (File dir : dirs) {
+                if (parentOrSame(f, dir)) {
+                    ret.add(type);
+                }
+            }
+        }
+        return ret;
+    }
+
+    public boolean outputContains(File f) {
+        List<File> checkList = new LinkedList<>(getOutputClassDirs());
+        if (outputResources != null) {
+            checkList.add(outputResources);
+        }
+        for (File check : checkList) {
+            if (parentOrSame(f, check)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public Set<File> getOutputClassDirs() {
+        return outputClassDirs != null ? outputClassDirs : 
Collections.<File>emptySet();
+    }
+
+    /**
+     * Return the directory of resources output.
+     * 
+     * @return return the directory of output resources, it might be 
<code>null</code>.
+     */
+    public File getOutputResources() {
+        return outputResources;
+    }
+
+    /**
+     * Returns those SourceSets within this project which output is on our
+     * compile/runtime classpath. Most common example is: 'test' SourceSet
+     * usually returns the 'main' SourceSet as dependency.
+     *
+     * @return the in project SourceSet dependencies of this SourceSet.
+     */
+    public Set<GradleJavaSourceSet> getSourceDependencies() {
+        return sourceDependencies;
+    }
+
+    /**
+     * Returns {@code true} if the given file belongs either to the sources or
+     * the outputs of this SourceSet. Due to practical consideration if the
+     * project is a war project and this SourceSet is the main SourceSet then
+     * the content of the project 'webapp' folder is also associated with this
+     * SourceSet.
+     *
+     * @param f the file to test
+     * @return {@code true} if the given file can be associated with this
+     *         SourceSet
+     */
+    public boolean contains(File f) {
+        boolean web = (webApp != null) && parentOrSame(f, webApp);
+        return web || outputContains(f) || getSourceType(f) != null;
+    }
+
+    /**
+     * Tries to find a resource given by its relative path name in the
+     * directories associated with this SourceSet. The output directories
+     * are checked before the source ones.
+     * This method returns with the first resource if it is found.
+     *
+     * @param name the name of the resources, use "/" as separator character.
+     * @return the full path of the first resource found or {@code null}
+     *         if no such resource can be associated with this SourceSet.
+     */
+    public File findResource(String name) {
+        return findResource(name, true);
+    }
+
+    /**
+     * Tries to find a resource given by its relative path name in the
+     * directories associated with this SourceSet. The output directories
+     * are checked before the source ones (if they are included).
+     * This method returns with the first resource if it is found.
+     *
+     * @param name the name of the resources, use "/" as separator character.
+     * @param includeOutputs include the outputs (classes and resources) in 
the search
+     * @param types Source types to check, if omitted, all source types will 
be included.
+     * @return the full path of the first resource found or {@code null}
+     *         if no such resource can be associated with this SourceSet.
+     */
+    public File findResource(String name, boolean includeOutputs, 
SourceType... types) {
 
 Review comment:
   As long as Gradle itself works with Files, I see no benefit using FileObject 
abstraction. Path maybe, if Gradle would start to use that.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to