From 2f4dd5c73d88746ee4f514c8262fb9e2fb9dd736 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Thu, 5 Oct 2017 14:42:21 +0300 Subject: [PATCH] Support gitlab archives PY-26364 fixed. --- .../python/packaging/PyRequirement.java | 43 +++++++++++-------- .../python/packaging/PyRequirementTest.java | 21 +++------ 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/python/openapi/src/com/jetbrains/python/packaging/PyRequirement.java b/python/openapi/src/com/jetbrains/python/packaging/PyRequirement.java index 203a68cbc36f..142fdc5cb04a 100644 --- a/python/openapi/src/com/jetbrains/python/packaging/PyRequirement.java +++ b/python/openapi/src/com/jetbrains/python/packaging/PyRequirement.java @@ -1,18 +1,16 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package com.jetbrains.python.packaging; import com.intellij.openapi.editor.Document; @@ -61,6 +59,10 @@ public class PyRequirement { private static final Pattern GITHUB_ARCHIVE_URL = Pattern.compile("https?://github\\.com/[^/\\s]+/(?<" + NAME_GROUP + ">[^/\\s]+)/archive/\\S+" + COMMENT_REGEXP); + @NotNull + private static final Pattern GITLAB_ARCHIVE_URL = + Pattern.compile("https?://gitlab\\.com/[^/\\s]+/(?<" + NAME_GROUP + ">[^/\\s]+)/repository/\\S+" + COMMENT_REGEXP); + @NotNull private static final Pattern ARCHIVE_URL = Pattern.compile("https?://\\S+/" + @@ -309,11 +311,16 @@ public class PyRequirement { @Nullable public static PyRequirement fromLine(@NotNull String line) { - final PyRequirement githubArchiveUrl = parseGithubArchiveUrl(line); + final PyRequirement githubArchiveUrl = parseGitArchiveUrl(GITHUB_ARCHIVE_URL, line); if (githubArchiveUrl != null) { return githubArchiveUrl; } + final PyRequirement gitlabArchiveUrl = parseGitArchiveUrl(GITLAB_ARCHIVE_URL, line); + if (gitlabArchiveUrl != null) { + return gitlabArchiveUrl; + } + final PyRequirement archiveUrl = parseArchiveUrl(line); if (archiveUrl != null) { return archiveUrl; @@ -349,8 +356,8 @@ public class PyRequirement { } @Nullable - private static PyRequirement parseGithubArchiveUrl(@NotNull String line) { - final Matcher matcher = GITHUB_ARCHIVE_URL.matcher(line); + private static PyRequirement parseGitArchiveUrl(@NotNull Pattern pattern, @NotNull String line) { + final Matcher matcher = pattern.matcher(line); if (matcher.matches()) { return new PyRequirement(matcher.group(NAME_GROUP), Collections.emptyList(), Collections.singletonList(dropComments(line, matcher))); diff --git a/python/testSrc/com/jetbrains/python/packaging/PyRequirementTest.java b/python/testSrc/com/jetbrains/python/packaging/PyRequirementTest.java index f2935af155ec..b2cd8af80e79 100644 --- a/python/testSrc/com/jetbrains/python/packaging/PyRequirementTest.java +++ b/python/testSrc/com/jetbrains/python/packaging/PyRequirementTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.packaging; import com.intellij.openapi.util.Pair; @@ -80,6 +66,11 @@ public class PyRequirementTest extends PyTestCase { doTest("https://github.com/divio/MyProject1/archive/master.zip?1450634746.0107164"); } + // PY-26364 + public void testGitlabArchiveUrl() { + doTest("https://gitlab.com/mrh1997/MyProject1/repository/master/archive.zip"); + } + // VCS // PY-6328 public void testGit() {