jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1581093 - in /jena/branches/jena-fuseki-new-ui: src-dev/dev/RunFuseki2.java src/main/java/org/apache/jena/fuseki/server/FusekiServer.java src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java src/main/webapp/WEB-INF/web.xml
Date Mon, 24 Mar 2014 22:25:36 GMT
Author: andy
Date: Mon Mar 24 22:25:36 2014
New Revision: 1581093

URL: http://svn.apache.org/r1581093
Log:
Initialize run area.

Modified:
    jena/branches/jena-fuseki-new-ui/src-dev/dev/RunFuseki2.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java
    jena/branches/jena-fuseki-new-ui/src/main/webapp/WEB-INF/web.xml

Modified: jena/branches/jena-fuseki-new-ui/src-dev/dev/RunFuseki2.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src-dev/dev/RunFuseki2.java?rev=1581093&r1=1581092&r2=1581093&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src-dev/dev/RunFuseki2.java (original)
+++ jena/branches/jena-fuseki-new-ui/src-dev/dev/RunFuseki2.java Mon Mar 24 22:25:36 2014
@@ -20,7 +20,6 @@ package dev;
 
 import java.nio.file.Paths ;
 
-import org.apache.jena.atlas.lib.FileOps ;
 import org.apache.jena.fuseki.FusekiCmd ;
 import org.apache.jena.fuseki.server.FusekiServer ;
 
