Skip to content

Commit

Permalink
Merge pull request #11 from timja/namespaced
Browse files Browse the repository at this point in the history
Add live theme switching support
  • Loading branch information
timbrown5 authored and jonesbusy committed Mar 19, 2022
2 parents 8355e18 + d0d55a1 commit 61030c4
Show file tree
Hide file tree
Showing 30 changed files with 4,560 additions and 599 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
light-theme.css
target

# mvn hpi:run
work

# IntelliJ IDEA project files
*.iml
*.iws
*.ipr
.idea

# Eclipse project files
.settings
.classpath
.project

# VS code project files
.vscode
>>>>>>> Add grey and light blue theme
7 changes: 7 additions & 0 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.3</version>
</extension>
</extensions>
2 changes: 2 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-Pconsume-incrementals
-Pmight-produce-incrementals
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ This should allow Jenkins administrators to easily switch themes and allow users

[![Screenshot jenkins-material-red main](screenshots/indigo_main_small.png)](screenshots/indigo_main_large.png)

'Grey':

[![Screenshot jenkins-material-red main](screenshots/grey_main_small.png)](screenshots/grey_main_large.png)

'Light Blue':

[![Screenshot jenkins-material-red main](screenshots/light_blue_main_small.png)](screenshots/light_blue_main_large.png)


## Installation
To install this theme search for 'Material theme' in your Jenkins update center.

