Merge pull request #89 from gnodet/fix-mvn

Fix mvn
This commit is contained in:
Peter Palaga
2020-10-14 10:37:32 +02:00
committed by GitHub
22 changed files with 576 additions and 62 deletions

View File

@@ -0,0 +1,24 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
main is org.apache.maven.cli.MavenCli from plexus.core
set maven.conf default ${maven.home}/conf
[plexus.core]
load ${maven.conf}/logging
optionally ${maven.home}/lib/ext/*.jar
load ${maven.home}/lib/*.jar

201
daemon/src/main/distro/bin/mvn Executable file
View File

@@ -0,0 +1,201 @@
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# -----------------------------------------------------------------------------
# Apache Maven Startup Script
#
# Environment Variable Prerequisites
#
# JAVA_HOME Must point at your Java Development Kit installation.
# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
# -----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
mingw=false;
case "`uname`" in
CYGWIN*) cygwin=true;;
MINGW*) mingw=true;;
esac
## resolve links - $0 may be a link to Maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
MAVEN_HOME=`dirname "$PRG"`/..
# make it fully qualified
MAVEN_HOME=`cd "$MAVEN_HOME" && pwd`
cd "$saveddir"
# For Cygwin, ensure paths are in Unix format before anything is touched
if $cygwin ; then
[ -n "$MAVEN_HOME" ] &&
MAVEN_HOME=`cygpath --unix "$MAVEN_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For MinGW, ensure paths are in Unix format before anything is touched
if $mingw ; then
[ -n "$MAVEN_HOME" ] &&
MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`(cd "$JAVA_HOME"; pwd)`
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ] ; then
JAVACMD=`which java`
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
echo "The JAVA_HOME environment variable is not defined correctly" >&2
echo "This environment variable is needed to run this program" >&2
echo "NB: JAVA_HOME should point to a JDK not a JRE" >&2
exit 1
fi
CLASSWORLDS_JAR=`echo "${MAVEN_HOME}"/boot/plexus-classworlds-*.jar`
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
[ -n "$MAVEN_HOME" ] &&
MAVEN_HOME=`cygpath --path --windows "$MAVEN_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$CLASSWORLDS_JAR" ] &&
CLASSWORLDS_JAR=`cygpath --path --windows "$CLASSWORLDS_JAR"`
fi
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
(
basedir=`find_file_argument_basedir "$@"`
wdir="${basedir}"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
wdir=`cd "$wdir/.."; pwd`
done
echo "${basedir}"
)
}
find_file_argument_basedir() {
(
basedir=`pwd`
found_file_switch=0
for arg in "$@"; do
if [ ${found_file_switch} -eq 1 ]; then
if [ -d "${arg}" ]; then
basedir=`cd "${arg}" && pwd -P`
elif [ -f "${arg}" ]; then
basedir=`dirname "${arg}"`
basedir=`cd "${basedir}" && pwd -P`
if [ ! -d "${basedir}" ]; then
echo "Directory ${basedir} extracted from the -f/--file command-line argument ${arg} does not exist" >&2
exit 1
fi
else
echo "POM file ${arg} specified with the -f/--file command line argument does not exist" >&2
exit 1
fi
break
fi
if [ "$arg" = "-f" -o "$arg" = "--file" ]; then
found_file_switch=1
fi
done
echo "${basedir}"
)
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "`tr -s '\r\n' ' ' < "$1"`"
fi
}
MAVEN_PROJECTBASEDIR="${MAVEN_BASEDIR:-`find_maven_basedir "$@"`}"
MAVEN_OPTS="`concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config"` $MAVEN_OPTS"
# For Cygwin, switch project base directory path to Windows format before
# executing Maven otherwise this will cause Maven not to consider it.
if $cygwin ; then
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
export MAVEN_PROJECTBASEDIR
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "${CLASSWORLDS_JAR}" \
"-Dlogback.configurationFile=${MAVEN_HOME}/conf/logging/logback-mvn.xml" \
"-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
"-Dmvnd.home=${MAVEN_HOME}" \
"-Dmaven.home=${MAVEN_HOME}" \
"-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${CLASSWORLDS_LAUNCHER} "$@"

View File

@@ -17,5 +17,187 @@
# specific language governing permissions and limitations
# under the License.
"`dirname "$0"`/mvn" --builder smart --threads 8 --define buildtime.output.log --define maven.logging=smart "$@"
# -----------------------------------------------------------------------------
# Apache Maven Startup Script
#
# Environment Variable Prerequisites
#
# JAVA_HOME Must point at your Java Development Kit installation.
# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
# -----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
mingw=false;
case "`uname`" in
CYGWIN*) cygwin=true;;
MINGW*) mingw=true;;
esac
## resolve links - $0 may be a link to Maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
MAVEN_HOME=`dirname "$PRG"`/..
# make it fully qualified
MAVEN_HOME=`cd "$MAVEN_HOME" && pwd`
cd "$saveddir"
# For Cygwin, ensure paths are in Unix format before anything is touched
if $cygwin ; then
[ -n "$MAVEN_HOME" ] &&
MAVEN_HOME=`cygpath --unix "$MAVEN_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For MinGW, ensure paths are in Unix format before anything is touched
if $mingw ; then
[ -n "$MAVEN_HOME" ] &&
MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`(cd "$JAVA_HOME"; pwd)`
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ] ; then
JAVACMD=`which java`
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
echo "The JAVA_HOME environment variable is not defined correctly" >&2
echo "This environment variable is needed to run this program" >&2
echo "NB: JAVA_HOME should point to a JDK not a JRE" >&2
exit 1
fi
CLASSWORLDS_JAR=`echo "${MAVEN_HOME}"/boot/plexus-classworlds-*.jar`
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
[ -n "$MAVEN_HOME" ] &&
MAVEN_HOME=`cygpath --path --windows "$MAVEN_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$CLASSWORLDS_JAR" ] &&
CLASSWORLDS_JAR=`cygpath --path --windows "$CLASSWORLDS_JAR"`
fi
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
(
basedir=`find_file_argument_basedir "$@"`
wdir="${basedir}"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
wdir=`cd "$wdir/.."; pwd`
done
echo "${basedir}"
)
}
find_file_argument_basedir() {
(
basedir=`pwd`
found_file_switch=0
for arg in "$@"; do
if [ ${found_file_switch} -eq 1 ]; then
if [ -d "${arg}" ]; then
basedir=`cd "${arg}" && pwd -P`
elif [ -f "${arg}" ]; then
basedir=`dirname "${arg}"`
basedir=`cd "${basedir}" && pwd -P`
if [ ! -d "${basedir}" ]; then
echo "Directory ${basedir} extracted from the -f/--file command-line argument ${arg} does not exist" >&2
exit 1
fi
else
echo "POM file ${arg} specified with the -f/--file command line argument does not exist" >&2
exit 1
fi
break
fi
if [ "$arg" = "-f" -o "$arg" = "--file" ]; then
found_file_switch=1
fi
done
echo "${basedir}"
)
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "`tr -s '\r\n' ' ' < "$1"`"
fi
}
MAVEN_PROJECTBASEDIR="${MAVEN_BASEDIR:-`find_maven_basedir "$@"`}"
MAVEN_OPTS="`concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config"` $MAVEN_OPTS"
# For Cygwin, switch project base directory path to Windows format before
# executing Maven otherwise this will cause Maven not to consider it.
if $cygwin ; then
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
export MAVEN_PROJECTBASEDIR
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "${CLASSWORLDS_JAR}" \
"-Dlogback.configurationFile=${MAVEN_HOME}/conf/logging/logback.xml" \
-Dmvnd.logging=mvns \
"-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
"-Dmvnd.home=${MAVEN_HOME}" \
"-Dmaven.home=${MAVEN_HOME}" \
"-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${CLASSWORLDS_LAUNCHER} --builder smart --threads 0.5C "$@"

View File

@@ -0,0 +1,42 @@
<!--
Copyright 2020 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
| Local developer build logging configuration.
| * console log shows overall info+ build messages and project errors
| * overall build.log file includes all build log messages
| * project-specific build.log files include corresponding project build log messages
-->
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator" />
<!--
| write project-specific build log messages to ${project.build.directory}/build.log files
-->
<appender name="CONSOLE" class="org.apache.maven.cli.logging.SimpleAppender" />
<logger name="Sisu" level="INFO" />
<!-- suppress annoying @threadSafe and checksum failure warning messages -->
<logger name="org.apache.maven.lifecycle.internal.builder.BuilderCommon" level="ERROR" />
<logger name="org.eclipse.aether.internal.impl.WarnChecksumPolicy" level="ERROR" />
<root level="${consoleLevel:-info}">
<appender-ref ref="CONSOLE" />
</root>
</configuration>

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.maven.cli.logging;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.pattern.ThrowableProxyConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.CoreConstants;
import static org.apache.maven.shared.utils.logging.MessageUtils.level;
public class SimpleAppender extends AppenderBase<ILoggingEvent> {
@Override
protected void append(ILoggingEvent eventObject) {
StringBuilder buf = new StringBuilder();
buf.append('[');
buf.append(renderLevel(eventObject.getLevel()));
buf.append(']');
buf.append(' ');
buf.append(eventObject.getFormattedMessage());
buf.append(CoreConstants.LINE_SEPARATOR);
IThrowableProxy tp = eventObject.getThrowableProxy();
if (tp != null) {
buf.append(CoreConstants.LINE_SEPARATOR);
buf.append(new ThrowableProxyConverter().convert(eventObject));
}
System.out.print(buf.toString());
}
private String renderLevel(Level level) {
switch (level.toInt()) {
case Level.TRACE_INT:
return level().debug("TRACE");
case Level.DEBUG_INT:
return level().debug("DEBUG");
case Level.INFO_INT:
return level().info("INFO");
case Level.WARN_INT:
return level().warning("WARNING");
case Level.ERROR_INT:
return level().error("ERROR");
default:
throw new IllegalStateException("Level " + level + " is unknown.");
}
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.fuse.mvnd.logging.internal;
import org.apache.maven.cli.logging.Slf4jConfiguration;
public class MvndSlf4jConfiguration implements Slf4jConfiguration {
@Override
public void setRootLoggerLevel(Level level) {
}
@Override
public void activate() {
}
}

View File

@@ -34,7 +34,12 @@ public abstract class AbstractLoggingSpy extends AbstractEventSpy {
public static AbstractLoggingSpy instance() {
if (instance == null) {
instance = new MavenLoggingSpy();
if ("mvns".equals(System.getProperty("mvnd.logging", "mvn"))) {
instance = new MavenLoggingSpy();
} else {
instance = new AbstractLoggingSpy() {
};
}
}
return instance;
}
@@ -112,32 +117,23 @@ public abstract class AbstractLoggingSpy extends AbstractEventSpy {
protected void onStartProject(String projectId, String display) {
MDC.put(KEY_PROJECT_ID, projectId);
update();
}
protected void onStopProject(String projectId, String display) {
MDC.put(KEY_PROJECT_ID, projectId);
update();
MDC.remove(KEY_PROJECT_ID);
}
protected void onStartMojo(String projectId, String display) {
Slf4jLogger.setCurrentProject(projectId);
MDC.put(KEY_PROJECT_ID, projectId);
update();
}
protected void onStopMojo(String projectId, String display) {
MDC.put(KEY_PROJECT_ID, projectId);
update();
}
protected void onProjectLog(String projectId, String message) {
MDC.put(KEY_PROJECT_ID, projectId);
update();
}
protected void update() {
}
private String getProjectId(ExecutionEvent event) {

View File

@@ -15,22 +15,11 @@
*/
package org.jboss.fuse.mvnd.logging.smart;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.jline.terminal.Size;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import org.jline.utils.AttributedString;
import org.jline.utils.Display;
import org.jboss.fuse.mvnd.common.logging.TerminalOutput;
public class MavenLoggingSpy extends AbstractLoggingSpy {
private Map<String, String> projects = new LinkedHashMap<>();
private Terminal terminal;
private Display display;
private TerminalOutput output;
public MavenLoggingSpy() {
}
@@ -38,61 +27,43 @@ public class MavenLoggingSpy extends AbstractLoggingSpy {
@Override
public void init(Context context) throws Exception {
super.init(context);
terminal = (Terminal) context.getData().get("terminal");
if (terminal == null) {
terminal = TerminalBuilder.terminal();
}
display = new Display(terminal, false);
output = new TerminalOutput(null);
}
@Override
public void close() throws Exception {
display.update(Collections.emptyList(), 0);
terminal.flush();
terminal.close();
terminal = null;
display = null;
output.close();
super.close();
}
@Override
protected void onStartProject(String projectId, String display) {
projects.put(projectId, display);
super.onStartProject(projectId, display);
output.projectStateChanged(projectId, display);
}
@Override
protected void onStopProject(String projectId, String display) {
projects.remove(projectId);
output.projectFinished(projectId);
super.onStopProject(projectId, display);
}
@Override
protected void onStartMojo(String projectId, String display) {
projects.put(projectId, display);
super.onStartMojo(projectId, display);
output.projectStateChanged(projectId, display);
}
@Override
protected void onStopMojo(String projectId, String display) {
projects.put(projectId, display);
output.projectStateChanged(projectId, ":" + projectId);
super.onStopMojo(projectId, display);
}
@Override
protected void onProjectLog(String projectId, String message) {
super.onProjectLog(projectId, message);
}
protected void update() {
Size size = terminal.getSize();
display.resize(size.getRows(), size.getColumns());
List<AttributedString> lines = new ArrayList<>();
lines.add(new AttributedString("Building..."));
for (String build : projects.values()) {
lines.add(new AttributedString(build));
}
display.update(lines, -1);
output.accept(projectId, message);
}
}

View File

@@ -16,4 +16,4 @@
# key = Slf4j effective logger factory implementation
# value = corresponding o.a.m.cli.logging.Slf4jConfiguration class
ch.qos.logback.classic.LoggerContext org.jboss.fuse.mvnd.logging.logback.internal.InadequateSlf4jConfiguration
ch.qos.logback.classic.LoggerContext org.jboss.fuse.mvnd.logging.internal.MvndSlf4jConfiguration