org.eclipse.jgit.errors.InvalidPatternException Java Examples
The following examples show how to use
org.eclipse.jgit.errors.InvalidPatternException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JGitAPIImpl.java From git-client-plugin with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public Set<String> getRemoteTagNames(String tagPattern) throws GitException { /* BUG: Lists local tag names, not remote tag names */ if (tagPattern == null) tagPattern = "*"; try (Repository repo = getRepository()) { Set<String> tags = new HashSet<>(); FileNameMatcher matcher = new FileNameMatcher(tagPattern, '/'); List<Ref> refList = repo.getRefDatabase().getRefsByPrefix(R_TAGS); for (Ref ref : refList) { String name = ref.getName().substring(R_TAGS.length()); matcher.reset(); matcher.append(name); if (matcher.isMatch()) tags.add(name); } return tags; } catch (IOException | InvalidPatternException e) { throw new GitException(e); } }
Example #2
Source File: JGitAPIImpl.java From git-client-plugin with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public Set<String> getTagNames(String tagPattern) throws GitException { if (tagPattern == null) tagPattern = "*"; Set<String> tags = new HashSet<>(); try (Repository repo = getRepository()) { FileNameMatcher matcher = new FileNameMatcher(tagPattern, null); Map<String, Ref> tagList = repo.getTags(); for (String name : tagList.keySet()) { matcher.reset(); matcher.append(name); if (matcher.isMatch()) tags.add(name); } } catch (InvalidPatternException e) { throw new GitException(e); } return tags; }
Example #3
Source File: WildcardTest.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "pathMatcherData") public static void pathMatcherTest(@NotNull String pattern, @NotNull String path, @Nullable Boolean expectedMatch) throws InvalidPatternException { final Wildcard wildcard = new Wildcard(pattern); PathMatcher matcher = wildcard.getMatcher(); for (String name : WildcardHelper.splitPattern(path)) { if (matcher == null) break; boolean isDir = name.endsWith("/"); matcher = matcher.createChild(isDir ? name.substring(0, name.length() - 1) : name, isDir); } if (expectedMatch == null) { Assert.assertNull(matcher); } else { Assert.assertNotNull(matcher); Assert.assertEquals(matcher.isMatch(), expectedMatch.booleanValue()); } }
Example #4
Source File: WildcardHelper.java From git-lfs-migrate with MIT License | 6 votes |
@NotNull private static NameMatcher nameMatcher(@NotNull String mask) throws InvalidPatternException { if (mask.equals("**/")) { return RecursiveMatcher.INSTANCE; } final boolean dirOnly = mask.endsWith("/"); final String nameMask = tryRemoveBackslashes(dirOnly ? mask.substring(0, mask.length() - 1) : mask); if ((nameMask.indexOf('[') < 0) && (nameMask.indexOf(']') < 0) && (nameMask.indexOf('\\') < 0)) { // Subversion compatible mask. if (nameMask.indexOf('?') < 0) { int asterisk = nameMask.indexOf('*'); if (asterisk < 0) { return new EqualsMatcher(nameMask, dirOnly); } else if (mask.indexOf('*', asterisk + 1) < 0) { return new SimpleMatcher(nameMask.substring(0, asterisk), nameMask.substring(asterisk + 1), dirOnly); } } return new ComplexMatcher(nameMask, dirOnly, true); } else { return new ComplexMatcher(nameMask, dirOnly, false); } }
Example #5
Source File: Wildcard.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
public Wildcard(@NotNull String pattern) throws InvalidPatternException { final NameMatcher[] nameMatchers = createNameMatchers(pattern); if (nameMatchers.length > 0) { if (hasRecursive(nameMatchers)) { if (nameMatchers.length == 2 && nameMatchers[0].isRecursive() && !nameMatchers[1].isRecursive()) { matcher = new FileMaskMatcher(nameMatchers[1]); } else { matcher = new RecursivePathMatcher(nameMatchers); } } else { matcher = new SimplePathMatcher(nameMatchers); } svnCompatible = nameMatchers[nameMatchers.length - 1].getSvnMask() != null; } else { matcher = AlwaysMatcher.INSTANCE; svnCompatible = false; } }
Example #6
Source File: WildcardHelper.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
@NotNull static NameMatcher nameMatcher(@NotNull String mask) throws InvalidPatternException { if (mask.equals("**/")) { return RecursiveMatcher.INSTANCE; } final boolean dirOnly = mask.endsWith("/"); final String nameMask = tryRemoveBackslashes(dirOnly ? mask.substring(0, mask.length() - 1) : mask); if ((nameMask.indexOf('[') < 0) && (nameMask.indexOf(']') < 0) && (nameMask.indexOf('\\') < 0)) { // Subversion compatible mask. if (nameMask.indexOf('?') < 0) { int asterisk = nameMask.indexOf('*'); if (asterisk < 0) { return new EqualsMatcher(nameMask, dirOnly); } else if (mask.indexOf('*', asterisk + 1) < 0) { return new SimpleMatcher(nameMask.substring(0, asterisk), nameMask.substring(asterisk + 1), dirOnly); } } return new ComplexMatcher(nameMask, dirOnly, true); } else { return new ComplexMatcher(nameMask, dirOnly, false); } }
Example #7
Source File: WildcardTest.java From git-lfs-migrate with MIT License | 6 votes |
@Test(dataProvider = "pathMatcherData") public static void nativeMatcherExactTest(@NotNull String pattern, @NotNull String path, @Nullable Boolean ignored, @Nullable Boolean expectedMatch) throws InvalidPatternException, IOException, InterruptedException { Path temp = Files.createTempDirectory("git-matcher"); try { if (new ProcessBuilder() .directory(temp.toFile()) .command("git", "init", ".") .start() .waitFor() != 0) { throw new SkipException("Can't find git"); } Files.write(temp.resolve(".gitattributes"), (pattern + " test\n").getBytes(StandardCharsets.UTF_8)); byte[] output = ByteStreams.toByteArray( new ProcessBuilder() .directory(temp.toFile()) .command("git", "check-attr", "-a", "--", path) .start() .getInputStream() ); Assert.assertEquals(output.length > 0, expectedMatch == Boolean.TRUE); } finally { Files.walkFileTree(temp, new DeleteTreeVisitor()); } }
Example #8
Source File: GitIgnore.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
/** * Parse and store .gitignore data (http://git-scm.com/docs/gitignore). * <p> * Important: * * An optional prefix "!" which negates the pattern is not supported. * * Mask trailing slash is not supported (/foo/bar/ works like /foo/bar). * * @param reader Original file content. */ public GitIgnore(@NotNull BufferedReader reader) throws IOException { final List<String> localList = new ArrayList<>(); final List<String> globalList = new ArrayList<>(); matchers = new ArrayList<>(); String txt; while ((txt = reader.readLine()) != null) { final String line = trimLine(txt); if (line.isEmpty()) continue; try { final Wildcard wildcard = new Wildcard(line); if (wildcard.isSvnCompatible()) { processMatcher(localList, globalList, matchers, wildcard.getMatcher()); } } catch (InvalidPatternException | PatternSyntaxException e) { log.warn("Found invalid git pattern: {}", line); } } local = localList.toArray(emptyStrings); global = globalList.toArray(emptyStrings); }
Example #9
Source File: GitConverter.java From git-lfs-migrate with MIT License | 6 votes |
public GitConverter(@NotNull DB cache, @NotNull Path basePath, @NotNull String[] globs) throws IOException, InvalidPatternException { this.basePath = basePath; this.cache = cache; this.globs = globs.clone(); this.matchers = convertGlobs(globs); Arrays.sort(globs); for (String glob : globs) { new FileNameMatcher(glob, '/'); } tempPath = basePath.resolve("lfs/tmp"); Files.createDirectories(tempPath); //noinspection unchecked cacheMeta = cache.<String, MetaData>hashMap("meta") .keySerializer(Serializer.STRING) .valueSerializer(new SerializerJava()) .createOrOpen(); }
Example #10
Source File: WildcardTest.java From git-lfs-migrate with MIT License | 5 votes |
private static void pathMatcherCheck(@NotNull String pattern, @NotNull String path, boolean exact, @Nullable Boolean expectedMatch) throws InvalidPatternException { PathMatcher matcher = WildcardHelper.createMatcher(pattern, exact); for (String name : WildcardHelper.splitPattern(path)) { if (matcher == null) break; boolean isDir = name.endsWith("/"); matcher = matcher.createChild(isDir ? name.substring(0, name.length() - 1) : name, isDir); } if (expectedMatch == null) { Assert.assertNull(matcher); } else { Assert.assertNotNull(matcher); Assert.assertEquals(matcher.isMatch(), expectedMatch.booleanValue()); } }
Example #11
Source File: Wildcard.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
private static NameMatcher[] createNameMatchers(@NotNull String pattern) throws InvalidPatternException { final List<String> tokens = WildcardHelper.splitPattern(pattern); WildcardHelper.normalizePattern(tokens); final NameMatcher[] result = new NameMatcher[tokens.size() - 1]; for (int i = 0; i < result.length; ++i) { result[i] = WildcardHelper.nameMatcher(tokens.get(i + 1)); } return result; }
Example #12
Source File: GitAttributesFactory.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
@NotNull @Override public GitProperty[] create(@NotNull InputStream stream) throws IOException { AttributesNode r = new AttributesNode(); r.parse(stream); final List<GitProperty> properties = new ArrayList<>(); for (AttributesRule rule : r.getRules()) { final Wildcard wildcard; try { wildcard = new Wildcard(rule.getPattern()); } catch (InvalidPatternException | PatternSyntaxException e) { log.warn("Found invalid git pattern: {}", rule.getPattern()); continue; } final Attributes attrs = new Attributes(rule.getAttributes().toArray(emptyAttributes)); final EolType eolType = getEolType(attrs); if (eolType != null) { processProperty(properties, wildcard, SVNProperty.MIME_TYPE, eolType.mimeType); processProperty(properties, wildcard, SVNProperty.EOL_STYLE, eolType.eolStyle); } processProperty(properties, wildcard, SVNProperty.NEEDS_LOCK, getNeedsLock(attrs)); final String filter = getFilter(attrs); if (filter != null) properties.add(new GitFilterProperty(wildcard.getMatcher(), filter)); } return properties.toArray(GitProperty.emptyArray); }
Example #13
Source File: GitConverterTest.java From git-lfs-migrate with MIT License | 5 votes |
@Test(dataProvider = "matchFilenameProvider") public void matchFilenameTest(@NotNull String path, boolean expected) throws IOException, InvalidPatternException { FileSystem fs = Jimfs.newFileSystem(Configuration.unix()); GitConverter converter = new GitConverter(DBMaker.memoryDB().make(), fs.getPath("/tmp/migrate"), new String[]{ "*.zip", ".*", "LICENSE", "test*", "/root", "some/data", }); Assert.assertEquals(converter.matchFilename(path), expected); }
Example #14
Source File: WildcardHelper.java From git-lfs-migrate with MIT License | 5 votes |
private static NameMatcher[] createNameMatchers(@NotNull String pattern) throws InvalidPatternException { final List<String> tokens = WildcardHelper.splitPattern(pattern); WildcardHelper.normalizePattern(tokens); final NameMatcher[] result = new NameMatcher[tokens.size() - 1]; for (int i = 0; i < result.length; ++i) { result[i] = WildcardHelper.nameMatcher(tokens.get(i + 1)); } return result; }
Example #15
Source File: WildcardHelper.java From git-lfs-migrate with MIT License | 5 votes |
@Nullable public static PathMatcher createMatcher(@NotNull String pattern, boolean exact) throws InvalidPatternException { final NameMatcher[] nameMatchers = createNameMatchers(pattern); if (nameMatchers.length > 0) { return new RecursivePathMatcher(nameMatchers, exact); } else { return exact ? null : AlwaysMatcher.INSTANCE; } }
Example #16
Source File: Main.java From git-lfs-migrate with MIT License | 5 votes |
public static void processRepository(@NotNull Path srcPath, @NotNull Path dstPath, @NotNull Path cachePath, @Nullable Client client, int writeThreads, int uploadThreads, @NotNull String... globs) throws IOException, InterruptedException, ExecutionException, InvalidPatternException { removeDirectory(dstPath); Files.createDirectories(dstPath); final Repository srcRepo = new FileRepositoryBuilder() .setMustExist(true) .setGitDir(srcPath.toFile()).build(); final Repository dstRepo = new FileRepositoryBuilder() .setMustExist(false) .setGitDir(dstPath.toFile()).build(); try (DB cache = DBMaker.fileDB(cachePath.resolve("git-lfs-migrate.mapdb").toFile()) .fileMmapEnableIfSupported() .checksumHeaderBypass() .make()) { final GitConverter converter = new GitConverter(cache, dstPath, globs); dstRepo.create(true); // Load all revision list. ConcurrentMap<TaskKey, ObjectId> converted = new ConcurrentHashMap<>(); try (HttpUploader uploader = createHttpUploader(srcRepo, client, uploadThreads)) { log.info("Converting object without dependencies in " + writeThreads + " threads..."); Deque<TaskKey> pass2 = processWithoutDependencies(converter, srcRepo, dstRepo, converted, uploader, writeThreads); log.info("Converting object with dependencies in single thread..."); processSingleThread(converter, srcRepo, dstRepo, converted, uploader, pass2); } log.info("Recreating refs..."); for (Map.Entry<String, Ref> ref : srcRepo.getAllRefs().entrySet()) { RefUpdate refUpdate = dstRepo.updateRef(ref.getKey()); final ObjectId oldId = ref.getValue().getObjectId(); final ObjectId newId = converted.get(new TaskKey(GitConverter.TaskType.Simple, "", oldId)); refUpdate.setNewObjectId(newId); refUpdate.update(); log.info(" convert ref: {} -> {} ({})", oldId.getName(), newId.getName(), ref.getKey()); } } finally { dstRepo.close(); srcRepo.close(); } }
Example #17
Source File: GitConverter.java From git-lfs-migrate with MIT License | 5 votes |
@NotNull private static PathMatcher[] convertGlobs(String[] globs) throws InvalidPatternException { final PathMatcher[] matchers = new PathMatcher[globs.length]; for (int i = 0; i < globs.length; ++i) { String glob = globs[i]; if (!glob.contains("/")) { glob = "**/" + glob; } matchers[i] = WildcardHelper.createMatcher(glob, true); } return matchers; }
Example #18
Source File: WildcardTest.java From git-lfs-migrate with MIT License | 4 votes |
@Test(dataProvider = "pathMatcherData") public static void pathMatcherExactTest(@NotNull String pattern, @NotNull String path, @Nullable Boolean ignored, @Nullable Boolean expectedMatch) throws InvalidPatternException { pathMatcherCheck(pattern, path, true, expectedMatch); }
Example #19
Source File: WildcardTest.java From git-lfs-migrate with MIT License | 4 votes |
@Test(dataProvider = "pathMatcherData") public static void pathMatcherPrefixTest(@NotNull String pattern, @NotNull String path, @Nullable Boolean expectedMatch, @Nullable Boolean ignored) throws InvalidPatternException { pathMatcherCheck(pattern, path, false, expectedMatch); }
Example #20
Source File: ComplexMatcher.java From git-as-svn with GNU General Public License v2.0 | 4 votes |
public ComplexMatcher(@NotNull String pattern, boolean dirOnly, boolean svnMask) throws InvalidPatternException { this.pattern = pattern; this.dirOnly = dirOnly; this.svnMask = svnMask; this.matcher = IMatcher.createPathMatcher(dirOnly ? pattern.substring(0, pattern.length() - 1) : pattern, dirOnly); }
Example #21
Source File: ComplexMatcher.java From git-lfs-migrate with MIT License | 4 votes |
public ComplexMatcher(@NotNull String pattern, boolean dirOnly, boolean svnMask) throws InvalidPatternException { this.pattern = pattern; this.dirOnly = dirOnly; this.svnMask = svnMask; this.matcher = PathMatcher.createPathMatcher(dirOnly ? pattern.substring(0, pattern.length() - 1) : pattern, null, dirOnly); }
Example #22
Source File: WildcardTest.java From git-as-svn with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider = "nameMatcherData") public static void nameMatcherTest(@NotNull String mask, boolean recursive, @Nullable String svnMask) throws InvalidPatternException { final NameMatcher matcher = WildcardHelper.nameMatcher(mask); Assert.assertEquals(matcher.isRecursive(), recursive); Assert.assertEquals(svnMask, matcher.getSvnMask()); }