Skip to content

Commit

Permalink
[FORGE-831] Use check for a log manager service which JBoss Log Manag…
Browse files Browse the repository at this point in the history
…er provides
  • Loading branch information
jamezp committed Mar 20, 2013
1 parent 5790c8d commit e09292d
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 13 deletions.
59 changes: 55 additions & 4 deletions bootstrap/src/main/java/org/jboss/forge/bootstrap/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

package org.jboss.forge.bootstrap;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
Expand All @@ -29,32 +33,39 @@

/**
* A class with a main method to bootstrap Forge.
*
*
* You can deploy addons by calling {@link Bootstrap#install(String)}
*
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*
*/
public class Bootstrap
{
private static Logger logger = Logger.getLogger(Bootstrap.class.getName());

private final Forge forge;
private boolean exitAfter = false;

public static void main(final String[] args)
{
// Look for a logmanager before any logging takes place
final String logManagerName = getServiceName(Bootstrap.class.getClassLoader(), "java.util.logging.LogManager");
if (logManagerName != null)
{
System.setProperty("java.util.logging.manager", logManagerName);
}
Bootstrap bootstrap = new Bootstrap(args);
bootstrap.start();
}

private Bootstrap(String[] args)
{
final Logger logger = Logger.getLogger(Bootstrap.class.getName());
boolean listInstalled = false;
String installAddon = null;
String removeAddon = null;
forge = ServiceLoader.load(Forge.class).iterator().next();


List<AddonRepository> repositories = new ArrayList<AddonRepository>();
if (args.length > 0)
{
Expand Down Expand Up @@ -211,4 +222,44 @@ private void remove(String addonCoordinates)
}
}

private static String getServiceName(final ClassLoader classLoader, final String className)
{
final InputStream stream = classLoader.getResourceAsStream("META-INF/services/" + className);
if (stream != null)
{
try
{
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = reader.readLine()) != null)
{
final int i = line.indexOf('#');
if (i != -1)
{
line = line.substring(0, i);
}
line = line.trim();
if (line.length() == 0) continue;
return line;
}

}
catch (IOException ignored)
{
// ignore
}
finally
{
try
{
stream.close();
} catch (IOException ignored)
{
// ignore
}
}
}
return null;
}

}
19 changes: 12 additions & 7 deletions container/pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!-- ~ JBoss, by Red Hat. ~ Copyright 2010, Red Hat, Inc., and individual contributors ~ by the @authors tag. See the copyright.txt
in the distribution for a ~ full listing of individual contributors. ~ ~ This is free software; you can redistribute it and/or
modify it ~ under the terms of the GNU Lesser General Public License as ~ published by the Free Software Foundation; either
version 2.1 of ~ the License, or (at your option) any later version. ~ ~ This software is distributed in the hope that it
will be useful, ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU ~ Lesser General Public License for more details. ~ ~ You should have received a copy of the GNU Lesser
General Public ~ License along with this software; if not, write to the Free ~ Software Foundation, Inc., 51 Franklin St,
<!-- ~ JBoss, by Red Hat. ~ Copyright 2010, Red Hat, Inc., and individual contributors ~ by the @authors tag. See the copyright.txt
in the distribution for a ~ full listing of individual contributors. ~ ~ This is free software; you can redistribute it and/or
modify it ~ under the terms of the GNU Lesser General Public License as ~ published by the Free Software Foundation; either
version 2.1 of ~ the License, or (at your option) any later version. ~ ~ This software is distributed in the hope that it
will be useful, ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU ~ Lesser General Public License for more details. ~ ~ You should have received a copy of the GNU Lesser
General Public ~ License along with this software; if not, write to the Free ~ Software Foundation, Inc., 51 Franklin St,
Fifth Floor, Boston, MA ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org. -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand Down Expand Up @@ -45,6 +45,11 @@
<artifactId>forge-proxy</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,12 @@ else if (!file.isDirectory())
systemPaths.add("org/jboss/forge/parser/xml/util");
systemPaths.add("org/jboss/forge/proxy");
systemPaths.add("org/jboss/forge/test");
systemPaths.add("org/jboss/logmanager");
systemPaths.add("org/jboss/logmanager/config");
systemPaths.add("org/jboss/logmanager/errormanager");
systemPaths.add("org/jboss/logmanager/filters");
systemPaths.add("org/jboss/logmanager/formatters");
systemPaths.add("org/jboss/logmanager/handlers");
systemPaths.add("org/jboss/modules");
systemPaths.add("org/jboss/modules/filter");
systemPaths.add("org/jboss/modules/log");
Expand Down
5 changes: 4 additions & 1 deletion dist/src/main/resources/bin/forge
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ if $cygwin; then
HOME=`cygpath --path --windows "$HOME"`
fi

