You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@htrace.apache.org by cm...@apache.org on 2014/12/31 01:12:29 UTC

incubator-htrace git commit: HTRACE-35. bundler: support nested js and html files (cmccabe)

Repository: incubator-htrace
Updated Branches:
  refs/heads/master 6b36b1aa6 -> a303830fc


HTRACE-35. bundler: support nested js and html files (cmccabe)


Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/a303830f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/a303830f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/a303830f

Branch: refs/heads/master
Commit: a303830fc0a97e2a5ef1fb30a3e5cd318b65ef3e
Parents: 6b36b1a
Author: Colin P. Mccabe <cm...@apache.org>
Authored: Tue Dec 30 14:36:00 2014 -0800
Committer: Colin P. Mccabe <cm...@apache.org>
Committed: Tue Dec 30 16:10:42 2014 -0800

----------------------------------------------------------------------
 .../go/src/org/apache/htrace/bundler/bundler.go | 63 +++++++++++++-------
 .../go/src/org/apache/htrace/htraced/rest.go    |  6 +-
 htrace-core/src/web/index.html                  |  4 +-
 htrace-core/src/web/nested/nested.html          | 24 ++++++++
 4 files changed, 73 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/a303830f/htrace-core/src/go/src/org/apache/htrace/bundler/bundler.go
----------------------------------------------------------------------
diff --git a/htrace-core/src/go/src/org/apache/htrace/bundler/bundler.go b/htrace-core/src/go/src/org/apache/htrace/bundler/bundler.go
index 7e6f542..9a71eed 100644
--- a/htrace-core/src/go/src/org/apache/htrace/bundler/bundler.go
+++ b/htrace-core/src/go/src/org/apache/htrace/bundler/bundler.go
@@ -32,6 +32,7 @@ import (
 	"io/ioutil"
 	"log"
 	"os"
+	"path/filepath"
 	"strings"
 )
 
@@ -57,6 +58,8 @@ const APACHE_HEADER = `/*
 
 const GENERATED_CODE_COMMENT = "// THIS IS GENERATED CODE.  DO NOT EDIT."
 
+var SEP string = string(os.PathSeparator)
+
 // Return true if a file contains a given string.
 func fileContainsString(path, line string) (bool, error) {
 	file, err := os.Open(path)
@@ -76,12 +79,17 @@ func fileContainsString(path, line string) (bool, error) {
 	return false, nil
 }
 
+// Converts a source file path to a destination file path
+func sfileToDfile(sfile string) string {
+	return strings.Replace(sfile, SEP, "__", -1) + ".go"
+}
+
 // Delete generated files that are in dfiles but not sfiles.
 // sfiles and dfiles must be sorted by file name.
-func deleteUnusedDst(sfiles []os.FileInfo, dst string, dfiles []os.FileInfo) error {
+func deleteUnusedDst(sfiles []string, dst string, dfiles []os.FileInfo) error {
 	s := 0
 	for d := range dfiles {
-		fullDst := dst + string(os.PathSeparator) + dfiles[d].Name()
+		fullDst := dst + SEP + dfiles[d].Name()
 		generated, err := fileContainsString(fullDst, GENERATED_CODE_COMMENT)
 		if err != nil {
 			return err
@@ -95,11 +103,12 @@ func deleteUnusedDst(sfiles []os.FileInfo, dst string, dfiles []os.FileInfo) err
 			if s >= len(sfiles) {
 				break
 			}
-			if sfiles[s].Name()+".go" == dfiles[d].Name() {
+			tgt := sfileToDfile(sfiles[s])
+			if tgt == dfiles[d].Name() {
 				found = true
 				break
 			}
-			if sfiles[s].Name()+".go" > dfiles[d].Name() {
+			if tgt > dfiles[d].Name() {
 				break
 			}
 			s++
@@ -115,17 +124,10 @@ func deleteUnusedDst(sfiles []os.FileInfo, dst string, dfiles []os.FileInfo) err
 	return nil
 }
 
-func stripSuffixes(str string) string {
-	idx := strings.Index(str, ".")
-	if idx < 0 {
-		return str
-	}
-	return str[0:idx]
-}
-
-func createBundleFile(pkg, src, sfile, tdir string) error {
+func createBundleFile(pkg, src, sfile, dst string) error {
 	// Open destination file and write header.
-	fullDst := tdir + string(os.PathSeparator) + sfile + ".go"
+	tgt := sfileToDfile(sfile)
+	fullDst := dst + SEP + tgt
 	out, err := os.Create(fullDst)
 	if err != nil {
 		return err
@@ -143,13 +145,13 @@ func createBundleFile(pkg, src, sfile, tdir string) error {
 	if err != nil {
 		return err
 	}
-	_, err = out.WriteString(fmt.Sprintf("var _ = addResource(\"/%s\", `\n", stripSuffixes(sfile)))
+	_, err = out.WriteString(fmt.Sprintf("var _ = addResource(\"%s\", `\n", tgt[:len(tgt)-3]))
 	if err != nil {
 		return err
 	}
 
 	// Open source file and create scanner.
