jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1868562 - in /jackrabbit/commons/filevault-package-maven-plugin/trunk/src: main/java/org/apache/jackrabbit/filevault/maven/packaging/ main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/ test/java/org/apache/ja...
Date Thu, 17 Oct 2019 17:41:05 GMT
Author: kwin
Date: Thu Oct 17 17:41:05 2019
New Revision: 1868562

URL: http://svn.apache.org/viewvc?rev=1868562&view=rev
Log:
JCRVLT-386 try to resolve package metadata also from Maven dependencies
which don't have a zip file connected

Added:
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
Modified:
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependency.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DirectoryValidationContext.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/GenerateMetadataMultiModuleIT.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/sub2/pom.xml

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java?rev=1868562&r1=1868561&r2=1868562&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
Thu Oct 17 17:41:05 2019
@@ -44,6 +44,7 @@ import org.apache.jackrabbit.vault.fs.ap
 import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
 import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
 import org.apache.jackrabbit.vault.fs.io.AccessControlHandling;
+import org.apache.jackrabbit.vault.packaging.Dependency;
 import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.jackrabbit.vault.packaging.PackageProperties;
 import org.apache.jackrabbit.vault.packaging.PackageType;
@@ -708,7 +709,7 @@ public class GenerateMetadataMojo extend
     private String computeDependencies() throws IOException {
         String dependenciesString = null;
         if (dependencies.length > 0) {
-            dependenciesString = org.apache.jackrabbit.vault.packaging.Dependency.toString(MavenBasedPackageDependency.resolve(project,
getLog(), dependencies));
+            dependenciesString = org.apache.jackrabbit.vault.packaging.Dependency.toString(MavenBasedPackageDependency.resolve(project,
getLog(), dependencies).toArray(new Dependency[0]));
         }
         return dependenciesString;
     }
@@ -907,56 +908,8 @@ public class GenerateMetadataMojo extend
         return fileMap;
     }
 
