This is an automated email from the ASF dual-hosted git repository. sseifert pushed a commit to branch feature/SLING-13056-site-parent in repository https://gitbox.apache.org/repos/asf/sling-feature-converter-maven-plugin.git
commit 72b63715456e68251ab98300d238f4bc149116d5 Author: Stefan Seifert <[email protected]> AuthorDate: Wed Jan 14 13:26:14 2026 +0100 SLING-13056 apply spotless formatting --- pom.xml | 188 +++++++++---------- .../cpconverter/maven/mojos/AbstractBaseMojo.java | 30 +-- .../cpconverter/maven/mojos/ContentPackage.java | 88 +++++---- .../cpconverter/maven/mojos/ConvertCPMojo.java | 208 ++++++++++----------- .../cpconverter/maven/mojos/ConvertPMMojo.java | 60 +++--- 5 files changed, 287 insertions(+), 287 deletions(-) diff --git a/pom.xml b/pom.xml index 51b19c8..6806259 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> +<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information @@ -26,16 +26,14 @@ <packaging>maven-plugin</packaging> <name>Apache Sling Feature Model Converter Plugin</name> - <description> - Maven Plugin to convert Configurations / Packages to Feature Model format - </description> + <description>Maven Plugin to convert Configurations / Packages to Feature Model format</description> <url>https://sling.apache.org/components/sling-feature-converter-maven-plugin/</url> <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-feature-converter-maven-plugin.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-feature-converter-maven-plugin.git</developerConnection> - <url>https://github.com/apache/sling-feature-converter-maven-plugin.git</url> <tag>HEAD</tag> + <url>https://github.com/apache/sling-feature-converter-maven-plugin.git</url> </scm> <properties> @@ -52,96 +50,6 @@ <maven.site.path>${project.artifactId}-archives/${project.artifactId}-LATEST</maven.site.path> </properties> - <build> - <plugins> - <plugin> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-component-metadata</artifactId> - <version>${plexus-component-metadata.version}</version> - <executions> - <execution> - <id>generate-metadata</id> - <goals> - <goal>generate-metadata</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <executions> - <execution> - <id>mojo-descriptor</id> - <phase>process-classes</phase> - <goals> - <goal>descriptor</goal> - </goals> - </execution> - <execution> - <id>generated-helpmojo</id> - <goals> - <goal>helpmojo</goal> - </goals> - </execution> - </executions> - <configuration> - <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-scm-publish-plugin</artifactId> - <configuration> - <checkoutDirectory>${user.home}/maven-sites/${maven.site.path}</checkoutDirectory> - <tryUpdate>true</tryUpdate> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-plugin</artifactId> - <configuration> - <excludes> - <exclude>src/site/markdown/**</exclude> - <exclude>src/test/resources/**/*.txt</exclude> - <exclude>src/test/resources/**/*.feature</exclude> - <exclude>src/test/resources/META-INF/services/*</exclude> - <exclude>src/it/**/*.json</exclude> - </excludes> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <configuration> - <debug>true</debug> - <projectsDirectory>src/it</projectsDirectory> - <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> - <pomIncludes> - <pomInclude>*/pom.xml</pomInclude> - </pomIncludes> - <postBuildHookScript>verify</postBuildHookScript> - <scriptVariables> - <plugin.group>${project.groupId}</plugin.group> - <!-- The version of the test version which should match the plugin version but maybe off during a release --> - <plugin.version>1.0.2</plugin.version> - </scriptVariables> - <localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath> - </configuration> - <executions> - <execution> - <id>integration-test</id> - <goals> - <goal>install</goal> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - <dependencies> <dependency> <groupId>javax.jcr</groupId> @@ -278,6 +186,96 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-component-metadata</artifactId> + <version>${plexus-component-metadata.version}</version> + <executions> + <execution> + <id>generate-metadata</id> + <goals> + <goal>generate-metadata</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <configuration> + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> + </configuration> + <executions> + <execution> + <id>mojo-descriptor</id> + <goals> + <goal>descriptor</goal> + </goals> + <phase>process-classes</phase> + </execution> + <execution> + <id>generated-helpmojo</id> + <goals> + <goal>helpmojo</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-scm-publish-plugin</artifactId> + <configuration> + <checkoutDirectory>${user.home}/maven-sites/${maven.site.path}</checkoutDirectory> + <tryUpdate>true</tryUpdate> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-plugin</artifactId> + <configuration> + <excludes> + <exclude>src/site/markdown/**</exclude> + <exclude>src/test/resources/**/*.txt</exclude> + <exclude>src/test/resources/**/*.feature</exclude> + <exclude>src/test/resources/META-INF/services/*</exclude> + <exclude>src/it/**/*.json</exclude> + </excludes> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <configuration> + <debug>true</debug> + <projectsDirectory>src/it</projectsDirectory> + <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> + <pomIncludes> + <pomInclude>*/pom.xml</pomInclude> + </pomIncludes> + <postBuildHookScript>verify</postBuildHookScript> + <scriptVariables> + <plugin.group>${project.groupId}</plugin.group> + <!-- The version of the test version which should match the plugin version but maybe off during a release --> + <plugin.version>1.0.2</plugin.version> + </scriptVariables> + <localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath> + </configuration> + <executions> + <execution> + <id>integration-test</id> + <goals> + <goal>install</goal> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + <reporting> <plugins> <plugin> diff --git a/src/main/java/org/apache/sling/cpconverter/maven/mojos/AbstractBaseMojo.java b/src/main/java/org/apache/sling/cpconverter/maven/mojos/AbstractBaseMojo.java index b8af956..2c5a9ab 100644 --- a/src/main/java/org/apache/sling/cpconverter/maven/mojos/AbstractBaseMojo.java +++ b/src/main/java/org/apache/sling/cpconverter/maven/mojos/AbstractBaseMojo.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * 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. + * 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.apache.sling.cpconverter.maven.mojos; @@ -25,9 +27,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller; -public abstract class AbstractBaseMojo - extends AbstractMojo -{ +public abstract class AbstractBaseMojo extends AbstractMojo { @Parameter(property = "project", readonly = true, required = true) protected MavenProject project; diff --git a/src/main/java/org/apache/sling/cpconverter/maven/mojos/ContentPackage.java b/src/main/java/org/apache/sling/cpconverter/maven/mojos/ContentPackage.java index 419482d..9a73294 100644 --- a/src/main/java/org/apache/sling/cpconverter/maven/mojos/ContentPackage.java +++ b/src/main/java/org/apache/sling/cpconverter/maven/mojos/ContentPackage.java @@ -1,21 +1,33 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * 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. + * 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.apache.sling.cpconverter.maven.mojos; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; @@ -27,16 +39,6 @@ import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResult; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - public class ContentPackage { /** @@ -76,7 +78,7 @@ public class ContentPackage { public void setModuleIsContentPackage(boolean moduleIsContentPackage) { this.moduleIsContentPackage = moduleIsContentPackage; - if(this.moduleIsContentPackage) { + if (this.moduleIsContentPackage) { types.add("content-package"); } else { types.remove("content-package"); @@ -87,8 +89,10 @@ public class ContentPackage { return moduleIsContentPackage; } - Collection<Artifact> getMatchingArtifacts(final MavenProject project, - RepositorySystem repoSystem, RepositorySystemSession repoSession, + Collection<Artifact> getMatchingArtifacts( + final MavenProject project, + RepositorySystem repoSystem, + RepositorySystemSession repoSession, List<RemoteRepository> remoteRepos) { // get artifacts depending on whether we exclude transitives or not final Set<Artifact> artifacts; @@ -121,7 +125,7 @@ public class ContentPackage { } // Add the project artifact itself to convert after building a content package - if(moduleIsContentPackage) { + if (moduleIsContentPackage) { Artifact projectArtifact = project.getArtifact(); System.out.println("Project Artifact: " + projectArtifact); fileArtifacts.add(projectArtifact); @@ -129,13 +133,18 @@ public class ContentPackage { return getMatchingArtifacts(fileArtifacts); } - private Artifact resolveArtifact(final RepositorySystem repoSystem, final RepositorySystemSession repoSession, - final List<RemoteRepository> remoteRepos, final Artifact artifact) { + private Artifact resolveArtifact( + final RepositorySystem repoSystem, + final RepositorySystemSession repoSession, + final List<RemoteRepository> remoteRepos, + final Artifact artifact) { try { // Get an Aether Artifact org.eclipse.aether.artifact.Artifact a = new org.eclipse.aether.artifact.DefaultArtifact( - artifact.getGroupId(), artifact.getArtifactId(), - artifact.getClassifier(), artifact.getType(), + artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getClassifier(), + artifact.getType(), artifact.getVersion()); ArtifactRequest req = new ArtifactRequest(a, remoteRepos, null); @@ -144,8 +153,13 @@ public class ContentPackage { if (res.isResolved()) { org.eclipse.aether.artifact.Artifact aetherArt = res.getArtifact(); Artifact mavenArt = new DefaultArtifact( - aetherArt.getGroupId(), aetherArt.getArtifactId(), aetherArt.getVersion(), null, aetherArt.getExtension(), - aetherArt.getClassifier(), new DefaultArtifactHandler()); + aetherArt.getGroupId(), + aetherArt.getArtifactId(), + aetherArt.getVersion(), + null, + aetherArt.getExtension(), + aetherArt.getClassifier(), + new DefaultArtifactHandler()); mavenArt.setFile(aetherArt.getFile()); return mavenArt; } else { @@ -164,11 +178,11 @@ public class ContentPackage { System.out.println("Check Artifact Artifact: " + artifact.getArtifactId()); System.out.println("Check Artifact Type: " + artifact.getType()); System.out.println("Check Artifact Classifier: " + artifact.getClassifier()); - if(groupId.equals(artifact.getGroupId()) - && artifactId.equals(artifact.getArtifactId()) - && types.contains(artifact.getType()) - && (classifier.equals(artifact.getClassifier()) || (classifier.equals("") && artifact.getClassifier() == null)) - ) { + if (groupId.equals(artifact.getGroupId()) + && artifactId.equals(artifact.getArtifactId()) + && types.contains(artifact.getType()) + && (classifier.equals(artifact.getClassifier()) + || (classifier.equals("") && artifact.getClassifier() == null))) { matches.add(artifact); } } diff --git a/src/main/java/org/apache/sling/cpconverter/maven/mojos/ConvertCPMojo.java b/src/main/java/org/apache/sling/cpconverter/maven/mojos/ConvertCPMojo.java index 975c21c..8182c89 100644 --- a/src/main/java/org/apache/sling/cpconverter/maven/mojos/ConvertCPMojo.java +++ b/src/main/java/org/apache/sling/cpconverter/maven/mojos/ConvertCPMojo.java @@ -1,21 +1,34 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * 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. + * 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.apache.sling.cpconverter.maven.mojos; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; @@ -38,17 +51,6 @@ import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import static org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter.PACKAGE_CLASSIFIER; import static org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter.ZIP_TYPE; @@ -57,14 +59,8 @@ import static org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelCo * and places the converted Content Package into the local * Maven Repository */ -@Mojo( - name = "convert-cp", - requiresProject = true, - threadSafe = true -) -public class ConvertCPMojo - extends AbstractBaseMojo -{ +@Mojo(name = "convert-cp", requiresProject = true, threadSafe = true) +public class ConvertCPMojo extends AbstractBaseMojo { public static final String CFG_STRICT_VALIDATION = "strictValidation"; public static final String CFG_MERGE_CONFIGURATIONS = "mergeConfigurations"; @@ -113,7 +109,7 @@ public class ConvertCPMojo @Parameter(property = CFG_STRICT_VALIDATION, defaultValue = DEFAULT_STRING_VALIDATION + "") private boolean strictValidation; - //AS TODO: Is that applicable to a single CP ? + // AS TODO: Is that applicable to a single CP ? /** * If set to {@code true} the OSGi Configurations with same PID are merged. */ @@ -193,7 +189,7 @@ public class ConvertCPMojo @Parameter(property = CFG_FILTER_PATTERNS) private List<String> filterPatterns; - @Parameter(defaultValue="${repositorySystemSession}") + @Parameter(defaultValue = "${repositorySystemSession}") private RepositorySystemSession repoSession; @Component @@ -205,19 +201,20 @@ public class ConvertCPMojo @Override public void execute() throws MojoExecutionException, MojoFailureException { // Un-encode a given Artifact Override Id - if(artifactIdOverride != null) { + if (artifactIdOverride != null) { String old = artifactIdOverride; artifactIdOverride = artifactIdOverride.replaceAll("\\$\\{\\{", "\\$\\{"); artifactIdOverride = artifactIdOverride.replaceAll("}}", "}"); - getLog().info("Replaced Old Artifact Id Override: '" + old + "', with new one: '" + artifactIdOverride + "'"); + getLog().info("Replaced Old Artifact Id Override: '" + old + "', with new one: '" + artifactIdOverride + + "'"); } // Parse the System Properties if provided - Map<String,String> properties = new HashMap<>(); - if(systemProperties != null) { - for(String systemProperty: systemProperties) { - if(systemProperty != null) { + Map<String, String> properties = new HashMap<>(); + if (systemProperties != null) { + for (String systemProperty : systemProperties) { + if (systemProperty != null) { int index = systemProperty.indexOf("="); - if(index > 0 && index < systemProperty.length() - 1) { + if (index > 0 && index < systemProperty.length() - 1) { String key = systemProperty.substring(0, index); String value = systemProperty.substring(index + 1); properties.put(key, value); @@ -227,42 +224,24 @@ public class ConvertCPMojo } try { DefaultFeaturesManager featuresManager = new DefaultFeaturesManager( - mergeConfigurations, - bundleStartOrder, - fmOutput, - artifactIdOverride, - fmPrefix, - properties - ); - if (!apiRegions.isEmpty()) - featuresManager.setAPIRegions(apiRegions); - - if (exportToApiRegion != null) - featuresManager.setExportToAPIRegion(exportToApiRegion); + mergeConfigurations, bundleStartOrder, fmOutput, artifactIdOverride, fmPrefix, properties); + if (!apiRegions.isEmpty()) featuresManager.setAPIRegions(apiRegions); + + if (exportToApiRegion != null) featuresManager.setExportToAPIRegion(exportToApiRegion); ContentPackage2FeatureModelConverter converter = new ContentPackage2FeatureModelConverter(strictValidation) - .setFeaturesManager( - featuresManager - ) - .setBundlesDeployer( - new DefaultArtifactsDeployer( - convertedCPOutput - ) - ) - .setEntryHandlersManager( - new DefaultEntryHandlersManager() - ) - .setAclManager( - new DefaultAclManager() - ) - .setEmitter(DefaultPackagesEventsEmitter.open(fmOutput)) - .setResourceFilter(getResourceFilter()); - - if(contentPackages == null || contentPackages.isEmpty()) { + .setFeaturesManager(featuresManager) + .setBundlesDeployer(new DefaultArtifactsDeployer(convertedCPOutput)) + .setEntryHandlersManager(new DefaultEntryHandlersManager()) + .setAclManager(new DefaultAclManager()) + .setEmitter(DefaultPackagesEventsEmitter.open(fmOutput)) + .setResourceFilter(getResourceFilter()); + + if (contentPackages == null || contentPackages.isEmpty()) { getLog().info("Project Artifact File: " + project.getArtifact()); String targetPath = project.getModel().getBuild().getDirectory() + "/" - + project.getModel().getBuild().getFinalName() - + "." + ZIP_TYPE; + + project.getModel().getBuild().getFinalName() + + "." + ZIP_TYPE; File targetFile = new File(targetPath); if (targetFile.exists() && targetFile.isFile() && targetFile.canRead()) { converter.convert(project.getArtifact().getFile()); @@ -270,10 +249,11 @@ public class ConvertCPMojo getLog().error("Artifact is not found: " + targetPath); } } else { - for(ContentPackage contentPackage: contentPackages) { + for (ContentPackage contentPackage : contentPackages) { contentPackage.setExcludeTransitive(true); contentPackage.setModuleIsContentPackage(isContentPackage); - getLog().info("Content Package Artifact File: " + contentPackage.toString() + ", is module CP: " + isContentPackage); + getLog().info("Content Package Artifact File: " + contentPackage.toString() + ", is module CP: " + + isContentPackage); final Collection<Artifact> artifacts = contentPackage.getMatchingArtifacts(project, repoSystem, repoSession, remoteRepos); if (artifacts.isEmpty()) { @@ -287,9 +267,13 @@ public class ConvertCPMojo if (source != null && source.exists() && source.isFile() && source.canRead()) { converter.convert(source); Artifact convertedPackage = new DefaultArtifact( - artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), - "compile", ZIP_TYPE, PACKAGE_CLASSIFIER, artifactHandlerManager.getArtifactHandler(ZIP_TYPE) - ); + artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersion(), + "compile", + ZIP_TYPE, + PACKAGE_CLASSIFIER, + artifactHandlerManager.getArtifactHandler(ZIP_TYPE)); } else { getLog().error("Artifact is not found: " + artifact); } @@ -300,12 +284,10 @@ public class ConvertCPMojo } catch (Throwable t) { throw new MojoExecutionException("Content Package Converter Exception", t); } - } private ResourceFilter getResourceFilter() { - if (filterPatterns == null || filterPatterns.size() == 0) - return null; + if (filterPatterns == null || filterPatterns.size() == 0) return null; RegexBasedResourceFilter filter = new RegexBasedResourceFilter(); for (String filterPattern : filterPatterns) { @@ -320,11 +302,11 @@ public class ConvertCPMojo * bypassing the Maven Installer as this is giving us grief */ private void installGeneratedArtifacts() { - if(installConvertedCP) { + if (installConvertedCP) { File destFolder = repoSession.getLocalRepository().getBasedir(); - if(destFolder.isDirectory()) { + if (destFolder.isDirectory()) { copyFiles(convertedCPOutput, destFolder); - if(isContentPackage) { + if (isContentPackage) { installFMDescriptor(project.getArtifact()); } } @@ -342,35 +324,46 @@ public class ConvertCPMojo * @param destination Destination folder (inside the local Maven repo). This is the corresponding folder to the source */ private void copyFiles(File source, File destination) { - for(File file: source.listFiles()) { + for (File file : source.listFiles()) { String name = file.getName(); - if(file.isDirectory()) { + if (file.isDirectory()) { File newDest = new File(destination, name); - if(!newDest.exists()) { + if (!newDest.exists()) { newDest.mkdirs(); } - if(newDest.isDirectory()) { + if (newDest.isDirectory()) { copyFiles(file, newDest); } else { - getLog().warn("Source File: '" + file.getAbsolutePath() + "' is a folder but its counterpart is a file: " + newDest.getAbsolutePath()); + getLog().warn("Source File: '" + file.getAbsolutePath() + + "' is a folder but its counterpart is a file: " + newDest.getAbsolutePath()); } } else { File newDest = new File(destination, name); - if(!newDest.exists()) { + if (!newDest.exists()) { // Copy File over try { Files.copy(file.toPath(), newDest.toPath(), StandardCopyOption.COPY_ATTRIBUTES); } catch (IOException e) { - getLog().warn("Failed to copy File: '" + file.getAbsolutePath() + "' to File: " + newDest.getAbsolutePath(), e); + getLog().warn( + "Failed to copy File: '" + file.getAbsolutePath() + "' to File: " + + newDest.getAbsolutePath(), + e); } } else { // We only overwrite converted files - if(name.endsWith(PACKAGE_CLASSIFIER + "." + ZIP_TYPE)) { + if (name.endsWith(PACKAGE_CLASSIFIER + "." + ZIP_TYPE)) { // Copy File over try { - Files.copy(file.toPath(), newDest.toPath(), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); + Files.copy( + file.toPath(), + newDest.toPath(), + StandardCopyOption.COPY_ATTRIBUTES, + StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { - getLog().warn("Failed to copy generated File: '" + file.getAbsolutePath() + "' to File: " + newDest.getAbsolutePath(), e); + getLog().warn( + "Failed to copy generated File: '" + file.getAbsolutePath() + "' to File: " + + newDest.getAbsolutePath(), + e); } } else { getLog().info("Ignore File: '" + file.getAbsolutePath()); @@ -381,19 +374,23 @@ public class ConvertCPMojo } private void installFMDescriptor(Artifact artifact) { - if(installConvertedCP) { + if (installConvertedCP) { Collection<Artifact> artifacts = Collections.synchronizedCollection(new ArrayList<>()); // Source FM Descriptor File Path String fmDescriptorFilePath = fmPrefix + artifact.getArtifactId() + ".json"; File fmDescriptorFile = new File(fmOutput, fmDescriptorFilePath); - if(fmDescriptorFile.exists() && fmDescriptorFile.canRead()) { + if (fmDescriptorFile.exists() && fmDescriptorFile.canRead()) { // Need to create a new Artifact Handler for the different extension and an Artifact to not // change the module artifact DefaultArtifactHandler fmArtifactHandler = new DefaultArtifactHandler("slingosgifeature"); DefaultArtifact fmArtifact = new DefaultArtifact( - artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), - artifact.getScope(), "slingosgifeature", artifact.getArtifactId(), fmArtifactHandler - ); + artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersion(), + artifact.getScope(), + "slingosgifeature", + artifact.getArtifactId(), + fmArtifactHandler); fmArtifact.setFile(fmDescriptorFile); artifacts.add(fmArtifact); try { @@ -407,17 +404,12 @@ public class ConvertCPMojo } } - private void installArtifact(ProjectBuildingRequest pbr, Collection<Artifact> artifacts ) - throws MojoFailureException, MojoExecutionException - { - try - { + private void installArtifact(ProjectBuildingRequest pbr, Collection<Artifact> artifacts) + throws MojoFailureException, MojoExecutionException { + try { installer.install(pbr, artifacts); - } - catch ( ArtifactInstallerException e ) - { - throw new MojoExecutionException( "ArtifactInstallerException", e ); + } catch (ArtifactInstallerException e) { + throw new MojoExecutionException("ArtifactInstallerException", e); } } - } diff --git a/src/main/java/org/apache/sling/cpconverter/maven/mojos/ConvertPMMojo.java b/src/main/java/org/apache/sling/cpconverter/maven/mojos/ConvertPMMojo.java index e4d93c9..2cc701c 100644 --- a/src/main/java/org/apache/sling/cpconverter/maven/mojos/ConvertPMMojo.java +++ b/src/main/java/org/apache/sling/cpconverter/maven/mojos/ConvertPMMojo.java @@ -1,27 +1,23 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * 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. + * 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.apache.sling.cpconverter.maven.mojos; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.sling.feature.modelconverter.ProvisioningToFeature; - import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -31,18 +27,18 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.sling.feature.modelconverter.ProvisioningToFeature; + /** * Converts the given list of Provisioning Models into * Feature Models */ -@Mojo( - name = "convert-pm", - requiresProject = true, - threadSafe = true -) -public final class ConvertPMMojo - extends AbstractBaseMojo -{ +@Mojo(name = "convert-pm", requiresProject = true, threadSafe = true) +public final class ConvertPMMojo extends AbstractBaseMojo { public static final String CFG_INPUT_FOLDER = "inputFolder"; public static final String CFG_OUTPUT_FOLDER = "outputFolder"; @@ -128,7 +124,7 @@ public final class ConvertPMMojo private String checkForPlaceholder(String text) { String answer = text; - if(answer != null) { + if (answer != null) { answer = answer.replaceAll("\\$\\{\\{", "\\$\\{"); answer = answer.replaceAll("}}", "}"); getLog().info("Replaced Old Artifact Id Override: '" + text + "', with new one: '" + answer + "'"); @@ -147,7 +143,7 @@ public final class ConvertPMMojo String outputFolderPath = project.getBasedir() + "/" + outputFolder; File output = new File(outputFolderPath); if (!output.exists()) { - if(!output.mkdirs()) { + if (!output.mkdirs()) { throw new MojoFailureException("Could not create Output Folder: " + outputFolder); } } @@ -211,11 +207,11 @@ public final class ConvertPMMojo // Because of the XML structure run modes can have leading, trailing spaces so we need to trim them here public List<String> trimList(List<String> list) { List<String> answer = new ArrayList<>(); - if(list != null) { - for(String entry: list) { - if(entry != null) { + if (list != null) { + for (String entry : list) { + if (entry != null) { entry = entry.trim(); - if(!entry.isEmpty()) { + if (!entry.isEmpty()) { answer.add(entry); } }
