~tcarrio/github-sync

86ed517545ab5f7a383f5ee45995c97d3e644c94 — Tom Carrio 4 years ago 414af56 master
Configured CI for testing and mirror
19 files changed, 215 insertions(+), 31 deletions(-)

M .build.yml
M .gitignore
A .mvn/wrapper/MavenWrapperDownloader.java
A .mvn/wrapper/maven-wrapper.jar
A .mvn/wrapper/maven-wrapper.properties
A LICENSE
M pom.xml
R src/main/java/dev/carrio/github_sync/api/{IProjectController.java => api/IProjectController.java}
R src/main/java/dev/carrio/github_sync/api/{ProjectControllerImpl.java => api/ProjectControllerImpl.java}
R src/main/java/dev/carrio/github_sync/{dto/ActionDto.java => api/dto/ActionDto.java}
R src/main/java/dev/carrio/github_sync/{dto/ProjectDto.java => api/dto/ProjectDto.java}
R src/main/java/dev/carrio/github_sync/{entity/AbstractUUIDEntity.java => api/entity/AbstractUUIDEntity.java}
R src/main/java/dev/carrio/github_sync/{entity/Project.java => api/entity/Project.java}
R src/main/java/dev/carrio/github_sync/{entity/Repository.java => api/entity/Repository.java}
R src/main/java/dev/carrio/github_sync/{entity/User.java => api/entity/User.java}
A src/main/java/dev/carrio/github_sync/api/service/IProjectService.java
R src/main/java/dev/carrio/github_sync/{service/ProjectService.java => api/service/ProjectServiceImpl.java}
R src/test/java/dev/carrio/github_sync/{NativeProjectControllerIT.java => api/NativeProjectControllerIT.java}
R src/test/java/dev/carrio/github_sync/{ProjectControllerTest.java => api/ProjectControllerTest.java}
M .build.yml => .build.yml +8 -3
@@ 1,7 1,9 @@
image: archlinux
packages:
  - jdk11-openjdk
  - podman
sources:
  - https://git.sr.ht/~xaffe/takingstack
  - https://git.sr.ht/~tcarrio/github-sync
  - https://git.sr.ht/~tcarrio/git-mirror
environment:


@@ 10,7 12,10 @@ environment:
secrets:
  - 4e983fc2-9d24-43eb-9986-1c18feb2e7b8
tasks:
  - use-java-11: archlinux-java set java-11-openjdk
  - await-docker: while ! docker ps; do sleep 1; done
  - test-and-build: ./mvnw package -Pnative -Dquarkus.native.container-build=true
  - start-db: sudo podman run --rm -it -d --name=pgsql -e POSTGRES_PASSWORD=localdev -e POSTGRES_DB=sync_db -p 5432:5432 postgres
  - test: |
      sudo archlinux-java set java-11-openjdk
      cd $PROJECT_DIR
      ./mvnw clean test
  - stop-db: sudo podman stop pgsql
  - mirror-all: git-mirror/git-mirror.sh $PROJECT_DIR
\ No newline at end of file

M .gitignore => .gitignore +0 -1
@@ 1,5 1,4 @@
#Maven
.mvn
target/
pom.xml.tag
pom.xml.releaseBackup

A .mvn/wrapper/MavenWrapperDownloader.java => .mvn/wrapper/MavenWrapperDownloader.java +117 -0
@@ 0,0 1,117 @@
/*
 * Copyright 2007-present the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;

public class MavenWrapperDownloader {

    private static final String WRAPPER_VERSION = "0.5.6";
    /**
     * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
     */
    private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
        + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";

    /**
     * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
     * use instead of the default one.
     */
    private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
            ".mvn/wrapper/maven-wrapper.properties";

    /**
     * Path where the maven-wrapper.jar will be saved to.
     */
    private static final String MAVEN_WRAPPER_JAR_PATH =
            ".mvn/wrapper/maven-wrapper.jar";

    /**
     * Name of the property which should be used to override the default download url for the wrapper.
     */
    private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";

    public static void main(String args[]) {
        System.out.println("- Downloader started");
        File baseDirectory = new File(args[0]);
        System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());

        // If the maven-wrapper.properties exists, read it and check if it contains a custom
        // wrapperUrl parameter.
        File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
        String url = DEFAULT_DOWNLOAD_URL;
        if(mavenWrapperPropertyFile.exists()) {
            FileInputStream mavenWrapperPropertyFileInputStream = null;
            try {
                mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
                Properties mavenWrapperProperties = new Properties();
                mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
                url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
            } catch (IOException e) {
                System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
            } finally {
                try {
                    if(mavenWrapperPropertyFileInputStream != null) {
                        mavenWrapperPropertyFileInputStream.close();
                    }
                } catch (IOException e) {
                    // Ignore ...
                }
            }
        }
        System.out.println("- Downloading from: " + url);

        File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
        if(!outputFile.getParentFile().exists()) {
            if(!outputFile.getParentFile().mkdirs()) {
                System.out.println(
                        "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
            }
        }
        System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
        try {
            downloadFileFromURL(url, outputFile);
            System.out.println("Done");
            System.exit(0);
        } catch (Throwable e) {
            System.out.println("- Error downloading");
            e.printStackTrace();
            System.exit(1);
        }
    }

    private static void downloadFileFromURL(String urlString, File destination) throws Exception {
        if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
            String username = System.getenv("MVNW_USERNAME");
            char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
            Authenticator.setDefault(new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });
        }
        URL website = new URL(urlString);
        ReadableByteChannel rbc;
        rbc = Channels.newChannel(website.openStream());
        FileOutputStream fos = new FileOutputStream(destination);
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
        fos.close();
        rbc.close();
    }

}

