Merge remote-tracking branch 'airsonic/pr/919'

master
Andrew DeMaria 6 years ago
commit 83882b18d9
No known key found for this signature in database
GPG Key ID: 0A3F5E91F8364EDF
  1. 4
      airsonic-main/src/main/java/org/airsonic/player/ajax/TagService.java
  2. 2
      airsonic-main/src/main/java/org/airsonic/player/command/UserSettingsCommand.java
  3. 5
      airsonic-main/src/main/java/org/airsonic/player/controller/DownloadController.java
  4. 3
      airsonic-main/src/main/java/org/airsonic/player/controller/PlayerSettingsController.java
  5. 6
      airsonic-main/src/main/java/org/airsonic/player/controller/UploadController.java
  6. 3
      airsonic-main/src/main/java/org/airsonic/player/domain/MusicIndex.java
  7. 2
      airsonic-main/src/main/java/org/airsonic/player/domain/PlayQueue.java
  8. 2
      airsonic-main/src/main/java/org/airsonic/player/domain/TranscodeScheme.java
  9. 4
      airsonic-main/src/main/java/org/airsonic/player/domain/Transcoding.java
  10. 11
      airsonic-main/src/main/java/org/airsonic/player/domain/TransferStatus.java
  11. 2
      airsonic-main/src/main/java/org/airsonic/player/domain/User.java
  12. 2
      airsonic-main/src/main/java/org/airsonic/player/io/TranscodeInputStream.java
  13. 2
      airsonic-main/src/main/java/org/airsonic/player/monitor/MetricsManager.java
  14. 3
      airsonic-main/src/main/java/org/airsonic/player/service/LastFmService.java
  15. 4
      airsonic-main/src/main/java/org/airsonic/player/service/MediaFileService.java
  16. 8
      airsonic-main/src/main/java/org/airsonic/player/service/MusicIndexService.java
  17. 10
      airsonic-main/src/main/java/org/airsonic/player/service/PodcastService.java
  18. 4
      airsonic-main/src/main/java/org/airsonic/player/service/SecurityService.java
  19. 2
      airsonic-main/src/main/java/org/airsonic/player/service/SettingsService.java
  20. 2
      airsonic-main/src/main/java/org/airsonic/player/service/SonosService.java
  21. 4
      airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java
  22. 4
      airsonic-main/src/main/java/org/airsonic/player/service/sonos/SonosHelper.java
  23. 2
      airsonic-main/src/main/java/org/airsonic/player/taglib/UrlTag.java
  24. 7
      airsonic-main/src/main/java/org/airsonic/player/util/StringUtil.java
  25. 18
      airsonic-main/src/test/java/org/airsonic/player/service/PlaylistServiceTestImport.java

