onami-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1504063 - in /onami/sandbox/console/src/main: java/org/apache/onami/console/commands/ java/org/apache/onami/console/modules/config/ java/org/apache/onami/console/modules/descriptor/ mdo/
Date Wed, 17 Jul 2013 09:29:16 GMT
Author: simonetripodi
Date: Wed Jul 17 09:29:16 2013
New Revision: 1504063

URL: http://svn.apache.org/r1504063
Log:
use the URL class loader to collect additional artifacts to run the custom console

Modified:
    onami/sandbox/console/src/main/java/org/apache/onami/console/commands/ConsoleRunner.java
    onami/sandbox/console/src/main/java/org/apache/onami/console/modules/config/DefaultConfigurationModule.java
    onami/sandbox/console/src/main/java/org/apache/onami/console/modules/descriptor/IoDescriptorsModule.java
    onami/sandbox/console/src/main/mdo/console.mdo

Modified: onami/sandbox/console/src/main/java/org/apache/onami/console/commands/ConsoleRunner.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/commands/ConsoleRunner.java?rev=1504063&r1=1504062&r2=1504063&view=diff
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/commands/ConsoleRunner.java
(original)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/commands/ConsoleRunner.java
Wed Jul 17 09:29:16 2013
@@ -39,13 +39,16 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
 
 import jline.console.ConsoleReader;
 
-import org.apache.onami.console.descriptor.Console;
-import org.apache.onami.console.descriptor.io.jackson.OnamiConsoleJacksonReader;
-import org.apache.onami.console.descriptor.io.snakeyaml.OnamiConsoleSnakeYamlReader;
-import org.apache.onami.console.descriptor.io.xpp3.OnamiConsoleXpp3Reader;
+import org.apache.onami.console.descriptor.ConsoleConfiguration;
+import org.apache.onami.console.descriptor.io.jackson.OnamiConsoleConfigurationJacksonReader;
+import org.apache.onami.console.descriptor.io.snakeyaml.OnamiConsoleConfigurationSnakeYamlReader;
+import org.apache.onami.console.descriptor.io.xpp3.OnamiConsoleConfigurationXpp3Reader;
 import org.apache.onami.console.modules.config.DefaultConfigurationModule;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.slf4j.Logger;
@@ -86,12 +89,41 @@ public final class ConsoleRunner
 
         // read the console configuration
 
-        Console consoleConfiguration = readConsoleConfiguration();
+        ConsoleConfiguration consoleConfiguration = readConsoleConfiguration();
+
+        // build the console classloader
+
+        ClassLoader artifactsClassLoader;
+
+        if ( !consoleConfiguration.getArtifacts().isEmpty() )
+        {
+            URL[] urls = new URL[consoleConfiguration.getArtifacts().size()];
+
+            for ( int i = 0; i < urls.length; i++ )
+            {
+                String artifactUrl = consoleConfiguration.getArtifacts().get( i );
+                try
+                {
+                    urls[i] = new URL( artifactUrl );
+                }
+                catch ( MalformedURLException e )
+                {
+                    logger.warn( "Artifact {} can not be loaded: {} - It will be ignored",
+                                 artifactUrl, e.getMessage() );
+                }
+            }
+
+            artifactsClassLoader = new URLClassLoader( urls, getClass().getClassLoader()
);
+        }
+        else
+        {
+            artifactsClassLoader = getClass().getClassLoader();
+        }
 
         // setup the injector by discovering modules automatically
 
-        Injector injector = createInjector( expandVariables( loadModules() ),
-                                            new DefaultConfigurationModule( consoleConfiguration
) );
+        Injector injector = createInjector( expandVariables( loadModules( artifactsClassLoader
) ),
+                                            new DefaultConfigurationModule( consoleConfiguration.getProperties()
) );
 
         // retrieve components needed to run the console
 
@@ -194,14 +226,14 @@ public final class ConsoleRunner
         }
     }
 
-    private Console readConsoleConfiguration()
+    private ConsoleConfiguration readConsoleConfiguration()
     {
         File userDir = new File( getProperty( "user.dir" ) );
         File ocrXmlDescriptor = new File( userDir, "ocr.xml" );
         File ocrJsonDescriptor = new File( userDir, "ocr.json" );
         File ocrYamlDescriptor = new File( userDir, "ocr.yaml" );
 
-        Console console = null;
+        ConsoleConfiguration console = null;
         FileInputStream fis = null;
 
         if (ocrXmlDescriptor.exists())
@@ -211,7 +243,7 @@ public final class ConsoleRunner
             try
             {
                 fis = new FileInputStream( ocrXmlDescriptor );
-                console = new OnamiConsoleXpp3Reader().read( fis );
+                console = new OnamiConsoleConfigurationXpp3Reader().read( fis );
 
                 logger.info( "XML configuration {} read", ocrXmlDescriptor );
             }
@@ -241,7 +273,7 @@ public final class ConsoleRunner
             try
             {
                 fis = new FileInputStream( ocrJsonDescriptor );
-                console = new OnamiConsoleJacksonReader().read( fis );
+                console = new OnamiConsoleConfigurationJacksonReader().read( fis );
 
                 logger.info( "JSON configuration {} read", ocrJsonDescriptor );
             }
@@ -266,7 +298,7 @@ public final class ConsoleRunner
             try
             {
                 fis = new FileInputStream( ocrYamlDescriptor );
-                console = new OnamiConsoleSnakeYamlReader().read( fis );
+                console = new OnamiConsoleConfigurationSnakeYamlReader().read( fis );
 
                 logger.info( "YAML configuration {} read", ocrYamlDescriptor );
             }
@@ -289,7 +321,7 @@ public final class ConsoleRunner
             logger.info( "No ocr.xml/ocr.json/ocr.yaml configuration file found in {}, creating
default console.",
                          userDir);
 
-            console = new Console();
+            console = new ConsoleConfiguration();
         }
 
         return console;

