Skip to content

Commit

Permalink
Move parsers from core-api #10650
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol-sialitski committed Aug 15, 2024
1 parent dcefb15 commit eb7923e
Show file tree
Hide file tree
Showing 102 changed files with 139 additions and 86 deletions.
2 changes: 2 additions & 0 deletions modules/admin/admin-impl/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
dependencies {
implementation project( ':admin:admin-api' )
implementation project( ':core:core-internal' )
implementation project( ':core:core-parser' )

testImplementation( testFixtures( project(":core:core-api") ) )
testImplementation( testFixtures( project(":core:core-parser") ) )
testImplementation( testFixtures( project(":core:core-app") ) )
testImplementation( testFixtures( project(":web:web-api") ) )
testImplementation( testFixtures( project(":jaxrs:jaxrs-impl") ) )
Expand Down
1 change: 1 addition & 0 deletions modules/core/core-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencies {
implementation project( ':core:core-api' )
implementation project( ':core:core-internal' )
implementation project( ':core:core-parser' )
implementation libs.osgi.service.cm

testFixturesApi project( ':core:core-api' )
Expand Down
1 change: 1 addition & 0 deletions modules/core/core-auth/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dependencies {
implementation project( ':core:core-api' )
implementation project( ':core:core-parser' )

testImplementation( testFixtures( project(":core:core-app") ) )
}
Expand Down
7 changes: 7 additions & 0 deletions modules/core/core-common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies {
implementation project( ':core:core-api' )
}

jar {
bnd( 'Bundle-Name': 'Enonic XP Core - Common', 'Export-Package': 'com.enonic.xp.*' )
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.enonic.xp.impl.common;

import com.enonic.xp.app.ApplicationKey;

public final class ApiMountResolver
{
private static final int APPLICATION_KEY_INDEX = 0;

private static final int API_KEY_INDEX = 1;

private final String[] apiMountParts;

public ApiMountResolver( final String apiMount )
{
this.apiMountParts = apiMount.split( ":", 2 );
}

public ApplicationKey resolveApplicationKey()
{
return apiMountParts.length != 1 ? resolveApplicationKey( apiMountParts[APPLICATION_KEY_INDEX].trim() ) : null;
}

public String resolveApiKey()
{
final String trimmedApiKey = apiMountParts.length == 1 ? apiMountParts[0].trim() : apiMountParts[API_KEY_INDEX].trim();
return trimmedApiKey.isBlank() ? null : trimmedApiKey;
}

private ApplicationKey resolveApplicationKey( final String applicationKey )
{
try
{
return ApplicationKey.from( applicationKey );
}
catch ( Exception e )
{
throw new IllegalArgumentException( String.format( "Invalid applicationKey '%s'", applicationKey ), e );
}
}
}
1 change: 1 addition & 0 deletions modules/core/core-content/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dependencies {
implementation project( ':core:core-api' )
implementation project( ':core:core-parser' )
implementation project( ':core:core-internal' )

testFixturesApi( testFixtures( project(":core:core-app") ) )
Expand Down
3 changes: 2 additions & 1 deletion modules/core/core-export/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
dependencies {
implementation project( ':core:core-api' )
implementation project( ':core:core-parser' )

testImplementation( testFixtures( project(":core:core-repo") ) )
testImplementation( testFixtures( project( ":core:core-repo" ) ) )
}

jar {
Expand Down
1 change: 1 addition & 0 deletions modules/core/core-macro/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dependencies {
implementation project( ':core:core-api' )
implementation project( ':core:core-parser' )
implementation project( ':core:core-internal' )

testImplementation( testFixtures( project(":core:core-app") ) )
Expand Down
11 changes: 11 additions & 0 deletions modules/core/core-parser/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dependencies {
api( libs.guava ) {
exclude group: 'com.google.code.findbugs'
}
implementation project( ':core:core-api' )
implementation project( ':core:core-common' )
}

jar {
bnd( 'Bundle-Name': 'Enonic XP Core - Parser', 'Export-Package': 'com.enonic.xp.*' )
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.enonic.xp.annotation.PublicApi;

@PublicApi
public final class DomBuilder
{
private final Document document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.convert.Converters;

import static com.google.common.base.Strings.nullToEmpty;

@PublicApi
public final class DomElement
{
private final Element elem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import com.enonic.xp.api.ApiMountDescriptor;
import com.enonic.xp.api.ApiMountDescriptors;
import com.enonic.xp.app.ApplicationKey;
import com.enonic.xp.app.ApplicationRelativeResolver;
import com.enonic.xp.impl.common.ApiMountResolver;
import com.enonic.xp.resource.ResourceKey;
import com.enonic.xp.site.SiteDescriptor;
import com.enonic.xp.site.XDataMapping;
Expand Down Expand Up @@ -66,10 +67,6 @@ public final class XmlSiteParser

private static final String API_DESCRIPTOR_TAG_NAME = "api";

private static final int APPLICATION_KEY_INDEX = 0;

private static final int API_KEY_INDEX = 1;

private SiteDescriptor.Builder siteDescriptorBuilder;

public XmlSiteParser siteDescriptorBuilder( final SiteDescriptor.Builder siteDescriptorBuilder )
Expand Down Expand Up @@ -228,42 +225,11 @@ private ControllerMappingDescriptor toMappingDescriptor( final DomElement mappin

private ApiMountDescriptor toApiMountDescriptor( final DomElement apiElement )
{
final ApiMountDescriptor.Builder builder = ApiMountDescriptor.create();

final String apiMount = apiElement.getValue().trim();
final ApiMountResolver apiMountResolver = new ApiMountResolver( apiElement.getValue().trim() );

if ( !apiMount.contains( ":" ) )
{
builder.applicationKey( this.currentApplication );
if ( !apiMount.isBlank() )
{
builder.apiKey( apiMount );
}
}
else
{
final String[] parts = apiMount.split( ":", 2 );

builder.applicationKey( resolveApplicationKey( parts[APPLICATION_KEY_INDEX].trim() ) );
final String apiKey = parts[API_KEY_INDEX].trim();
if ( !apiKey.isBlank() )
{
builder.apiKey( apiKey );
}
}

return builder.build();
}

private ApplicationKey resolveApplicationKey( final String applicationKey )
{
try
{
return ApplicationKey.from( applicationKey );
}
catch ( Exception e )
{
throw new IllegalArgumentException( String.format( "Invalid applicationKey '%s'", applicationKey ), e );
}
return ApiMountDescriptor.create()
.applicationKey( Objects.requireNonNullElse( apiMountResolver.resolveApplicationKey(), this.currentApplication ) )
.apiKey( apiMountResolver.resolveApiKey() )
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.api.ApiMountDescriptor;
import com.enonic.xp.api.ApiMountDescriptors;
import com.enonic.xp.app.ApplicationKey;
import com.enonic.xp.impl.common.ApiMountResolver;
import com.enonic.xp.webapp.WebappDescriptor;
import com.enonic.xp.xml.DomElement;

Expand Down Expand Up @@ -55,42 +56,11 @@ private List<ApiMountDescriptor> parseApiMounts( final DomElement apisElement )

private ApiMountDescriptor toApiMountDescriptor( final DomElement apiElement )
{
final ApiMountDescriptor.Builder builder = ApiMountDescriptor.create();
final ApiMountResolver apiMountResolver = new ApiMountResolver( apiElement.getValue().trim() );

final String apiMount = apiElement.getValue().trim();

if ( !apiMount.contains( ":" ) )
{
builder.applicationKey( this.currentApplication );
if ( !apiMount.isBlank() )
{
builder.apiKey( apiMount );
}
}
else
{
final String[] parts = apiMount.split( ":", 2 );

builder.applicationKey( resolveApplicationKey( parts[APPLICATION_KEY_INDEX].trim() ) );
final String apiKey = parts[API_KEY_INDEX].trim();
if ( !apiKey.isBlank() )
{
builder.apiKey( apiKey );
}
}

return builder.build();
}

private ApplicationKey resolveApplicationKey( final String applicationKey )
{
try
{
return ApplicationKey.from( applicationKey );
}
catch ( Exception e )
{
throw new IllegalArgumentException( String.format( "Invalid applicationKey '%s'", applicationKey ), e );
}
return ApiMountDescriptor.create()
.applicationKey( Objects.requireNonNullElse( apiMountResolver.resolveApplicationKey(), this.currentApplication ) )
.apiKey( apiMountResolver.resolveApiKey() )
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.enonic.xp.support;

import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class ResourceTestHelper
{
private final Object testInstance;

public ResourceTestHelper( final Object testInstance )
{
this.testInstance = testInstance;
}

public String loadTestFile( final String fileName )
{
final URL url = getResource( testInstance.getClass().getSimpleName() + "-" + fileName );
try (InputStream stream = url.openStream())
{
return new String( stream.readAllBytes(), StandardCharsets.UTF_8 );
}
catch ( final Exception e )
{
throw new RuntimeException( "Failed to load test file: " + url, e );
}
}

public URL getTestResource( final String fileName )
{
return getResource( testInstance.getClass().getSimpleName() + "-" + fileName );
}

public URL getResource( final String fileName )
{
final URL resource = testInstance.getClass().getResource( fileName );
if ( resource == null )
{
throw new IllegalArgumentException( "Resource [" + fileName + "] not found relative to: " + testInstance.getClass() );
}
return resource;
}
}
3 changes: 2 additions & 1 deletion modules/core/core-schema/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
dependencies {
implementation project( ':core:core-api' )
implementation project( ':core:core-parser' )

testFixturesApi project( ':core:core-api' )
testImplementation( testFixtures( project(":core:core-app") ) )
testImplementation( testFixtures( project( ":core:core-app" ) ) )
}

jar {
Expand Down
1 change: 1 addition & 0 deletions modules/core/core-service/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dependencies {
implementation project( ':core:core-api' )
implementation project( ':core:core-parser' )

testImplementation( testFixtures( project(":core:core-app") ) )
testImplementation( testFixtures( project(":core:core-content") ) )
Expand Down
3 changes: 2 additions & 1 deletion modules/core/core-site/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
dependencies {
implementation project( ':core:core-api' )
implementation project( ':core:core-parser' )

testImplementation( testFixtures( project(":core:core-app") ) )
testImplementation( testFixtures( project( ":core:core-app" ) ) )
}

jar {
Expand Down
2 changes: 2 additions & 0 deletions modules/core/core-task/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
dependencies {
implementation project( ':portal:portal-api' )
implementation project( ':core:core-internal' )
implementation project( ':core:core-parser' )
implementation libs.hazelcast.hazelcast

testImplementation( testFixtures( project(":script:script-impl") ) )
testImplementation( project(":portal:portal-impl") )
testImplementation( testFixtures( project(":core:core-api") ) )
testImplementation( testFixtures( project(":core:core-parser") ) )
testImplementation( testFixtures( project(":core:core-app") ) )
testImplementation( testFixtures( project(":core:core-internal") ) )
}
Expand Down
2 changes: 2 additions & 0 deletions modules/itest/itest-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ dependencies {
testImplementation project( ':core:core-scheduler' )
testImplementation project( ':core:core-app' )
testImplementation project( ':core:core-export' )
testImplementation project( ':core:core-common' )
testImplementation project( ':core:core-parser' )

testImplementation libs.hazelcast.hazelcast

Expand Down
1 change: 1 addition & 0 deletions modules/lib/lib-schema/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dependencies {
compileOnly project( ':script:script-api' )

testImplementation project( ':tools:testing' )
testImplementation project( ':core:core-parser' )
}
2 changes: 2 additions & 0 deletions modules/portal/portal-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ dependencies {
implementation project( ':portal:portal-api' )
implementation project( ':admin:admin-api' )
implementation project( ':core:core-internal' )
implementation project( ':core:core-parser' )
implementation libs.attoparser

testImplementation( project( ':core:core-macro' ) )
testImplementation( testFixtures( project( ':script:script-impl' ) ) )
testImplementation( project( ':web:web-impl' ) )
testImplementation( testFixtures( project(":core:core-api") ) )
testImplementation( testFixtures( project(":core:core-parser") ) )
testImplementation( testFixtures( project(":web:web-api") ) )
testImplementation( testFixtures( project(":core:core-content") ) )
}
Expand Down
2 changes: 2 additions & 0 deletions modules/runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ addBundle( project( ':admin:admin-api' ), 10 )

// Core bundles
addBundle( project( ':core:core-event' ), 22 )
addBundle( project( ':core:core-common' ), 22 )
addBundle( project( ':core:core-parser' ), 22 )
addBundle( project( ':core:core-schema' ), 22 )
addBundle( project( ':core:core-repo' ), 22 )
addBundle( project( ':core:core-security' ), 22 )
Expand Down
Loading

0 comments on commit eb7923e

Please sign in to comment.