@ -73,7 +73,7 @@ public class TagService {
Integer trackNumber = null; Integer trackNumber = null;
if (track != null) { if (track != null) {
try { try {
trackNumber = new Integer(track); trackNumber = Integer.valueOf(track);
} catch (NumberFormatException x) { } catch (NumberFormatException x) {
LOG.warn("Illegal track number: " + track, x); LOG.warn("Illegal track number: " + track, x);
} }
@ -82,7 +82,7 @@ public class TagService {
Integer yearNumber = null; Integer yearNumber = null;
if (year != null) { if (year != null) {
try { try {
yearNumber = new Integer(year); yearNumber = Integer.valueOf(year);
} catch (NumberFormatException x) { } catch (NumberFormatException x) {
LOG.warn("Illegal year: " + year, x); LOG.warn("Illegal year: " + year, x);
} }

@ -295,7 +295,7 @@ public class UserSettingsCommand {
isSettingsRole = user != null && user.isSettingsRole(); isSettingsRole = user != null && user.isSettingsRole();
isShareRole = user != null && user.isShareRole(); isShareRole = user != null && user.isShareRole();
isLdapAuthenticated = user != null && user.isLdapAuthenticated(); isLdapAuthenticated = user != null && user.isLdapAuthenticated();
setNewUser(false); isNewUser = false;
} }
} }

@ -368,9 +368,8 @@ public class DownloadController implements LastModified {
*/ */
private long computeCrc(File file) throws IOException { private long computeCrc(File file) throws IOException {
CRC32 crc = new CRC32(); CRC32 crc = new CRC32();
InputStream in = new FileInputStream(file);
try { try (InputStream in = new FileInputStream(file)) {
byte[] buf = new byte[8192]; byte[] buf = new byte[8192];
int n = in.read(buf); int n = in.read(buf);
@ -379,8 +378,6 @@ public class DownloadController implements LastModified {
n = in.read(buf); n = in.read(buf);
} }
} finally {
in.close();
} }
return crc.getValue(); return crc.getValue();

@ -106,8 +106,9 @@ public class PlayerSettingsController {
command.setAdmin(user.isAdminRole()); command.setAdmin(user.isAdminRole());
command.setJavaJukeboxMixers(Arrays.stream(AudioSystemUtils.listAllMixers()).map(info -> info.getName()).toArray(String[]::new)); command.setJavaJukeboxMixers(Arrays.stream(AudioSystemUtils.listAllMixers()).map(info -> info.getName()).toArray(String[]::new));
if (player != null) {
command.setJavaJukeboxMixer(player.getJavaJukeboxMixer()); command.setJavaJukeboxMixer(player.getJavaJukeboxMixer());
}
model.addAttribute("command",command); model.addAttribute("command",command);
} }

@ -166,9 +166,7 @@ public class UploadController {
private void unzip(File file, List<File> unzippedFiles) throws Exception { private void unzip(File file, List<File> unzippedFiles) throws Exception {
LOG.info("Unzipping " + file); LOG.info("Unzipping " + file);
ZipFile zipFile = new ZipFile(file); try (ZipFile zipFile = new ZipFile(file)) {
try {
Enumeration<?> entries = zipFile.entries(); Enumeration<?> entries = zipFile.entries();
@ -210,8 +208,6 @@ public class UploadController {
zipFile.close(); zipFile.close();
file.delete(); file.delete();
} finally {
zipFile.close();
} }
} }

@ -24,6 +24,7 @@ import java.text.CollationKey;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* A music index is a mapping from an index string to a list of prefixes. A complete index consists of a list of * A music index is a mapping from an index string to a list of prefixes. A complete index consists of a list of
@ -99,7 +100,7 @@ public class MusicIndex implements Serializable {
final MusicIndex musicIndex = (MusicIndex) o; final MusicIndex musicIndex = (MusicIndex) o;
if (index != null ? !index.equals(musicIndex.index) : musicIndex.index != null) { if (!Objects.equals(index, musicIndex.index)) {
return false; return false;
} }

@ -215,10 +215,8 @@ public class PlayQueue {
} }
files.remove(index); files.remove(index);
if (index != -1) {
this.index = Math.max(0, Math.min(this.index, size() - 1)); this.index = Math.max(0, Math.min(this.index, size() - 1));
} }
}
/** /**
* Clears the playlist. * Clears the playlist.

@ -85,7 +85,7 @@ public enum TranscodeScheme {
if (this == OFF) { if (this == OFF) {
return "No limit"; return "No limit";
} }
return "" + getMaxBitRate() + " Kbps"; return getMaxBitRate() + " Kbps";
} }
/** /**

@ -21,6 +21,8 @@ package org.airsonic.player.domain;
import org.airsonic.player.util.StringUtil; import org.airsonic.player.util.StringUtil;
import java.util.Objects;
/** /**
* Contains the configuration for a transcoding, i.e., a specification of how a given media format * Contains the configuration for a transcoding, i.e., a specification of how a given media format
* should be converted to another. * should be converted to another.
@ -213,7 +215,7 @@ public class Transcoding {
} }
Transcoding that = (Transcoding) o; Transcoding that = (Transcoding) o;
return !(id != null ? !id.equals(that.id) : that.id != null); return Objects.equals(id, that.id);
} }
public int hashCode() { public int hashCode() {

@ -234,8 +234,8 @@ public class TransferStatus {
this.active = active; this.active = active;
if (active) { if (active) {
setBytesSkipped(0L); bytesSkipped = 0L;
setBytesTotal(0L); bytesTotal = 0L;
setBytesTransfered(0L); setBytesTransfered(0L);
} else { } else {
createSample(getBytesTransfered(), true); createSample(getBytesTransfered(), true);
@ -281,10 +281,9 @@ public class TransferStatus {
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); String builder = "TransferStatus-" + hashCode() + " [player: " + player.getId() + ", file: " +
builder.append("TransferStatus-").append(hashCode()).append(" [player: ").append(player.getId()).append(", file: "); file + ", terminated: " + terminated + ", active: " + active + "]";
builder.append(file).append(", terminated: ").append(terminated).append(", active: ").append(active).append("]"); return builder;
return builder.toString();
} }
/** /**

@ -206,7 +206,7 @@ public class User {
@Override @Override
public String toString() { public String toString() {
StringBuffer result = new StringBuffer(username); StringBuilder result = new StringBuilder(username);
if (isAdminRole) { if (isAdminRole) {
result.append(" [admin]"); result.append(" [admin]");

@ -56,7 +56,7 @@ public class TranscodeInputStream extends InputStream {
public TranscodeInputStream(ProcessBuilder processBuilder, final InputStream in, File tmpFile) throws IOException { public TranscodeInputStream(ProcessBuilder processBuilder, final InputStream in, File tmpFile) throws IOException {
this.tmpFile = tmpFile; this.tmpFile = tmpFile;
StringBuffer buf = new StringBuffer("Starting transcoder: "); StringBuilder buf = new StringBuilder("Starting transcoder: ");
for (String s : processBuilder.command()) { for (String s : processBuilder.command()) {
buf.append('[').append(s).append("] "); buf.append('[').append(s).append("] ");
} }

@ -49,7 +49,7 @@ public class MetricsManager {
} }
} }
} }
return metricsActivatedByConfiguration.booleanValue(); return metricsActivatedByConfiguration;
} }
/** /**

@ -183,9 +183,8 @@ public class LastFmService {
*/ */
public List<MediaFile> getSimilarSongs(org.airsonic.player.domain.Artist artist, int count, public List<MediaFile> getSimilarSongs(org.airsonic.player.domain.Artist artist, int count,
List<MusicFolder> musicFolders) throws IOException { List<MusicFolder> musicFolders) throws IOException {
List<MediaFile> similarSongs = new ArrayList<MediaFile>();
similarSongs.addAll(mediaFileDao.getSongsByArtist(artist.getName(), 0, 1000)); List<MediaFile> similarSongs = new ArrayList<MediaFile>(mediaFileDao.getSongsByArtist(artist.getName(), 0, 1000));
for (org.airsonic.player.domain.Artist similarArtist : getSimilarArtists(artist, 100, false, musicFolders)) { for (org.airsonic.player.domain.Artist similarArtist : getSimilarArtists(artist, 100, false, musicFolders)) {
similarSongs.addAll(mediaFileDao.getSongsByArtist(similarArtist.getName(), 0, 1000)); similarSongs.addAll(mediaFileDao.getSongsByArtist(similarArtist.getName(), 0, 1000));
} }

@ -347,10 +347,6 @@ public class MediaFileService {
/** /**
* Returns random songs matching search criteria. * Returns random songs matching search criteria.
* *
* @param criteria Random search criteria.
* @param count Max number of songs to return.
* @return Random songs
* @see SearchService.getRandomSongs
*/ */
public List<MediaFile> getRandomSongs(RandomSearchCriteria criteria, String username) { public List<MediaFile> getRandomSongs(RandomSearchCriteria criteria, String username) {
return mediaFileDao.getRandomSongs(criteria, username); return mediaFileDao.getRandomSongs(criteria, username);

@ -265,13 +265,7 @@ public class MusicIndexService {
indexB = Integer.MAX_VALUE; indexB = Integer.MAX_VALUE;
} }
if (indexA < indexB) { return Integer.compare(indexA, indexB);
return -1;
}
if (indexA > indexB) {
return 1;
}
return 0;
} }
} }
} }

@ -450,7 +450,7 @@ public class PodcastService {
if (getEpisodeByUrl(url) == null) { if (getEpisodeByUrl(url) == null) {
Long length = null; Long length = null;
try { try {
length = new Long(enclosure.getAttributeValue("length")); length = Long.valueOf(enclosure.getAttributeValue("length"));
} catch (Exception x) { } catch (Exception x) {
LOG.warn("Failed to parse enclosure length.", x); LOG.warn("Failed to parse enclosure length.", x);
} }
@ -470,13 +470,7 @@ public class PodcastService {
long timeA = a.getPublishDate() == null ? 0L : a.getPublishDate().getTime(); long timeA = a.getPublishDate() == null ? 0L : a.getPublishDate().getTime();
long timeB = b.getPublishDate() == null ? 0L : b.getPublishDate().getTime(); long timeB = b.getPublishDate() == null ? 0L : b.getPublishDate().getTime();
if (timeA < timeB) { return Long.compare(timeB, timeA);
return 1;
}
if (timeA > timeB) {
return -1;
}
return 0;
} }
}); });

