Skip to content

Commit

Permalink
Fixed mapping of extracted statements in commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed May 13, 2024
1 parent 66e0904 commit f384dbc
Show file tree
Hide file tree
Showing 14 changed files with 3,895 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6780,7 +6780,9 @@ private AbstractCodeMapping findParentMappingContainingOperationInvocation() {
}
if(statementContainingOperationInvocation != null) {
if(mapping.getFragment2().equals(statementContainingOperationInvocation.getParent())) {
return mapping;
boolean extractedStatement = parentMapper.extractedStatements.containsKey(this.container2) && parentMapper.extractedStatements.get(this.container2).contains(mapping.getFragment1());
if(!extractedStatement)
return mapping;
}
if(statementContainingOperationInvocation.getParent() != null && statementContainingOperationInvocation.getParent().getParent() != null &&
statementContainingOperationInvocation.getParent().getLocationInfo().getCodeElementType().equals(CodeElementType.BLOCK) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ public void handle(String commitId, List<Refactoring> refactorings) {
"https://github.com/spring-projects/spring-boot.git, 07766c436cb89128eac5389d33f76329b758d8df, spring-boot-07766c436cb89128eac5389d33f76329b758d8df.txt",
"https://github.com/spring-projects/spring-framework.git, 58fbf60d2d5d28d96c351eb539a52bceffac270a, spring-framework-58fbf60d2d5d28d96c351eb539a52bceffac270a.txt",
"https://github.com/hibernate/hibernate-orm.git, bf7607e24495af5133165ae6ed6b85feecf59148, hibernate-orm-bf7607e24495af5133165ae6ed6b85feecf59148.txt",
"https://github.com/tsantalis/RefactoringMiner.git, 0894f346564f8b31cf836def67e952fb93a6036d, miner-0894f346564f8b31cf836def67e952fb93a6036d.txt"
"https://github.com/tsantalis/RefactoringMiner.git, 0894f346564f8b31cf836def67e952fb93a6036d, miner-0894f346564f8b31cf836def67e952fb93a6036d.txt",
"https://github.com/eclipse-jgit/jgit.git, 7ff6eb584cf8b83f83a3b5edf897feb53dbf42c0, jgit-7ff6eb584cf8b83f83a3b5edf897feb53dbf42c0.txt"
})
public void testExtractMethodStatementMappings(String url, String commit, String testResultFileName) throws Exception {
GitHistoryRefactoringMinerImpl miner = new GitHistoryRefactoringMinerImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,36 @@ public void handle(String commitId, List<Refactoring> refactorings) {
Assert.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && actual.containsAll(expected));
}

@Test
public void testExtractMethodStatementMappings26() throws Exception {
GitHistoryRefactoringMinerImpl miner = new GitHistoryRefactoringMinerImpl();
final List<String> actual = new ArrayList<>();
miner.detectAtCommitWithGitHubAPI("https://github.com/eclipse-jgit/jgit.git", "7ff6eb584cf8b83f83a3b5edf897feb53dbf42c0", new File(REPOS), new RefactoringHandler() {
@Override
public void handle(String commitId, List<Refactoring> refactorings) {
List<UMLOperationBodyMapper> parentMappers = new ArrayList<>();
for (Refactoring ref : refactorings) {
if(ref instanceof ExtractOperationRefactoring) {
ExtractOperationRefactoring ex = (ExtractOperationRefactoring)ref;
UMLOperationBodyMapper bodyMapper = ex.getBodyMapper();
if(!bodyMapper.isNested()) {
if(!parentMappers.contains(bodyMapper.getParentMapper())) {
parentMappers.add(bodyMapper.getParentMapper());
}
}
mapperInfo(bodyMapper, actual);
}
}
for(UMLOperationBodyMapper parentMapper : parentMappers) {
mapperInfo(parentMapper, actual);
}
}
});

List<String> expected = IOUtils.readLines(new FileReader(EXPECTED_PATH + "jgit-7ff6eb584cf8b83f83a3b5edf897feb53dbf42c0.txt"));
Assert.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && actual.containsAll(expected));
}

