]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/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 BSD_NEW
= new FreeLicense(
64 "The BSD 3-Clause License",
65 "http://opensource.org/licenses/BSD-3-Clause", null, RESOURCES
66 + "bsd-3-clause.txt") {
69 public final static FreeLicense BSD
= BSD_NEW
;
71 public final static FreeLicense CDDL_v1
= new FreeLicense(
72 "Common Development and Distribution License",
73 "http://opensource.org/licenses/CDDL-1.0", null, RESOURCES
76 public final static FreeLicense CDDL
= CDDL_v1
;
78 /** Public domain corner case */
79 public final static License PUBLIC_DOMAIN
= new License() {
81 public String
getUri() {
82 return "http://creativecommons.org/about/pdm";
85 public String
getText() {
86 return "This work is free of known copyright restrictions.";
89 public String
getName() {
90 return "Public Domain License";
93 public String
getLink() {
94 return "http://wiki.creativecommons.org/PDM_FAQ";
98 private final String name
, uri
, link
, resource
;
100 public FreeLicense(String name
, String uri
) {
101 this(name
, uri
, null, null);
104 public FreeLicense(String name
, String uri
, String link
) {
105 this(name
, uri
, link
, null);
108 public FreeLicense(String name
, String uri
, String link
, String resource
) {
110 throw new SlcException("URI cannot be null");
114 this.resource
= resource
;
118 public String
getName() {
122 public String
getUri() {
126 public String
getLink() {
131 public String
getText() {
132 InputStream in
= null;
135 if (resource
!= null)
136 url
= getClass().getClassLoader().getResource(resource
);
139 in
= url
.openStream();
140 String text
= IOUtils
.toString(in
);
142 } catch (Exception e
) {
143 throw new SlcException("Cannot retrieve license " + name
+ " from "
146 IOUtils
.closeQuietly(in
);
151 public boolean equals(Object obj
) {
152 if (!(obj
instanceof License
))
154 return ((License
) obj
).getUri().equals(getUri());
158 public int hashCode() {
159 return getUri().hashCode();
163 public String
toString() {
164 return name
+ " (" + uri
+ ")";