Add sonarqube (#37)

This commit is contained in:
Mikołaj Pich
2017-11-26 16:32:33 +01:00
committed by Rafał Borcz
parent 9ee0ca3010
commit 647ed08460
39 changed files with 277 additions and 148 deletions

View File

@ -1,6 +1,6 @@
apply plugin: 'java-library'
apply plugin: 'org.sonarqube'
apply plugin: 'jacoco'
apply plugin: "io.github.ddimtirov.codacy"
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'
@ -8,9 +8,9 @@ sourceCompatibility = "1.7"
targetCompatibility = "1.7"
ext {
PUBLISH_GROUP_ID = 'io.github.wulkanowy'
PUBLISH_GROUP_ID = GROUP_ID
PUBLISH_ARTIFACT_ID = 'api'
PUBLISH_VERSION = '0.1.0'
PUBLISH_VERSION = System.getenv('GIT_TAG')
}
test {
@ -21,6 +21,12 @@ test {
}
}
jacocoTestReport {
reports {
xml.enabled true
}
}
dependencies {
implementation 'org.jsoup:jsoup:1.10.3'
implementation 'org.apache.commons:commons-lang3:3.6'
@ -29,9 +35,18 @@ dependencies {
testImplementation 'org.mockito:mockito-core:2.11.0'
}
version = PUBLISH_VERSION
group = GROUP_ID
sonarqube {
properties {
property "sonar.projectName", GROUP_ID + ":api"
property "sonar.projectKey", GROUP_ID + ":wulkanowy-api"
}
}
def siteUrl = 'https://github.com/wulkanowy/wulkanowy'
def gitUrl = 'https://github.com/wulkanowy/wulkanowy.git'
version = '0.1.0'
bintray {
user = System.getenv('BINTRAY_USER')
@ -45,10 +60,11 @@ bintray {
vcsUrl = gitUrl
labels = ['aar', 'android', 'wulkanowy', 'api']
publicDownloadNumbers = true
publish = true
version {
name = '0.1.0'
vcsTag = '0.1.0'
name = PUBLISH_VERSION
vcsTag = PUBLISH_VERSION
released = new Date()
}
}
@ -83,3 +99,18 @@ install {
}
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}

View File

@ -5,19 +5,19 @@ import java.util.Map;
public class Cookies {
private Map<String, String> cookies = new HashMap<>();
private Map<String, String> jar = new HashMap<>();
public Map<String, String> getItems() {
return cookies;
return jar;
}
public Cookies setItems(Map<String, String> items) {
this.cookies = items;
this.jar = items;
return this;
}
public Cookies addItems(Map<String, String> items) {
this.cookies.putAll(items);
this.jar.putAll(items);
return this;
}
}

View File

@ -16,7 +16,9 @@ public class StudentAndParent extends Api {
private String baseUrl = "https://uonetplus-opiekun.vulcan.net.pl/{symbol}/{ID}/";
private String gradesPageUrl = baseUrl + "Oceny/Wszystkie";
private static final String SYMBOL_PLACEHOLDER = "{symbol}";
private static final String GRADES_PAGE_URL = "Oceny/Wszystkie";
private String symbol;
@ -33,7 +35,7 @@ public class StudentAndParent extends Api {
}
public String getGradesPageUrl() {
return gradesPageUrl;
return baseUrl + GRADES_PAGE_URL;
}
public String getBaseUrl() {
@ -58,11 +60,11 @@ public class StudentAndParent extends Api {
public String getSnpPageUrl() throws IOException, NotLoggedInErrorException {
if (null != getId()) {
return getBaseUrl().replace("{symbol}", getSymbol()).replace("{ID}", getId());
return getBaseUrl().replace(SYMBOL_PLACEHOLDER, getSymbol()).replace("{ID}", getId());
}
// get url to uonetplus-opiekun.vulcan.net.pl
Document startPage = getPageByUrl(getStartPageUrl().replace("{symbol}", getSymbol()));
Document startPage = getPageByUrl(getStartPageUrl().replace(SYMBOL_PLACEHOLDER, getSymbol()));
Element studentTileLink = startPage.select(".panel.linkownia.pracownik.klient > a").first();
if (null == studentTileLink) {
@ -92,7 +94,7 @@ public class StudentAndParent extends Api {
public Document getSnPPageDocument(String url) throws IOException {
return getPageByUrl(getBaseUrl()
.replace("{symbol}", getSymbol())
.replace(SYMBOL_PLACEHOLDER, getSymbol())
.replace("{ID}", getId()) + url);
}

View File

@ -14,7 +14,7 @@ public class ExamsWeek {
private final StudentAndParent snp;
private final String examsPageUrl = "Sprawdziany.mvc/Terminarz?rodzajWidoku=2&data=";
private static final String EXAMS_PAGE_URL = "Sprawdziany.mvc/Terminarz?rodzajWidoku=2&data=";
public ExamsWeek(StudentAndParent snp) {
this.snp = snp;
@ -25,7 +25,7 @@ public class ExamsWeek {
}
public Week getWeek(String tick, final boolean onlyNotEmpty) throws IOException {
Document examsPage = snp.getSnPPageDocument(examsPageUrl + tick);
Document examsPage = snp.getSnPPageDocument(EXAMS_PAGE_URL + tick);
Elements examsDays = examsPage.select(".mainContainer > div:not(.navigation)");
List<Day> days = new ArrayList<>();

View File

@ -16,13 +16,12 @@ import java.util.regex.Pattern;
import io.github.wulkanowy.api.Semester;
import io.github.wulkanowy.api.StudentAndParent;
import io.github.wulkanowy.api.login.LoginErrorException;
public class GradesList {
private StudentAndParent snp = null;
private String gradesPageUrl = "Oceny/Wszystkie?details=2&okres=";
private static final String GRADES_PAGE_URL = "Oceny/Wszystkie?details=2&okres=";
private List<Grade> grades = new ArrayList<>();
@ -31,10 +30,10 @@ public class GradesList {
}
public String getGradesPageUrl() {
return gradesPageUrl;
return GRADES_PAGE_URL;
}
public List<Grade> getAll() throws IOException, LoginErrorException, ParseException {
public List<Grade> getAll() throws IOException, ParseException {
return getAll("");
}

View File

@ -14,14 +14,14 @@ public class SubjectsList {
private StudentAndParent snp = null;
private String subjectsPageUrl = "Oceny/Wszystkie?details=1";
private static final String SUBJECTS_PAGE_URL = "Oceny/Wszystkie?details=1";
public SubjectsList(StudentAndParent snp) {
this.snp = snp;
}
public List<Subject> getAll() throws IOException {
Document subjectPage = snp.getSnPPageDocument(subjectsPageUrl);
Document subjectPage = snp.getSnPPageDocument(SUBJECTS_PAGE_URL);
Elements rows = subjectPage.select(".ocenyZwykle-table > tbody > tr");

View File

@ -90,7 +90,7 @@ public class Login extends Api {
Elements els = Jsoup.parse(certificate.replaceAll(":", ""), "", Parser.xmlParser())
.select("[AttributeName=\"UserInstance\"] samlAttributeValue");
if (0 == els.size()) {
if (els.isEmpty()) {
return "";
}

View File

@ -13,23 +13,23 @@ public class AchievementsList {
private StudentAndParent snp = null;
private List<String> achievementsList = new ArrayList<>();
private List<String> achievements = new ArrayList<>();
private String notesPageUrl = "UwagiOsiagniecia.mvc/Wszystkie";
private static final String NOTES_PAGE_URL = "UwagiOsiagniecia.mvc/Wszystkie";
public AchievementsList(StudentAndParent snp) {
this.snp = snp;
}
public List<String> getAllAchievements() throws IOException {
Element pageFragment = snp.getSnPPageDocument(notesPageUrl)
Element pageFragment = snp.getSnPPageDocument(NOTES_PAGE_URL)
.select(".mainContainer > div").get(1);
Elements items = pageFragment.select("article");
for (Element item : items) {
achievementsList.add(item.text());
achievements.add(item.text());
}
return achievementsList;
return achievements;
}
}

View File

@ -13,23 +13,23 @@ public class NotesList {
private StudentAndParent snp = null;
private List<Note> notesList = new ArrayList<>();
private List<Note> notes = new ArrayList<>();
private String notesPageUrl = "UwagiOsiagniecia.mvc/Wszystkie";
private static final String NOTES_PAGE_URL = "UwagiOsiagniecia.mvc/Wszystkie";
public NotesList(StudentAndParent snp) {
this.snp = snp;
}
public List<Note> getAllNotes() throws IOException {
Element pageFragment = snp.getSnPPageDocument(notesPageUrl)
Element pageFragment = snp.getSnPPageDocument(NOTES_PAGE_URL)
.select(".mainContainer > div").get(0);
Elements items = pageFragment.select("article");
Elements dates = pageFragment.select("h2");
int index = 0;
for (Element item : items) {
notesList.add(new Note()
notes.add(new Note()
.setDate(dates.get(index++).text())
.setTeacher(snp.getRowDataChildValue(item, 1))
.setCategory(snp.getRowDataChildValue(item, 2))
@ -37,6 +37,6 @@ public class NotesList {
);
}
return notesList;
return notes;
}
}

View File

@ -10,14 +10,14 @@ public class SchoolInfo {
private StudentAndParent snp = null;
private String schoolPageUrl = "Szkola.mvc/Nauczyciele";
private static final String SCHOOL_PAGE_URL = "Szkola.mvc/Nauczyciele";
public SchoolInfo(StudentAndParent snp) {
this.snp = snp;
}
public SchoolData getSchoolData() throws IOException {
Element e = snp.getSnPPageDocument(schoolPageUrl)
Element e = snp.getSnPPageDocument(SCHOOL_PAGE_URL)
.select(".mainContainer > article").get(0);
return new SchoolData()

View File

@ -14,14 +14,14 @@ public class TeachersInfo {
private StudentAndParent snp = null;
private String schoolPageUrl = "Szkola.mvc/Nauczyciele";
private static final String SCHOOL_PAGE_URL = "Szkola.mvc/Nauczyciele";
public TeachersInfo(StudentAndParent snp) {
this.snp = snp;
}
public TeachersData getTeachersData() throws IOException {
Document doc = snp.getSnPPageDocument(schoolPageUrl);
Document doc = snp.getSnPPageDocument(SCHOOL_PAGE_URL);
Elements rows = doc.select(".mainContainer > table tbody tr");
String description = doc.select(".mainContainer > p").first().text();

View File

@ -9,24 +9,23 @@ import java.util.ArrayList;
import java.util.List;
import io.github.wulkanowy.api.StudentAndParent;
import io.github.wulkanowy.api.login.LoginErrorException;
public class Timetable {
private StudentAndParent snp;
private String timetablePageUrl = "Lekcja.mvc/PlanLekcji?data=";
private static final String TIMETABLE_PAGE_URL = "Lekcja.mvc/PlanLekcji?data=";
public Timetable(StudentAndParent snp) {
this.snp = snp;
}
public Week getWeekTable() throws IOException, LoginErrorException {
public Week getWeekTable() throws IOException {
return getWeekTable("");
}
public Week getWeekTable(String tick) throws IOException {
Element table = snp.getSnPPageDocument(timetablePageUrl + tick)
Element table = snp.getSnPPageDocument(TIMETABLE_PAGE_URL + tick)
.select(".mainContainer .presentData").first();
Elements tableHeaderCells = table.select("thead th");
@ -100,14 +99,14 @@ public class Timetable {
lesson.setRoom(spans.get(3).text());
}
lesson = getLessonGroupDivisionInfo(lesson, spans);
lesson = getLessonTypeInfo(lesson, spans);
lesson = getLessonDescriptionInfo(lesson, spans);
addGroupDivisionInfo(lesson, spans);
adTypeInfo(lesson, spans);
addDescriptionInfo(lesson, spans);
return lesson;
}
private Lesson getLessonGroupDivisionInfo(Lesson lesson, Elements e) {
private void addGroupDivisionInfo(Lesson lesson, Elements e) {
if ((4 == e.size() && (e.first().attr("class").equals("")) ||
(5 == e.size() && e.first().hasClass(Lesson.CLASS_NEW_MOVED_IN_OR_CHANGED)))) {
lesson.setDivisionIntoGroups(true);
@ -118,11 +117,9 @@ public class Timetable {
lesson.setTeacher(e.get(2).text());
lesson.setRoom(e.get(3).text());
}
return lesson;
}
private Lesson getLessonTypeInfo(Lesson lesson, Elements e) {
private void adTypeInfo(Lesson lesson, Elements e) {
if (e.first().hasClass(Lesson.CLASS_MOVED_OR_CANCELED)) {
lesson.setMovedOrCanceled(true);
} else if (e.first().hasClass(Lesson.CLASS_NEW_MOVED_IN_OR_CHANGED)) {
@ -135,17 +132,13 @@ public class Timetable {
|| e.first().attr("class").equals("")) {
lesson.setRealized(true);
}
return lesson;
}
private Lesson getLessonDescriptionInfo(Lesson lesson, Elements e) {
private void addDescriptionInfo(Lesson lesson, Elements e) {
if ((4 == e.size() || 5 == e.size())
&& (e.first().hasClass(Lesson.CLASS_MOVED_OR_CANCELED)
|| e.first().hasClass(Lesson.CLASS_NEW_MOVED_IN_OR_CHANGED))) {
lesson.setDescription(StringUtils.substringBetween(e.last().text(), "(", ")"));
}
return lesson;
}
}

View File

@ -6,15 +6,16 @@ import org.jsoup.nodes.Element;
import java.io.IOException;
import io.github.wulkanowy.api.StudentAndParent;
import io.github.wulkanowy.api.login.LoginErrorException;
public class BasicInformation {
private static Document studentDataPageDocument;
private Document studentDataPageDocument;
private StudentAndParent snp;
private String studentDataPageUrl = "Uczen.mvc/DanePodstawowe";
private static final String STUDENT_DATA_PAGE_URL = "Uczen.mvc/DanePodstawowe";
private static final String CONTENT_QUERY = ".mainContainer > article";
public BasicInformation(StudentAndParent snp) {
this.snp = snp;
@ -22,14 +23,14 @@ public class BasicInformation {
public Document getStudentDataPageDocument() throws IOException {
if (null == studentDataPageDocument) {
studentDataPageDocument = snp.getSnPPageDocument(studentDataPageUrl);
studentDataPageDocument = snp.getSnPPageDocument(STUDENT_DATA_PAGE_URL);
}
return studentDataPageDocument;
}
public PersonalData getPersonalData() throws IOException, LoginErrorException {
Element e = getStudentDataPageDocument().select(".mainContainer > article").get(0);
public PersonalData getPersonalData() throws IOException {
Element e = getStudentDataPageDocument().select(CONTENT_QUERY).get(0);
String name = snp.getRowDataChildValue(e, 1);
String[] names = name.split(" ");
@ -47,8 +48,8 @@ public class BasicInformation {
.setParentsNames(snp.getRowDataChildValue(e, 7));
}
public AddressData getAddressData() throws IOException, LoginErrorException {
Element e = getStudentDataPageDocument().select(".mainContainer > article").get(1);
public AddressData getAddressData() throws IOException {
Element e = getStudentDataPageDocument().select(CONTENT_QUERY).get(1);
return new AddressData()
.setAddress(snp.getRowDataChildValue(e, 1))
@ -57,8 +58,8 @@ public class BasicInformation {
}
public ContactDetails getContactDetails() throws IOException, LoginErrorException {
Element e = getStudentDataPageDocument().select(".mainContainer > article").get(2);
public ContactDetails getContactDetails() throws IOException {
Element e = getStudentDataPageDocument().select(CONTENT_QUERY).get(2);
return new ContactDetails()
.setPhoneNumber(snp.getRowDataChildValue(e, 1))

View File

@ -13,14 +13,14 @@ public class FamilyInformation {
private StudentAndParent snp;
private String studentDataPageUrl = "Uczen.mvc/DanePodstawowe";
private static final String STUDENT_DATA_PAGE_URL = "Uczen.mvc/DanePodstawowe";
public FamilyInformation(StudentAndParent snp) {
this.snp = snp;
}
public List<FamilyMember> getFamilyMembers() throws IOException {
Elements membersElements = snp.getSnPPageDocument(studentDataPageUrl)
Elements membersElements = snp.getSnPPageDocument(STUDENT_DATA_PAGE_URL)
.select(".mainContainer > article:nth-of-type(n+4)");
List<FamilyMember> familyMembers = new ArrayList<>();