-    /**
-     * Establishes a session-shareable workDirectory lookup map for the given pluginContext.
-     *
-     * @param pluginContext a Map retrieved from {@link MavenSession#getPluginContext(PluginDescriptor,
MavenProject)}.
-     * @return a lookup Map. The key is {@link Artifact#getId()} and value is {@link AbstractMetadataPackageMojo#workDirectory}.
-     */
-    @SuppressWarnings("unchecked")
-    static Map<String, File> getArtifactWorkDirectoryLookup(final Map pluginContext)
{
-        final String workDirectoryLookupKey = "workDirectoryLookup";
-        if (!pluginContext.containsKey(workDirectoryLookupKey)) {
-            pluginContext.put(workDirectoryLookupKey, new ConcurrentHashMap<String, File>());
-        }
-        return (Map<String, File>) pluginContext.get(workDirectoryLookupKey);
-    }
-
-    /**
-     * Find the other project which produces the provided artifact.
-     *
-     * @param artifact the dependency artifact needle
-     * @return another project that is a dependency of thisProject
-     */
-    MavenProject findModuleForArtifact(final Artifact artifact) {
-        for (MavenProject otherProject : session.getProjects()) {
-            if (otherProject != this.project) {
-                final Artifact otherArtifact = otherProject.getArtifact();
-                if (getModuleArtifactKey(artifact).equals(getModuleArtifactKey(otherArtifact)))
{
-                    return otherProject;
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Construct a handler-independent artifact disambiguation key. This helps with the issue
-     * of matching dependency artifacts, which cannot reliably reference their original artifact
handler to match the
-     * correct packaging type, to multimodule artifacts, which include the packaging type
in their getId() result.
-     *
-     * I.E. {@link Artifact#getId()} contains either ":content-package:" or ":zip:" depending
on whether it comes from
-     * this.session.getProjects() -> MavenProject#getArtifact() or from this.project.getArtifacts().
-     *
-     * @param artifact the module artifact ({@link MavenProject#getArtifact()}) to identify
-     * @return a handler-independent artifact disambiguation key
-     */
-    String getModuleArtifactKey(final Artifact artifact) {
-        return this.embedArtifactLayout.pathOf(artifact);
-    }
-
     private Map<String, File> getSubPackages() throws MojoFailureException {
-        final String propsRelPath = "META-INF/vault/properties.xml";
+        final String propsRelPath = Constants.META_DIR + "/" + Constants.PROPERTIES_XML;
         Map<String, File> fileMap = new HashMap<>();
         for (SubPackage pack : subPackages) {
             final Collection<Artifact> artifacts = pack.getMatchingArtifacts(project);
@@ -984,10 +937,14 @@ public class GenerateMetadataMojo extend
 
                     // if not identifiable as a filevault content-package dependency, assume
a generic archive layout.
                     if (otherWorkDirectory == null) {
-                        otherWorkDirectory = source;
+                        otherWorkDirectory = source; // points to "target/classes"
                     }
 
-                    final File propsXml = new File(otherWorkDirectory, propsRelPath);
+                    File propsXml = new File(otherWorkDirectory, propsRelPath);
+                    if (!propsXml.exists()) {
+                        // fallback to work dir (assuming the same folder name)
+                        propsXml = new File(otherWorkDirectory.getParent(), workDirectory.getName()
+ "/" + propsRelPath);
+                    }
                     try (InputStream input = new FileInputStream(propsXml)) {
                         props.loadFromXML(input);
                     } catch (IOException e) {
@@ -1026,6 +983,54 @@ public class GenerateMetadataMojo extend
         return fileMap;
     }
 
+    /**
+     * Establishes a session-shareable workDirectory lookup map for the given pluginContext.
+     *
+     * @param pluginContext a Map retrieved from {@link MavenSession#getPluginContext(PluginDescriptor,
MavenProject)}.
+     * @return a lookup Map. The key is {@link Artifact#getId()} and value is {@link AbstractMetadataPackageMojo#workDirectory}.
+     */
+    @SuppressWarnings("unchecked")
+    static Map<String, File> getArtifactWorkDirectoryLookup(final Map pluginContext)
{
+        final String workDirectoryLookupKey = "workDirectoryLookup";
+        if (!pluginContext.containsKey(workDirectoryLookupKey)) {
+            pluginContext.put(workDirectoryLookupKey, new ConcurrentHashMap<String, File>());
+        }
+        return (Map<String, File>) pluginContext.get(workDirectoryLookupKey);
+    }
+
+    /**
+     * Find the other project which produces the provided artifact.
+     *
+     * @param artifact the dependency artifact needle
+     * @return another project that is a dependency of thisProject
+     */
+    MavenProject findModuleForArtifact(final Artifact artifact) {
+        for (MavenProject otherProject : session.getProjects()) {
+            if (otherProject != this.project) {
+                final Artifact otherArtifact = otherProject.getArtifact();
+                if (getModuleArtifactKey(artifact).equals(getModuleArtifactKey(otherArtifact)))
{
+                    return otherProject;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Construct a handler-independent artifact disambiguation key. This helps with the issue
+     * of matching dependency artifacts, which cannot reliably reference their original artifact
handler to match the
+     * correct packaging type, to multimodule artifacts, which include the packaging type
in their getId() result.
+     *
+     * I.E. {@link Artifact#getId()} contains either ":content-package:" or ":zip:" depending
on whether it comes from
+     * this.session.getProjects() -> MavenProject#getArtifact() or from this.project.getArtifacts().
+     *
+     * @param artifact the module artifact ({@link MavenProject#getArtifact()}) to identify
+     * @return a handler-independent artifact disambiguation key
+     */
+    String getModuleArtifactKey(final Artifact artifact) {
+        return this.embedArtifactLayout.pathOf(artifact);
+    }
+
     private void addWorkspaceFilter(final String filterRoot) {
         filters.add(new PathFilterSet(filterRoot));
     }

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependency.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependency.java?rev=1868562&r1=1868561&r2=1868562&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependency.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependency.java
Thu Oct 17 17:41:05 2019
@@ -18,7 +18,11 @@ package org.apache.jackrabbit.filevault.
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Collection;
+import java.util.LinkedList;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.apache.jackrabbit.vault.packaging.Dependency;
@@ -108,14 +112,17 @@ public class MavenBasedPackageDependency
      * @param project the Maven project
      * @param log the Logger
      * @param dependencyList The list of {@link MavenBasedPackageDependency} instances to
convert.
-     * @return The Vault Packaging Dependency representing the dependencies.
+     * @return The Vault Packaging Dependency representing the resolved dependencies. Not
all given items from the {@code dependencyList} can necessarily be resolved, therefore the
the size of the collection might be less than the size of the collection given in {@code dependencyList}

      * @throws IOException in case meta information could not be read from the project dependency
or the 
      * dependency is not a content package.
      */
-    public static org.apache.jackrabbit.vault.packaging.Dependency[] resolve(final MavenProject
project, final Log log, final MavenBasedPackageDependency... dependencyList) throws IOException
{
-        org.apache.jackrabbit.vault.packaging.Dependency[] dependencies = new org.apache.jackrabbit.vault.packaging.Dependency[dependencyList.length];
-        for (int i = 0; i < dependencies.length; i++) {
-            dependencies[i] = dependencyList[i].resolve(project, log);
+    public static @Nonnull Collection<Dependency> resolve(final MavenProject project,
final Log log, final MavenBasedPackageDependency... dependencyList) throws IOException {
+        Collection<Dependency> dependencies = new LinkedList<>();
+        for (int i = 0; i < dependencyList.length; i++) {
+            Dependency dependency = dependencyList[i].resolve(project, log);
+            if (dependency != null) {
+                dependencies.add(dependency);
+            }
         }
         return dependencies;
     }
@@ -127,7 +134,7 @@ public class MavenBasedPackageDependency
      * dependency is not a content package.
      */
     @SuppressWarnings("deprecation")
-    private org.apache.jackrabbit.vault.packaging.Dependency resolve(final MavenProject project,
final Log log) throws IOException {
+    private @CheckForNull org.apache.jackrabbit.vault.packaging.Dependency resolve(final
MavenProject project, final Log log) throws IOException {
         if (!StringUtils.isEmpty(group) || !StringUtils.isEmpty(name)) {
             log.warn("Using package id in dependencies is deprecated. Use Maven coordinates
(given via 'groupId' and 'artifactId') instead of '" + group + ":" + name +"'!");
         }
@@ -136,8 +143,15 @@ public class MavenBasedPackageDependency
             if (project != null) {
                 for (Artifact a : project.getDependencyArtifacts()) {
                     if (a.getArtifactId().equals(artifactId) && a.getGroupId().equals(groupId))
{
-                        readMetaData(a.getFile(), log);
-                        foundMavenDependency = true;
+                        // check if file exists and if it points to a real file (might also
point to a classes dir)
+                        try {
+                            readMetaData(a.getFile(), log);
+                            foundMavenDependency = true;
+                        } catch (IOException e) {
+                            // can not resolve name and group
+                            log.warn("Could not resolve dependency '" + this + "'", e);
+                            return null;
+                        }
                         break;
                     }
                 }
@@ -145,7 +159,8 @@ public class MavenBasedPackageDependency
                     throw new IOException("Specified dependency '" + this + "' was not found
among the Maven dependencies of this project!");
                 }
             } else {
-                throw new IOException("Dependency '" + this + "' was given via Maven coordinates
but there is no Maven project connect which allows to resolve those.");
+                log.warn("Dependency '" + this + "' was given via Maven coordinates but there
is no Maven project connected which allows to resolve those.");
+                return null;
             }
         }
         if (StringUtils.isEmpty(group) || StringUtils.isEmpty(name)) {
@@ -156,7 +171,19 @@ public class MavenBasedPackageDependency
     }
 
     public void readMetaData(File file, Log log) throws IOException {
-        PackageInfo info = DefaultPackageInfo.read(file);
+        PackageInfo info;
+        if (file.isDirectory()) {
+            log.info("Trying to extract package info from folder '" + file + "' as no package
is availabe for the given dependency " + this);
+            info = DefaultPackageInfo.read(file);
+            if (info == null) {
+                // fallback to work dir
+                File fallbackDirectory = new File(file.getParent(), "vault-work");
+                log.info("Trying to extract package info from fallback folder '" + fallbackDirectory
+ "' as no package is availabe for the given dependency " + this);
+                info = DefaultPackageInfo.read(fallbackDirectory);
+            }
+        } else {
+            info = DefaultPackageInfo.read(file);
+        }
         if (info != null) {
             PackageId id = info.getId();
             group = id.getGroup();
@@ -167,9 +194,10 @@ public class MavenBasedPackageDependency
             }
             this.info = info;
         } else {
-            throw new IOException("Specified dependency " + this + " is not a package.");
+            throw new IOException("Dependency at '" + file + "' does not contain mandatory
metadata for a content-package");
         }
     }
+
     /**
      * Returns the package info or {@code null}.
      *

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DirectoryValidationContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DirectoryValidationContext.java?rev=1868562&r1=1868561&r2=1868562&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DirectoryValidationContext.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DirectoryValidationContext.java
Thu Oct 17 17:41:05 2019
@@ -68,17 +68,21 @@ public class DirectoryValidationContext
         if (propertiesPath == null || !Files.exists(propertiesPath)) {
             propertiesPath = generatedMetaInfRootDirectory.toPath().resolve(RELATIVE_PROPERTIES_XML_PATH);
             if (!Files.exists(propertiesPath)) {
-                throw new IllegalStateException("No " + RELATIVE_PROPERTIES_XML_PATH + "
found in either " +metaInfRootDirectory + " or " + generatedMetaInfRootDirectory);
+                throw new IllegalStateException("No '" + RELATIVE_PROPERTIES_XML_PATH + "'
found in either '" +metaInfRootDirectory + "' or '" + generatedMetaInfRootDirectory + "'");
             }
-            log.debug("Using " + RELATIVE_PROPERTIES_XML_PATH + " from directory " + generatedMetaInfRootDirectory);
+            log.debug("Using '" + RELATIVE_PROPERTIES_XML_PATH + "' from directory " + generatedMetaInfRootDirectory);
         } else {
-            log.debug("Using " + RELATIVE_PROPERTIES_XML_PATH + " from directory " + metaInfRootDirectory);
+            log.debug("Using '" + RELATIVE_PROPERTIES_XML_PATH + "' from directory " + metaInfRootDirectory);
         }
         properties = DefaultPackageProperties.fromFile(propertiesPath);
         
         // filter always comes from the workDir
         filter = new DefaultWorkspaceFilter();
-        filter.load(new File(generatedMetaInfRootDirectory, Constants.VAULT_DIR +"/"+Constants.FILTER_XML));
+        File filterFile = new File(generatedMetaInfRootDirectory, Constants.VAULT_DIR +"/"+Constants.FILTER_XML);
+        if (!filterFile.exists()) {
+            throw new IllegalStateException("No mandatory '" + Constants.VAULT_DIR +"/"+Constants.FILTER_XML
+ "' found in " + generatedMetaInfRootDirectory + "'");
+        }
+        filter.load(filterFile);
         
         this.resolvedDependencies = resolver.resolve(getProperties().getDependencies(), resolvedDependencies,
log);
     }

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/GenerateMetadataMultiModuleIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/GenerateMetadataMultiModuleIT.java?rev=1868562&r1=1868561&r2=1868562&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/GenerateMetadataMultiModuleIT.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/GenerateMetadataMultiModuleIT.java
Thu Oct 17 17:41:05 2019
@@ -21,7 +21,8 @@ import org.junit.Test;
 public class GenerateMetadataMultiModuleIT {
 
     /**
-     * Tests that the generate-manifest goal generates the expected filter.xml when run on
+     * Tests that the generate-manifest goal generates the expected filter.xml and
+     * runs validation successfully when run on
      * inter-module dependencies in a multi-module setup for clean + test goals.
      */
     @Test
@@ -31,12 +32,14 @@ public class GenerateMetadataMultiModule
                 .setTestGoals("clean", "test")
                 .setVerifyPackageContents(false)
                 .build()
-                .verifyExpectedFilterInWorkDirectory("container/target/vault-work");
+                .verifyExpectedFilterInWorkDirectory("container/target/vault-work")
+                .verifyExpectedLogLines(); // make sure validation runs
     }
 
     /**
-     * Tests that the generate-manifest goal generates the expected filter.xml when run on
-     * inter-module dependencies in a multi-module setup for clean + test goals.
+     * Tests that the generate-manifest goal generates the expected filter.xml and
+     * runs validation successfully when run on when run on
+     * inter-module dependencies in a multi-module setup for clean + package goals.
      */
     @Test
     public void multi_module_build_clean_package() throws Exception {

Added: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt?rev=1868562&view=auto
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
(added)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
Thu Oct 17 17:41:05 2019
@@ -0,0 +1 @@
+[INFO] No explicit version range given for dependency 'Dependency{group='test', groupId='org.apache.jackrabbit.filevault',
name='package-plugin-test-pkg-sub1', artifactId='package-plugin-test-pkg-sub1', version='null'}'.
Using default version range derived from the Maven dependency
\ No newline at end of file

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/sub2/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/sub2/pom.xml?rev=1868562&r1=1868561&r2=1868562&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/sub2/pom.xml
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/sub2/pom.xml
Thu Oct 17 17:41:05 2019
@@ -45,8 +45,22 @@
                 <extensions>true</extensions>
                 <configuration>
                     <group>test</group>
+                    <dependencies>
+                        <dependency>
+                            <groupId>org.apache.jackrabbit.filevault</groupId>
+                            <artifactId>package-plugin-test-pkg-sub1</artifactId>
+                        </dependency>
+                    </dependencies>
                 </configuration>
             </plugin>
         </plugins>
     </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.jackrabbit.filevault</groupId>
+            <artifactId>package-plugin-test-pkg-sub1</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+            <type>zip</type>
+        </dependency>
+    </dependencies>
 </project>



Mime
View raw message