forge_exec_cmd="\"$JAVACMD\" $FORGE_DEBUG_ARGS $FORGE_OPTS \"-Dforge.home=${FORGE_HOME}\" -cp \"${FORGE_HOME}/lib/*\" $FORGE_MAIN_CLASS"
forge_exec_cmd="\"$JAVACMD\" $FORGE_DEBUG_ARGS $FORGE_OPTS \"-Dforge.home=${FORGE_HOME}\" \
\"-Dorg.jboss.forge.log.file=${FORGE_HOME}/log/forge.log\" \
\"-Dlogging.configuration=file:${FORGE_HOME}/logging.properties\" \
-cp \"${FORGE_HOME}/lib/*\" $FORGE_MAIN_CLASS"

eval $forge_exec_cmd "$QUOTED_ARGS"
5 changes: 4 additions & 1 deletion dist/src/main/resources/bin/forge.bat
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ goto runForge
@REM Start Forge
:runForge
set FORGE_MAIN_CLASS=org.jboss.forge.bootstrap.Bootstrap
%FORGE_JAVA_EXE% %FORGE_DEBUG_ARGS% %FORGE_OPTS% "-Dforge.home=%FORGE_HOME%" -cp "%FORGE_HOME%\lib\*" %FORGE_MAIN_CLASS%
%FORGE_JAVA_EXE% %FORGE_DEBUG_ARGS% %FORGE_OPTS% "-Dforge.home=%FORGE_HOME%" ^
"-Dorg.jboss.forge.log.file=%FORGE_HOME%\log\forge.log" ^
"-Dlogging.configuration=file:%FORGE_HOME%\logging.properties" ^
-cp "%FORGE_HOME%\lib\*" %FORGE_MAIN_CLASS%
if ERRORLEVEL 1 goto error
goto end

Expand Down
58 changes: 58 additions & 0 deletions dist/src/main/resources/logging.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# JBoss, Home of Professional Open Source.
# Copyright 2013, Red Hat, Inc., and individual contributors
# as indicated by the @author tags. See the copyright.txt file in the
# distribution for a full listing of individual contributors.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
#

# Additional loggers to configure (the root logger is always configured)
loggers=

logger.level=INFO
# Add CONSOLE to the comma delimited list if console output is wanted
logger.handlers=FILE

# Console handler
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.level=INFO
handler.CONSOLE.formatter=CONSOLE
handler.CONSOLE.properties=autoFlush,target
handler.CONSOLE.autoFlush=true
handler.CONSOLE.target=SYSTEM_OUT

# Rotating handler
handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.FILE.level=ALL
handler.FILE.formatter=PATTERN
handler.FILE.properties=autoFlush,append,fileName,suffix
handler.FILE.constructorProperties=fileName,append
handler.FILE.autoFlush=true
handler.FILE.append=true
handler.FILE.fileName=${org.jboss.forge.log.file:forge.log}
handler.FILE.suffix=.yyyy-MM-dd

# Format for the console. The %K{level} is for colorized output
formatter.CONSOLE=org.jboss.logmanager.formatters.PatternFormatter
formatter.CONSOLE.properties=pattern
formatter.CONSOLE.pattern=%K{level}%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%E%n

# Default pattern formatter
formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.constructorProperties=pattern
formatter.PATTERN.pattern=%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%E%n
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<version.arquillian>1.0.3.Final</version.arquillian>
<version.arquillian.container>1.0.0.CR5</version.arquillian.container>
<version.cdi>1.1-20130305</version.cdi>
<version.org.jboss.logmanager.jboss-logmanager>1.4.1.Final</version.org.jboss.logmanager.jboss-logmanager>
<version.jboss.spec>3.0.1.Final</version.jboss.spec>
<version.jboss.modules>1.1.3.GA</version.jboss.modules>
<version.junit>4.11</version.junit>
Expand Down Expand Up @@ -139,6 +140,13 @@
<version>${version.slf4j}</version>
</dependency>

<!-- JBoss Logging dependencies -->
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
<version>${version.org.jboss.logmanager.jboss-logmanager}</version>
</dependency>

<dependency>
<groupId>org.jboss.modules</groupId>
<artifactId>jboss-modules</artifactId>
Expand Down

0 comments on commit e09292d

Please sign in to comment.