Skip to content

Commit

Permalink
[TP] update to Eclipse 4.30 and latest versions of other dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Dec 30, 2023
1 parent f3b12d7 commit 2968bc5
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public void testNonOSGiArtifact_missingArtifactGenerate_defaultInstructions() th
attributes.getValue(Constants.BUNDLE_SYMBOLICNAME));
assertEquals("Bundle derived from maven artifact com.google.errorprone:error_prone_annotations:2.18.0",
attributes.getValue(Constants.BUNDLE_NAME));
assertEqualManifestHeaders(Constants.IMPORT_PACKAGE, attributes,
"javax.lang.model.element;resolution:=optional");
assertEqualManifestHeaders(Constants.IMPORT_PACKAGE, attributes, "java.lang;resolution:=optional",
"java.lang.annotation;resolution:=optional", "javax.lang.model.element;resolution:=optional");
assertEqualManifestHeaders(Constants.EXPORT_PACKAGE, attributes,
"com.google.errorprone.annotations;version=\"2.18.0\";uses:=\"javax.lang.model.element\"",
"com.google.errorprone.annotations.concurrent;version=\"2.18.0\"");
Expand Down Expand Up @@ -220,7 +220,8 @@ public void testNonOSGiArtifact_missingArtifactGenerate_customInstructions() thr
attributes.getValue(Constants.BUNDLE_SYMBOLICNAME));
assertEquals("Bundle in Test from artifact com.google.errorprone:error_prone_annotations:2.18.0:",
attributes.getValue(Constants.BUNDLE_NAME));
assertEqualManifestHeaders(Constants.IMPORT_PACKAGE, attributes, "javax.lang.model.element");
assertEqualManifestHeaders(Constants.IMPORT_PACKAGE, attributes, "java.lang", "java.lang.annotation",
"javax.lang.model.element");
assertEqualManifestHeaders(Constants.EXPORT_PACKAGE, attributes,
"com.google.errorprone.annotations;version=\"2.18.0\";uses:=\"javax.lang.model.element\"",
"com.google.errorprone.annotations.concurrent;version=\"2.18.0\"");
Expand Down Expand Up @@ -280,7 +281,7 @@ public void testNonOSGiArtifact_missingArtifactGenerate_changedCustomInstruction
assertEquals("others.wrapped.error_prone_annotations.source",
getGeneratedSourceBundle(target).getBundleInfo().getSymbolicName());
}

