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

BACKLOG-22357: Introduce new tooling to investigate import-package and export-package in the system #61

Merged
merged 6 commits into from
Feb 21, 2024
Merged
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
33 changes: 32 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
</scm>

<properties>
<jahia-depends/>
<jahia-module-type>system</jahia-module-type>
<jahia-static-resources>/css,/images,/javascript,/swf</jahia-static-resources>
<require-capability>osgi.extender;filter:="(osgi.extender=org.jahia.bundles.blueprint.extender.config)"</require-capability>
Expand Down Expand Up @@ -95,6 +96,27 @@
<version>${osgi.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jahia.modules</groupId>
<artifactId>graphql-dxm-provider</artifactId>
<version>2.7.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.github.graphql-java</groupId>
<artifactId>graphql-java-annotations</artifactId>
<version>${graphql-java-annotations.version}</version>
<scope>provided</scope>
</dependency>

<!-- Embed dependencies -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.utils</artifactId>
<version>${felix.utils.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -130,6 +152,13 @@
org.springframework.core.io,
org.springframework.core.io.support,
org.springframework.web.context,
graphql.annotations.annotationTypes;version="[7.2,99)";resolution:=optional,
graphql.schema;version="[13.0,22)";resolution:=optional,
org.jahia.modules.graphql.provider.dxm;version="[2.7,4)";resolution:=optional,
org.jahia.modules.graphql.provider.dxm.admin;version="[2.7,4)";resolution:=optional,
org.jahia.modules.graphql.provider.dxm.node;version="[2.7,4)";resolution:=optional,
org.jahia.modules.graphql.provider.dxm.osgi.annotations;version="[2.7,4)";resolution:=optional,
org.jahia.modules.graphql.provider.dxm.util;version="[2.7,4)";resolution:=optional,
${jahia.plugin.projectPackageImport},
*
</Import-Package>
Expand All @@ -145,8 +174,10 @@
org.jahia.modules.tools.probe.runtime.impl.*,
org.jahia.modules.tools.probe.statistics.impl.*,
org.jahia.modules.tools.modules.*,
org.jahia.modules.tools.karaf.*
org.jahia.modules.tools.karaf.*,
org.jahia.modules.tools.gql.*
</_dsannotations>
<Embed-Dependency>*; scope=compile; type=!pom; inline=true</Embed-Dependency>
</instructions>
</configuration>
</plugin>
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/org/jahia/modules/tools/gql/ToolsGraphQLEnabler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2002-2022 Jahia Solutions Group SA. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jahia.modules.tools.gql;

import org.jahia.services.templates.JahiaTemplateManagerService;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* In order to avoid hard dependency on the GraphQL provider, we need to enable the GraphQL extensions provider only if
* the GraphQL provider is deployed.
*/
@Component(immediate = true)
public class ToolsGraphQLEnabler {

private JahiaTemplateManagerService templateManagerService;

@Reference
public void setTemplateManagerService(JahiaTemplateManagerService templateManagerService) {
this.templateManagerService = templateManagerService;
}

@Activate
public void activate(ComponentContext componentContext) {
if (templateManagerService.getAnyDeployedTemplatePackage("graphql-dxm-provider") != null) {
componentContext.enableComponent(ToolsGraphQLExtensionsProvider.class.getName());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2002-2022 Jahia Solutions Group SA. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jahia.modules.tools.gql;

import org.jahia.modules.graphql.provider.dxm.DXGraphQLExtensionsProvider;
import org.osgi.service.component.annotations.Component;

@Component(immediate = true, service= DXGraphQLExtensionsProvider.class, enabled = false)
public class ToolsGraphQLExtensionsProvider implements DXGraphQLExtensionsProvider {
// Extensions are scanned in current bundle, no need for declaring them manually
}
46 changes: 46 additions & 0 deletions src/main/java/org/jahia/modules/tools/gql/admin/ToolsGraphQL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2002-2022 Jahia Solutions Group SA. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jahia.modules.tools.gql.admin;

import graphql.annotations.annotationTypes.*;
import org.jahia.modules.graphql.provider.dxm.util.GqlUtils;
import org.jahia.modules.tools.gql.admin.osgi.FindExportPackage;
import org.jahia.modules.tools.gql.admin.osgi.OSGIPackageHeaderChecker;
import org.jahia.modules.tools.gql.admin.osgi.FindImportPackage;


@GraphQLName("AdminTools")
@GraphQLDescription("Jahia admin tools")
public class ToolsGraphQL {
@GraphQLField
@GraphQLDescription("Will return all the import packages matching the given parameters.")
public FindImportPackage findMatchingImportPackages(
@GraphQLName("RegExp") @GraphQLDescription("will return only import-package matching the RegExp") String regExp,
@GraphQLName("version") @GraphQLDescription("will return only import-package matching the given version") String version,
@GraphQLName("versionMissing") @GraphQLDescription("will return only import-package with no version range limitations") @GraphQLDefaultValue(GqlUtils.SupplierFalse.class) boolean versionMissing
) {
return OSGIPackageHeaderChecker.findImportPackages(regExp, version, versionMissing);
}

@GraphQLField
@GraphQLDescription("Will return all the duplicate export packages and the bundles that export them")
public FindExportPackage findMatchingExportPackages(
@GraphQLName("RegExp") @GraphQLDescription("will return only export-package matching the RegExp") String regExp,
@GraphQLName("duplicates") @GraphQLDescription("will return only export-package found multiple times for a same package name") @GraphQLDefaultValue(GqlUtils.SupplierFalse.class) boolean duplicates
) {
return OSGIPackageHeaderChecker.findExportPackages(regExp, duplicates);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2002-2022 Jahia Solutions Group SA. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jahia.modules.tools.gql.admin;

import graphql.annotations.annotationTypes.GraphQLDescription;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import graphql.annotations.annotationTypes.GraphQLTypeExtension;
import org.jahia.modules.graphql.provider.dxm.admin.GqlAdminQuery;

@GraphQLTypeExtension(GqlAdminQuery.class)
public class ToolsGraphQLAdminExtension {
@GraphQLField
@GraphQLName("tools")
@GraphQLDescription("Jahia admin tools")
public static ToolsGraphQL getTools() {
return new ToolsGraphQL();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2002-2022 Jahia Solutions Group SA. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jahia.modules.tools.gql.admin.osgi;

import graphql.annotations.annotationTypes.GraphQLDescription;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import org.osgi.framework.Bundle;

/**
* An abstract class that provide basic bundle information for a GQL result that would involve bundle.
* Can be implemented to automatically provide bundle GQL fields.
*/
public abstract class BundleResultEntry {
sergehuber marked this conversation as resolved.
Show resolved Hide resolved
private final String bundleName;
private final String bundleSymbolicName;
private final String bundleDisplayName;
private final long bundleId;

public BundleResultEntry(Bundle bundle) {
this.bundleName = bundle.getHeaders().get("Bundle-Name");
this.bundleSymbolicName = bundle.getSymbolicName();
this.bundleDisplayName = bundleName != null ?
bundleName + " (" + bundleSymbolicName + ")" :
bundleSymbolicName;
this.bundleId = bundle.getBundleId();
}

@GraphQLField
@GraphQLName("bundleName")
@GraphQLDescription("Name of the bundle.")
public String getBundleName() {
return bundleName;
}

@GraphQLField
@GraphQLName("bundleSymbolicName")
@GraphQLDescription("Symbolic name of the bundle.")
public String getBundleSymbolicName() {
return bundleSymbolicName;
}

@GraphQLField
@GraphQLName("bundleDisplayName")
@GraphQLDescription("Display name of the bundle.")
public String getBundleDisplayName() {
return bundleDisplayName;
}

@GraphQLField
@GraphQLName("bundleId")
@GraphQLDescription("ID of the bundle.")
public long getBundleId() {
return bundleId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2002-2022 Jahia Solutions Group SA. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jahia.modules.tools.gql.admin.osgi;

import graphql.annotations.annotationTypes.GraphQLDescription;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import org.osgi.framework.Bundle;

@GraphQLName("BundleWithExportPackage")
@GraphQLDescription("Result of the export package inspector operation.")
public class BundleWithExportPackage extends BundleResultEntry{
private final String matchingExportPackage;

public BundleWithExportPackage(String exportPackage, Bundle bundle) {
super(bundle);
this.matchingExportPackage = exportPackage;
}

@GraphQLField
@GraphQLName("matchingExportPackage")
@GraphQLDescription("The full export-package clause.")
public String getPackage() {
return matchingExportPackage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2002-2022 Jahia Solutions Group SA. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jahia.modules.tools.gql.admin.osgi;

import graphql.annotations.annotationTypes.GraphQLDescription;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import org.osgi.framework.Bundle;

import java.util.HashSet;
import java.util.Set;

@GraphQLName("BundleWithImportPackages")
@GraphQLDescription("Result of the import package inspector operation.")
public class BundleWithImportPackages extends BundleResultEntry{
private final Set<String> matchingImportedPackage = new HashSet<>();

public BundleWithImportPackages(Bundle bundle) {
super(bundle);
}

@GraphQLField
@GraphQLName("matchingImportPackages")
@GraphQLDescription("List of matching imported packages.")
public Set<String> getMatchingImportedPackage() {
return matchingImportedPackage;
}

public void addMatchingImportedPackage(String importedPackage) {
matchingImportedPackage.add(importedPackage);
}
}
Loading
Loading