]>
git.argeo.org Git - gpl/argeo-slc.git/blob - repo/FreeLicense.java
1 package org
.argeo
.slc
.repo
;
3 import java
.io
.InputStream
;
6 import org
.apache
.commons
.io
.IOUtils
;
7 import org
.argeo
.slc
.SlcException
;
8 import org
.argeo
.slc
.build
.License
;
10 /** A free software license */
11 public abstract class FreeLicense
implements License
{
12 final static String RESOURCES
= "/org/argeo/slc/repo/license/";
15 public final static FreeLicense GPL_v3
= new FreeLicense(
16 "GNU General Public License, version 3.0",
17 "http://www.gnu.org/licenses/gpl-3.0.txt",
18 "http://www.gnu.org/licenses/", RESOURCES
+ "gpl-3.0.txt") {
21 public final static FreeLicense GPL_v2
= new FreeLicense(
22 "GNU General Public License, version 2.0",
23 "http://www.gnu.org/licenses/gpl-2.0.txt",
24 "http://www.gnu.org/licenses/", RESOURCES
+ "gpl-2.0.txt") {
26 public final static FreeLicense GPL
= GPL_v3
;
28 public final static FreeLicense LGPL_v3
= new FreeLicense(
29 "GNU Lesser General Public License, version 3.0",
30 "http://www.gnu.org/licenses/lgpl-3.0.txt",
31 "http://www.gnu.org/licenses/", RESOURCES
+ "lgpl-3.0.txt") {
34 public final static FreeLicense LGPL_v2
= new FreeLicense(
35 "GNU Lesser General Public License, version 2.1",
36 "http://www.gnu.org/licenses/lgpl-2.1.txt",
37 "http://www.gnu.org/licenses/", RESOURCES
+ "lgpl-2.1.txt") {
39 public final static FreeLicense LGPL
= LGPL_v3
;
42 public final static FreeLicense APACHE_v2
= new FreeLicense(
43 "Apache License, Version 2.0",
44 "http://www.apache.org/licenses/LICENSE-2.0.txt",
45 "http://www.apache.org/licenses/", RESOURCES
+ "apache-2.0.txt") {
47 public final static FreeLicense APACHE
= APACHE_v2
;
50 public final static FreeLicense EPL_v1
= new FreeLicense(
51 "Eclipse Public License, Version 1.0",
52 "http://www.eclipse.org/legal/epl-v10.html",
53 "http://www.eclipse.org/legal/eplfaq.php", RESOURCES
56 public final static FreeLicense EPL
= EPL_v1
;
59 public final static FreeLicense MIT
= new FreeLicense("The MIT License",
60 "http://opensource.org/licenses/MIT", null, RESOURCES
+ "mit.txt") {
63 public final static FreeLicense CDDL_v1
= new FreeLicense(
64 "Common Development and Distribution License",
65 "http://opensource.org/licenses/CDDL-1.0", null, RESOURCES
68 public final static FreeLicense CDDL
= CDDL_v1
;
70 /** Public domain corner case */
71 public final static License PUBLIC_DOMAIN
= new License() {
73 public String
getUri() {
74 return "http://creativecommons.org/about/pdm";
77 public String
getText() {
78 return "This work is free of known copyright restrictions.";
81 public String
getName() {
82 return "Public Domain License";
85 public String
getLink() {
86 return "http://wiki.creativecommons.org/PDM_FAQ";
90 private final String name
, uri
, link
, resource
;
92 public FreeLicense(String name
, String uri
) {
93 this(name
, uri
, null, null);
96 public FreeLicense(String name
, String uri
, String link
) {
97 this(name
, uri
, link
, null);
100 public FreeLicense(String name
, String uri
, String link
, String resource
) {
102 throw new SlcException("URI cannot be null");
106 this.resource
= resource
;
110 public String
getName() {
114 public String
getUri() {
118 public String
getLink() {
123 public String
getText() {
124 InputStream in
= null;
127 if (resource
!= null)
128 url
= getClass().getClassLoader().getResource(resource
);
131 in
= url
.openStream();
132 String text
= IOUtils
.toString(in
);
134 } catch (Exception e
) {
135 throw new SlcException("Cannot retrieve license " + name
+ " from "
138 IOUtils
.closeQuietly(in
);
143 public boolean equals(Object obj
) {
144 if (!(obj
instanceof License
))
146 return ((License
) obj
).getUri().equals(getUri());
150 public int hashCode() {
151 return getUri().hashCode();
155 public String
toString() {
156 return name
+ " (" + uri
+ ")";