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

Check if runmode is used for mutable content packages #156 #157

Merged
merged 1 commit into from
May 14, 2022
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
2 changes: 1 addition & 1 deletion aemanalyser-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ governing permissions and limitations under the License.
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.feature.cpconverter</artifactId>
<version>1.1.14</version>
<version>1.1.15-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public Feature provide(final ArtifactId id) {
}

if ( artifactsDeployer != null ) {
artifactsDeployer.deploy(new FileArtifactWriter(featureFile), newFeatureID);
artifactsDeployer.deploy(new FileArtifactWriter(featureFile), null, newFeatureID);
}
projectFeatures.put(aggregate.getKey(), feature);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter;
import org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter.SlingInitialContentPolicy;
import org.apache.sling.feature.cpconverter.ConverterException;
import org.apache.sling.feature.cpconverter.accesscontrol.AclManager;
import org.apache.sling.feature.cpconverter.accesscontrol.DefaultAclManager;
import org.apache.sling.feature.cpconverter.artifacts.ArtifactWriter;
import org.apache.sling.feature.cpconverter.artifacts.ArtifactsDeployer;
import org.apache.sling.feature.cpconverter.artifacts.LocalMavenRepositoryArtifactsDeployer;
import org.apache.sling.feature.cpconverter.features.DefaultFeaturesManager;
import org.apache.sling.feature.cpconverter.filtering.RegexBasedResourceFilter;
import org.apache.sling.feature.cpconverter.filtering.ResourceFilter;
import org.apache.sling.feature.cpconverter.handlers.DefaultEntryHandlersManager;
import org.apache.sling.feature.cpconverter.index.DefaultIndexManager;
import org.apache.sling.feature.cpconverter.shared.ConverterConstants;
import org.apache.sling.feature.cpconverter.vltpkg.DefaultPackagesEventsEmitter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -103,7 +108,16 @@ public void setArtifactIdOverride(String artifactIdOverride) {
this.artifactIdOverride = artifactIdOverride;
}