A .mvn/wrapper/maven-wrapper.jar => .mvn/wrapper/maven-wrapper.jar +0 -0
A .mvn/wrapper/maven-wrapper.properties => .mvn/wrapper/maven-wrapper.properties +2 -0
@@ 0,0 1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

A LICENSE => LICENSE +21 -0
@@ 0,0 1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Thomas Carrio

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 NONINFRINGEMENT. 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.

M pom.xml => pom.xml +16 -0
@@ 119,6 119,22 @@
      </activation>
      <build>
        <plugins>
<!--          <plugin>-->
<!--            <groupId>io.quarkus</groupId>-->
<!--            <artifactId>quarkus-maven-plugin</artifactId>-->
<!--            <version>${quarkus.platform.version}</version>-->
<!--            <executions>-->
<!--              <execution>-->
<!--                <goals>-->
<!--                  <goal>native-image</goal>-->
<!--                </goals>-->
<!--                <configuration>-->
<!--                  <enableHttpUrlHandler>true</enableHttpUrlHandler>-->
<!--                  <additionalBuildArgs>-J-Xmx2G</additionalBuildArgs>-->
<!--                </configuration>-->
<!--              </execution>-->
<!--            </executions>-->
<!--          </plugin>-->
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${surefire-plugin.version}</version>

R src/main/java/dev/carrio/github_sync/api/IProjectController.java => src/main/java/dev/carrio/github_sync/api/api/IProjectController.java +3 -3
@@ 1,7 1,7 @@
package dev.carrio.github_sync.api;
package dev.carrio.github_sync.api.api;

import dev.carrio.github_sync.dto.ActionDto;
import dev.carrio.github_sync.dto.ProjectDto;
import dev.carrio.github_sync.api.dto.ProjectDto;
import dev.carrio.github_sync.api.dto.ActionDto;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

R src/main/java/dev/carrio/github_sync/api/ProjectControllerImpl.java => src/main/java/dev/carrio/github_sync/api/api/ProjectControllerImpl.java +10 -10
@@ 1,8 1,8 @@
package dev.carrio.github_sync.api;
package dev.carrio.github_sync.api.api;

import dev.carrio.github_sync.dto.ActionDto;
import dev.carrio.github_sync.dto.ProjectDto;
import dev.carrio.github_sync.service.ProjectService;
import dev.carrio.github_sync.api.dto.ActionDto;
import dev.carrio.github_sync.api.dto.ProjectDto;
import dev.carrio.github_sync.api.service.IProjectService;

import javax.inject.Inject;
import javax.ws.rs.*;


@@ 12,26 12,26 @@ import java.util.UUID;

public class ProjectControllerImpl implements IProjectController {
    @Inject
    private ProjectService projectService;
    private IProjectService projectServiceImpl;

    @Override
    public List<ProjectDto> getProjects() {
        return this.projectService.getProjects();
        return this.projectServiceImpl.getProjects();
    }

    @Override
    public Optional<ProjectDto> getProject(@PathParam("id") UUID id) {
        return this.projectService.getProject(id);
        return this.projectServiceImpl.getProject(id);
    }

    @Override
    public UUID createProject(ProjectDto project) {
        return this.projectService.createProject(project);
        return this.projectServiceImpl.createProject(project);
    }

