Skip to content

Commit

Permalink
Improve logging and add guide to the README
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Apr 8, 2020
1 parent 401226c commit 6e6ba95
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 37 deletions.
74 changes: 50 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ Lightweight repository manager for Maven artifacts.
It is a simple solution to replace managers like Nexus, Archiva or Artifactory.
As a successor of NanoMaven, you should also check the [Reposilite](https://github.com/panda-lang/reposilite) - enhanced repository management software mainly dedicated for Maven artifacts.

![obraz](https://user-images.githubusercontent.com/4235722/78812901-73b8c680-79cc-11ea-95d5-9763a53e4240.png)

#### Download
Releases: [GitHub Downloads](https://github.com/dzikoysk/NanoMaven/releases)
![Preview](https://user-images.githubusercontent.com/4235722/78812901-73b8c680-79cc-11ea-95d5-9763a53e4240.png)

#### Features
* [x] Working repository manager
Expand All @@ -19,50 +16,79 @@ Releases: [GitHub Downloads](https://github.com/dzikoysk/NanoMaven/releases)
* [ ] Statistics
* [ ] Code quality

#### Configuration
#### Download
Releases: [GitHub Downloads](https://github.com/dzikoysk/NanoMaven/releases)

#### Commands & Configuration
List of available management commands

```bash
NanoMaven 2.0.0 Commands:
help - List available commands
tokens - List all generated tokens
keygen <path> <alias> - Generate a new access token for the given path
rs - Reinstall all artifacts
stop - Shutdown server
```

Configuration

```yaml
# ~~~~~~~~~~~~~~~~~~~~~~ #
# Nano Maven #
# ~~~~~~~~~~~~~~~~~~~~~~ #

# General Repository Name
repository-name: NanoMaven Repository
repositoryName: NanoMaven Repository

# Hostname
hostname: ''
# Port
port: 80

# Include a repository names in the path
repository-path-enabled: false
repositoryPathEnabled: false
# Enable directory indexing
indexing-enabled: true
indexingEnabled: true

# Root directories of repositories
repositories:
- releases
- snapshots

# Nested Maven
nested-maven: true
nestedMaven: true
# External Maven directory (if 'nested-maven': false)
external-maven: /usr/local/share/java/maven33
externalMaven: /usr/local/share/java/maven33

# Accept deployment connections
deploy-enabled: true
# Require authorization
authorization-enabled: true
# Administrator accounts
administrators:
- dzikoysk
deployEnabled: true
```
#### Commands
Commands can be invoked from the console
#### Guide
To deploy artifacts we have to generate `access token` assigned to the given path. Example usages:

```bash
NanoMaven 2.0.0 Commands:
help - List available commands
tokens - List all generated tokens
keygen <path> <alias> - Generate a new access token for the given path
rs - Reinstall all artifacts
stop - Shutdown server
keygen / admin
19:55:20.692 INFO | Generated new access token for admin (/)
19:55:20.692 INFO | AW7-kaXSSXTRVL_Ip9v7ruIiqe56gh96o1XdSrqZCyTX2vUsrZU3roVOfF-YYF-y
19:55:20.723 INFO | Stored tokens: 1
keygen /org/panda-lang/nanomaven nanomaven
19:56:09.109 INFO | Generated new access token for nanomaven (/org/panda-lang/nanomaven)
19:56:09.109 INFO | OFnV-2GiZeX0cHpeDvuLo0xjUpU5wNUcpkR4521fG68U9anfqNwKsVkFcQUCK4yk
19:56:09.114 INFO | Stored tokens: 2
```

To use generated token add a new server in your `./m2/settings.xml`

```xml
<server>
<id>{repository-id}</id>
<username>{alias}</username>
<password>{token}</password>
</server>
```
#### Maven builds
You can also use maven builds to embed NanoMaven in your application

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/panda_lang/nanomaven/NanoConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class NanoConstants {

public static final String VERSION = "2.0.0";

static final String GREETING_MESSAGE = ansi().bold().fg(Color.CYAN).a("NanoMaven ").reset().a(NanoConstants.VERSION).toString();
static final String GREETING_MESSAGE = ansi().bold().fg(Color.GREEN).a("NanoMaven ").reset().a(NanoConstants.VERSION).toString();

public static final String CONFIGURATION_FILE_NAME = "nanomaven.yml";

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/panda_lang/nanomaven/NanoMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ public static void main(String[] args) throws Exception {
}

public void launch() throws Exception {
getLogger().info("");
getLogger().info(NanoConstants.GREETING_MESSAGE);
getLogger().info("");

NanoMaven.getLogger().info("--- Preparing workspace");
NanoWorkspace workspace = new NanoWorkspace();
workspace.prepare();

Expand All @@ -66,13 +69,16 @@ public void launch() throws Exception {
FrontendLoader frontendLoader = new FrontendLoader();
this.frontend = frontendLoader.loadFrontend(NanoConstants.FRONTEND_FILE_NAME);

getLogger().info("--- Loading data");
this.tokenService = new TokenService();
tokenService.load();
getLogger().info("");

this.repositoryService = new RepositoryService();
repositoryService.scan(configuration);
getLogger().info("");

getLogger().info("Binding at *::" + configuration.getPort());
getLogger().info("Binding server at *::" + configuration.getPort());
this.httpServer = new NanoHttpServer(this);
this.uptime = System.currentTimeMillis();

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/panda_lang/nanomaven/NanoWorkspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
public class NanoWorkspace {

public void prepare() {
NanoMaven.getLogger().info("Preparing workspace");

if (!FilesUtils.fileExists(NanoConstants.CONFIGURATION_FILE_NAME)) {
NanoMaven.getLogger().info("Generating default configuration file.");
FilesUtils.copyResource("/nanomaven.yml", NanoConstants.CONFIGURATION_FILE_NAME);
Expand All @@ -39,7 +37,7 @@ public void prepare() {
NanoMaven.getLogger().info("Default repositories have been created");
}
else {
NanoMaven.getLogger().info("Using an existing repositories");
NanoMaven.getLogger().info("Using an existing repositories directory");
}

// Maven
Expand All @@ -61,6 +59,8 @@ public void prepare() {
else {
NanoMaven.getLogger().info("Using an existing tokens data file");
}

NanoMaven.getLogger().info("");
}

}
11 changes: 9 additions & 2 deletions src/main/java/org/panda_lang/nanomaven/auth/KeygenCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.panda_lang.nanomaven.NanoMaven;
import org.panda_lang.nanomaven.console.NanoCommand;

import java.io.IOException;

public final class KeygenCommand implements NanoCommand {

private final TokenService tokenService;
Expand All @@ -40,8 +42,13 @@ public void call(NanoMaven nanoMaven) {
String token = tokenService.generateToken();
tokenService.addToken(new Token(path, alias, TokenService.B_CRYPT_TOKENS_ENCODER.encode(token)));

NanoMaven.getLogger().info("Generated new access token for " + alias + " (" + path + ")");
NanoMaven.getLogger().info(token);
try {
NanoMaven.getLogger().info("Generated new access token for " + alias + " (" + path + ")");
NanoMaven.getLogger().info(token);
tokenService.save();
} catch (IOException e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

public class TokensStorage {

Expand All @@ -40,18 +41,19 @@ public void loadTokens() throws IOException {
tokenService.addToken(token);
}

NanoMaven.getLogger().info("Loaded tokens: " + tokenService.count());
NanoMaven.getLogger().info("Tokens: " + tokenService.count());
}

public void saveTokens() throws IOException {
TokensCollection tokensCollection = YamlUtils.load(TOKENS_FILE, TokensCollection.class);
TokensCollection tokensCollection = new TokensCollection();
tokensCollection.setTokens(new ArrayList<>());

for (Token token : tokenService.getTokens()) {
tokensCollection.getTokens().add(token);
}

YamlUtils.save(TOKENS_FILE, tokensCollection);
NanoMaven.getLogger().info("Saved tokens: " + tokensCollection.getTokens().size());
NanoMaven.getLogger().info("Stored tokens: " + tokensCollection.getTokens().size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void scan(NanoConfiguration configuration) {
File rootDirectory = new File("repositories");
repositories.clear();

NanoMaven.getLogger().info("Scanning to find repositories...");
NanoMaven.getLogger().info("--- Scanning to find repositories");

for (String repositoryName : configuration.getRepositories()) {
File repositoryDirectory = new File(rootDirectory, repositoryName);
Expand All @@ -51,12 +51,12 @@ public void scan(NanoConfiguration configuration) {
}

Repository repository = new Repository(repositoryName);
NanoMaven.getLogger().info(" + " + repositoryDirectory.getName());
NanoMaven.getLogger().info("+ " + repositoryDirectory.getName());

repositories.put(repository.getRepositoryName(), repository);
}

NanoMaven.getLogger().info("Result: " + repositories.size() + " repositories have been found");
NanoMaven.getLogger().info(repositories.size() + " repositories have been found");
}

public Artifact find(String... path) {
Expand Down

0 comments on commit 6e6ba95

Please sign in to comment.