Modified: onami/sandbox/console/src/main/java/org/apache/onami/console/modules/config/DefaultConfigurationModule.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/modules/config/DefaultConfigurationModule.java?rev=1504063&r1=1504062&r2=1504063&view=diff
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/modules/config/DefaultConfigurationModule.java
(original)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/modules/config/DefaultConfigurationModule.java
Wed Jul 17 09:29:16 2013
@@ -23,17 +23,17 @@ import static com.google.inject.Scopes.S
 import static com.google.inject.name.Names.named;
 
 import java.io.File;
+import java.util.Properties;
 
 import org.apache.onami.configuration.ConfigurationModule;
-import org.apache.onami.console.descriptor.Console;
 
 public final class DefaultConfigurationModule
     extends ConfigurationModule
 {
 
-    private final Console consoleConfiguration;
+    private final Properties consoleConfiguration;
 
-    public DefaultConfigurationModule( Console consoleConfiguration )
+    public DefaultConfigurationModule( Properties consoleConfiguration )
     {
         this.consoleConfiguration = consoleConfiguration;
     }
@@ -56,7 +56,7 @@ public final class DefaultConfigurationM
         bind( File.class ).annotatedWith( named( "ocr.repo.dir" ) ).toProvider( OnamiConsoleRepoDirProvider.class
).in( SINGLETON );
 
         // configuration
-        bindProperties( consoleConfiguration.getProperties() );
+        bindProperties( consoleConfiguration );
     }
 
 }

Modified: onami/sandbox/console/src/main/java/org/apache/onami/console/modules/descriptor/IoDescriptorsModule.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/modules/descriptor/IoDescriptorsModule.java?rev=1504063&r1=1504062&r2=1504063&view=diff
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/modules/descriptor/IoDescriptorsModule.java
(original)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/modules/descriptor/IoDescriptorsModule.java
Wed Jul 17 09:29:16 2013
@@ -21,9 +21,9 @@ package org.apache.onami.console.modules
 
 import static com.google.inject.Scopes.SINGLETON;
 
-import org.apache.onami.console.descriptor.io.jackson.OnamiConsoleJacksonReader;
-import org.apache.onami.console.descriptor.io.snakeyaml.OnamiConsoleSnakeYamlReader;
-import org.apache.onami.console.descriptor.io.xpp3.OnamiConsoleXpp3Reader;
+import org.apache.onami.console.descriptor.io.jackson.OnamiConsoleConfigurationJacksonReader;
+import org.apache.onami.console.descriptor.io.snakeyaml.OnamiConsoleConfigurationSnakeYamlReader;
+import org.apache.onami.console.descriptor.io.xpp3.OnamiConsoleConfigurationXpp3Reader;
 
 import com.google.inject.AbstractModule;
 
@@ -35,9 +35,9 @@ public final class IoDescriptorsModule
     protected void configure()
     {
         // textual configurations unmarshallers
-        bind( OnamiConsoleJacksonReader.class ).in( SINGLETON );
-        bind( OnamiConsoleSnakeYamlReader.class ).in( SINGLETON );
-        bind( OnamiConsoleXpp3Reader.class ).in( SINGLETON );
+        bind( OnamiConsoleConfigurationJacksonReader.class ).in( SINGLETON );
+        bind( OnamiConsoleConfigurationSnakeYamlReader.class ).in( SINGLETON );
+        bind( OnamiConsoleConfigurationXpp3Reader.class ).in( SINGLETON );
     }
 
 }

Modified: onami/sandbox/console/src/main/mdo/console.mdo
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/mdo/console.mdo?rev=1504063&r1=1504062&r2=1504063&view=diff
==============================================================================
--- onami/sandbox/console/src/main/mdo/console.mdo (original)
+++ onami/sandbox/console/src/main/mdo/console.mdo Wed Jul 17 09:29:16 2013
@@ -22,8 +22,8 @@
        xsi:schemaLocation="http://modello.codehaus.org/MODELLO/1.4.1 http://modello.codehaus.org/xsd/modello-1.4.1.xsd"
        xsd.namespace="http://onami.apache.org/console/1.x/">
 