@ -96,8 +96,8 @@ public class SecurityService implements UserDetailsService {
List<GrantedAuthority> authorities = new ArrayList<>(); List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("IS_AUTHENTICATED_ANONYMOUSLY")); authorities.add(new SimpleGrantedAuthority("IS_AUTHENTICATED_ANONYMOUSLY"));
authorities.add(new SimpleGrantedAuthority("ROLE_USER")); authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
for (int i = 0; i < roles.length; i++) { for (String role : roles) {
authorities.add(new SimpleGrantedAuthority("ROLE_" + roles[i].toUpperCase())); authorities.add(new SimpleGrantedAuthority("ROLE_" + role.toUpperCase()));
} }
return authorities; return authorities;
} }

@ -606,7 +606,7 @@ public class SettingsService {
* @param limit The download bitrate limit in Kbit/s. Zero if unlimited. * @param limit The download bitrate limit in Kbit/s. Zero if unlimited.
*/ */
public void setDownloadBitrateLimit(long limit) { public void setDownloadBitrateLimit(long limit) {
setProperty(KEY_DOWNLOAD_BITRATE_LIMIT, "" + limit); setProperty(KEY_DOWNLOAD_BITRATE_LIMIT, String.valueOf(limit));
} }
/** /**

@ -464,7 +464,7 @@ public class SonosService implements SonosSoap {
if (StringUtils.isNumeric(part)) { if (StringUtils.isNumeric(part)) {
result.add(Integer.parseInt(part)); result.add(Integer.parseInt(part));
} else { } else {
int dashIndex = part.indexOf("-"); int dashIndex = part.indexOf('-');
int from = Integer.parseInt(part.substring(0, dashIndex)); int from = Integer.parseInt(part.substring(0, dashIndex));
int to = Integer.parseInt(part.substring(dashIndex + 1)); int to = Integer.parseInt(part.substring(dashIndex + 1));
for (int i = from; i <= to; i++) { for (int i = from; i <= to; i++) {

@ -161,7 +161,7 @@ public class JaudiotaggerParser extends MetaDataParser {
Integer result = null; Integer result = null;
try { try {
result = new Integer(trackNumber); result = Integer.valueOf(trackNumber);
} catch (NumberFormatException x) { } catch (NumberFormatException x) {
Matcher matcher = TRACK_NUMBER_PATTERN.matcher(trackNumber); Matcher matcher = TRACK_NUMBER_PATTERN.matcher(trackNumber);
if (matcher.matches()) { if (matcher.matches()) {
@ -187,7 +187,7 @@ public class JaudiotaggerParser extends MetaDataParser {
Integer result = null; Integer result = null;
try { try {
result = new Integer(year); result = Integer.valueOf(year);
} catch (NumberFormatException x) { } catch (NumberFormatException x) {
Matcher matcher = YEAR_NUMBER_PATTERN.matcher(year); Matcher matcher = YEAR_NUMBER_PATTERN.matcher(year);
if (matcher.matches()) { if (matcher.matches()) {

@ -118,9 +118,7 @@ public class SonosHelper {
List<MediaFile> albums = searchService.getRandomAlbums(40, musicFolders); List<MediaFile> albums = searchService.getRandomAlbums(40, musicFolders);
List<MediaFile> songs = new ArrayList<MediaFile>(); List<MediaFile> songs = new ArrayList<MediaFile>();
for (MediaFile album : albums) { for (MediaFile album : albums) {
for (MediaFile file : filterMusic(mediaFileService.getChildrenOf(album, true, false, false))) { songs.addAll(filterMusic(mediaFileService.getChildrenOf(album, true, false, false)));
songs.add(file);
}
} }
Collections.shuffle(songs); Collections.shuffle(songs);
songs = songs.subList(0, Math.min(count, songs.size())); songs = songs.subList(0, Math.min(count, songs.size()));

@ -88,7 +88,7 @@ public class UrlTag extends BodyTagSupport {
private String formatUrl() throws JspException { private String formatUrl() throws JspException {
String baseUrl = UrlSupport.resolveUrl(value, null, pageContext); String baseUrl = UrlSupport.resolveUrl(value, null, pageContext);
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
result.append(baseUrl); result.append(baseUrl);
if (!parameters.isEmpty()) { if (!parameters.isEmpty()) {
result.append('?'); result.append('?');

@ -30,10 +30,7 @@ import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.text.*; import java.text.*;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -327,7 +324,7 @@ public final class StringUtil {
* @return Whether a and b are equal, or both null. * @return Whether a and b are equal, or both null.
*/ */
public static boolean isEqual(Object a, Object b) { public static boolean isEqual(Object a, Object b) {
return a == null ? b == null : a.equals(b); return Objects.equals(a, b);
} }
/** /**

@ -88,9 +88,9 @@ public class PlaylistServiceTestImport {
FileUtils.touch(mf2); FileUtils.touch(mf2);
File mf3 = folder.newFile(); File mf3 = folder.newFile();
FileUtils.touch(mf3); FileUtils.touch(mf3);
builder.append(mf1.getAbsolutePath() + "\n"); builder.append(mf1.getAbsolutePath()).append("\n");
builder.append(mf2.getAbsolutePath() + "\n"); builder.append(mf2.getAbsolutePath()).append("\n");
builder.append(mf3.getAbsolutePath() + "\n"); builder.append(mf3.getAbsolutePath()).append("\n");
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8")); InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
@ -122,9 +122,9 @@ public class PlaylistServiceTestImport {
FileUtils.touch(mf2); FileUtils.touch(mf2);
File mf3 = folder.newFile(); File mf3 = folder.newFile();
FileUtils.touch(mf3); FileUtils.touch(mf3);
builder.append("File1=" + mf1.getAbsolutePath() + "\n"); builder.append("File1=").append(mf1.getAbsolutePath()).append("\n");
builder.append("File2=" + mf2.getAbsolutePath() + "\n"); builder.append("File2=").append(mf2.getAbsolutePath()).append("\n");
builder.append("File3=" + mf3.getAbsolutePath() + "\n"); builder.append("File3=").append(mf3.getAbsolutePath()).append("\n");
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8")); InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
@ -158,9 +158,9 @@ public class PlaylistServiceTestImport {
FileUtils.touch(mf2); FileUtils.touch(mf2);
File mf3 = folder.newFile(); File mf3 = folder.newFile();
FileUtils.touch(mf3); FileUtils.touch(mf3);
builder.append("<track><location>file://" + mf1.getAbsolutePath() + "</location></track>\n"); builder.append("<track><location>file://").append(mf1.getAbsolutePath()).append("</location></track>\n");
builder.append("<track><location>file://" + mf2.getAbsolutePath() + "</location></track>\n"); builder.append("<track><location>file://").append(mf2.getAbsolutePath()).append("</location></track>\n");
builder.append("<track><location>file://" + mf3.getAbsolutePath() + "</location></track>\n"); builder.append("<track><location>file://").append(mf3.getAbsolutePath()).append("</location></track>\n");
builder.append(" </trackList>\n" + "</playlist>\n"); builder.append(" </trackList>\n" + "</playlist>\n");
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));

Loading…
Cancel
Save