mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-17 09:06:55 +01:00
checkstyle/pmd/findbugs fixes
Former-commit-id: ed64aebbc7c5f25978b8e4b6391a6d7fc08749be
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
package org.owasp.dependencycheck.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -63,7 +62,7 @@ public class DependencyVersion implements Iterable {
|
||||
versionParts = new ArrayList<String>();
|
||||
if (version != null) {
|
||||
final Pattern rx = Pattern.compile("(\\d+|[a-z]+\\d+)");
|
||||
Matcher matcher = rx.matcher(version.toLowerCase());
|
||||
final Matcher matcher = rx.matcher(version.toLowerCase());
|
||||
while (matcher.find()) {
|
||||
versionParts.add(matcher.group());
|
||||
}
|
||||
@@ -78,7 +77,7 @@ public class DependencyVersion implements Iterable {
|
||||
private List<String> versionParts;
|
||||
|
||||
/**
|
||||
* Get the value of versionParts
|
||||
* Get the value of versionParts.
|
||||
*
|
||||
* @return the value of versionParts
|
||||
*/
|
||||
@@ -87,7 +86,7 @@ public class DependencyVersion implements Iterable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of versionParts
|
||||
* Set the value of versionParts.
|
||||
*
|
||||
* @param versionParts new value of versionParts
|
||||
*/
|
||||
|
||||
@@ -1,20 +1,37 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* This file is part of DependencyCheck.
|
||||
*
|
||||
* DependencyCheck is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* DependencyCheck 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 General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* DependencyCheck. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* Copyright (c) 2013 Jeremy Long. All Rights Reserved.
|
||||
*/
|
||||
package org.owasp.dependencycheck.utils;
|
||||
|
||||
import java.util.regex.MatchResult;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <p>A utility class to extract version numbers from file names (or other strings
|
||||
* containing version numbers.</p>
|
||||
*
|
||||
* @author Jeremy Long (jeremy.long@gmail.com)
|
||||
*/
|
||||
public final class DependencyVersionUtil {
|
||||
//private final static Pattern RX_VERSION = Pattern.compile("\\d+(\\.\\d+)*(\\d+[a-zA-Z]{1,3}\\d+)?");
|
||||
private final static Pattern RX_VERSION = Pattern.compile("\\d+(\\.\\d+)+(\\.?[a-zA-Z_-]{1,3}\\d+)?");
|
||||
/**
|
||||
* Regular expression to extract version numbers from file names.
|
||||
*/
|
||||
private static final Pattern RX_VERSION = Pattern.compile("\\d+(\\.\\d+)+(\\.?[a-zA-Z_-]{1,3}\\d+)?");
|
||||
|
||||
/**
|
||||
* Private constructor for utility class.
|
||||
@@ -22,12 +39,22 @@ public final class DependencyVersionUtil {
|
||||
private DependencyVersionUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>A utility class to extract version numbers from file names (or other strings
|
||||
* containing version numbers.<br/>
|
||||
* Example:<br/>
|
||||
* Give the file name: library-name-1.4.1r2-release.jar<br/>
|
||||
* This function would return: 1.4.1.r2</p>
|
||||
*
|
||||
* @param filename the filename being analyzed
|
||||
* @return a DependencyVersion containing the version
|
||||
*/
|
||||
public static DependencyVersion parseVersionFromFileName(String filename) {
|
||||
if (filename == null) {
|
||||
return null;
|
||||
}
|
||||
String version = null;
|
||||
Matcher matcher = RX_VERSION.matcher(filename);
|
||||
final Matcher matcher = RX_VERSION.matcher(filename);
|
||||
if (matcher.find()) {
|
||||
version = matcher.group();
|
||||
}
|
||||
@@ -39,30 +66,5 @@ public final class DependencyVersionUtil {
|
||||
return null;
|
||||
}
|
||||
return new DependencyVersion(version);
|
||||
|
||||
|
||||
// String name = null;
|
||||
// final int pos = filename.lastIndexOf('.');
|
||||
// if (pos>0) {
|
||||
// name = filename.substring(0, pos).toLowerCase();
|
||||
// } else {
|
||||
// name = filename.toLowerCase();
|
||||
// }
|
||||
//// if (name.endsWith("-snapshot")) {
|
||||
//// name = name.substring(0,name.length() - 9);
|
||||
//// }
|
||||
//// if (name.endsWith("-release")) {
|
||||
//// name = name.substring(0,name.length() - 8);
|
||||
//// }
|
||||
// final String[] parts = name.split("[_-]");
|
||||
// if (parts == null || parts.length == 0) {
|
||||
// return null;
|
||||
// }
|
||||
// for (int x = parts.length - 1; x >= 0; x--) {
|
||||
// if (RX_VERSION.matcher(parts[x]).matches()) {
|
||||
// return new DependencyVersion(parts[x]);
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user