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

FIXED #13: Test trend result chart not shown on inherited project #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Plik stworzony dnia 11 kwi 2014 przez krzysztofkos
*
* Copyright ATREM S.A. ATREM 2014(C)
*/

package hudson.plugins.project_inheritance.projects.inheritance;

import hudson.Extension;

@Extension
public class BuildPageInheritanceChecker extends RequestInheritanceChecker {

/**
*
* Checks if given URI is job build page
*/
@Override
public boolean isInheritanceRequired(String requestURI) {
boolean isBuildPageUri = requestURI.endsWith("/build");
return isBuildPageUri;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Plik stworzony dnia 11 kwi 2014 przez krzysztofkos
*
* Copyright ATREM S.A. ATREM 2014(C)
*/

package hudson.plugins.project_inheritance.projects.inheritance;

import hudson.Extension;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Extension
public class DashboardViewInheritanceChecker extends RequestInheritanceChecker {

public static final Pattern portletImageUriRegExp = Pattern
.compile(".*/view/[^/]+/portlet/dashboard_portlet_\\d+/.*");

public static final Pattern viewUriRegExp = Pattern.compile(".*/view/[^/]+/?");

/**
* Checks if given request comes from view main page or from dashboard portlet.
*/
@Override
public boolean isInheritanceRequired(String requestURI) {
boolean isPortletImage = isPortletImageURI(requestURI);
boolean isViewRoot = isViewRootURI(requestURI);
return isViewRoot || isPortletImage;
}

private boolean isViewRootURI(String requestURI) {
Matcher dashboardViewUriMatcher = viewUriRegExp.matcher(requestURI);
boolean isDashboardView = dashboardViewUriMatcher.matches();
return isDashboardView;
}

private boolean isPortletImageURI(String requestURI) {
Matcher portletImageUriMatcher = portletImageUriRegExp.matcher(requestURI);
boolean isPortletImage = portletImageUriMatcher.matches();
return isPortletImage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import hudson.model.Describable;
import hudson.model.Saveable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.Project;
import hudson.model.Queue;
import hudson.plugins.project_inheritance.projects.InheritanceProject;
Expand Down Expand Up @@ -64,8 +65,6 @@
* @param <T> the target type of the field this helper is written for.
*/
public abstract class InheritanceGovernor<T> {
public static final Pattern runUriRegExp = Pattern.compile(".*/job/[^/]+/[0-9]+/.*");

public final String fieldName;
public final SELECTOR orderMode;
public final InheritanceProject caller;
Expand Down Expand Up @@ -439,20 +438,26 @@ public static boolean inheritanceLookupRequired(InheritanceProject root, boolean
StaplerRequest req = Stapler.getCurrentRequest();
if (req != null) {
String uri = req.getRequestURI();
//Check if we request the build page
if (uri.endsWith("/build")) {
return true;
}
//Check if we were requested by page for a run
if (runUriRegExp.matcher(uri).matches()) {
return true;
}
if (inheritanceRequiredByRequestURI(uri)) {
return true;
}
}

//in all other cases, we don't require (or want) inheritance
return false;
}

private static boolean inheritanceRequiredByRequestURI(String uri) {
List<RequestInheritanceChecker> list = Hudson.getInstance().getExtensionList(
RequestInheritanceChecker.class);
for (RequestInheritanceChecker requestInheritanceChecker : list) {
if (requestInheritanceChecker.isInheritanceRequired(uri)) {
return true;
}
}
return false;
}

/**
* This method uses reflection to tell whether the current state means
* that versioning is needed or not.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Plik stworzony dnia 11 kwi 2014 przez krzysztofkos
*
* Copyright ATREM S.A. ATREM 2014(C)
*/

package hudson.plugins.project_inheritance.projects.inheritance;

import hudson.Extension;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Extension
public class JobViewInheritanceChecker extends RequestInheritanceChecker {

private static final String JOB_MAIN_VIEW_REGEX = ".*/job/[^/]+/";

private static final String JOB_RUN_PAGE_REGEX = "[0-9]+/.*";

private static final String TEST_TREND_GRAPH_REGEX = "test/trend(Map)?";

private static final String FINDBUGS_TREND_GRAPH_REGEX = "findbugs/trendGraph/(png|map)";

private static final String JACOCO_TREND_GRAPH_REGEX = "jacoco/graph";

public static final Pattern jobUriRegExp;

static {
StringBuilder regExpBuilder = new StringBuilder();
regExpBuilder.append(JOB_MAIN_VIEW_REGEX);
regExpBuilder.append("(");
regExpBuilder.append(JOB_RUN_PAGE_REGEX);
regExpBuilder.append("|");
regExpBuilder.append(TEST_TREND_GRAPH_REGEX);
regExpBuilder.append("|");
regExpBuilder.append(FINDBUGS_TREND_GRAPH_REGEX);
regExpBuilder.append("|");
regExpBuilder.append(JACOCO_TREND_GRAPH_REGEX);
regExpBuilder.append(")?");
jobUriRegExp = Pattern.compile(regExpBuilder.toString());
}

/**
* Checks if given URI is job main page or one of its specified subpages.
*/
@Override
public boolean isInheritanceRequired(String requestURI) {
Matcher matcher = jobUriRegExp.matcher(requestURI);
return matcher.matches();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Plik stworzony dnia 11 kwi 2014 przez krzysztofkos
*
* Copyright ATREM S.A. ATREM 2014(C)
*/

package hudson.plugins.project_inheritance.projects.inheritance;

import hudson.ExtensionPoint;

/**
* Allows to decide if inheritance is required during processing request.
*
* @author krzysztofkos
*
*/
public abstract class RequestInheritanceChecker implements ExtensionPoint {

/**
* Decides if inheritance is required during processing request. This decision is
* based on given request URI.
*
* @param requestURI
* URI of the request being processed
* @return <code>true</code> if inheritance is needed, <code>false</code> otherwise.
*/
public abstract boolean isInheritanceRequired(String requestURI);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Plik stworzony dnia 11 kwi 2014 przez krzysztofkos
*
* Copyright ATREM S.A. ATREM 2014(C)
*/

package hudson.plugins.project_inheritance.projects.inheritance;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class BuildPageInheritanceCheckerTest {
@Test
public void isInheritanceRequired_buildPageURI_retunsTrue() {
BuildPageInheritanceChecker checker = new BuildPageInheritanceChecker();
String requestUri = "http://server_name/job/JobName/build";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Plik stworzony dnia 11 kwi 2014 przez krzysztofkos
*
* Copyright ATREM S.A. ATREM 2014(C)
*/

package hudson.plugins.project_inheritance.projects.inheritance;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class DashboardViewInheritanceSelectorTest {

@Test
public void isInheritanceRequired_dashboardViewURI_retunsTrue() {
DashboardViewInheritanceChecker checker = new DashboardViewInheritanceChecker();
String requestUri = "http://server_name/view/ViewName/";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

@Test
public void isInheritanceRequired_dashboardViewURIWithoutTrailingSlash_retunsTrue() {
DashboardViewInheritanceChecker checker = new DashboardViewInheritanceChecker();
String requestUri = "http://server_name/view/ViewName";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

@Test
public void isInheritanceRequired_protletImageURI_retunsTrue() {
DashboardViewInheritanceChecker checker = new DashboardViewInheritanceChecker();
String requestUri = "http://server_name/view/ViewName/portlet/dashboard_portlet_6911/summaryGraph/png";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Plik stworzony dnia 11 kwi 2014 przez krzysztofkos
*
* Copyright ATREM S.A. ATREM 2014(C)
*/

package hudson.plugins.project_inheritance.projects.inheritance;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class JobViewInheritanceCheckerTest {

@Test
public void isInheritanceRequired_specificBuildPageURI_retunsTrue() {
JobViewInheritanceChecker checker = new JobViewInheritanceChecker();
String requestUri = "http://server_name/job/JobName/1/";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

@Test
public void isInheritanceRequired_notJobURI_retunsFalse() {
JobViewInheritanceChecker checker = new JobViewInheritanceChecker();
String requestUri = "http://server_name/anything/";
boolean result = checker.isInheritanceRequired(requestUri);
assertFalse(result);
}

@Test
public void isInheritanceRequired_specificBuildSubpageURI_retunsTrue() {
JobViewInheritanceChecker checker = new JobViewInheritanceChecker();
String requestUri = "http://server_name/job/JobName/1/anyPage";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

@Test
public void isInheritanceRequired_jobMainPageURI_retunsTrue() {
JobViewInheritanceChecker checker = new JobViewInheritanceChecker();
String requestUri = "http://server_name/job/JobName/";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

@Test
public void isInheritanceRequired_testTrendChartURI_retunsTrue() {
JobViewInheritanceChecker checker = new JobViewInheritanceChecker();
String requestUri = "http://server_name/job/JobName/test/trend";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

@Test
public void isInheritanceRequired_testTrendLazyMapURI_retunsTrue() {
JobViewInheritanceChecker checker = new JobViewInheritanceChecker();
String requestUri = "http://server_name/job/JobName/test/trendMap";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

@Test
public void isInheritanceRequired_findbugsTrendChartURI_retunsTrue() {
JobViewInheritanceChecker checker = new JobViewInheritanceChecker();
String requestUri = "http://server_name/job/JobName/findbugs/trendGraph/png";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

@Test
public void isInheritanceRequired_findbugsTrendLazyMapURI_retunsTrue() {
JobViewInheritanceChecker checker = new JobViewInheritanceChecker();
String requestUri = "http://server_name/job/JobName/findbugs/trendGraph/map";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

@Test
public void isInheritanceRequired_jacocoTrendChartURI_retunsTrue() {
JobViewInheritanceChecker checker = new JobViewInheritanceChecker();
String requestUri = "http://server_name/job/JobName/jacoco/graph";
boolean result = checker.isInheritanceRequired(requestUri);
assertTrue(result);
}

@Test
public void isInheritanceRequired_otherJobSubpageURI_retunsFalse() {
JobViewInheritanceChecker checker = new JobViewInheritanceChecker();
String requestUri = "http://server_name/job/JobName/other";
boolean result = checker.isInheritanceRequired(requestUri);
assertFalse(result);
}
}