changeset 10:086a55aa2620

PasswdUserConfig. Error logging.
author Mikhail Kryshen <mikhail@kryshen.net>
date Mon, 02 Nov 2009 23:17:40 +0300
parents a3321ea9b33f
children 3a71cbe721f9
files nbproject/build-impl.xml nbproject/genfiles.properties src/kryshen/catalina/startup/HomesUserConfig.java src/kryshen/catalina/startup/PasswdUserConfig.java src/kryshen/catalina/startup/UserConfig.java
diffstat 5 files changed, 159 insertions(+), 29 deletions(-) [+]
line diff
     1.1 --- a/nbproject/build-impl.xml	Mon Nov 02 18:36:24 2009 +0300
     1.2 +++ b/nbproject/build-impl.xml	Mon Nov 02 23:17:40 2009 +0300
     1.3 @@ -20,6 +20,13 @@
     1.4  
     1.5          -->
     1.6  <project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="tomcat-userconfig-impl">
     1.7 +    <fail message="Please build using Ant 1.7.1 or higher.">
     1.8 +        <condition>
     1.9 +            <not>
    1.10 +                <antversion atleast="1.7.1"/>
    1.11 +            </not>
    1.12 +        </condition>
    1.13 +    </fail>
    1.14      <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
    1.15      <!-- 
    1.16                  ======================
    1.17 @@ -152,10 +159,18 @@
    1.18              <attribute default="${includes}" name="includes"/>
    1.19              <attribute default="${excludes}" name="excludes"/>
    1.20              <attribute default="${javac.debug}" name="debug"/>
    1.21 -            <attribute default="/does/not/exist" name="sourcepath"/>
    1.22 +            <attribute default="${empty.dir}" name="sourcepath"/>
    1.23 +            <attribute default="${empty.dir}" name="gensrcdir"/>
    1.24              <element name="customize" optional="true"/>
    1.25              <sequential>
    1.26 +                <property location="${build.dir}/empty" name="empty.dir"/>
    1.27 +                <mkdir dir="${empty.dir}"/>
    1.28                  <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}">
    1.29 +                    <src>
    1.30 +                        <dirset dir="@{gensrcdir}" erroronmissingdir="false">
    1.31 +                            <include name="*"/>
    1.32 +                        </dirset>
    1.33 +                    </src>
    1.34                      <classpath>
    1.35                          <path path="@{classpath}"/>
    1.36                      </classpath>
    1.37 @@ -271,6 +286,8 @@
    1.38                  <java classname="@{classname}" dir="${work.dir}" fork="true">
    1.39                      <jvmarg line="${debug-args-line}"/>
    1.40                      <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
    1.41 +                    <jvmarg value="-Dfile.encoding=${source.encoding}"/>
    1.42 +                    <redirector errorencoding="${source.encoding}" inputencoding="${source.encoding}" outputencoding="${source.encoding}"/>
    1.43                      <jvmarg line="${run.jvmargs}"/>
    1.44                      <classpath>
    1.45                          <path path="@{classpath}"/>
    1.46 @@ -287,12 +304,15 @@
    1.47      <target name="-init-macrodef-java">
    1.48          <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
    1.49              <attribute default="${main.class}" name="classname"/>
    1.50 +            <attribute default="${run.classpath}" name="classpath"/>
    1.51              <element name="customize" optional="true"/>
    1.52              <sequential>
    1.53                  <java classname="@{classname}" dir="${work.dir}" fork="true">
    1.54 +                    <jvmarg value="-Dfile.encoding=${source.encoding}"/>
    1.55 +                    <redirector errorencoding="${source.encoding}" inputencoding="${source.encoding}" outputencoding="${source.encoding}"/>
    1.56                      <jvmarg line="${run.jvmargs}"/>
    1.57                      <classpath>
    1.58 -                        <path path="${run.classpath}"/>
    1.59 +                        <path path="@{classpath}"/>
    1.60                      </classpath>
    1.61                      <syspropertyset>
    1.62                          <propertyref prefix="run-sys-prop."/>
    1.63 @@ -332,10 +352,15 @@
    1.64          <!-- You can override this target in the ../build.xml file. -->
    1.65      </target>
    1.66      <target if="do.depend.true" name="-compile-depend">
    1.67 -        <j2seproject3:depend/>
    1.68 +        <pathconvert property="build.generated.subdirs">
    1.69 +            <dirset dir="${build.generated.sources.dir}" erroronmissingdir="false">
    1.70 +                <include name="*"/>
    1.71 +            </dirset>
    1.72 +        </pathconvert>
    1.73 +        <j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/>
    1.74      </target>
    1.75      <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
    1.76 -        <j2seproject3:javac/>
    1.77 +        <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
    1.78          <copy todir="${build.classes.dir}">
    1.79              <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
    1.80          </copy>
    1.81 @@ -352,7 +377,7 @@
    1.82      <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
    1.83          <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
    1.84          <j2seproject3:force-recompile/>
    1.85 -        <j2seproject3:javac excludes="" includes="${javac.includes}" sourcepath="${src.dir}"/>
    1.86 +        <j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.dir}"/>
    1.87      </target>
    1.88      <target name="-post-compile-single">
    1.89          <!-- Empty placeholder for easier customization. -->
    1.90 @@ -418,11 +443,29 @@
    1.91          <property location="${dist.jar}" name="dist.jar.resolved"/>
    1.92          <echo>java -jar "${dist.jar.resolved}"</echo>
    1.93      </target>
    1.94 +    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="libs.CopyLibs.classpath" name="-do-jar-with-libraries-without-manifest" unless="manifest.available+main.class">
    1.95 +        <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
    1.96 +        <pathconvert property="run.classpath.without.build.classes.dir">
    1.97 +            <path path="${run.classpath}"/>
    1.98 +            <map from="${build.classes.dir.resolved}" to=""/>
    1.99 +        </pathconvert>
   1.100 +        <pathconvert pathsep=" " property="jar.classpath">
   1.101 +            <path path="${run.classpath.without.build.classes.dir}"/>
   1.102 +            <chainedmapper>
   1.103 +                <flattenmapper/>
   1.104 +                <globmapper from="*" to="lib/*"/>
   1.105 +            </chainedmapper>
   1.106 +        </pathconvert>
   1.107 +        <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
   1.108 +        <copylibs compress="${jar.compress}" jarfile="${dist.jar}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
   1.109 +            <fileset dir="${build.classes.dir}"/>
   1.110 +        </copylibs>
   1.111 +    </target>
   1.112      <target name="-post-jar">
   1.113          <!-- Empty placeholder for easier customization. -->
   1.114          <!-- You can override this target in the ../build.xml file. -->
   1.115      </target>
   1.116 -    <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
   1.117 +    <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-do-jar-with-libraries-without-manifest,-post-jar" description="Build JAR." name="jar"/>
   1.118      <!--
   1.119                  =================
   1.120                  EXECUTION SECTION
   1.121 @@ -442,6 +485,10 @@
   1.122          <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
   1.123          <j2seproject1:java classname="${run.class}"/>
   1.124      </target>
   1.125 +    <target depends="init,-do-not-recompile,compile-test-single" name="run-test-with-main">
   1.126 +        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
   1.127 +        <j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/>
   1.128 +    </target>
   1.129      <!--
   1.130                  =================
   1.131                  DEBUGGING SECTION
   1.132 @@ -450,6 +497,9 @@
   1.133      <target depends="init" if="netbeans.home" name="-debug-start-debugger">
   1.134          <j2seproject1:nbjpdastart name="${debug.class}"/>
   1.135      </target>
   1.136 +    <target depends="init" if="netbeans.home" name="-debug-start-debugger-main-test">
   1.137 +        <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${debug.class}"/>
   1.138 +    </target>
   1.139      <target depends="init,compile" name="-debug-start-debuggee">
   1.140          <j2seproject3:debug>
   1.141              <customize>
   1.142 @@ -467,6 +517,11 @@
   1.143          <j2seproject3:debug classname="${debug.class}"/>
   1.144      </target>
   1.145      <target depends="init,-do-not-recompile,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
   1.146 +    <target depends="init,compile-test-single" if="netbeans.home" name="-debug-start-debuggee-main-test">
   1.147 +        <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
   1.148 +        <j2seproject3:debug classname="${debug.class}" classpath="${debug.test.classpath}"/>
   1.149 +    </target>
   1.150 +    <target depends="init,-do-not-recompile,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/>
   1.151      <target depends="init" name="-pre-debug-fix">
   1.152          <fail unless="fix.includes">Must set fix.includes</fail>
   1.153          <property name="javac.includes" value="${fix.includes}.java"/>
   1.154 @@ -489,6 +544,9 @@
   1.155              <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
   1.156                  <filename name="**/*.java"/>
   1.157              </fileset>
   1.158 +            <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
   1.159 +                <include name="**/*.java"/>
   1.160 +            </fileset>
   1.161          </javadoc>
   1.162      </target>
   1.163      <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
   1.164 @@ -550,7 +608,7 @@
   1.165          <j2seproject3:junit testincludes="**/*Test.java"/>
   1.166      </target>
   1.167      <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
   1.168 -        <fail if="tests.failed">Some tests failed; see details above.</fail>
   1.169 +        <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
   1.170      </target>
   1.171      <target depends="init" if="have.tests" name="test-report"/>
   1.172      <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
   1.173 @@ -563,7 +621,7 @@
   1.174          <j2seproject3:junit excludes="" includes="${test.includes}"/>
   1.175      </target>
   1.176      <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
   1.177 -        <fail if="tests.failed">Some tests failed; see details above.</fail>
   1.178 +        <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
   1.179      </target>
   1.180      <target depends="init,-do-not-recompile,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
   1.181      <!--
     2.1 --- a/nbproject/genfiles.properties	Mon Nov 02 18:36:24 2009 +0300
     2.2 +++ b/nbproject/genfiles.properties	Mon Nov 02 23:17:40 2009 +0300
     2.3 @@ -4,5 +4,5 @@
     2.4  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
     2.5  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
     2.6  nbproject/build-impl.xml.data.CRC32=8168bf3c
     2.7 -nbproject/build-impl.xml.script.CRC32=22b92b6d
     2.8 -nbproject/build-impl.xml.stylesheet.CRC32=65b8de21
     2.9 +nbproject/build-impl.xml.script.CRC32=92172d17
    2.10 +nbproject/build-impl.xml.stylesheet.CRC32=5c621a33@1.26.2.45
     3.1 --- a/src/kryshen/catalina/startup/HomesUserConfig.java	Mon Nov 02 18:36:24 2009 +0300
     3.2 +++ b/src/kryshen/catalina/startup/HomesUserConfig.java	Mon Nov 02 23:17:40 2009 +0300
     3.3 @@ -6,6 +6,7 @@
     3.4  package kryshen.catalina.startup;
     3.5  
     3.6  import java.io.File;
     3.7 +import org.apache.juli.logging.LogFactory;
     3.8  
     3.9  /**
    3.10   *
    3.11 @@ -13,26 +14,17 @@
    3.12   */
    3.13  public class HomesUserConfig extends UserConfig {
    3.14  
    3.15 -    /**
    3.16 -     * The directory name to be searched for within each user home directory.
    3.17 -     */
    3.18 -    private String directoryName = "public_webapps";
    3.19 +    protected static org.apache.juli.logging.Log log =
    3.20 +            org.apache.juli.logging.LogFactory.getLog(HomesUserConfig.class);
    3.21 +
    3.22      /**
    3.23       * The base directory containing user home directories.
    3.24       */
    3.25      private String homeBase = null;
    3.26  
    3.27 -    public String getDirectoryName() {
    3.28 -        return directoryName;
    3.29 -    }
    3.30  
    3.31 -    /**
    3.32 -     * Set the directory name for user web applications.
    3.33 -     *
    3.34 -     * @param directoryName The new directory name
    3.35 -     */
    3.36 -    public void setDirectoryName(String directoryName) {
    3.37 -        this.directoryName = directoryName;
    3.38 +    public HomesUserConfig() {
    3.39 +        log = LogFactory.getLog(HomesUserConfig.class);
    3.40      }
    3.41  
    3.42      /**
    3.43 @@ -56,7 +48,7 @@
    3.44          File homeBaseFile = new File(homeBase);
    3.45  
    3.46          if (!homeBaseFile.exists() || !homeBaseFile.isDirectory()) {
    3.47 -            host.getLogger().error("Invalid home base.");
    3.48 +            log.error("Invalid home base.");
    3.49              return;
    3.50          }
    3.51  
    3.52 @@ -69,8 +61,7 @@
    3.53                  continue;
    3.54              }
    3.55  
    3.56 -            File base = new File(home, directoryName);
    3.57 -            deployUserApps(name, base);
    3.58 +            deployUserApps(name, home);
    3.59          }
    3.60      }
    3.61  }
     4.1 --- a/src/kryshen/catalina/startup/PasswdUserConfig.java	Mon Nov 02 18:36:24 2009 +0300
     4.2 +++ b/src/kryshen/catalina/startup/PasswdUserConfig.java	Mon Nov 02 23:17:40 2009 +0300
     4.3 @@ -1,5 +1,13 @@
     4.4  package kryshen.catalina.startup;
     4.5  
     4.6 +import java.io.BufferedReader;
     4.7 +import java.io.File;
     4.8 +import java.io.FileReader;
     4.9 +import java.io.IOException;
    4.10 +import java.io.InputStreamReader;
    4.11 +import java.util.regex.Pattern;
    4.12 +import org.apache.juli.logging.LogFactory;
    4.13 +
    4.14  /**
    4.15   *
    4.16   * @author Mikhail Kryshen
    4.17 @@ -8,6 +16,11 @@
    4.18  
    4.19      private static final String PASSWD_DATABASE = "passwd";
    4.20  
    4.21 +    /* Passwd format details. */
    4.22 +    private static final Pattern PASSWD_SPLIT_PATTERN = Pattern.compile(":");
    4.23 +    private static final int PASSWD_FIELD_USERNAME = 0;
    4.24 +    private static final int PASSWD_FIELD_HOME = 5;
    4.25 +
    4.26      /**
    4.27       * Command for retrieving passwd database.
    4.28       */
    4.29 @@ -18,6 +31,10 @@
    4.30       */
    4.31      private String passwd = "/etc/passwd";
    4.32  
    4.33 +    public PasswdUserConfig() {
    4.34 +        log = LogFactory.getLog(PasswdUserConfig.class);
    4.35 +    }
    4.36 +
    4.37      /**
    4.38       * Get command for retrieving passwd database.
    4.39       */
    4.40 @@ -48,6 +65,43 @@
    4.41  
    4.42      @Override
    4.43      protected void deployUserApps() {
    4.44 -        // TODO
    4.45 +        BufferedReader in;
    4.46 +
    4.47 +        try {
    4.48 +            if (getent == null) {
    4.49 +                in = new BufferedReader(new FileReader(passwd));
    4.50 +            } else {
    4.51 +                Process process = Runtime.getRuntime().exec(
    4.52 +                        getent, new String[]{PASSWD_DATABASE});
    4.53 +
    4.54 +                in = new BufferedReader(
    4.55 +                        new InputStreamReader(process.getInputStream()));
    4.56 +            }
    4.57 +
    4.58 +            String line;
    4.59 +
    4.60 +            try {
    4.61 +                while ((line = in.readLine()) != null) {
    4.62 +                    String[] fields = PASSWD_SPLIT_PATTERN.split(line);
    4.63 +
    4.64 +                    String name = fields[PASSWD_FIELD_USERNAME];
    4.65 +                    File home = new File(fields[PASSWD_FIELD_HOME]);
    4.66 +
    4.67 +                    if (!home.isDirectory()) {
    4.68 +                        log.error("Invalid home directory for user"
    4.69 +                                + name + ": " + home.getPath() + ".");
    4.70 +                        continue;
    4.71 +                    }
    4.72 +
    4.73 +                    deployUserApps(name, home);
    4.74 +                }
    4.75 +            } finally {
    4.76 +                in.close();
    4.77 +            }
    4.78 +        } catch (IOException e) {
    4.79 +            log.error("Error reading passwd database.", e);
    4.80 +        } catch (ArrayIndexOutOfBoundsException e) {
    4.81 +            log.error("Invalid passwd format.", e);
    4.82 +        }
    4.83      }
    4.84  }
     5.1 --- a/src/kryshen/catalina/startup/UserConfig.java	Mon Nov 02 18:36:24 2009 +0300
     5.2 +++ b/src/kryshen/catalina/startup/UserConfig.java	Mon Nov 02 23:17:40 2009 +0300
     5.3 @@ -2,6 +2,7 @@
     5.4  
     5.5  import java.io.File;
     5.6  import org.apache.catalina.startup.HostConfig;
     5.7 +import org.apache.juli.logging.LogFactory;
     5.8  
     5.9  /**
    5.10   *
    5.11 @@ -9,6 +10,29 @@
    5.12   */
    5.13  public abstract class UserConfig extends HostConfig {
    5.14  
    5.15 +    /**
    5.16 +     * The directory name to be searched for within each user home directory.
    5.17 +     */
    5.18 +    private String directoryName = "public_webapps";
    5.19 +
    5.20 +    
    5.21 +    protected UserConfig() {
    5.22 +        log = LogFactory.getLog(UserConfig.class);
    5.23 +    }
    5.24 +    
    5.25 +    public String getDirectoryName() {
    5.26 +        return directoryName;
    5.27 +    }
    5.28 +
    5.29 +    /**
    5.30 +     * Set the directory name for user web applications.
    5.31 +     *
    5.32 +     * @param directoryName The new directory name
    5.33 +     */
    5.34 +    public void setDirectoryName(String directoryName) {
    5.35 +        this.directoryName = directoryName;
    5.36 +    }
    5.37 +
    5.38      @Override
    5.39      protected void deployApps() {       
    5.40          deployUserApps();
    5.41 @@ -22,7 +46,9 @@
    5.42  
    5.43      protected abstract void deployUserApps();
    5.44  
    5.45 -    protected void deployUserApps(String user, File base) {
    5.46 +    protected void deployUserApps(String user, File home) {
    5.47 +        File base = new File(home, directoryName);
    5.48 +
    5.49          if (!base.exists() || !base.isDirectory() || !base.canRead()) {
    5.50              return;
    5.51          }
    5.52 @@ -40,6 +66,7 @@
    5.53      protected void deployDirectories(String user, File base, String[] files) {
    5.54  
    5.55          if (files == null) {
    5.56 +            log.error("Error reading base directory: " + base.getPath() + ".");
    5.57              return;
    5.58          }
    5.59