-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
eschleb
committed
Oct 1, 2024
0 parents
commit b119a9a
Showing
18 changed files
with
1,124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: release and deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
release: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: '0' | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 17 | ||
- name: Maven setup | ||
uses: s4u/[email protected] | ||
with: | ||
servers: | | ||
[{ | ||
"id": "magnolia.enterprise.group", | ||
"username": "${{secrets.MGNL_NEXUS_USER}}", | ||
"password": "${{secrets.MGNL_NEXUS_PASS}}" | ||
}] | ||
- name: Maven verify | ||
run: mvn verify --batch-mode | ||
# Install xmllint | ||
- name: Install dependencies | ||
run: sudo apt-get update && sudo apt-get install libxml2-utils | ||
# Set git user name and email | ||
- name: Set up Git | ||
run: | | ||
chmod +x ci/setup-git.sh | ||
ci/setup-git.sh | ||
# Release, set correct versions and create tag | ||
- name: Release (versioning/tag) | ||
run: | | ||
chmod +x ci/mvn-release.sh | ||
ci/mvn-release.sh | ||
deploy-release: | ||
|
||
needs: release | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: 'main' | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
server-id: central | ||
server-username: MAVEN_USERNAME | ||
server-password: MAVEN_PASSWORD | ||
gpg-passphrase: MAVEN_GPG_PASSPHRASE | ||
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} | ||
- name: Release Maven package | ||
run: mvn deploy -Pdeploy | ||
env: | ||
MAVEN_USERNAME: ${{ secrets.SONATYPE_USER }} | ||
MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} | ||
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: verify | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- main | ||
|
||
jobs: | ||
verify: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
- name: Maven setup | ||
uses: s4u/[email protected] | ||
with: | ||
servers: | | ||
[{ | ||
"id": "magnolia.enterprise.group", | ||
"username": "${{secrets.MGNL_NEXUS_USER}}", | ||
"password": "${{secrets.MGNL_NEXUS_PASS}}" | ||
}] | ||
- name: Maven verify | ||
run: mvn verify --batch-mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
# Magnolia SpringRenderer | ||
|
||
The spring renderer module makes the Spring-Framework available for Magnolia. <bR> | ||
Recommended to be used with [dynamic builders modules](https://github.com/merkle-open/magnolia-dynamic-builders). | ||
|
||
## Requirements | ||
* Java 17 | ||
* Magnolia >= 6.3 | ||
|
||
## Setup | ||
|
||
### Add Maven dependency: | ||
```xml | ||
<dependency> | ||
<groupId>com.merkle.oss.magnolia</groupId> | ||
<artifactId>magnolia-spring-renderer</artifactId> | ||
<version>0.0.1</version> | ||
</dependency> | ||
``` | ||
|
||
### Spring dispatcher-servlet | ||
Create config: | ||
```java | ||
import info.magnolia.rendering.renderer.FreemarkerRenderer; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
|
||
import com.merkle.oss.magnolia.renderer.spring.MagnoliaHandlerMethodArgumentResolver; | ||
import com.merkle.oss.magnolia.renderer.spring.MagnoliaTemplateView; | ||
import com.merkle.oss.magnolia.renderer.spring.cache.DisableCacheHandlerInterceptorAdapter; | ||
|
||
@Configuration | ||
public class SpringRendererServletConfiguration extends WebMvcConfigurationSupport { | ||
|
||
@Override | ||
protected void addArgumentResolvers(final List<HandlerMethodArgumentResolver> argumentResolvers) { | ||
argumentResolvers.add(new MagnoliaHandlerMethodArgumentResolver()); | ||
} | ||
|
||
@Override | ||
protected void addInterceptors(final InterceptorRegistry registry) { | ||
registry.addInterceptor(new DisableCacheHandlerInterceptorAdapter()); | ||
} | ||
|
||
@Bean | ||
public MagnoliaTemplateView.Resolver viewResolver() { | ||
return new MagnoliaTemplateView.Resolver(FreemarkerRenderer.class); | ||
} | ||
|
||
... | ||
} | ||
``` | ||
|
||
Create DispatcherServletProvider: | ||
```java | ||
import info.magnolia.cms.util.CustomServletConfig; | ||
import info.magnolia.objectfactory.Components; | ||
|
||
import java.util.Collections; | ||
|
||
import javax.inject.Inject; | ||
import javax.servlet.ServletContext; | ||
|
||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; | ||
import org.springframework.web.servlet.DispatcherServlet; | ||
|
||
import com.machinezoo.noexception.Exceptions; | ||
import com.merkle.oss.magnolia.renderer.spring.DispatcherServletProvider; | ||
|
||
public class SpringRendererDispatcherServletProvider implements DispatcherServletProvider { | ||
private final DispatcherServlet dispatcherServlet; | ||
|
||
@Inject | ||
public SpringRendererDispatcherServletProvider() { | ||
dispatcherServlet = Components.newInstance(DispatcherServlet.class); | ||
dispatcherServlet.setContextConfigLocation(SpringRendererServletConfiguration.class.getName()); | ||
dispatcherServlet.setContextClass(AnnotationConfigWebApplicationContext.class); | ||
Exceptions.wrap().run(() -> dispatcherServlet.init(new CustomServletConfig("springRenderer", Components.getComponent(ServletContext.class), Collections.emptyMap()))); | ||
} | ||
|
||
@Override | ||
public DispatcherServlet get() { | ||
return dispatcherServlet; | ||
} | ||
} | ||
``` | ||
|
||
Add guice binding: | ||
```xml | ||
<component> | ||
<type>com.merkle.oss.magnolia.renderer.spring.DispatcherServletProvider</type> | ||
<implementation>com.somepackage.SpringRendererDispatcherServletProvider</implementation> | ||
<scope>singleton</scope> | ||
</component> | ||
``` | ||
|
||
## How to use | ||
Create a spring controller with one requestHandler method that matches the id of the template. | ||
|
||
## Example | ||
### Component-template | ||
|
||
```java | ||
import javax.jcr.Node; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
|
||
import com.merkle.oss.magnolia.renderer.spring.SpringRenderer; | ||
import com.merkle.oss.magnolia.templatebuilder.annotation.Template; | ||
|
||
@Template( | ||
id = SomeComponent.ID, | ||
title = "templates.components." + SomeComponent.NAME + ".title", | ||
dialog = SomeComponentDialog.ID, | ||
description = "templates.components." + SomeComponent.NAME + ".description", | ||
renderer = SpringRenderer.NAME | ||
//templateScript is provided dynamically in render method below!! | ||
) | ||
@Controller | ||
public class SomeComponent extends BaseComponent { | ||
public static final String NAME = "SomeComponent"; | ||
public static final String ID = "SomeApp:components/" + NAME; | ||
|
||
@RequestMapping(ID) | ||
public String render(final Model model, final Node node) { | ||
model.addAttribute("someComponentAttribute", "someValue"); | ||
return "/someModule/templates/components/somePage.ftl"; | ||
} | ||
} | ||
``` | ||
### Page-template with area | ||
|
||
```java | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import javax.inject.Inject; | ||
import javax.jcr.Node; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
|
||
import com.merkle.oss.magnolia.templatebuilder.annotation.Available; | ||
import com.merkle.oss.magnolia.templatebuilder.annotation.Template; | ||
import com.merkle.oss.magnolia.templatebuilder.annotation.area.Area; | ||
import com.merkle.oss.magnolia.templatebuilder.annotation.area.AvailableComponentClasses; | ||
import com.merkle.oss.magnolia.templatebuilder.annotation.area.AvailableComponents; | ||
|
||
@Template( | ||
id = SomePage.ID, | ||
title = "templates.pages." + SomePage.NAME + ".title", | ||
dialog = SomePageDialog.ID, | ||
description = "templates.pages." + SomePage.NAME + ".description", | ||
renderer = "freemarker" | ||
//templateScript is provided dynamically in render method below!! | ||
) | ||
@Controller | ||
public class SomePage { | ||
public static final String NAME = "SomePage"; | ||
public static final String ID = "SomeApp:pages/" + NAME; | ||
|
||
@Available | ||
public boolean isAvailable(final Node node) { | ||
//TODO implement | ||
return true; | ||
} | ||
|
||
@RequestMapping(ID) | ||
public String render(final Model model, final Node node) { | ||
model.addAttribute("somePageAttribute", "someValue"); | ||
return "/someModule/templates/pages/somePage.ftl"; | ||
} | ||
|
||
@Area( | ||
id = ContentArea.ID, | ||
name = ContentArea.NAME, | ||
title = "templates.areas." + SomePage.ContentArea.NAME + ".title" | ||
//templateScript is provided dynamically in render method below!! | ||
) | ||
@AvailableComponentClasses({ SomeComponent.class }) | ||
@Controller | ||
public static class ContentArea { | ||
public static final String NAME = "ContentArea"; | ||
public static final String ID = SomePage.ID + "/" + NAME; | ||
|
||
@RequestMapping(ID) | ||
public String render(final Model model, final Node node) { | ||
model.addAttribute("someAreaAttribute", "someValue"); | ||
return "/someModule/templates/areas/contentArea.ftl"; | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Customization | ||
### HandlerMethodArgumentResolver | ||
Implement and bind a different HandlerMethodArgumentResolver if necessary (see spring config). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
CURRENT_VERSION=`xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml` | ||
|
||
if [[ $CURRENT_VERSION == *-SNAPSHOT ]]; then | ||
NEW_VERSION=${CURRENT_VERSION%'-SNAPSHOT'} | ||
NEXT_VERSION=`bash ci/semver.sh -p $NEW_VERSION` | ||
NEXT_SNAPSHOT="$NEXT_VERSION-SNAPSHOT" | ||
echo "perform release of $NEW_VERSION from $CURRENT_VERSION and set next develop version $NEXT_SNAPSHOT" | ||
|
||
mvn versions:set -DnewVersion=$NEW_VERSION versions:commit --no-transfer-progress | ||
|
||
echo "commit new release version" | ||
git commit -a -m "Release $NEW_VERSION: set main to new release version" | ||
|
||
echo "Update version in README.md" | ||
sed -i -e "s|<version>[0-9A-Za-z._-]\{1,\}</version>|<version>$NEW_VERSION</version>|g" README.md && rm -f README.md-e | ||
git commit -a -m "Release $NEW_VERSION: Update README.md" | ||
|
||
echo "create tag for new release" | ||
git tag -a $NEW_VERSION -m "Release $NEW_VERSION: tag release" | ||
|
||
echo "merge main back to develop" | ||
git fetch --all | ||
git checkout develop | ||
git merge main | ||
|
||
mvn versions:set -DnewVersion=$NEXT_SNAPSHOT versions:commit --no-transfer-progress | ||
|
||
echo "commit new snapshot version" | ||
git commit -a -m "Release $NEW_VERSION: set develop to next development version $NEXT_SNAPSHOT" | ||
|
||
git push --all | ||
git push --tags | ||
fi |
Oops, something went wrong.