Skip to content

Commit

Permalink
Allow for better overriding of the logging configuration. Remove conf…
Browse files Browse the repository at this point in the history
…iguration settings from the scripts and add to the bootstrap.
  • Loading branch information
jamezp committed Mar 21, 2013
1 parent 9c29a99 commit 444e3f6
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 7 deletions.
6 changes: 6 additions & 0 deletions bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<groupId>org.jboss.forge</groupId>
<artifactId>forge-addon-container</artifactId>
</dependency>
<!-- Optional log manager dependency -->
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
<optional>true</optional>
</dependency>

</dependencies>

Expand Down
39 changes: 37 additions & 2 deletions bootstrap/src/main/java/org/jboss/forge/bootstrap/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.logging.Logger;

Expand All @@ -24,6 +25,7 @@
import org.jboss.forge.container.impl.AddonRepositoryImpl;
import org.jboss.forge.container.repositories.AddonRepository;
import org.jboss.forge.container.repositories.MutableAddonRepository;
import org.jboss.forge.container.util.OperatingSystemUtils;
import org.jboss.forge.dependencies.Coordinate;
import org.jboss.forge.dependencies.builder.CoordinateBuilder;
import org.jboss.forge.dependencies.builder.DependencyQueryBuilder;
Expand All @@ -47,13 +49,46 @@ public class Bootstrap

public static void main(final String[] args)
{
final List<String> bootstrapArgs = new ArrayList<String>();
final Properties systemProperties = System.getProperties();
// Set system properties
for (String arg : args)
{
if (arg.startsWith("-D"))
{
final String name;
final String value;
final int index = arg.indexOf("=");
if (index == -1)
{
name = arg.substring(2);
value = "true";
} else
{
name = arg.substring(2, index);
value = arg.substring(index + 1);
}
systemProperties.setProperty(name, value);
}
else
{
bootstrapArgs.add(arg);
}
}

// Check for the forge log directory
final String logDir = systemProperties.getProperty("org.jboss.forge.log.file",
new File(OperatingSystemUtils.getUserForgeDir(), "log/forge.log").getAbsolutePath());
// Ensure this value is always set
systemProperties.setProperty("org.jboss.forge.log.file", logDir);

// 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);
systemProperties.setProperty("java.util.logging.manager", logManagerName);
}
Bootstrap bootstrap = new Bootstrap(args);
Bootstrap bootstrap = new Bootstrap(bootstrapArgs.toArray(new String[bootstrapArgs.size()]));
bootstrap.start();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.
*/

package org.jboss.forge.bootstrap;

import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.jboss.forge.container.util.OperatingSystemUtils;
import org.jboss.logmanager.ConfigurationLocator;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
public class LoggingConfigurationLocator implements ConfigurationLocator
{
static final FilenameFilter LOGGING_CONFIG_FILTER = new FilenameFilter()
{
@Override
public boolean accept(final File dir, final String name)
{
return name.equals("logging.properties");
}
};

@Override
public InputStream findConfiguration() throws IOException
{
// First look for the property
final String propLoc = System.getProperty("logging.configuration");
if (propLoc != null) try
{
return new URL(propLoc).openStream();
} catch (IOException e)
{
System.err.printf("Unable to read the logging configuration from '%s' (%s)%n", propLoc, e);
}
File[] files = null;
// Second attempt to find the configuration in the users .forge directory
final File userForgeDir = OperatingSystemUtils.getUserForgeDir();
// Look for a logging.properties file
if (userForgeDir.isDirectory())
{
files = userForgeDir.listFiles(LOGGING_CONFIG_FILTER);
if (files != null && files.length > 0)
{
return new FileInputStream(files[0]);
}
}
// Finally default to $FORGE_HOME/logging.properties
final File forgeHomeDir = OperatingSystemUtils.getForgeHomeDir();
// Look for a logging.properties file
if (forgeHomeDir.isDirectory())
{
files = forgeHomeDir.listFiles(LOGGING_CONFIG_FILTER);
}
// If the file was found, return it, otherwise return null
if (files != null && files.length > 0)
{
return new FileInputStream(files[0]);
}
System.err.println("No logging configuration was found.");
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.jboss.forge.bootstrap.LoggingConfigurationLocator
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public static boolean isLinux()
return getOsName().startsWith("Linux") || getOsName().startsWith("linux");
}

public static File getForgeHomeDir()
{
return new File(System.getProperty("forge.home")).getAbsoluteFile();
}

public static File getUserHomeDir()
{
return new File(System.getProperty("user.home")).getAbsoluteFile();
Expand All @@ -51,6 +56,11 @@ public static String getUserHomePath()
return getUserHomeDir().getAbsolutePath();
}

public static File getUserForgeDir()
{
return new File(getUserHomeDir(), ".forge").getAbsoluteFile();
}

public static void setPretendWindows(boolean value)
{
PRETEND_WINDOWS = value;
Expand Down
2 changes: 0 additions & 2 deletions dist/src/main/resources/bin/forge
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ if $cygwin; then
fi

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"
4 changes: 1 addition & 3 deletions dist/src/main/resources/bin/forge.bat
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ goto runForge
:runForge
set FORGE_MAIN_CLASS=org.jboss.forge.bootstrap.Bootstrap
%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%
-cp "%FORGE_HOME%\lib\*" %FORGE_MAIN_CLASS% %FORGE_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end

Expand Down

0 comments on commit 444e3f6

Please sign in to comment.