Skip to content
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

JENKINS-54439 Jcasc compatibility #97

Merged
merged 37 commits into from Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cd5531d
Upgrade parent pom
timja May 13, 2019
1b28a47
Convert to global configuration
timja May 13, 2019
5027aa6
Mostly working
timja May 15, 2019
36e6435
Add test
timja May 16, 2019
95516b5
Hack it for now
timja May 16, 2019
2b7f141
Fix typo
timja May 16, 2019
93af67c
Check it is a local knowledge base
timja May 16, 2019
063e53f
Fix dropdown descriptor
timja May 19, 2019
da45f8b
Fix image url
timja May 19, 2019
f05fd6a
Add mongo db test
timja May 19, 2019
bd4e111
Fix convert
timja May 25, 2019
ed63042
Remove irrelevant test cases and fix convert
timja May 25, 2019
9afb41b
Remove unneeded defaults
timja May 25, 2019
3108eec
Remove unneeded alias
timja May 25, 2019
b3984ae
Add getters needed for jelly to work =/
timja May 25, 2019
2303376
Fix checkstyle
timja May 27, 2019
c6ed5f3
Upgrade checkstyle to allow using lambdas
timja May 27, 2019
a056a6f
Fix web test
timja May 27, 2019
e19691c
Fix other test
timja May 27, 2019
052e859
Fix most tests
timja May 27, 2019
971794b
Fix another test
timja May 28, 2019
9dcd436
Fix checkstyle
timja May 28, 2019
cd5be43
Fix null pointer
timja May 28, 2019
d86e755
Rerun CI
timja May 29, 2019
c91b881
Update src/test/java/com/sonyericsson/jenkins/plugins/bfa/jcasc/Confi…
timja Jun 20, 2019
2246e08
Merge branch 'master' into feature/jcasc-compatibility
timja Jun 20, 2019
3813f5d
Merge branch 'feature/jcasc-compatibility' of github.com:timja/build-…
timja Jun 20, 2019
178a2fb
Remove load from start method
timja Jun 20, 2019
5e6a587
Use Jenkins XSTREAM instance
timja Jun 20, 2019
ed66f4a
Fix imports
timja Jun 20, 2019
3881e99
No null Sod variables please
timja Jun 20, 2019
c95114f
Fix checkstyle
timja Jun 20, 2019
742e1e4
Fix classloader issue
timja Jun 20, 2019
9c9a98c
Convert sodVariables to describable
timja Jun 21, 2019
396c4be
Merge branch 'master' into feature/jcasc-compatibility
timja Jun 24, 2019
1076b6b
Merge branch 'master' into feature/jcasc-compatibility
timja Jun 27, 2019
2a75a78
Restore test
timja Jun 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions pom.xml
Expand Up @@ -20,6 +20,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<powermock.version>1.6.6</powermock.version>
<checkstyle.version>3.1.0</checkstyle.version>
<configuration-as-code.version>1.20</configuration-as-code.version>
</properties>

<licenses>
Expand Down Expand Up @@ -166,6 +167,20 @@
<version>3.6</version>
</dependency>

