diff --git a/app/Global.java b/app/Global.java index 0549b8d1b..1ded38568 100644 --- a/app/Global.java +++ b/app/Global.java @@ -162,14 +162,14 @@ private String createSeed(String basicSeed) { } private void replaceSiteSecretKey(String seed) throws IOException { - SecureRandom random = new SecureRandom(seed.getBytes()); + SecureRandom random = new SecureRandom(seed.getBytes(Config.getCharset())); String secret = new BigInteger(130, random).toString(32); Path path = Paths.get("conf/application.conf"); byte[] bytes = Files.readAllBytes(path); - String config = new String(bytes); + String config = new String(bytes, Config.getCharset()); config = config.replace(DEFAULT_SECRET, secret); - Files.write(path, config.getBytes()); + Files.write(path, config.getBytes(Config.getCharset())); } private boolean hasError(Form newUserForm) { diff --git a/app/controllers/BoardApp.java b/app/controllers/BoardApp.java index 13d175c6c..c4820e06b 100644 --- a/app/controllers/BoardApp.java +++ b/app/controllers/BoardApp.java @@ -55,6 +55,7 @@ import java.io.IOException; import java.util.List; +import java.util.Objects; import static com.avaje.ebean.Expr.icontains; @@ -244,7 +245,7 @@ public void run() { private static void unmarkAnotherReadmePostingIfExists(Project project, Long postingNumber) { Posting previousReadmePosting = Posting.findREADMEPosting(project); - if(previousReadmePosting != null && previousReadmePosting.getNumber() != postingNumber){ + if(previousReadmePosting != null && !Objects.equals(previousReadmePosting.getNumber(), postingNumber)){ previousReadmePosting.readme = false; previousReadmePosting.directSave(); } diff --git a/app/controllers/CodeHistoryApp.java b/app/controllers/CodeHistoryApp.java index 24cda5066..d54a258c7 100644 --- a/app/controllers/CodeHistoryApp.java +++ b/app/controllers/CodeHistoryApp.java @@ -98,7 +98,7 @@ public static Result show(String ownerName, String projectName, String commitId) Project project = Project.findByOwnerAndProjectName(ownerName, projectName); PlayRepository repository = RepositoryService.getRepository(project); - Commit commit = null; + Commit commit; try { commit = repository.getCommit(commitId); diff --git a/app/controllers/ImportApp.java b/app/controllers/ImportApp.java index e02d48a17..715cd0fd7 100644 --- a/app/controllers/ImportApp.java +++ b/app/controllers/ImportApp.java @@ -42,6 +42,7 @@ import java.io.File; import java.io.IOException; import java.util.List; +import java.util.Objects; import static play.data.Form.form; @@ -57,7 +58,7 @@ public static Result importForm() { } @Transactional - public static Result newProject() throws GitAPIException, IOException { + public static Result newProject() throws Exception { if( !AccessControl.isGlobalResourceCreatable(UserApp.currentUser()) ){ return forbidden("'" + UserApp.currentUser().name + "' has no permission"); } @@ -180,7 +181,7 @@ private static ValidationResult validateForm(Form newProjectForm, Organ result = badRequest(create.render("title.newProject", newProjectForm, orgUserList)); } - if (ownerIsUser && UserApp.currentUser().id != user.id) { + if (ownerIsUser && !Objects.equals(UserApp.currentUser().id, user.id)) { newProjectForm.reject("owner", "project.owner.invalidate"); hasError = true; result = badRequest(create.render("title.newProject", newProjectForm, orgUserList)); diff --git a/app/controllers/IssueApp.java b/app/controllers/IssueApp.java index 34d509b3a..46f892525 100644 --- a/app/controllers/IssueApp.java +++ b/app/controllers/IssueApp.java @@ -75,9 +75,6 @@ public static Result userIssues(String state, String format, int pageNum) throws Page issues = el.findPagingList(itemsPerPage).getPage(searchCondition.pageNum); switch(format){ - case EXCEL_EXT: - return issuesAsExcel(project, el); - case "pjax": return issuesAsPjax(project, issues, searchCondition); @@ -312,7 +309,7 @@ public static Result massUpdate(String ownerName, String projectName) { if(hasAssignee(issue)) { oldAssignee = issue.assignee.user; } - Assignee newAssignee = null; + Assignee newAssignee; if (issueMassUpdate.assignee.isAnonymous()) { newAssignee = null; } else { diff --git a/app/controllers/PullRequestApp.java b/app/controllers/PullRequestApp.java index 02b5f0b54..b1e7509ce 100755 --- a/app/controllers/PullRequestApp.java +++ b/app/controllers/PullRequestApp.java @@ -654,7 +654,7 @@ public Result getResult() { } - public static class SearchCondition { + public static class SearchCondition implements Cloneable { public Project project; public String filter; public Long contributorId; diff --git a/app/models/AbstractPosting.java b/app/models/AbstractPosting.java index 36f65f90d..d8ae2ae0e 100644 --- a/app/models/AbstractPosting.java +++ b/app/models/AbstractPosting.java @@ -23,11 +23,11 @@ import models.enumeration.ResourceType; import models.resource.Resource; import models.resource.ResourceConvertible; - import org.joda.time.Duration; import play.data.format.Formats; import play.data.validation.Constraints; -import play.db.ebean.*; +import play.db.ebean.Model; +import play.db.ebean.Transactional; import utils.JodaDateUtil; import javax.persistence.*; diff --git a/app/models/Assignee.java b/app/models/Assignee.java index 2e763936a..dfa087598 100644 --- a/app/models/Assignee.java +++ b/app/models/Assignee.java @@ -20,16 +20,14 @@ */ package models; -import java.util.Set; +import play.data.validation.Constraints.Required; +import play.db.ebean.Model; -import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; - -import play.data.validation.Constraints.Required; -import play.db.ebean.Model; +import java.util.Set; @Entity public class Assignee extends Model { diff --git a/app/models/Attachment.java b/app/models/Attachment.java index 1b3519a97..3db042b58 100644 --- a/app/models/Attachment.java +++ b/app/models/Attachment.java @@ -20,7 +20,6 @@ */ package models; -import utils.AttachmentCache; import controllers.AttachmentApp; import models.enumeration.ResourceType; import models.resource.GlobalResource; @@ -33,6 +32,7 @@ import play.db.ebean.Model; import play.libs.Akka; import scala.concurrent.duration.Duration; +import utils.AttachmentCache; import utils.FileUtil; import utils.JodaDateUtil; diff --git a/app/models/AuthInfo.java b/app/models/AuthInfo.java index 52eff9610..c7247f02d 100644 --- a/app/models/AuthInfo.java +++ b/app/models/AuthInfo.java @@ -21,7 +21,6 @@ package models; import play.data.validation.Constraints; -import utils.ReservedWordsValidator; public class AuthInfo { @Constraints.Required diff --git a/app/models/Issue.java b/app/models/Issue.java index 60696e5e4..ad18b8918 100644 --- a/app/models/Issue.java +++ b/app/models/Issue.java @@ -35,6 +35,7 @@ import models.resource.Resource; import models.support.SearchCondition; import org.apache.commons.lang3.time.DateUtils; +import org.apache.shiro.util.CollectionUtils; import play.data.Form; import play.data.format.Formats; import play.i18n.Messages; @@ -68,11 +69,8 @@ public class Issue extends AbstractPosting implements LabelOwner { @Formats.DateTime(pattern = "yyyy-MM-dd") public Date dueDate; - public static List availableStates = new ArrayList<>(); - static { - availableStates.add(State.OPEN); - availableStates.add(State.CLOSED); - } + public static final List availableStates = + Collections.unmodifiableList(CollectionUtils.asList(State.OPEN, State.CLOSED)); @ManyToOne public Milestone milestone; @@ -371,7 +369,7 @@ public boolean assignedUserEquals(Assignee otherAssignee) { return otherAssignee == null || otherAssignee.user == null || otherAssignee.user.isAnonymous(); } if (otherAssignee == null || otherAssignee.user == null || otherAssignee.user.isAnonymous()) { - return assignee == null || assignee.user == null || assignee.user.isAnonymous(); + return assignee.user.isAnonymous(); } return assignee.equals(otherAssignee) || assignee.user.equals(otherAssignee.user); } diff --git a/app/models/IssueComment.java b/app/models/IssueComment.java index de73e275d..de952dcbb 100644 --- a/app/models/IssueComment.java +++ b/app/models/IssueComment.java @@ -30,7 +30,7 @@ @Entity public class IssueComment extends Comment { private static final long serialVersionUID = 1L; - public static Finder find = new Finder<>(Long.class, IssueComment.class); + public static final Finder find = new Finder<>(Long.class, IssueComment.class); @ManyToOne public Issue issue; diff --git a/app/models/IssueEvent.java b/app/models/IssueEvent.java index 49f34296e..185053d97 100644 --- a/app/models/IssueEvent.java +++ b/app/models/IssueEvent.java @@ -27,7 +27,9 @@ import play.db.ebean.Model; import javax.persistence.*; -import java.util.*; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; import java.util.regex.Matcher; @Entity @@ -55,7 +57,7 @@ public class IssueEvent extends Model implements TimelineItem { private static final int DRAFT_TIME_IN_MILLIS = Configuration.root() .getMilliseconds("application.issue-event.draft-time", 30 * 1000L).intValue(); - public static Finder find = new Finder<>(Long.class, + public static final Finder find = new Finder<>(Long.class, IssueEvent.class); /** diff --git a/app/models/IssueLabelCategory.java b/app/models/IssueLabelCategory.java index 4f72f8fdf..1411f9f21 100644 --- a/app/models/IssueLabelCategory.java +++ b/app/models/IssueLabelCategory.java @@ -21,10 +21,10 @@ package models; import models.enumeration.ResourceType; -import play.db.ebean.Model; import models.resource.Resource; import models.resource.ResourceConvertible; import play.data.validation.Constraints.Required; +import play.db.ebean.Model; import javax.persistence.*; import javax.validation.constraints.Size; diff --git a/app/models/LabelOwner.java b/app/models/LabelOwner.java index f0174d411..ff380c125 100644 --- a/app/models/LabelOwner.java +++ b/app/models/LabelOwner.java @@ -20,10 +20,10 @@ */ package models; -import java.util.Set; - import models.resource.ResourceConvertible; +import java.util.Set; + /** * @see models.resource.ResourceConvertible */ diff --git a/app/models/Milestone.java b/app/models/Milestone.java index 5e014cb64..63e7fb4d6 100644 --- a/app/models/Milestone.java +++ b/app/models/Milestone.java @@ -20,20 +20,24 @@ */ package models; -import models.enumeration.*; +import models.enumeration.Direction; +import models.enumeration.Matching; +import models.enumeration.ResourceType; +import models.enumeration.State; import models.resource.Resource; import models.resource.ResourceConvertible; -import models.support.*; - +import models.support.FinderTemplate; +import models.support.OrderParams; +import models.support.SearchParams; import org.apache.commons.lang3.time.DateUtils; -import play.data.format.*; -import play.data.validation.*; -import play.db.ebean.*; +import play.data.format.Formats; +import play.data.validation.Constraints; +import play.db.ebean.Model; import play.i18n.Messages; import utils.JodaDateUtil; import javax.persistence.*; -import java.text.*; +import java.text.SimpleDateFormat; import java.util.*; @Entity diff --git a/app/models/NonRangedCodeCommentThread.java b/app/models/NonRangedCodeCommentThread.java index 62f56c757..6baa3b564 100644 --- a/app/models/NonRangedCodeCommentThread.java +++ b/app/models/NonRangedCodeCommentThread.java @@ -20,9 +20,10 @@ */ package models; +import org.apache.commons.lang3.StringUtils; + import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; -import org.apache.commons.lang3.StringUtils; /** * @author Keesun Baik diff --git a/app/models/NotificationEvent.java b/app/models/NotificationEvent.java index 3fed20cd7..9a820884e 100644 --- a/app/models/NotificationEvent.java +++ b/app/models/NotificationEvent.java @@ -20,7 +20,6 @@ */ package models; -import com.avaje.ebean.RawSql; import com.avaje.ebean.RawSqlBuilder; import controllers.UserApp; import controllers.routes; @@ -42,7 +41,6 @@ import playRepository.*; import scala.concurrent.duration.Duration; import utils.AccessControl; -import utils.Config; import utils.EventConstants; import utils.RouteUtil; @@ -52,7 +50,10 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.*; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -66,7 +67,7 @@ public class NotificationEvent extends Model { @Id public Long id; - public static Finder find = new Finder<>(Long.class, NotificationEvent.class); + public static final Finder find = new Finder<>(Long.class, NotificationEvent.class); public String title; diff --git a/app/models/NotificationMail.java b/app/models/NotificationMail.java index 6727c1755..fcb8c34b6 100644 --- a/app/models/NotificationMail.java +++ b/app/models/NotificationMail.java @@ -20,8 +20,8 @@ */ package models; -import mailbox.EmailAddressWithDetail; import info.schleichardt.play2.mailplugin.Mailer; +import mailbox.EmailAddressWithDetail; import models.enumeration.ResourceType; import models.enumeration.UserState; import models.resource.Resource; @@ -43,11 +43,11 @@ import utils.Markdown; import utils.Url; +import javax.annotation.Nullable; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; -import javax.annotation.Nullable; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToOne; @@ -69,7 +69,7 @@ public class NotificationMail extends Model { @OneToOne public NotificationEvent notificationEvent; - public static Finder find = new Finder<>(Long.class, + public static final Finder find = new Finder<>(Long.class, NotificationMail.class); public static void onStart() { diff --git a/app/models/OrganizationUser.java b/app/models/OrganizationUser.java index eb39278cd..248dd826d 100644 --- a/app/models/OrganizationUser.java +++ b/app/models/OrganizationUser.java @@ -20,14 +20,13 @@ */ package models; -import java.util.List; +import models.enumeration.RoleType; +import play.db.ebean.Model; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; - -import models.enumeration.RoleType; -import play.db.ebean.Model; +import java.util.List; @Entity public class OrganizationUser extends Model { diff --git a/app/models/PostingComment.java b/app/models/PostingComment.java index 734a13ac3..4cfe97f92 100644 --- a/app/models/PostingComment.java +++ b/app/models/PostingComment.java @@ -23,12 +23,13 @@ import models.enumeration.ResourceType; import models.resource.Resource; -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.ManyToOne; @Entity public class PostingComment extends Comment { private static final long serialVersionUID = 1L; - public static Finder find = new Finder<>(Long.class, PostingComment.class); + public static final Finder find = new Finder<>(Long.class, PostingComment.class); @ManyToOne public Posting posting; diff --git a/app/models/Project.java b/app/models/Project.java index d63139ce4..742e81362 100644 --- a/app/models/Project.java +++ b/app/models/Project.java @@ -46,7 +46,10 @@ import javax.persistence.*; import javax.servlet.ServletException; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Set; @Entity public class Project extends Model implements LabelOwner { diff --git a/app/models/ProjectMenuSetting.java b/app/models/ProjectMenuSetting.java index fbcb85e5d..2bffc0d5b 100644 --- a/app/models/ProjectMenuSetting.java +++ b/app/models/ProjectMenuSetting.java @@ -22,7 +22,9 @@ import play.db.ebean.Model; -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; @Entity public class ProjectMenuSetting extends Model { diff --git a/app/models/ProjectTransfer.java b/app/models/ProjectTransfer.java index 0a1ce8b3d..4707b63f1 100644 --- a/app/models/ProjectTransfer.java +++ b/app/models/ProjectTransfer.java @@ -38,7 +38,7 @@ public class ProjectTransfer extends Model implements ResourceConvertible { private static final long serialVersionUID = 1L; - public static Finder find = new Finder<>(Long.class, ProjectTransfer.class); + public static final Finder find = new Finder<>(Long.class, ProjectTransfer.class); @Id public Long id; diff --git a/app/models/ProjectUser.java b/app/models/ProjectUser.java index 6442d9a03..64034708e 100644 --- a/app/models/ProjectUser.java +++ b/app/models/ProjectUser.java @@ -20,14 +20,15 @@ */ package models; -import java.util.*; +import models.enumeration.RoleType; +import play.db.ebean.Model; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; - -import models.enumeration.RoleType; -import play.db.ebean.Model; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; @Entity public class ProjectUser extends Model { diff --git a/app/models/Property.java b/app/models/Property.java index 9598d6263..70009942e 100644 --- a/app/models/Property.java +++ b/app/models/Property.java @@ -24,6 +24,7 @@ import play.db.ebean.Model; import utils.Diagnostic; +import javax.annotation.Nonnull; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -91,7 +92,7 @@ public static enum Name { public static void onStart() { Diagnostic.register(new Diagnostic() { @Override - public List check() { + public @Nonnull List check() { List errors = new ArrayList<>(); for (Property.Name name : Property.Name.values()) { diff --git a/app/models/PullRequest.java b/app/models/PullRequest.java index 534a7c74e..5c982ca43 100644 --- a/app/models/PullRequest.java +++ b/app/models/PullRequest.java @@ -571,9 +571,9 @@ public String fetchSourceBranch() throws IOException, GitAPIException { return destination; } - public void updateMergedCommitId(Merger.MergeResult merger) { - mergedCommitIdFrom = merger.getLeftParentId().getName(); - mergedCommitIdTo = merger.getMergeCommitId().getName(); + public void updateMergedCommitId(Merger.MergeResult mergeResult) { + mergedCommitIdFrom = mergeResult.getLeftParentId().getName(); + mergedCommitIdTo = mergeResult.getMergeCommitId().getName(); update(); } diff --git a/app/models/PullRequestCommit.java b/app/models/PullRequestCommit.java index 829beb72c..2e12e83a5 100644 --- a/app/models/PullRequestCommit.java +++ b/app/models/PullRequestCommit.java @@ -20,28 +20,22 @@ */ package models; -import java.util.Date; -import java.util.List; - -import javax.annotation.Nonnull; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.Transient; - import org.apache.commons.lang3.StringUtils; import play.db.ebean.Model; import playRepository.GitCommit; import utils.JodaDateUtil; +import javax.annotation.Nonnull; +import javax.persistence.*; +import java.util.Date; +import java.util.List; + @Entity public class PullRequestCommit extends Model implements TimelineItem { private static final long serialVersionUID = -4343181252386722689L; - public static Finder find = new Finder<>(Long.class, PullRequestCommit.class); + public static final Finder find = new Finder<>(Long.class, PullRequestCommit.class); @Id public String id; diff --git a/app/models/PullRequestEvent.java b/app/models/PullRequestEvent.java index 3b847e88a..41ed61f76 100644 --- a/app/models/PullRequestEvent.java +++ b/app/models/PullRequestEvent.java @@ -20,26 +20,25 @@ */ package models; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import javax.persistence.*; - -import org.apache.commons.lang3.StringUtils; import models.enumeration.EventType; import models.enumeration.State; +import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; import play.db.ebean.Model; import utils.EventConstants; import utils.JodaDateUtil; +import javax.persistence.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + @Entity public class PullRequestEvent extends Model implements TimelineItem { private static final long serialVersionUID = 1981361242582594128L; - public static Finder finder = new Finder<>(Long.class, PullRequestEvent.class); + public static final Finder finder = new Finder<>(Long.class, PullRequestEvent.class); @Id public Long id; diff --git a/app/models/PushedBranch.java b/app/models/PushedBranch.java index 8c8384a39..df21f4570 100644 --- a/app/models/PushedBranch.java +++ b/app/models/PushedBranch.java @@ -20,19 +20,17 @@ */ package models; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import org.apache.commons.lang.StringUtils; +import org.eclipse.jgit.lib.Constants; +import play.db.ebean.Model; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.Table; - -import org.apache.commons.lang.StringUtils; -import org.eclipse.jgit.lib.Constants; - -import play.db.ebean.Model; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; /** * @author Wansoon Park diff --git a/app/models/Role.java b/app/models/Role.java index b5296cdab..602f857d8 100644 --- a/app/models/Role.java +++ b/app/models/Role.java @@ -20,21 +20,20 @@ */ package models; -import java.util.ArrayList; -import java.util.List; +import models.enumeration.RoleType; +import play.db.ebean.Model; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; - -import models.enumeration.RoleType; -import play.db.ebean.Model; +import java.util.ArrayList; +import java.util.List; @Entity public class Role extends Model { private static final long serialVersionUID = 1L; - public static Finder find = new Finder<>(Long.class, + public static final Finder find = new Finder<>(Long.class, Role.class); @Id diff --git a/app/models/Search.java b/app/models/Search.java index 07f17d238..d7f0ad7fb 100644 --- a/app/models/Search.java +++ b/app/models/Search.java @@ -20,7 +20,10 @@ */ package models; -import com.avaje.ebean.*; +import com.avaje.ebean.Expr; +import com.avaje.ebean.ExpressionList; +import com.avaje.ebean.Junction; +import com.avaje.ebean.Page; import models.enumeration.Operation; import models.enumeration.ProjectScope; import models.enumeration.UserState; diff --git a/app/models/SimpleCommentThread.java b/app/models/SimpleCommentThread.java index ea971ce68..4cee2f84e 100644 --- a/app/models/SimpleCommentThread.java +++ b/app/models/SimpleCommentThread.java @@ -23,8 +23,6 @@ import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; -import play.db.ebean.Model.Finder; - /** * @author Keesun Baik */ diff --git a/app/models/SiteAdmin.java b/app/models/SiteAdmin.java index e80f37cd4..708bcfec0 100644 --- a/app/models/SiteAdmin.java +++ b/app/models/SiteAdmin.java @@ -20,15 +20,14 @@ */ package models; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.OneToOne; - import controllers.UserApp; import org.apache.shiro.crypto.RandomNumberGenerator; import org.apache.shiro.crypto.SecureRandomNumberGenerator; import play.db.ebean.Model; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; import java.util.Arrays; @Entity diff --git a/app/models/Unwatch.java b/app/models/Unwatch.java index 2f360598f..0700f56ef 100644 --- a/app/models/Unwatch.java +++ b/app/models/Unwatch.java @@ -22,14 +22,14 @@ import models.enumeration.ResourceType; -import javax.persistence.*; +import javax.persistence.Entity; import java.util.List; @Entity public class Unwatch extends UserAction { private static final long serialVersionUID = 1L; - public static Finder find = new Finder<>(Long.class, Unwatch.class); + public static final Finder find = new Finder<>(Long.class, Unwatch.class); public static List findBy(ResourceType resourceType, String resourceId) { return findBy(find, resourceType, resourceId); diff --git a/app/models/User.java b/app/models/User.java index 2220b5d5e..ba12718dc 100644 --- a/app/models/User.java +++ b/app/models/User.java @@ -20,35 +20,33 @@ */ package models; -import java.text.SimpleDateFormat; -import java.util.*; - -import javax.persistence.*; -import javax.persistence.OrderBy; -import javax.persistence.criteria.Expression; - import com.avaje.ebean.*; import controllers.UserApp; -import models.enumeration.*; +import models.enumeration.ResourceType; +import models.enumeration.RoleType; +import models.enumeration.UserState; import models.resource.GlobalResource; import models.resource.Resource; import models.resource.ResourceConvertible; - import models.support.UserComparator; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.crypto.hash.Sha256Hash; import org.apache.shiro.util.ByteSource; import play.data.format.Formats; import play.data.validation.Constraints; -import play.data.validation.Constraints.*; +import play.data.validation.Constraints.Pattern; +import play.data.validation.Constraints.Required; +import play.data.validation.Constraints.ValidateWith; import play.db.ebean.Model; import play.db.ebean.Transactional; -import scala.reflect.internal.Trees; import play.i18n.Messages; import utils.JodaDateUtil; import utils.ReservedWordsValidator; -import static com.avaje.ebean.Expr.eq; +import javax.persistence.*; +import javax.persistence.OrderBy; +import java.text.SimpleDateFormat; +import java.util.*; @Table(name = "n4user") @Entity diff --git a/app/models/UserProjectNotification.java b/app/models/UserProjectNotification.java index 95f3763c3..1199f5766 100644 --- a/app/models/UserProjectNotification.java +++ b/app/models/UserProjectNotification.java @@ -39,7 +39,7 @@ public class UserProjectNotification extends Model { private static final long serialVersionUID = 1L; - public static Finder find = new Finder<>(Long.class, UserProjectNotification.class); + public static final Finder find = new Finder<>(Long.class, UserProjectNotification.class); @Id public Long id; diff --git a/app/models/Watch.java b/app/models/Watch.java index 91f36bc4d..f5d9f566c 100644 --- a/app/models/Watch.java +++ b/app/models/Watch.java @@ -30,7 +30,7 @@ import org.apache.commons.collections.Predicate; import utils.AccessControl; -import javax.persistence.*; +import javax.persistence.Entity; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -40,7 +40,7 @@ public class Watch extends UserAction { private static final long serialVersionUID = 1L; - public static Finder find = new Finder<>(Long.class, Watch.class); + public static final Finder find = new Finder<>(Long.class, Watch.class); public static List findBy(ResourceType resourceType, String resourceId) { return findBy(find, resourceType, resourceId); diff --git a/app/models/YobiUpdate.java b/app/models/YobiUpdate.java index add27323e..0def29835 100644 --- a/app/models/YobiUpdate.java +++ b/app/models/YobiUpdate.java @@ -23,18 +23,15 @@ import com.github.zafarkhaja.semver.Version; import com.github.zafarkhaja.semver.util.UnexpectedElementTypeException; -import com.typesafe.config.*; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; -import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.lib.Ref; import play.Configuration; -import play.Logger; import play.libs.Akka; import scala.concurrent.duration.Duration; import utils.Config; -import java.util.*; +import java.util.Collection; import java.util.concurrent.TimeUnit; public class YobiUpdate { diff --git a/app/models/enumeration/EventType.java b/app/models/enumeration/EventType.java index f2acc4a66..16324de7d 100644 --- a/app/models/enumeration/EventType.java +++ b/app/models/enumeration/EventType.java @@ -22,7 +22,10 @@ import play.i18n.Messages; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; public enum EventType { diff --git a/app/models/resource/GlobalResource.java b/app/models/resource/GlobalResource.java index 1d13550ec..84f29080e 100644 --- a/app/models/resource/GlobalResource.java +++ b/app/models/resource/GlobalResource.java @@ -21,7 +21,6 @@ package models.resource; import models.Project; -import models.resource.Resource; abstract public class GlobalResource extends Resource { @Override diff --git a/app/models/resource/Resource.java b/app/models/resource/Resource.java index a2d1ee1e9..2211db072 100644 --- a/app/models/resource/Resource.java +++ b/app/models/resource/Resource.java @@ -258,7 +258,7 @@ public static Resource findByPath(String path) { return null; } - ResourceType resourceType = null; + ResourceType resourceType; try { resourceType = ResourceType.getValue(segments[0]); diff --git a/app/models/resource/ResourcePersistAdapter.java b/app/models/resource/ResourcePersistAdapter.java index 7119df445..c81470f80 100644 --- a/app/models/resource/ResourcePersistAdapter.java +++ b/app/models/resource/ResourcePersistAdapter.java @@ -20,14 +20,13 @@ */ package models.resource; -import models.Unwatch; -import models.Watch; - import com.avaje.ebean.EbeanServer; import com.avaje.ebean.Query; import com.avaje.ebean.Transaction; import com.avaje.ebean.event.BeanPersistAdapter; import com.avaje.ebean.event.BeanPersistRequest; +import models.Unwatch; +import models.Watch; /** * @see com.avaje.ebean.event.BeanPersistController diff --git a/app/models/support/FinderTemplate.java b/app/models/support/FinderTemplate.java index 7a9c2a6e1..08a74bdc9 100644 --- a/app/models/support/FinderTemplate.java +++ b/app/models/support/FinderTemplate.java @@ -20,11 +20,12 @@ */ package models.support; -import com.avaje.ebean.*; +import com.avaje.ebean.ExpressionList; +import com.avaje.ebean.Page; +import play.db.ebean.Model; -import play.db.ebean.*; - -import java.util.*; +import java.util.Collection; +import java.util.List; public class FinderTemplate { diff --git a/app/models/support/ModelLock.java b/app/models/support/ModelLock.java index ba2a97854..5eb4062f9 100644 --- a/app/models/support/ModelLock.java +++ b/app/models/support/ModelLock.java @@ -20,12 +20,11 @@ */ package models.support; -import java.util.Map; - import com.google.common.collect.MapMaker; - import play.db.ebean.Model; +import java.util.Map; + public class ModelLock { private final Map locks = new MapMaker().weakValues().makeMap(); diff --git a/app/models/support/Options.java b/app/models/support/Options.java index 0083e1100..2138a64fc 100644 --- a/app/models/support/Options.java +++ b/app/models/support/Options.java @@ -20,7 +20,7 @@ */ package models.support; -import java.util.*; +import java.util.LinkedHashMap; public class Options extends LinkedHashMap { private static final long serialVersionUID = 1L; diff --git a/app/models/support/OrderParam.java b/app/models/support/OrderParam.java index 5c70361eb..3a899b821 100644 --- a/app/models/support/OrderParam.java +++ b/app/models/support/OrderParam.java @@ -20,7 +20,7 @@ */ package models.support; -import models.enumeration.*; +import models.enumeration.Direction; public class OrderParam { diff --git a/app/models/support/OrderParams.java b/app/models/support/OrderParams.java index 54368e1e9..8c631a6eb 100644 --- a/app/models/support/OrderParams.java +++ b/app/models/support/OrderParams.java @@ -20,9 +20,10 @@ */ package models.support; -import models.enumeration.*; +import models.enumeration.Direction; -import java.util.*; +import java.util.ArrayList; +import java.util.List; public class OrderParams { diff --git a/app/models/support/ReviewSearchCondition.java b/app/models/support/ReviewSearchCondition.java index 0b379a5f4..ecbb1078f 100644 --- a/app/models/support/ReviewSearchCondition.java +++ b/app/models/support/ReviewSearchCondition.java @@ -20,19 +20,22 @@ */ package models.support; -import models.*; -import java.util.List; -import com.avaje.ebean.Junction; -import models.enumeration.Direction; import com.avaje.ebean.ExpressionList; +import com.avaje.ebean.Junction; import controllers.AbstractPostingApp; +import models.CommentThread; +import models.Project; +import models.ReviewComment; +import models.enumeration.Direction; import org.apache.commons.lang.StringUtils; +import java.util.List; + /** * The class for searching, sorting and filtering in review menu of a project. */ -public class ReviewSearchCondition extends AbstractPostingApp.SearchCondition { +public class ReviewSearchCondition extends AbstractPostingApp.SearchCondition implements Cloneable { public String state; public Long authorId; public Long participantId; diff --git a/app/models/support/SearchCondition.java b/app/models/support/SearchCondition.java index de787294e..6877c5237 100644 --- a/app/models/support/SearchCondition.java +++ b/app/models/support/SearchCondition.java @@ -36,7 +36,7 @@ import static models.enumeration.ResourceType.ISSUE_COMMENT; import static models.enumeration.ResourceType.ISSUE_POST; -public class SearchCondition extends AbstractPostingApp.SearchCondition { +public class SearchCondition extends AbstractPostingApp.SearchCondition implements Cloneable { public String state; public Boolean commentedCheck; public Long milestoneId; @@ -256,7 +256,7 @@ public ExpressionList asExpressionList(Project project) { Junction junction = el.disjunction(); junction.icontains("title", filter) .icontains("body", filter); - List ids = null; + List ids; if( project == null){ ids = Issue.finder.where() .icontains("comments.contents", filter).findIds(); diff --git a/app/models/support/SearchParam.java b/app/models/support/SearchParam.java index 8aea41308..612259fd3 100644 --- a/app/models/support/SearchParam.java +++ b/app/models/support/SearchParam.java @@ -20,7 +20,7 @@ */ package models.support; -import models.enumeration.*; +import models.enumeration.Matching; public class SearchParam { diff --git a/app/models/support/SearchParams.java b/app/models/support/SearchParams.java index 25e7c00c4..29fa3a69f 100644 --- a/app/models/support/SearchParams.java +++ b/app/models/support/SearchParams.java @@ -20,9 +20,10 @@ */ package models.support; -import models.enumeration.*; +import models.enumeration.Matching; -import java.util.*; +import java.util.ArrayList; +import java.util.List; public class SearchParams { diff --git a/app/playRepository/BareCommit.java b/app/playRepository/BareCommit.java index e8d9652cb..669fdfcd4 100644 --- a/app/playRepository/BareCommit.java +++ b/app/playRepository/BareCommit.java @@ -26,6 +26,7 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.treewalk.CanonicalTreeParser; +import utils.Config; import java.io.File; import java.io.IOException; @@ -36,8 +37,9 @@ import static org.eclipse.jgit.lib.Constants.HEAD; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; -import static utils.LineEnding.*; -import static playRepository.BareRepository.*; +import static playRepository.BareRepository.findFileLineEnding; +import static utils.LineEnding.addEOL; +import static utils.LineEnding.changeLineEnding; public class BareCommit { private PersonIdent personIdent; @@ -138,7 +140,7 @@ private TreeFormatter rebuildExistingTreeWith(String fileName, ObjectId fileObje boolean isInsertedInTree = false; while(!treeParser.eof()){ - String entryName = new String(treeParser.getEntryPathBuffer(), 0, treeParser.getEntryPathLength()); + String entryName = new String(treeParser.getEntryPathBuffer(), 0, treeParser.getEntryPathLength(), Config.getCharset()); String nameForComparison = entryName; if (treeParser.getEntryFileMode() == FileMode.TREE){ @@ -149,12 +151,12 @@ private TreeFormatter rebuildExistingTreeWith(String fileName, ObjectId fileObje isInsertedInTree = true; } else if (nameForComparison.compareTo(fileName) > 0 && isInsertedInTree == false) { formatter.append(fileName, FileMode.REGULAR_FILE, fileObjectId); - formatter.append(entryName.getBytes() + formatter.append(entryName.getBytes(Config.getCharset()) , treeParser.getEntryFileMode() , treeParser.getEntryObjectId()); isInsertedInTree = true; } else { - formatter.append(entryName.getBytes() + formatter.append(entryName.getBytes(Config.getCharset()) , treeParser.getEntryFileMode() , treeParser.getEntryObjectId()); } @@ -174,7 +176,8 @@ private CanonicalTreeParser getCanonicalTreeParser(Repository repository) throws } private ObjectId createGitObjectWithText(String contents) throws IOException { - return objectInserter.insert(OBJ_BLOB, contents.getBytes(), 0, contents.getBytes().length); + byte[] bytes = contents.getBytes(Config.getCharset()); + return objectInserter.insert(OBJ_BLOB, bytes, 0, bytes.length); } private void refUpdate(ObjectId commitId, String refName) throws IOException { diff --git a/app/playRepository/BareRepository.java b/app/playRepository/BareRepository.java index 7e1429254..af4c42eb6 100644 --- a/app/playRepository/BareRepository.java +++ b/app/playRepository/BareRepository.java @@ -36,7 +36,7 @@ import java.io.IOException; import static org.eclipse.jgit.lib.Constants.HEAD; -import static utils.LineEnding.*; +import static utils.LineEnding.findLineEnding; public class BareRepository { /** @@ -58,7 +58,7 @@ public static String readREADME(Project project){ if (loader == null) { return null; } - return new String(loader.getCachedBytes()); + return new String(loader.getCachedBytes(), utils.Config.getCharset()); } public static Repository getRepository(Project project){ @@ -125,7 +125,7 @@ public static EndingType findFileLineEnding(Repository repository, String fileNa if(oldObjectId.equals(ObjectId.zeroId())){ return EndingType.UNDEFINED; } else { - String fileContents = new String(repository.open(oldObjectId).getBytes()); + String fileContents = new String(repository.open(oldObjectId).getBytes(), utils.Config.getCharset()); return findLineEnding(fileContents); } } diff --git a/app/playRepository/GitRepository.java b/app/playRepository/GitRepository.java index ffd5d63bc..b0c6f93f5 100644 --- a/app/playRepository/GitRepository.java +++ b/app/playRepository/GitRepository.java @@ -162,7 +162,7 @@ public static Repository buildGitRepository(Project project, boolean alternatesM } public static void cloneLocalRepository(Project originalProject, Project forkProject) - throws IOException, GitAPIException { + throws Exception { try { cloneHardLinkedRepository(originalProject, forkProject); } catch (Exception e) { @@ -638,7 +638,7 @@ public byte[] getRawFile(String revision, String path) throws IOException { * initializing {@code Cache} used in the repository. */ @Override - public void delete() { + public void delete() throws Exception { repository.close(); WindowCacheConfig config = new WindowCacheConfig(); config.install(); @@ -1065,8 +1065,8 @@ public static Set getRelatedAuthors(Repository repository, String revA, St if (diffs.size() > BLAME_FILE_LIMIT) { String msg = String.format("Reject to get related authors " + "from changes because of performance issue: The " + - "changes include %n files and it exceeds our limit " + - "of '%n' files.", diffs.size(), BLAME_FILE_LIMIT); + "changes include %d files and it exceeds our limit " + + "of '%d' files.", diffs.size(), BLAME_FILE_LIMIT); throw new LimitExceededException(msg); } diff --git a/app/playRepository/PlayRepository.java b/app/playRepository/PlayRepository.java index c63086f32..d27fb9096 100644 --- a/app/playRepository/PlayRepository.java +++ b/app/playRepository/PlayRepository.java @@ -42,7 +42,7 @@ public interface PlayRepository { public abstract byte[] getRawFile(String revision, String path) throws IOException, SVNException; - public abstract void delete(); + public abstract void delete() throws Exception; public abstract String getPatch(String commitId) throws IOException, SVNException; diff --git a/app/playRepository/RepositoryService.java b/app/playRepository/RepositoryService.java index 609d78b8d..f1e5c321a 100644 --- a/app/playRepository/RepositoryService.java +++ b/app/playRepository/RepositoryService.java @@ -59,7 +59,7 @@ public static Map vcsTypes() { * @see {@link playRepository.PlayRepository#delete()} */ public static void deleteRepository(Project project) - throws IOException, ServletException { + throws Exception { RepositoryService.getRepository(project).delete(); } @@ -67,8 +67,7 @@ public static void deleteRepository(Project project) * @see {@link #deleteRepository(Project)} * @see {@link PlayRepository#create()} */ - public static void createRepository(Project project) throws IOException, ServletException, - UnsupportedOperationException, SVNException { + public static void createRepository(Project project) throws Exception { RepositoryService.deleteRepository(project); RepositoryService.getRepository(project).create(); } diff --git a/app/playRepository/SVNRepository.java b/app/playRepository/SVNRepository.java index 07804796f..d590d621f 100644 --- a/app/playRepository/SVNRepository.java +++ b/app/playRepository/SVNRepository.java @@ -40,13 +40,11 @@ import org.tmatesoft.svn.core.wc.SVNDiffClient; import org.tmatesoft.svn.core.wc.SVNRevision; import play.libs.Json; +import utils.Config; import utils.FileUtil; import utils.GravatarUtil; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; +import java.io.*; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -210,22 +208,22 @@ public void create() throws SVNException { } @Override - public void delete() { + public void delete() throws Exception { FileUtil.rm_rf(new File(getRepoPrefix() + ownerName + "/" + projectName)); } @Override - public String getPatch(String commitId) throws SVNException { + public String getPatch(String commitId) throws SVNException, UnsupportedEncodingException { long rev = Integer.parseInt(commitId); return getPatch(rev - 1, rev); } @Override - public String getPatch(String revA, String revB) throws SVNException { + public String getPatch(String revA, String revB) throws SVNException, UnsupportedEncodingException { return getPatch(Long.parseLong(revA), Long.parseLong(revB)); } - private String getPatch(long revA, long revB) throws SVNException { + private String getPatch(long revA, long revB) throws SVNException, UnsupportedEncodingException { // Prepare required arguments. SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName)); @@ -239,7 +237,7 @@ private String getPatch(long revA, long revB) throws SVNException { diffClient.doDiff(svnURL, null, SVNRevision.create(revA), SVNRevision.create(revB), SVNDepth.INFINITY, true, byteArrayOutputStream); - return byteArrayOutputStream.toString(); + return byteArrayOutputStream.toString(Config.getCharset().name()); } @Override @@ -346,7 +344,7 @@ public boolean isFile(String path) throws SVNException, IOException { @Override public boolean isFile(String path, String revStr) throws SVNException { - return isFile(path, Long.valueOf(revStr)); + return isFile(path, Long.parseLong(revStr)); } diff --git a/app/utils/BasicAuthAction.java b/app/utils/BasicAuthAction.java index 23060e1cc..061427113 100644 --- a/app/utils/BasicAuthAction.java +++ b/app/utils/BasicAuthAction.java @@ -23,14 +23,13 @@ import controllers.UserApp; import models.User; import org.apache.commons.codec.binary.Base64; +import play.libs.F.Promise; import play.mvc.Action; import play.mvc.Http; import play.mvc.Http.Context; import play.mvc.Http.Request; import play.mvc.Http.Response; import play.mvc.Result; -import play.mvc.Result; -import play.libs.F.Promise; import java.io.UnsupportedEncodingException; @@ -59,10 +58,7 @@ public static User parseCredentials(String credentials) throws MalformedCredenti return null; } - String userpassBase64 = credentials.substring(6); - byte[] userpassBytes; - - userpassBytes = Base64.decodeBase64(userpassBase64.getBytes()); + byte[] userpassBytes = Base64.decodeBase64(credentials.substring(6)); // Use ISO-8859-1 only and not others, even if in RFC 2616, Section 2.2 "Basic Rules" allows // TEXT to be encoded according to the rules of RFC 2047. diff --git a/app/utils/Config.java b/app/utils/Config.java index 685af29b5..6d144cf6f 100644 --- a/app/utils/Config.java +++ b/app/utils/Config.java @@ -26,6 +26,7 @@ import play.mvc.Http; import java.net.*; +import java.nio.charset.Charset; import java.util.Enumeration; public class Config { @@ -56,10 +57,6 @@ public static String getSiteName() { public static String getHostport(String defaultValue) { play.Configuration config = play.Configuration.root(); - if (config == null) { - return defaultValue; - } - String hostname = play.Configuration.root().getString("application.hostname"); if (hostname != null && !hostname.isEmpty()) { @@ -106,11 +103,9 @@ private static InetAddress getDefaultAddress() throws SocketException, UnknownHo public static String getHostname() { play.Configuration config = play.Configuration.root(); - if (config != null) { - String hostname = play.Configuration.root().getString("application.hostname"); - if (hostname != null && !hostname.isEmpty()) { - return hostname; - } + String hostname = play.Configuration.root().getString("application.hostname"); + if (hostname != null && !hostname.isEmpty()) { + return hostname; } try { @@ -139,10 +134,6 @@ public static String getHostport() { public static String getScheme(String defaultValue) { play.Configuration config = play.Configuration.root(); - if (config == null) { - return defaultValue; - } - String scheme = config.getString("application.scheme"); if (scheme == null || scheme.isEmpty()) { @@ -281,4 +272,8 @@ private static String getEmail(String prefix) { return user + "@" + config.getString(prefix + ".domain", getHostname()); } } + + public static Charset getCharset() { + return Charset.forName("UTF-8"); + } } diff --git a/app/utils/FastHttpDateFormat.java b/app/utils/FastHttpDateFormat.java index 59d353367..f34196a6d 100644 --- a/app/utils/FastHttpDateFormat.java +++ b/app/utils/FastHttpDateFormat.java @@ -14,14 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package utils; -import play.*; - -import java.text.*; -import java.util.*; -import java.util.concurrent.*; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; +import java.util.concurrent.ConcurrentHashMap; /** * Utility class to generate HTTP dates. @@ -34,28 +35,31 @@ public final class FastHttpDateFormat { // -------------------------------------------------------------- Variables - protected static final int CACHE_SIZE = + private static final int CACHE_SIZE = Integer.parseInt(System.getProperty("org.apache.tomcat.util.http.FastHttpDateFormat.CACHE_SIZE", "1000")); /** - * HTTP date format. + * The only date format permitted when generating HTTP headers. */ - protected static final SimpleDateFormat format = - new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); + public static final String RFC1123_DATE = + "EEE, dd MMM yyyy HH:mm:ss zzz"; + + private static final SimpleDateFormat format = + new SimpleDateFormat(RFC1123_DATE, Locale.US); /** * The set of SimpleDateFormat formats to use in getDateHeader(). */ - protected static final SimpleDateFormat formats[] = { - new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US), + private static final SimpleDateFormat formats[] = { + new SimpleDateFormat(RFC1123_DATE, Locale.US), new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US), new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US) }; - protected final static TimeZone gmtZone = TimeZone.getTimeZone("GMT"); + private static final TimeZone gmtZone = TimeZone.getTimeZone("GMT"); /** @@ -75,27 +79,27 @@ public final class FastHttpDateFormat { /** * Instant on which the currentDate object was generated. */ - protected static long currentDateGenerated = 0L; + private static volatile long currentDateGenerated = 0L; /** * Current formatted date. */ - protected static String currentDate = null; + private static String currentDate = null; /** * Formatter cache. */ - protected static final ConcurrentHashMap formatCache = - new ConcurrentHashMap<>(CACHE_SIZE); + private static final ConcurrentHashMap formatCache = + new ConcurrentHashMap<>(CACHE_SIZE); /** * Parser cache. */ - protected static final ConcurrentHashMap parseCache = - new ConcurrentHashMap<>(CACHE_SIZE); + private static final ConcurrentHashMap parseCache = + new ConcurrentHashMap<>(CACHE_SIZE); // --------------------------------------------------------- Public Methods @@ -110,8 +114,8 @@ public static final String getCurrentDate() { if ((now - currentDateGenerated) > 1000) { synchronized (format) { if ((now - currentDateGenerated) > 1000) { - currentDateGenerated = now; currentDate = format.format(new Date(now)); + currentDateGenerated = now; } } } @@ -126,26 +130,24 @@ public static final String getCurrentDate() { public static final String formatDate (long value, DateFormat threadLocalformat) { - Long longValue = value; + Long longValue = new Long(value); String cachedDate = formatCache.get(longValue); - if (cachedDate != null) + if (cachedDate != null) { return cachedDate; + } - String newDate; + String newDate = null; Date dateValue = new Date(value); if (threadLocalformat != null) { newDate = threadLocalformat.format(dateValue); updateFormatCache(longValue, newDate); } else { - synchronized (formatCache) { - synchronized (format) { - newDate = format.format(dateValue); - } - updateFormatCache(longValue, newDate); + synchronized (format) { + newDate = format.format(dateValue); } + updateFormatCache(longValue, newDate); } return newDate; - } @@ -155,27 +157,24 @@ public static final String getCurrentDate() { public static final long parseDate(String value, DateFormat[] threadLocalformats) { - Logger.debug("parseDate " + value); Long cachedDate = parseCache.get(value); - if (cachedDate != null) - return cachedDate; + if (cachedDate != null) { + return cachedDate.longValue(); + } - Long date; + Long date = null; if (threadLocalformats != null) { date = internalParseDate(value, threadLocalformats); updateParseCache(value, date); } else { - synchronized (parseCache) { - date = internalParseDate(value, formats); - updateParseCache(value, date); - } + date = internalParseDate(value, formats); + updateParseCache(value, date); } if (date == null) { return (-1L); - } else { - return date; } + return date.longValue(); } @@ -188,13 +187,14 @@ public static final long parseDate(String value, for (int i = 0; (date == null) && (i < formats.length); i++) { try { date = formats[i].parse(value); - } catch (ParseException ignored) { + } catch (ParseException e) { + // Ignore } } if (date == null) { return null; } - return date.getTime(); + return new Long(date.getTime()); } diff --git a/app/utils/FileUtil.java b/app/utils/FileUtil.java index 29eb55f28..ce6a51544 100644 --- a/app/utils/FileUtil.java +++ b/app/utils/FileUtil.java @@ -32,11 +32,12 @@ public class FileUtil { - public static final int MAX_SIZE_FOR_BINARY_DETECTION = 512; - - public static void rm_rf(File file){ + public static void rm_rf(File file) throws Exception { if(file.isDirectory()){ File[] list = file.listFiles(); + if (list == null) { + throw new Exception("Unexpected error while deleting: " + file); + } for (File f : list) { rm_rf(f); } diff --git a/app/utils/Markdown.java b/app/utils/Markdown.java index 02634d6ff..069c84ffa 100644 --- a/app/utils/Markdown.java +++ b/app/utils/Markdown.java @@ -34,6 +34,7 @@ import java.io.Reader; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.Charset; public class Markdown { @@ -50,15 +51,15 @@ private static ScriptEngine buildEngine() { try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(XSS_JS_FILE); - reader = new InputStreamReader(is); + reader = new InputStreamReader(is, Config.getCharset()); _engine.eval(reader); is = Thread.currentThread().getContextClassLoader().getResourceAsStream(MARKED_JS_FILE); - reader = new InputStreamReader(is); + reader = new InputStreamReader(is, Config.getCharset()); _engine.eval(reader); is = Thread.currentThread().getContextClassLoader().getResourceAsStream(HIGHLIGHT_JS_FILE); - reader = new InputStreamReader(is); + reader = new InputStreamReader(is, Config.getCharset()); _engine.eval(reader); } catch (Exception ex) { throw new RuntimeException(ex); diff --git a/app/utils/MomentUtil.java b/app/utils/MomentUtil.java index a0c485174..d966029bd 100644 --- a/app/utils/MomentUtil.java +++ b/app/utils/MomentUtil.java @@ -46,7 +46,7 @@ private static ScriptEngine buildEngine() { try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(MOMENT_JS_FILE); - reader = new InputStreamReader(is); + reader = new InputStreamReader(is, Config.getCharset()); _engine.eval(reader); } catch (Exception ex) { throw new RuntimeException(ex); diff --git a/app/utils/PlayServletRequest.java b/app/utils/PlayServletRequest.java index 36487df95..ce4a51a72 100644 --- a/app/utils/PlayServletRequest.java +++ b/app/utils/PlayServletRequest.java @@ -20,35 +20,6 @@ */ package utils; -import java.io.*; -import java.net.URI; -import java.net.URISyntaxException; -import java.security.Principal; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import javax.servlet.AsyncContext; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.servlet.http.Part; - import org.tmatesoft.svn.core.internal.util.SVNEncodingUtil; import play.Play; import play.i18n.Lang; @@ -56,6 +27,15 @@ import play.mvc.Http.RawBuffer; import play.mvc.Http.Request; +import javax.servlet.*; +import javax.servlet.http.*; +import java.io.*; +import java.net.URI; +import java.net.URISyntaxException; +import java.security.Principal; +import java.text.SimpleDateFormat; +import java.util.*; + public class PlayServletRequest implements HttpServletRequest { private String characterEncoding; @@ -516,15 +496,7 @@ public HttpSession getSession() { @Override public HttpSession getSession(boolean create) { - if (httpSession != null) { - return httpSession; - } - - if (create) { - return new PlayServletSession(new PlayServletContext()); - } else { - return null; - } + return httpSession; } @Override diff --git a/app/utils/PlayServletResponse.java b/app/utils/PlayServletResponse.java index 44df5faa8..3a29aa566 100644 --- a/app/utils/PlayServletResponse.java +++ b/app/utils/PlayServletResponse.java @@ -25,6 +25,7 @@ import javax.servlet.*; import javax.servlet.http.*; import java.io.*; +import java.nio.charset.Charset; import java.util.*; public class PlayServletResponse implements HttpServletResponse { @@ -116,7 +117,9 @@ public PlayServletResponse(Response response) throws IOException { this.statusLock = new Object(); this.inputStream = new PipedInputStream(); this.outputStream = new ChunkedOutputStream(new PipedOutputStream(this.inputStream)); - this.pw = new PrintWriter(this.outputStream); + this.pw = new PrintWriter( + new BufferedWriter(new OutputStreamWriter(this.outputStream, Config.getCharset())), + false); } @Override @@ -221,7 +224,7 @@ public void addCookie(Cookie cookie) { @Override public void addDateHeader(String name, long date) { - addHeader(name, FastHttpDateFormat.formatDate(date, FastHttpDateFormat.format)); + addHeader(name, FastHttpDateFormat.formatDate(date, null)); } @Override @@ -329,7 +332,7 @@ public void sendRedirect(String location) throws IOException { @Override public void setDateHeader(String name, long date) { - this.response.setHeader(name, FastHttpDateFormat.formatDate(date, FastHttpDateFormat.format)); + this.response.setHeader(name, FastHttpDateFormat.formatDate(date, null)); } @Override diff --git a/app/utils/RouteUtil.java b/app/utils/RouteUtil.java index 5624ca8aa..dea55958b 100644 --- a/app/utils/RouteUtil.java +++ b/app/utils/RouteUtil.java @@ -34,7 +34,7 @@ import utils.TemplateHelper.DiffRenderer$; public class RouteUtil { - public static DiffRenderer$ diffRenderer = new DiffRenderer$(); + public static final DiffRenderer$ diffRenderer = new DiffRenderer$(); public static String getUrl(ResourceType resourceType, String resourceId) { Long longId = Long.valueOf(resourceId); diff --git a/app/utils/TemplateHelper.scala b/app/utils/TemplateHelper.scala index 653528759..9a0dddc4d 100644 --- a/app/utils/TemplateHelper.scala +++ b/app/utils/TemplateHelper.scala @@ -1,5 +1,6 @@ package utils +import org.apache.commons.lang3.StringUtils import play.mvc.Call import org.joda.time.DateTimeConstants import org.apache.commons.io.FilenameUtils @@ -105,10 +106,8 @@ object TemplateHelper { } } - def equals(a: String, b: String) = (a == b) || a.equals(b) - def equalsThen(a: String, b: String, thenStr: String): String = { - if(a != null && b != null && equals(a, b)){ + if(a != null && b != null && StringUtils.equals(a, b)){ thenStr } else { "" @@ -125,7 +124,7 @@ object TemplateHelper { // Whether the given uris are pointing the same resource. def resourceEquals(a: URI, b: URI) = - nullOrEquals(a.getHost, b.getHost) && getPort(a) == getPort(b) && equals(a.getPath, b.getPath) + nullOrEquals(a.getHost, b.getHost) && getPort(a) == getPort(b) && StringUtils.equals(a.getPath, b.getPath) // Get the url to return to the list page from the view page. // Return the referrer if the it is the uri for the list page, an/ return the @@ -520,7 +519,7 @@ object TemplateHelper { } def getCorrectedPath(filePath:String, fileName:String):String = { - if((filePath != "") && (filePath.substring(filePath.length() - 1) == "/")){ + if(StringUtils.isNotEmpty(filePath) && (filePath.substring(filePath.length() - 1) == "/")){ filePath + fileName } else { filePath + "/" + fileName diff --git a/app/views/code/svnDiff.scala.html b/app/views/code/svnDiff.scala.html index 683e96bb7..936e405ad 100644 --- a/app/views/code/svnDiff.scala.html +++ b/app/views/code/svnDiff.scala.html @@ -27,6 +27,7 @@ @import utils.AccessControl._ @import play.libs.Json.toJson @import utils.Markdown +@import org.apache.commons.lang3.StringUtils @projectLayout(Messages("code.commits") + " @" + commit.getId, project, utils.MenuType.CODE) { @projectMenu(project, utils.MenuType.CODE, "main-menu-only") @@ -42,7 +43,7 @@ @defining(RepositoryService.getRepository(project).getBranchNames()) { branches => @for(branch <- branches){ @common.branchItem("history", project, branch, null, - utils.TemplateHelper.equals(branch, selectedBranch)) + StringUtils.equals(branch, selectedBranch)) } } diff --git a/test/controllers/ProjectAppTest.java b/test/controllers/ProjectAppTest.java index a50a1a9c7..28256d293 100644 --- a/test/controllers/ProjectAppTest.java +++ b/test/controllers/ProjectAppTest.java @@ -436,7 +436,7 @@ public void testTransferProjectToWrongUser() { } @Test - public void testAcceptTransfer() throws IOException, ServletException, SVNException { + public void testAcceptTransfer() throws Exception { //Given GitRepository.setRepoPrefix("resources/test/repo/git/"); @@ -462,7 +462,7 @@ public void testAcceptTransfer() throws IOException, ServletException, SVNExcept } @Test - public void testAcceptTransferWithWrongKey() throws IOException, ServletException, SVNException { + public void testAcceptTransferWithWrongKey() throws Exception { //Given GitRepository.setRepoPrefix("resources/test/repo/git/"); diff --git a/test/models/CodeCommentThreadTest.java b/test/models/CodeCommentThreadTest.java index d22419e76..560be1993 100644 --- a/test/models/CodeCommentThreadTest.java +++ b/test/models/CodeCommentThreadTest.java @@ -28,7 +28,6 @@ import org.junit.Test; import playRepository.BareCommit; import playRepository.GitRepository; -import support.Git; import utils.JodaDateUtil; import java.io.File; @@ -55,7 +54,7 @@ public void before() throws IOException, GitAPIException { } @After - public void after() { + public void after() throws Exception { rm_rf(new File(REPO_PREFIX)); } diff --git a/test/models/PullRequestTest.java b/test/models/PullRequestTest.java index 797529a8c..a266d6ca7 100644 --- a/test/models/PullRequestTest.java +++ b/test/models/PullRequestTest.java @@ -20,7 +20,6 @@ */ package models; -import errors.PullRequestException; import org.apache.commons.lang3.time.DateUtils; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; @@ -65,8 +64,7 @@ public class PullRequestTest extends ModelTest { private Project forkedProject; @Before - public void initRepositories() throws IOException, GitAPIException, ServletException, - PullRequestException, SVNException { + public void initRepositories() throws Exception { GitRepository.setRepoPrefix(REPO_PREFIX); app = support.Helpers.makeTestApplication(); @@ -124,7 +122,7 @@ public void initRepositories() throws IOException, GitAPIException, ServletExcep } @After - public void after() { + public void after() throws Exception { rm_rf(new File(REPO_PREFIX)); rm_rf(new File(LOCAL_REPO_PREFIX)); Helpers.stop(app);