use of java.util.regex.Pattern in project lombok by rzwitserloot.
the class CompileChangelog method sectionByVersion.
private static String sectionByVersion(String markdown, String version) {
if (version.toUpperCase().endsWith("-HEAD") || version.toUpperCase().endsWith("-EDGE")) {
version = version.substring(0, version.length() - 5);
}
Pattern p = Pattern.compile("(?is-m)^.*###\\s*v" + version + ".*?\n(.*?)(?:###\\s*v.*)?$");
Matcher m = p.matcher(markdown);
return m.matches() ? m.group(1) : null;
}
use of java.util.regex.Pattern in project dbeaver by serge-rider.
the class MavenArtifact method resolveVersion.
public MavenArtifactVersion resolveVersion(DBRProgressMonitor monitor, String versionRef) throws IOException {
if (CommonUtils.isEmpty(versionRef)) {
throw new IOException("Empty artifact " + this + " version");
}
boolean predefinedVersion = versionRef.equals(MavenArtifactReference.VERSION_PATTERN_RELEASE) || versionRef.equals(MavenArtifactReference.VERSION_PATTERN_LATEST) || versionRef.equals(MavenArtifactReference.VERSION_PATTERN_SNAPSHOT);
boolean lookupVersion = predefinedVersion || isVersionPattern(versionRef);
if (lookupVersion && !metadataLoaded) {
loadMetadata(monitor);
}
String versionInfo;
if (lookupVersion) {
List<String> allVersions = versions;
switch(versionRef) {
case MavenArtifactReference.VERSION_PATTERN_RELEASE:
versionInfo = releaseVersion;
if (!CommonUtils.isEmpty(versionInfo) && DriverUtils.isBetaVersion(versionInfo)) {
versionInfo = null;
}
break;
case MavenArtifactReference.VERSION_PATTERN_LATEST:
versionInfo = latestVersion;
break;
default:
if (versionRef.startsWith("{") && versionRef.endsWith("}")) {
// Regex - find most recent version matching this pattern
String regex = versionRef.substring(1, versionRef.length() - 1);
try {
Pattern versionPattern = Pattern.compile(regex);
List<String> versions = new ArrayList<>(allVersions);
for (Iterator<String> iter = versions.iterator(); iter.hasNext(); ) {
if (!versionPattern.matcher(iter.next()).matches()) {
iter.remove();
}
}
versionInfo = DriverUtils.findLatestVersion(versions);
} catch (Exception e) {
throw new IOException("Bad version pattern: " + regex);
}
} else {
versionInfo = getVersionFromSpec(versionRef);
}
break;
}
if (versionInfo == null) {
if (allVersions.isEmpty()) {
throw new IOException("Artifact '" + this + "' has empty version list");
}
// Use latest version
versionInfo = DriverUtils.findLatestVersion(allVersions);
}
} else {
if (versionRef.startsWith("[") || versionRef.startsWith("(")) {
versionInfo = getVersionFromSpec(versionRef);
} else {
versionInfo = versionRef;
}
}
MavenArtifactVersion localVersion = getVersion(versionInfo);
if (localVersion == null) {
localVersion = makeLocalVersion(monitor, versionInfo, lookupVersion);
}
return localVersion;
}
use of java.util.regex.Pattern in project dbeaver by serge-rider.
the class MavenArtifact method parseDirectory.
private void parseDirectory(InputStream dirStream) throws IOException, XMLException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copyStream(dirStream, baos);
String dir = baos.toString();
Pattern hrefPattern = Pattern.compile("a href=\"(.+)/?\"");
Matcher matcher = hrefPattern.matcher(dir);
while (matcher.find()) {
String href = matcher.group(1);
while (href.endsWith("/")) {
href = href.substring(0, href.length() - 1);
}
int divPos = href.lastIndexOf('/');
if (divPos != -1) {
href = href.substring(divPos + 1);
}
if (href.equals("..")) {
continue;
}
versions.add(href);
}
}
use of java.util.regex.Pattern in project dbeaver by serge-rider.
the class OracleUtils method insertCreateReplace.
public static String insertCreateReplace(OracleSourceObject object, boolean body, String source) {
String sourceType = object.getSourceType().name();
if (body) {
sourceType += " BODY";
}
Pattern srcPattern = Pattern.compile("^(" + sourceType + ")\\s+(\"{0,1}\\w+\"{0,1})", Pattern.CASE_INSENSITIVE);
Matcher matcher = srcPattern.matcher(source);
if (matcher.find()) {
return "CREATE OR REPLACE " + matcher.group(1) + " " + DBUtils.getQuotedIdentifier(object.getSchema()) + "." + matcher.group(2) + source.substring(matcher.end());
}
return source;
}
use of java.util.regex.Pattern in project AndResGuard by shwenzhang.
the class ARSCDecoder method readEntry.
/**
* 需要防止由于某些非常恶心的白名单,导致出现重复id
*
* @throws IOException
* @throws AndrolibException
*/
private void readEntry() throws IOException, AndrolibException {
mIn.skipBytes(2);
short flags = mIn.readShort();
int specNamesId = mIn.readInt();
if (mPkg.isCanProguard()) {
//混效过,或者已经添加到白名单的都不需要再处理了
if (!mProguardBuilder.isReplaced(mCurEntryID) && !mProguardBuilder.isInWhiteList(mCurEntryID)) {
Configuration config = mApkDecoder.getConfig();
boolean isWhiteList = false;
if (config.mUseWhiteList) {
//判断是否走whitelist
HashMap<String, HashMap<String, HashSet<Pattern>>> whiteList = config.mWhiteList;
String packName = mPkg.getName();
if (whiteList.containsKey(packName)) {
HashMap<String, HashSet<Pattern>> typeMaps = whiteList.get(packName);
String typeName = mType.getName();
if (typeMaps.containsKey(typeName)) {
String specName = mSpecNames.get(specNamesId).toString();
HashSet<Pattern> patterns = typeMaps.get(typeName);
for (Iterator<Pattern> it = patterns.iterator(); it.hasNext(); ) {
Pattern p = it.next();
if (p.matcher(specName).matches()) {
mPkg.putSpecNamesReplace(mResId, specName);
mPkg.putSpecNamesblock(specName);
mProguardBuilder.setInWhiteList(mCurEntryID, true);
mType.putSpecProguardName(specName);
isWhiteList = true;
break;
}
}
}
}
}
String replaceString = null;
if (!isWhiteList) {
boolean keepMapping = false;
if (config.mUseKeepMapping) {
HashMap<String, HashMap<String, HashMap<String, String>>> resMapping = config.mOldResMapping;
String packName = mPkg.getName();
if (resMapping.containsKey(packName)) {
HashMap<String, HashMap<String, String>> typeMaps = resMapping.get(packName);
String typeName = mType.getName();
if (typeMaps.containsKey(typeName)) {
//这里面的东东已经提前去掉,请放心使用
HashMap<String, String> proguard = typeMaps.get(typeName);
String specName = mSpecNames.get(specNamesId).toString();
if (proguard.containsKey(specName)) {
keepMapping = true;
replaceString = proguard.get(specName);
}
}
}
}
if (!keepMapping) {
replaceString = mProguardBuilder.getReplaceString();
}
mProguardBuilder.setInReplaceList(mCurEntryID, true);
if (replaceString == null) {
throw new AndrolibException("readEntry replaceString == null");
}
generalResIDMapping(mPkg.getName(), mType.getName(), mSpecNames.get(specNamesId).toString(), replaceString);
mPkg.putSpecNamesReplace(mResId, replaceString);
mPkg.putSpecNamesblock(replaceString);
mType.putSpecProguardName(replaceString);
}
}
}
boolean readDirect;
if ((flags & ENTRY_FLAG_COMPLEX) == 0) {
readDirect = true;
readValue(readDirect, specNamesId);
} else {
readDirect = false;
readComplexEntry(readDirect, specNamesId);
}
}
Aggregations