You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by mr...@apache.org on 2007/10/06 21:34:10 UTC

svn commit: r582527 - /labs/discordia/license-sucker.rb

Author: mriou
Date: Sat Oct  6 12:34:09 2007
New Revision: 582527

URL: http://svn.apache.org/viewvc?rev=582527&view=rev
Log:
Producing RDF license descriptions.

Modified:
    labs/discordia/license-sucker.rb

Modified: labs/discordia/license-sucker.rb
URL: http://svn.apache.org/viewvc/labs/discordia/license-sucker.rb?rev=582527&r1=582526&r2=582527&view=diff
==============================================================================
--- labs/discordia/license-sucker.rb (original)
+++ labs/discordia/license-sucker.rb Sat Oct  6 12:34:09 2007
@@ -138,15 +138,30 @@
       parent.empty? ? nil : parent
     end
 
-    [:artifactId, :groupId, :version].each do |meth|
+    [:artifactId, :groupId, :version, :name].each do |meth|
       define_method(meth) do
-        @doc.elements["//#{meth}"].text.chomp
+        elmts = @doc.elements["//#{meth}"]
+        elmts.text.chomp if elmts
       end
     end
 
   end
 
   class Serializer
+    # Conversion from license name to its URL
+    LICENSE = [
+      [/Apache.*2/, "http://www.apache.org/licenses/LICENSE-2.0.txt"],
+      [/Apache.*1\.1/, "http://www.apache.org/licenses/LICENSE-1.1"],
+      [/Apache/, "http://www.apache.org/licenses/LICENSE-1.0"],
+      [/BSD/, "http://www.opensource.org/licenses/bsd-license.php"],
+      [/Public Domain/, "http://creativecommons.org/licenses/publicdomain/"],
+      [/(LGPL)|(GNU Library).*3/, "http://www.gnu.org/licenses/lgpl-3.0.txt"],
+      [/(LGPL)|(GNU Library)/, "http://opensource.org/licenses/lgpl-license.php"],
+      [/(GPL)|(GNU Public License).*3/, "http://www.gnu.org/licenses/gpl-3.0.txt"],
+      [/(GPL)|(GNU Public License)/, "http://opensource.org/licenses/gpl-license.php"],
+      [/(MIT)|(Massachusetts)/, "http://opensource.org/licenses/mit-license.php"],
+      [/.*/, "Unknown"]
+    ]
     # Instantiate with the pom of the project to serialize
     # information for and the one containing the licenses
     # (can be the same, nil, or a parent project pom).
@@ -155,23 +170,38 @@
     end
 
     def write
-      # Building the doc
+      # Building the doc, no matter the language XML is verbose
       doc = REXML::Document.new
-      project = doc.add_element("artifact")
-      project.add_element("name").text = @pom.artifactId
-      project.add_element("project").text = @pom.groupId
-      project.add_element("version").text = @pom.version
-      licenses = project.add_element("licenses")
+      rdf = doc.add_element("rdf:RDF")
+      rdf.add_namespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
+      rdf.add_namespace("doap", "http://usefulinc.com/ns/doap#")
+      rdf.add_namespace("dsc", "http://apache.org/ns/2007/discordia#")
+      project = rdf.add_element("doap:Project")
+      project.add_attribute("rdf:about", "mvn://#{@pom.groupId}/#{@pom.artifactId}/#{@pom.version}")
+      project.add_element("doap:name").text = @pom.name if @pom.name
       (@license_pom || @pom).licenses.each do |lic_info|
-        license = licenses.add_element("license")
-        ["name", "url", "distribution"].each do |info|
-          license.add_element(info).text = lic_info[info] if lic_info[info]
-        end
+        license = project.add_element("dis:has_license")
+        off_url, url = sanitize(lic_info["name"], lic_info["url"])
+        license.add_attribute("rdf:about", off_url)
+        license.add_element("dis:source").text = url
       end
 
       # Saving it
       doc.write(File.new("#{@pom.groupId}-#{@pom.artifactId}-#{@pom.version}.rdf", "w"), 0)
     end
+
+    private
+    # Making our best to reconcile the license info
+    def sanitize(name, url)
+      # Converting the name to a standard url
+      if name
+        off_url = LICENSE.select { |match, lic_url| match=~name }.first[1]
+        url ? [off_url, url] : [off_url, off_url]
+      else
+        [url, url]
+      end
+    end
+
   end
 end
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org