Commits

nclarkekb  committed f61e139

#155 change added to updated script files.
Completed location unaware env.cmd and jhove2[_debug].cmd invocation support.
Changed File ident module to only initialize upon use.

  • Participants
  • Parent commits 4960447

Comments (0)

Files changed (10)

File config/spring/module/identify/file/jhove2-identify-file-config.xml

        (http://www.macports.org/). 
    -->
    <!-- IF MAGIC IS NOT INSTALLED, YOU MUST DISABLE THIS ENTIRE BEAN -->
-<!--   <bean id="LibmagicIdentifier" -->
-<!--         class="org.jhove2.module.identify.file.LibmagicIdentifier" -->
-<!--         scope="singleton" -->
-<!--         init-method="init" -->
-<!--         destroy-method="shutdown"> -->
-<!--     <constructor-arg ref="BaseModuleAccessor"/> -->
-<!--     <property name="developers"> -->
-<!--       <list value-type="org.jhove2.core.Agent"> -->
-<!--         <ref bean="BnFAgent"/> -->
-<!--       </list> -->
-<!--     </property> -->
-    
-    <!-- Point the magicFileDir property to a directory containing
-         Magic definition files to force the compilation of these files
-         when the LibmagicIdentifier starts (once per JVM run). If this
-         property is not set, the system-provided (on UNIX and Linux
-         systems) definitions will be used.
-     -->
-    <!--property name="magicFileDir" value="classpath:file/Magdir"/-->
-    <!--property name="magicFileDir" value="/home/nicl/workspace/file-5.11/magic/Magdir/warc"/-->
-    
-<!--   </bean> -->
-
+   <bean id="LibmagicIdentifier"
+         class="org.jhove2.module.identify.file.LibmagicIdentifier"
+         scope="singleton"
+         init-method="init"
+         destroy-method="shutdown">
+     <constructor-arg ref="BaseModuleAccessor"/>
+     <property name="developers">
+       <list value-type="org.jhove2.core.Agent">
+         <ref bean="BnFAgent"/>
+       </list>
+     </property>
+     <!-- Point the magicFileDir property to a directory containing
+          Magic definition files to force the compilation of these files
+          when the LibmagicIdentifier starts (once per JVM run). If this
+          property is not set, the system-provided (on UNIX and Linux
+          systems) definitions will be used.
+      -->
+     <!--property name="magicFileDir" value="classpath:file/Magdir"/-->
+     <!--property name="magicFileDir" value="/home/nicl/workspace/file-5.11/magic/Magdir/warc"/-->
+   </bean>
 </beans>
 		</license>
 	</licenses>
 	<repositories>
-		<!--repository>
-			<id>Antiaction</id>
-			<name>Antiaction Repository</name>
-			<url>http://repository.antiaction.com/</url>
-		</repository-->
 		<!-- JWAT -->
 		<repository>
 			<id>Sonatype-snapshots</id>

File src/main/java/org/jhove2/module/format/gzip/properties/GzipEntryProperties.java

      * Returns whether the entry is compliant or not.
      * @return whether the entry is compliant or not
      */
-    @ReportableProperty(order = 1, value = "Is non compliancy.")
+    @ReportableProperty(order = 1, value = "Is non compliant.")
     public boolean getIsNonCompliant() {
         return entry.isNonCompliant;
     }

File src/main/java/org/jhove2/module/identify/file/LibmagicIdentifier.java

 
 package org.jhove2.module.identify.file;
 
-
 import java.io.File;
 import java.io.IOException;
 import java.util.Collections;
 
 import com.sleepycat.persist.model.Persistent;
 
-
 /**
  * A {@link SourceIdentifier source identifier} that wraps the
  * libmagic dynamic library of the UNIX <code>file</code> identifier
  * @author hbian
  */
 @Persistent
-public class LibmagicIdentifier
-	extends AbstractFileSourceIdentifier
-	implements SourceIdentifier
-{
-    /** Module version identifier. */
+public class LibmagicIdentifier extends AbstractFileSourceIdentifier
+	implements SourceIdentifier {
+
+	/** Module version identifier. */
     public final static String VERSION = "2.0.0";
     /** Module release date. */
     public final static String RELEASE = "2011-01-31";
 	/**Instantiate a new <code>DROIDIdentifier</code> module that wraps DROID.
 	 * @throws JHOVE2Exception 
 	 */
-	public LibmagicIdentifier()
-		throws JHOVE2Exception
-	{
+	public LibmagicIdentifier() throws JHOVE2Exception {
 		this(null);
 	}
 	
 	 * @throws JHOVE2Exception 
 	 */
 	public LibmagicIdentifier(ModuleAccessor moduleAccessor)
-		throws JHOVE2Exception
-	{
+			throws JHOVE2Exception {
 		super(VERSION, RELEASE, RIGHTS, Scope.Generic, moduleAccessor);
 	}
 	
+    /**
+     * Initializes this instance. This method should be called once
+     * all the configuration properties (dependency injection) set.
+     *
+     * @throws JHOVE2Exception if any error occurred.
+     */
+    public void init() throws JHOVE2Exception {
+    }
+
+    /**
+     * Initialize module if it has not been done yet.
+     * @throws JHOVE2Exception if an error occurs during initialization
+     */
+    public void checkIfInitialized() throws JHOVE2Exception {
+    	if (libmagicWrapper == null) {
+        	// Initialize libmagic wrapper.
+            libmagicWrapper = new LibmagicJnaWrapper();
+
+            String compiledMagicPath = null;
+            if (this.magicFileDir != null) {
+                // Magic source directory set. => Compile magic files.
+            	if (libmagicWrapper.compile(
+                                    magicFileDir.getAbsolutePath()) != 0) {
+                    throw new JHOVE2Exception("Magic file compile error: "
+                                              + libmagicWrapper.getError());
+                }
+                // Look for compiled magic file. Its location varies according to
+                // some compilation options of libmagic.
+                // Was it stored in the current directory?
+                String dbName = magicFileDir.getName() + MAGIC_DB_EXTENSION;
+                File magicPath = new File(dbName);
+                if (! magicPath.isFile()) {
+                    // Nope! Must be in the parent dir. of the source definitions.
+                    magicPath = new File(magicFileDir.getParentFile(), dbName);
+                }
+                compiledMagicPath = magicPath.getAbsolutePath();
+                // Keep compiled file ref. for shutdown time cleanup.
+                compiledMagic = magicPath;
+                compiledMagic.deleteOnExit();
+            }
+            // Load magic definitions. 
+            if (libmagicWrapper.load(compiledMagicPath) != 0) {
+                String fileRef = (compiledMagicPath != null)?
+                                    "Magic database \"" + compiledMagicPath + '"':
+                                    "Default magic database";
+                throw new JHOVE2Exception(fileRef + " load error: "
+                                                  + libmagicWrapper.getError());
+            }
+    	}
+    }
+
+    /**
+     * Shuts down this instance, releasing used resources.
+     */
+    public void shutdown() {
+    	if (libmagicWrapper != null) {
+            libmagicWrapper.close();
+            libmagicWrapper = null;
+    	}
+        if (compiledMagic != null) {
+            // Delete compiled magic file.
+            compiledMagic.delete();
+            compiledMagic = null;
+        }
+    }
+
     /** {@inheritDoc} */
     @Override
     public Set<FormatIdentification> identify(JHOVE2 jhove2, Source source,
-                                                             Input input)
-                                        throws IOException, JHOVE2Exception {
+    		Input input) throws IOException, JHOVE2Exception {
+    	checkIfInitialized();
         // Extract MIME type and encoding using libmagic.
         String mimeType = null;
         /* The following code is not compatible with the current JHove2 core.
     }
 
     /**
-     * Initializes this instance. This method should be called once
-     * all the configuration properties (dependency injection) set.
-     *
-     * @throws JHOVE2Exception if any error occurred.
-     */
-    public void init() throws JHOVE2Exception {
-    	// Initialize libmagic wrapper.
-        libmagicWrapper = new LibmagicJnaWrapper();
-
-        String compiledMagicPath = null;
-        if (this.magicFileDir != null) {
-            // Magic source directory set. => Compile magic files.
-        	if (libmagicWrapper.compile(
-                                magicFileDir.getAbsolutePath()) != 0) {
-                throw new JHOVE2Exception("Magic file compile error: "
-                                          + libmagicWrapper.getError());
-            }
-            // Look for compiled magic file. Its location varies according to
-            // some compilation options of libmagic.
-            // Was it stored in the current directory?
-            String dbName = magicFileDir.getName() + MAGIC_DB_EXTENSION;
-            File magicPath = new File(dbName);
-            if (! magicPath.isFile()) {
-                // Nope! Must be in the parent dir. of the source definitions.
-                magicPath = new File(magicFileDir.getParentFile(), dbName);
-            }
-            compiledMagicPath = magicPath.getAbsolutePath();
-            // Keep compiled file ref. for shutdown time cleanup.
-            compiledMagic = magicPath;
-            compiledMagic.deleteOnExit();
-        }
-        // Load magic definitions. 
-        if (libmagicWrapper.load(compiledMagicPath) != 0) {
-            String fileRef = (compiledMagicPath != null)?
-                                "Magic database \"" + compiledMagicPath + '"':
-                                "Default magic database";
-            throw new JHOVE2Exception(fileRef + " load error: "
-                                              + libmagicWrapper.getError());
-        }
-    }
-
-    /**
-     * Shuts down this instance, releasing used resources.
-     */
-    public void shutdown() {
-        libmagicWrapper.close();
-
-        if (compiledMagic != null) {
-            // Delete compiled magic file.
-            compiledMagic.delete();
-            compiledMagic = null;
-        }
-    }
-
-    /**
      * Returns the {@link I8R identifier} of the JHove2 format
      * corresponding to the specified MIME type.
      * @param  jhove2     the JHove2 characterization context.
      *         JHove2 configuration.
      */
     private static I8R getJhoveFormatId(JHOVE2 jhove2, String mimeType)
-                                                        throws JHOVE2Exception {
+    		throws JHOVE2Exception {
         if (mimeTypesToFormatIds == null) {
             Map<String,I8R> m = new HashMap<String,I8R>();
 

File src/main/scripts/env.cmd

 REM JHOVE2_HOME, and CP. Edit this file if you need to modify the settings for
 REM these variables or define additional variables, such as JAVA_HOME. For more
 REM information, refer to the JHOVE2 User's Guide at http://jhove2.org.
-REM
-REM NOTE: The jhove2-<version>.jar filename jhove2-2.0.0 
-REM is injected via filtering as part of the maven build process.    
-REM CP is set manually until Maven bug of filtering Windows path is fixed
-
 
 REM If JAVA_HOME is not set, use java.exe in execution path
 if "%JAVA_HOME%" == "" (
 SET JHOVE2_HOME=%~dp0
 
 REM CP must contain a semicolon-separated list of JARs used by JHOVE2.
-REM SET CP=%JHOVE2_HOME%\lib\jhove2-2.0.0.jar;%JHOVE2_HOME%\lib\je-4.0.103.jar;%JHOVE2_HOME%\lib\aopalliance-1.0.jar;%JHOVE2_HOME%\lib\jts-1.10.jar;%JHOVE2_HOME%\lib\commons-beanutils-1.7.0.jar;%JHOVE2_HOME%\lib\commons-logging-1.1.1.jar;%JHOVE2_HOME%\lib\commons-logging-api-1.1.jar;%JHOVE2_HOME%\lib\commons-pool-1.5.3.jar;%JHOVE2_HOME%\lib\vecmath-1.3.2.jar;%JHOVE2_HOME%\lib\jdom-1.0.jar;%JHOVE2_HOME%\lib\junit-4.4.jar;%JHOVE2_HOME%\lib\log4j-1.2.14.jar;%JHOVE2_HOME%\lib\jsr-275-1.0-beta-2.jar;%JHOVE2_HOME%\lib\jargs-1.0.jar;%JHOVE2_HOME%\lib\stringtemplate-3.2.jar;%JHOVE2_HOME%\lib\gt-api-2.6.5.jar;%JHOVE2_HOME%\lib\gt-main-2.6.5.jar;%JHOVE2_HOME%\lib\gt-metadata-2.6.5.jar;%JHOVE2_HOME%\lib\gt-referencing-2.6.5.jar;%JHOVE2_HOME%\lib\gt-shapefile-2.6.5.jar;%JHOVE2_HOME%\lib\mvel2-2.0.18.jar;%JHOVE2_HOME%\lib\geoapi-2.3-M1.jar;%JHOVE2_HOME%\lib\geoapi-pending-2.3-M1.jar;%JHOVE2_HOME%\lib\spring-beans-2.5.6.jar;%JHOVE2_HOME%\lib\spring-context-2.5.6.jar;%JHOVE2_HOME%\lib\spring-core-2.5.6.jar;%JHOVE2_HOME%\lib\spring-test-2.5.6.jar;%JHOVE2_HOME%\lib\soap-2.3.1.jar;%JHOVE2_HOME%\lib\xercesImpl-2.9.1.jar;%JHOVE2_HOME%\lib\xml-apis-1.3.04.jar;%JHOVE2_HOME%\lib\xml-resolver-1.2.jar;%JHOVE2_HOME%\config\droid;%JHOVE2_HOME%\config
-
-REM SET CP=%CP%;%JHOVE2_HOME%\lib\jwat-arc-0.8.0-20120117.161007-14.jar
-REM SET CP=%CP%;%JHOVE2_HOME%\lib\jwat-common-0.8.0-20120117.160951-14.jar
-REM SET CP=%CP%;%JHOVE2_HOME%\lib\jwat-gzip-0.8.0-SNAPSHOT.jar
-REM SET CP=%CP%;%JHOVE2_HOME%\lib\jwat-warc-0.8.0-20120117.161029-14.jar
-
 SET CP=%JHOVE2_HOME%\config\droid;%JHOVE2_HOME%\config
 
-@echo off
-FOR /R ./lib %%a in (*.jar) DO CALL :AddToPath %%a
+FOR /R %JHOVE2_HOME%/lib %%a in (*.jar) DO CALL :AddToPath %%a
 REM ECHO %CP%
 GOTO :EOF
 
 :AddToPath
-SET CP=%1;%CP%
+SET CP=%CP%;%1
 GOTO :EOF

File src/main/scripts/env.sh

 # JHOVE2_HOME, and CP. Edit this file if you need to modify the settings for
 # these variables or define additional variables, such as JAVA_HOME. For more
 # information, refer to the JHOVE2 User's Guide at http://jhove2.org.
-#
-# NOTE: The jhove2-<version>.jar filename jhove2-2.0.0 and the 
-# classpath $JHOVE2_HOME/lib/aopalliance-1.0.jar:$JHOVE2_HOME/lib/je-4.0.103.jar:$JHOVE2_HOME/lib/jts-1.10.jar:$JHOVE2_HOME/lib/commons-beanutils-1.7.0.jar:$JHOVE2_HOME/lib/commons-logging-1.1.1.jar:$JHOVE2_HOME/lib/commons-logging-api-1.1.jar:$JHOVE2_HOME/lib/commons-pool-1.5.3.jar:$JHOVE2_HOME/lib/vecmath-1.3.2.jar:$JHOVE2_HOME/lib/jdom-1.0.jar:$JHOVE2_HOME/lib/junit-4.4.jar:$JHOVE2_HOME/lib/log4j-1.2.14.jar:$JHOVE2_HOME/lib/jsr-275-1.0-beta-2.jar:$JHOVE2_HOME/lib/jargs-1.0.jar:$JHOVE2_HOME/lib/gt-api-2.6.5.jar:$JHOVE2_HOME/lib/gt-main-2.6.5.jar:$JHOVE2_HOME/lib/gt-metadata-2.6.5.jar:$JHOVE2_HOME/lib/gt-referencing-2.6.5.jar:$JHOVE2_HOME/lib/gt-shapefile-2.6.5.jar:$JHOVE2_HOME/lib/jwat-arc-0.8.0-SNAPSHOT.jar:$JHOVE2_HOME/lib/jwat-common-0.8.0-SNAPSHOT.jar:$JHOVE2_HOME/lib/jwat-gzip-0.8.0-SNAPSHOT.jar:$JHOVE2_HOME/lib/jwat-warc-0.8.0-SNAPSHOT.jar:$JHOVE2_HOME/lib/mvel2-2.0.18.jar:$JHOVE2_HOME/lib/geoapi-2.3-M1.jar:$JHOVE2_HOME/lib/geoapi-pending-2.3-M1.jar:$JHOVE2_HOME/lib/spring-beans-2.5.6.jar:$JHOVE2_HOME/lib/spring-context-2.5.6.jar:$JHOVE2_HOME/lib/spring-core-2.5.6.jar:$JHOVE2_HOME/lib/spring-test-2.5.6.jar:$JHOVE2_HOME/lib/soap-2.3.1.jar:$JHOVE2_HOME/lib/xercesImpl-2.9.1.jar:$JHOVE2_HOME/lib/xml-apis-1.3.04.jar:$JHOVE2_HOME/lib/xml-resolver-1.2.jar
-# are injected via filtering as part of the maven build process.    
 
 # If JAVA_HOME is not set, use the java in the execution path
 if [ ${JAVA_HOME} ] ; then
 # make it fully qualified
 JHOVE2_HOME=`cd "$JHOVE2_HOME" && pwd`
 
-#CP=$JHOVE2_HOME/lib/jhove2-2.0.0.jar:$JHOVE2_HOME/lib/aopalliance-1.0.jar:$JHOVE2_HOME/lib/je-4.0.103.jar:$JHOVE2_HOME/lib/jts-1.10.jar:$JHOVE2_HOME/lib/commons-beanutils-1.7.0.jar:$JHOVE2_HOME/lib/commons-logging-1.1.1.jar:$JHOVE2_HOME/lib/commons-logging-api-1.1.jar:$JHOVE2_HOME/lib/commons-pool-1.5.3.jar:$JHOVE2_HOME/lib/vecmath-1.3.2.jar:$JHOVE2_HOME/lib/jdom-1.0.jar:$JHOVE2_HOME/lib/junit-4.4.jar:$JHOVE2_HOME/lib/log4j-1.2.14.jar:$JHOVE2_HOME/lib/jsr-275-1.0-beta-2.jar:$JHOVE2_HOME/lib/jargs-1.0.jar:$JHOVE2_HOME/lib/gt-api-2.6.5.jar:$JHOVE2_HOME/lib/gt-main-2.6.5.jar:$JHOVE2_HOME/lib/gt-metadata-2.6.5.jar:$JHOVE2_HOME/lib/gt-referencing-2.6.5.jar:$JHOVE2_HOME/lib/gt-shapefile-2.6.5.jar:$JHOVE2_HOME/lib/jwat-arc-0.8.0-SNAPSHOT.jar:$JHOVE2_HOME/lib/jwat-common-0.8.0-SNAPSHOT.jar:$JHOVE2_HOME/lib/jwat-gzip-0.8.0-SNAPSHOT.jar:$JHOVE2_HOME/lib/jwat-warc-0.8.0-SNAPSHOT.jar:$JHOVE2_HOME/lib/mvel2-2.0.18.jar:$JHOVE2_HOME/lib/geoapi-2.3-M1.jar:$JHOVE2_HOME/lib/geoapi-pending-2.3-M1.jar:$JHOVE2_HOME/lib/spring-beans-2.5.6.jar:$JHOVE2_HOME/lib/spring-context-2.5.6.jar:$JHOVE2_HOME/lib/spring-core-2.5.6.jar:$JHOVE2_HOME/lib/spring-test-2.5.6.jar:$JHOVE2_HOME/lib/soap-2.3.1.jar:$JHOVE2_HOME/lib/xercesImpl-2.9.1.jar:$JHOVE2_HOME/lib/xml-apis-1.3.04.jar:$JHOVE2_HOME/lib/xml-resolver-1.2.jar:$JHOVE2_HOME/config:$JHOVE2_HOME/config/droid
-
 # CP must contain a colon-separated list of JARs used by JHOVE2.
 CP=$JHOVE2_HOME/config:$JHOVE2_HOME/config/droid
 #CP=$JHOVE2_HOME/file-config:$JHOVE2_HOME/config/droid

File src/main/scripts/jhove2.cmd

 
 setlocal enableextensions
 
-call env
+call %~dp0\env.cmd
 
-%JAVA% -Xms256m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=256M -cp "%CP%" org.jhove2.app.JHOVE2CommandLine %*
+if "%JAVA_OPTS%" == "" (
+  set JAVA_OPTS=-Xms256m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=256M
+)
 
-REM %JAVA% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044 -Xms256m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=256M -cp "%CP%" org.jhove2.app.JHOVE2CommandLine %*
+%JAVA% %JAVA_OPTS% -cp "%CP%" org.jhove2.app.JHOVE2CommandLine %*

File src/main/scripts/jhove2.sh

 . "${ProgDir}/env.sh"
 
 if [ -z "${JAVA_OPTS}" ]; then
-  JAVA_OPTS="-Xms256m -Xmx1025m -XX:PermSize=64M -XX:MaxPermSize=256M"
+  JAVA_OPTS="-Xms256m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=256M"
 fi
 
-"${JAVA}" ${JAVA_OPTS} -cp "$CP" org.jhove2.app.JHOVE2CommandLine $@
+"${JAVA}" ${JAVA_OPTS} -cp "$CP" org.jhove2.app.JHOVE2CommandLine "$@"

File src/main/scripts/jhove2_debug.cmd

 
 setlocal enableextensions
 
-call env
+call %~dp0\env.cmd
 
-REM %JAVA% -Xms256m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=256M -cp "%CP%" org.jhove2.app.JHOVE2CommandLine %*
+if "%JAVA_DEBUG_OPTS%" == "" (
+   set JAVA_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044
+)
 
-%JAVA% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044 -Xms256m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=256M -cp "%CP%" org.jhove2.app.JHOVE2CommandLine %*
+if "%JAVA_OPTS%" == "" (
+   set JAVA_OPTS=-Xms256m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=256M
+)
+
+%JAVA% %JAVA_DEBUG_OPTS% %JAVA_OPTS% -cp "%CP%" org.jhove2.app.JHOVE2CommandLine %*

File src/main/scripts/jhove2_debug.sh

 ProgDir=`dirname "$0"`
 . "${ProgDir}/env.sh"
 
-if [ -z "${JAVA_OPTS}" ]; then
-  JAVA_OPTS="-Xms256m -Xmx1025m -XX:PermSize=64M -XX:MaxPermSize=256M"
+if [ -z "${JAVA_DEBUG_OPTS}" ]; then
+  JAVA_DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044"
 fi
 
-"${JAVA}" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044 ${JAVA_OPTS} -cp "$CP" org.jhove2.app.JHOVE2CommandLine $@
+if [ -z "${JAVA_OPTS}" ]; then
+  JAVA_OPTS="-Xms256m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=256M"
+fi
+
+"${JAVA}" ${JAVA_DEBUG_OPTS} ${JAVA_OPTS} -cp "$CP" org.jhove2.app.JHOVE2CommandLine "$@"