    @Override
    public UUID updateProject(UUID id, ProjectDto project) {
        Optional<UUID> updated = this.projectService.updateProject(id, project);
        Optional<UUID> updated = this.projectServiceImpl.updateProject(id, project);
        if (!updated.isPresent()) {
            throw new NotFoundException(String.format("No project with ID %s found", id.toString()));
        }


@@ 43,7 43,7 @@ public class ProjectControllerImpl implements IProjectController {
    public ActionDto deleteProject(@PathParam("id") String id) {
        ActionDto currentAction = new ActionDto();
        try {
            Optional<UUID> deleted = this.projectService.deleteProject(id);
            Optional<UUID> deleted = this.projectServiceImpl.deleteProject(id);

            currentAction.success = deleted.isPresent();
            if (!currentAction.success) {

R src/main/java/dev/carrio/github_sync/dto/ActionDto.java => src/main/java/dev/carrio/github_sync/api/dto/ActionDto.java +1 -1
@@ 1,4 1,4 @@
package dev.carrio.github_sync.dto;
package dev.carrio.github_sync.api.dto;

public class ActionDto {
    public Boolean success;

R src/main/java/dev/carrio/github_sync/dto/ProjectDto.java => src/main/java/dev/carrio/github_sync/api/dto/ProjectDto.java +1 -1
@@ 1,4 1,4 @@
package dev.carrio.github_sync.dto;
package dev.carrio.github_sync.api.dto;

import java.net.URL;


R src/main/java/dev/carrio/github_sync/entity/AbstractUUIDEntity.java => src/main/java/dev/carrio/github_sync/api/entity/AbstractUUIDEntity.java +1 -1
@@ 1,4 1,4 @@
package dev.carrio.github_sync.entity;
package dev.carrio.github_sync.api.entity;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

R src/main/java/dev/carrio/github_sync/entity/Project.java => src/main/java/dev/carrio/github_sync/api/entity/Project.java +1 -1
@@ 1,4 1,4 @@
package dev.carrio.github_sync.entity;
package dev.carrio.github_sync.api.entity;

import javax.persistence.Entity;
import java.net.URL;

R src/main/java/dev/carrio/github_sync/entity/Repository.java => src/main/java/dev/carrio/github_sync/api/entity/Repository.java +1 -1
@@ 1,4 1,4 @@
package dev.carrio.github_sync.entity;
package dev.carrio.github_sync.api.entity;


//@Entity(name = "Repository")

R src/main/java/dev/carrio/github_sync/entity/User.java => src/main/java/dev/carrio/github_sync/api/entity/User.java +1 -1
@@ 1,4 1,4 @@
package dev.carrio.github_sync.entity;
package dev.carrio.github_sync.api.entity;


import javax.persistence.Entity;

A src/main/java/dev/carrio/github_sync/api/service/IProjectService.java => src/main/java/dev/carrio/github_sync/api/service/IProjectService.java +15 -0
@@ 0,0 1,15 @@
package dev.carrio.github_sync.api.service;

import dev.carrio.github_sync.api.dto.ProjectDto;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface IProjectService {
    List<ProjectDto> getProjects();
    Optional<ProjectDto> getProject(UUID id);
    UUID createProject(ProjectDto project);
    Optional<UUID> updateProject(UUID id, ProjectDto project);
    Optional<UUID> deleteProject(String id);
}

R src/main/java/dev/carrio/github_sync/service/ProjectService.java => src/main/java/dev/carrio/github_sync/api/service/ProjectServiceImpl.java +4 -4
@@ 1,7 1,7 @@
package dev.carrio.github_sync.service;
package dev.carrio.github_sync.api.service;

import dev.carrio.github_sync.dto.ProjectDto;
import dev.carrio.github_sync.entity.Project;
import dev.carrio.github_sync.api.dto.ProjectDto;
import dev.carrio.github_sync.api.entity.Project;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;


@@ 17,7 17,7 @@ import java.util.UUID;
import java.util.stream.Collectors;

@ApplicationScoped
public class ProjectService {
public class ProjectServiceImpl implements IProjectService {
    @Inject
    public EntityManager em;


R src/test/java/dev/carrio/github_sync/NativeProjectControllerIT.java => src/test/java/dev/carrio/github_sync/api/NativeProjectControllerIT.java +1 -1
@@ 1,4 1,4 @@
package dev.carrio.github_sync;
package dev.carrio.github_sync.api;

import io.quarkus.test.junit.NativeImageTest;


R src/test/java/dev/carrio/github_sync/ProjectControllerTest.java => src/test/java/dev/carrio/github_sync/api/ProjectControllerTest.java +12 -3
@@ 1,14 1,24 @@
package dev.carrio.github_sync;
package dev.carrio.github_sync.api;

import dev.carrio.github_sync.api.api.ProjectControllerImpl;
import dev.carrio.github_sync.api.dto.ProjectDto;
import dev.carrio.github_sync.api.service.IProjectService;
import dev.carrio.github_sync.api.service.ProjectServiceImpl;
import io.quarkus.test.Mock;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

@QuarkusTest
public class ProjectControllerTest {

    @Test
    public void testProjectsEndpoint() {
        given()


@@ 17,5 27,4 @@ public class ProjectControllerTest {
             .statusCode(200)
             .body(is("[]"));
    }

}
\ No newline at end of file