-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rationalize logging subsystem #400
Changes from all commits
b334867
a2b849a
f6dc795
5596f1d
1b7dd8d
a8b1208
4a3add8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,8 @@ | |
<properties> | ||
<changelist>999999-SNAPSHOT</changelist> | ||
<gitHubRepo>jenkinsci/plugin-compat-tester</gitHubRepo> | ||
<logbackVersion>1.4.5</logbackVersion> | ||
<maven.scm.providers.version>1.6</maven.scm.providers.version> | ||
<slf4j.version>2.0.6</slf4j.version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we now need to define this version for both |
||
<spotbugs.effort>Max</spotbugs.effort> | ||
</properties> | ||
|
||
|
@@ -46,27 +46,12 @@ | |
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>2.0.6</version> | ||
<version>${slf4j.version}</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consuming the new property in the original consumer. It will also be consumed later on in a new consumer ( |
||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-access</artifactId> | ||
<version>${logbackVersion}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>${logbackVersion}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
<version>${logbackVersion}</version> | ||
</dependency> | ||
Comment on lines
-55
to
-69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the removal of Logback this is no longer needed and has therefore been deleted. |
||
<dependency> | ||
<groupId>com.beust</groupId> | ||
<artifactId>jcommander</artifactId> | ||
|
@@ -77,6 +62,11 @@ | |
<artifactId>maven-scm-provider-svnjava</artifactId> | ||
<version>1.12</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jenkins.lib</groupId> | ||
<artifactId>support-log-formatter</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
Comment on lines
+65
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using our standard project-wide JUL formatter for consistency with Jenkins core and other Jenkins components. |
||
<dependency> | ||
<groupId>jakarta.servlet</groupId> | ||
<artifactId>jakarta.servlet-api</artifactId> | ||
|
@@ -205,6 +195,10 @@ | |
<groupId>commons-jelly</groupId> | ||
<artifactId>commons-jelly-tags-xml</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>io.jenkins.stapler</groupId> | ||
<artifactId>jenkins-stapler-support</artifactId> | ||
|
@@ -338,6 +332,11 @@ | |
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-jdk14</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
basil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
|
@@ -370,7 +369,7 @@ | |
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.3.0</version> | ||
<!-- Version specified in parent POM --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated minor cleanup: I noticed this version was redundant while adding the new entry for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
|
@@ -417,6 +416,17 @@ | |
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<!-- Version specified in parent POM --> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<java.util.logging.config.class>org.jenkins.tools.test.logging.LoggingConfiguration</java.util.logging.config.class> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed to get the tests to use our custom logging configuration, which is useful when debugging tests in an IDE. For production this is enabled by a static initializer in |
||
</systemPropertyVariables> | ||
<runOrder>alphabetical</runOrder> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated code cleanup: getting the tests to be run in a consistent order. The plugin parent POM has this, but the |
||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
import org.codehaus.plexus.PlexusContainerException; | ||
import org.jenkins.tools.test.logging.LoggingConfiguration; | ||
import org.jenkins.tools.test.model.PluginCompatTesterConfig; | ||
import org.jenkins.tools.test.exception.PomExecutionException; | ||
import org.jenkins.tools.test.model.TestStatus; | ||
|
@@ -47,6 +48,14 @@ | |
*/ | ||
public class PluginCompatTesterCli { | ||
|
||
static { | ||
String configFile = System.getProperty("java.util.logging.config.file"); | ||
String configClass = System.getProperty("java.util.logging.config.class"); | ||
if (configClass == null && configFile == null) { | ||
new LoggingConfiguration(); | ||
} | ||
} | ||
Comment on lines
+51
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed to get production to use our custom logging configuration (I tried to find a way to add a |
||
|
||
@SuppressFBWarnings( | ||
value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", | ||
justification = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import org.apache.maven.scm.ScmException; | ||
import org.apache.maven.scm.ScmFileSet; | ||
|
@@ -22,10 +24,12 @@ | |
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout; | ||
|
||
/** | ||
* Utility class to ease create simple hooks for multimodule projects | ||
* Utility class to ease create simple hooks for multi-module projects | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Maven documentation (not that it is a particularly consistent source of correct spelling) spells this with a hyphen, so do the same here. |
||
*/ | ||
public abstract class AbstractMultiParentHook extends PluginCompatTesterHookBeforeCheckout { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(AbstractMultiParentHook.class.getName()); | ||
|
||
protected boolean firstRun = true; | ||
|
||
private PomData pomData; | ||
|
@@ -40,10 +44,10 @@ public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception | |
boolean shouldExecuteHook = config.getLocalCheckoutDir() == null || !config.getLocalCheckoutDir().exists(); | ||
|
||
if (shouldExecuteHook) { | ||
System.out.println("Executing Hook for " + getParentProjectName()); | ||
LOGGER.log(Level.INFO, "Executing hook for {0}", getParentProjectName()); | ||
// Determine if we need to run the download; only run for first identified plugin in the series | ||
if (firstRun) { | ||
System.out.println("Preparing for Multimodule checkout"); | ||
LOGGER.log(Level.INFO, "Preparing for multi-module checkout"); | ||
|
||
// Checkout to the parent directory. All other processes will be on the child directory | ||
File parentPath = new File(config.workDirectory.getAbsolutePath() + "/" + getParentFolder()); | ||
|
@@ -52,10 +56,10 @@ public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception | |
String scmTag; | ||
if (pomData.getScmTag() != null) { | ||
scmTag = pomData.getScmTag(); | ||
System.out.println(String.format("Using SCM tag '%s' from POM.", scmTag)); | ||
LOGGER.log(Level.INFO, "Using SCM tag {0} from POM", scmTag); | ||
} else { | ||
scmTag = getParentProjectName() + "-" + currentPlugin.version; | ||
System.out.println(String.format("POM did not provide an SCM tag. Inferring tag '%s'.", scmTag)); | ||
LOGGER.log(Level.INFO, "POM did not provide an SCM tag; inferring tag {0}", scmTag); | ||
} | ||
// Like PluginCompatTester.cloneFromSCM but with subdirectories trimmed: | ||
cloneFromSCM(currentPlugin, parentPath, scmTag, getUrl(), config.getFallbackGitHubOrganization()); | ||
|
@@ -68,7 +72,7 @@ public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception | |
// Change the "download"" directory; after download, it's simply used for reference | ||
File childPath = new File(config.workDirectory.getAbsolutePath() + "/" + getParentFolder() + "/" + getPluginFolderName(currentPlugin)); | ||
|
||
System.out.println("Child path for " + currentPlugin.getDisplayName() + " " + childPath); | ||
LOGGER.log(Level.INFO, "Child path for {0}: {1}", new Object[]{currentPlugin.getDisplayName(), childPath.getPath()}); | ||
moreInfo.put("checkoutDir", childPath); | ||
moreInfo.put("pluginDir", childPath); | ||
moreInfo.put("parentFolder", getParentFolder()); | ||
|
@@ -96,7 +100,7 @@ private void cloneFromSCM(UpdateSite.Plugin currentPlugin, File parentPath, Stri | |
if (connectionURL != null) { | ||
connectionURL = connectionURL.replace("git://", "https://"); // See: https://github.blog/2021-09-01-improving-git-protocol-security-github/ | ||
} | ||
System.out.println("Checking out from SCM connection URL: " + connectionURL + " (" + getParentProjectName() + "-" + currentPlugin.version + ") at tag " + scmTag); | ||
LOGGER.log(Level.INFO, "Checking out from SCM connection URL {0}: {1} ({2}-{3}) at tag {4}", new Object[]{connectionURL, getParentProjectName(), currentPlugin.version, scmTag}); | ||
if (parentPath.isDirectory()) { | ||
FileUtils.deleteDirectory(parentPath); | ||
} | ||
|
@@ -122,11 +126,11 @@ public String getUrl() { | |
|
||
protected void configureLocalCheckOut(UpdateSite.Plugin currentPlugin, File localCheckoutDir, Map<String, Object> moreInfo) { | ||
// Do nothing to keep compatibility with pre-existing Hooks | ||
System.out.println("Ignoring localCheckoutDir for " + currentPlugin.getDisplayName()); | ||
LOGGER.log(Level.INFO, "Ignoring local checkout directory for {0}", currentPlugin.getDisplayName()); | ||
} | ||
|
||
/** | ||
* Returns the folder where the multimodule project parent will be checked out | ||
* Returns the folder where the multi-module project parent will be checked out | ||
*/ | ||
protected abstract String getParentFolder(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import org.apache.maven.scm.ScmFileSet; | ||
import org.apache.maven.scm.ScmTag; | ||
import org.apache.maven.scm.command.checkout.CheckOutScmResult; | ||
|
@@ -18,9 +20,11 @@ | |
* each plugin is in its own repository, these plugins automatically fail since they are "not | ||
* found". | ||
* | ||
* <p>This is an example of what needs to change to handle multimodule parents. | ||
* <p>This is an example of what needs to change to handle multi-module parents. | ||
*/ | ||
public class ExampleMultiParent { //extends PluginCompatTesterHookBeforeCheckout { | ||
private static final Logger LOGGER = Logger.getLogger(ExampleMultiParent.class.getName()); | ||
|
||
private String parentUrl = "scm:git:[email protected]:jenkinsci/parent_repo.git"; | ||
private String parentName = "parent_repo"; | ||
private List<String> allBundlePlugins = List.of("possible", "plugins"); | ||
|
@@ -49,12 +53,12 @@ public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception | |
|
||
// Determine if we need to run the download; only run for first identified plugin in the series | ||
if(firstRun){ | ||
System.out.println("Preparing for Multimodule checkout."); | ||
LOGGER.log(Level.INFO, "Preparing for multi-module checkout"); | ||
|
||
// Checkout to the parent directory. All other processes will be on the child directory | ||
File parentPath = new File(config.workDirectory.getAbsolutePath()+"/"+parentName); | ||
|
||
System.out.println("Checking out from SCM connection URL : "+parentUrl+" ("+parentName+"-"+currentPlugin.version+")"); | ||
LOGGER.log(Level.INFO, "Checking out from SCM connection URL: {0} ({1}-{2})", new Object[]{parentUrl, parentName, currentPlugin.version}); | ||
ScmManager scmManager = SCMManagerFactory.getInstance().createScmManager(); | ||
ScmRepository repository = scmManager.makeScmRepository(parentUrl); | ||
CheckOutScmResult result = scmManager.checkOut(repository, new ScmFileSet(parentPath), new ScmTag(parentName+"-"+currentPlugin.version)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,13 @@ | |
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class NodeCleanupBeforeCompileHook extends PluginCompatTesterHookBeforeCompile { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(NodeCleanupBeforeCompileHook.class.getName()); | ||
|
||
@Override | ||
public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception { | ||
PluginCompatTesterConfig config = (PluginCompatTesterConfig) moreInfo.get("config"); | ||
|
@@ -18,16 +22,15 @@ public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception | |
if (shouldExecuteHook) { | ||
File pluginDir = (File) moreInfo.get("pluginDir"); | ||
try { | ||
System.out.println("Executing node and node_modules cleanup hook"); | ||
LOGGER.log(Level.INFO, "Executing node and node_modules cleanup hook"); | ||
compile(pluginDir); | ||
return moreInfo; | ||
} catch (Exception e) { | ||
System.out.println("Exception executing hook"); | ||
System.out.println(e); | ||
LOGGER.log(Level.WARNING, "Exception executing hook", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All this logging and throwing is itself an anti-pattern that could be cleaned up in a future PR that deals with error handling and propagation, but is explicitly out of scope for this PR. |
||
throw e; | ||
} | ||
} else { | ||
System.out.println("Hook not triggered. Continuing."); | ||
LOGGER.log(Level.INFO, "Hook not triggered; continuing"); | ||
return moreInfo; | ||
} | ||
} | ||
|
@@ -37,7 +40,7 @@ public void validate(Map<String, Object> toCheck) { | |
} | ||
|
||
private void compile(File path) throws IOException { | ||
System.out.println("Calling removeNodeFolders"); | ||
LOGGER.log(Level.INFO, "Calling removeNodeFolders"); | ||
removeNodeFolders(path); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the removal of Logback this is no longer needed and has therefore been deleted.