Skip to content

Commit

Permalink
Revert "feat(objectionary#909): fetch license from github"
Browse files Browse the repository at this point in the history
This reverts commit 9c5dce1.
  • Loading branch information
l3r8yJ committed Dec 10, 2024
1 parent 9c5dce1 commit 94aef76
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 45 deletions.
11 changes: 0 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,6 @@ SOFTWARE.
<artifactId>jhome</artifactId>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-http</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>jping</artifactId>
<version>0.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand Down
36 changes: 9 additions & 27 deletions src/main/java/org/eolang/jeo/representation/License.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
*/
package org.eolang.jeo.representation;

import com.jcabi.http.request.JdkRequest;
import jakarta.ws.rs.HttpMethod;
import jakarta.ws.rs.core.HttpHeaders;
import java.io.IOException;
import org.cactoos.Scalar;
import org.cactoos.text.FormattedText;
import org.cactoos.io.ResourceOf;
import org.cactoos.text.TextOf;

/**
* Representation of project license.
Expand All @@ -38,44 +35,29 @@
public final class License implements Scalar<String> {

/**
* Request url.
* The name of file with license.
*/
private final String url;
private final String name;

/**
* Ctor with default value.
*/
public License() {
this(
new FormattedText(
"%s://%s%s",
"https",
"raw.githubusercontent.com",
"/objectionary/jeo-maven-plugin/refs/heads/master/LICENSE.txt"
).toString()
);
this("LICENSE.txt");
}

/**
* Primary ctor.
*
* @param url The url to fetch the license.
* @param name The name of file with license.
*/
public License(final String url) {
this.url = url;
public License(final String name) {
this.name = name;
}

@Override
public String value() {
try {
return new JdkRequest(this.url)
.method(HttpMethod.GET)
.header(HttpHeaders.ACCEPT, "text/html")
.fetch()
.body();
} catch (final IOException exc) {
throw new IllegalStateException("Can't fetch the license", exc);
}
return new TextOf(new ResourceOf(this.name)).toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Iterator;
import org.cactoos.scalar.Sticky;
import org.eolang.jeo.representation.License;
import org.xembly.Directive;
import org.xembly.Directives;
Expand Down Expand Up @@ -119,7 +118,7 @@ public Iterator<Directive> iterator() {
.add("listing")
.set(this.listing)
.up()
.add("license").set(new Sticky<>(new License())).up()
.add("license").set(new License()).up()
.append(this.metas)
.attr("ms", this.milliseconds)
.add("objects");
Expand Down
21 changes: 21 additions & 0 deletions src/main/resources/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016-2024 Objectionary.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 2 additions & 5 deletions src/test/java/org/eolang/jeo/representation/LicenseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,27 @@
*/
package org.eolang.jeo.representation;

import com.yegor256.WeAreOnline;
import org.cactoos.text.FormattedText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Test suite for {@link License}.
*
* @since 0.6.27
*/
@ExtendWith(WeAreOnline.class)
final class LicenseTest {

@Test
void readsLicenseFileCorrectly() throws Exception {
final String name = "LICENSE.txt";
MatcherAssert.assertThat(
new FormattedText(
"Unexpected license content",
"Unexpected file:'%s' content",
name
).asString(),
new License().value(),
new License(name).value(),
Matchers.containsString("MIT")
);
}
Expand Down

0 comments on commit 94aef76

Please sign in to comment.