repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
albfernandez/javadbf | src/test/java/com/linuxense/javadbf/FixtureDBaseF5Test.java | // Path: src/test/java/com/linuxense/javadbf/testutils/AssertUtils.java
// public class AssertUtils {
//
// public static void assertColumnDefinition(DBFField field, String columnName, DBFDataType type, int length, int decimal) {
// Assert.assertEquals(columnName, field.getName());
// Assert.assertEquals(type, field.getType());
// Assert.assertEquals(length, field.getLength());
// Assert.assertEquals(decimal, field.getDecimalCount());
// }
//
// }
//
// Path: src/test/java/com/linuxense/javadbf/testutils/DbfToTxtTest.java
// public final class DbfToTxtTest {
//
// private DbfToTxtTest() {
// throw new AssertionError("no instances");
// }
//
// public static void export(DBFReader reader, File file) {
//
// PrintWriter writer = null;
// try {
// writer = new PrintWriter(file, "UTF-8");
// Object[] row = null;
//
// while ((row = reader.nextRecord()) != null) {
// for (Object o : row) {
// writer.print(o + ";");
// }
// writer.println("");
// }
// }
// catch (IOException e) {
// // nop
// }
// finally {
// DBFUtils.close(writer);
// }
// }
//
// public static void writeToConsole(File file) throws FileNotFoundException {
// DBFReader reader = null;
// try {
//
//
// // create a DBFReader object
// reader = new DBFReader(new BufferedInputStream(new FileInputStream(file)));
//
// // get the field count if you want for some reasons like the following
//
// int numberOfFields = reader.getFieldCount();
//
// // use this count to fetch all field information
// // if required
//
// for (int i = 0; i < numberOfFields; i++) {
//
// DBFField field = reader.getField(i);
//
// // // do something with it if you want
// // // refer the JavaDoc API reference for more details
// // //
// System.out.println(field.getType() + " (" + field.getLength() + ") "+ field.getName());
// }
//
// // Now, lets us start reading the rows
//
// Object[] rowObjects;
//
// int count = 0;
// System.out.println("-------------------");
//
//
// while ((rowObjects = reader.nextRecord()) != null) {
// count++;
// for (int i = 0; i < rowObjects.length; i++) {
// System.out.println(rowObjects[i]);
// }
// System.out.println("-------------------");
// }
// System.out.println(file.getName() + " count=" + count);
//
// // By now, we have iterated through all of the rows
// }
// finally {
// DBFUtils.close(reader);
// }
// }
//
// public static int parseFileCountRecords(File file) throws FileNotFoundException {
// DBFReader reader = null;
// int count=0;
// try {
// // create a DBFReader object
// reader = new DBFReader(new BufferedInputStream(new FileInputStream(file)));
// while(reader.nextRow() != null) {
// count++;
// }
// }
// finally {
// DBFUtils.close(reader);
// }
// return count;
// }
//
// public static void main(String[] args) throws Exception {
// File f = new File(args[0]);
// writeToConsole(f);
// }
// }
| import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import org.junit.Assert;
import org.junit.Test;
import com.linuxense.javadbf.testutils.AssertUtils;
import com.linuxense.javadbf.testutils.DbfToTxtTest; | /*
(C) Copyright 2017 Alberto Fernández <infjaf@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
package com.linuxense.javadbf;
public class FixtureDBaseF5Test {
@Test
public void test31() throws Exception {
File file = new File("src/test/resources/fixtures/dbase_f5.dbf");
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(file));
DBFReader reader = new DBFReader(inputStream);
reader.setMemoFile(new File("src/test/resources/fixtures/dbase_f5.fpt"));
DBFHeader header = reader.getHeader();
Assert.assertNotNull(header);
Assert.assertEquals(59, header.fieldArray.length);
Assert.assertEquals(975, header.numberOfRecords);
DBFField[] fieldArray = header.fieldArray;
int i = 0;
| // Path: src/test/java/com/linuxense/javadbf/testutils/AssertUtils.java
// public class AssertUtils {
//
// public static void assertColumnDefinition(DBFField field, String columnName, DBFDataType type, int length, int decimal) {
// Assert.assertEquals(columnName, field.getName());
// Assert.assertEquals(type, field.getType());
// Assert.assertEquals(length, field.getLength());
// Assert.assertEquals(decimal, field.getDecimalCount());
// }
//
// }
//
// Path: src/test/java/com/linuxense/javadbf/testutils/DbfToTxtTest.java
// public final class DbfToTxtTest {
//
// private DbfToTxtTest() {
// throw new AssertionError("no instances");
// }
//
// public static void export(DBFReader reader, File file) {
//
// PrintWriter writer = null;
// try {
// writer = new PrintWriter(file, "UTF-8");
// Object[] row = null;
//
// while ((row = reader.nextRecord()) != null) {
// for (Object o : row) {
// writer.print(o + ";");
// }
// writer.println("");
// }
// }
// catch (IOException e) {
// // nop
// }
// finally {
// DBFUtils.close(writer);
// }
// }
//
// public static void writeToConsole(File file) throws FileNotFoundException {
// DBFReader reader = null;
// try {
//
//
// // create a DBFReader object
// reader = new DBFReader(new BufferedInputStream(new FileInputStream(file)));
//
// // get the field count if you want for some reasons like the following
//
// int numberOfFields = reader.getFieldCount();
//
// // use this count to fetch all field information
// // if required
//
// for (int i = 0; i < numberOfFields; i++) {
//
// DBFField field = reader.getField(i);
//
// // // do something with it if you want
// // // refer the JavaDoc API reference for more details
// // //
// System.out.println(field.getType() + " (" + field.getLength() + ") "+ field.getName());
// }
//
// // Now, lets us start reading the rows
//
// Object[] rowObjects;
//
// int count = 0;
// System.out.println("-------------------");
//
//
// while ((rowObjects = reader.nextRecord()) != null) {
// count++;
// for (int i = 0; i < rowObjects.length; i++) {
// System.out.println(rowObjects[i]);
// }
// System.out.println("-------------------");
// }
// System.out.println(file.getName() + " count=" + count);
//
// // By now, we have iterated through all of the rows
// }
// finally {
// DBFUtils.close(reader);
// }
// }
//
// public static int parseFileCountRecords(File file) throws FileNotFoundException {
// DBFReader reader = null;
// int count=0;
// try {
// // create a DBFReader object
// reader = new DBFReader(new BufferedInputStream(new FileInputStream(file)));
// while(reader.nextRow() != null) {
// count++;
// }
// }
// finally {
// DBFUtils.close(reader);
// }
// return count;
// }
//
// public static void main(String[] args) throws Exception {
// File f = new File(args[0]);
// writeToConsole(f);
// }
// }
// Path: src/test/java/com/linuxense/javadbf/FixtureDBaseF5Test.java
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import org.junit.Assert;
import org.junit.Test;
import com.linuxense.javadbf.testutils.AssertUtils;
import com.linuxense.javadbf.testutils.DbfToTxtTest;
/*
(C) Copyright 2017 Alberto Fernández <infjaf@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
package com.linuxense.javadbf;
public class FixtureDBaseF5Test {
@Test
public void test31() throws Exception {
File file = new File("src/test/resources/fixtures/dbase_f5.dbf");
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(file));
DBFReader reader = new DBFReader(inputStream);
reader.setMemoFile(new File("src/test/resources/fixtures/dbase_f5.fpt"));
DBFHeader header = reader.getHeader();
Assert.assertNotNull(header);
Assert.assertEquals(59, header.fieldArray.length);
Assert.assertEquals(975, header.numberOfRecords);
DBFField[] fieldArray = header.fieldArray;
int i = 0;
| AssertUtils.assertColumnDefinition(fieldArray[i++], "NF", DBFDataType.fromCode((byte) 'N'), 5, 0); |
albfernandez/javadbf | src/test/java/com/linuxense/javadbf/DBFReaderPrintTest.java | // Path: src/test/java/com/linuxense/javadbf/testutils/DbfToTxtTest.java
// public final class DbfToTxtTest {
//
// private DbfToTxtTest() {
// throw new AssertionError("no instances");
// }
//
// public static void export(DBFReader reader, File file) {
//
// PrintWriter writer = null;
// try {
// writer = new PrintWriter(file, "UTF-8");
// Object[] row = null;
//
// while ((row = reader.nextRecord()) != null) {
// for (Object o : row) {
// writer.print(o + ";");
// }
// writer.println("");
// }
// }
// catch (IOException e) {
// // nop
// }
// finally {
// DBFUtils.close(writer);
// }
// }
//
// public static void writeToConsole(File file) throws FileNotFoundException {
// DBFReader reader = null;
// try {
//
//
// // create a DBFReader object
// reader = new DBFReader(new BufferedInputStream(new FileInputStream(file)));
//
// // get the field count if you want for some reasons like the following
//
// int numberOfFields = reader.getFieldCount();
//
// // use this count to fetch all field information
// // if required
//
// for (int i = 0; i < numberOfFields; i++) {
//
// DBFField field = reader.getField(i);
//
// // // do something with it if you want
// // // refer the JavaDoc API reference for more details
// // //
// System.out.println(field.getType() + " (" + field.getLength() + ") "+ field.getName());
// }
//
// // Now, lets us start reading the rows
//
// Object[] rowObjects;
//
// int count = 0;
// System.out.println("-------------------");
//
//
// while ((rowObjects = reader.nextRecord()) != null) {
// count++;
// for (int i = 0; i < rowObjects.length; i++) {
// System.out.println(rowObjects[i]);
// }
// System.out.println("-------------------");
// }
// System.out.println(file.getName() + " count=" + count);
//
// // By now, we have iterated through all of the rows
// }
// finally {
// DBFUtils.close(reader);
// }
// }
//
// public static int parseFileCountRecords(File file) throws FileNotFoundException {
// DBFReader reader = null;
// int count=0;
// try {
// // create a DBFReader object
// reader = new DBFReader(new BufferedInputStream(new FileInputStream(file)));
// while(reader.nextRow() != null) {
// count++;
// }
// }
// finally {
// DBFUtils.close(reader);
// }
// return count;
// }
//
// public static void main(String[] args) throws Exception {
// File f = new File(args[0]);
// writeToConsole(f);
// }
// }
| import com.linuxense.javadbf.testutils.DbfToTxtTest;
import java.io.File;
import java.io.FileInputStream;
import org.junit.Test; | /*
(C) Copyright 2017 Alberto Fernández <infjaf@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
package com.linuxense.javadbf;
public class DBFReaderPrintTest {
@Test
public void printFile() throws Exception {
File file = new File("src/test/resources/books.dbf");
DBFReader reader = null;
try {
reader = new DBFReader(new FileInputStream(file)); | // Path: src/test/java/com/linuxense/javadbf/testutils/DbfToTxtTest.java
// public final class DbfToTxtTest {
//
// private DbfToTxtTest() {
// throw new AssertionError("no instances");
// }
//
// public static void export(DBFReader reader, File file) {
//
// PrintWriter writer = null;
// try {
// writer = new PrintWriter(file, "UTF-8");
// Object[] row = null;
//
// while ((row = reader.nextRecord()) != null) {
// for (Object o : row) {
// writer.print(o + ";");
// }
// writer.println("");
// }
// }
// catch (IOException e) {
// // nop
// }
// finally {
// DBFUtils.close(writer);
// }
// }
//
// public static void writeToConsole(File file) throws FileNotFoundException {
// DBFReader reader = null;
// try {
//
//
// // create a DBFReader object
// reader = new DBFReader(new BufferedInputStream(new FileInputStream(file)));
//
// // get the field count if you want for some reasons like the following
//
// int numberOfFields = reader.getFieldCount();
//
// // use this count to fetch all field information
// // if required
//
// for (int i = 0; i < numberOfFields; i++) {
//
// DBFField field = reader.getField(i);
//
// // // do something with it if you want
// // // refer the JavaDoc API reference for more details
// // //
// System.out.println(field.getType() + " (" + field.getLength() + ") "+ field.getName());
// }
//
// // Now, lets us start reading the rows
//
// Object[] rowObjects;
//
// int count = 0;
// System.out.println("-------------------");
//
//
// while ((rowObjects = reader.nextRecord()) != null) {
// count++;
// for (int i = 0; i < rowObjects.length; i++) {
// System.out.println(rowObjects[i]);
// }
// System.out.println("-------------------");
// }
// System.out.println(file.getName() + " count=" + count);
//
// // By now, we have iterated through all of the rows
// }
// finally {
// DBFUtils.close(reader);
// }
// }
//
// public static int parseFileCountRecords(File file) throws FileNotFoundException {
// DBFReader reader = null;
// int count=0;
// try {
// // create a DBFReader object
// reader = new DBFReader(new BufferedInputStream(new FileInputStream(file)));
// while(reader.nextRow() != null) {
// count++;
// }
// }
// finally {
// DBFUtils.close(reader);
// }
// return count;
// }
//
// public static void main(String[] args) throws Exception {
// File f = new File(args[0]);
// writeToConsole(f);
// }
// }
// Path: src/test/java/com/linuxense/javadbf/DBFReaderPrintTest.java
import com.linuxense.javadbf.testutils.DbfToTxtTest;
import java.io.File;
import java.io.FileInputStream;
import org.junit.Test;
/*
(C) Copyright 2017 Alberto Fernández <infjaf@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
package com.linuxense.javadbf;
public class DBFReaderPrintTest {
@Test
public void printFile() throws Exception {
File file = new File("src/test/resources/books.dbf");
DBFReader reader = null;
try {
reader = new DBFReader(new FileInputStream(file)); | DbfToTxtTest.export(reader, File.createTempFile("javadbf-test", ".txt")); |
albfernandez/javadbf | src/test/java/com/linuxense/javadbf/FixtureDBase8bTest.java | // Path: src/test/java/com/linuxense/javadbf/testutils/DateUtils.java
// public static Date createDate(int year, int month, int day) {
// Calendar c = Calendar.getInstance();
// c.set(Calendar.YEAR, year);
// c.set(Calendar.MONTH, month - 1);
// c.set(Calendar.DAY_OF_MONTH, day);
// c.set(Calendar.HOUR_OF_DAY, 0);
// c.set(Calendar.MINUTE, 0);
// c.set(Calendar.SECOND, 0);
// c.set(Calendar.MILLISECOND, 0);
// return c.getTime();
// }
| import static com.linuxense.javadbf.testutils.DateUtils.createDate;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.Date;
import org.junit.Assert;
import org.junit.Test; | Assert.assertEquals(DBFDataType.DATE, header.fieldArray[2].getType());
Assert.assertEquals(0, header.fieldArray[2].getDecimalCount());
Assert.assertEquals(8, header.fieldArray[2].getLength());
Assert.assertEquals("LOGICAL", header.fieldArray[3].getName());
Assert.assertEquals(DBFDataType.LOGICAL, header.fieldArray[3].getType());
Assert.assertEquals(0, header.fieldArray[3].getDecimalCount());
Assert.assertEquals(1, header.fieldArray[3].getLength());
Assert.assertEquals("FLOAT", header.fieldArray[4].getName());
Assert.assertEquals(DBFDataType.FLOATING_POINT, header.fieldArray[4].getType());
Assert.assertEquals(18, header.fieldArray[4].getDecimalCount());
Assert.assertEquals(20, header.fieldArray[4].getLength());
Assert.assertEquals("MEMO", header.fieldArray[5].getName());
Assert.assertEquals(DBFDataType.MEMO, header.fieldArray[5].getType());
Assert.assertEquals(0, header.fieldArray[5].getDecimalCount());
Assert.assertEquals(10, header.fieldArray[5].getLength());
Assert.assertEquals(10, header.numberOfRecords);
Object[] row = null;
row = reader.nextRecord();
Assert.assertEquals("One", row[0]);
Assert.assertTrue(row[1] instanceof Number);
Assert.assertEquals(1, ((Number)row[1]).intValue());
Assert.assertTrue(row[2] instanceof Date); | // Path: src/test/java/com/linuxense/javadbf/testutils/DateUtils.java
// public static Date createDate(int year, int month, int day) {
// Calendar c = Calendar.getInstance();
// c.set(Calendar.YEAR, year);
// c.set(Calendar.MONTH, month - 1);
// c.set(Calendar.DAY_OF_MONTH, day);
// c.set(Calendar.HOUR_OF_DAY, 0);
// c.set(Calendar.MINUTE, 0);
// c.set(Calendar.SECOND, 0);
// c.set(Calendar.MILLISECOND, 0);
// return c.getTime();
// }
// Path: src/test/java/com/linuxense/javadbf/FixtureDBase8bTest.java
import static com.linuxense.javadbf.testutils.DateUtils.createDate;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.Date;
import org.junit.Assert;
import org.junit.Test;
Assert.assertEquals(DBFDataType.DATE, header.fieldArray[2].getType());
Assert.assertEquals(0, header.fieldArray[2].getDecimalCount());
Assert.assertEquals(8, header.fieldArray[2].getLength());
Assert.assertEquals("LOGICAL", header.fieldArray[3].getName());
Assert.assertEquals(DBFDataType.LOGICAL, header.fieldArray[3].getType());
Assert.assertEquals(0, header.fieldArray[3].getDecimalCount());
Assert.assertEquals(1, header.fieldArray[3].getLength());
Assert.assertEquals("FLOAT", header.fieldArray[4].getName());
Assert.assertEquals(DBFDataType.FLOATING_POINT, header.fieldArray[4].getType());
Assert.assertEquals(18, header.fieldArray[4].getDecimalCount());
Assert.assertEquals(20, header.fieldArray[4].getLength());
Assert.assertEquals("MEMO", header.fieldArray[5].getName());
Assert.assertEquals(DBFDataType.MEMO, header.fieldArray[5].getType());
Assert.assertEquals(0, header.fieldArray[5].getDecimalCount());
Assert.assertEquals(10, header.fieldArray[5].getLength());
Assert.assertEquals(10, header.numberOfRecords);
Object[] row = null;
row = reader.nextRecord();
Assert.assertEquals("One", row[0]);
Assert.assertTrue(row[1] instanceof Number);
Assert.assertEquals(1, ((Number)row[1]).intValue());
Assert.assertTrue(row[2] instanceof Date); | Assert.assertEquals(createDate(1970,1,1), row[2]); |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/CarServiceInterface.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
| import io.github.cdelmas.spike.common.domain.Car;
import org.restlet.resource.Get; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.hello;
public interface CarServiceInterface {
@Get | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/CarServiceInterface.java
import io.github.cdelmas.spike.common.domain.Car;
import org.restlet.resource.Get;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.hello;
public interface CarServiceInterface {
@Get | public Car[] getAllCars(); |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarsResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
| import javax.ws.rs.core.UriInfo;
import java.util.List;
import static java.util.stream.Collectors.toList;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars")
public class CarsResource {
@Context
UriInfo uriInfo;
@Inject | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarsResource.java
import javax.ws.rs.core.UriInfo;
import java.util.List;
import static java.util.stream.Collectors.toList;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars")
public class CarsResource {
@Context
UriInfo uriInfo;
@Inject | private CarRepository carRepository; |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarsResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
| import javax.ws.rs.core.UriInfo;
import java.util.List;
import static java.util.stream.Collectors.toList;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars")
public class CarsResource {
@Context
UriInfo uriInfo;
@Inject
private CarRepository carRepository;
@GET
@Produces(MediaType.APPLICATION_JSON) | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarsResource.java
import javax.ws.rs.core.UriInfo;
import java.util.List;
import static java.util.stream.Collectors.toList;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars")
public class CarsResource {
@Context
UriInfo uriInfo;
@Inject
private CarRepository carRepository;
@GET
@Produces(MediaType.APPLICATION_JSON) | public Response all(@Auth User user) { |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarsResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
| import javax.ws.rs.core.UriInfo;
import java.util.List;
import static java.util.stream.Collectors.toList;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars")
public class CarsResource {
@Context
UriInfo uriInfo;
@Inject
private CarRepository carRepository;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response all(@Auth User user) { | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarsResource.java
import javax.ws.rs.core.UriInfo;
import java.util.List;
import static java.util.stream.Collectors.toList;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars")
public class CarsResource {
@Context
UriInfo uriInfo;
@Inject
private CarRepository carRepository;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response all(@Auth User user) { | List<Car> cars = carRepository.all(); |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/auth/AuthTokenVerifier.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
| import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.auth.User;
import javaslang.control.Try;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
import org.restlet.security.Verifier;
import javax.inject.Inject; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.infrastructure.auth;
public class AuthTokenVerifier implements Verifier {
@Inject | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/auth/AuthTokenVerifier.java
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.auth.User;
import javaslang.control.Try;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
import org.restlet.security.Verifier;
import javax.inject.Inject;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.infrastructure.auth;
public class AuthTokenVerifier implements Verifier {
@Inject | private AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory; |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/auth/AuthTokenVerifier.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
| import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.auth.User;
import javaslang.control.Try;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
import org.restlet.security.Verifier;
import javax.inject.Inject; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.infrastructure.auth;
public class AuthTokenVerifier implements Verifier {
@Inject
private AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory;
@Override
public int verify(Request request, Response response) {
final String token;
try {
ChallengeResponse cr = request.getChallengeResponse();
if (cr == null) {
return RESULT_MISSING;
} else if (ChallengeScheme.HTTP_OAUTH_BEARER.equals(cr.getScheme())) {
final String bearer = cr.getRawValue();
if (bearer == null || bearer.isEmpty()) {
return RESULT_MISSING;
}
token = bearer;
} else {
return RESULT_UNSUPPORTED;
}
} catch (Exception ex) {
return RESULT_INVALID;
}
| // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/auth/AuthTokenVerifier.java
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.auth.User;
import javaslang.control.Try;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
import org.restlet.security.Verifier;
import javax.inject.Inject;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.infrastructure.auth;
public class AuthTokenVerifier implements Verifier {
@Inject
private AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory;
@Override
public int verify(Request request, Response response) {
final String token;
try {
ChallengeResponse cr = request.getChallengeResponse();
if (cr == null) {
return RESULT_MISSING;
} else if (ChallengeScheme.HTTP_OAUTH_BEARER.equals(cr.getScheme())) {
final String bearer = cr.getRawValue();
if (bearer == null || bearer.isEmpty()) {
return RESULT_MISSING;
}
token = bearer;
} else {
return RESULT_UNSUPPORTED;
}
} catch (Exception ex) {
return RESULT_INVALID;
}
| Try<User> user = accessTokenVerificationCommandFactory.createVerificationCommand(token).executeCommand(); |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarModule.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
| import com.google.inject.AbstractModule;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
import org.restlet.Application; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarModule extends AbstractModule {
@Override
protected void configure() {
bind(Application.class).annotatedWith(Car.class).to(CarApplication.class); | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarModule.java
import com.google.inject.AbstractModule;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
import org.restlet.Application;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarModule extends AbstractModule {
@Override
protected void configure() {
bind(Application.class).annotatedWith(Car.class).to(CarApplication.class); | bind(CarRepository.class).to(InMemoryCarRepository.class); |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarModule.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
| import com.google.inject.AbstractModule;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
import org.restlet.Application; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarModule extends AbstractModule {
@Override
protected void configure() {
bind(Application.class).annotatedWith(Car.class).to(CarApplication.class); | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarModule.java
import com.google.inject.AbstractModule;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
import org.restlet.Application;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarModule extends AbstractModule {
@Override
protected void configure() {
bind(Application.class).annotatedWith(Car.class).to(CarApplication.class); | bind(CarRepository.class).to(InMemoryCarRepository.class); |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/RestComponent.java | // Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/JacksonCustomConverter.java
// public class JacksonCustomConverter extends JacksonConverter {
//
// @Override
// protected <T> JacksonRepresentation<T> create(MediaType mediaType, T source) {
// ObjectMapper mapper = createMapper();
// JacksonRepresentation<T> jr = new JacksonRepresentation<>(mediaType, source);
// jr.setObjectMapper(mapper);
// return jr;
// }
//
// @Override
// protected <T> JacksonRepresentation<T> create(Representation source, Class<T> objectClass) {
// ObjectMapper mapper = createMapper();
// JacksonRepresentation<T> jr = new JacksonRepresentation<>(source, objectClass);
// jr.setObjectMapper(mapper);
// return jr;
// }
//
//
// private ObjectMapper createMapper() {
// JsonFactory jsonFactory = new JsonFactory();
// jsonFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
// ObjectMapper mapper = new ObjectMapper(jsonFactory);
// mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// mapper.registerModule(new Jdk8Module());
// return mapper;
// }
//
// }
| import org.restlet.util.Series;
import javax.inject.Inject;
import java.util.List;
import io.github.cdelmas.spike.restlet.car.Car;
import io.github.cdelmas.spike.restlet.hello.Hello;
import io.github.cdelmas.spike.restlet.infrastructure.JacksonCustomConverter;
import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.Server;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.Parameter;
import org.restlet.data.Protocol;
import org.restlet.engine.Engine;
import org.restlet.engine.converter.ConverterHelper;
import org.restlet.ext.jackson.JacksonConverter;
import org.restlet.security.ChallengeAuthenticator;
import org.restlet.security.Verifier; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet;
public class RestComponent extends Component {
@Inject
public RestComponent(@Hello Application helloApp, @Car Application carApp, Verifier authTokenVerifier) {
getClients().add(Protocol.HTTPS);
Server secureServer = getServers().add(Protocol.HTTPS, 8043);
Series<Parameter> parameters = secureServer.getContext().getParameters();
parameters.add("sslContextFactory", "org.restlet.engine.ssl.DefaultSslContextFactory");
parameters.add("keyStorePath", System.getProperty("javax.net.ssl.keyStorePath"));
getDefaultHost().attach("/api/hello", secure(helloApp, authTokenVerifier, "ame"));
getDefaultHost().attach("/api/cars", secure(carApp, authTokenVerifier, "ame")); | // Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/JacksonCustomConverter.java
// public class JacksonCustomConverter extends JacksonConverter {
//
// @Override
// protected <T> JacksonRepresentation<T> create(MediaType mediaType, T source) {
// ObjectMapper mapper = createMapper();
// JacksonRepresentation<T> jr = new JacksonRepresentation<>(mediaType, source);
// jr.setObjectMapper(mapper);
// return jr;
// }
//
// @Override
// protected <T> JacksonRepresentation<T> create(Representation source, Class<T> objectClass) {
// ObjectMapper mapper = createMapper();
// JacksonRepresentation<T> jr = new JacksonRepresentation<>(source, objectClass);
// jr.setObjectMapper(mapper);
// return jr;
// }
//
//
// private ObjectMapper createMapper() {
// JsonFactory jsonFactory = new JsonFactory();
// jsonFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
// ObjectMapper mapper = new ObjectMapper(jsonFactory);
// mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// mapper.registerModule(new Jdk8Module());
// return mapper;
// }
//
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/RestComponent.java
import org.restlet.util.Series;
import javax.inject.Inject;
import java.util.List;
import io.github.cdelmas.spike.restlet.car.Car;
import io.github.cdelmas.spike.restlet.hello.Hello;
import io.github.cdelmas.spike.restlet.infrastructure.JacksonCustomConverter;
import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.Server;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.Parameter;
import org.restlet.data.Protocol;
import org.restlet.engine.Engine;
import org.restlet.engine.converter.ConverterHelper;
import org.restlet.ext.jackson.JacksonConverter;
import org.restlet.security.ChallengeAuthenticator;
import org.restlet.security.Verifier;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet;
public class RestComponent extends Component {
@Inject
public RestComponent(@Hello Application helloApp, @Car Application carApp, Verifier authTokenVerifier) {
getClients().add(Protocol.HTTPS);
Server secureServer = getServers().add(Protocol.HTTPS, 8043);
Series<Parameter> parameters = secureServer.getContext().getParameters();
parameters.add("sslContextFactory", "org.restlet.engine.ssl.DefaultSslContextFactory");
parameters.add("keyStorePath", System.getProperty("javax.net.ssl.keyStorePath"));
getDefaultHost().attach("/api/hello", secure(helloApp, authTokenVerifier, "ame"));
getDefaultHost().attach("/api/cars", secure(carApp, authTokenVerifier, "ame")); | replaceConverter(JacksonConverter.class, new JacksonCustomConverter()); |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/infrastructure/auth/FacebookTokenAuthenticator.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
| import com.google.common.base.Optional;
import io.dropwizard.auth.AuthenticationException;
import io.dropwizard.auth.Authenticator;
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.auth.User;
import javaslang.control.Try;
import javax.inject.Inject; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.infrastructure.auth;
public class FacebookTokenAuthenticator implements Authenticator<String, User> {
@Inject | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/infrastructure/auth/FacebookTokenAuthenticator.java
import com.google.common.base.Optional;
import io.dropwizard.auth.AuthenticationException;
import io.dropwizard.auth.Authenticator;
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.auth.User;
import javaslang.control.Try;
import javax.inject.Inject;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.infrastructure.auth;
public class FacebookTokenAuthenticator implements Authenticator<String, User> {
@Inject | AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory; |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
| import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import org.restlet.data.Status;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;
import javax.inject.Inject; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarResource extends ServerResource {
@Inject | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarResource.java
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import org.restlet.data.Status;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;
import javax.inject.Inject;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarResource extends ServerResource {
@Inject | private CarRepository carRepository; |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
| import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import org.restlet.data.Status;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;
import javax.inject.Inject; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarResource extends ServerResource {
@Inject
private CarRepository carRepository;
private int carId;
@Override
protected void doInit() throws ResourceException {
super.doInit();
this.carId = Integer.parseInt(getAttribute("id"));
}
@Get("json")
public CarRepresentation byId() {
io.github.cdelmas.spike.common.domain.Car car = carRepository.byId(carId).orElseThrow(() -> new ResourceException(Status.CLIENT_ERROR_NOT_FOUND));
CarRepresentation carRepresentation = new CarRepresentation(car); | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarResource.java
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import org.restlet.data.Status;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;
import javax.inject.Inject;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarResource extends ServerResource {
@Inject
private CarRepository carRepository;
private int carId;
@Override
protected void doInit() throws ResourceException {
super.doInit();
this.carId = Integer.parseInt(getAttribute("id"));
}
@Get("json")
public CarRepresentation byId() {
io.github.cdelmas.spike.common.domain.Car car = carRepository.byId(carId).orElseThrow(() -> new ResourceException(Status.CLIENT_ERROR_NOT_FOUND));
CarRepresentation carRepresentation = new CarRepresentation(car); | carRepresentation.addLink(Link.self(getReference().toString())); |
cdelmas/microservices-comparison | vertx/src/main/java/io/github/cdelmas/spike/vertx/car/CarsResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
| import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.Json;
import io.vertx.ext.web.RoutingContext;
import java.util.List;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static io.vertx.core.json.Json.encode;
import static java.util.stream.Collectors.toList; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.car;
public class CarsResource {
private final CarRepository carRepository;
public CarsResource(CarRepository carRepository) {
this.carRepository = carRepository;
}
public void all(RoutingContext routingContext) { | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
// Path: vertx/src/main/java/io/github/cdelmas/spike/vertx/car/CarsResource.java
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.Json;
import io.vertx.ext.web.RoutingContext;
import java.util.List;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static io.vertx.core.json.Json.encode;
import static java.util.stream.Collectors.toList;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.car;
public class CarsResource {
private final CarRepository carRepository;
public CarsResource(CarRepository carRepository) {
this.carRepository = carRepository;
}
public void all(RoutingContext routingContext) { | List<Car> all = carRepository.all(); |
cdelmas/microservices-comparison | vertx/src/main/java/io/github/cdelmas/spike/vertx/car/CarsResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
| import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.Json;
import io.vertx.ext.web.RoutingContext;
import java.util.List;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static io.vertx.core.json.Json.encode;
import static java.util.stream.Collectors.toList; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.car;
public class CarsResource {
private final CarRepository carRepository;
public CarsResource(CarRepository carRepository) {
this.carRepository = carRepository;
}
public void all(RoutingContext routingContext) {
List<Car> all = carRepository.all();
HttpServerResponse response = routingContext.response();
response.putHeader("content-type", "application/json")
.putHeader("total-count", String.valueOf(all.size()))
.end(encode(all.stream().map(car -> {
CarRepresentation carRepresentation = new CarRepresentation(car); | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
// Path: vertx/src/main/java/io/github/cdelmas/spike/vertx/car/CarsResource.java
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.Json;
import io.vertx.ext.web.RoutingContext;
import java.util.List;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static io.vertx.core.json.Json.encode;
import static java.util.stream.Collectors.toList;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.car;
public class CarsResource {
private final CarRepository carRepository;
public CarsResource(CarRepository carRepository) {
this.carRepository = carRepository;
}
public void all(RoutingContext routingContext) {
List<Car> all = carRepository.all();
HttpServerResponse response = routingContext.response();
response.putHeader("content-type", "application/json")
.putHeader("total-count", String.valueOf(all.size()))
.end(encode(all.stream().map(car -> {
CarRepresentation carRepresentation = new CarRepresentation(car); | carRepresentation.addLink(self(routingContext.request().absoluteURI() + "/" + car.getId())); |
cdelmas/microservices-comparison | vertx/src/main/java/io/github/cdelmas/spike/vertx/hello/HelloResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: vertx/src/main/java/io/github/cdelmas/spike/vertx/infrastructure/auth/MyUser.java
// public class MyUser extends AbstractUser {
//
// private AuthProvider authProvider;
// private final long id;
// private final String name;
// private final String token;
//
// public MyUser(long id, String name, String token) {
// this.id = id;
// this.name = name;
// this.token = token;
// }
//
// @Override
// protected void doIsPermitted(String permission, Handler<AsyncResult<Boolean>> resultHandler) {
// resultHandler.handle(Future.failedFuture("Not implemented yet"));
// }
//
// @Override
// public JsonObject principal() {
// return new JsonObject().put("id", id).put("name", name).put("token", token);
// }
//
// @Override
// public void setAuthProvider(AuthProvider authProvider) {
// this.authProvider = authProvider;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
// }
| import static java.util.Arrays.toString;
import static java.util.stream.Collectors.toList;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.vertx.infrastructure.auth.MyUser;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.Json;
import io.vertx.ext.auth.User;
import io.vertx.ext.web.RoutingContext;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import static java.util.Arrays.asList; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.hello;
public class HelloResource {
private final HttpClient httpClient;
public HelloResource(HttpClient httpClient) {
this.httpClient = httpClient;
}
public void hello(RoutingContext routingContext) {
httpClient.getAbs("https://localhost:8090/cars")
.putHeader("Accept", "application/json")
.putHeader("Authorization", "Bearer " + routingContext.user().principal().getString("token"))
.handler(response ->
response.bodyHandler(buffer -> {
if (response.statusCode() == 200) { | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: vertx/src/main/java/io/github/cdelmas/spike/vertx/infrastructure/auth/MyUser.java
// public class MyUser extends AbstractUser {
//
// private AuthProvider authProvider;
// private final long id;
// private final String name;
// private final String token;
//
// public MyUser(long id, String name, String token) {
// this.id = id;
// this.name = name;
// this.token = token;
// }
//
// @Override
// protected void doIsPermitted(String permission, Handler<AsyncResult<Boolean>> resultHandler) {
// resultHandler.handle(Future.failedFuture("Not implemented yet"));
// }
//
// @Override
// public JsonObject principal() {
// return new JsonObject().put("id", id).put("name", name).put("token", token);
// }
//
// @Override
// public void setAuthProvider(AuthProvider authProvider) {
// this.authProvider = authProvider;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
// }
// Path: vertx/src/main/java/io/github/cdelmas/spike/vertx/hello/HelloResource.java
import static java.util.Arrays.toString;
import static java.util.stream.Collectors.toList;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.vertx.infrastructure.auth.MyUser;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.Json;
import io.vertx.ext.auth.User;
import io.vertx.ext.web.RoutingContext;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import static java.util.Arrays.asList;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.hello;
public class HelloResource {
private final HttpClient httpClient;
public HelloResource(HttpClient httpClient) {
this.httpClient = httpClient;
}
public void hello(RoutingContext routingContext) {
httpClient.getAbs("https://localhost:8090/cars")
.putHeader("Accept", "application/json")
.putHeader("Authorization", "Bearer " + routingContext.user().principal().getString("token"))
.handler(response ->
response.bodyHandler(buffer -> {
if (response.statusCode() == 200) { | List<Car> cars = new ArrayList<>(asList(Json.decodeValue(buffer.toString(), Car[].class))); |
cdelmas/microservices-comparison | common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
| import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.common.persistence;
@Singleton
public class InMemoryCarRepository implements CarRepository {
private final AtomicInteger idGenerator = new AtomicInteger(1); | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.common.persistence;
@Singleton
public class InMemoryCarRepository implements CarRepository {
private final AtomicInteger idGenerator = new AtomicInteger(1); | private final Map<Integer, Car> repository = new ConcurrentHashMap<>(); |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/hello/RemoteCarService.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
| import io.github.cdelmas.spike.common.domain.Car;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import java.util.List;
import static java.util.Arrays.asList; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.hello;
public class RemoteCarService implements CarService {
@Inject
private Client client;
@Context
private Request request;
@Override | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/hello/RemoteCarService.java
import io.github.cdelmas.spike.common.domain.Car;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import java.util.List;
import static java.util.Arrays.asList;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.hello;
public class RemoteCarService implements CarService {
@Inject
private Client client;
@Context
private Request request;
@Override | public List<Car> getAllCars(String auth) { |
cdelmas/microservices-comparison | spring-boot/src/main/java/io/github/cdelmas/spike/springboot/car/CarsController.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
| import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import org.springframework.cloud.security.oauth2.resource.EnableOAuth2Resource;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;
import javax.inject.Inject;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Optional;
import static java.util.stream.Collectors.toList;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.springboot.car;
@EnableOAuth2Resource
@RestController
@RequestMapping(value = "/cars", produces = "application/json")
public class CarsController {
| // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
// Path: spring-boot/src/main/java/io/github/cdelmas/spike/springboot/car/CarsController.java
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import org.springframework.cloud.security.oauth2.resource.EnableOAuth2Resource;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;
import javax.inject.Inject;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Optional;
import static java.util.stream.Collectors.toList;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.springboot.car;
@EnableOAuth2Resource
@RestController
@RequestMapping(value = "/cars", produces = "application/json")
public class CarsController {
| private final CarRepository carRepository; |
cdelmas/microservices-comparison | spring-boot/src/main/java/io/github/cdelmas/spike/springboot/car/CarsController.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
| import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import org.springframework.cloud.security.oauth2.resource.EnableOAuth2Resource;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;
import javax.inject.Inject;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Optional;
import static java.util.stream.Collectors.toList;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.springboot.car;
@EnableOAuth2Resource
@RestController
@RequestMapping(value = "/cars", produces = "application/json")
public class CarsController {
private final CarRepository carRepository;
@Inject
public CarsController(CarRepository carRepository) {
this.carRepository = carRepository;
}
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<CarRepresentation>> allCars() { | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
// Path: spring-boot/src/main/java/io/github/cdelmas/spike/springboot/car/CarsController.java
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import org.springframework.cloud.security.oauth2.resource.EnableOAuth2Resource;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;
import javax.inject.Inject;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Optional;
import static java.util.stream.Collectors.toList;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.springboot.car;
@EnableOAuth2Resource
@RestController
@RequestMapping(value = "/cars", produces = "application/json")
public class CarsController {
private final CarRepository carRepository;
@Inject
public CarsController(CarRepository carRepository) {
this.carRepository = carRepository;
}
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<CarRepresentation>> allCars() { | List<Car> cars = carRepository.all(); |
cdelmas/microservices-comparison | sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/Main.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
| import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
import spark.Request;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.List;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static java.util.stream.Collectors.toList;
import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.halt;
import static spark.Spark.post;
import static spark.SparkBase.port;
import static spark.SparkBase.secure; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.sparkjava;
public class Main {
public static void main(String[] args) {
port(8099); // defaults on 4567
ObjectMapper objectMapper = createObjectMapper();
configureUnirest(objectMapper);
secureServer();
| // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
// Path: sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/Main.java
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
import spark.Request;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.List;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static java.util.stream.Collectors.toList;
import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.halt;
import static spark.Spark.post;
import static spark.SparkBase.port;
import static spark.SparkBase.secure;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.sparkjava;
public class Main {
public static void main(String[] args) {
port(8099); // defaults on 4567
ObjectMapper objectMapper = createObjectMapper();
configureUnirest(objectMapper);
secureServer();
| AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory = new AccessTokenVerificationCommandFactory(); |
cdelmas/microservices-comparison | sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/Main.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
| import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
import spark.Request;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.List;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static java.util.stream.Collectors.toList;
import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.halt;
import static spark.Spark.post;
import static spark.SparkBase.port;
import static spark.SparkBase.secure; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.sparkjava;
public class Main {
public static void main(String[] args) {
port(8099); // defaults on 4567
ObjectMapper objectMapper = createObjectMapper();
configureUnirest(objectMapper);
secureServer();
AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory = new AccessTokenVerificationCommandFactory();
AuthenticationFilter authenticationFilter = new AuthenticationFilter(accessTokenVerificationCommandFactory);
before(authenticationFilter::filter);
HelloResource helloResource = new HelloResource();
get("/hello", helloResource::hello);
| // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
// Path: sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/Main.java
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
import spark.Request;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.List;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static java.util.stream.Collectors.toList;
import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.halt;
import static spark.Spark.post;
import static spark.SparkBase.port;
import static spark.SparkBase.secure;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.sparkjava;
public class Main {
public static void main(String[] args) {
port(8099); // defaults on 4567
ObjectMapper objectMapper = createObjectMapper();
configureUnirest(objectMapper);
secureServer();
AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory = new AccessTokenVerificationCommandFactory();
AuthenticationFilter authenticationFilter = new AuthenticationFilter(accessTokenVerificationCommandFactory);
before(authenticationFilter::filter);
HelloResource helloResource = new HelloResource();
get("/hello", helloResource::hello);
| CarRepository carRepository = new InMemoryCarRepository(); |
cdelmas/microservices-comparison | sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/Main.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
| import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
import spark.Request;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.List;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static java.util.stream.Collectors.toList;
import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.halt;
import static spark.Spark.post;
import static spark.SparkBase.port;
import static spark.SparkBase.secure; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.sparkjava;
public class Main {
public static void main(String[] args) {
port(8099); // defaults on 4567
ObjectMapper objectMapper = createObjectMapper();
configureUnirest(objectMapper);
secureServer();
AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory = new AccessTokenVerificationCommandFactory();
AuthenticationFilter authenticationFilter = new AuthenticationFilter(accessTokenVerificationCommandFactory);
before(authenticationFilter::filter);
HelloResource helloResource = new HelloResource();
get("/hello", helloResource::hello);
| // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
// Path: sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/Main.java
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
import spark.Request;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.List;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static java.util.stream.Collectors.toList;
import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.halt;
import static spark.Spark.post;
import static spark.SparkBase.port;
import static spark.SparkBase.secure;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.sparkjava;
public class Main {
public static void main(String[] args) {
port(8099); // defaults on 4567
ObjectMapper objectMapper = createObjectMapper();
configureUnirest(objectMapper);
secureServer();
AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory = new AccessTokenVerificationCommandFactory();
AuthenticationFilter authenticationFilter = new AuthenticationFilter(accessTokenVerificationCommandFactory);
before(authenticationFilter::filter);
HelloResource helloResource = new HelloResource();
get("/hello", helloResource::hello);
| CarRepository carRepository = new InMemoryCarRepository(); |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
| import java.util.Optional;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars/{id}")
@Produces(MediaType.APPLICATION_JSON)
public class CarResource {
@Context
UriInfo uriInfo;
@Inject | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarResource.java
import java.util.Optional;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars/{id}")
@Produces(MediaType.APPLICATION_JSON)
public class CarResource {
@Context
UriInfo uriInfo;
@Inject | private CarRepository carRepository; |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
| import java.util.Optional;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars/{id}")
@Produces(MediaType.APPLICATION_JSON)
public class CarResource {
@Context
UriInfo uriInfo;
@Inject
private CarRepository carRepository;
@GET | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarResource.java
import java.util.Optional;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars/{id}")
@Produces(MediaType.APPLICATION_JSON)
public class CarResource {
@Context
UriInfo uriInfo;
@Inject
private CarRepository carRepository;
@GET | public Response byId(@Auth User user, @PathParam("id") int carId) { |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
| import java.util.Optional;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars/{id}")
@Produces(MediaType.APPLICATION_JSON)
public class CarResource {
@Context
UriInfo uriInfo;
@Inject
private CarRepository carRepository;
@GET
public Response byId(@Auth User user, @PathParam("id") int carId) { | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarResource.java
import java.util.Optional;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars/{id}")
@Produces(MediaType.APPLICATION_JSON)
public class CarResource {
@Context
UriInfo uriInfo;
@Inject
private CarRepository carRepository;
@GET
public Response byId(@Auth User user, @PathParam("id") int carId) { | Optional<Car> car = carRepository.byId(carId); |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
| import java.util.Optional;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars/{id}")
@Produces(MediaType.APPLICATION_JSON)
public class CarResource {
@Context
UriInfo uriInfo;
@Inject
private CarRepository carRepository;
@GET
public Response byId(@Auth User user, @PathParam("id") int carId) {
Optional<Car> car = carRepository.byId(carId);
return car.map(c -> {
CarRepresentation carRepresentation = new CarRepresentation(c); | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarResource.java
import java.util.Optional;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
@Path("/cars/{id}")
@Produces(MediaType.APPLICATION_JSON)
public class CarResource {
@Context
UriInfo uriInfo;
@Inject
private CarRepository carRepository;
@GET
public Response byId(@Auth User user, @PathParam("id") int carId) {
Optional<Car> car = carRepository.byId(carId);
return car.map(c -> {
CarRepresentation carRepresentation = new CarRepresentation(c); | carRepresentation.addLink(Link.self(uriInfo.getAbsolutePathBuilder().build(c.getId()).toString())); |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarsResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
| import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import org.restlet.data.Reference;
import org.restlet.data.Status;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;
import javax.inject.Inject;
import java.util.List;
import static java.util.stream.Collectors.toList; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarsResource extends ServerResource {
@Inject | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarsResource.java
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import org.restlet.data.Reference;
import org.restlet.data.Status;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;
import javax.inject.Inject;
import java.util.List;
import static java.util.stream.Collectors.toList;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarsResource extends ServerResource {
@Inject | private CarRepository carRepository; |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarsResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
| import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import org.restlet.data.Reference;
import org.restlet.data.Status;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;
import javax.inject.Inject;
import java.util.List;
import static java.util.stream.Collectors.toList; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarsResource extends ServerResource {
@Inject
private CarRepository carRepository;
@Get("json")
public List<CarRepresentation> all() {
List<io.github.cdelmas.spike.common.domain.Car> cars = carRepository.all();
getResponse().getHeaders().add("total-count", String.valueOf(cars.size()));
return cars.stream().map(c -> {
CarRepresentation carRepresentation = new CarRepresentation(c); | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public class Link {
// private String rel;
// private String href;
// private String method;
//
// public static Link self(String href) {
// return new Link("self", href);
// }
//
// public static Link remove(String href) {
// return new Link("remove", href,"DELETE");
// }
//
// public Link(String rel, String href, String method) {
// this.rel = rel;
// this.href = href;
// this.method = method;
// }
//
// public Link(String rel, String href) {
// this(rel, href, "GET");
// }
//
// Link() {
// }
//
// public String getRel() {
// return rel;
// }
//
// public void setRel(String rel) {
// this.rel = rel;
// }
//
// public String getHref() {
// return href;
// }
//
// public void setHref(String href) {
// this.href = href;
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarsResource.java
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.hateoas.Link;
import org.restlet.data.Reference;
import org.restlet.data.Status;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;
import javax.inject.Inject;
import java.util.List;
import static java.util.stream.Collectors.toList;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.car;
public class CarsResource extends ServerResource {
@Inject
private CarRepository carRepository;
@Get("json")
public List<CarRepresentation> all() {
List<io.github.cdelmas.spike.common.domain.Car> cars = carRepository.all();
getResponse().getHeaders().add("total-count", String.valueOf(cars.size()));
return cars.stream().map(c -> {
CarRepresentation carRepresentation = new CarRepresentation(c); | carRepresentation.addLink(Link.self(new Reference(getReference()).addSegment(String.valueOf(c.getId())).toString())); |
cdelmas/microservices-comparison | vertx/src/main/java/io/github/cdelmas/spike/vertx/car/CarRepresentation.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Representation.java
// public class Representation {
//
// private final List<Link> links = new ArrayList<>(1); // most of the time, there will only have 1 link (self)
//
// public void addLink(Link link) {
// links.add(link);
// }
//
// public List<Link> getLinks() {
// return unmodifiableList(links);
// }
// }
| import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.hateoas.Representation; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.car;
public class CarRepresentation extends Representation {
private final String name;
private final int id;
| // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Representation.java
// public class Representation {
//
// private final List<Link> links = new ArrayList<>(1); // most of the time, there will only have 1 link (self)
//
// public void addLink(Link link) {
// links.add(link);
// }
//
// public List<Link> getLinks() {
// return unmodifiableList(links);
// }
// }
// Path: vertx/src/main/java/io/github/cdelmas/spike/vertx/car/CarRepresentation.java
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.hateoas.Representation;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.car;
public class CarRepresentation extends Representation {
private final String name;
private final int id;
| public CarRepresentation(Car car) { |
cdelmas/microservices-comparison | sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/AuthenticationFilter.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
| import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.auth.User;
import javaslang.control.Try;
import spark.Request;
import spark.Response;
import static spark.Spark.halt; | package io.github.cdelmas.spike.sparkjava;
public class AuthenticationFilter {
private final AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory;
public AuthenticationFilter(AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory) {
this.accessTokenVerificationCommandFactory = accessTokenVerificationCommandFactory;
}
public void filter(Request request, Response response) {
String token = readToken(request); | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/AccessTokenVerificationCommandFactory.java
// public class AccessTokenVerificationCommandFactory {
//
// public AccessTokenVerificationCommand createVerificationCommand(String accessToken) {
// return new FacebookAccessTokenVerificationCommand(accessToken);
// }
//
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
// Path: sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/AuthenticationFilter.java
import io.github.cdelmas.spike.common.auth.AccessTokenVerificationCommandFactory;
import io.github.cdelmas.spike.common.auth.User;
import javaslang.control.Try;
import spark.Request;
import spark.Response;
import static spark.Spark.halt;
package io.github.cdelmas.spike.sparkjava;
public class AuthenticationFilter {
private final AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory;
public AuthenticationFilter(AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory) {
this.accessTokenVerificationCommandFactory = accessTokenVerificationCommandFactory;
}
public void filter(Request request, Response response) {
String token = readToken(request); | Try<User> user = accessTokenVerificationCommandFactory.createVerificationCommand(token).executeCommand(); |
cdelmas/microservices-comparison | sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/CarsResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
| import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import spark.Request;
import spark.Response;
import spark.Route;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static java.util.stream.Collectors.toList; | package io.github.cdelmas.spike.sparkjava;
public class CarsResource {
private final CarRepository carRepository;
private final ObjectMapper objectMapper;
public CarsResource(CarRepository carRepository, ObjectMapper objectMapper) {
this.carRepository = carRepository;
this.objectMapper = objectMapper;
}
public List<CarRepresentation> all(Request request, Response response) { | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
// Path: sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/CarsResource.java
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import spark.Request;
import spark.Response;
import spark.Route;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static java.util.stream.Collectors.toList;
package io.github.cdelmas.spike.sparkjava;
public class CarsResource {
private final CarRepository carRepository;
private final ObjectMapper objectMapper;
public CarsResource(CarRepository carRepository, ObjectMapper objectMapper) {
this.carRepository = carRepository;
this.objectMapper = objectMapper;
}
public List<CarRepresentation> all(Request request, Response response) { | List<Car> cars = carRepository.all(); |
cdelmas/microservices-comparison | sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/CarsResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
| import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import spark.Request;
import spark.Response;
import spark.Route;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static java.util.stream.Collectors.toList; | package io.github.cdelmas.spike.sparkjava;
public class CarsResource {
private final CarRepository carRepository;
private final ObjectMapper objectMapper;
public CarsResource(CarRepository carRepository, ObjectMapper objectMapper) {
this.carRepository = carRepository;
this.objectMapper = objectMapper;
}
public List<CarRepresentation> all(Request request, Response response) {
List<Car> cars = carRepository.all();
response.header("count", String.valueOf(cars.size()));
response.type("application/json");
return cars.stream().map(c -> {
CarRepresentation carRepresentation = new CarRepresentation(c); | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
// Path: sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/CarsResource.java
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import spark.Request;
import spark.Response;
import spark.Route;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
import static java.util.stream.Collectors.toList;
package io.github.cdelmas.spike.sparkjava;
public class CarsResource {
private final CarRepository carRepository;
private final ObjectMapper objectMapper;
public CarsResource(CarRepository carRepository, ObjectMapper objectMapper) {
this.carRepository = carRepository;
this.objectMapper = objectMapper;
}
public List<CarRepresentation> all(Request request, Response response) {
List<Car> cars = carRepository.all();
response.header("count", String.valueOf(cars.size()));
response.type("application/json");
return cars.stream().map(c -> {
CarRepresentation carRepresentation = new CarRepresentation(c); | carRepresentation.addLink(self(request.url() + "/" + c.getId())); |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/Main.java | // Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/infrastructure/DropwizardApplication.java
// public class DropwizardApplication extends Application<DropwizardServerConfiguration> {
//
// private GuiceBundle<DropwizardServerConfiguration> guiceBundle;
//
// @Override
// public void run(DropwizardServerConfiguration configuration, Environment environment) throws Exception {
// environment.healthChecks().register("template", guiceBundle.getInjector().getInstance(TemplateHealthCheck.class));
// environment.jersey().register(guiceBundle.getInjector().getInstance(HelloWorldResource.class));
// environment.jersey().register(guiceBundle.getInjector().getInstance(CarsResource.class));
// environment.jersey().register(guiceBundle.getInjector().getInstance(CarResource.class));
// environment.jersey().register(AuthFactory.binder(
// new OAuthFactory<>(guiceBundle.getInjector().getInstance(FacebookTokenAuthenticator.class),
// getName() + "-Realm",
// User.class)));
// }
//
// @Override
// public String getName() {
// return "Dropwizard Spike Server";
// }
//
// @Override
// public void initialize(Bootstrap<DropwizardServerConfiguration> bootstrap) {
// guiceBundle = GuiceBundle.<DropwizardServerConfiguration>newBuilder()
// .addModule(new HelloModule())
// .addModule(new CarModule())
// .setConfigClass(DropwizardServerConfiguration.class)
// .build();
// bootstrap.addBundle(guiceBundle);
// bootstrap.addBundle(new Java8Bundle());
//
// ObjectMapper objectMapper = bootstrap.getObjectMapper();
// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// }
// }
| import io.github.cdelmas.spike.dropwizard.infrastructure.DropwizardApplication; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard;
public class Main {
public static void main(String[] args) throws Exception { | // Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/infrastructure/DropwizardApplication.java
// public class DropwizardApplication extends Application<DropwizardServerConfiguration> {
//
// private GuiceBundle<DropwizardServerConfiguration> guiceBundle;
//
// @Override
// public void run(DropwizardServerConfiguration configuration, Environment environment) throws Exception {
// environment.healthChecks().register("template", guiceBundle.getInjector().getInstance(TemplateHealthCheck.class));
// environment.jersey().register(guiceBundle.getInjector().getInstance(HelloWorldResource.class));
// environment.jersey().register(guiceBundle.getInjector().getInstance(CarsResource.class));
// environment.jersey().register(guiceBundle.getInjector().getInstance(CarResource.class));
// environment.jersey().register(AuthFactory.binder(
// new OAuthFactory<>(guiceBundle.getInjector().getInstance(FacebookTokenAuthenticator.class),
// getName() + "-Realm",
// User.class)));
// }
//
// @Override
// public String getName() {
// return "Dropwizard Spike Server";
// }
//
// @Override
// public void initialize(Bootstrap<DropwizardServerConfiguration> bootstrap) {
// guiceBundle = GuiceBundle.<DropwizardServerConfiguration>newBuilder()
// .addModule(new HelloModule())
// .addModule(new CarModule())
// .setConfigClass(DropwizardServerConfiguration.class)
// .build();
// bootstrap.addBundle(guiceBundle);
// bootstrap.addBundle(new Java8Bundle());
//
// ObjectMapper objectMapper = bootstrap.getObjectMapper();
// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/Main.java
import io.github.cdelmas.spike.dropwizard.infrastructure.DropwizardApplication;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard;
public class Main {
public static void main(String[] args) throws Exception { | new DropwizardApplication().run(args); |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/HelloResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
| import io.github.cdelmas.spike.common.domain.Car;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import javax.inject.Inject;
import java.util.List;
import static java.util.stream.Collectors.toList; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.hello;
public class HelloResource extends ServerResource {
@Inject
private CarService carService;
@Get("txt")
public String hello() { | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/HelloResource.java
import io.github.cdelmas.spike.common.domain.Car;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import javax.inject.Inject;
import java.util.List;
import static java.util.stream.Collectors.toList;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.hello;
public class HelloResource extends ServerResource {
@Inject
private CarService carService;
@Get("txt")
public String hello() { | List<Car> cars = carService.list(); |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarRepresentation.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Representation.java
// public class Representation {
//
// private final List<Link> links = new ArrayList<>(1); // most of the time, there will only have 1 link (self)
//
// public void addLink(Link link) {
// links.add(link);
// }
//
// public List<Link> getLinks() {
// return unmodifiableList(links);
// }
// }
| import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.hateoas.Representation; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
public class CarRepresentation extends Representation {
private int id;
private String name;
| // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Representation.java
// public class Representation {
//
// private final List<Link> links = new ArrayList<>(1); // most of the time, there will only have 1 link (self)
//
// public void addLink(Link link) {
// links.add(link);
// }
//
// public List<Link> getLinks() {
// return unmodifiableList(links);
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarRepresentation.java
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.hateoas.Representation;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
public class CarRepresentation extends Representation {
private int id;
private String name;
| public CarRepresentation(Car car) { |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/Main.java | // Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarModule.java
// public class CarModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Car.class).to(CarApplication.class);
// bind(CarRepository.class).to(InMemoryCarRepository.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/HelloModule.java
// public class HelloModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Hello.class).to(HelloApplication.class);
// bind(CarService.class).to(RemoteCarService.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/di/RestletInfraModule.java
// public class RestletInfraModule extends AbstractModule {
// @Override
// protected void configure() {
// bind(Verifier.class).to(AuthTokenVerifier.class);
// }
// }
| import com.google.inject.Guice;
import com.google.inject.Injector;
import io.github.cdelmas.spike.restlet.car.CarModule;
import io.github.cdelmas.spike.restlet.hello.HelloModule;
import io.github.cdelmas.spike.restlet.infrastructure.di.RestletInfraModule;
import org.restlet.ext.guice.SelfInjectingServerResourceModule; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet;
public class Main {
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new SelfInjectingServerResourceModule(), | // Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarModule.java
// public class CarModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Car.class).to(CarApplication.class);
// bind(CarRepository.class).to(InMemoryCarRepository.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/HelloModule.java
// public class HelloModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Hello.class).to(HelloApplication.class);
// bind(CarService.class).to(RemoteCarService.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/di/RestletInfraModule.java
// public class RestletInfraModule extends AbstractModule {
// @Override
// protected void configure() {
// bind(Verifier.class).to(AuthTokenVerifier.class);
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/Main.java
import com.google.inject.Guice;
import com.google.inject.Injector;
import io.github.cdelmas.spike.restlet.car.CarModule;
import io.github.cdelmas.spike.restlet.hello.HelloModule;
import io.github.cdelmas.spike.restlet.infrastructure.di.RestletInfraModule;
import org.restlet.ext.guice.SelfInjectingServerResourceModule;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet;
public class Main {
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new SelfInjectingServerResourceModule(), | new RestletInfraModule(), |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/Main.java | // Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarModule.java
// public class CarModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Car.class).to(CarApplication.class);
// bind(CarRepository.class).to(InMemoryCarRepository.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/HelloModule.java
// public class HelloModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Hello.class).to(HelloApplication.class);
// bind(CarService.class).to(RemoteCarService.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/di/RestletInfraModule.java
// public class RestletInfraModule extends AbstractModule {
// @Override
// protected void configure() {
// bind(Verifier.class).to(AuthTokenVerifier.class);
// }
// }
| import com.google.inject.Guice;
import com.google.inject.Injector;
import io.github.cdelmas.spike.restlet.car.CarModule;
import io.github.cdelmas.spike.restlet.hello.HelloModule;
import io.github.cdelmas.spike.restlet.infrastructure.di.RestletInfraModule;
import org.restlet.ext.guice.SelfInjectingServerResourceModule; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet;
public class Main {
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new SelfInjectingServerResourceModule(),
new RestletInfraModule(), | // Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarModule.java
// public class CarModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Car.class).to(CarApplication.class);
// bind(CarRepository.class).to(InMemoryCarRepository.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/HelloModule.java
// public class HelloModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Hello.class).to(HelloApplication.class);
// bind(CarService.class).to(RemoteCarService.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/di/RestletInfraModule.java
// public class RestletInfraModule extends AbstractModule {
// @Override
// protected void configure() {
// bind(Verifier.class).to(AuthTokenVerifier.class);
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/Main.java
import com.google.inject.Guice;
import com.google.inject.Injector;
import io.github.cdelmas.spike.restlet.car.CarModule;
import io.github.cdelmas.spike.restlet.hello.HelloModule;
import io.github.cdelmas.spike.restlet.infrastructure.di.RestletInfraModule;
import org.restlet.ext.guice.SelfInjectingServerResourceModule;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet;
public class Main {
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new SelfInjectingServerResourceModule(),
new RestletInfraModule(), | new CarModule(), |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/Main.java | // Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarModule.java
// public class CarModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Car.class).to(CarApplication.class);
// bind(CarRepository.class).to(InMemoryCarRepository.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/HelloModule.java
// public class HelloModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Hello.class).to(HelloApplication.class);
// bind(CarService.class).to(RemoteCarService.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/di/RestletInfraModule.java
// public class RestletInfraModule extends AbstractModule {
// @Override
// protected void configure() {
// bind(Verifier.class).to(AuthTokenVerifier.class);
// }
// }
| import com.google.inject.Guice;
import com.google.inject.Injector;
import io.github.cdelmas.spike.restlet.car.CarModule;
import io.github.cdelmas.spike.restlet.hello.HelloModule;
import io.github.cdelmas.spike.restlet.infrastructure.di.RestletInfraModule;
import org.restlet.ext.guice.SelfInjectingServerResourceModule; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet;
public class Main {
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new SelfInjectingServerResourceModule(),
new RestletInfraModule(),
new CarModule(), | // Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/car/CarModule.java
// public class CarModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Car.class).to(CarApplication.class);
// bind(CarRepository.class).to(InMemoryCarRepository.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/HelloModule.java
// public class HelloModule extends AbstractModule {
//
// @Override
// protected void configure() {
// bind(Application.class).annotatedWith(Hello.class).to(HelloApplication.class);
// bind(CarService.class).to(RemoteCarService.class);
// }
// }
//
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/di/RestletInfraModule.java
// public class RestletInfraModule extends AbstractModule {
// @Override
// protected void configure() {
// bind(Verifier.class).to(AuthTokenVerifier.class);
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/Main.java
import com.google.inject.Guice;
import com.google.inject.Injector;
import io.github.cdelmas.spike.restlet.car.CarModule;
import io.github.cdelmas.spike.restlet.hello.HelloModule;
import io.github.cdelmas.spike.restlet.infrastructure.di.RestletInfraModule;
import org.restlet.ext.guice.SelfInjectingServerResourceModule;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet;
public class Main {
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new SelfInjectingServerResourceModule(),
new RestletInfraModule(),
new CarModule(), | new HelloModule()); |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarModule.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
| import com.google.inject.AbstractModule;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
public class CarModule extends AbstractModule {
@Override
protected void configure() { | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarModule.java
import com.google.inject.AbstractModule;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
public class CarModule extends AbstractModule {
@Override
protected void configure() { | bind(CarRepository.class).to(InMemoryCarRepository.class); |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarModule.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
| import com.google.inject.AbstractModule;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
public class CarModule extends AbstractModule {
@Override
protected void configure() { | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/persistence/InMemoryCarRepository.java
// @Singleton
// public class InMemoryCarRepository implements CarRepository {
//
// private final AtomicInteger idGenerator = new AtomicInteger(1);
// private final Map<Integer, Car> repository = new ConcurrentHashMap<>();
//
// @Override
// public Optional<Car> byId(int id) {
// return Optional.ofNullable(repository.get(id));
// }
//
// @Override
// public List<Car> all() {
// return new ArrayList<>(repository.values());
// }
//
// @Override
// public void save(Car car) {
// if (car.getId() == null) {
// car.setId(idGenerator.getAndIncrement());
// }
// repository.put(car.getId(), car);
// }
//
// @Override
// public void update(Car car) {
// save(car);
// }
//
// @Override
// public void delete(Car car) {
// repository.remove(car.getId());
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/car/CarModule.java
import com.google.inject.AbstractModule;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.github.cdelmas.spike.common.persistence.InMemoryCarRepository;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.car;
public class CarModule extends AbstractModule {
@Override
protected void configure() { | bind(CarRepository.class).to(InMemoryCarRepository.class); |
cdelmas/microservices-comparison | sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/HelloResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
| import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import io.github.cdelmas.spike.common.domain.Car;
import spark.Request;
import spark.Response;
import java.util.Arrays;
import java.util.List;
import static java.util.stream.Collectors.toList; | package io.github.cdelmas.spike.sparkjava;
public class HelloResource {
public String hello (Request request, Response response) {
String token = readToken(request); | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/HelloResource.java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import io.github.cdelmas.spike.common.domain.Car;
import spark.Request;
import spark.Response;
import java.util.Arrays;
import java.util.List;
import static java.util.stream.Collectors.toList;
package io.github.cdelmas.spike.sparkjava;
public class HelloResource {
public String hello (Request request, Response response) {
String token = readToken(request); | HttpResponse<Car[]> carHttpResponse; |
cdelmas/microservices-comparison | spring-boot/src/main/java/io/github/cdelmas/spike/springboot/car/CarRepresentation.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
| import io.github.cdelmas.spike.common.domain.Car;
import org.springframework.hateoas.ResourceSupport; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.springboot.car;
public class CarRepresentation extends ResourceSupport {
private final String name;
| // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: spring-boot/src/main/java/io/github/cdelmas/spike/springboot/car/CarRepresentation.java
import io.github.cdelmas.spike.common.domain.Car;
import org.springframework.hateoas.ResourceSupport;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.springboot.car;
public class CarRepresentation extends ResourceSupport {
private final String name;
| public CarRepresentation(Car car) { |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/di/RestletInfraModule.java | // Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/auth/AuthTokenVerifier.java
// public class AuthTokenVerifier implements Verifier {
//
// @Inject
// private AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory;
//
// @Override
// public int verify(Request request, Response response) {
// final String token;
//
// try {
// ChallengeResponse cr = request.getChallengeResponse();
// if (cr == null) {
// return RESULT_MISSING;
// } else if (ChallengeScheme.HTTP_OAUTH_BEARER.equals(cr.getScheme())) {
// final String bearer = cr.getRawValue();
// if (bearer == null || bearer.isEmpty()) {
// return RESULT_MISSING;
// }
// token = bearer;
// } else {
// return RESULT_UNSUPPORTED;
// }
// } catch (Exception ex) {
// return RESULT_INVALID;
// }
//
// Try<User> user = accessTokenVerificationCommandFactory.createVerificationCommand(token).executeCommand();
// return user.map(u -> {
// org.restlet.security.User restletUser = createRestletUser(u);
// request.getClientInfo().setUser(restletUser);
// request.getAttributes().put("token", token);
// return RESULT_VALID;
// }).orElse(RESULT_INVALID);
// }
//
// private org.restlet.security.User createRestletUser(User user) {
// org.restlet.security.User restletUser = new org.restlet.security.User();
// restletUser.setIdentifier(user.getId());
// restletUser.setLastName(user.getName());
// return restletUser;
// }
//
// }
| import com.google.inject.AbstractModule;
import io.github.cdelmas.spike.restlet.infrastructure.auth.AuthTokenVerifier;
import org.restlet.security.Verifier; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.infrastructure.di;
public class RestletInfraModule extends AbstractModule {
@Override
protected void configure() { | // Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/auth/AuthTokenVerifier.java
// public class AuthTokenVerifier implements Verifier {
//
// @Inject
// private AccessTokenVerificationCommandFactory accessTokenVerificationCommandFactory;
//
// @Override
// public int verify(Request request, Response response) {
// final String token;
//
// try {
// ChallengeResponse cr = request.getChallengeResponse();
// if (cr == null) {
// return RESULT_MISSING;
// } else if (ChallengeScheme.HTTP_OAUTH_BEARER.equals(cr.getScheme())) {
// final String bearer = cr.getRawValue();
// if (bearer == null || bearer.isEmpty()) {
// return RESULT_MISSING;
// }
// token = bearer;
// } else {
// return RESULT_UNSUPPORTED;
// }
// } catch (Exception ex) {
// return RESULT_INVALID;
// }
//
// Try<User> user = accessTokenVerificationCommandFactory.createVerificationCommand(token).executeCommand();
// return user.map(u -> {
// org.restlet.security.User restletUser = createRestletUser(u);
// request.getClientInfo().setUser(restletUser);
// request.getAttributes().put("token", token);
// return RESULT_VALID;
// }).orElse(RESULT_INVALID);
// }
//
// private org.restlet.security.User createRestletUser(User user) {
// org.restlet.security.User restletUser = new org.restlet.security.User();
// restletUser.setIdentifier(user.getId());
// restletUser.setLastName(user.getName());
// return restletUser;
// }
//
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/infrastructure/di/RestletInfraModule.java
import com.google.inject.AbstractModule;
import io.github.cdelmas.spike.restlet.infrastructure.auth.AuthTokenVerifier;
import org.restlet.security.Verifier;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.infrastructure.di;
public class RestletInfraModule extends AbstractModule {
@Override
protected void configure() { | bind(Verifier.class).to(AuthTokenVerifier.class); |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/hello/HelloModule.java | // Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/infrastructure/DropwizardServerConfiguration.java
// public class DropwizardServerConfiguration extends Configuration {
// @NotEmpty
// private String template;
//
// @NotEmpty
// private String defaultName = "Stranger";
//
// @Valid
// @NotNull
// private JerseyClientConfiguration httpClient = new JerseyClientConfiguration();
//
// @JsonProperty("httpClient")
// public JerseyClientConfiguration getJerseyClientConfiguration() {
// return httpClient;
// }
//
// @JsonProperty
// public String getTemplate() {
// return template;
// }
//
// @JsonProperty
// public void setTemplate(String template) {
// this.template = template;
// }
//
// @JsonProperty
// public String getDefaultName() {
// return defaultName;
// }
//
// @JsonProperty
// public void setDefaultName(String name) {
// this.defaultName = name;
// }
//
// }
| import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.setup.Environment;
import io.github.cdelmas.spike.dropwizard.infrastructure.DropwizardServerConfiguration;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.client.Client; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.hello;
public class HelloModule extends AbstractModule {
private Client client;
@Override
protected void configure() {
bind(CarService.class).to(RemoteCarService.class);
}
@Provides
@Named("template") | // Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/infrastructure/DropwizardServerConfiguration.java
// public class DropwizardServerConfiguration extends Configuration {
// @NotEmpty
// private String template;
//
// @NotEmpty
// private String defaultName = "Stranger";
//
// @Valid
// @NotNull
// private JerseyClientConfiguration httpClient = new JerseyClientConfiguration();
//
// @JsonProperty("httpClient")
// public JerseyClientConfiguration getJerseyClientConfiguration() {
// return httpClient;
// }
//
// @JsonProperty
// public String getTemplate() {
// return template;
// }
//
// @JsonProperty
// public void setTemplate(String template) {
// this.template = template;
// }
//
// @JsonProperty
// public String getDefaultName() {
// return defaultName;
// }
//
// @JsonProperty
// public void setDefaultName(String name) {
// this.defaultName = name;
// }
//
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/hello/HelloModule.java
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.setup.Environment;
import io.github.cdelmas.spike.dropwizard.infrastructure.DropwizardServerConfiguration;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.client.Client;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.hello;
public class HelloModule extends AbstractModule {
private Client client;
@Override
protected void configure() {
bind(CarService.class).to(RemoteCarService.class);
}
@Provides
@Named("template") | public String provideTemplate(DropwizardServerConfiguration configuration) { |
cdelmas/microservices-comparison | spring-boot/src/main/java/io/github/cdelmas/spike/springboot/hello/SampleController.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
| import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import io.github.cdelmas.spike.common.domain.Car;
import org.springframework.cloud.security.oauth2.resource.EnableOAuth2Resource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.List; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.springboot.hello;
@EnableOAuth2Resource
@RestController
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home(@RequestHeader("Authorization") String authToken) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Accept", "application/json");
headers.add("Authorization", authToken);
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(null, headers);
RestTemplate rest = new RestTemplate(); | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: spring-boot/src/main/java/io/github/cdelmas/spike/springboot/hello/SampleController.java
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import io.github.cdelmas.spike.common.domain.Car;
import org.springframework.cloud.security.oauth2.resource.EnableOAuth2Resource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.List;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.springboot.hello;
@EnableOAuth2Resource
@RestController
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home(@RequestHeader("Authorization") String authToken) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Accept", "application/json");
headers.add("Authorization", authToken);
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(null, headers);
RestTemplate rest = new RestTemplate(); | ResponseEntity<Car[]> responseEntity = rest.exchange("https://localhost:8443/cars", HttpMethod.GET, requestEntity, Car[].class); |
cdelmas/microservices-comparison | sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/CarRepresentation.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Representation.java
// public class Representation {
//
// private final List<Link> links = new ArrayList<>(1); // most of the time, there will only have 1 link (self)
//
// public void addLink(Link link) {
// links.add(link);
// }
//
// public List<Link> getLinks() {
// return unmodifiableList(links);
// }
// }
| import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.hateoas.Representation; | package io.github.cdelmas.spike.sparkjava;
public class CarRepresentation extends Representation {
private final String name;
| // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Representation.java
// public class Representation {
//
// private final List<Link> links = new ArrayList<>(1); // most of the time, there will only have 1 link (self)
//
// public void addLink(Link link) {
// links.add(link);
// }
//
// public List<Link> getLinks() {
// return unmodifiableList(links);
// }
// }
// Path: sparkjava/src/main/java/io/github/cdelmas/spike/sparkjava/CarRepresentation.java
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.hateoas.Representation;
package io.github.cdelmas.spike.sparkjava;
public class CarRepresentation extends Representation {
private final String name;
| public CarRepresentation(Car c) { |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/hello/HelloWorldResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
| import static java.util.stream.Collectors.toList;
import com.codahale.metrics.annotation.Timed;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.hello;
@Path("/hello-world")
@Produces(MediaType.APPLICATION_JSON)
public class HelloWorldResource {
private final String template;
private final String defaultName;
private final AtomicLong counter;
@Inject
private CarService carService;
@Inject
public HelloWorldResource(@Named("template") String template, @Named("defaultName") String defaultName) {
this.template = template;
this.defaultName = defaultName;
this.counter = new AtomicLong();
}
@GET
@Timed | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/hello/HelloWorldResource.java
import static java.util.stream.Collectors.toList;
import com.codahale.metrics.annotation.Timed;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.hello;
@Path("/hello-world")
@Produces(MediaType.APPLICATION_JSON)
public class HelloWorldResource {
private final String template;
private final String defaultName;
private final AtomicLong counter;
@Inject
private CarService carService;
@Inject
public HelloWorldResource(@Named("template") String template, @Named("defaultName") String defaultName) {
this.template = template;
this.defaultName = defaultName;
this.counter = new AtomicLong();
}
@GET
@Timed | public Saying sayHello(@Auth User user, @QueryParam("name") Optional<String> name) { |
cdelmas/microservices-comparison | dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/hello/HelloWorldResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
| import static java.util.stream.Collectors.toList;
import com.codahale.metrics.annotation.Timed;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.hello;
@Path("/hello-world")
@Produces(MediaType.APPLICATION_JSON)
public class HelloWorldResource {
private final String template;
private final String defaultName;
private final AtomicLong counter;
@Inject
private CarService carService;
@Inject
public HelloWorldResource(@Named("template") String template, @Named("defaultName") String defaultName) {
this.template = template;
this.defaultName = defaultName;
this.counter = new AtomicLong();
}
@GET
@Timed
public Saying sayHello(@Auth User user, @QueryParam("name") Optional<String> name) {
final String value = String.format(template, name.orElse(defaultName)); | // Path: common/src/main/java/io/github/cdelmas/spike/common/auth/User.java
// public class User {
//
// private final String id;
//
// private final String name;
// private String token;
//
// public User(String id, String name) {
// this.id = id;
// this.name = name;
// }
//
// public String getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
//
// public String getToken() {
// return token;
// }
//
// public void setToken(String token) {
// this.token = token;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: dropwizard/src/main/java/io/github/cdelmas/spike/dropwizard/hello/HelloWorldResource.java
import static java.util.stream.Collectors.toList;
import com.codahale.metrics.annotation.Timed;
import io.dropwizard.auth.Auth;
import io.github.cdelmas.spike.common.auth.User;
import io.github.cdelmas.spike.common.domain.Car;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.dropwizard.hello;
@Path("/hello-world")
@Produces(MediaType.APPLICATION_JSON)
public class HelloWorldResource {
private final String template;
private final String defaultName;
private final AtomicLong counter;
@Inject
private CarService carService;
@Inject
public HelloWorldResource(@Named("template") String template, @Named("defaultName") String defaultName) {
this.template = template;
this.defaultName = defaultName;
this.counter = new AtomicLong();
}
@GET
@Timed
public Saying sayHello(@Auth User user, @QueryParam("name") Optional<String> name) {
final String value = String.format(template, name.orElse(defaultName)); | List<Car> allCars = carService.getAllCars(user.getToken()); |
cdelmas/microservices-comparison | restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/RemoteCarService.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
| import io.github.cdelmas.spike.common.domain.Car;
import org.restlet.Client;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.Parameter;
import org.restlet.data.Protocol;
import org.restlet.resource.ClientResource;
import org.restlet.util.Series;
import java.util.List;
import static java.util.Arrays.asList; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.hello;
public class RemoteCarService implements CarService {
@Override | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: restlet-server/src/main/java/io/github/cdelmas/spike/restlet/hello/RemoteCarService.java
import io.github.cdelmas.spike.common.domain.Car;
import org.restlet.Client;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.Parameter;
import org.restlet.data.Protocol;
import org.restlet.resource.ClientResource;
import org.restlet.util.Series;
import java.util.List;
import static java.util.Arrays.asList;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.restlet.hello;
public class RemoteCarService implements CarService {
@Override | public List<Car> list() { |
cdelmas/microservices-comparison | vertx/src/main/java/io/github/cdelmas/spike/vertx/car/CarResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
| import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.Json;
import io.vertx.ext.web.RoutingContext;
import java.util.Optional;
import static io.github.cdelmas.spike.common.hateoas.Link.self; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.car;
public class CarResource {
private final CarRepository carRepository;
public CarResource(CarRepository carRepository) {
this.carRepository = carRepository;
}
public void byId(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
String idParam = routingContext.request().getParam("id");
if (idParam == null) {
response.setStatusCode(400).end();
} else { | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
// Path: vertx/src/main/java/io/github/cdelmas/spike/vertx/car/CarResource.java
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.Json;
import io.vertx.ext.web.RoutingContext;
import java.util.Optional;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.car;
public class CarResource {
private final CarRepository carRepository;
public CarResource(CarRepository carRepository) {
this.carRepository = carRepository;
}
public void byId(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
String idParam = routingContext.request().getParam("id");
if (idParam == null) {
response.setStatusCode(400).end();
} else { | Optional<Car> car = carRepository.byId(Integer.parseInt(idParam)); |
cdelmas/microservices-comparison | vertx/src/main/java/io/github/cdelmas/spike/vertx/car/CarResource.java | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
| import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.Json;
import io.vertx.ext.web.RoutingContext;
import java.util.Optional;
import static io.github.cdelmas.spike.common.hateoas.Link.self; | /*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.car;
public class CarResource {
private final CarRepository carRepository;
public CarResource(CarRepository carRepository) {
this.carRepository = carRepository;
}
public void byId(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
String idParam = routingContext.request().getParam("id");
if (idParam == null) {
response.setStatusCode(400).end();
} else {
Optional<Car> car = carRepository.byId(Integer.parseInt(idParam));
if (car.isPresent()) {
CarRepresentation carRepresentation = new CarRepresentation(car.get()); | // Path: common/src/main/java/io/github/cdelmas/spike/common/domain/Car.java
// public class Car {
//
// private Integer id;
// private String name;
//
// public Car(String name) {
// this.name = name;
// }
//
// Car() {
//
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Integer getId() {
// return id;
// }
//
// public String getName() {
// return name;
// }
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/domain/CarRepository.java
// public interface CarRepository {
//
// Optional<Car> byId(int id);
//
// List<Car> all();
//
// void save(Car car);
//
// void update(Car car);
//
// void delete(Car car);
// }
//
// Path: common/src/main/java/io/github/cdelmas/spike/common/hateoas/Link.java
// public static Link self(String href) {
// return new Link("self", href);
// }
// Path: vertx/src/main/java/io/github/cdelmas/spike/vertx/car/CarResource.java
import io.github.cdelmas.spike.common.domain.Car;
import io.github.cdelmas.spike.common.domain.CarRepository;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.Json;
import io.vertx.ext.web.RoutingContext;
import java.util.Optional;
import static io.github.cdelmas.spike.common.hateoas.Link.self;
/*
Copyright 2015 Cyril Delmas
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.
*/
package io.github.cdelmas.spike.vertx.car;
public class CarResource {
private final CarRepository carRepository;
public CarResource(CarRepository carRepository) {
this.carRepository = carRepository;
}
public void byId(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
String idParam = routingContext.request().getParam("id");
if (idParam == null) {
response.setStatusCode(400).end();
} else {
Optional<Car> car = carRepository.byId(Integer.parseInt(idParam));
if (car.isPresent()) {
CarRepresentation carRepresentation = new CarRepresentation(car.get()); | carRepresentation.addLink(self(routingContext.request().absoluteURI())); |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/StringOutputStream.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/utils/CharUtil.java
// public class CharUtil {
//
// /**
// * Converts byte array to char array.
// */
// public static char[] toCharArray(byte[] barr) {
// if (barr == null) {
// return null;
// }
// char[] carr = new char[barr.length];
// for (int i = 0; i < barr.length; i++) {
// carr[i] = (char) barr[i];
// }
// return carr;
// }
// }
| import uk.co.pols.bamboo.gitplugin.client.utils.CharUtil;
import java.io.Serializable;
import java.io.OutputStream; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
/**
* Provides an OutputStream to an internal String. Internally converts bytes
* to a Strings and stores them in an internal StringBuffer.
*/
public class StringOutputStream extends OutputStream implements Serializable {
private StringBuffer buf = null;
public StringOutputStream() {
super();
buf = new StringBuffer();
}
/**
* Returns the content of the internal StringBuffer as a String, the result
* of all writing to this OutputStream.
*
* @return returns the content of the internal StringBuffer
*/
public String toString() {
return buf.toString();
}
/**
* Sets the internal StringBuffer to null.
*/
public void close() {
buf = null;
}
/**
* Writes and appends byte array to StringOutputStream.
*
* @param b byte array
*/
public void write(byte[] b) { | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/utils/CharUtil.java
// public class CharUtil {
//
// /**
// * Converts byte array to char array.
// */
// public static char[] toCharArray(byte[] barr) {
// if (barr == null) {
// return null;
// }
// char[] carr = new char[barr.length];
// for (int i = 0; i < barr.length; i++) {
// carr[i] = (char) barr[i];
// }
// return carr;
// }
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/StringOutputStream.java
import uk.co.pols.bamboo.gitplugin.client.utils.CharUtil;
import java.io.Serializable;
import java.io.OutputStream;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
/**
* Provides an OutputStream to an internal String. Internally converts bytes
* to a Strings and stores them in an internal StringBuffer.
*/
public class StringOutputStream extends OutputStream implements Serializable {
private StringBuffer buf = null;
public StringOutputStream() {
super();
buf = new StringBuffer();
}
/**
* Returns the content of the internal StringBuffer as a String, the result
* of all writing to this OutputStream.
*
* @return returns the content of the internal StringBuffer
*/
public String toString() {
return buf.toString();
}
/**
* Sets the internal StringBuffer to null.
*/
public void close() {
buf = null;
}
/**
* Writes and appends byte array to StringOutputStream.
*
* @param b byte array
*/
public void write(byte[] b) { | buf.append(CharUtil.toCharArray(b)); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogParserTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogParser.java
// public class GitLogParser {
// private static final String AUTHOR_LINE_PREFIX = "Author:";
// private static final String NEW_COMMIT_LINE_PREFIX = "commit";
// private static final DateTimeFormatter GIT_ISO_DATE_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss Z");
// private static final String DATE_LINE_PREFIX = "Date:";
// private static final String MERGE_LINE_PREFIX = "Merge";
//
// private String log;
// private String mostRecentCommitDate = null;
//
// public GitLogParser(String log) {
// this.log = (log == null) ? "" : log;
// }
//
// public List<Commit> extractCommits(String notOnlastRevisionChecked) {
// List<Commit> commits = new ArrayList<Commit>();
// GitCommitLogEntry commitLogEntry = new GitCommitLogEntry("Unknown");
//
// for (String line : log.split("\n")) {
// if (line.startsWith(NEW_COMMIT_LINE_PREFIX)) {
// if (commitLogEntry.isValidCommit(notOnlastRevisionChecked)) {
// commits.add(commitLogEntry.toBambooCommit());
// }
// commitLogEntry = new GitCommitLogEntry(line.substring(NEW_COMMIT_LINE_PREFIX.length() + 1));
// } else if (line.startsWith(AUTHOR_LINE_PREFIX)) {
// commitLogEntry.addAuthor(line);
// } else if (line.startsWith(DATE_LINE_PREFIX)) {
// commitLogEntry.addDate(line);
// } else if (line.length() > 0 && Character.isDigit(line.toCharArray()[0])) {
// commitLogEntry.addFileName(line);
// } else if (line.startsWith(MERGE_LINE_PREFIX)) {
// // ignore
// } else if (line.length() > 0 && !"\n".equals(line)) {
// commitLogEntry.addCommentLine(line);
// }
// }
//
// if (commitLogEntry.isValidCommit(notOnlastRevisionChecked)) {
// commits.add(commitLogEntry.toBambooCommit());
// }
// return commits;
// }
//
// public String getMostRecentCommitDate() {
// return mostRecentCommitDate;
// }
//
// public class GitCommitLogEntry {
// private StringBuffer comment = new StringBuffer();
// private List<CommitFile> commitFiles = new ArrayList<CommitFile>();
// private String commitId;
// private Author author = null;
// private DateTime date = null;
//
// public GitCommitLogEntry(String commitId) {
// this.commitId = commitId;
// }
//
// public void addFileName(String line) {
// StringTokenizer stringTokenizer = new StringTokenizer(line);
// try {
// skipLinesAdded(stringTokenizer);
// skipLinesDeleted(stringTokenizer);
// commitFiles.add(fileWithinCurrentCommit(stringTokenizer.nextToken(), commitId));
// } catch (Exception e) {
// // can't parse, so lets add it to the comment, so we don't lose it
// comment.append(line).append("\n");
// }
// }
//
// public void addCommentLine(String line) {
// comment.append(line).append("\n");
// }
//
// public void addAuthor(String line) {
// author = extractAuthor(line);
// }
//
// public void addDate(String line) {
// String commitDate = line.substring(DATE_LINE_PREFIX.length()).trim();
// if (mostRecentCommitDate == null) {
// mostRecentCommitDate = commitDate;
// }
// date = GIT_ISO_DATE_FORMAT.parseDateTime(commitDate);
// }
//
// public boolean isValidCommit(String dateOfLastRecordCommit) {
// return author != null && date != null && !sameDateStampAsThePreviouslyProcessedCommit(dateOfLastRecordCommit);
// }
//
// private boolean sameDateStampAsThePreviouslyProcessedCommit(String dateOfLastRecordCommit) {
// if (dateOfLastRecordCommit == null) {
// return false;
// }
//
// DateTime dateTime = GIT_ISO_DATE_FORMAT.parseDateTime(dateOfLastRecordCommit);
// return dateTime.equals(date);
// }
//
// public Commit toBambooCommit() {
// CommitImpl commit = new CommitImpl(author, comment.toString(), date.toDate());
// commit.setFiles(commitFiles);
// return commit;
// }
//
// private int skipLinesDeleted(StringTokenizer stringTokenizer) {
// return Integer.parseInt(stringTokenizer.nextToken());
// }
//
// private int skipLinesAdded(StringTokenizer st) {
// return Integer.parseInt(st.nextToken());
// }
//
// private Author extractAuthor(String line) {
// String[] tokens = line.substring(AUTHOR_LINE_PREFIX.length()).trim().split(" ");
// if (tokens.length == 1 || tokens.length == 2) {
// return new AuthorImpl(tokens[0]);
// }
// if (tokens.length == 3) {
// return new AuthorImpl(tokens[0] + " " + tokens[1]);
// }
//
// return new AuthorImpl(Author.UNKNOWN_AUTHOR);
// }
//
// private CommitFileImpl fileWithinCurrentCommit(String filename, String commitId) {
// CommitFileImpl file = new CommitFileImpl(filename);
// file.setRevision(commitId);
// return file;
// }
// }
// }
| import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.commit.CommitFile;
import junit.framework.TestCase;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.text.ParseException;
import java.util.List;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogParser; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class GitLogParserTest extends TestCase {
private static final int MOST_RECENT_COMMIT = 0;
private static final int FIRST_COMMIT = 28;
public void testReturnsAnEmptyListOfCommitsIfTheLogIsEmpty() { | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogParser.java
// public class GitLogParser {
// private static final String AUTHOR_LINE_PREFIX = "Author:";
// private static final String NEW_COMMIT_LINE_PREFIX = "commit";
// private static final DateTimeFormatter GIT_ISO_DATE_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss Z");
// private static final String DATE_LINE_PREFIX = "Date:";
// private static final String MERGE_LINE_PREFIX = "Merge";
//
// private String log;
// private String mostRecentCommitDate = null;
//
// public GitLogParser(String log) {
// this.log = (log == null) ? "" : log;
// }
//
// public List<Commit> extractCommits(String notOnlastRevisionChecked) {
// List<Commit> commits = new ArrayList<Commit>();
// GitCommitLogEntry commitLogEntry = new GitCommitLogEntry("Unknown");
//
// for (String line : log.split("\n")) {
// if (line.startsWith(NEW_COMMIT_LINE_PREFIX)) {
// if (commitLogEntry.isValidCommit(notOnlastRevisionChecked)) {
// commits.add(commitLogEntry.toBambooCommit());
// }
// commitLogEntry = new GitCommitLogEntry(line.substring(NEW_COMMIT_LINE_PREFIX.length() + 1));
// } else if (line.startsWith(AUTHOR_LINE_PREFIX)) {
// commitLogEntry.addAuthor(line);
// } else if (line.startsWith(DATE_LINE_PREFIX)) {
// commitLogEntry.addDate(line);
// } else if (line.length() > 0 && Character.isDigit(line.toCharArray()[0])) {
// commitLogEntry.addFileName(line);
// } else if (line.startsWith(MERGE_LINE_PREFIX)) {
// // ignore
// } else if (line.length() > 0 && !"\n".equals(line)) {
// commitLogEntry.addCommentLine(line);
// }
// }
//
// if (commitLogEntry.isValidCommit(notOnlastRevisionChecked)) {
// commits.add(commitLogEntry.toBambooCommit());
// }
// return commits;
// }
//
// public String getMostRecentCommitDate() {
// return mostRecentCommitDate;
// }
//
// public class GitCommitLogEntry {
// private StringBuffer comment = new StringBuffer();
// private List<CommitFile> commitFiles = new ArrayList<CommitFile>();
// private String commitId;
// private Author author = null;
// private DateTime date = null;
//
// public GitCommitLogEntry(String commitId) {
// this.commitId = commitId;
// }
//
// public void addFileName(String line) {
// StringTokenizer stringTokenizer = new StringTokenizer(line);
// try {
// skipLinesAdded(stringTokenizer);
// skipLinesDeleted(stringTokenizer);
// commitFiles.add(fileWithinCurrentCommit(stringTokenizer.nextToken(), commitId));
// } catch (Exception e) {
// // can't parse, so lets add it to the comment, so we don't lose it
// comment.append(line).append("\n");
// }
// }
//
// public void addCommentLine(String line) {
// comment.append(line).append("\n");
// }
//
// public void addAuthor(String line) {
// author = extractAuthor(line);
// }
//
// public void addDate(String line) {
// String commitDate = line.substring(DATE_LINE_PREFIX.length()).trim();
// if (mostRecentCommitDate == null) {
// mostRecentCommitDate = commitDate;
// }
// date = GIT_ISO_DATE_FORMAT.parseDateTime(commitDate);
// }
//
// public boolean isValidCommit(String dateOfLastRecordCommit) {
// return author != null && date != null && !sameDateStampAsThePreviouslyProcessedCommit(dateOfLastRecordCommit);
// }
//
// private boolean sameDateStampAsThePreviouslyProcessedCommit(String dateOfLastRecordCommit) {
// if (dateOfLastRecordCommit == null) {
// return false;
// }
//
// DateTime dateTime = GIT_ISO_DATE_FORMAT.parseDateTime(dateOfLastRecordCommit);
// return dateTime.equals(date);
// }
//
// public Commit toBambooCommit() {
// CommitImpl commit = new CommitImpl(author, comment.toString(), date.toDate());
// commit.setFiles(commitFiles);
// return commit;
// }
//
// private int skipLinesDeleted(StringTokenizer stringTokenizer) {
// return Integer.parseInt(stringTokenizer.nextToken());
// }
//
// private int skipLinesAdded(StringTokenizer st) {
// return Integer.parseInt(st.nextToken());
// }
//
// private Author extractAuthor(String line) {
// String[] tokens = line.substring(AUTHOR_LINE_PREFIX.length()).trim().split(" ");
// if (tokens.length == 1 || tokens.length == 2) {
// return new AuthorImpl(tokens[0]);
// }
// if (tokens.length == 3) {
// return new AuthorImpl(tokens[0] + " " + tokens[1]);
// }
//
// return new AuthorImpl(Author.UNKNOWN_AUTHOR);
// }
//
// private CommitFileImpl fileWithinCurrentCommit(String filename, String commitId) {
// CommitFileImpl file = new CommitFileImpl(filename);
// file.setRevision(commitId);
// return file;
// }
// }
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogParserTest.java
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.commit.CommitFile;
import junit.framework.TestCase;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.text.ParseException;
import java.util.List;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogParser;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class GitLogParserTest extends TestCase {
private static final int MOST_RECENT_COMMIT = 0;
private static final int FIRST_COMMIT = 28;
public void testReturnsAnEmptyListOfCommitsIfTheLogIsEmpty() { | GitLogParser parser = new GitLogParser(""); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/CmdLineGitClientTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitPullCommand.java
// public interface GitPullCommand {
// void pullUpdatesFromRemoteRepository(BuildLogger buildLogger, String repositoryUrl, String branch) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/Git.java
// public interface Git {
//
// boolean isValidRepo(File sourceDirectory);
//
// GitCloneCommand repositoryClone();
//
// GitCheckoutCommand checkout();
//
// GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked);
//
// GitPullCommand pull(File sourceCodeDirectory);
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.util.ArrayList;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.commit.CommitImpl;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.repository.RepositoryException;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitPullCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.*;
import uk.co.pols.bamboo.gitplugin.client.git.Git; | package uk.co.pols.bamboo.gitplugin;
public class CmdLineGitClientTest extends MockObjectTestCase {
private static final String LAST_REVISION_CHECKED = "2009-03-22 01:09:25 +0000";
private static final String REPOSITORY_URL = "repository.url";
private static final String REPOSITORY_BRANCH = "master";
private static final String PLAN_KEY = "plankey";
private static final String NO_PREVIOUS_LATEST_UPDATE_TIME = null;
private static final File SOURCE_CODE_DIRECTORY = new File("src");
private BuildLogger buildLogger = mock(BuildLogger.class); | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitPullCommand.java
// public interface GitPullCommand {
// void pullUpdatesFromRemoteRepository(BuildLogger buildLogger, String repositoryUrl, String branch) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/Git.java
// public interface Git {
//
// boolean isValidRepo(File sourceDirectory);
//
// GitCloneCommand repositoryClone();
//
// GitCheckoutCommand checkout();
//
// GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked);
//
// GitPullCommand pull(File sourceCodeDirectory);
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/CmdLineGitClientTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.util.ArrayList;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.commit.CommitImpl;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.repository.RepositoryException;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitPullCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.*;
import uk.co.pols.bamboo.gitplugin.client.git.Git;
package uk.co.pols.bamboo.gitplugin;
public class CmdLineGitClientTest extends MockObjectTestCase {
private static final String LAST_REVISION_CHECKED = "2009-03-22 01:09:25 +0000";
private static final String REPOSITORY_URL = "repository.url";
private static final String REPOSITORY_BRANCH = "master";
private static final String PLAN_KEY = "plankey";
private static final String NO_PREVIOUS_LATEST_UPDATE_TIME = null;
private static final File SOURCE_CODE_DIRECTORY = new File("src");
private BuildLogger buildLogger = mock(BuildLogger.class); | private GitPullCommand gitPullCommand = mock(GitPullCommand.class); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/CmdLineGitClientTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitPullCommand.java
// public interface GitPullCommand {
// void pullUpdatesFromRemoteRepository(BuildLogger buildLogger, String repositoryUrl, String branch) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/Git.java
// public interface Git {
//
// boolean isValidRepo(File sourceDirectory);
//
// GitCloneCommand repositoryClone();
//
// GitCheckoutCommand checkout();
//
// GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked);
//
// GitPullCommand pull(File sourceCodeDirectory);
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.util.ArrayList;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.commit.CommitImpl;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.repository.RepositoryException;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitPullCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.*;
import uk.co.pols.bamboo.gitplugin.client.git.Git; | package uk.co.pols.bamboo.gitplugin;
public class CmdLineGitClientTest extends MockObjectTestCase {
private static final String LAST_REVISION_CHECKED = "2009-03-22 01:09:25 +0000";
private static final String REPOSITORY_URL = "repository.url";
private static final String REPOSITORY_BRANCH = "master";
private static final String PLAN_KEY = "plankey";
private static final String NO_PREVIOUS_LATEST_UPDATE_TIME = null;
private static final File SOURCE_CODE_DIRECTORY = new File("src");
private BuildLogger buildLogger = mock(BuildLogger.class);
private GitPullCommand gitPullCommand = mock(GitPullCommand.class);
private GitLogCommand gitLogCommand = mock(GitLogCommand.class);
private GitCloneCommand gitCloneCommand = mock(GitCloneCommand.class);
private GitCheckoutCommand gitCheckoutCommand = mock(GitCheckoutCommand.class); | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitPullCommand.java
// public interface GitPullCommand {
// void pullUpdatesFromRemoteRepository(BuildLogger buildLogger, String repositoryUrl, String branch) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/Git.java
// public interface Git {
//
// boolean isValidRepo(File sourceDirectory);
//
// GitCloneCommand repositoryClone();
//
// GitCheckoutCommand checkout();
//
// GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked);
//
// GitPullCommand pull(File sourceCodeDirectory);
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/CmdLineGitClientTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.util.ArrayList;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.commit.CommitImpl;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.repository.RepositoryException;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitPullCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.*;
import uk.co.pols.bamboo.gitplugin.client.git.Git;
package uk.co.pols.bamboo.gitplugin;
public class CmdLineGitClientTest extends MockObjectTestCase {
private static final String LAST_REVISION_CHECKED = "2009-03-22 01:09:25 +0000";
private static final String REPOSITORY_URL = "repository.url";
private static final String REPOSITORY_BRANCH = "master";
private static final String PLAN_KEY = "plankey";
private static final String NO_PREVIOUS_LATEST_UPDATE_TIME = null;
private static final File SOURCE_CODE_DIRECTORY = new File("src");
private BuildLogger buildLogger = mock(BuildLogger.class);
private GitPullCommand gitPullCommand = mock(GitPullCommand.class);
private GitLogCommand gitLogCommand = mock(GitLogCommand.class);
private GitCloneCommand gitCloneCommand = mock(GitCloneCommand.class);
private GitCheckoutCommand gitCheckoutCommand = mock(GitCheckoutCommand.class); | private Git git = mock(Git.class); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/CmdLineGitClientTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitPullCommand.java
// public interface GitPullCommand {
// void pullUpdatesFromRemoteRepository(BuildLogger buildLogger, String repositoryUrl, String branch) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/Git.java
// public interface Git {
//
// boolean isValidRepo(File sourceDirectory);
//
// GitCloneCommand repositoryClone();
//
// GitCheckoutCommand checkout();
//
// GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked);
//
// GitPullCommand pull(File sourceCodeDirectory);
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.util.ArrayList;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.commit.CommitImpl;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.repository.RepositoryException;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitPullCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.*;
import uk.co.pols.bamboo.gitplugin.client.git.Git; | package uk.co.pols.bamboo.gitplugin;
public class CmdLineGitClientTest extends MockObjectTestCase {
private static final String LAST_REVISION_CHECKED = "2009-03-22 01:09:25 +0000";
private static final String REPOSITORY_URL = "repository.url";
private static final String REPOSITORY_BRANCH = "master";
private static final String PLAN_KEY = "plankey";
private static final String NO_PREVIOUS_LATEST_UPDATE_TIME = null;
private static final File SOURCE_CODE_DIRECTORY = new File("src");
private BuildLogger buildLogger = mock(BuildLogger.class);
private GitPullCommand gitPullCommand = mock(GitPullCommand.class);
private GitLogCommand gitLogCommand = mock(GitLogCommand.class);
private GitCloneCommand gitCloneCommand = mock(GitCloneCommand.class);
private GitCheckoutCommand gitCheckoutCommand = mock(GitCheckoutCommand.class);
private Git git = mock(Git.class);
private ArrayList<Commit> commits = new ArrayList<Commit>(); | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitPullCommand.java
// public interface GitPullCommand {
// void pullUpdatesFromRemoteRepository(BuildLogger buildLogger, String repositoryUrl, String branch) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/Git.java
// public interface Git {
//
// boolean isValidRepo(File sourceDirectory);
//
// GitCloneCommand repositoryClone();
//
// GitCheckoutCommand checkout();
//
// GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked);
//
// GitPullCommand pull(File sourceCodeDirectory);
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/CmdLineGitClientTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.util.ArrayList;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.commit.CommitImpl;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.repository.RepositoryException;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitPullCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.*;
import uk.co.pols.bamboo.gitplugin.client.git.Git;
package uk.co.pols.bamboo.gitplugin;
public class CmdLineGitClientTest extends MockObjectTestCase {
private static final String LAST_REVISION_CHECKED = "2009-03-22 01:09:25 +0000";
private static final String REPOSITORY_URL = "repository.url";
private static final String REPOSITORY_BRANCH = "master";
private static final String PLAN_KEY = "plankey";
private static final String NO_PREVIOUS_LATEST_UPDATE_TIME = null;
private static final File SOURCE_CODE_DIRECTORY = new File("src");
private BuildLogger buildLogger = mock(BuildLogger.class);
private GitPullCommand gitPullCommand = mock(GitPullCommand.class);
private GitLogCommand gitLogCommand = mock(GitLogCommand.class);
private GitCloneCommand gitCloneCommand = mock(GitCloneCommand.class);
private GitCheckoutCommand gitCheckoutCommand = mock(GitCheckoutCommand.class);
private Git git = mock(Git.class);
private ArrayList<Commit> commits = new ArrayList<Commit>(); | private CmdLineGitClient gitClient = new CmdLineGitClient(git); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitPullCommandTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitPullCommand.java
// public class ExecutorGitPullCommand implements GitPullCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitPullCommand.class);
//
// private String gitExe;
// private File sourceCodeDirectory;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitPullCommand(String gitExe, File sourceCodeDirectory, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.sourceCodeDirectory = sourceCodeDirectory;
// this.commandExecutor = commandExecutor;
// }
//
// public void pullUpdatesFromRemoteRepository(BuildLogger buildLogger, String repositoryUrl, String branch) throws IOException {
// log.info(buildLogger.addBuildLogEntry("Pulling source from branch '" + branch + "' @ '" + repositoryUrl + "' into '" + sourceCodeDirectory.getAbsolutePath() + "'."));
//
// String pullOutput = commandExecutor.execute(new String[]{gitExe, "pull", repositoryUrl, branch + ":" + branch}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, pullOutput);
//
// // git submodule commands will silently do nothing if no submodules are configured
// String submoduleInitOutput = commandExecutor.execute(new String[]{gitExe, "submodule", "init"}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, submoduleInitOutput);
//
// String submoduleUpdateOutput = commandExecutor.execute(new String[]{gitExe, "submodule", "update"}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, submoduleUpdateOutput);
// }
//
// private void checkCommandOutput(BuildLogger buildLogger, String repositoryUrl, String output) throws IOException {
// if (output.contains("fatal:")) {
// throw new IOException("Could not pull from '" + repositoryUrl + "'. git-pull: " + output);
// } else {
// log.info(buildLogger.addBuildLogEntry(output));
// }
// }
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitPullCommand; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitPullCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String GIT_EXE = "git";
| // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitPullCommand.java
// public class ExecutorGitPullCommand implements GitPullCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitPullCommand.class);
//
// private String gitExe;
// private File sourceCodeDirectory;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitPullCommand(String gitExe, File sourceCodeDirectory, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.sourceCodeDirectory = sourceCodeDirectory;
// this.commandExecutor = commandExecutor;
// }
//
// public void pullUpdatesFromRemoteRepository(BuildLogger buildLogger, String repositoryUrl, String branch) throws IOException {
// log.info(buildLogger.addBuildLogEntry("Pulling source from branch '" + branch + "' @ '" + repositoryUrl + "' into '" + sourceCodeDirectory.getAbsolutePath() + "'."));
//
// String pullOutput = commandExecutor.execute(new String[]{gitExe, "pull", repositoryUrl, branch + ":" + branch}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, pullOutput);
//
// // git submodule commands will silently do nothing if no submodules are configured
// String submoduleInitOutput = commandExecutor.execute(new String[]{gitExe, "submodule", "init"}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, submoduleInitOutput);
//
// String submoduleUpdateOutput = commandExecutor.execute(new String[]{gitExe, "submodule", "update"}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, submoduleUpdateOutput);
// }
//
// private void checkCommandOutput(BuildLogger buildLogger, String repositoryUrl, String output) throws IOException {
// if (output.contains("fatal:")) {
// throw new IOException("Could not pull from '" + repositoryUrl + "'. git-pull: " + output);
// } else {
// log.info(buildLogger.addBuildLogEntry(output));
// }
// }
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitPullCommandTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitPullCommand;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitPullCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String GIT_EXE = "git";
| private final CommandExecutor commandExecutor = mock(CommandExecutor.class); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitPullCommandTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitPullCommand.java
// public class ExecutorGitPullCommand implements GitPullCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitPullCommand.class);
//
// private String gitExe;
// private File sourceCodeDirectory;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitPullCommand(String gitExe, File sourceCodeDirectory, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.sourceCodeDirectory = sourceCodeDirectory;
// this.commandExecutor = commandExecutor;
// }
//
// public void pullUpdatesFromRemoteRepository(BuildLogger buildLogger, String repositoryUrl, String branch) throws IOException {
// log.info(buildLogger.addBuildLogEntry("Pulling source from branch '" + branch + "' @ '" + repositoryUrl + "' into '" + sourceCodeDirectory.getAbsolutePath() + "'."));
//
// String pullOutput = commandExecutor.execute(new String[]{gitExe, "pull", repositoryUrl, branch + ":" + branch}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, pullOutput);
//
// // git submodule commands will silently do nothing if no submodules are configured
// String submoduleInitOutput = commandExecutor.execute(new String[]{gitExe, "submodule", "init"}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, submoduleInitOutput);
//
// String submoduleUpdateOutput = commandExecutor.execute(new String[]{gitExe, "submodule", "update"}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, submoduleUpdateOutput);
// }
//
// private void checkCommandOutput(BuildLogger buildLogger, String repositoryUrl, String output) throws IOException {
// if (output.contains("fatal:")) {
// throw new IOException("Could not pull from '" + repositoryUrl + "'. git-pull: " + output);
// } else {
// log.info(buildLogger.addBuildLogEntry(output));
// }
// }
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitPullCommand; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitPullCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String GIT_EXE = "git";
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
private final BuildLogger buildLogger = mock(BuildLogger.class);
public void testExecuteAPullCommandAgainstTheRemoteBranch() throws IOException {
checking(new Expectations() {{
one(buildLogger).addBuildLogEntry("Pulling source from branch 'some-branch' @ 'gitRepositoryUrl' into '" + SOURCE_CODE_DIRECTORY.getAbsolutePath() + "'.");
one(commandExecutor).execute(new String[]{GIT_EXE, "pull", "gitRepositoryUrl", "some-branch:some-branch"}, SOURCE_CODE_DIRECTORY); will(returnValue("PULL COMMAND OUTPUT"));
one(buildLogger).addBuildLogEntry("PULL COMMAND OUTPUT");
one(commandExecutor).execute(new String[]{GIT_EXE, "submodule", "init"}, SOURCE_CODE_DIRECTORY); will(returnValue("SUBMODULE INIT COMMAND OUTPUT"));
one(buildLogger).addBuildLogEntry("SUBMODULE INIT COMMAND OUTPUT");
one(commandExecutor).execute(new String[]{GIT_EXE, "submodule", "update"}, SOURCE_CODE_DIRECTORY); will(returnValue("SUBMODULE UPDATE COMMAND OUTPUT"));
one(buildLogger).addBuildLogEntry("SUBMODULE UPDATE COMMAND OUTPUT");
}});
| // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitPullCommand.java
// public class ExecutorGitPullCommand implements GitPullCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitPullCommand.class);
//
// private String gitExe;
// private File sourceCodeDirectory;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitPullCommand(String gitExe, File sourceCodeDirectory, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.sourceCodeDirectory = sourceCodeDirectory;
// this.commandExecutor = commandExecutor;
// }
//
// public void pullUpdatesFromRemoteRepository(BuildLogger buildLogger, String repositoryUrl, String branch) throws IOException {
// log.info(buildLogger.addBuildLogEntry("Pulling source from branch '" + branch + "' @ '" + repositoryUrl + "' into '" + sourceCodeDirectory.getAbsolutePath() + "'."));
//
// String pullOutput = commandExecutor.execute(new String[]{gitExe, "pull", repositoryUrl, branch + ":" + branch}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, pullOutput);
//
// // git submodule commands will silently do nothing if no submodules are configured
// String submoduleInitOutput = commandExecutor.execute(new String[]{gitExe, "submodule", "init"}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, submoduleInitOutput);
//
// String submoduleUpdateOutput = commandExecutor.execute(new String[]{gitExe, "submodule", "update"}, sourceCodeDirectory);
// checkCommandOutput(buildLogger, repositoryUrl, submoduleUpdateOutput);
// }
//
// private void checkCommandOutput(BuildLogger buildLogger, String repositoryUrl, String output) throws IOException {
// if (output.contains("fatal:")) {
// throw new IOException("Could not pull from '" + repositoryUrl + "'. git-pull: " + output);
// } else {
// log.info(buildLogger.addBuildLogEntry(output));
// }
// }
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitPullCommandTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitPullCommand;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitPullCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String GIT_EXE = "git";
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
private final BuildLogger buildLogger = mock(BuildLogger.class);
public void testExecuteAPullCommandAgainstTheRemoteBranch() throws IOException {
checking(new Expectations() {{
one(buildLogger).addBuildLogEntry("Pulling source from branch 'some-branch' @ 'gitRepositoryUrl' into '" + SOURCE_CODE_DIRECTORY.getAbsolutePath() + "'.");
one(commandExecutor).execute(new String[]{GIT_EXE, "pull", "gitRepositoryUrl", "some-branch:some-branch"}, SOURCE_CODE_DIRECTORY); will(returnValue("PULL COMMAND OUTPUT"));
one(buildLogger).addBuildLogEntry("PULL COMMAND OUTPUT");
one(commandExecutor).execute(new String[]{GIT_EXE, "submodule", "init"}, SOURCE_CODE_DIRECTORY); will(returnValue("SUBMODULE INIT COMMAND OUTPUT"));
one(buildLogger).addBuildLogEntry("SUBMODULE INIT COMMAND OUTPUT");
one(commandExecutor).execute(new String[]{GIT_EXE, "submodule", "update"}, SOURCE_CODE_DIRECTORY); will(returnValue("SUBMODULE UPDATE COMMAND OUTPUT"));
one(buildLogger).addBuildLogEntry("SUBMODULE UPDATE COMMAND OUTPUT");
}});
| ExecutorGitPullCommand gitPullCommand = new ExecutorGitPullCommand(GIT_EXE, SOURCE_CODE_DIRECTORY, commandExecutor); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/GitHubWebRepositoryViewerTest.java | // Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitFileImpl commitFile(String revision) {
// CommitFileImpl commitFile = new CommitFileImpl("src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java");
// commitFile.setRevision(revision);
// return commitFile;
// }
//
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitImpl commitWithFile(String revision) {
// CommitImpl commit = new CommitImpl();
// commit.addFile(commitFile(revision));
// return commit;
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import java.util.Arrays;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitFile;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitWithFile; | package uk.co.pols.bamboo.gitplugin;
public class GitHubWebRepositoryViewerTest extends MockObjectTestCase {
private GitHubWebRepositoryViewer gitHubWebRepositoryViewer = new GitHubWebRepositoryViewer();
public void testWorksWithTheGitHubRepositoryPlugin() {
assertEquals(Arrays.asList("uk.co.pols.bamboo.gitplugin:github"), gitHubWebRepositoryViewer.getSupportedRepositories());
}
public void testProvidesBambooWithWebUrlAllowingTheCodeChangePageLinkBackToGitHub() {
gitHubWebRepositoryViewer.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin");
| // Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitFileImpl commitFile(String revision) {
// CommitFileImpl commitFile = new CommitFileImpl("src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java");
// commitFile.setRevision(revision);
// return commitFile;
// }
//
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitImpl commitWithFile(String revision) {
// CommitImpl commit = new CommitImpl();
// commit.addFile(commitFile(revision));
// return commit;
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/GitHubWebRepositoryViewerTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import java.util.Arrays;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitFile;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitWithFile;
package uk.co.pols.bamboo.gitplugin;
public class GitHubWebRepositoryViewerTest extends MockObjectTestCase {
private GitHubWebRepositoryViewer gitHubWebRepositoryViewer = new GitHubWebRepositoryViewer();
public void testWorksWithTheGitHubRepositoryPlugin() {
assertEquals(Arrays.asList("uk.co.pols.bamboo.gitplugin:github"), gitHubWebRepositoryViewer.getSupportedRepositories());
}
public void testProvidesBambooWithWebUrlAllowingTheCodeChangePageLinkBackToGitHub() {
gitHubWebRepositoryViewer.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin");
| assertEquals("https://github.com/andypols/git-bamboo-plugin/commit/71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6", gitHubWebRepositoryViewer.getWebRepositoryUrlForCommit(commitWithFile("71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6"), null)); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/GitHubWebRepositoryViewerTest.java | // Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitFileImpl commitFile(String revision) {
// CommitFileImpl commitFile = new CommitFileImpl("src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java");
// commitFile.setRevision(revision);
// return commitFile;
// }
//
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitImpl commitWithFile(String revision) {
// CommitImpl commit = new CommitImpl();
// commit.addFile(commitFile(revision));
// return commit;
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import java.util.Arrays;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitFile;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitWithFile; | package uk.co.pols.bamboo.gitplugin;
public class GitHubWebRepositoryViewerTest extends MockObjectTestCase {
private GitHubWebRepositoryViewer gitHubWebRepositoryViewer = new GitHubWebRepositoryViewer();
public void testWorksWithTheGitHubRepositoryPlugin() {
assertEquals(Arrays.asList("uk.co.pols.bamboo.gitplugin:github"), gitHubWebRepositoryViewer.getSupportedRepositories());
}
public void testProvidesBambooWithWebUrlAllowingTheCodeChangePageLinkBackToGitHub() {
gitHubWebRepositoryViewer.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin");
assertEquals("https://github.com/andypols/git-bamboo-plugin/commit/71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6", gitHubWebRepositoryViewer.getWebRepositoryUrlForCommit(commitWithFile("71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6"), null)); | // Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitFileImpl commitFile(String revision) {
// CommitFileImpl commitFile = new CommitFileImpl("src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java");
// commitFile.setRevision(revision);
// return commitFile;
// }
//
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitImpl commitWithFile(String revision) {
// CommitImpl commit = new CommitImpl();
// commit.addFile(commitFile(revision));
// return commit;
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/GitHubWebRepositoryViewerTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import java.util.Arrays;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitFile;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitWithFile;
package uk.co.pols.bamboo.gitplugin;
public class GitHubWebRepositoryViewerTest extends MockObjectTestCase {
private GitHubWebRepositoryViewer gitHubWebRepositoryViewer = new GitHubWebRepositoryViewer();
public void testWorksWithTheGitHubRepositoryPlugin() {
assertEquals(Arrays.asList("uk.co.pols.bamboo.gitplugin:github"), gitHubWebRepositoryViewer.getSupportedRepositories());
}
public void testProvidesBambooWithWebUrlAllowingTheCodeChangePageLinkBackToGitHub() {
gitHubWebRepositoryViewer.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin");
assertEquals("https://github.com/andypols/git-bamboo-plugin/commit/71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6", gitHubWebRepositoryViewer.getWebRepositoryUrlForCommit(commitWithFile("71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6"), null)); | assertEquals("https://github.com/andypols/git-bamboo-plugin/blob/71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6/src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java", gitHubWebRepositoryViewer.getWebRepositoryUrlForFile(commitFile("71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6"))); |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/Git.java
// public interface Git {
//
// boolean isValidRepo(File sourceDirectory);
//
// GitCloneCommand repositoryClone();
//
// GitCheckoutCommand checkout();
//
// GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked);
//
// GitPullCommand pull(File sourceCodeDirectory);
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogCommand.java
// public interface GitLogCommand {
// List<Commit> extractCommits() throws IOException;
//
// String getLastRevisionChecked();
// }
| import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.repository.RepositoryException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import uk.co.pols.bamboo.gitplugin.client.git.Git;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogCommand;
import java.io.File;
import java.io.IOException;
import java.util.List; | package uk.co.pols.bamboo.gitplugin.client;
public class CmdLineGitClient implements GitClient {
private static final Log log = LogFactory.getLog(CmdLineGitClient.class); | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/Git.java
// public interface Git {
//
// boolean isValidRepo(File sourceDirectory);
//
// GitCloneCommand repositoryClone();
//
// GitCheckoutCommand checkout();
//
// GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked);
//
// GitPullCommand pull(File sourceCodeDirectory);
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogCommand.java
// public interface GitLogCommand {
// List<Commit> extractCommits() throws IOException;
//
// String getLastRevisionChecked();
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.repository.RepositoryException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import uk.co.pols.bamboo.gitplugin.client.git.Git;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogCommand;
import java.io.File;
import java.io.IOException;
import java.util.List;
package uk.co.pols.bamboo.gitplugin.client;
public class CmdLineGitClient implements GitClient {
private static final Log log = LogFactory.getLog(CmdLineGitClient.class); | private Git git; |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/Git.java
// public interface Git {
//
// boolean isValidRepo(File sourceDirectory);
//
// GitCloneCommand repositoryClone();
//
// GitCheckoutCommand checkout();
//
// GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked);
//
// GitPullCommand pull(File sourceCodeDirectory);
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogCommand.java
// public interface GitLogCommand {
// List<Commit> extractCommits() throws IOException;
//
// String getLastRevisionChecked();
// }
| import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.repository.RepositoryException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import uk.co.pols.bamboo.gitplugin.client.git.Git;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogCommand;
import java.io.File;
import java.io.IOException;
import java.util.List; | package uk.co.pols.bamboo.gitplugin.client;
public class CmdLineGitClient implements GitClient {
private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
private Git git;
public CmdLineGitClient(Git git) {
this.git = git;
}
public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
try {
if (!git.isValidRepo(sourceCodeDirectory)) {
initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
} else {
git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
}
git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
| // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/Git.java
// public interface Git {
//
// boolean isValidRepo(File sourceDirectory);
//
// GitCloneCommand repositoryClone();
//
// GitCheckoutCommand checkout();
//
// GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked);
//
// GitPullCommand pull(File sourceCodeDirectory);
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogCommand.java
// public interface GitLogCommand {
// List<Commit> extractCommits() throws IOException;
//
// String getLastRevisionChecked();
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.repository.RepositoryException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import uk.co.pols.bamboo.gitplugin.client.git.Git;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogCommand;
import java.io.File;
import java.io.IOException;
import java.util.List;
package uk.co.pols.bamboo.gitplugin.client;
public class CmdLineGitClient implements GitClient {
private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
private Git git;
public CmdLineGitClient(Git git) {
this.git = git;
}
public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
try {
if (!git.isValidRepo(sourceCodeDirectory)) {
initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
} else {
git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
}
git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
| GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/utils/CharUtilTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/utils/CharUtil.java
// public class CharUtil {
//
// /**
// * Converts byte array to char array.
// */
// public static char[] toCharArray(byte[] barr) {
// if (barr == null) {
// return null;
// }
// char[] carr = new char[barr.length];
// for (int i = 0; i < barr.length; i++) {
// carr[i] = (char) barr[i];
// }
// return carr;
// }
// }
| import junit.framework.TestCase;
import uk.co.pols.bamboo.gitplugin.client.utils.CharUtil; | package uk.co.pols.bamboo.gitplugin.client.utils;
public class CharUtilTest extends TestCase {
private static final String TEST_STRING = "Test ...";
public void testConvertsAByteArrayIntoACharacterArray() {
assertEqualArrays(
new char[] { 'T', 'e', 's', 't', ' ', '.', '.', '.'}, | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/utils/CharUtil.java
// public class CharUtil {
//
// /**
// * Converts byte array to char array.
// */
// public static char[] toCharArray(byte[] barr) {
// if (barr == null) {
// return null;
// }
// char[] carr = new char[barr.length];
// for (int i = 0; i < barr.length; i++) {
// carr[i] = (char) barr[i];
// }
// return carr;
// }
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/utils/CharUtilTest.java
import junit.framework.TestCase;
import uk.co.pols.bamboo.gitplugin.client.utils.CharUtil;
package uk.co.pols.bamboo.gitplugin.client.utils;
public class CharUtilTest extends TestCase {
private static final String TEST_STRING = "Test ...";
public void testConvertsAByteArrayIntoACharacterArray() {
assertEqualArrays(
new char[] { 'T', 'e', 's', 't', ' ', '.', '.', '.'}, | CharUtil.toCharArray(TEST_STRING.getBytes()) |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/GitClient.java
// public interface GitClient {
//
// String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/CmdLineGit.java
// public class CmdLineGit implements Git {
// private GitCommandDiscoverer gitCommandDiscoverer = gitCommandDiscoverer();
//
// public boolean isValidRepo(File sourceDirectory) {
// return new FileBasedGitRepositoryDetector().containsValidRepo(sourceDirectory);
// }
//
// public GitPullCommand pull(File sourceCodeDirectory) {
// return new ExecutorGitPullCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, new AntCommandExecutor());
// }
//
// public GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked) {
// return new ExecutorGitLogCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, lastRevisionChecked, new AntCommandExecutor());
// }
//
// public GitCloneCommand repositoryClone() {
// return new ExecutorGitCloneCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// public GitCheckoutCommand checkout() {
// return new ExecutorGitCheckoutCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// private GitCommandDiscoverer gitCommandDiscoverer() {
// return new BestGuessGitCommandDiscoverer(new AntCommandExecutor());
// }
// }
| import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.v2.build.BuildChanges;
import com.atlassian.bamboo.v2.build.BuildChangesImpl;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.GitClient;
import uk.co.pols.bamboo.gitplugin.client.git.CmdLineGit;
import java.util.ArrayList;
import java.util.List;
import static com.atlassian.bamboo.plan.PlanKeys.getPlanKey;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.REPOSITORY; |
@Override
public int hashCode() {
return new HashCodeBuilder(101, 11)
.append(getKey())
.append(getRepositoryUrl())
.append(getTriggerIpAddress())
.toHashCode();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof GitRepository)) {
return false;
}
GitRepository rhs = (GitRepository) o;
return new EqualsBuilder()
.append(getRepositoryUrl(), rhs.getRepositoryUrl())
.append(getTriggerIpAddress(), rhs.getTriggerIpAddress())
.isEquals();
}
public int compareTo(Object obj) {
GitRepository o = (GitRepository) obj;
return new CompareToBuilder()
.append(getRepositoryUrl(), o.getRepositoryUrl())
.append(getTriggerIpAddress(), o.getTriggerIpAddress())
.toComparison();
}
| // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/GitClient.java
// public interface GitClient {
//
// String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/CmdLineGit.java
// public class CmdLineGit implements Git {
// private GitCommandDiscoverer gitCommandDiscoverer = gitCommandDiscoverer();
//
// public boolean isValidRepo(File sourceDirectory) {
// return new FileBasedGitRepositoryDetector().containsValidRepo(sourceDirectory);
// }
//
// public GitPullCommand pull(File sourceCodeDirectory) {
// return new ExecutorGitPullCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, new AntCommandExecutor());
// }
//
// public GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked) {
// return new ExecutorGitLogCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, lastRevisionChecked, new AntCommandExecutor());
// }
//
// public GitCloneCommand repositoryClone() {
// return new ExecutorGitCloneCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// public GitCheckoutCommand checkout() {
// return new ExecutorGitCheckoutCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// private GitCommandDiscoverer gitCommandDiscoverer() {
// return new BestGuessGitCommandDiscoverer(new AntCommandExecutor());
// }
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.v2.build.BuildChanges;
import com.atlassian.bamboo.v2.build.BuildChangesImpl;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.GitClient;
import uk.co.pols.bamboo.gitplugin.client.git.CmdLineGit;
import java.util.ArrayList;
import java.util.List;
import static com.atlassian.bamboo.plan.PlanKeys.getPlanKey;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.REPOSITORY;
@Override
public int hashCode() {
return new HashCodeBuilder(101, 11)
.append(getKey())
.append(getRepositoryUrl())
.append(getTriggerIpAddress())
.toHashCode();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof GitRepository)) {
return false;
}
GitRepository rhs = (GitRepository) o;
return new EqualsBuilder()
.append(getRepositoryUrl(), rhs.getRepositoryUrl())
.append(getTriggerIpAddress(), rhs.getTriggerIpAddress())
.isEquals();
}
public int compareTo(Object obj) {
GitRepository o = (GitRepository) obj;
return new CompareToBuilder()
.append(getRepositoryUrl(), o.getRepositoryUrl())
.append(getTriggerIpAddress(), o.getTriggerIpAddress())
.toComparison();
}
| protected GitClient gitClient() { |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/GitClient.java
// public interface GitClient {
//
// String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/CmdLineGit.java
// public class CmdLineGit implements Git {
// private GitCommandDiscoverer gitCommandDiscoverer = gitCommandDiscoverer();
//
// public boolean isValidRepo(File sourceDirectory) {
// return new FileBasedGitRepositoryDetector().containsValidRepo(sourceDirectory);
// }
//
// public GitPullCommand pull(File sourceCodeDirectory) {
// return new ExecutorGitPullCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, new AntCommandExecutor());
// }
//
// public GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked) {
// return new ExecutorGitLogCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, lastRevisionChecked, new AntCommandExecutor());
// }
//
// public GitCloneCommand repositoryClone() {
// return new ExecutorGitCloneCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// public GitCheckoutCommand checkout() {
// return new ExecutorGitCheckoutCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// private GitCommandDiscoverer gitCommandDiscoverer() {
// return new BestGuessGitCommandDiscoverer(new AntCommandExecutor());
// }
// }
| import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.v2.build.BuildChanges;
import com.atlassian.bamboo.v2.build.BuildChangesImpl;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.GitClient;
import uk.co.pols.bamboo.gitplugin.client.git.CmdLineGit;
import java.util.ArrayList;
import java.util.List;
import static com.atlassian.bamboo.plan.PlanKeys.getPlanKey;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.REPOSITORY; | @Override
public int hashCode() {
return new HashCodeBuilder(101, 11)
.append(getKey())
.append(getRepositoryUrl())
.append(getTriggerIpAddress())
.toHashCode();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof GitRepository)) {
return false;
}
GitRepository rhs = (GitRepository) o;
return new EqualsBuilder()
.append(getRepositoryUrl(), rhs.getRepositoryUrl())
.append(getTriggerIpAddress(), rhs.getTriggerIpAddress())
.isEquals();
}
public int compareTo(Object obj) {
GitRepository o = (GitRepository) obj;
return new CompareToBuilder()
.append(getRepositoryUrl(), o.getRepositoryUrl())
.append(getTriggerIpAddress(), o.getTriggerIpAddress())
.toComparison();
}
protected GitClient gitClient() { | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/GitClient.java
// public interface GitClient {
//
// String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/CmdLineGit.java
// public class CmdLineGit implements Git {
// private GitCommandDiscoverer gitCommandDiscoverer = gitCommandDiscoverer();
//
// public boolean isValidRepo(File sourceDirectory) {
// return new FileBasedGitRepositoryDetector().containsValidRepo(sourceDirectory);
// }
//
// public GitPullCommand pull(File sourceCodeDirectory) {
// return new ExecutorGitPullCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, new AntCommandExecutor());
// }
//
// public GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked) {
// return new ExecutorGitLogCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, lastRevisionChecked, new AntCommandExecutor());
// }
//
// public GitCloneCommand repositoryClone() {
// return new ExecutorGitCloneCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// public GitCheckoutCommand checkout() {
// return new ExecutorGitCheckoutCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// private GitCommandDiscoverer gitCommandDiscoverer() {
// return new BestGuessGitCommandDiscoverer(new AntCommandExecutor());
// }
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.v2.build.BuildChanges;
import com.atlassian.bamboo.v2.build.BuildChangesImpl;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.GitClient;
import uk.co.pols.bamboo.gitplugin.client.git.CmdLineGit;
import java.util.ArrayList;
import java.util.List;
import static com.atlassian.bamboo.plan.PlanKeys.getPlanKey;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.REPOSITORY;
@Override
public int hashCode() {
return new HashCodeBuilder(101, 11)
.append(getKey())
.append(getRepositoryUrl())
.append(getTriggerIpAddress())
.toHashCode();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof GitRepository)) {
return false;
}
GitRepository rhs = (GitRepository) o;
return new EqualsBuilder()
.append(getRepositoryUrl(), rhs.getRepositoryUrl())
.append(getTriggerIpAddress(), rhs.getTriggerIpAddress())
.isEquals();
}
public int compareTo(Object obj) {
GitRepository o = (GitRepository) obj;
return new CompareToBuilder()
.append(getRepositoryUrl(), o.getRepositoryUrl())
.append(getTriggerIpAddress(), o.getTriggerIpAddress())
.toComparison();
}
protected GitClient gitClient() { | return new CmdLineGitClient(new CmdLineGit()); |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/GitClient.java
// public interface GitClient {
//
// String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/CmdLineGit.java
// public class CmdLineGit implements Git {
// private GitCommandDiscoverer gitCommandDiscoverer = gitCommandDiscoverer();
//
// public boolean isValidRepo(File sourceDirectory) {
// return new FileBasedGitRepositoryDetector().containsValidRepo(sourceDirectory);
// }
//
// public GitPullCommand pull(File sourceCodeDirectory) {
// return new ExecutorGitPullCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, new AntCommandExecutor());
// }
//
// public GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked) {
// return new ExecutorGitLogCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, lastRevisionChecked, new AntCommandExecutor());
// }
//
// public GitCloneCommand repositoryClone() {
// return new ExecutorGitCloneCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// public GitCheckoutCommand checkout() {
// return new ExecutorGitCheckoutCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// private GitCommandDiscoverer gitCommandDiscoverer() {
// return new BestGuessGitCommandDiscoverer(new AntCommandExecutor());
// }
// }
| import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.v2.build.BuildChanges;
import com.atlassian.bamboo.v2.build.BuildChangesImpl;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.GitClient;
import uk.co.pols.bamboo.gitplugin.client.git.CmdLineGit;
import java.util.ArrayList;
import java.util.List;
import static com.atlassian.bamboo.plan.PlanKeys.getPlanKey;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.REPOSITORY; | @Override
public int hashCode() {
return new HashCodeBuilder(101, 11)
.append(getKey())
.append(getRepositoryUrl())
.append(getTriggerIpAddress())
.toHashCode();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof GitRepository)) {
return false;
}
GitRepository rhs = (GitRepository) o;
return new EqualsBuilder()
.append(getRepositoryUrl(), rhs.getRepositoryUrl())
.append(getTriggerIpAddress(), rhs.getTriggerIpAddress())
.isEquals();
}
public int compareTo(Object obj) {
GitRepository o = (GitRepository) obj;
return new CompareToBuilder()
.append(getRepositoryUrl(), o.getRepositoryUrl())
.append(getTriggerIpAddress(), o.getTriggerIpAddress())
.toComparison();
}
protected GitClient gitClient() { | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/CmdLineGitClient.java
// public class CmdLineGitClient implements GitClient {
// private static final Log log = LogFactory.getLog(CmdLineGitClient.class);
// private Git git;
//
// public CmdLineGitClient(Git git) {
// this.git = git;
// }
//
// public String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException {
// try {
// if (!git.isValidRepo(sourceCodeDirectory)) {
// initialiseRemoteRepository(sourceCodeDirectory, repositoryUrl, branch, buildLogger);
// } else {
// git.checkout().checkoutBranch(buildLogger, branch, false, sourceCodeDirectory);
// }
//
// git.pull(sourceCodeDirectory).pullUpdatesFromRemoteRepository(buildLogger, repositoryUrl, branch);
//
// GitLogCommand gitLogCommand = git.log(sourceCodeDirectory, lastRevisionChecked);
// List<Commit> gitCommits = gitLogCommand.extractCommits();
// String latestRevisionOnServer = gitLogCommand.getLastRevisionChecked();
//
// if (lastRevisionChecked == null) {
// log.info(buildLogger.addBuildLogEntry("Never checked logs for '" + planKey + "' on path '" + repositoryUrl + "' setting latest revision to " + latestRevisionOnServer));
// return latestRevisionOnServer;
// }
// if (!lastRevisionChecked.equals(latestRevisionOnServer)) {
// log.info(buildLogger.addBuildLogEntry("Collecting changes for '" + planKey + "' on path '" + repositoryUrl + "' since " + lastRevisionChecked));
// commits.addAll(gitCommits);
// }
//
// return latestRevisionOnServer;
// } catch (IOException e) {
// throw new RepositoryException("Failed to get latest update", e);
// }
// }
//
// private void initialiseRemoteRepository(File sourceDirectory, String repositoryUrl, String branch, BuildLogger buildLogger) throws RepositoryException {
// log.info(buildLogger.addBuildLogEntry(sourceDirectory.getAbsolutePath() + " is empty. Creating new git repository"));
// try {
// git.repositoryClone().cloneUrl(buildLogger, repositoryUrl, sourceDirectory);
// git.checkout().checkoutBranch(buildLogger, branch, true, sourceDirectory);
// } catch (IOException e) {
// throw new RepositoryException("Failed to initialise repository", e);
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/GitClient.java
// public interface GitClient {
//
// String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/CmdLineGit.java
// public class CmdLineGit implements Git {
// private GitCommandDiscoverer gitCommandDiscoverer = gitCommandDiscoverer();
//
// public boolean isValidRepo(File sourceDirectory) {
// return new FileBasedGitRepositoryDetector().containsValidRepo(sourceDirectory);
// }
//
// public GitPullCommand pull(File sourceCodeDirectory) {
// return new ExecutorGitPullCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, new AntCommandExecutor());
// }
//
// public GitLogCommand log(File sourceCodeDirectory, String lastRevisionChecked) {
// return new ExecutorGitLogCommand(gitCommandDiscoverer.gitCommand(), sourceCodeDirectory, lastRevisionChecked, new AntCommandExecutor());
// }
//
// public GitCloneCommand repositoryClone() {
// return new ExecutorGitCloneCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// public GitCheckoutCommand checkout() {
// return new ExecutorGitCheckoutCommand(gitCommandDiscoverer.gitCommand(), new AntCommandExecutor());
// }
//
// private GitCommandDiscoverer gitCommandDiscoverer() {
// return new BestGuessGitCommandDiscoverer(new AntCommandExecutor());
// }
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.v2.build.BuildChanges;
import com.atlassian.bamboo.v2.build.BuildChangesImpl;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import uk.co.pols.bamboo.gitplugin.client.CmdLineGitClient;
import uk.co.pols.bamboo.gitplugin.client.GitClient;
import uk.co.pols.bamboo.gitplugin.client.git.CmdLineGit;
import java.util.ArrayList;
import java.util.List;
import static com.atlassian.bamboo.plan.PlanKeys.getPlanKey;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.REPOSITORY;
@Override
public int hashCode() {
return new HashCodeBuilder(101, 11)
.append(getKey())
.append(getRepositoryUrl())
.append(getTriggerIpAddress())
.toHashCode();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof GitRepository)) {
return false;
}
GitRepository rhs = (GitRepository) o;
return new EqualsBuilder()
.append(getRepositoryUrl(), rhs.getRepositoryUrl())
.append(getTriggerIpAddress(), rhs.getTriggerIpAddress())
.isEquals();
}
public int compareTo(Object obj) {
GitRepository o = (GitRepository) obj;
return new CompareToBuilder()
.append(getRepositoryUrl(), o.getRepositoryUrl())
.append(getTriggerIpAddress(), o.getTriggerIpAddress())
.toComparison();
}
protected GitClient gitClient() { | return new CmdLineGitClient(new CmdLineGit()); |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/client/git/CmdLineGit.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/utils/FileBasedGitRepositoryDetector.java
// public class FileBasedGitRepositoryDetector implements GitRepositoryDetector {
// public boolean containsValidRepo(File sourceDir) {
// try {
// return sourceDir.exists() && (new File(sourceDir.getCanonicalPath() + File.separator + ".git").exists() || new File(sourceDir.getCanonicalPath() + File.separator + "HEAD").exists());
// } catch (IOException e) {
// return false;
// }
// }
// }
| import uk.co.pols.bamboo.gitplugin.client.git.commands.*;
import uk.co.pols.bamboo.gitplugin.client.utils.FileBasedGitRepositoryDetector;
import java.io.File; | package uk.co.pols.bamboo.gitplugin.client.git;
public class CmdLineGit implements Git {
private GitCommandDiscoverer gitCommandDiscoverer = gitCommandDiscoverer();
public boolean isValidRepo(File sourceDirectory) { | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/utils/FileBasedGitRepositoryDetector.java
// public class FileBasedGitRepositoryDetector implements GitRepositoryDetector {
// public boolean containsValidRepo(File sourceDir) {
// try {
// return sourceDir.exists() && (new File(sourceDir.getCanonicalPath() + File.separator + ".git").exists() || new File(sourceDir.getCanonicalPath() + File.separator + "HEAD").exists());
// } catch (IOException e) {
// return false;
// }
// }
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/CmdLineGit.java
import uk.co.pols.bamboo.gitplugin.client.git.commands.*;
import uk.co.pols.bamboo.gitplugin.client.utils.FileBasedGitRepositoryDetector;
import java.io.File;
package uk.co.pols.bamboo.gitplugin.client.git;
public class CmdLineGit implements Git {
private GitCommandDiscoverer gitCommandDiscoverer = gitCommandDiscoverer();
public boolean isValidRepo(File sourceDirectory) { | return new FileBasedGitRepositoryDetector().containsValidRepo(sourceDirectory); |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitPullCommand.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
| import com.atlassian.bamboo.build.logger.BuildLogger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitPullCommand implements GitPullCommand {
private static final Log log = LogFactory.getLog(ExecutorGitPullCommand.class);
private String gitExe;
private File sourceCodeDirectory; | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitPullCommand.java
import com.atlassian.bamboo.build.logger.BuildLogger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitPullCommand implements GitPullCommand {
private static final Log log = LogFactory.getLog(ExecutorGitPullCommand.class);
private String gitExe;
private File sourceCodeDirectory; | private CommandExecutor commandExecutor; |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/GitRepositoryConfigTest.java | // Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitFileImpl commitFile(String revision) {
// CommitFileImpl commitFile = new CommitFileImpl("src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java");
// commitFile.setRevision(revision);
// return commitFile;
// }
//
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitImpl commitWithFile(String revision) {
// CommitImpl commit = new CommitImpl();
// commit.addFile(commitFile(revision));
// return commit;
// }
| import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.utils.error.SimpleErrorCollection;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.jmock.integration.junit3.MockObjectTestCase;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.REPOSITORY;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.WEB_REPOSITORY;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitFile;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitWithFile; | repositoryConfig.addDefaultValues(buildConfiguration, REPOSITORY);
assertEquals("master", buildConfiguration.getProperty(GitRepositoryConfig.GIT_BRANCH));
}
public void testTrimsWhiteSpaceOffTheRepositoryUrl() {
repositoryConfig.setRepositoryUrl(" git@github.com:andypols/git-bamboo-plugin.git ");
assertEquals("git@github.com:andypols/git-bamboo-plugin.git", repositoryConfig.getRepositoryUrl());
}
public void testTrimsWhiteSpaceOffTheWebRepositoryUrl() {
repositoryConfig.setWebRepositoryUrl(" https://github.com/andypols/git-bamboo-plugin/tree/master ");
assertEquals("https://github.com/andypols/git-bamboo-plugin/tree/master", repositoryConfig.getWebRepositoryUrl());
}
public void testHasWebBasedRepositoryAccessIfTheUserHasSpecifiedTheWebUrl() {
repositoryConfig.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin/tree/master");
assertTrue(repositoryConfig.hasWebBasedRepositoryAccess());
}
public void testDoesNotHaveWebBasedRepositoryAccessIfTheUserHasSpecifiedTheWebUrl() {
assertFalse(repositoryConfig.hasWebBasedRepositoryAccess());
}
public void testDerivesTheTheCommitUrlFromTheRepositoryUrl() {
repositoryConfig.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin");
| // Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitFileImpl commitFile(String revision) {
// CommitFileImpl commitFile = new CommitFileImpl("src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java");
// commitFile.setRevision(revision);
// return commitFile;
// }
//
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitImpl commitWithFile(String revision) {
// CommitImpl commit = new CommitImpl();
// commit.addFile(commitFile(revision));
// return commit;
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/GitRepositoryConfigTest.java
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.utils.error.SimpleErrorCollection;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.jmock.integration.junit3.MockObjectTestCase;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.REPOSITORY;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.WEB_REPOSITORY;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitFile;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitWithFile;
repositoryConfig.addDefaultValues(buildConfiguration, REPOSITORY);
assertEquals("master", buildConfiguration.getProperty(GitRepositoryConfig.GIT_BRANCH));
}
public void testTrimsWhiteSpaceOffTheRepositoryUrl() {
repositoryConfig.setRepositoryUrl(" git@github.com:andypols/git-bamboo-plugin.git ");
assertEquals("git@github.com:andypols/git-bamboo-plugin.git", repositoryConfig.getRepositoryUrl());
}
public void testTrimsWhiteSpaceOffTheWebRepositoryUrl() {
repositoryConfig.setWebRepositoryUrl(" https://github.com/andypols/git-bamboo-plugin/tree/master ");
assertEquals("https://github.com/andypols/git-bamboo-plugin/tree/master", repositoryConfig.getWebRepositoryUrl());
}
public void testHasWebBasedRepositoryAccessIfTheUserHasSpecifiedTheWebUrl() {
repositoryConfig.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin/tree/master");
assertTrue(repositoryConfig.hasWebBasedRepositoryAccess());
}
public void testDoesNotHaveWebBasedRepositoryAccessIfTheUserHasSpecifiedTheWebUrl() {
assertFalse(repositoryConfig.hasWebBasedRepositoryAccess());
}
public void testDerivesTheTheCommitUrlFromTheRepositoryUrl() {
repositoryConfig.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin");
| assertEquals("https://github.com/andypols/git-bamboo-plugin/commit/71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6", repositoryConfig.getWebRepositoryUrlForCommit(commitWithFile("71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6"))); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/GitRepositoryConfigTest.java | // Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitFileImpl commitFile(String revision) {
// CommitFileImpl commitFile = new CommitFileImpl("src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java");
// commitFile.setRevision(revision);
// return commitFile;
// }
//
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitImpl commitWithFile(String revision) {
// CommitImpl commit = new CommitImpl();
// commit.addFile(commitFile(revision));
// return commit;
// }
| import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.utils.error.SimpleErrorCollection;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.jmock.integration.junit3.MockObjectTestCase;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.REPOSITORY;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.WEB_REPOSITORY;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitFile;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitWithFile; | repositoryConfig.setRepositoryUrl(" git@github.com:andypols/git-bamboo-plugin.git ");
assertEquals("git@github.com:andypols/git-bamboo-plugin.git", repositoryConfig.getRepositoryUrl());
}
public void testTrimsWhiteSpaceOffTheWebRepositoryUrl() {
repositoryConfig.setWebRepositoryUrl(" https://github.com/andypols/git-bamboo-plugin/tree/master ");
assertEquals("https://github.com/andypols/git-bamboo-plugin/tree/master", repositoryConfig.getWebRepositoryUrl());
}
public void testHasWebBasedRepositoryAccessIfTheUserHasSpecifiedTheWebUrl() {
repositoryConfig.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin/tree/master");
assertTrue(repositoryConfig.hasWebBasedRepositoryAccess());
}
public void testDoesNotHaveWebBasedRepositoryAccessIfTheUserHasSpecifiedTheWebUrl() {
assertFalse(repositoryConfig.hasWebBasedRepositoryAccess());
}
public void testDerivesTheTheCommitUrlFromTheRepositoryUrl() {
repositoryConfig.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin");
assertEquals("https://github.com/andypols/git-bamboo-plugin/commit/71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6", repositoryConfig.getWebRepositoryUrlForCommit(commitWithFile("71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6")));
}
public void testDerivesTheTheCommitFileUrlFromTheRepositoryUrl() {
repositoryConfig.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin");
| // Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitFileImpl commitFile(String revision) {
// CommitFileImpl commitFile = new CommitFileImpl("src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java");
// commitFile.setRevision(revision);
// return commitFile;
// }
//
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/SampleCommitFactory.java
// public static CommitImpl commitWithFile(String revision) {
// CommitImpl commit = new CommitImpl();
// commit.addFile(commitFile(revision));
// return commit;
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/GitRepositoryConfigTest.java
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.atlassian.bamboo.utils.error.SimpleErrorCollection;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.jmock.integration.junit3.MockObjectTestCase;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.REPOSITORY;
import static uk.co.pols.bamboo.gitplugin.GitRepositoryConfig.AvailableConfig.WEB_REPOSITORY;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitFile;
import static uk.co.pols.bamboo.gitplugin.SampleCommitFactory.commitWithFile;
repositoryConfig.setRepositoryUrl(" git@github.com:andypols/git-bamboo-plugin.git ");
assertEquals("git@github.com:andypols/git-bamboo-plugin.git", repositoryConfig.getRepositoryUrl());
}
public void testTrimsWhiteSpaceOffTheWebRepositoryUrl() {
repositoryConfig.setWebRepositoryUrl(" https://github.com/andypols/git-bamboo-plugin/tree/master ");
assertEquals("https://github.com/andypols/git-bamboo-plugin/tree/master", repositoryConfig.getWebRepositoryUrl());
}
public void testHasWebBasedRepositoryAccessIfTheUserHasSpecifiedTheWebUrl() {
repositoryConfig.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin/tree/master");
assertTrue(repositoryConfig.hasWebBasedRepositoryAccess());
}
public void testDoesNotHaveWebBasedRepositoryAccessIfTheUserHasSpecifiedTheWebUrl() {
assertFalse(repositoryConfig.hasWebBasedRepositoryAccess());
}
public void testDerivesTheTheCommitUrlFromTheRepositoryUrl() {
repositoryConfig.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin");
assertEquals("https://github.com/andypols/git-bamboo-plugin/commit/71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6", repositoryConfig.getWebRepositoryUrlForCommit(commitWithFile("71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6")));
}
public void testDerivesTheTheCommitFileUrlFromTheRepositoryUrl() {
repositoryConfig.setWebRepositoryUrl("https://github.com/andypols/git-bamboo-plugin");
| assertEquals("https://github.com/andypols/git-bamboo-plugin/blob/71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6/src/main/java/uk/co/pols/bamboo/gitplugin/GitRepository.java", repositoryConfig.getWebRepositoryUrlForFile(commitFile("71b2bf41fb82a12ca3d4d34bd62568d9167dc6d6"))); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommandTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommand.java
// public class ExecutorGitLogCommand implements GitLogCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitLogCommand.class);
//
// private String gitExe;
// private File sourceCodeDirectory;
// private String lastRevisionChecked;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitLogCommand(String gitExe, File sourceCodeDirectory, String lastRevisionChecked, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.sourceCodeDirectory = sourceCodeDirectory;
// this.lastRevisionChecked = "null".equals(lastRevisionChecked) ? null : lastRevisionChecked;
// this.commandExecutor = commandExecutor;
// }
//
// public List<Commit> extractCommits() throws IOException {
// String logText = commandExecutor.execute(getCommandLine(), sourceCodeDirectory);
//
// log.info(logText);
// GitLogParser logParser = new GitLogParser(logText);
//
// List<Commit> commits = logParser.extractCommits(lastRevisionChecked);
// lastRevisionChecked = logParser.getMostRecentCommitDate();
//
// return commits;
// }
//
// public String getLastRevisionChecked() {
// return lastRevisionChecked;
// }
//
// private String[] getCommandLine() {
// if (lastRevisionChecked == null) {
// return new String[]{gitExe, "log", "-1", "--numstat", "--date=iso8601"};
// }
// return new String[]{gitExe, "log", "--numstat", "--date=iso8601", "--since=\"" + lastRevisionChecked + "\""};
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogCommand.java
// public interface GitLogCommand {
// List<Commit> extractCommits() throws IOException;
//
// String getLastRevisionChecked();
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import java.util.List;
import com.atlassian.bamboo.commit.Commit;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitLogCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogCommand; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitLogCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String DATE_OF_LAST_BUILD = "2009-03-13 01:24:44 +0000";
private static final String GIT_EXE = "git";
| // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommand.java
// public class ExecutorGitLogCommand implements GitLogCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitLogCommand.class);
//
// private String gitExe;
// private File sourceCodeDirectory;
// private String lastRevisionChecked;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitLogCommand(String gitExe, File sourceCodeDirectory, String lastRevisionChecked, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.sourceCodeDirectory = sourceCodeDirectory;
// this.lastRevisionChecked = "null".equals(lastRevisionChecked) ? null : lastRevisionChecked;
// this.commandExecutor = commandExecutor;
// }
//
// public List<Commit> extractCommits() throws IOException {
// String logText = commandExecutor.execute(getCommandLine(), sourceCodeDirectory);
//
// log.info(logText);
// GitLogParser logParser = new GitLogParser(logText);
//
// List<Commit> commits = logParser.extractCommits(lastRevisionChecked);
// lastRevisionChecked = logParser.getMostRecentCommitDate();
//
// return commits;
// }
//
// public String getLastRevisionChecked() {
// return lastRevisionChecked;
// }
//
// private String[] getCommandLine() {
// if (lastRevisionChecked == null) {
// return new String[]{gitExe, "log", "-1", "--numstat", "--date=iso8601"};
// }
// return new String[]{gitExe, "log", "--numstat", "--date=iso8601", "--since=\"" + lastRevisionChecked + "\""};
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogCommand.java
// public interface GitLogCommand {
// List<Commit> extractCommits() throws IOException;
//
// String getLastRevisionChecked();
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommandTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import java.util.List;
import com.atlassian.bamboo.commit.Commit;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitLogCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogCommand;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitLogCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String DATE_OF_LAST_BUILD = "2009-03-13 01:24:44 +0000";
private static final String GIT_EXE = "git";
| private final CommandExecutor commandExecutor = mock(CommandExecutor.class); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommandTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommand.java
// public class ExecutorGitLogCommand implements GitLogCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitLogCommand.class);
//
// private String gitExe;
// private File sourceCodeDirectory;
// private String lastRevisionChecked;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitLogCommand(String gitExe, File sourceCodeDirectory, String lastRevisionChecked, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.sourceCodeDirectory = sourceCodeDirectory;
// this.lastRevisionChecked = "null".equals(lastRevisionChecked) ? null : lastRevisionChecked;
// this.commandExecutor = commandExecutor;
// }
//
// public List<Commit> extractCommits() throws IOException {
// String logText = commandExecutor.execute(getCommandLine(), sourceCodeDirectory);
//
// log.info(logText);
// GitLogParser logParser = new GitLogParser(logText);
//
// List<Commit> commits = logParser.extractCommits(lastRevisionChecked);
// lastRevisionChecked = logParser.getMostRecentCommitDate();
//
// return commits;
// }
//
// public String getLastRevisionChecked() {
// return lastRevisionChecked;
// }
//
// private String[] getCommandLine() {
// if (lastRevisionChecked == null) {
// return new String[]{gitExe, "log", "-1", "--numstat", "--date=iso8601"};
// }
// return new String[]{gitExe, "log", "--numstat", "--date=iso8601", "--since=\"" + lastRevisionChecked + "\""};
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogCommand.java
// public interface GitLogCommand {
// List<Commit> extractCommits() throws IOException;
//
// String getLastRevisionChecked();
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import java.util.List;
import com.atlassian.bamboo.commit.Commit;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitLogCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogCommand; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitLogCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String DATE_OF_LAST_BUILD = "2009-03-13 01:24:44 +0000";
private static final String GIT_EXE = "git";
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
public void testGetsTheMostRecentLogItemIfNotCheckedLogBefore() throws IOException { | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommand.java
// public class ExecutorGitLogCommand implements GitLogCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitLogCommand.class);
//
// private String gitExe;
// private File sourceCodeDirectory;
// private String lastRevisionChecked;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitLogCommand(String gitExe, File sourceCodeDirectory, String lastRevisionChecked, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.sourceCodeDirectory = sourceCodeDirectory;
// this.lastRevisionChecked = "null".equals(lastRevisionChecked) ? null : lastRevisionChecked;
// this.commandExecutor = commandExecutor;
// }
//
// public List<Commit> extractCommits() throws IOException {
// String logText = commandExecutor.execute(getCommandLine(), sourceCodeDirectory);
//
// log.info(logText);
// GitLogParser logParser = new GitLogParser(logText);
//
// List<Commit> commits = logParser.extractCommits(lastRevisionChecked);
// lastRevisionChecked = logParser.getMostRecentCommitDate();
//
// return commits;
// }
//
// public String getLastRevisionChecked() {
// return lastRevisionChecked;
// }
//
// private String[] getCommandLine() {
// if (lastRevisionChecked == null) {
// return new String[]{gitExe, "log", "-1", "--numstat", "--date=iso8601"};
// }
// return new String[]{gitExe, "log", "--numstat", "--date=iso8601", "--since=\"" + lastRevisionChecked + "\""};
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogCommand.java
// public interface GitLogCommand {
// List<Commit> extractCommits() throws IOException;
//
// String getLastRevisionChecked();
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommandTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import java.util.List;
import com.atlassian.bamboo.commit.Commit;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitLogCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogCommand;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitLogCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String DATE_OF_LAST_BUILD = "2009-03-13 01:24:44 +0000";
private static final String GIT_EXE = "git";
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
public void testGetsTheMostRecentLogItemIfNotCheckedLogBefore() throws IOException { | GitLogCommand gitLogCommand = new ExecutorGitLogCommand(GIT_EXE, SOURCE_CODE_DIRECTORY, null, commandExecutor); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommandTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommand.java
// public class ExecutorGitLogCommand implements GitLogCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitLogCommand.class);
//
// private String gitExe;
// private File sourceCodeDirectory;
// private String lastRevisionChecked;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitLogCommand(String gitExe, File sourceCodeDirectory, String lastRevisionChecked, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.sourceCodeDirectory = sourceCodeDirectory;
// this.lastRevisionChecked = "null".equals(lastRevisionChecked) ? null : lastRevisionChecked;
// this.commandExecutor = commandExecutor;
// }
//
// public List<Commit> extractCommits() throws IOException {
// String logText = commandExecutor.execute(getCommandLine(), sourceCodeDirectory);
//
// log.info(logText);
// GitLogParser logParser = new GitLogParser(logText);
//
// List<Commit> commits = logParser.extractCommits(lastRevisionChecked);
// lastRevisionChecked = logParser.getMostRecentCommitDate();
//
// return commits;
// }
//
// public String getLastRevisionChecked() {
// return lastRevisionChecked;
// }
//
// private String[] getCommandLine() {
// if (lastRevisionChecked == null) {
// return new String[]{gitExe, "log", "-1", "--numstat", "--date=iso8601"};
// }
// return new String[]{gitExe, "log", "--numstat", "--date=iso8601", "--since=\"" + lastRevisionChecked + "\""};
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogCommand.java
// public interface GitLogCommand {
// List<Commit> extractCommits() throws IOException;
//
// String getLastRevisionChecked();
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import java.util.List;
import com.atlassian.bamboo.commit.Commit;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitLogCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogCommand; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitLogCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String DATE_OF_LAST_BUILD = "2009-03-13 01:24:44 +0000";
private static final String GIT_EXE = "git";
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
public void testGetsTheMostRecentLogItemIfNotCheckedLogBefore() throws IOException { | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommand.java
// public class ExecutorGitLogCommand implements GitLogCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitLogCommand.class);
//
// private String gitExe;
// private File sourceCodeDirectory;
// private String lastRevisionChecked;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitLogCommand(String gitExe, File sourceCodeDirectory, String lastRevisionChecked, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.sourceCodeDirectory = sourceCodeDirectory;
// this.lastRevisionChecked = "null".equals(lastRevisionChecked) ? null : lastRevisionChecked;
// this.commandExecutor = commandExecutor;
// }
//
// public List<Commit> extractCommits() throws IOException {
// String logText = commandExecutor.execute(getCommandLine(), sourceCodeDirectory);
//
// log.info(logText);
// GitLogParser logParser = new GitLogParser(logText);
//
// List<Commit> commits = logParser.extractCommits(lastRevisionChecked);
// lastRevisionChecked = logParser.getMostRecentCommitDate();
//
// return commits;
// }
//
// public String getLastRevisionChecked() {
// return lastRevisionChecked;
// }
//
// private String[] getCommandLine() {
// if (lastRevisionChecked == null) {
// return new String[]{gitExe, "log", "-1", "--numstat", "--date=iso8601"};
// }
// return new String[]{gitExe, "log", "--numstat", "--date=iso8601", "--since=\"" + lastRevisionChecked + "\""};
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitLogCommand.java
// public interface GitLogCommand {
// List<Commit> extractCommits() throws IOException;
//
// String getLastRevisionChecked();
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommandTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import java.util.List;
import com.atlassian.bamboo.commit.Commit;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitLogCommand;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitLogCommand;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitLogCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String DATE_OF_LAST_BUILD = "2009-03-13 01:24:44 +0000";
private static final String GIT_EXE = "git";
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
public void testGetsTheMostRecentLogItemIfNotCheckedLogBefore() throws IOException { | GitLogCommand gitLogCommand = new ExecutorGitLogCommand(GIT_EXE, SOURCE_CODE_DIRECTORY, null, commandExecutor); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCheckoutCommandTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCheckoutCommand.java
// public class ExecutorGitCheckoutCommand implements GitCheckoutCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitCheckoutCommand.class);
// private String gitExe;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitCheckoutCommand(String gitExe, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.commandExecutor = commandExecutor;
// }
//
// public void checkoutBranch(BuildLogger buildLogger, String branch, boolean create, File sourceDirectory) throws IOException {
// if(create) {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " checkout -b " + branch + " origin/" + branch + "'"));
// commandExecutor.execute(new String[]{"git", "checkout", "-b", branch, "origin/" + branch}, sourceDirectory);
// } else {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " checkout " + branch + "'"));
// commandExecutor.execute(new String[]{"git", "checkout", branch}, sourceDirectory);
// }
// }}
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitCheckoutCommand; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCheckoutCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String GIT_EXE = "git";
| // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCheckoutCommand.java
// public class ExecutorGitCheckoutCommand implements GitCheckoutCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitCheckoutCommand.class);
// private String gitExe;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitCheckoutCommand(String gitExe, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.commandExecutor = commandExecutor;
// }
//
// public void checkoutBranch(BuildLogger buildLogger, String branch, boolean create, File sourceDirectory) throws IOException {
// if(create) {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " checkout -b " + branch + " origin/" + branch + "'"));
// commandExecutor.execute(new String[]{"git", "checkout", "-b", branch, "origin/" + branch}, sourceDirectory);
// } else {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " checkout " + branch + "'"));
// commandExecutor.execute(new String[]{"git", "checkout", branch}, sourceDirectory);
// }
// }}
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCheckoutCommandTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitCheckoutCommand;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCheckoutCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String GIT_EXE = "git";
| private final CommandExecutor commandExecutor = mock(CommandExecutor.class); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCheckoutCommandTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCheckoutCommand.java
// public class ExecutorGitCheckoutCommand implements GitCheckoutCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitCheckoutCommand.class);
// private String gitExe;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitCheckoutCommand(String gitExe, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.commandExecutor = commandExecutor;
// }
//
// public void checkoutBranch(BuildLogger buildLogger, String branch, boolean create, File sourceDirectory) throws IOException {
// if(create) {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " checkout -b " + branch + " origin/" + branch + "'"));
// commandExecutor.execute(new String[]{"git", "checkout", "-b", branch, "origin/" + branch}, sourceDirectory);
// } else {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " checkout " + branch + "'"));
// commandExecutor.execute(new String[]{"git", "checkout", branch}, sourceDirectory);
// }
// }}
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitCheckoutCommand; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCheckoutCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String GIT_EXE = "git";
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
private final BuildLogger buildLogger = mock(BuildLogger.class);
public void testCheckoutsAndANewRemoteTrackingBranch() throws IOException { | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCheckoutCommand.java
// public class ExecutorGitCheckoutCommand implements GitCheckoutCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitCheckoutCommand.class);
// private String gitExe;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitCheckoutCommand(String gitExe, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.commandExecutor = commandExecutor;
// }
//
// public void checkoutBranch(BuildLogger buildLogger, String branch, boolean create, File sourceDirectory) throws IOException {
// if(create) {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " checkout -b " + branch + " origin/" + branch + "'"));
// commandExecutor.execute(new String[]{"git", "checkout", "-b", branch, "origin/" + branch}, sourceDirectory);
// } else {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " checkout " + branch + "'"));
// commandExecutor.execute(new String[]{"git", "checkout", branch}, sourceDirectory);
// }
// }}
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCheckoutCommandTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitCheckoutCommand;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCheckoutCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = new File("source/directory");
private static final String GIT_EXE = "git";
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
private final BuildLogger buildLogger = mock(BuildLogger.class);
public void testCheckoutsAndANewRemoteTrackingBranch() throws IOException { | ExecutorGitCheckoutCommand checkoutCommand = new ExecutorGitCheckoutCommand(GIT_EXE, commandExecutor); |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCloneCommand.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
| import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCloneCommand implements GitCloneCommand {
private static final Log log = LogFactory.getLog(ExecutorGitCloneCommand.class);
private String gitExe; | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCloneCommand.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCloneCommand implements GitCloneCommand {
private static final Log log = LogFactory.getLog(ExecutorGitCloneCommand.class);
private String gitExe; | private CommandExecutor commandExecutor; |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommand.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
| import com.atlassian.bamboo.commit.Commit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
import java.util.List;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitLogCommand implements GitLogCommand {
private static final Log log = LogFactory.getLog(ExecutorGitLogCommand.class);
private String gitExe;
private File sourceCodeDirectory;
private String lastRevisionChecked; | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitLogCommand.java
import com.atlassian.bamboo.commit.Commit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
import java.util.List;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitLogCommand implements GitLogCommand {
private static final Log log = LogFactory.getLog(ExecutorGitLogCommand.class);
private String gitExe;
private File sourceCodeDirectory;
private String lastRevisionChecked; | private CommandExecutor commandExecutor; |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCloneCommandTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCloneCommand.java
// public class ExecutorGitCloneCommand implements GitCloneCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitCloneCommand.class);
// private String gitExe;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitCloneCommand(String gitExe, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.commandExecutor = commandExecutor;
// }
//
// public void cloneUrl(BuildLogger buildLogger, String repositoryUrl, File sourceDirectory) throws IOException {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " clone " + repositoryUrl + "'"));
//
// // make sure we have a directory in which to execute the clone command
// File parentDirectory = sourceDirectory.getParentFile();
// parentDirectory.mkdirs();
//
// // Can't clone into an existing directory
// deleteDirectory(sourceDirectory);
//
// log.info(buildLogger.addBuildLogEntry(commandExecutor.execute(new String[]{gitExe, "clone", repositoryUrl, sourceDirectory.getPath()}, parentDirectory)));
// }
//
// private void deleteDirectory(File path) {
// if (path.exists()) {
// for (File file : path.listFiles()) {
// if (file.isDirectory()) {
// deleteDirectory(file);
// } else {
// file.delete();
// }
// }
// path.delete();
// }
//
// }
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitCloneCommand; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCloneCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = createTempDir();
private static final String GIT_EXE = "git";
| // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCloneCommand.java
// public class ExecutorGitCloneCommand implements GitCloneCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitCloneCommand.class);
// private String gitExe;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitCloneCommand(String gitExe, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.commandExecutor = commandExecutor;
// }
//
// public void cloneUrl(BuildLogger buildLogger, String repositoryUrl, File sourceDirectory) throws IOException {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " clone " + repositoryUrl + "'"));
//
// // make sure we have a directory in which to execute the clone command
// File parentDirectory = sourceDirectory.getParentFile();
// parentDirectory.mkdirs();
//
// // Can't clone into an existing directory
// deleteDirectory(sourceDirectory);
//
// log.info(buildLogger.addBuildLogEntry(commandExecutor.execute(new String[]{gitExe, "clone", repositoryUrl, sourceDirectory.getPath()}, parentDirectory)));
// }
//
// private void deleteDirectory(File path) {
// if (path.exists()) {
// for (File file : path.listFiles()) {
// if (file.isDirectory()) {
// deleteDirectory(file);
// } else {
// file.delete();
// }
// }
// path.delete();
// }
//
// }
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCloneCommandTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitCloneCommand;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCloneCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = createTempDir();
private static final String GIT_EXE = "git";
| private final CommandExecutor commandExecutor = mock(CommandExecutor.class); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCloneCommandTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCloneCommand.java
// public class ExecutorGitCloneCommand implements GitCloneCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitCloneCommand.class);
// private String gitExe;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitCloneCommand(String gitExe, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.commandExecutor = commandExecutor;
// }
//
// public void cloneUrl(BuildLogger buildLogger, String repositoryUrl, File sourceDirectory) throws IOException {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " clone " + repositoryUrl + "'"));
//
// // make sure we have a directory in which to execute the clone command
// File parentDirectory = sourceDirectory.getParentFile();
// parentDirectory.mkdirs();
//
// // Can't clone into an existing directory
// deleteDirectory(sourceDirectory);
//
// log.info(buildLogger.addBuildLogEntry(commandExecutor.execute(new String[]{gitExe, "clone", repositoryUrl, sourceDirectory.getPath()}, parentDirectory)));
// }
//
// private void deleteDirectory(File path) {
// if (path.exists()) {
// for (File file : path.listFiles()) {
// if (file.isDirectory()) {
// deleteDirectory(file);
// } else {
// file.delete();
// }
// }
// path.delete();
// }
//
// }
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitCloneCommand; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCloneCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = createTempDir();
private static final String GIT_EXE = "git";
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
private final BuildLogger buildLogger = mock(BuildLogger.class);
public void testExecutesTheCloneCommandInTheSourceCodesParentDirectoryAsCannot() throws IOException { | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCloneCommand.java
// public class ExecutorGitCloneCommand implements GitCloneCommand {
// private static final Log log = LogFactory.getLog(ExecutorGitCloneCommand.class);
// private String gitExe;
// private CommandExecutor commandExecutor;
//
// public ExecutorGitCloneCommand(String gitExe, CommandExecutor commandExecutor) {
// this.gitExe = gitExe;
// this.commandExecutor = commandExecutor;
// }
//
// public void cloneUrl(BuildLogger buildLogger, String repositoryUrl, File sourceDirectory) throws IOException {
// log.info(buildLogger.addBuildLogEntry("Running '" + gitExe + " clone " + repositoryUrl + "'"));
//
// // make sure we have a directory in which to execute the clone command
// File parentDirectory = sourceDirectory.getParentFile();
// parentDirectory.mkdirs();
//
// // Can't clone into an existing directory
// deleteDirectory(sourceDirectory);
//
// log.info(buildLogger.addBuildLogEntry(commandExecutor.execute(new String[]{gitExe, "clone", repositoryUrl, sourceDirectory.getPath()}, parentDirectory)));
// }
//
// private void deleteDirectory(File path) {
// if (path.exists()) {
// for (File file : path.listFiles()) {
// if (file.isDirectory()) {
// deleteDirectory(file);
// } else {
// file.delete();
// }
// }
// path.delete();
// }
//
// }
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCloneCommandTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import com.atlassian.bamboo.build.logger.BuildLogger;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorGitCloneCommand;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCloneCommandTest extends MockObjectTestCase {
private static final File SOURCE_CODE_DIRECTORY = createTempDir();
private static final String GIT_EXE = "git";
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
private final BuildLogger buildLogger = mock(BuildLogger.class);
public void testExecutesTheCloneCommandInTheSourceCodesParentDirectoryAsCannot() throws IOException { | ExecutorGitCloneCommand cloneCommand = new ExecutorGitCloneCommand(GIT_EXE, commandExecutor); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/GitRepositoryTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitCommandDiscoverer.java
// public interface GitCommandDiscoverer {
// String gitCommand();
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/GitClient.java
// public interface GitClient {
//
// String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException;
// }
| import com.atlassian.bamboo.build.BuildLoggerManager;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.plan.PlanKeys;
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.repository.cvsimpl.CVSRepository;
import com.atlassian.bamboo.v2.build.BuildChanges;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.jmock.Expectations;
import org.jmock.integration.junit3.MockObjectTestCase;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitCommandDiscoverer;
import uk.co.pols.bamboo.gitplugin.client.GitClient;
import java.io.File;
import java.util.ArrayList; | package uk.co.pols.bamboo.gitplugin;
public class GitRepositoryTest extends MockObjectTestCase {
private static final String PLAN_KEY = "plan-key";
private static final File SRC_CODE_DIR = new File("test/src/code/directory");
private static final String RESPOSITORY_URL = "RepositoryUrl";
private static final String BRANCH = "Branch";
private GitRepositoryConfig gitRepositoryConfig = new GitRepositoryConfig(); | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitCommandDiscoverer.java
// public interface GitCommandDiscoverer {
// String gitCommand();
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/GitClient.java
// public interface GitClient {
//
// String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException;
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/GitRepositoryTest.java
import com.atlassian.bamboo.build.BuildLoggerManager;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.plan.PlanKeys;
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.repository.cvsimpl.CVSRepository;
import com.atlassian.bamboo.v2.build.BuildChanges;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.jmock.Expectations;
import org.jmock.integration.junit3.MockObjectTestCase;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitCommandDiscoverer;
import uk.co.pols.bamboo.gitplugin.client.GitClient;
import java.io.File;
import java.util.ArrayList;
package uk.co.pols.bamboo.gitplugin;
public class GitRepositoryTest extends MockObjectTestCase {
private static final String PLAN_KEY = "plan-key";
private static final File SRC_CODE_DIR = new File("test/src/code/directory");
private static final String RESPOSITORY_URL = "RepositoryUrl";
private static final String BRANCH = "Branch";
private GitRepositoryConfig gitRepositoryConfig = new GitRepositoryConfig(); | private GitClient gitClient = mock(GitClient.class); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/GitRepositoryTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitCommandDiscoverer.java
// public interface GitCommandDiscoverer {
// String gitCommand();
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/GitClient.java
// public interface GitClient {
//
// String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException;
// }
| import com.atlassian.bamboo.build.BuildLoggerManager;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.plan.PlanKeys;
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.repository.cvsimpl.CVSRepository;
import com.atlassian.bamboo.v2.build.BuildChanges;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.jmock.Expectations;
import org.jmock.integration.junit3.MockObjectTestCase;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitCommandDiscoverer;
import uk.co.pols.bamboo.gitplugin.client.GitClient;
import java.io.File;
import java.util.ArrayList; | package uk.co.pols.bamboo.gitplugin;
public class GitRepositoryTest extends MockObjectTestCase {
private static final String PLAN_KEY = "plan-key";
private static final File SRC_CODE_DIR = new File("test/src/code/directory");
private static final String RESPOSITORY_URL = "RepositoryUrl";
private static final String BRANCH = "Branch";
private GitRepositoryConfig gitRepositoryConfig = new GitRepositoryConfig();
private GitClient gitClient = mock(GitClient.class);
private BuildLoggerManager buildLoggerManager = mock(BuildLoggerManager.class);
private BuildLogger buildLogger = mock(BuildLogger.class); | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/GitCommandDiscoverer.java
// public interface GitCommandDiscoverer {
// String gitCommand();
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/GitClient.java
// public interface GitClient {
//
// String getLatestUpdate(BuildLogger buildLogger, String repositoryUrl, String branch, String planKey, String lastRevisionChecked, List<Commit> commits, File sourceCodeDirectory) throws RepositoryException;
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/GitRepositoryTest.java
import com.atlassian.bamboo.build.BuildLoggerManager;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.commit.Commit;
import com.atlassian.bamboo.plan.PlanKeys;
import com.atlassian.bamboo.repository.AbstractRepository;
import com.atlassian.bamboo.repository.Repository;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.repository.cvsimpl.CVSRepository;
import com.atlassian.bamboo.v2.build.BuildChanges;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
import org.jmock.Expectations;
import org.jmock.integration.junit3.MockObjectTestCase;
import uk.co.pols.bamboo.gitplugin.client.git.commands.GitCommandDiscoverer;
import uk.co.pols.bamboo.gitplugin.client.GitClient;
import java.io.File;
import java.util.ArrayList;
package uk.co.pols.bamboo.gitplugin;
public class GitRepositoryTest extends MockObjectTestCase {
private static final String PLAN_KEY = "plan-key";
private static final File SRC_CODE_DIR = new File("test/src/code/directory");
private static final String RESPOSITORY_URL = "RepositoryUrl";
private static final String BRANCH = "Branch";
private GitRepositoryConfig gitRepositoryConfig = new GitRepositoryConfig();
private GitClient gitClient = mock(GitClient.class);
private BuildLoggerManager buildLoggerManager = mock(BuildLoggerManager.class);
private BuildLogger buildLogger = mock(BuildLogger.class); | private GitCommandDiscoverer commandDiscoverer = mock(GitCommandDiscoverer.class); |
andypols/git-bamboo-plugin | src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCheckoutCommand.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
| import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.atlassian.bamboo.build.logger.BuildLogger;
import java.io.File;
import java.io.IOException;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCheckoutCommand implements GitCheckoutCommand {
private static final Log log = LogFactory.getLog(ExecutorGitCheckoutCommand.class);
private String gitExe; | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorGitCheckoutCommand.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.atlassian.bamboo.build.logger.BuildLogger;
import java.io.File;
import java.io.IOException;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorGitCheckoutCommand implements GitCheckoutCommand {
private static final Log log = LogFactory.getLog(ExecutorGitCheckoutCommand.class);
private String gitExe; | private CommandExecutor commandExecutor; |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorWhichCommandTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorWhichCommand.java
// public class ExecutorWhichCommand implements WhichCommand {
// private CommandExecutor commandExecutor;
// private static final String UNKNOWN = "";
//
// public ExecutorWhichCommand(CommandExecutor commandExecutor) {
// this.commandExecutor = commandExecutor;
// }
//
// public String which(String command) throws IOException {
// if(isUnixPlatform()) {
// return commandExecutor.execute(new String[]{"which", "git"}, new File(""));
// }
// return UNKNOWN;
// }
//
// private boolean isUnixPlatform() {
// return Os.isFamily(Os.FAMILY_UNIX);
// }
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.IOException;
import java.io.File;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorWhichCommand; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorWhichCommandTest extends MockObjectTestCase {
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
public void testExecuteWhichCommandToDiscoverTheGitBinary() throws IOException { | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorWhichCommand.java
// public class ExecutorWhichCommand implements WhichCommand {
// private CommandExecutor commandExecutor;
// private static final String UNKNOWN = "";
//
// public ExecutorWhichCommand(CommandExecutor commandExecutor) {
// this.commandExecutor = commandExecutor;
// }
//
// public String which(String command) throws IOException {
// if(isUnixPlatform()) {
// return commandExecutor.execute(new String[]{"which", "git"}, new File(""));
// }
// return UNKNOWN;
// }
//
// private boolean isUnixPlatform() {
// return Os.isFamily(Os.FAMILY_UNIX);
// }
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/ExecutorWhichCommandTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.IOException;
import java.io.File;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
import uk.co.pols.bamboo.gitplugin.client.git.commands.ExecutorWhichCommand;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class ExecutorWhichCommandTest extends MockObjectTestCase {
private final CommandExecutor commandExecutor = mock(CommandExecutor.class);
public void testExecuteWhichCommandToDiscoverTheGitBinary() throws IOException { | ExecutorWhichCommand whichCommand = new ExecutorWhichCommand(commandExecutor); |
andypols/git-bamboo-plugin | src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/BestGuessGitCommandDiscovererTest.java | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/BestGuessGitCommandDiscoverer.java
// public class BestGuessGitCommandDiscoverer implements GitCommandDiscoverer {
// private static final Log log = LogFactory.getLog(BestGuessGitCommandDiscoverer.class);
//
// public static final String DEFAULT_GIT_EXE = "/opt/local/bin/git";
// public static final String GIT_HOME = "GIT_HOME";
// private CommandExecutor executor;
//
// public BestGuessGitCommandDiscoverer(CommandExecutor executor) {
// this.executor = executor;
// }
//
// public String gitCommand() {
// return discoverLocationOfGitCommandLineBinary();
// }
//
// private String discoverLocationOfGitCommandLineBinary() {
// if (System.getProperty(GIT_HOME) != null) {
// return System.getProperty(GIT_HOME);
// }
//
// String gitPath = whichGitIsInThePath();
// if (StringUtils.isNotBlank(gitPath)) {
// return gitPath.trim();
// }
//
// return DEFAULT_GIT_EXE;
// }
//
// private String whichGitIsInThePath() {
// try {
// WhichCommand whichCommand = new ExecutorWhichCommand(executor);
// return whichCommand.which("git");
// } catch (IOException e) {
// log.error("Failed to execute the git command", e);
// return null;
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
| import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import uk.co.pols.bamboo.gitplugin.client.git.commands.BestGuessGitCommandDiscoverer;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor; | package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class BestGuessGitCommandDiscovererTest extends MockObjectTestCase {
private CommandExecutor commandExecutor = mock(CommandExecutor.class); | // Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/BestGuessGitCommandDiscoverer.java
// public class BestGuessGitCommandDiscoverer implements GitCommandDiscoverer {
// private static final Log log = LogFactory.getLog(BestGuessGitCommandDiscoverer.class);
//
// public static final String DEFAULT_GIT_EXE = "/opt/local/bin/git";
// public static final String GIT_HOME = "GIT_HOME";
// private CommandExecutor executor;
//
// public BestGuessGitCommandDiscoverer(CommandExecutor executor) {
// this.executor = executor;
// }
//
// public String gitCommand() {
// return discoverLocationOfGitCommandLineBinary();
// }
//
// private String discoverLocationOfGitCommandLineBinary() {
// if (System.getProperty(GIT_HOME) != null) {
// return System.getProperty(GIT_HOME);
// }
//
// String gitPath = whichGitIsInThePath();
// if (StringUtils.isNotBlank(gitPath)) {
// return gitPath.trim();
// }
//
// return DEFAULT_GIT_EXE;
// }
//
// private String whichGitIsInThePath() {
// try {
// WhichCommand whichCommand = new ExecutorWhichCommand(executor);
// return whichCommand.which("git");
// } catch (IOException e) {
// log.error("Failed to execute the git command", e);
// return null;
// }
// }
// }
//
// Path: src/main/java/uk/co/pols/bamboo/gitplugin/client/git/commands/CommandExecutor.java
// public interface CommandExecutor {
// String execute(String[] commandLine, File sourceCodeDirectory) throws IOException;
// }
// Path: src/test/java/uk/co/pols/bamboo/gitplugin/client/git/commands/BestGuessGitCommandDiscovererTest.java
import org.jmock.integration.junit3.MockObjectTestCase;
import org.jmock.Expectations;
import java.io.File;
import java.io.IOException;
import uk.co.pols.bamboo.gitplugin.client.git.commands.BestGuessGitCommandDiscoverer;
import uk.co.pols.bamboo.gitplugin.client.git.commands.CommandExecutor;
package uk.co.pols.bamboo.gitplugin.client.git.commands;
public class BestGuessGitCommandDiscovererTest extends MockObjectTestCase {
private CommandExecutor commandExecutor = mock(CommandExecutor.class); | private BestGuessGitCommandDiscoverer commandDiscoverer = new BestGuessGitCommandDiscoverer(commandExecutor); |
oktie/stringer | javaCode/simfunctions/GeneralizedEditSimilarity.java | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/experiment/IdScore.java
// public class IdScore implements Comparable<IdScore> {
// int id;
//
// double score;
//
// public int compareTo(IdScore other) {
// return (int) Math.signum(other.score - this.score);
// }
//
// public IdScore(int id, double score) {
// this.id = id;
// this.score = score;
// }
//
// public String toString(){
// return "[ "+id+" : "+score+" ] ";
// }
// }
| import experiment.IdScore;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import utility.Config;
import dbdriver.MySqlDB; | return tokenVector;
}
//This stores the normalized ed for querytokens with all other tokens
public static void initializeTokenTokenEDMap(String query, HashMap<String, Double> qgramIDF){
tokenStokenTEDst = new HashMap<String, HashMap<String, Double>>();
String[] tokens = query.toLowerCase().split(" ");
for(int i=0; i < tokens.length; i++){
HashMap<String, Double> tokenEDMap = new HashMap<String, Double>();
for(String token: qgramIDF.keySet()){
tokenEDMap.put(token, normalizedEditDistance(tokens[i], token));
}
tokenStokenTEDst.put(tokens[i], tokenEDMap);
}
}
public double getNormalizedEditDistanceFromEDMap(String s, String t){
double ed =0;
try{
ed = tokenStokenTEDst.get(s).get(t);
}catch (Exception e) {
System.err.println("The ED MAP does not contain entry for "+s+" and "+t);
// TODO: handle exception
ed = normalizedEditDistance(s, t);
}
return ed;
}
public void preprocessTable(Vector<String> records, HashMap<String, Double> qgramIDF,
Vector<HashMap<String, Double>> recordTokenWeights, String tableName) { | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/experiment/IdScore.java
// public class IdScore implements Comparable<IdScore> {
// int id;
//
// double score;
//
// public int compareTo(IdScore other) {
// return (int) Math.signum(other.score - this.score);
// }
//
// public IdScore(int id, double score) {
// this.id = id;
// this.score = score;
// }
//
// public String toString(){
// return "[ "+id+" : "+score+" ] ";
// }
// }
// Path: javaCode/simfunctions/GeneralizedEditSimilarity.java
import experiment.IdScore;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import utility.Config;
import dbdriver.MySqlDB;
return tokenVector;
}
//This stores the normalized ed for querytokens with all other tokens
public static void initializeTokenTokenEDMap(String query, HashMap<String, Double> qgramIDF){
tokenStokenTEDst = new HashMap<String, HashMap<String, Double>>();
String[] tokens = query.toLowerCase().split(" ");
for(int i=0; i < tokens.length; i++){
HashMap<String, Double> tokenEDMap = new HashMap<String, Double>();
for(String token: qgramIDF.keySet()){
tokenEDMap.put(token, normalizedEditDistance(tokens[i], token));
}
tokenStokenTEDst.put(tokens[i], tokenEDMap);
}
}
public double getNormalizedEditDistanceFromEDMap(String s, String t){
double ed =0;
try{
ed = tokenStokenTEDst.get(s).get(t);
}catch (Exception e) {
System.err.println("The ED MAP does not contain entry for "+s+" and "+t);
// TODO: handle exception
ed = normalizedEditDistance(s, t);
}
return ed;
}
public void preprocessTable(Vector<String> records, HashMap<String, Double> qgramIDF,
Vector<HashMap<String, Double>> recordTokenWeights, String tableName) { | Config config = new Config(); |
oktie/stringer | javaCode/simfunctions/GeneralizedEditSimilarity.java | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/experiment/IdScore.java
// public class IdScore implements Comparable<IdScore> {
// int id;
//
// double score;
//
// public int compareTo(IdScore other) {
// return (int) Math.signum(other.score - this.score);
// }
//
// public IdScore(int id, double score) {
// this.id = id;
// this.score = score;
// }
//
// public String toString(){
// return "[ "+id+" : "+score+" ] ";
// }
// }
| import experiment.IdScore;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import utility.Config;
import dbdriver.MySqlDB; | }
//This stores the normalized ed for querytokens with all other tokens
public static void initializeTokenTokenEDMap(String query, HashMap<String, Double> qgramIDF){
tokenStokenTEDst = new HashMap<String, HashMap<String, Double>>();
String[] tokens = query.toLowerCase().split(" ");
for(int i=0; i < tokens.length; i++){
HashMap<String, Double> tokenEDMap = new HashMap<String, Double>();
for(String token: qgramIDF.keySet()){
tokenEDMap.put(token, normalizedEditDistance(tokens[i], token));
}
tokenStokenTEDst.put(tokens[i], tokenEDMap);
}
}
public double getNormalizedEditDistanceFromEDMap(String s, String t){
double ed =0;
try{
ed = tokenStokenTEDst.get(s).get(t);
}catch (Exception e) {
System.err.println("The ED MAP does not contain entry for "+s+" and "+t);
// TODO: handle exception
ed = normalizedEditDistance(s, t);
}
return ed;
}
public void preprocessTable(Vector<String> records, HashMap<String, Double> qgramIDF,
Vector<HashMap<String, Double>> recordTokenWeights, String tableName) {
Config config = new Config(); | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/experiment/IdScore.java
// public class IdScore implements Comparable<IdScore> {
// int id;
//
// double score;
//
// public int compareTo(IdScore other) {
// return (int) Math.signum(other.score - this.score);
// }
//
// public IdScore(int id, double score) {
// this.id = id;
// this.score = score;
// }
//
// public String toString(){
// return "[ "+id+" : "+score+" ] ";
// }
// }
// Path: javaCode/simfunctions/GeneralizedEditSimilarity.java
import experiment.IdScore;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import utility.Config;
import dbdriver.MySqlDB;
}
//This stores the normalized ed for querytokens with all other tokens
public static void initializeTokenTokenEDMap(String query, HashMap<String, Double> qgramIDF){
tokenStokenTEDst = new HashMap<String, HashMap<String, Double>>();
String[] tokens = query.toLowerCase().split(" ");
for(int i=0; i < tokens.length; i++){
HashMap<String, Double> tokenEDMap = new HashMap<String, Double>();
for(String token: qgramIDF.keySet()){
tokenEDMap.put(token, normalizedEditDistance(tokens[i], token));
}
tokenStokenTEDst.put(tokens[i], tokenEDMap);
}
}
public double getNormalizedEditDistanceFromEDMap(String s, String t){
double ed =0;
try{
ed = tokenStokenTEDst.get(s).get(t);
}catch (Exception e) {
System.err.println("The ED MAP does not contain entry for "+s+" and "+t);
// TODO: handle exception
ed = normalizedEditDistance(s, t);
}
return ed;
}
public void preprocessTable(Vector<String> records, HashMap<String, Double> qgramIDF,
Vector<HashMap<String, Double>> recordTokenWeights, String tableName) {
Config config = new Config(); | MySqlDB mysqlDB = new MySqlDB(config.returnURL(), config.user, config.passwd); |
oktie/stringer | javaCode/simfunctions/GeneralizedEditSimilarity.java | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/experiment/IdScore.java
// public class IdScore implements Comparable<IdScore> {
// int id;
//
// double score;
//
// public int compareTo(IdScore other) {
// return (int) Math.signum(other.score - this.score);
// }
//
// public IdScore(int id, double score) {
// this.id = id;
// this.score = score;
// }
//
// public String toString(){
// return "[ "+id+" : "+score+" ] ";
// }
// }
| import experiment.IdScore;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import utility.Config;
import dbdriver.MySqlDB; | // Find the tf's of all the qgrams
getDFandTFweight(k - 1, str, qgramIDF, recordTokenWeights);
}
numberOfRecords++;
}
}
mysqlDB.close();
} catch (Exception e) {
System.out.println("database error: cannot read table");
e.printStackTrace();
}
if (logToDB) {
storePreprocessedDataToDB(tableName, recordTokenWeights, extractMetricName(this.getClass().getName())
+ "_tf");
}
// convert the df into IDF
convertDFtoIDF(qgramIDF, numberOfRecords, recordTokenWeights);
if (logToDB) {
storePreprocessedIDF(tableName, qgramIDF, extractMetricName(this.getClass().getName()) + "_idf");
}
// Now convert the tf in fileQrmanWeight to tfidf weights
/*
* convertTFtoWeights(records, qgramIDF, recordTokenWeights); if
* (logToDB) { storePreprocessedDataToDB(tableName, recordTokenWeights,
* extractMetricName(this.getClass().getName()) + "_wt"); }
*/
}
// This function is for the metrics which has to go iteratively through all
// the records to get the final scoreList | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/experiment/IdScore.java
// public class IdScore implements Comparable<IdScore> {
// int id;
//
// double score;
//
// public int compareTo(IdScore other) {
// return (int) Math.signum(other.score - this.score);
// }
//
// public IdScore(int id, double score) {
// this.id = id;
// this.score = score;
// }
//
// public String toString(){
// return "[ "+id+" : "+score+" ] ";
// }
// }
// Path: javaCode/simfunctions/GeneralizedEditSimilarity.java
import experiment.IdScore;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import utility.Config;
import dbdriver.MySqlDB;
// Find the tf's of all the qgrams
getDFandTFweight(k - 1, str, qgramIDF, recordTokenWeights);
}
numberOfRecords++;
}
}
mysqlDB.close();
} catch (Exception e) {
System.out.println("database error: cannot read table");
e.printStackTrace();
}
if (logToDB) {
storePreprocessedDataToDB(tableName, recordTokenWeights, extractMetricName(this.getClass().getName())
+ "_tf");
}
// convert the df into IDF
convertDFtoIDF(qgramIDF, numberOfRecords, recordTokenWeights);
if (logToDB) {
storePreprocessedIDF(tableName, qgramIDF, extractMetricName(this.getClass().getName()) + "_idf");
}
// Now convert the tf in fileQrmanWeight to tfidf weights
/*
* convertTFtoWeights(records, qgramIDF, recordTokenWeights); if
* (logToDB) { storePreprocessedDataToDB(tableName, recordTokenWeights,
* extractMetricName(this.getClass().getName()) + "_wt"); }
*/
}
// This function is for the metrics which has to go iteratively through all
// the records to get the final scoreList | public List<IdScore> getSimilarRecords(String query, HashMap<String, Double> qgramIDF, |
oktie/stringer | javaCode/ricochet/TimeSR.java | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
| import dbdriver.MySqlDB;
import java.io.*;
import java.util.*;
import utility.Config;
| clusterInfo[ci]=members;
ci++;
}
}
System.out.println("num of cluster produced : "+exactNoCluster);
return maxi;
}
public double averageValue = 0;
void processing() {
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistance[i][j] = r;
actualDistance[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
averageValue = totalDistance;
}
public static void saveClusters(HashMap<Integer,Integer> tidClusters, String tablename, String thresholdS){
| // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
// Path: javaCode/ricochet/TimeSR.java
import dbdriver.MySqlDB;
import java.io.*;
import java.util.*;
import utility.Config;
clusterInfo[ci]=members;
ci++;
}
}
System.out.println("num of cluster produced : "+exactNoCluster);
return maxi;
}
public double averageValue = 0;
void processing() {
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistance[i][j] = r;
actualDistance[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
averageValue = totalDistance;
}
public static void saveClusters(HashMap<Integer,Integer> tidClusters, String tablename, String thresholdS){
| Config config = new Config();
|
oktie/stringer | javaCode/ricochet/TimeSR.java | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
| import dbdriver.MySqlDB;
import java.io.*;
import java.util.*;
import utility.Config;
|
ci++;
}
}
System.out.println("num of cluster produced : "+exactNoCluster);
return maxi;
}
public double averageValue = 0;
void processing() {
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistance[i][j] = r;
actualDistance[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
averageValue = totalDistance;
}
public static void saveClusters(HashMap<Integer,Integer> tidClusters, String tablename, String thresholdS){
Config config = new Config();
| // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
// Path: javaCode/ricochet/TimeSR.java
import dbdriver.MySqlDB;
import java.io.*;
import java.util.*;
import utility.Config;
ci++;
}
}
System.out.println("num of cluster produced : "+exactNoCluster);
return maxi;
}
public double averageValue = 0;
void processing() {
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistance[i][j] = r;
actualDistance[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
averageValue = totalDistance;
}
public static void saveClusters(HashMap<Integer,Integer> tidClusters, String tablename, String thresholdS){
Config config = new Config();
| MySqlDB mysqlDB = new MySqlDB(config.returnURL(), config.user, config.passwd);
|
oktie/stringer | javaCode/ricochet/TimeCR.java | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
| import java.io.*;
import java.util.*;
import utility.Config;
import dbdriver.MySqlDB;
| }
clusterInfo[ci]=members;
ci++;
}
}
System.out.print("num of cluster produced : "+exactNoCluster+"\n");
return maxi;
}
public double actualDistanceB[][];
void processing() {
actualDistanceB = new double[mySize][mySize];
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistanceB[i][j] = r;
actualDistanceB[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
}
public static void saveClusters(HashMap<Integer,BitSet> clusterNums, String tablename, String thresholdS){
| // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
// Path: javaCode/ricochet/TimeCR.java
import java.io.*;
import java.util.*;
import utility.Config;
import dbdriver.MySqlDB;
}
clusterInfo[ci]=members;
ci++;
}
}
System.out.print("num of cluster produced : "+exactNoCluster+"\n");
return maxi;
}
public double actualDistanceB[][];
void processing() {
actualDistanceB = new double[mySize][mySize];
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistanceB[i][j] = r;
actualDistanceB[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
}
public static void saveClusters(HashMap<Integer,BitSet> clusterNums, String tablename, String thresholdS){
| Config config = new Config();
|
oktie/stringer | javaCode/ricochet/TimeCR.java | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
| import java.io.*;
import java.util.*;
import utility.Config;
import dbdriver.MySqlDB;
| clusterInfo[ci]=members;
ci++;
}
}
System.out.print("num of cluster produced : "+exactNoCluster+"\n");
return maxi;
}
public double actualDistanceB[][];
void processing() {
actualDistanceB = new double[mySize][mySize];
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistanceB[i][j] = r;
actualDistanceB[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
}
public static void saveClusters(HashMap<Integer,BitSet> clusterNums, String tablename, String thresholdS){
Config config = new Config();
| // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
// Path: javaCode/ricochet/TimeCR.java
import java.io.*;
import java.util.*;
import utility.Config;
import dbdriver.MySqlDB;
clusterInfo[ci]=members;
ci++;
}
}
System.out.print("num of cluster produced : "+exactNoCluster+"\n");
return maxi;
}
public double actualDistanceB[][];
void processing() {
actualDistanceB = new double[mySize][mySize];
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistanceB[i][j] = r;
actualDistanceB[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
}
public static void saveClusters(HashMap<Integer,BitSet> clusterNums, String tablename, String thresholdS){
Config config = new Config();
| MySqlDB mysqlDB = new MySqlDB(config.returnURL(), config.user, config.passwd);
|
oktie/stringer | javaCode/simfunctions/SoftTfIdf.java | // Path: javaCode/experiment/IdScore.java
// public class IdScore implements Comparable<IdScore> {
// int id;
//
// double score;
//
// public int compareTo(IdScore other) {
// return (int) Math.signum(other.score - this.score);
// }
//
// public IdScore(int id, double score) {
// this.id = id;
// this.score = score;
// }
//
// public String toString(){
// return "[ "+id+" : "+score+" ] ";
// }
// }
| import experiment.IdScore;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import com.wcohen.ss.JaroWinkler; | /*******************************************************************************
* Copyright (c) 2006-2007 University of Toronto Database Group
*
* 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.
*******************************************************************************/
package simfunctions;
public class SoftTfIdf extends TfIdf {
public static boolean localDebugMode = true;
public static double jwSimilarityThreshold = 0.8;
public HashMap<String, Double> getTF(String str) {
tokenizeUsingQgrams = false;
return getTokenTFMultiple(str);
}
public void printDebug(String str){
//if(localDebugMode)
// System.out.print(str);
}
// Returns the maximum similar token based on Jaro-Wrinkler score
public String getMaximumSimilarToken(String token, Set<String> tupleTokens, JaroWinkler jw) {
double currentScore = 0, maxScore = 0;
boolean isFirstToken = true;
String maxSimilarToken = "";
printDebug(token+"\n");
for (String tok : tupleTokens) {
if(isFirstToken){
maxSimilarToken = tok;
isFirstToken = false;
}
currentScore = jw.score(jw.prepare(token), jw.prepare(tok));
printDebug(tok+" "+currentScore+" :: ");
if (currentScore > maxScore) {
maxScore = currentScore;
maxSimilarToken = tok;
}
}
printDebug("\nMaxSimilar "+maxSimilarToken+" "+maxScore+" :: \n");
return maxSimilarToken;
}
| // Path: javaCode/experiment/IdScore.java
// public class IdScore implements Comparable<IdScore> {
// int id;
//
// double score;
//
// public int compareTo(IdScore other) {
// return (int) Math.signum(other.score - this.score);
// }
//
// public IdScore(int id, double score) {
// this.id = id;
// this.score = score;
// }
//
// public String toString(){
// return "[ "+id+" : "+score+" ] ";
// }
// }
// Path: javaCode/simfunctions/SoftTfIdf.java
import experiment.IdScore;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import com.wcohen.ss.JaroWinkler;
/*******************************************************************************
* Copyright (c) 2006-2007 University of Toronto Database Group
*
* 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.
*******************************************************************************/
package simfunctions;
public class SoftTfIdf extends TfIdf {
public static boolean localDebugMode = true;
public static double jwSimilarityThreshold = 0.8;
public HashMap<String, Double> getTF(String str) {
tokenizeUsingQgrams = false;
return getTokenTFMultiple(str);
}
public void printDebug(String str){
//if(localDebugMode)
// System.out.print(str);
}
// Returns the maximum similar token based on Jaro-Wrinkler score
public String getMaximumSimilarToken(String token, Set<String> tupleTokens, JaroWinkler jw) {
double currentScore = 0, maxScore = 0;
boolean isFirstToken = true;
String maxSimilarToken = "";
printDebug(token+"\n");
for (String tok : tupleTokens) {
if(isFirstToken){
maxSimilarToken = tok;
isFirstToken = false;
}
currentScore = jw.score(jw.prepare(token), jw.prepare(tok));
printDebug(tok+" "+currentScore+" :: ");
if (currentScore > maxScore) {
maxScore = currentScore;
maxSimilarToken = tok;
}
}
printDebug("\nMaxSimilar "+maxSimilarToken+" "+maxScore+" :: \n");
return maxSimilarToken;
}
| public List<IdScore> getSimilarRecords(String query, HashMap<String, Double> qgramIDF, |
oktie/stringer | javaCode/simfunctions/TimeRunProbabilityAssignmentWJBM25.java | // Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
| import java.sql.ResultSet;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import dbdriver.MySqlDB;
import utility.Config; | String str = strs.get(tid);
double sim = metric.getSimilarityScore(rep, qgramIDF, meanIDF, recordTokenWeights, tid, str);
//if (debug_mode) {System.out.println(str + " " + (sim/strSet.cardinality()));}
//System.out.println(str + " " + (sim));
//probs.put(tid,sim/rep.length());
probs.put(tid,sim);
sum += sim;
//probs.put(sn,rand.nextDouble());
}
for (int sn:strs.keySet()){
//String str = strs.get(sn);
probs.put(sn, probs.get(sn)/sum);
if (debug_mode) {System.out.println(strs.get(sn) + " " + probs.get(sn));}
}
if (debug_mode) {System.out.println();}
return probs;
}
public static void main(String[] args) {
String tablename = "20K";
//String pairTable = "pairs";
String probTable = "probs";
boolean log_sig_to_db = true;
boolean show_times = true;
| // Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
// Path: javaCode/simfunctions/TimeRunProbabilityAssignmentWJBM25.java
import java.sql.ResultSet;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import dbdriver.MySqlDB;
import utility.Config;
String str = strs.get(tid);
double sim = metric.getSimilarityScore(rep, qgramIDF, meanIDF, recordTokenWeights, tid, str);
//if (debug_mode) {System.out.println(str + " " + (sim/strSet.cardinality()));}
//System.out.println(str + " " + (sim));
//probs.put(tid,sim/rep.length());
probs.put(tid,sim);
sum += sim;
//probs.put(sn,rand.nextDouble());
}
for (int sn:strs.keySet()){
//String str = strs.get(sn);
probs.put(sn, probs.get(sn)/sum);
if (debug_mode) {System.out.println(strs.get(sn) + " " + probs.get(sn));}
}
if (debug_mode) {System.out.println();}
return probs;
}
public static void main(String[] args) {
String tablename = "20K";
//String pairTable = "pairs";
String probTable = "probs";
boolean log_sig_to_db = true;
boolean show_times = true;
| Config config = new Config(); |
oktie/stringer | javaCode/simfunctions/TimeRunProbabilityAssignmentWJBM25.java | // Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
| import java.sql.ResultSet;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import dbdriver.MySqlDB;
import utility.Config; | double sim = metric.getSimilarityScore(rep, qgramIDF, meanIDF, recordTokenWeights, tid, str);
//if (debug_mode) {System.out.println(str + " " + (sim/strSet.cardinality()));}
//System.out.println(str + " " + (sim));
//probs.put(tid,sim/rep.length());
probs.put(tid,sim);
sum += sim;
//probs.put(sn,rand.nextDouble());
}
for (int sn:strs.keySet()){
//String str = strs.get(sn);
probs.put(sn, probs.get(sn)/sum);
if (debug_mode) {System.out.println(strs.get(sn) + " " + probs.get(sn));}
}
if (debug_mode) {System.out.println();}
return probs;
}
public static void main(String[] args) {
String tablename = "20K";
//String pairTable = "pairs";
String probTable = "probs";
boolean log_sig_to_db = true;
boolean show_times = true;
Config config = new Config(); | // Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
// Path: javaCode/simfunctions/TimeRunProbabilityAssignmentWJBM25.java
import java.sql.ResultSet;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import dbdriver.MySqlDB;
import utility.Config;
double sim = metric.getSimilarityScore(rep, qgramIDF, meanIDF, recordTokenWeights, tid, str);
//if (debug_mode) {System.out.println(str + " " + (sim/strSet.cardinality()));}
//System.out.println(str + " " + (sim));
//probs.put(tid,sim/rep.length());
probs.put(tid,sim);
sum += sim;
//probs.put(sn,rand.nextDouble());
}
for (int sn:strs.keySet()){
//String str = strs.get(sn);
probs.put(sn, probs.get(sn)/sum);
if (debug_mode) {System.out.println(strs.get(sn) + " " + probs.get(sn));}
}
if (debug_mode) {System.out.println();}
return probs;
}
public static void main(String[] args) {
String tablename = "20K";
//String pairTable = "pairs";
String probTable = "probs";
boolean log_sig_to_db = true;
boolean show_times = true;
Config config = new Config(); | MySqlDB mysqlDB = new MySqlDB(config.returnURL(), config.user, config.passwd); |
oktie/stringer | javaCode/ricochet/TimeBSR.java | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
| import java.io.*;
import java.util.*;
import utility.Config;
import dbdriver.MySqlDB;
| next = newcent1;
adjNext.removeElement(next);
listCenters.add(next);
listAdjacent.add(adjNext);
}
}
}
}
public double averageValue = 0;
void processing() {
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistance[i][j] = r;
actualDistance[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
averageValue = totalDistance;
}
public static void saveClusters(HashMap<Integer,Integer> tidClusters, String tablename, String thresholdS){
| // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
// Path: javaCode/ricochet/TimeBSR.java
import java.io.*;
import java.util.*;
import utility.Config;
import dbdriver.MySqlDB;
next = newcent1;
adjNext.removeElement(next);
listCenters.add(next);
listAdjacent.add(adjNext);
}
}
}
}
public double averageValue = 0;
void processing() {
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistance[i][j] = r;
actualDistance[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
averageValue = totalDistance;
}
public static void saveClusters(HashMap<Integer,Integer> tidClusters, String tablename, String thresholdS){
| Config config = new Config();
|
oktie/stringer | javaCode/ricochet/TimeBSR.java | // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
| import java.io.*;
import java.util.*;
import utility.Config;
import dbdriver.MySqlDB;
| adjNext.removeElement(next);
listCenters.add(next);
listAdjacent.add(adjNext);
}
}
}
}
public double averageValue = 0;
void processing() {
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistance[i][j] = r;
actualDistance[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
averageValue = totalDistance;
}
public static void saveClusters(HashMap<Integer,Integer> tidClusters, String tablename, String thresholdS){
Config config = new Config();
| // Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
//
// Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
// Path: javaCode/ricochet/TimeBSR.java
import java.io.*;
import java.util.*;
import utility.Config;
import dbdriver.MySqlDB;
adjNext.removeElement(next);
listCenters.add(next);
listAdjacent.add(adjNext);
}
}
}
}
public double averageValue = 0;
void processing() {
double totalDistance = 0;
double totalEdges = 0;
for (int i=0; i<mySize; i++) {
for (int j=i+1; j<mySize; j++) {
double r = actualDistance[i][j];
r = (1f/r) * (1f/r);
r = (myDegree[i]*myDegree[j])/r;
actualDistance[i][j] = r;
actualDistance[j][i] = r;
totalEdges = totalEdges + 2;
totalDistance = totalDistance + r + r;
}
}
totalDistance = totalDistance/(1F*totalEdges);
averageValue = totalDistance;
}
public static void saveClusters(HashMap<Integer,Integer> tidClusters, String tablename, String thresholdS){
Config config = new Config();
| MySqlDB mysqlDB = new MySqlDB(config.returnURL(), config.user, config.passwd);
|
oktie/stringer | javaCode/simfunctions/RunProbabilityAssignment.java | // Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
| import java.sql.ResultSet;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import dbdriver.MySqlDB;
import utility.Config; | //BitSet copy = new BitSet();
//copy = (BitSet)(strSet.clone());
//copy.and(repSet);
//probs.put(sn,sim/copy.cardinality());
//sum += sim/copy.cardinality();
//probs.put(sn,(sim/total));
//sum += (sim/total);
}
for (int sn:strs.keySet()){
//String str = strs.get(sn);
probs.put(sn, probs.get(sn)/sum);
if (debug_mode) {System.out.println(strs.get(sn) + " " + probs.get(sn));}
}
if (debug_mode) {System.out.println();}
return probs;
}
public static void main(String[] args) {
String tablename = "pe";
//String pairTable = "pairs";
String probTable = "probs";
boolean log_sig_to_db = true;
boolean show_times = true;
| // Path: javaCode/dbdriver/MySqlDB.java
// public class MySqlDB
// {
// //String url, usr, passwd;
// Connection con=null;
// Statement st=null;
//
// public MySqlDB(String url, String user, String passwd) {
// try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// }
// catch (Exception E) {
// System.err.println("Unable to load driver.");
// E.printStackTrace();
// System.exit(1);
// }
// try {
// Connection con2 = DriverManager.getConnection(url, user, passwd);
// //System.out.println(url+" "+user+" "+passwd);
// con = con2;
// }
// catch (SQLException E) {
// System.out.println("SQLException: " + E.getMessage());
// System.out.println("SQLState: " + E.getSQLState());
// System.out.println("VendorError: " + E.getErrorCode());
// E.printStackTrace();
// con=null;
// System.exit(1);
// }
//
//
//
// }
//
// public ResultSet executeQuery(String query) throws java.lang.Exception {
// return con.createStatement().executeQuery(query);
// }
//
// public DatabaseMetaData getMetaData() throws java.lang.Exception {
// return con.getMetaData();
// }
//
// public int executeUpdate(String query) throws java.lang.Exception {
// return con.createStatement().executeUpdate(query);
// }
//
// public PreparedStatement prepareStatement(String query)
// throws java.lang.Exception {
// return con.prepareStatement(query);
// }
//
// public void close() throws Exception {
// if(con != null)
// con.close();
// }
// }
//
// Path: javaCode/utility/Config.java
// public class Config
// {
// public String cfgFileName;
// public String dbName;
// public String host ;
// public String user ;
// public String passwd;
// public String port ;
// public String url ;
// public boolean useFile;
// public String fileName;
// public String dbServer;
// public String outputFile;
// public String preprocessingColumn;
// public boolean debugMode;
// public int dbOption;
//
// public static String storeResultDirectory = "c:/Users/admin/dcp-workspace/log/";
// public static String queryFileName = "c:/Users/admin/dcp-workspace/data/_fixedQueries_";
// public static String expResultTablePrefix = "_ExpRes_";
// public static String queryClass = "dcp.clean";
//
// public static boolean tokenizeUsingQgrams = true;
// public int numHeaders;
//
//
// public String bm25WeightTable = "$Aux$_BM253_0_cu1_string_BMBaseWeights";
// public String tfidfWeightTable = "$Aux$_TfIdf3_0_cu1_string_Weights";
// // Class constructor
// public Config() {
// outputFile = "geneRatios.txt";
//
// host = "localhost";
// user = "root";
// passwd = "";
// port = "3306";
// url = "";
// useFile = false;
// fileName = "tmpFile";
// dbServer = "mysql";
// numHeaders = 7;
// dbName = "midas";
// preprocessingColumn = "name";
//
// //dbName = "probtest";
// //preprocessingColumn = "title";
// }
//
// public String returnURL(){
// if(dbOption == 1)
// url = "jdbc:postgres://"+ host + ":"+ port +"/"+ dbName;
// else
// url = "jdbc:mysql://"+host+":"+port+"/"+dbName ;
// return url;
// }
//
// public void setDebugMode(boolean val){
// debugMode = val;
// }
//
// public void setDbName(String name){
// dbName = name;
// }
//
// }
// Path: javaCode/simfunctions/RunProbabilityAssignment.java
import java.sql.ResultSet;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import dbdriver.MySqlDB;
import utility.Config;
//BitSet copy = new BitSet();
//copy = (BitSet)(strSet.clone());
//copy.and(repSet);
//probs.put(sn,sim/copy.cardinality());
//sum += sim/copy.cardinality();
//probs.put(sn,(sim/total));
//sum += (sim/total);
}
for (int sn:strs.keySet()){
//String str = strs.get(sn);
probs.put(sn, probs.get(sn)/sum);
if (debug_mode) {System.out.println(strs.get(sn) + " " + probs.get(sn));}
}
if (debug_mode) {System.out.println();}
return probs;
}
public static void main(String[] args) {
String tablename = "pe";
//String pairTable = "pairs";
String probTable = "probs";
boolean log_sig_to_db = true;
boolean show_times = true;
| Config config = new Config(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.