Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recode library code structure, organization and more #1

Merged
merged 40 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e15d2f6
Update README.md
aivruu Aug 15, 2024
5ee16a4
chore: Remove old test classes, models and implementations
aivruu Aug 20, 2024
b51c055
chore: Remove old test classes, models and implementations
aivruu Aug 20, 2024
857ea58
chore(projects): Include sub-projects on project's settings file
aivruu Aug 20, 2024
5034718
chore(project): Declare new project structure with new properties and…
aivruu Aug 20, 2024
82b7bd4
chore(docs): Modify and include some new documentation for packages
aivruu Aug 20, 2024
1cc0542
feat(test): Create new tests for verify http-requests, models and more
aivruu Aug 20, 2024
5132a78
feat: Create new codecs, models and builders for Repository and Relea…
aivruu Aug 20, 2024
7f5e76c
feat: Create new codecs, models and builders for Repository and Relea…
aivruu Aug 20, 2024
ca0b402
chore(LoggerUtils): Suffered package relocation
aivruu Aug 20, 2024
75c4cb7
feat(codec): Implement new CodecProvider with implementation for dese…
aivruu Aug 20, 2024
7ab0d61
feat(DownloaderUtils): Create class for download-operations static-fu…
aivruu Aug 20, 2024
9c9d5d3
feat(RequestableModel): Implement interface model to mark identifiabl…
aivruu Aug 20, 2024
eea8265
feat(RequestConstants): Create class to store constant-values used fo…
aivruu Aug 20, 2024
3708ed5
feat(request-guide): Create guide with instructions for request-model…
aivruu Aug 20, 2024
84fae59
Create download-assets-guide.md
aivruu Aug 20, 2024
6928d7b
docs(RepositoryUrlBuilder): Small change on function documentation text
aivruu Aug 21, 2024
f187c42
Merge remote-tracking branch 'origin/recode' into recode
aivruu Aug 21, 2024
662ebab
chore(LatestReleaseModel): Use "->" char instead of ":" on string spl…
aivruu Aug 21, 2024
fb7e83e
chore(download-guide): Finalize assets-download usage guide
aivruu Aug 21, 2024
9399eea
feat(http-model): Implement functions with Consumer's for define logi…
aivruu Aug 23, 2024
33c6b36
feat(release-model): Include fixed-thread-pool for better use of asyn…
aivruu Aug 23, 2024
66c0629
feat(http): Implement changes from super-class and improve structure …
aivruu Aug 23, 2024
03dca44
chore(tests): Adapt them to the functions structures
aivruu Aug 23, 2024
3a004bc
chore(request-guide): Implement made changes to GitHubHttpRequestMode…
aivruu Aug 23, 2024
99a8ad6
chore(download-guide): Modify code-examples structure
aivruu Aug 23, 2024
b7ebbd6
chore(codec): Modify package for codec-types and codec-provider impl
aivruu Aug 23, 2024
8f5ffe4
chore(http-model): Use requestUsingThen method on requestThen method
aivruu Aug 23, 2024
b0a05e3
chore(http): Import CodecProviderImpl for http-model implementations
aivruu Aug 23, 2024
0e19f7d
chore(git): Ignore 'api/downloads' test directory
aivruu Aug 25, 2024
31dad29
chore(tests): Adapt tests for the new library structure
aivruu Aug 25, 2024
b2aff23
feat(status-provider): Implement status-providers for downloading-ope…
aivruu Aug 25, 2024
c63e707
chore(logger): Remove logger usage
aivruu Aug 25, 2024
bd4cfd8
chore(DownloaderUtils): Use DownloadStatusProvider for assets-downloa…
aivruu Aug 25, 2024
7c62b4c
chore(http-model): Include ResponseStatusProvider usage and implement…
aivruu Aug 25, 2024
ae5cc40
chore(LatestReleaseModel): Use DownloadStatusProvider for single asse…
aivruu Aug 25, 2024
1c2818a
chore(docs): Modify documentation for packages
aivruu Aug 25, 2024
b82689f
chore(RepositoryUrlBuilder): Remove NotNull annotations
aivruu Aug 25, 2024
0c618fb
chore(http-impl): Implement changes made on GithubHttpRequestModel in…
aivruu Aug 25, 2024
1f344ee
fix(http-model): Invalid import for CodecProvider
aivruu Aug 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ root = true
charset = utf-8
indent_size = 2
indent_style = space
max_line_length = 200
max_line_length = 121

ij_continuation_indent_size = 4
ij_continuation_indent_size = 2
ij_java_class_count_to_use_import_on_demand = 999999
ij_java_insert_inner_class_imports = false
ij_java_names_count_to_use_import_on_demand = 999999
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore git attributes.
.gitattributes