@@ -51,14 +50,10 @@ public class RunFuseki2
     }
     
     private static void main1() {
-        FusekiServer.FUSEKI_HOME = Paths.get(".").toAbsolutePath() ;
+        FusekiServer.FUSEKI_HOME = Paths.get("").toAbsolutePath() ;
         FusekiServer.FUSEKI_BASE = Paths.get("run") ;
         FusekiServer.init() ;
         
-        // Clean server state?
-        if ( true )
-            FileOps.clearDirectory(FusekiServer.dirSystemDatabase.toString()) ; 
-        
         String tmpdir = System.getenv("TMPDIR") ;
         if ( tmpdir == null )
             tmpdir = System.getenv("TMP") ;

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java?rev=1581093&r1=1581092&r2=1581093&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
Mon Mar 24 22:25:36 2014
@@ -134,27 +134,47 @@ public class FusekiServer
         // Copy in defaults?
         Path dirTemplatesMasters = makePath(FUSEKI_HOME, templatesNameBase) ;
         mustExist(dirTemplatesMasters) ;
-
-        ensureDir(FUSEKI_BASE) ;
         
+        if ( Files.isRegularFile(FUSEKI_BASE) ) 
+            throw new FusekiConfigException("FUSEKI_BASE exists but is a file") ;
+        boolean initFusekiBase = ! Files.exists(FUSEKI_BASE) || emptyDir(FUSEKI_BASE) ;
+        
+        ensureDir(FUSEKI_BASE) ;
+
         dirTemplates        = makePath(FUSEKI_BASE, templatesNameBase) ;
-        boolean copyTemplates = ! exists(dirTemplates) ;
         ensureDir(dirTemplates) ; 
 
+        dirDatabases        = makePathEnsureDir(FUSEKI_BASE, databasesLocationBase) ;
         dirBackups          = makePathEnsureDir(FUSEKI_BASE, backupDirNameBase) ;
         dirConfiguration    = makePathEnsureDir(FUSEKI_BASE, configDirNameBase) ;
         dirLogs             = makePathEnsureDir(FUSEKI_BASE, logsNameBase) ;
         dirSystemDatabase   = makePathEnsureDir(FUSEKI_BASE, systemDatabaseNameBase) ;
         dirFileArea         = makePathEnsureDir(FUSEKI_BASE, systemFileAreaBase) ;
         
-        if ( copyTemplates )
+        String dftShiroIniFile = "shiro.ini" ;
+        if ( initFusekiBase ) { 
+            Fuseki.configLog.info("Initializing FUSEKI_BASE") ;
+            copyFile(FUSEKI_HOME.resolve(dftShiroIniFile), FUSEKI_BASE.resolve(dftShiroIniFile))
; 
             copyFileFilter(dirTemplatesMasters, dirTemplates, filterConfig) ;
+        }
+    }
+
+    private static boolean emptyDir(Path dir) {
+        return dir.toFile().list().length <= 2 ;
+    }
+    
+    private static void copyFile(Path src, Path dst) {
+        try {
+            Files.copy(src, dst, StandardCopyOption.COPY_ATTRIBUTES) ;
+        } catch (IOException e) {
+            IO.exception("Failed to copy file "+src, e);
+            e.printStackTrace();
+        }
     }
 
     private static void copyFileFilter(Path srcDir, Path dstDir, FilenameFilter filterConfig)
{
         String[] files = srcDir.toFile().list(filterConfig) ;
-        for ( String fn : files )
-        {
+        for ( String fn : files ) {
             try {
                 Path src = srcDir.resolve(fn) ;
                 Path dst = dstDir.resolve(fn) ;
@@ -282,7 +302,9 @@ public class FusekiServer
     
     // ---- Helpers
 
-    private static void ensureDir(Path directory) {
+    /** Ensure a directory exists, creating it if necessary.
+     */
+    private static void  ensureDir(Path directory) {
         File dir = directory.toFile() ;
         if ( ! dir.exists() )
             dir.mkdirs() ;

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java?rev=1581093&r1=1581092&r2=1581093&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java
Mon Mar 24 22:25:36 2014
@@ -72,6 +72,7 @@ public class ShiroEnvironmentLoader exte
             ResourceBasedWebEnvironment env = (ResourceBasedWebEnvironment)environment ;
             String[] locations = env.getConfigLocations() ;
             String loc = huntForShiroIni(locations) ;
+            Fuseki.configLog.info("Shiro file: "+loc);
             if (loc != null )
                 locations = new String[] {loc} ;
             env.setConfigLocations(locations);
@@ -107,10 +108,10 @@ public class ShiroEnvironmentLoader exte
             Path p = Paths.get(loc) ;
             String fn = resolve(FusekiServer.FUSEKI_BASE, p) ;
             if ( fn != null )
-                return "file:/"+fn ;
+                return "file://"+fn ;
             fn = resolve(FusekiServer.FUSEKI_HOME, p) ;
             if ( fn != null )
-                return "file:/"+fn ;
+                return "file://"+fn ;
             
             // Try in webapp.
             
@@ -128,7 +129,7 @@ public class ShiroEnvironmentLoader exte
     private static String resolve(Path dir, Path file) {
         Path p = dir.resolve(file) ;
         if ( p.toFile().exists() )
-            return p.toString() ;
+            return p.normalize().toString() ;
         return null ;
     }
 

Modified: jena/branches/jena-fuseki-new-ui/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/webapp/WEB-INF/web.xml?rev=1581093&r1=1581092&r2=1581093&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/webapp/WEB-INF/web.xml (original)
+++ jena/branches/jena-fuseki-new-ui/src/main/webapp/WEB-INF/web.xml Mon Mar 24 22:25:36 2014
@@ -11,7 +11,7 @@
   <!-- First filter -->
   <listener>
     <!--<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>-->
-    <!-- Support multiple locations -->
+    <!-- Support multiple locations, looks in Fuseki-relevant places -->
     <listener-class>org.apache.jena.fuseki.server.ShiroEnvironmentLoader</listener-class>
   </listener>
 
@@ -31,7 +31,9 @@
 
   <context-param>
     <param-name>shiroConfigLocations</param-name>
-    <!-- Try : FUSEKI_BASE, FUSEKI_HOME, war resource -->
+    <!-- Try a path name in: FUSEKI_BASE, FUSEKI_HOME, war resource
+	 If a "file:" then look there and there only.
+    -->
     <param-value>shiro.ini</param-value>
   </context-param>
 



Mime
View raw message