お次は、次の4行を処理していきましょう。

[plexus.core]
optionally ${maven.home}/lib/ext/*.jar
load       ${maven.home}/lib/*.jar
load       ${maven.home}/conf/logging
[plexus.core]

この行に該当するのは、以下のコード。うん。短くてよろしいw。

else if ( line.startsWith( "[" ) )
{
    int rbrack = line.indexOf( "]" );

    if ( rbrack < 0 )
    {
        throw new ConfigurationException( "Invalid realm specifier", lineNo, line );
    }

    String realmName = line.substring( 1, rbrack );

    handler.addRealm( realmName );

    curRealm = realmName;
}

かっこはちゃんと対応付けないと怒られるって訳ね。(例外を投げられるという形で。)

結局このかっこの中身は、realmNameなのだそうな。このrealmってのがちょっと曲者だな。

最初の行で解析した時に、「mainRealmName = "plexus.core"」としてたので、ここと対応してるんだな。きっと。

でなんとなくこの[plexus.core]というレルム(realm)の設定に該当するのが、次の三行なんだろう。

WikiPediaさんで「レルム」って単語を調べてみると、次のようなことなんだそうな。

英語のレルムrealm、発音: [ˈrɛlm])は、君主の支配する共同体または領土を指し、特に王国その他の君主制国家を指す。 古フランス語の「reaume」(現代フランス語の royaume(ロワイヨーム;王国)が英語に取り入れられ、17世紀初めに現在の綴りへと変化した。

ま、領土とか国とかってニュアンスの言葉ですかね。今見てるのが、classworldsってな名前のライブラリなので、世界の中に、国が複数あるというようのイメージでしょうかね。classworldsが複数形なのはどんな意味なんだろ。(パラレルワールドってことか??)

お次の行は、

optionally ${maven.home}/lib/ext/*.jar

で、解析してんのは、以下のコード。

else if ( line.startsWith( OPTIONALLY_PREFIX ) )
{
    String constituent = line.substring( OPTIONALLY_PREFIX.length() ).trim();

    constituent = filter( constituent );

    if ( constituent.indexOf( "*" ) >= 0 )
    {
        loadGlob( constituent, true /*optionally*/ );
    }
    else
    {
        File file = new File( constituent );

        if ( file.exists() )
        {
            handler.addLoadFile( file );
        }
        else
        {
            try
            {
                handler.addLoadURL( new URL( constituent ) );
            }
            catch ( MalformedURLException e )
            {
                // swallow
            }
        }
    }
}

例によって「${maven.home}」はfilter()メソッドで処理してますね。さらに今回お初なのが、「*」の部分。loadGlob()というメソッドで処理しているくらいなので、いわゆるグロブってやつですな。

protected void loadGlob( String line,
                         boolean optionally )
    throws MalformedURLException, FileNotFoundException, ConfigurationException
{
    File globFile = new File( line );

    File dir = globFile.getParentFile();
    if ( !dir.exists() )
    {
        if ( optionally )
        {
            return;
        }
        else
        {
            throw new FileNotFoundException( dir.toString() );
        }
    }

    String localName = globFile.getName();

    int starLoc = localName.indexOf( "*" );

    final String prefix = localName.substring( 0, starLoc );

    final String suffix = localName.substring( starLoc + 1 );

    File[] matches = dir.listFiles( new FilenameFilter()
    {
        public boolean accept( File dir,
                               String name )
        {
            if ( !name.startsWith( prefix ) )
            {
                return false;
            }

            if ( !name.endsWith( suffix ) )
            {
                return false;
            }

            return true;
        }
    } );

    for ( File match : matches )
    {
        handler.addLoadFile( match );
    }
}

で、つまりは、「${maven.home}/lib/ext/」ディレクトリの下の拡張子が「jar」であるファイル全てを拾ってくる訳ですね。

そんでもってloadGlob()さんの中では、該当するファイルがなくてもOKとするようなので、その辺りがoptionallyってことなんでしょう。

で、残るは以下の2行のみ。

load       ${maven.home}/lib/*.jar
load       ${maven.home}/conf/logging

この行に対応するのは、こちら。

else if ( line.startsWith( LOAD_PREFIX ) )
{
    String constituent = line.substring( LOAD_PREFIX.length() ).trim();

    constituent = filter( constituent );

    if ( constituent.indexOf( "*" ) >= 0 )
    {
        loadGlob( constituent, false /*not optionally*/ );
    }
    else
    {
        File file = new File( constituent );

        if ( file.exists() )
        {
            handler.addLoadFile( file );
        }
        else
        {
            try
            {
              handler.addLoadURL( new URL( constituent ) );
            }
            catch ( MalformedURLException e )
            {
                throw new FileNotFoundException( constituent );
            }
        }
    }
}