# Ignore Gradle build output directory
build

# Ignore IDE project settings directory.
.idea

# Ignore assets-download test directory.
api/downloads
48 changes: 0 additions & 48 deletions README.md

This file was deleted.

4 changes: 4 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
api(libs.annotations)
api(libs.gson)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Copyright (C) 2024 Aivruu - repo-viewer
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
package io.github.aivruu.repoviewer.api;

/**
* This class is used to store constants used for https-requests to GitHub's API.
*
* @since 2.3.4
*/
public class RequestConstants {
/** The normal url used for common-users to access to GitHub. */
public static final String GITHUB_NORMAL_URL = "https://github.com/%s/%s";
/** The url used for https-requests to GitHub's API. */
public static final String GITHUB_API_URL = "https://api.github.com/repos/%s/%s";

private RequestConstants() {
throw new UnsupportedOperationException("This class is for utility and cannot be instantiated.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright (C) 2024 Aivruu - repo-viewer
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
package io.github.aivruu.repoviewer.api.codec;

import io.github.aivruu.repoviewer.api.http.request.RequestableModel;
import org.jetbrains.annotations.Nullable;

/**
* This class is used for the deserialization handling of {@link RequestableModel}s.
*
* @since 2.3.4
*/
public interface CodecProvider {
/**
* Deserializes the {@code json} given into a specified-type {@link RequestableModel}.
*
* @param modelType the model-type to create since the given json.
* @param json the json to deserialize into a new model.
* @param <Model> the model-type specified that must be a {@link RequestableModel} implementation.
* @return The deserialized model, or {@code null} if something went wrong, or there's nothing
* to deserialize.
* @since 2.3.4
*/
<Model extends RequestableModel> @Nullable Model from(final Class<Model> modelType, final String json);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
*
* @since 0.0.1
*/
package me.qeklydev.downloader.codec;
package io.github.aivruu.repoviewer.api.codec;
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// Copyright (C) 2024 Aivruu - repo-viewer
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
package io.github.aivruu.repoviewer.api.download;

import io.github.aivruu.repoviewer.api.download.status.DownloadStatusProvider;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.nio.channels.Channels;

/**
* This class is used to perform download-operations from given URLs.
*
* @since 2.3.4
*/
public final class DownloaderUtils {
private DownloaderUtils() {
throw new UnsupportedOperationException("This class is used for utility and cannot be instantiated.");
}

/**
* Uses the URL object provided to download the content of that URL and be written into
* a specified file.
*
* @param fileName the name of the file to be written.
* @param from the url for the download.
* @return A {@link DownloadStatusProvider} with the {@code status-code} and the read {@code bytes-amount}
* for the operation.
* @see #fromUrlToFile(File, String)
* @since 2.3.4
*/
public static DownloadStatusProvider fromUrlToFileWithDirectory(final File directory, final String fileName,
final String from) {
return fromUrlToFile(new File(directory, fileName), from);
}

/**
* Downloads the content of the given url to write it into the given {@link File}.
*
* @param file the file where download's content will be written.
* @param from the url from where the content is going to be downloaded.
* @return A {@link DownloadStatusProvider} with the {@code status-code} and the read {@code bytes-amount}
* for the operation ending.
* <p>
* - {@link DownloadStatusProvider#assetDownloadFinished(long)} if the download was successful, will
* return it with the read-bytes amount.
* <p>
* - {@link DownloadStatusProvider#unknownAssetToDownload()} if any asset was downloaded, nothing to
* download.
* <p>
* - {@link DownloadStatusProvider#assetDownloadError()} if an error occurred during the downloading
* process.
* @see DownloadStatusProvider#ASSET_DOWNLOAD_FINISHED
* @see DownloadStatusProvider#UNKNOWN_ASSET_TO_DOWNLOAD
* @see DownloadStatusProvider#UNEXISTING_ASSET_DEFAULT_SIZE
* @see DownloadStatusProvider#ASSET_DOWNLOAD_ERROR
* @see DownloadStatusProvider#INVALID_ASSET_DEFAULT_SIZE
* @since 2.3.4
*/
public static DownloadStatusProvider fromUrlToFile(final File file, final String from) {
// Using the provided URL we create a new URI object with this
// same url, this method will throw an exception if given url
// syntax is not valid, and will provide a message for error
// description.
final var uriFromGiven = URI.create(from);
// We convert the URI instance into a URL object, and then we open
// the stream for channel data reading and write bytes to this channel
// at the given position.
try (final var readableByteChannel = Channels.newChannel(uriFromGiven.toURL().openStream());
final var fileOutputStream = new FileOutputStream(file)) {
final var transferBytesReat = fileOutputStream.getChannel().transferFrom(readableByteChannel,
/* The initial position for bytes transfer. */ 0, Long.MAX_VALUE);
return (transferBytesReat == 0)
? DownloadStatusProvider.unknownAssetToDownload()
: DownloadStatusProvider.assetDownloadFinished(transferBytesReat);
} catch (final IOException exception) {
return DownloadStatusProvider.assetDownloadError();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Provides utilities and status-code providers for I/O operations.
*
* @since 0.0.1
*/
package io.github.aivruu.repoviewer.api.download;
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// Copyright (C) 2024 Aivruu - repo-viewer
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
package io.github.aivruu.repoviewer.api.download.status;

/**
* This record is used as provider for status-code w/ results creation used for
* assets-download operations at {@link io.github.aivruu.repoviewer.api.download.DownloaderUtils}.
*
* @param status the status-code for the instance.
* @param result the read-bytes number to return as result for this instance.
* @since 2.3.4
*/
public record DownloadStatusProvider(byte status, long result) {
/** The asset was downloaded correctly. */
public static final byte ASSET_DOWNLOAD_FINISHED = 0;
/** The asset wasn't downloaded because of non-existing. */
public static final byte UNKNOWN_ASSET_TO_DOWNLOAD = 1;
/** The asset wasn't downloaded due to an error. */
public static final byte ASSET_DOWNLOAD_ERROR = 2;
/** Cached default-size to return for non-existing assets. */
public static final long UNEXISTING_ASSET_DEFAULT_SIZE = 0;
/** Cached default-size to return for non-downloaded assets. */
public static final long INVALID_ASSET_DEFAULT_SIZE = -1;

/**
* Creates a new {@link DownloadStatusProvider} with the {@link #ASSET_DOWNLOAD_FINISHED}
* status-code.
*
* @param result the read-bytes amount for the downloaded asset.
* @return The {@link DownloadStatusProvider} with the {@link #ASSET_DOWNLOAD_FINISHED} status-code.
* @since 2.3.4
*/
public static DownloadStatusProvider assetDownloadFinished(final long result) {
return new DownloadStatusProvider(ASSET_DOWNLOAD_FINISHED, result);
}

/**
* Creates a new {@link DownloadStatusProvider} with the {@link #UNKNOWN_ASSET_TO_DOWNLOAD}
* status-code, and using the default {@link #UNEXISTING_ASSET_DEFAULT_SIZE}.
*
* @return The {@link DownloadStatusProvider} with the {@link #UNEXISTING_ASSET_DEFAULT_SIZE} status-code.
* @since 2.3.4
*/
public static DownloadStatusProvider unknownAssetToDownload() {
return new DownloadStatusProvider(UNKNOWN_ASSET_TO_DOWNLOAD, UNEXISTING_ASSET_DEFAULT_SIZE);
}

/**
* Creates a new {@link DownloadStatusProvider} with the {@link #ASSET_DOWNLOAD_ERROR}
* status-code, and using the default {@link #INVALID_ASSET_DEFAULT_SIZE}.
*
* @return The {@link DownloadStatusProvider} with the {@link #ASSET_DOWNLOAD_ERROR} status-code.
* @since 2.3.4
*/
public static DownloadStatusProvider assetDownloadError() {
return new DownloadStatusProvider(ASSET_DOWNLOAD_ERROR, INVALID_ASSET_DEFAULT_SIZE);
}

/**
* Returns a boolean-state indicating if this provider's current status-code is {@link #ASSET_DOWNLOAD_FINISHED}.
*
* @return Whether this provider's current status-code is {@link #ASSET_DOWNLOAD_FINISHED}.
* @since 2.3.4
*/
public boolean finished() {
return this.status == ASSET_DOWNLOAD_FINISHED;
}

/**
* Returns a boolean-state indicating if this provider's current status-code is {@link #UNKNOWN_ASSET_TO_DOWNLOAD}.
*
* @return Whether this provider's current status-code is {@link #UNKNOWN_ASSET_TO_DOWNLOAD}.
* @since 2.3.4
*/
public boolean unknown() {
return this.status == UNKNOWN_ASSET_TO_DOWNLOAD;
}

/**
* Returns a boolean-state indicating if this provider's current status-code is {@link #ASSET_DOWNLOAD_ERROR}.
*
* @return Whether this provider's current status-code is {@link #ASSET_DOWNLOAD_ERROR}.
* @since 2.3.4
*/
public boolean error() {
return this.status == ASSET_DOWNLOAD_ERROR;
}
}
Loading
Loading