@Test
public void testSlidedStatementMappings() throws Exception {
GitHistoryRefactoringMinerImpl miner = new GitHistoryRefactoringMinerImpl();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
private sendPack() : void -> private sendPack(sideband boolean) : void
line range:771-771==line range:830-830
line range:824-824==line range:883-883
line range:826-826==line range:885-885
line range:828-828==line range:887-887
line range:831-831==line range:890-890
line range:833-833==line range:892-892
line range:835-835==line range:894-894
line range:837-837==line range:896-896
line range:838-838==line range:897-897
line range:839-839==line range:898-898
line range:844-844==line range:903-903
line range:849-849==line range:908-908
line range:851-851==line range:910-910
line range:853-853==line range:912-912
line range:857-857==line range:916-916
line range:859-859==line range:918-918
line range:861-861==line range:920-920
line range:863-863==line range:922-922
line range:865-865==line range:924-924
line range:869-869==line range:928-928
line range:870-870==line range:929-929
line range:873-873==line range:932-932
line range:874-874==line range:933-933
line range:875-875==line range:934-934
line range:879-879==line range:938-938
line range:883-883==line range:942-942
line range:886-886==line range:945-945
line range:772-772==line range:831-831
line range:773-773==line range:832-832
line range:776-776==line range:835-835
line range:778-778==line range:837-837
line range:780-781==line range:839-840
line range:783-784==line range:842-843
line range:785-785==line range:844-844
line range:791-791==line range:850-850
line range:793-793==line range:852-852
line range:797-797==line range:856-856
line range:798-800==line range:857-859
line range:801-801==line range:860-860
line range:802-802==line range:861-861
line range:804-804==line range:863-863
line range:807-807==line range:866-866
line range:809-809==line range:868-868
line range:810-810==line range:869-869
line range:812-812==line range:871-871
line range:813-813==line range:872-872
line range:814-814==line range:873-873
line range:815-815==line range:874-874
line range:816-816==line range:875-875
line range:819-819==line range:878-878
line range:822-822==line range:881-881
line range:777-778==line range:836-837
line range:782-786==line range:841-845
line range:775-787==line range:834-846
line range:790-794==line range:849-853
line range:789-805==line range:848-864
line range:796-803==line range:855-862
line range:795-805==line range:854-864
line range:808-809==line range:867-868
line range:825-826==line range:884-885
line range:823-826==line range:882-885
line range:821-826==line range:880-885
line range:820-827==line range:879-886
line range:818-829==line range:877-888
line range:832-840==line range:891-899
line range:848-849==line range:907-908
line range:852-853==line range:911-912
line range:847-854==line range:906-913
line range:856-857==line range:915-916
line range:860-861==line range:919-920
line range:864-865==line range:923-924
line range:843-866==line range:902-925
line range:842-867==line range:901-926
line range:872-876==line range:931-935
line range:811-880==line range:870-939
line range:878-880==line range:937-939
line range:882-883==line range:941-942
line range:885-886==line range:944-945
line range:782-786==line range:841-845
line range:775-787==line range:834-846
line range:790-792==line range:849-851
line range:792-794==line range:851-853
line range:796-803==line range:855-862
line range:820-827==line range:879-886
line range:818-829==line range:877-888
line range:832-834==line range:891-893
line range:834-840==line range:893-899
line range:847-850==line range:906-909
line range:850-854==line range:909-913
line range:843-866==line range:902-925
line range:842-867==line range:901-926
line range:872-876==line range:931-935
private sendPack() : void -> private sendPack() : void
line range:758-759==line range:774-775
line range:764-764==line range:780-780
line range:766-768==line range:782-784
line range:765-768==line range:781-784
line range:761-769==line range:777-785
line range:761-769==line range:777-785
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* Copyright (C) 2009-2010, Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.eclipse.jgit.http.server;

import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
import static javax.servlet.http.HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE;
import static org.eclipse.jgit.http.server.ServletUtils.ATTRIBUTE_HANDLER;
import static org.eclipse.jgit.http.server.ServletUtils.getInputStream;
import static org.eclipse.jgit.http.server.ServletUtils.getRepository;

import java.io.IOException;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.ReceivePack;
import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser;
import org.eclipse.jgit.transport.resolver.ReceivePackFactory;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;

/** Server side implementation of smart push over HTTP. */
class ReceivePackServlet extends HttpServlet {
private static final String REQ_TYPE = "application/x-git-receive-pack-request";

private static final String RSP_TYPE = "application/x-git-receive-pack-result";

private static final long serialVersionUID = 1L;

static class InfoRefs extends SmartServiceInfoRefs {
private final ReceivePackFactory<HttpServletRequest> receivePackFactory;

InfoRefs(ReceivePackFactory<HttpServletRequest> receivePackFactory,
List<Filter> filters) {
super("git-receive-pack", filters);
this.receivePackFactory = receivePackFactory;
}

@Override
protected void begin(HttpServletRequest req, Repository db)
throws IOException, ServiceNotEnabledException,
ServiceNotAuthorizedException {
ReceivePack rp = receivePackFactory.create(req, db);
req.setAttribute(ATTRIBUTE_HANDLER, rp);
}

@Override
protected void advertise(HttpServletRequest req,
PacketLineOutRefAdvertiser pck) throws IOException,
ServiceNotEnabledException, ServiceNotAuthorizedException {
ReceivePack rp = (ReceivePack) req.getAttribute(ATTRIBUTE_HANDLER);
try {
rp.sendAdvertisedRefs(pck);
} finally {
rp.getRevWalk().release();
}
}
}

static class Factory implements Filter {
private final ReceivePackFactory<HttpServletRequest> receivePackFactory;

Factory(ReceivePackFactory<HttpServletRequest> receivePackFactory) {
this.receivePackFactory = receivePackFactory;
}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse rsp = (HttpServletResponse) response;
ReceivePack rp;
try {
rp = receivePackFactory.create(req, getRepository(req));
} catch (ServiceNotAuthorizedException e) {
rsp.sendError(SC_UNAUTHORIZED);
return;

} catch (ServiceNotEnabledException e) {
RepositoryFilter.sendError(SC_FORBIDDEN, req, rsp);
return;
}

try {
req.setAttribute(ATTRIBUTE_HANDLER, rp);
chain.doFilter(req, rsp);
} finally {
req.removeAttribute(ATTRIBUTE_HANDLER);
}
}

public void init(FilterConfig filterConfig) throws ServletException {
// Nothing.
}

public void destroy() {
// Nothing.
}
}

@Override
public void doPost(final HttpServletRequest req,
final HttpServletResponse rsp) throws IOException {
if (!REQ_TYPE.equals(req.getContentType())) {
rsp.sendError(SC_UNSUPPORTED_MEDIA_TYPE);
return;
}

ReceivePack rp = (ReceivePack) req.getAttribute(ATTRIBUTE_HANDLER);
try {
rp.setBiDirectionalPipe(false);
rsp.setContentType(RSP_TYPE);

final SmartOutputStream out = new SmartOutputStream(req, rsp) {
@Override
public void flush() throws IOException {
doFlush();
}
};
rp.receive(getInputStream(req), out, null);
out.close();
} catch (IOException e) {
getServletContext().log(HttpServerText.get().internalErrorDuringReceivePack, e);
rsp.sendError(SC_INTERNAL_SERVER_ERROR);
return;
}
}
}
Loading

0 comments on commit f384dbc

Please sign in to comment.