public void convert(final Map<String, File> contentPackages) throws IOException, ConverterException {
/**
* Convert the packages
*
* @param contentPackages The map of packages
* @param additionalWarnings The list to add additional warnings
* @param additionalErrors The list to add additional errors
* @throws IOException
* @throws ConverterException
*/
public void convert(final Map<String, File> contentPackages, final List<String> additionalWarnings, final List<String> additionalErrors) throws IOException, ConverterException {
final Map<String, String> properties = new HashMap<>();

final AclManager aclManager = new DefaultAclManager(null, "system");
Expand All @@ -119,11 +133,25 @@ public void convert(final Map<String, File> contentPackages) throws IOException,

featuresManager.setExportToAPIRegion("global");

final Map<ArtifactId, String> mutableContentPackagesWithRunMode = new HashMap<>();

final File bundlesOutputDir = this.bundlesOutputDirectory != null
? this.bundlesOutputDirectory : this.converterOutputDirectory;
try (final ContentPackage2FeatureModelConverter converter = new ContentPackage2FeatureModelConverter(false,
SlingInitialContentPolicy.KEEP) ) {
converter.setFeaturesManager(featuresManager)
.setContentTypePackagePolicy(ContentPackage2FeatureModelConverter.PackagePolicy.PUT_IN_DEDICATED_FOLDER)
.setUnreferencedArtifactsDeployer(new ArtifactsDeployer() {

@Override
public @NotNull String deploy(@NotNull ArtifactWriter artifactWriter, @Nullable String runmode,
@NotNull ArtifactId id) throws IOException {
if ( runmode != null ) {
mutableContentPackagesWithRunMode.put(id, runmode);
}
return id.toMvnId();
}
})
.setBundlesDeployer(
new LocalMavenRepositoryArtifactsDeployer(
bundlesOutputDir
Expand All @@ -133,12 +161,6 @@ public void convert(final Map<String, File> contentPackages) throws IOException,
new DefaultEntryHandlersManager(Collections.emptyMap(), true,
SlingInitialContentPolicy.KEEP, ConverterConstants.SYSTEM_USER_REL_PATH_DEFAULT)
)
.setAclManager(
new DefaultAclManager()
)
.setIndexManager(
new DefaultIndexManager()
)
.setEmitter(DefaultPackagesEventsEmitter.open(this.featureOutputDirectory))
.setResourceFilter(getResourceFilter());
logger.info("Converting packages {}", contentPackages.keySet());
Expand All @@ -148,6 +170,11 @@ public void convert(final Map<String, File> contentPackages) throws IOException,
} catch (final Throwable t) {
throw new IOException("Content Package Converter exception " + t.getMessage(), t);
}
if ( !mutableContentPackagesWithRunMode.isEmpty() ) {
for(final Map.Entry<ArtifactId, String> entry : mutableContentPackagesWithRunMode.entrySet()) {
additionalWarnings.add("Mutable content package ".concat(entry.getKey().toMvnId()).concat(" has invalid runmode : ").concat(entry.getValue()));
}
}
}

private ResourceFilter getResourceFilter() {
Expand Down
2 changes: 1 addition & 1 deletion aemanalyser-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ governing permissions and limitations under the License.
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.feature.cpconverter</artifactId>
<version>1.1.14</version>
<version>1.1.15-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,22 @@ public void execute() throws MojoExecutionException, MojoFailureException {
for(final String msg : versionUtil.getVersionWarnings()) {
this.getLog().warn(msg);
}


// warnings and errors not generated by the analysers
final List<String> additionalWarnings = new ArrayList<>();
additionalWarnings.addAll(versionUtil.getVersionWarnings());
final List<String> additionalErrors = new ArrayList<>();

// 1. Phase : convert content packages
this.convertContentPackages();
this.convertContentPackages(additionalWarnings, additionalErrors);

try (ArtifactManager artifactManager = getArtifactManager()) {
ArtifactProvider compositeArtifactProvider = getCompositeArtifactProvider(artifactManager);
// 2. Phase : aggregate feature models
final List<Feature> features = this.aggregateFeatureModels(sdkId, addons, compositeArtifactProvider);

// 3. Phase : analyse features
this.analyseFeatures(features, versionUtil.getVersionWarnings(), compositeArtifactProvider);
this.analyseFeatures(features, additionalWarnings, additionalErrors, compositeArtifactProvider);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
Expand All @@ -269,7 +274,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
* Convert the content packages
* @throws MojoExecutionException If anything goes wrong
*/
void convertContentPackages() throws MojoExecutionException {
void convertContentPackages(final List<String> additionalWarnings, final List<String> additionalErrors) throws MojoExecutionException {
final AemPackageConverter converter = new AemPackageConverter();
converter.setArtifactIdOverride(new ArtifactId(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, "slingosgifeature").toMvnId());
converter.setConverterOutputDirectory(getConversionOutputDir());
Expand All @@ -281,7 +286,7 @@ void convertContentPackages() throws MojoExecutionException {
packages.put(contentPackage.getId().toString(), source);
}
try {
converter.convert(packages);
converter.convert(packages, additionalWarnings, additionalErrors);
} catch ( final ConverterException ce) {
getLog().error(ce.getMessage());
throw new MojoExecutionException(ce.getMessage());
Expand Down Expand Up @@ -401,10 +406,15 @@ public Feature provide(final ArtifactId id) {
*
* @param features The features
* @param additionalWarnings List of additional warnings, might be empty
* @param additionalErrors List of additional errors, might be empty
* @param artifactProvider The artifact provider
* @throws MojoFailureException If the analysis fails
* @throws MojoExecutionException If something goes wrong
*/
void analyseFeatures(final List<Feature> features, final List<String> additionalWarnings, final ArtifactProvider artifactProvider) throws MojoFailureException, MojoExecutionException {
void analyseFeatures(final List<Feature> features,
final List<String> additionalWarnings,
final List<String> additionalErrors,
final ArtifactProvider artifactProvider) throws MojoFailureException, MojoExecutionException {
boolean hasErrors = false;
try {
final AemAnalyser analyser = new AemAnalyser();
Expand All @@ -431,11 +441,12 @@ void analyseFeatures(final List<Feature> features, final List<String> additional
getLog().warn(msg);
}
}
// print additional errors, next
additionalErrors.stream().forEach(msg -> getLog().error(msg));

// finally, analyser errors
for(final String msg : result.getErrors()) {
getLog().error(msg);
}
hasErrors = result.hasErrors() || (strictValidation && result.hasWarnings());
result.getErrors().stream().forEach(msg -> getLog().error(msg));
hasErrors = result.hasErrors() || !additionalErrors.isEmpty() || (strictValidation && (result.hasWarnings() || !additionalWarnings.isEmpty()));

} catch ( final Exception e) {
throw new MojoExecutionException("A fatal error occurred while analysing the features, see error cause:",
Expand Down