]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/FreeLicense.java
0ce7fe8d753d654a5b0bc2677df8ea522e5bf555
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/";
14 public final static FreeLicense GPL_v3
= new FreeLicense(
15 "GNU General Public License, version 3.0",
16 "http://www.gnu.org/licenses/gpl-3.0.txt",
17 "http://www.gnu.org/licenses/", RESOURCES
+ "gpl-3.0.txt") {
20 public final static FreeLicense GPL_v2
= new FreeLicense(
21 "GNU General Public License, version 2.0",
22 "http://www.gnu.org/licenses/gpl-2.0.txt",
23 "http://www.gnu.org/licenses/", RESOURCES
+ "gpl-2.0.txt") {
26 public final static FreeLicense APACHE_v2
= new FreeLicense(
27 "Apache License, Version 2.0",
28 "http://www.apache.org/licenses/LICENSE-2.0.txt",
29 "http://www.apache.org/licenses/", RESOURCES
+ "apache-2.0.txt") {
32 public final static FreeLicense EPL_v1
= new FreeLicense(
33 "Eclipse Public License, Version 1.0",
34 "http://www.eclipse.org/legal/epl-v10.html",
35 "http://www.eclipse.org/legal/eplfaq.php", RESOURCES
39 public final static FreeLicense MIT
= new FreeLicense("The MIT License",
40 "http://opensource.org/licenses/MIT", null, RESOURCES
+ "mit.txt") {
43 public final static FreeLicense LGPL_v3
= new FreeLicense(
44 "GNU Lesser General Public License, version 3.0",
45 "http://www.gnu.org/licenses/lgpl-3.0.txt",
46 "http://www.gnu.org/licenses/", RESOURCES
+ "lgpl-3.0.txt") {
49 public final static FreeLicense LGPL_v2
= new FreeLicense(
50 "GNU Lesser General Public License, version 2.1",
51 "http://www.gnu.org/licenses/lgpl-2.1.txt",
52 "http://www.gnu.org/licenses/", RESOURCES
+ "lgpl-2.1.txt") {
55 private final String name
, uri
, link
, resource
;
57 public FreeLicense(String name
, String uri
) {
58 this(name
, uri
, null, null);
61 public FreeLicense(String name
, String uri
, String link
) {
62 this(name
, uri
, link
, null);
65 public FreeLicense(String name
, String uri
, String link
, String resource
) {
67 throw new SlcException("URI cannot be null");
71 this.resource
= resource
;
75 public String
getName() {
79 public String
getUri() {
83 public String
getLink() {
88 public String
getText() {
89 InputStream in
= null;
93 url
= getClass().getClassLoader().getResource(resource
);
96 in
= url
.openStream();
97 String text
= IOUtils
.toString(in
);
99 } catch (Exception e
) {
100 throw new SlcException("Cannot retrieve license " + name
+ " from "
103 IOUtils
.closeQuietly(in
);
108 public boolean equals(Object obj
) {
109 if (!(obj
instanceof License
))
111 return ((License
) obj
).getUri().equals(getUri());
115 public int hashCode() {
116 return getUri().hashCode();
120 public String
toString() {
121 return name
+ " (" + uri
+ ")";