-  <id>OnamiConsole</id>
-  <name>OnamiConsole</name>
+  <id>OnamiConsoleConfiguration</id>
+  <name>OnamiConsoleConfiguration</name>
   <description>The Apache Onami-Console configuration model</description>
   <comment>The Apache Onami-Console configuration model</comment>
 
@@ -36,7 +36,7 @@
 
   <classes>
     <class xml.tagName="console" rootElement="true" java.toString="true">
-      <name>Console</name>
+      <name>ConsoleConfiguration</name>
       <version>1.0.0+</version>
       <fields>
         <field java.setter="false">
@@ -50,147 +50,15 @@
         </field>
         <field>
           <name>artifacts</name>
-          <description>Additional artifacts that this console needs to introduce.</description>
+          <description>Additional artifacts URL that this console needs to introduce.</description>
           <version>1.0.0+</version>
           <association>
-            <type>Artifact</type>
-            <multiplicity>*</multiplicity>
-          </association>
-        </field>
-      </fields>
-    </class>
-
-    <class java.toString="true">
-      <name>Artifact</name>
-      <version>1.0.0+</version>
-      <description>
-        <![CDATA[
-        The <code>&lt;dependency&gt;</code> element contains information
about a dependency
-        of the project.
-        ]]>
-      </description>
-      <fields>
-        <field>
-          <name>groupId</name>
-          <version>1.0.0+</version>
-          <required>true</required>
-          <description>
-            <![CDATA[
-            The project group that produced the dependency, e.g.
-            <code>org.apache.maven</code>.
-            ]]>
-          </description>
-          <type>String</type>
-        </field>
-        <field>
-          <name>artifactId</name>
-          <version>1.0.0+</version>
-          <required>true</required>
-          <description>
-            <![CDATA[
-            The unique id for an artifact produced by the project group, e.g.
-            <code>maven-artifact</code>.
-            ]]>
-          </description>
-          <type>String</type>
-        </field>
-        <field>
-          <name>version</name>
-          <version>1.0.0+</version>
-          <description>
-            <![CDATA[
-            The version of the dependency, e.g. <code>3.2.1</code>. In Maven
2, this can also be
-            specified as a range of versions.
-            ]]>
-          </description>
-          <type>String</type>
-        </field>
-        <field>
-          <name>url</name>
-          <version>1.0.0+</version>
-          <description>This url will be provided to the user if the jar file cannot
be downloaded
-            from the central repository.</description>
-          <type>String</type>
-        </field>
-        <field>
-          <name>type</name>
-          <version>1.0.0+</version>
-          <description>
-            <![CDATA[
-            The type of dependency. While it
-            usually represents the extension on the filename of the dependency,
-            that is not always the case. A type can be mapped to a different
-            extension and a classifier.
-            The type often corresponds to the packaging used, though this is also
-            not always the case.
-            Some examples are <code>jar</code>, <code>war</code>,
<code>ejb-client</code>
-            and <code>test-jar</code>: see <a href="../maven-core/artifact-handlers.html">default
-            artifact handlers</a> for a list.
-            New types can be defined by plugins that set
-            <code>extensions</code> to <code>true</code>, so this
is not a complete list.
-            ]]>
-          </description>
-          <type>String</type>
-          <defaultValue>jar</defaultValue>
-        </field>
-        <field>
-          <name>classifier</name>
-          <version>1.0.0+</version>
-          <description>
-            <![CDATA[
-            The classifier of the dependency. It is appended to
-            the filename after the version. This allows:
-            <ul>
-            <li>refering to attached artifact, for example <code>sources</code>
and <code>javadoc</code>:
-            see <a href="../maven-core/artifact-handlers.html">default artifact handlers</a>
for a list,</li>
-            <li>distinguishing two artifacts
-            that belong to the same POM but were built differently.
-            For example, <code>jdk14</code> and <code>jdk15</code>.</li>
-            </ul>
-            ]]>
-          </description>
-          <type>String</type>
-          <required>false</required>
-        </field>
-        <field>
-          <name>exclusions</name>
-          <version>1.0.0+</version>
-          <description>Lists a set of artifacts that should be excluded from this dependency's
-            artifact list when it comes to calculating transitive dependencies.</description>
-          <association>
-            <type>Exclusion</type>
+            <type>String</type>
             <multiplicity>*</multiplicity>
           </association>
         </field>
       </fields>
     </class>
-
-    <class java.toString="true">
-      <name>Exclusion</name>
-      <version>1.0.0+</version>
-      <description>
-        <![CDATA[
-        The <code>&lt;exclusion&gt;</code> element contains informations
required to exclude
-        an artifact to the project.
-        ]]>
-      </description>
-      <fields>
-        <field>
-          <name>groupId</name>
-          <version>1.0.0+</version>
-          <description>The group ID of the artifact to exclude.</description>
-          <type>String</type>
-          <required>true</required>
-        </field>
-        <field>
-          <name>artifactId</name>
-          <version>1.0.0+</version>
-          <description>The artifact ID of the artifact to exclude.</description>
-          <type>String</type>
-          <required>true</required>
-        </field>
-      </fields>
-    </class>
   </classes>
 
 </model>



Mime
View raw message