@Test
public void testNonOSGiArtifact_missingArtifactGenerate_hasVersions() throws Exception {
ITargetLocation target = resolveMavenTarget(
Expand Down Expand Up @@ -310,8 +311,8 @@ public void testNonOSGiArtifact_missingArtifactGenerate_hasVersions() throws Exc
String attribute = element.getAttribute(Constants.VERSION_ATTRIBUTE);
assertNotNull("Package " + value + " has no version attribute: " + element, attribute);
VersionRange versionRange = VersionRange.valueOf(attribute);
assertEquals("Unexpected version range " + versionRange + " on package " + value + ": " + element,
0, versionRange.getLeft().compareTo(Version.valueOf("9.5.0")));
assertEquals("Unexpected version range " + versionRange + " on package " + value + ": " + element, 0,
versionRange.getLeft().compareTo(Version.valueOf("9.5.0")));
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions org.eclipse.m2e.tests.common/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: M2E Testing Helpers
Bundle-SymbolicName: org.eclipse.m2e.tests.common;singleton:=true
Bundle-Version: 2.0.5.qualifier
Bundle-Version: 2.0.6.qualifier
Require-Bundle: org.junit;bundle-version="4.0.0",
org.eclipse.m2e.core;bundle-version="[2.0.0,3.0.0)",
org.eclipse.m2e.maven.runtime;bundle-version="[3.8.6,4.0.0)",
Expand All @@ -22,6 +22,5 @@ Bundle-Vendor: Eclipse.org - m2e
MavenArtifact-GroupId: org.eclipse.m2e
MavenArtifact-ArtifactId: org.eclipse.m2e.tests.common
Export-Package: org.eclipse.m2e.tests.common;x-friends:="org.eclipse.m2e.tests,org.eclipse.m2e.core.tests,org.eclipse.m2e.jdt.tests,org.eclipse.m2e.core.ui.tests,org.eclipse.m2e.wtp.tests"
Import-Package: javax.servlet;version="3.1.0",
javax.servlet.http;version="3.1.0"
Import-Package: org.eclipse.jetty.io;version="12.0.0"
Automatic-Module-Name: org.eclipse.m2e.tests.common
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@

package org.eclipse.m2e.tests.common;

import static org.junit.Assert.fail;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.security.Authenticator;
import org.eclipse.jetty.security.Constraint;
import org.eclipse.jetty.security.Constraint.Authorization;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
Expand All @@ -48,14 +48,14 @@
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.resource.PathResourceFactory;
import org.eclipse.jetty.util.ssl.SslContextFactory;


Expand Down Expand Up @@ -276,15 +276,15 @@ public HttpServer setProxyAuth(String username, String password) {
}

protected Handler newProxyHandler() {
return new AbstractHandler() {
return new Handler.Abstract() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) {
String auth = request.getHeader("Proxy-Authorization");
public boolean handle(Request request, Response response, Callback callback) throws Exception {
String auth = request.getHeaders().get(HttpHeader.PROXY_AUTHORIZATION);
if(auth != null) {
auth = auth.substring(auth.indexOf(' ') + 1).trim();
auth = new String(Base64.getDecoder().decode(auth));

}
return false;
}
};
}
Expand All @@ -302,19 +302,19 @@ public HttpServer setRedirectToHttps(boolean redirectToHttps) {
}

protected Handler newSslRedirectHandler() {
return new AbstractHandler() {
return new Handler.Abstract() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) {
public boolean handle(Request request, Response response, Callback callback) throws Exception {
int httpsPort = getHttpsPort();
if(!((Request) request).isHandled() && request.getServerPort() != httpsPort) {
String url = "https://" + request.getServerName() + ":" + httpsPort + request.getRequestURI();

response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", url);
((Request) request).setHandled(true);
if(Request.getServerPort(request) != httpsPort) {
String url = "https://" + Request.getServerName(request) + ":" + httpsPort + request.getHttpURI().getPath();
response.setStatus(HttpStatus.MOVED_PERMANENTLY_301);
response.getHeaders().put(HttpHeader.LOCATION, url);
callback.succeeded();
return true;
}
return false;
}

};
}

Expand Down Expand Up @@ -346,22 +346,13 @@ public HttpServer addSecuredRealm(String pathSpec, String... roles) {
return this;
}

protected SecurityHandler newSecurityHandler() {
List<ConstraintMapping> mappings = new ArrayList<>();
protected SecurityHandler newSecurityHandler() throws IOException {
SecurityHandler.PathMapped securityHandler = new SecurityHandler.PathMapped();

for(String pathSpec : securedRealms.keySet()) {
String[] roles = securedRealms.get(pathSpec);

Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(roles);
constraint.setAuthenticate(true);

ConstraintMapping constraintMapping = new ConstraintMapping();
constraintMapping.setConstraint(constraint);
constraintMapping.setPathSpec(pathSpec);

mappings.add(constraintMapping);
Constraint constraint = Constraint.from(Authenticator.BASIC_AUTH, Authorization.SPECIFIC_ROLE, roles);
securityHandler.put(pathSpec, constraint);
}

Properties p = new Properties();
Expand All @@ -380,17 +371,14 @@ protected SecurityHandler newSecurityHandler() {
File propFile = new File("target/users.properties");
try (FileOutputStream in = new FileOutputStream(propFile)) {
p.store(in, null);
} catch(IOException ex) {
fail("Unable to create users properties file");
}

HashLoginService userRealm = new HashLoginService("TestRealm", "target/users.properties");
HashLoginService userRealm = new HashLoginService("TestRealm",
new PathResourceFactory().newResource("target/users.properties"));
server.addBean(userRealm);

ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.setAuthenticator(new BasicAuthenticator());
securityHandler.setLoginService(userRealm);
securityHandler.setConstraintMappings(mappings);

return securityHandler;
}
Expand Down Expand Up @@ -488,9 +476,8 @@ public HttpServer setLatency(long millis) {
}

protected Handler newSleepHandler(final long millis) {
return new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) {
return new Handler.Abstract() {
public boolean handle(Request request, Response response, Callback callback) throws Exception {
if(millis >= 0) {
try {
Thread.sleep(millis);
Expand All @@ -506,8 +493,8 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
}
}
}
return false;
}

};
}

Expand All @@ -534,7 +521,7 @@ public HttpServer start() throws Exception {
connectors.add(newHttpsConnector());
}

HandlerList handlerList = new HandlerList();
Handler.Sequence handlerList = new Handler.Sequence();
if(!recordedPatterns.isEmpty()) {
handlerList.addHandler(new RecordingHandler());
}
Expand Down Expand Up @@ -645,58 +632,57 @@ public void stop() {
}
}

class ResHandler extends AbstractHandler {

@Override

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException {
private class ResHandler extends Handler.Abstract {

String uri = request.getRequestURI();
public boolean handle(Request request, Response response, Callback callback) throws Exception {
String uri = request.getHttpURI().getPath();

for(String contextRoot : resourceDirs.keySet()) {
String path = URIUtil.decodePath(trimContextRoot(uri, contextRoot));
if(path != null) {
File basedir = resourceDirs.get(contextRoot);
File file = new File(basedir, path);

if(HttpMethod.HEAD.equals(request.getMethod())) {
if(file.exists())
response.setStatus(HttpServletResponse.SC_OK);
else
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
((Request) request).setHandled(true);
return;
} else if(HttpMethod.PUT.equals(request.getMethod()) || HttpMethod.POST.equals(request.getMethod())) {
HttpMethod requestMethod = HttpMethod.fromString(request.getMethod());
if(HttpMethod.HEAD == requestMethod) {
if(file.exists()) {
response.setStatus(HttpStatus.OK_200);
} else {
response.setStatus(HttpStatus.NOT_FOUND_404);
}
callback.succeeded();
return true;
} else if(HttpMethod.PUT == requestMethod || HttpMethod.POST == requestMethod) {
file.getParentFile().mkdirs();

try (var input = request.getInputStream()) {
try (var input = Content.Source.asInputStream(request)) {
Files.copy(input, file.toPath());
}

response.setStatus(HttpServletResponse.SC_CREATED);
((Request) request).setHandled(true);
response.setStatus(HttpStatus.CREATED_201);
callback.succeeded();
return true;
} else if(file.isFile()) {

try (var outputStream = response.getOutputStream()) {
String filterEncoding = getFilterEncoding(path, resourceFilters.get(contextRoot));
if(filterEncoding == null) {
Files.copy(file.toPath(), outputStream);
} else {
String text = Files.readString(file.toPath(), Charset.forName(filterEncoding));
text = filter(text, filterTokens);
outputStream.write(text.getBytes(filterEncoding));
}
String filterEncoding = getFilterEncoding(path, resourceFilters.get(contextRoot));
byte[] bytes;
if(filterEncoding == null) {
bytes = Files.readAllBytes(file.toPath());
} else {
String text = Files.readString(file.toPath(), Charset.forName(filterEncoding));
text = filter(text, filterTokens);
bytes = text.getBytes(filterEncoding);
}
response.write(true, ByteBuffer.wrap(bytes), callback);

response.setStatus(HttpServletResponse.SC_OK);
((Request) request).setHandled(true);
response.setStatus(HttpStatus.OK_200);
callback.succeeded();
return true;
}

break;
return false;
}
}

return false;
}

private String getExtension(String path) {
Expand Down Expand Up @@ -727,11 +713,11 @@ private String filter(String str, Map<String, String> tokens) {

}

class RecordingHandler extends AbstractHandler {
private class RecordingHandler extends Handler.Abstract {

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) {
String uri = request.getRequestURI();
public boolean handle(Request request, Response response, Callback callback) throws Exception {
String uri = request.getHttpURI().getPath();

for(String pattern : recordedPatterns) {
if(uri.matches(pattern)) {
Expand All @@ -740,14 +726,13 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques

Map<String, String> headers = new HashMap<>();
recordedHeaders.put(uri, headers);
for(Enumeration<String> h = request.getHeaderNames(); h.hasMoreElements();) {
String headername = h.nextElement();
headers.put(headername, request.getHeader(headername));
for(HttpField field : request.getHeaders()) {
headers.put(field.getName(), field.getValue());
}
}
}
return false;
}

}

private static String normalizeContextRoot(String contextRoot) {
Expand Down
Loading

0 comments on commit 2968bc5

Please sign in to comment.