Expand All @@ -31,7 +40,7 @@ Or with the [configuration-as-code](https://github.com/jenkinsci/configuration-a
unclassified:
themeManager:
disableUserThemes: true
theme: "material-indigo" # or 'material-red'
theme: "material-indigo" # or 'material-red' or 'material-grey' or 'material-light-blue'
```
## Running (development)
Expand Down
26 changes: 14 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.2</version>
<version>4.37</version>
<relativePath />
</parent>
<groupId>io.jenkins.plugins</groupId>
<artifactId>material-theme</artifactId>
<version>0.4.2-SNAPSHOT</version>
<version>${revision}${changelist}</version>
<packaging>hpi</packaging>
<properties>
<revision>0.5.0</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/material-theme-plugin</gitHubRepo>
<revision>0.4.1</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.289.1</jenkins.version>
<jenkins.version>2.336</jenkins.version>
<java.level>8</java.level>
<tagNameFormat>@{project.version}</tagNameFormat>
<useBeta>true</useBeta>
Expand All @@ -25,8 +28,8 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.222.x</artifactId>
<version>10</version>
<artifactId>bom-2.332.x</artifactId>
<version>1155.v77b_fd92a_26fc</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand All @@ -37,7 +40,7 @@
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>theme-manager</artifactId>
<version>0.1</version>
<version>1.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -67,9 +70,9 @@
</developers>

<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
</scm>

Expand Down Expand Up @@ -98,8 +101,7 @@
<wroFile>${basedir}/src/main/config/wro.xml</wroFile>
<extraConfigFile>${basedir}/src/main/config/wro.properties</extraConfigFile>
<targetGroups>light-theme</targetGroups>
<cssDestinationFolder>${project.build.directory}/../src/main/resources/io/jenkins/plugins/materialtheme/style/</cssDestinationFolder>
<jsDestinationFolder>${project.build.directory}/../src/main/resources/io/jenkins/plugins/materialtheme/script/</jsDestinationFolder>
<cssDestinationFolder>${project.build.directory}/../src/main/webapp/</cssDestinationFolder>
<contextFolder>${basedir}/src/main/webapp/</contextFolder>
<ignoreMissingResources>true</ignoreMissingResources>
</configuration>
Expand Down
Binary file added screenshots/grey_main_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/grey_main_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/light_blue_main_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/light_blue_main_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.jenkins.plugins.materialtheme;

import io.jenkins.plugins.thememanager.Theme;
import io.jenkins.plugins.thememanager.ThemeManagerFactory;
import java.util.Arrays;

public class AbstractMaterialTheme extends ThemeManagerFactory {

public static final String BASE_CSS = "light-theme.css";
public static final String CUSTOMISED_CSS = "material-theme.css";

@Override
public Theme getTheme() {
return Theme.builder().withCssUrls(
Arrays.asList(toAssetUrl(BASE_CSS), getCssUrl(), toAssetUrl(CUSTOMISED_CSS)))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.jenkins.plugins.materialtheme;

import io.jenkins.plugins.thememanager.ThemeManagerFactoryDescriptor;

public abstract class AbstractMaterialThemeDescriptor extends ThemeManagerFactoryDescriptor {
public static final String ID = "material";

@Override
public String getThemeId() {
return ID;
}

@Override
public boolean isNamespaced() {
return true;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.jenkins.plugins.materialtheme;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import io.jenkins.plugins.thememanager.Theme;
import io.jenkins.plugins.thememanager.ThemeManagerFactory;
import io.jenkins.plugins.thememanager.ThemeManagerFactoryDescriptor;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

public class MaterialGreyThemeManagerFactory extends ThemeManagerFactory {

public static final String MATERIAL_GREY_CSS = "theme-grey.css";
public static final String MATERIAL_GREY_SYMBOL = "material-grey";
// Seems like this needs to be 'theme-<descriptor_symbol>'
public static final String MATERIAL_GREY_URL_NAME = "theme-material-grey";

@DataBoundConstructor
public MaterialGreyThemeManagerFactory() {
}

@Override
public Theme getTheme() {
return Theme.builder()
.withCssUrl(getCssUrl())
.build();
}

@Extension
@Symbol(MATERIAL_GREY_SYMBOL)
public static class MaterialGreyThemeManagerFactoryDescriptor extends ThemeManagerFactoryDescriptor {

@NonNull
@Override
public String getDisplayName() {
return "Material - Grey";
}

@Override
public ThemeManagerFactory getInstance() {
return new MaterialGreyThemeManagerFactory();
}

@Override
public String getThemeCssSuffix() {
return MATERIAL_GREY_CSS;
}

@NonNull
@Override
public String getThemeId() {
return MATERIAL_GREY_SYMBOL;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@
import org.kohsuke.stapler.WebMethod;

import static io.jenkins.plugins.materialtheme.AbstractMaterialThemeRootAction.MATERIAL_THEME_CSS;
import static io.jenkins.plugins.materialtheme.MaterialRedThemeManagerFactory.MATERIAL_RED_CSS;
import static io.jenkins.plugins.materialtheme.MaterialRedThemeManagerFactory.MATERIAL_RED_URL_NAME;

import static io.jenkins.plugins.materialtheme.MaterialGreyThemeManagerFactory.MATERIAL_GREY_CSS;
import static io.jenkins.plugins.materialtheme.MaterialGreyThemeManagerFactory.MATERIAL_GREY_URL_NAME;

@Extension
@Restricted(NoExternalUse.class)
public class MaterialRedThemeRootAction extends AbstractMaterialThemeRootAction {
public class MaterialGreyThemeRootAction extends AbstractMaterialThemeRootAction {

@Override
public String getUrlName() {
return MATERIAL_RED_URL_NAME;
return MATERIAL_GREY_URL_NAME;
}

@Override
public String getThemeCss() throws IOException {
String base_css = this.readCssFile(MATERIAL_THEME_CSS);
base_css = base_css.replace("<MATERIAL_PRIMARY>", "#f44336");
base_css = base_css.replace("<MATERIAL_SECONDARY>", "#e76056");
base_css = base_css.replace("<MATERIAL_PRIMARY>", "#9E9E9E");
base_css = base_css.replace("<MATERIAL_SECONDARY>", "#696666");
return base_css;
}

@WebMethod(name = MATERIAL_RED_CSS)
@WebMethod(name = MATERIAL_GREY_CSS)
public void doMaterialRedoThemeCss(StaplerRequest req, StaplerResponse res) throws IOException {
this.doRedoThemeCss(req, res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,19 @@
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

public class MaterialIndigoThemeManagerFactory extends ThemeManagerFactory {
public class MaterialIndigoThemeManagerFactory extends AbstractMaterialTheme {

public static final String MATERIAL_INDIGO_CSS = "theme-indigo.css";
public static final String MATERIAL_INDIGO_SYMBOL = "material-indigo";
// Seems like this needs to be 'theme-<descriptor_symbol>'
public static final String MATERIAL_INDIGO_URL_NAME = "theme-material-indigo";

@DataBoundConstructor
public MaterialIndigoThemeManagerFactory() {
}

@Override
public Theme getTheme() {
return Theme.builder()
.withCssUrl(getCssUrl())
.build();
}


@Extension
@Symbol(MATERIAL_INDIGO_SYMBOL)
public static class MaterialIndigoThemeManagerFactoryDescriptor extends ThemeManagerFactoryDescriptor {
public static class MaterialIndigoThemeManagerFactoryDescriptor extends AbstractMaterialThemeDescriptor {

@NonNull
@Override
Expand All @@ -46,10 +38,9 @@ public String getThemeCssSuffix() {
return MATERIAL_INDIGO_CSS;
}

@NonNull
@Override
public String getThemeId() {
return MATERIAL_INDIGO_SYMBOL;
public String getThemeKey() {
return ID + "-indigo";
}
}
}
Loading

0 comments on commit 61030c4

Please sign in to comment.