<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>${configuration-as-code.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>${configuration-as-code.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
Expand Down
237 changes: 103 additions & 134 deletions src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java
Expand Up @@ -31,33 +31,39 @@
import com.sonyericsson.jenkins.plugins.bfa.model.ScannerJobProperty;
import com.sonyericsson.jenkins.plugins.bfa.sod.ScanOnDemandQueue;
import com.sonyericsson.jenkins.plugins.bfa.sod.ScanOnDemandVariables;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.Plugin;
import hudson.PluginManager;
import hudson.PluginWrapper;
import hudson.model.Descriptor;
import hudson.XmlFile;
import hudson.init.InitMilestone;
import hudson.init.Initializer;
import hudson.init.Terminator;
import hudson.model.Hudson;
import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;
import hudson.security.Permission;
import hudson.security.PermissionGroup;
import hudson.util.CopyOnWriteList;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import jenkins.model.GlobalConfiguration;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* The main thing.
*
* @author Robert Sandell &lt;robert.sandell@sonyericsson.com&gt;
*/
public class PluginImpl extends Plugin {
@Extension
@Symbol("buildFailureAnalyzer")
public class PluginImpl extends GlobalConfiguration {
timja marked this conversation as resolved.
Show resolved Hide resolved

private static final Logger logger = Logger.getLogger(PluginImpl.class.getName());

Expand Down Expand Up @@ -113,8 +119,6 @@ public class PluginImpl extends Plugin {
private static final String DEFAULT_NO_CAUSES_MESSAGE = "No problems were identified. "
+ "If you know why this problem occurred, please add a suitable Cause for it.";

private static String staticResourcesBase = null;

/**
* Minimum allowed value for {@link #nrOfScanThreads}.
*/
Expand Down Expand Up @@ -142,13 +146,41 @@ public class PluginImpl extends Plugin {
/**
* ScanOnDemandVariable instance.
*/
private ScanOnDemandVariables sodVariables;
private ScanOnDemandVariables sodVariables = new ScanOnDemandVariables();

/**
* Default constructor.
*/
@DataBoundConstructor
public PluginImpl() {
load();
timja marked this conversation as resolved.
Show resolved Hide resolved
}

protected Object readResolve() {
if (sodVariables == null) {
this.sodVariables = new ScanOnDemandVariables();
}

return this;
}

/**
* {@inheritDoc}
*/
@Override
public void start() throws Exception {
super.start();
public XmlFile getConfigFile() {
return new XmlFile(
Jenkins.XSTREAM,
new File(Jenkins.getInstance().getRootDir(), "build-failure-analyzer.xml")
); // for backward compatibility
}

/**
* Starts the knowledge base.
*/
@Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED)
public void start() {
logger.finer("[BFA] Starting...");
load();
if (noCausesMessage == null) {
noCausesMessage = DEFAULT_NO_CAUSES_MESSAGE;
}
Expand All @@ -158,27 +190,6 @@ public void start() throws Exception {
if (nrOfScanThreads < 1) {
nrOfScanThreads = DEFAULT_NR_OF_SCAN_THREADS;
}
sodVariables = new ScanOnDemandVariables();
if (sodVariables.getMinimumSodWorkerThreads() < 1) {
sodVariables.setMinimumSodWorkerThreads(ScanOnDemandVariables.
DEFAULT_MINIMUM_SOD_WORKER_THREADS);
}
if (sodVariables.getMaximumSodWorkerThreads() < 1) {
sodVariables.setMaximumSodWorkerThreads(ScanOnDemandVariables.
DEFAULT_MAXIMUM_SOD_WORKER_THREADS);
}
if (sodVariables.getSodThreadKeepAliveTime() < 1) {
sodVariables.setSodThreadKeepAliveTime(ScanOnDemandVariables.
DEFAULT_SOD_THREADS_KEEP_ALIVE_TIME);
}
if (sodVariables.getSodWaitForJobShutdownTimeout() < 1) {
sodVariables.setSodWaitForJobShutdownTimeout(ScanOnDemandVariables.
DEFAULT_SOD_WAIT_FOR_JOBS_SHUTDOWN_TIMEOUT);
}
if (sodVariables.getSodCorePoolNumberOfThreads() < 1) {
sodVariables.setSodCorePoolNumberOfThreads(ScanOnDemandVariables.
DEFAULT_SOD_COREPOOL_THREADS);
}

if (knowledgeBase == null) {
if (causes == null) {
Expand All @@ -199,9 +210,11 @@ public void start() throws Exception {
}
}

@Override
public void stop() throws Exception {
super.stop();
/**
* Run on Jenkins shutdown.
*/
@Terminator
public void stop() {
ScanOnDemandQueue.shutdown();
knowledgeBase.stop();
}
Expand All @@ -212,22 +225,7 @@ public void stop() throws Exception {
* @return the base URI.
*/
public static String getStaticResourcesBase() {
if (staticResourcesBase == null) {
PluginManager pluginManager = Jenkins.getInstance().getPluginManager();
if (pluginManager != null) {
PluginWrapper wrapper = pluginManager.getPlugin(PluginImpl.class);
if (wrapper != null) {
staticResourcesBase = "/plugin/" + wrapper.getShortName();
}
}
//Did we really find it?
if (staticResourcesBase == null) {
//This is not the preferred way since the module name could change,
//But in some unit test cases we cannot reach the plug-in info.
return "/plugin/build-failure-analyzer";
}
}
return staticResourcesBase;
return "/plugin/build-failure-analyzer";
}

/**
Expand Down Expand Up @@ -303,16 +301,7 @@ public static String getDefaultIcon() {
*/
@Nonnull
public static PluginImpl getInstance() {
Jenkins jenkins = Jenkins.getInstance();
if (jenkins == null) {
throw new AssertionError("Jenkins is not here yet.");
}
PluginImpl plugin = jenkins.getPlugin(PluginImpl.class);
if (plugin == null) {
throw new AssertionError("Not here yet.");
} else {
return plugin;
}
return ExtensionList.lookup(PluginImpl.class).get(0);
}

/**
Expand Down Expand Up @@ -359,6 +348,42 @@ public boolean isGraphsEnabled() {
}
}

/**
* Sets if graphs are enabled.
* @param graphsEnabled the graph flag
*/
@DataBoundSetter
public void setGraphsEnabled(Boolean graphsEnabled) {
this.graphsEnabled = graphsEnabled;
}

/**
* Sets the no causes message.
* @param noCausesMessage the no causes message
*/
@DataBoundSetter
public void setNoCausesMessage(String noCausesMessage) {
this.noCausesMessage = noCausesMessage;
}

/**
* Sets the knowledge base.
* @param knowledgeBase the knowledge base
*/
@DataBoundSetter
public void setKnowledgeBase(KnowledgeBase knowledgeBase) {
this.knowledgeBase = knowledgeBase;
}

/**
* Sets the scan on demand variables.
* @param sodVariables the variables
*/
@DataBoundSetter
public void setSodVariables(ScanOnDemandVariables sodVariables) {
this.sodVariables = sodVariables;
}

/**
* If failed test cases should be represented as failure causes.
*
Expand Down Expand Up @@ -481,6 +506,10 @@ public void setMaxLogSize(int maxLogSize) {
* @return value
*/
public int getMaxLogSize() {
if (maxLogSize < 0) {
return DEFAULT_MAX_LOG_SIZE;
}

return maxLogSize;
}

Expand Down Expand Up @@ -576,83 +605,23 @@ public KnowledgeBase.KnowledgeBaseDescriptor getKnowledgeBaseDescriptor(String d


@Override
public void configure(StaplerRequest req, JSONObject o) throws Descriptor.FormException, IOException {
noCausesMessage = o.getString("noCausesMessage");
globalEnabled = o.getBoolean("globalEnabled");
doNotAnalyzeAbortedJob = o.optBoolean("doNotAnalyzeAbortedJob", false);
gerritTriggerEnabled = o.getBoolean("gerritTriggerEnabled");
graphsEnabled = o.getBoolean("graphsEnabled");
testResultParsingEnabled = o.getBoolean("testResultParsingEnabled");
testResultCategories = o.getString("testResultCategories");
maxLogSize = o.optInt("maxLogSize");
int scanThreads = o.getInt("nrOfScanThreads");
int minSodWorkerThreads = o.getInt("minimumNumberOfWorkerThreads");
int maxSodWorkerThreads = o.getInt("maximumNumberOfWorkerThreads");
int thrkeepAliveTime = o.getInt("threadKeepAliveTime");
int jobShutdownTimeWait = o.getInt("waitForJobShutdownTime");
int corePoolNumberOfThreads = o.getInt("corePoolNumberOfThreads");
if (scanThreads < MINIMUM_NR_OF_SCAN_THREADS) {
nrOfScanThreads = DEFAULT_NR_OF_SCAN_THREADS;
} else {
nrOfScanThreads = scanThreads;
}

if (maxLogSize < 0) {
maxLogSize = DEFAULT_MAX_LOG_SIZE;
}
public boolean configure(StaplerRequest req, JSONObject o) {
KnowledgeBase existingKb = this.knowledgeBase;
req.bindJSON(this, o);

if (corePoolNumberOfThreads < ScanOnDemandVariables.DEFAULT_SOD_COREPOOL_THREADS) {
sodVariables.setSodCorePoolNumberOfThreads(ScanOnDemandVariables.DEFAULT_SOD_COREPOOL_THREADS);
} else {
sodVariables.setSodCorePoolNumberOfThreads(corePoolNumberOfThreads);
}

if (jobShutdownTimeWait < ScanOnDemandVariables.DEFAULT_SOD_WAIT_FOR_JOBS_SHUTDOWN_TIMEOUT) {
sodVariables.setSodWaitForJobShutdownTimeout(ScanOnDemandVariables.
DEFAULT_SOD_WAIT_FOR_JOBS_SHUTDOWN_TIMEOUT);
} else {
sodVariables.setSodWaitForJobShutdownTimeout(jobShutdownTimeWait);
}
if (thrkeepAliveTime < ScanOnDemandVariables.DEFAULT_SOD_THREADS_KEEP_ALIVE_TIME) {
sodVariables.setSodThreadKeepAliveTime(ScanOnDemandVariables.DEFAULT_SOD_THREADS_KEEP_ALIVE_TIME);
} else {
sodVariables.setSodThreadKeepAliveTime(thrkeepAliveTime);
}
if (minSodWorkerThreads < ScanOnDemandVariables.DEFAULT_MINIMUM_SOD_WORKER_THREADS) {
sodVariables.setMinimumSodWorkerThreads(ScanOnDemandVariables.DEFAULT_MINIMUM_SOD_WORKER_THREADS);
} else {
sodVariables.setMinimumSodWorkerThreads(minSodWorkerThreads);
}
if (maxSodWorkerThreads < ScanOnDemandVariables.DEFAULT_MAXIMUM_SOD_WORKER_THREADS) {
sodVariables.setMaximumSodWorkerThreads(ScanOnDemandVariables.DEFAULT_MAXIMUM_SOD_WORKER_THREADS);
} else {
sodVariables.setMaximumSodWorkerThreads(maxSodWorkerThreads);
}
if (maxSodWorkerThreads < ScanOnDemandVariables.DEFAULT_MAXIMUM_SOD_WORKER_THREADS) {
sodVariables.setMaximumSodWorkerThreads(ScanOnDemandVariables.DEFAULT_MAXIMUM_SOD_WORKER_THREADS);
} else {
sodVariables.setMaximumSodWorkerThreads(maxSodWorkerThreads);
}
KnowledgeBase base = req.bindJSON(KnowledgeBase.class, o.getJSONObject("knowledgeBase"));
if (base != null && !knowledgeBase.equals(base)) {
try {
base.start();
} catch (Exception e) {
logger.log(Level.SEVERE, "Could not start new knowledge base, reverting ", e);
save();
return;
}
if (existingKb != null && !existingKb.equals(knowledgeBase)) {
if (o.getBoolean("convertOldKb")) {
try {
base.convertFrom(knowledgeBase);
knowledgeBase.start();
knowledgeBase.convertFrom(existingKb);
timja marked this conversation as resolved.
Show resolved Hide resolved
} catch (Exception e) {
logger.log(Level.SEVERE, "Could not convert knowledge base ", e);
}
knowledgeBase.stop();
}
knowledgeBase.stop();
knowledgeBase = base;
}

save();
return true;
}
}