You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@netbeans.apache.org by GitBox <gi...@apache.org> on 2017/11/08 14:36:47 UTC

[GitHub] JaroslavTulach closed pull request #256: NETBEANS-127 use path to relativize file to root folder instead of regexp

JaroslavTulach closed pull request #256: NETBEANS-127 use path to relativize file to root folder instead of regexp
URL: https://github.com/apache/incubator-netbeans/pull/256
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/RatReportTask.java b/nbbuild/antsrc/org/netbeans/nbbuild/RatReportTask.java
index 72b6b28a0..350757bfb 100644
--- a/nbbuild/antsrc/org/netbeans/nbbuild/RatReportTask.java
+++ b/nbbuild/antsrc/org/netbeans/nbbuild/RatReportTask.java
@@ -21,11 +21,11 @@
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -34,8 +34,6 @@
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -129,7 +127,7 @@ public void execute() throws BuildException {
                 simplfiedKey = simplfiedKey.replaceAll(".dir", "");
                 simplfiedKey = simplfiedKey.replaceAll(".depends", "");
                 clusterList.add(simplfiedKey);
-                modulebycluster.put(simplfiedKey, new HashSet<String>());
+                modulebycluster.put(simplfiedKey, new HashSet<>());
             }
         }
         for (String clusterName : clusterList) {
@@ -212,7 +210,7 @@ private static String writeFiles(Set<String> listFile, String repo) {
     private void doPopulateUnapproved(Map<String, ModuleInfo> moduleRATInfo, Element rootElement, XPath path) throws XPathExpressionException {
         NodeList evaluate = (NodeList) path.evaluate("descendant::resource[license-approval/@name=\"false\"]", rootElement, XPathConstants.NODESET);
         for (int i = 0; i < evaluate.getLength(); i++) {
-            String resources = evaluate.item(i).getAttributes().getNamedItem("name").getTextContent().replaceFirst(root.getPath() + File.separator, "");
+            String resources = relativize(evaluate.item(i).getAttributes().getNamedItem("name").getTextContent());
             String moduleName = getModuleName(resources);
             if (!moduleRATInfo.containsKey(moduleName)) {
                 moduleRATInfo.get(NOT_CLUSTER).addUnapproved(resources);
@@ -225,7 +223,7 @@ private void doPopulateUnapproved(Map<String, ModuleInfo> moduleRATInfo, Element
     private void doPopulateApproved(Map<String, ModuleInfo> moduleRATInfo, Element rootElement, XPath path) throws XPathExpressionException {
         NodeList evaluate = (NodeList) path.evaluate("descendant::resource[license-approval/@name=\"true\"]", rootElement, XPathConstants.NODESET);
         for (int i = 0; i < evaluate.getLength(); i++) {
-            String resources = evaluate.item(i).getAttributes().getNamedItem("name").getTextContent().replaceFirst(root.getPath() + File.separator, "");
+            String resources = relativize(evaluate.item(i).getAttributes().getNamedItem("name").getTextContent());
             String moduleName = getModuleName(resources);
             if (!moduleRATInfo.containsKey(moduleName)) {
                 moduleRATInfo.get(NOT_CLUSTER).addApproved(resources);
@@ -236,6 +234,12 @@ private void doPopulateApproved(Map<String, ModuleInfo> moduleRATInfo, Element r
         }
     }
 
+    private String relativize(String target) {
+        Path full = Paths.get(target);
+        Path rootPath = root.toPath();
+        return rootPath.relativize(full).toString();
+    }
+
     private String getModuleName(String resource) {
         String moduleName;
         if (!resource.contains(File.separator)) {


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services