]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/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("GPL-3.0-or-later",
16 "http://www.gnu.org/licenses/gpl-3.0.txt", null, RESOURCES
+ "gpl-3.0.txt") {
19 public final static FreeLicense GPL_v2
= new FreeLicense("GPL-2.0-or-later",
20 "http://www.gnu.org/licenses/gpl-2.0.txt", null, RESOURCES
+ "gpl-2.0.txt") {
22 public final static FreeLicense GPL
= GPL_v3
;
24 public final static FreeLicense LGPL_v3
= new FreeLicense("LGPL-3.0-or-later",
25 "http://www.gnu.org/licenses/lgpl-3.0.txt", null, RESOURCES
+ "lgpl-3.0.txt") {
28 public final static FreeLicense LGPL_v2
= new FreeLicense("LGPL-2.0-or-later",
29 "http://www.gnu.org/licenses/lgpl-2.1.txt", null, RESOURCES
+ "lgpl-2.1.txt") {
31 public final static FreeLicense LGPL
= LGPL_v3
;
34 public final static FreeLicense APACHE_v2
= new FreeLicense("Apache-2.0",
35 "http://www.apache.org/licenses/LICENSE-2.0.txt", null, RESOURCES
+ "apache-2.0.txt") {
37 public final static FreeLicense APACHE
= APACHE_v2
;
40 public final static FreeLicense EPL_v1
= new FreeLicense("EPL-1.0", "http://www.eclipse.org/legal/epl-v10.html",
41 null, RESOURCES
+ "epl-1.0.txt") {
43 public final static FreeLicense EPL_v2
= new FreeLicense("EPL-2.0", "http://www.eclipse.org/legal/epl-v20.html",
44 null, RESOURCES
+ "epl-1.0.txt") {
46 public final static FreeLicense EPL
= EPL_v1
;
49 public final static FreeLicense MIT
= new FreeLicense("MIT", "http://opensource.org/licenses/MIT", null,
50 RESOURCES
+ "mit.txt") {
53 public final static FreeLicense BSD_NEW
= new FreeLicense("BSD-3-Clause",
54 "http://opensource.org/licenses/BSD-3-Clause", null, RESOURCES
+ "bsd-3-clause.txt") {
57 public final static FreeLicense BSD
= BSD_NEW
;
59 public final static FreeLicense CDDL_v1
= new FreeLicense("CDDL-1.0", "http://opensource.org/licenses/CDDL-1.0",
60 null, RESOURCES
+ "cddl-1.0.txt") {
62 public final static FreeLicense CDDL
= CDDL_v1
;
64 public final static FreeLicense MOZILLA_v2
= new FreeLicense("MPL-2.0", "https://opensource.org/licenses/MPL-2.0",
65 null, RESOURCES
+ "cddl-1.0.txt") {
67 public final static FreeLicense MOZILLA
= MOZILLA_v2
;
69 /** Public domain corner case */
70 public final static License PUBLIC_DOMAIN
= new License() {
72 public String
getUri() {
73 return "http://creativecommons.org/about/pdm";
76 public String
getText() {
77 return "This work is free of known copyright restrictions.";
80 public String
getName() {
81 return "Public Domain License";
84 public String
getLink() {
85 return "http://wiki.creativecommons.org/PDM_FAQ";
89 private final String name
, uri
, link
, resource
;
91 public FreeLicense(String name
, String uri
) {
92 this(name
, uri
, null, null);
95 public FreeLicense(String name
, String uri
, String link
) {
96 this(name
, uri
, link
, null);
99 public FreeLicense(String name
, String uri
, String link
, String resource
) {
101 throw new SlcException("URI cannot be null");
105 this.resource
= resource
;
109 public String
getName() {
113 public String
getUri() {
117 public String
getLink() {
122 public String
getText() {
123 InputStream in
= null;
126 if (resource
!= null)
127 url
= getClass().getClassLoader().getResource(resource
);
130 in
= url
.openStream();
131 String text
= IOUtils
.toString(in
);
133 } catch (Exception e
) {
134 throw new SlcException("Cannot retrieve license " + name
+ " from " + url
, e
);
136 IOUtils
.closeQuietly(in
);
141 public boolean equals(Object obj
) {
142 if (!(obj
instanceof License
))
144 return ((License
) obj
).getUri().equals(getUri());
148 public int hashCode() {
149 return getUri().hashCode();
153 public String
toString() {
154 StringBuilder sb
= new StringBuilder(name
!= null ? name
: uri
);
156 // sb.append(';').append("link=").append(link);
157 // else if (uri != null && name != null)
158 // sb.append(';').append("link=").append(uri);
159 return sb
.toString();