tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andygumbre...@apache.org
Subject [2/5] tomee git commit: Pull versions up to parent activemq 5.15.0 commons-logging 1.2 Remove BeanValidationAppendixInterceptor ref Prefer maven settings.xml values #TOMEE-2121
Date Wed, 13 Sep 2017 18:59:17 GMT
Pull versions up to parent
activemq 5.15.0
commons-logging 1.2
Remove BeanValidationAppendixInterceptor ref
Prefer maven settings.xml values
#TOMEE-2121


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/050f0873
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/050f0873
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/050f0873

Branch: refs/heads/master
Commit: 050f0873dd61fc3a6c9c4aa22674d86976e90c9b
Parents: 6998e21
Author: andygumbrecht <andy.is@gmx.de>
Authored: Wed Sep 13 20:20:39 2017 +0200
Committer: andygumbrecht <andy.is@gmx.de>
Committed: Wed Sep 13 20:20:39 2017 +0200

----------------------------------------------------------------------
 .../loader/provisining/MavenResolver.java       | 56 +++++++++++++-------
 .../loader/provisining/MavenResolverTest.java   |  6 ++-
 2 files changed, 43 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/050f0873/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/MavenResolver.java
----------------------------------------------------------------------
diff --git a/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/MavenResolver.java
b/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/MavenResolver.java
index 8f0a22a..d5d1a9f 100644
--- a/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/MavenResolver.java
+++ b/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/MavenResolver.java
@@ -35,14 +35,18 @@ import java.io.File;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Objects;
 import java.util.Properties;
+import java.util.concurrent.atomic.AtomicReference;
 
 public class MavenResolver implements ArchiveResolver, ProvisioningResolverAware {
-    private static final String REPO1 = "http://repo1.maven.org/maven2/";
-    private static final String APACHE_SNAPSHOT = "https://repository.apache.org/snapshots/";
+    private static final String REPO1 = System.getProperty("openejb.deployer.repository",
"http://repo1.maven.org/maven2/");
+    private static final String APACHE_SNAPSHOT = System.getProperty("openejb.deployer.repository.snapshots",
"https://repository.apache.org/snapshots/");
     private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
+    private static final AtomicReference<DocumentBuilder> BUILDER = new AtomicReference<>(null);
 
     private static final SAXParserFactory FACTORY = SAXParserFactory.newInstance();
+
     static {
         FACTORY.setNamespaceAware(false);
         FACTORY.setValidating(false);
@@ -86,7 +90,7 @@ public class MavenResolver implements ArchiveResolver, ProvisioningResolverAware
         if (resolver != null) {
             return resolver.resolveStream(repo1Url);
         }
-        return SystemInstance.get().getComponent(ProvisioningResolver.class).resolveStream(repo1Url);
+        return Objects.requireNonNull(SystemInstance.get().getComponent(ProvisioningResolver.class)).resolveStream(repo1Url);
     }
 
     public String quickMvnUrl(final String raw) throws MalformedURLException {
@@ -120,6 +124,12 @@ public class MavenResolver implements ArchiveResolver, ProvisioningResolverAware
         return builder.toString();
     }
 
+    /**
+     * Locate the .m2 repository
+     * First look for the settings.xml value, else assume it is in the .m2 directory
+     *
+     * @return String path to repository
+     */
     private static String m2Home() {
 
         final Properties properties;
@@ -130,23 +140,32 @@ public class MavenResolver implements ArchiveResolver, ProvisioningResolverAware
         }
 
         String home = "";
-        File f = new File(properties.getProperty("openejb.m2.home", System.getProperty("user.home")
+ "/.m2/repository/"));
 
+        File f = new File(properties.getProperty("openejb.m2.settings", System.getProperty("user.home")
+ "/.m2/settings.xml"));
         if (f.exists()) {
-            home = f.getAbsolutePath();
-        } else {
-            f = new File(properties.getProperty("openejb.m2.settings", System.getProperty("user.home")
+ "/.m2/settings.xml"));
-            if (f.exists()) {
-                try {
+            try {
+
+                DocumentBuilder builder = BUILDER.get();
+                if (null == builder) {
                     final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-                    final DocumentBuilder builder = factory.newDocumentBuilder();
-                    final Document document = builder.parse(f);
-                    final XPathFactory xpf = XPathFactory.newInstance();
-                    final XPath xp = xpf.newXPath();
-                    home = xp.evaluate("//settings/localRepository/text()", document.getDocumentElement());
-                } catch (final Exception ignore) {
-                    //no-op
+                    builder = factory.newDocumentBuilder();
+                    BUILDER.set(builder);
                 }
+
+                final Document document = builder.parse(f);
+                final XPathFactory xpf = XPathFactory.newInstance();
+                final XPath xp = xpf.newXPath();
+                home = xp.evaluate("//settings/localRepository/text()", document.getDocumentElement());
+            } catch (final Exception ignore) {
+                //no-op
+            }
+        }
+
+        if (home.isEmpty()) {
+            f = new File(properties.getProperty("openejb.m2.home", System.getProperty("user.home")
+ "/.m2/repository/"));
+
+            if (f.exists()) {
+                home = f.getAbsolutePath();
             }
         }
 
@@ -301,13 +320,14 @@ public class MavenResolver implements ArchiveResolver, ProvisioningResolverAware
         }
 
         @Override
-        public void characters(final char[] ch, final int start, final int length) throws
SAXException {
+        public void characters(final char[] ch, final int start, final int length) {
             if (text != null) {
                 text.append(new String(ch, start, length));
             }
         }
 
-        public void endElement(final String uri, final String localName, final String qName)
throws SAXException {
+        @Override
+        public void endElement(final String uri, final String localName, final String qName)
{
             text = null;
         }
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/050f0873/container/openejb-loader/src/test/java/org/apache/openejb/loader/provisining/MavenResolverTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-loader/src/test/java/org/apache/openejb/loader/provisining/MavenResolverTest.java
b/container/openejb-loader/src/test/java/org/apache/openejb/loader/provisining/MavenResolverTest.java
index 7b7a5b8..4d96b72 100644
--- a/container/openejb-loader/src/test/java/org/apache/openejb/loader/provisining/MavenResolverTest.java
+++ b/container/openejb-loader/src/test/java/org/apache/openejb/loader/provisining/MavenResolverTest.java
@@ -18,11 +18,13 @@ package org.apache.openejb.loader.provisining;
 
 import org.apache.openejb.loader.Files;
 import org.apache.openejb.loader.IO;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.InputStream;
 import java.util.Collections;
 import java.util.jar.JarFile;
 
@@ -40,7 +42,9 @@ public class MavenResolverTest {
 
     @Test
     public void local() throws Exception {
-        assertEquals(ProvisioningResolver.LocalInputStream.class.getName(), resolver.resolve("mvn:junit:junit:4.12:jar").getClass().getName());
// use version of the pom to ensure it is local
+        try(InputStream is = resolver.resolve("mvn:junit:junit:4.12:jar")) {
+            Assert.assertNotNull(is); // use version of the pom to ensure it is local
+        }
     }
 
     private File getAvailableFile() {


Mime
View raw message