Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/on-code-change.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jahia/jahia-modules-action/static-analysis@v2
- uses: jahia/jahia-modules-action/static-analysis@add-checkstyle-to-static-analysis-github-action
with:
node_version: 20
yarn_version: 4.7.0
yarn_test_version: 4.7.0
auditci_level: critical

github_token: ${{ secrets.GH_API_TOKEN }}
build:
name: Build Module
runs-on: self-hosted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,80 +38,80 @@
*/
@Component(immediate = true)
public class JavascriptModuleListener implements BundleListener {
private static final Logger logger = LoggerFactory.getLogger(JavascriptModuleListener.class);
private GraalVMEngine engine;
private final Queue<Registrar> registrars = new ConcurrentLinkedQueue<>();

@Reference(cardinality = ReferenceCardinality.MANDATORY)
public void setEngine(GraalVMEngine engine) {
this.engine = engine;
}

@Reference(service = Registrar.class, policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE, policyOption = ReferencePolicyOption.GREEDY)
public void addRegistrar(Registrar registrar) {
for (Bundle bundle : getJavascriptModules()) {
registrar.register(bundle);
}

registrars.add(registrar);
}

public void removeRegistrar(Registrar registrar) {
registrars.remove(registrar);

for (Bundle bundle : getJavascriptModules()) {
registrar.unregister(bundle);
}
}

@Activate
public void activate(BundleContext context) {
for (Bundle bundle : getJavascriptModules()) {
engine.enableJavascriptModule(bundle);
}

context.addBundleListener(this);
}

@Deactivate
public void deactivate(BundleContext context) {
context.removeBundleListener(this);

for (Bundle bundle : getJavascriptModules()) {
engine.disableJavascriptModule(bundle);
}
}

@Override
public void bundleChanged(BundleEvent event) {
try {
Bundle bundle = event.getBundle();
if (isJavascriptModule(bundle)) {
if (event.getType() == BundleEvent.STARTED) {
engine.enableJavascriptModule(bundle);
for (Registrar registrar : registrars) {
registrar.register(bundle);
}
} else if (event.getType() == BundleEvent.STOPPED) {
for (Registrar registrar : registrars) {
registrar.unregister(bundle);
}
engine.disableJavascriptModule(bundle);
}
}
} catch (Exception e) {
logger.error("Cannot handle event {}", event.toString(), e);
}
}

public List<Bundle> getJavascriptModules() {
return Arrays.stream(engine.getBundleContext().getBundles())
.filter(bundle -> bundle.getState() == Bundle.ACTIVE && isJavascriptModule(bundle))
.collect(Collectors.toList());
}

public boolean isJavascriptModule(Bundle bundle) {
return bundle.getBundleId() != engine.getBundleContext().getBundle().getBundleId() &&
bundle.getHeaders().get(BUNDLE_HEADER_JAVASCRIPT_INIT_SCRIPT) != null;
}
private static final Logger logger = LoggerFactory.getLogger(JavascriptModuleListener.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

private GraalVMEngine engine;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

private final Queue<Registrar> registrars = new ConcurrentLinkedQueue<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.


@Reference(cardinality = ReferenceCardinality.MANDATORY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

public void setEngine(GraalVMEngine engine) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

this.engine = engine;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.


@Reference(service = Registrar.class, policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE, policyOption = ReferencePolicyOption.GREEDY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

public void addRegistrar(Registrar registrar) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

for (Bundle bundle : getJavascriptModules()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

registrar.register(bundle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.


registrars.add(registrar);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.


public void removeRegistrar(Registrar registrar) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

registrars.remove(registrar);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.


for (Bundle bundle : getJavascriptModules()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

registrar.unregister(bundle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.


@Activate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

public void activate(BundleContext context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

for (Bundle bundle : getJavascriptModules()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

engine.enableJavascriptModule(bundle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.


context.addBundleListener(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.


@Deactivate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

public void deactivate(BundleContext context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.

context.removeBundleListener(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck> reported by reviewdog 🐶
Line contains a tab character.


for (Bundle bundle : getJavascriptModules()) {
engine.disableJavascriptModule(bundle);
}
}

@Override
public void bundleChanged(BundleEvent event) {
try {
Bundle bundle = event.getBundle();
if (isJavascriptModule(bundle)) {
if (event.getType() == BundleEvent.STARTED) {
engine.enableJavascriptModule(bundle);
for (Registrar registrar : registrars) {
registrar.register(bundle);
}
} else if (event.getType() == BundleEvent.STOPPED) {
for (Registrar registrar : registrars) {
registrar.unregister(bundle);
}
engine.disableJavascriptModule(bundle);
}
}
} catch (Exception e) {
logger.error("Cannot handle event {}", event.toString(), e);
}
}

public List<Bundle> getJavascriptModules() {
return Arrays.stream(engine.getBundleContext().getBundles())
.filter(bundle -> bundle.getState() == Bundle.ACTIVE && isJavascriptModule(bundle))
.collect(Collectors.toList());
}

public boolean isJavascriptModule(Bundle bundle) {
return bundle.getBundleId() != engine.getBundleContext().getBundle().getBundleId() &&
bundle.getHeaders().get(BUNDLE_HEADER_JAVASCRIPT_INIT_SCRIPT) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ else if (packageRelativePath.equals("settings/template-thumbnail.png")) {
jos.putNextEntry(new ZipEntry("images/template-preview/" + StringUtils.substringAfter(packageRelativePath, "settings/")));
}
// Map everything else in settings/ to META-INF/
else {
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck> reported by reviewdog 🐶
'else' construct must use '{}'s.

jos.putNextEntry(new ZipEntry("META-INF/" + StringUtils.substringAfter(packageRelativePath, "settings/")));
}
} else if (packageRelativePath.startsWith("components") && packageRelativePath.endsWith(".png")) {
String[] parts = StringUtils.split(packageRelativePath, "/");
String nodeTypeName = parts[2];
Expand Down
Loading