-	fullSrc := src + string(os.PathSeparator) + sfile
+	fullSrc := src + SEP + sfile
 	in, err := os.Open(fullSrc)
 	if err != nil {
 		return err
@@ -186,9 +188,28 @@ func main() {
 	if *dst == "" {
 		log.Fatal("You must supply a dst directory for output.")
 	}
-	sfiles, err := ioutil.ReadDir(*src)
+	sfiles := make([]string, 0, 32)
+	absSrc, err := filepath.Abs(filepath.Clean(*src))
+	if err != nil {
+		log.Fatalf("Error getting absolute path for %s: %s\n", *src, err.Error())
+	}
+	err = filepath.Walk(absSrc, func(path string, info os.FileInfo, err error) error {
+		if err != nil {
+			return err
+		}
+		if info.IsDir() {
+			return nil
+		}
+		var suffix string
+		suffix, err = filepath.Rel(absSrc, path)
+		if err != nil {
+			return err
+		}
+		sfiles = append(sfiles, suffix)
+		return nil
+	})
 	if err != nil {
-		log.Fatal("Error listing files in src directory %s: %s\n", *src, err.Error())
+		log.Fatal("Error listing files in src directory %s: %s\n", absSrc, err.Error())
 	}
 	var dfiles []os.FileInfo
 	dfiles, err = ioutil.ReadDir(*dst)
@@ -197,11 +218,11 @@ func main() {
 	}
 	deleteUnusedDst(sfiles, *dst, dfiles)
 	for s := range sfiles {
-		err = createBundleFile(*pkg, *src, sfiles[s].Name(), *dst)
+		err = createBundleFile(*pkg, absSrc, sfiles[s], *dst)
 		if err != nil {
-			log.Fatal("Error creating bundle file for %s in %s: %s\n",
+			log.Fatalf("Error creating bundle file for %s in %s: %s\n",
 				sfiles[s], *dst, err.Error())
 		}
-		log.Printf("Bundled %s\n", *dst+string(os.PathSeparator)+sfiles[s].Name())
+		log.Printf("Bundled %s as %s\n", absSrc, absSrc + SEP + sfileToDfile(sfiles[s]))
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/a303830f/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go
----------------------------------------------------------------------
diff --git a/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go b/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go
index 5b97313..b704bd2 100644
--- a/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go
+++ b/htrace-core/src/go/src/org/apache/htrace/htraced/rest.go
@@ -27,6 +27,7 @@ import (
 	"org/apache/htrace/conf"
 	"org/apache/htrace/resource"
 	"strconv"
+	"strings"
 )
 
 type serverInfoHandler struct {
@@ -130,8 +131,11 @@ type defaultServeHandler struct {
 }
 
 func (hand *defaultServeHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
-	rsc := resource.Catalog[req.URL.Path]
+	ident := strings.TrimLeft(req.URL.Path, "/")
+	ident = strings.Replace(ident, "/", "__", -1)
+	rsc := resource.Catalog[ident]
 	if rsc == "" {
+		log.Printf("failed to find entry for %s\n", ident)
 		w.WriteHeader(http.StatusNotFound)
 		return
 	}

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/a303830f/htrace-core/src/web/index.html
----------------------------------------------------------------------
diff --git a/htrace-core/src/web/index.html b/htrace-core/src/web/index.html
index 1cab08b..cc73492 100644
--- a/htrace-core/src/web/index.html
+++ b/htrace-core/src/web/index.html
@@ -1,3 +1,5 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -14,8 +16,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 -->
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <body>
 <head><title>HTRACE</title></head>

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/a303830f/htrace-core/src/web/nested/nested.html
----------------------------------------------------------------------
diff --git a/htrace-core/src/web/nested/nested.html b/htrace-core/src/web/nested/nested.html
new file mode 100644
index 0000000..18fa410
--- /dev/null
+++ b/htrace-core/src/web/nested/nested.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+   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.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml">
+<body>
+<head><title>HTRACE</title></head>
+Nested world.<p/>
+</body>
+</html>