先ほどのoptionallyとほとんど同じ構成な感じですが、該当するファイルが存在しなかった場合に、例外とする部分が異なるようです。なので、optionallyをつけた場合はオプション扱いなのであってもなくてもOKだが、loadで指定した場合は、なかったら例外とするっていう仕様のようですね。

ちなみに、maven.homeのディレクトリ構成はこんな感じです。

$ tree
.
├── bin
│   ├── m2.conf
│   ├── mvn
│   ├── mvn.cmd
│   ├── mvnDebug
│   ├── mvnDebug.cmd
│   └── mvnyjp
├── boot
│   └── plexus-classworlds-2.5.2.jar
├── conf
│   ├── logging
│   │   └── simplelogger.properties
│   ├── settings.xml
│   └── toolchains.xml
└── lib
    ├── aether-api-1.0.2.v20150114.jar
    ├── aether-api.license
    ├── aether-connector-basic-1.0.2.v20150114.jar
    ├── aether-connector-basic.license
    ├── aether-impl-1.0.2.v20150114.jar
    ├── aether-impl.license
    ├── aether-spi-1.0.2.v20150114.jar
    ├── aether-spi.license
    ├── aether-transport-wagon-1.0.2.v20150114.jar
    ├── aether-transport-wagon.license
    ├── aether-util-1.0.2.v20150114.jar
    ├── aether-util.license
    ├── aopalliance-1.0.jar
    ├── cdi-api-1.0.jar
    ├── cdi-api.license
    ├── commons-cli-1.2.jar
    ├── commons-io-2.2.jar
    ├── commons-lang-2.6.jar
    ├── ext
    │   └── README.txt
    ├── guava-18.0.jar
    ├── javax.inject-1.jar
    ├── jsoup-1.7.2.jar
    ├── jsoup.license
    ├── jsr250-api-1.0.jar
    ├── jsr250-api.license
    ├── maven-aether-provider-3.3.3.jar
    ├── maven-aether-provider.license
    ├── maven-artifact-3.3.3.jar
    ├── maven-artifact.license
    ├── maven-builder-support-3.3.3.jar
    ├── maven-builder-support.license
    ├── maven-compat-3.3.3.jar
    ├── maven-compat.license
    ├── maven-core-3.3.3.jar
    ├── maven-core.license
    ├── maven-embedder-3.3.3.jar
    ├── maven-embedder.license
    ├── maven-model-3.3.3.jar
    ├── maven-model-builder-3.3.3.jar
    ├── maven-model-builder.license
    ├── maven-model.license
    ├── maven-plugin-api-3.3.3.jar
    ├── maven-plugin-api.license
    ├── maven-repository-metadata-3.3.3.jar
    ├── maven-repository-metadata.license
    ├── maven-settings-3.3.3.jar
    ├── maven-settings-builder-3.3.3.jar
    ├── maven-settings-builder.license
    ├── maven-settings.license
    ├── org.eclipse.sisu.inject-0.3.0.jar
    ├── org.eclipse.sisu.inject.license
    ├── org.eclipse.sisu.plexus-0.3.0.jar
    ├── org.eclipse.sisu.plexus.license
    ├── plexus-cipher-1.7.jar
    ├── plexus-cipher.license
    ├── plexus-component-annotations-1.5.5.jar
    ├── plexus-interpolation-1.21.jar
    ├── plexus-sec-dispatcher-1.3.jar
    ├── plexus-sec-dispatcher.license
    ├── plexus-utils-3.0.20.jar
    ├── sisu-guice-3.2.5-no_aop.jar
    ├── slf4j-api-1.7.5.jar
    ├── slf4j-api.license
    ├── slf4j-simple-1.7.5.jar
    ├── slf4j-simple.license
    ├── wagon-file-2.9.jar
    ├── wagon-file.license
    ├── wagon-http-2.9-shaded.jar
    ├── wagon-http-shared-2.9.jar
    ├── wagon-http-shared.license
    ├── wagon-http.license
    ├── wagon-provider-api-2.9.jar
    └── wagon-provider-api.license

6 directories, 83 files
load       ${maven.home}/lib/*.jar

に該当するファイルは、すごくいっぱいありますね。

load       ${maven.home}/conf/logging

こっちに該当するのは、「simplelogger.properties」のようだ。

ついでにこのファイルの内容を見ておくと、こんな感じ。

org.slf4j.simpleLogger.defaultLogLevel=info
org.slf4j.simpleLogger.showDateTime=false
org.slf4j.simpleLogger.showThreadName=false
org.slf4j.simpleLogger.showLogName=false
org.slf4j.simpleLogger.logFile=System.out
org.slf4j.simpleLogger.levelInBrackets=true
org.slf4j.simpleLogger.log.Sisu=info
org.slf4j.simpleLogger.warnLevelString=WARNING

これで一通り、設定ファイルの解析内容は見えたな。

results matching ""

    No results matching ""