Skip to content

Commit

Permalink
remove obsolete code from tools
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed May 11, 2020
1 parent 285d18c commit 488c87a
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 212 deletions.
27 changes: 13 additions & 14 deletions istack-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
Expand All @@ -120,7 +120,7 @@
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>codemodel</artifactId>
<version>2.3.2-2</version>
<version>3.0.0-M2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -414,31 +414,29 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${upper.java.level}</release>
<compilerArguments>
<Xlint:all />
</compilerArguments>
</configuration>
<executions>
<execution>
<id>base-compile</id>
<id>default-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>${base.java.level}</release>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
<compilerArguments>
<Xlint:all />
</compilerArguments>
</configuration>
</execution>
<execution>
<!--compile test classes with source/target 11-->
<id>default-testCompile</id>
<id>base-compile</id>
<goals>
<goal>testCompile</goal>
<goal>compile</goal>
</goals>
<configuration>
<release>11</release>
<release>${base.java.level}</release>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -547,6 +545,7 @@
<configuration>
<excludes>
<exclude>com/sun/istack/logging/StackHelper.class</exclude>
<exclude>com/sun/istack/tools/Utils.class</exclude>
</excludes>
</configuration>
</execution>
Expand Down
78 changes: 75 additions & 3 deletions istack-commons/tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,101 @@
</dependency>
</dependencies>

<properties>
<argLine/>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-mr-resource</id>
<phase>prepare-package</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${mrjar.sourceDirectory}</directory>
<targetPath>META-INF/versions</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<!--compile all as JPMS module-->
<id>default-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>9</source>
<target>9</target>
<compilerArgs>
<arg>--add-reads</arg>
<arg>com.sun.istack.tools=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>default-compile-mr</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${mrjar.sourceDirectory}/${upper.java.level}</compileSourceRoot>
</compileSourceRoots>
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/${upper.java.level}</outputDirectory>
<source>${upper.java.level}</source>
<target>${upper.java.level}</target>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<compilerArgs>
<arg>--add-reads</arg>
<arg>com.sun.istack.tools=org.testng</arg>
<arg>--add-reads</arg>
<arg>com.sun.istack.tools=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Export-Package>
!META-INF.*,
*
</Export-Package>
<Multi-Release>true</Multi-Release>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
@{argLine} --add-opens java.base/java.net=com.sun.istack.tools
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

package com.sun.istack.tools;

import java.net.Authenticator;

/**
*
* @author lukas
*/
final class Utils {

private Utils() {}

static Authenticator getCurrentAuthenticator() {
return Authenticator.getDefault();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -17,19 +17,13 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.Authenticator;
import java.net.Authenticator.RequestorType;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -100,7 +94,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
/**
* Proxy authorization string in form of username:password.
*
* @param proxyAuth
* @param proxyAuth Proxy authorization string
*/
public void setProxyAuth(String proxyAuth) {
if (proxyAuth == null) {
Expand Down Expand Up @@ -211,62 +205,7 @@ private AuthInfo parseLine(String text) throws Exception {
}

static Authenticator getCurrentAuthenticator() {
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<Authenticator>() {
@Override
public Authenticator run() throws Exception {
Method method = Authenticator.class.getMethod("getDefault");
return (Authenticator) method.invoke(null);
}

});
} catch (PrivilegedActionException pae) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, null, pae);
}
Exception ex = pae.getException();
if (!(ex instanceof NoSuchMethodException)) {
// if Authenticator.getDefault has not been found,
// we likely didn't get through sec, so return null
// and don't care about JDK version we're on
return null;
}
// or we're on JDK <9, so let's continue the old way...
}

final Field f = getTheAuthenticator();
if (f == null) {
return null;
}

try {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
f.setAccessible(true);
return null;
}
});
return (Authenticator) f.get(null);
} catch (IllegalAccessException | IllegalArgumentException ex) {
return null;
} finally {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
f.setAccessible(false);
return null;
}
});
}
}

private static Field getTheAuthenticator() {
try {
return Authenticator.class.getDeclaredField("theAuthenticator");
} catch (NoSuchFieldException | SecurityException ex) {
return null;
}
return Utils.getCurrentAuthenticator();
}

public static interface Receiver {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -87,8 +87,9 @@ public ParallelWorldClassLoader(ClassLoader parent,String prefix) {
jars = Collections.synchronizedSet(new HashSet<JarFile>());
}

@Override
protected Class findClass(String name) throws ClassNotFoundException {

StringBuffer sb = new StringBuffer(name.length()+prefix.length()+6);
sb.append(prefix).append(name.replace('.','/')).append(".class");

Expand All @@ -106,7 +107,7 @@ protected Class findClass(String name) throws ClassNotFoundException {
} catch (IOException ioe) {
throw new ClassNotFoundException(name);
}

if (is==null)
throw new ClassNotFoundException(name);

Expand All @@ -132,7 +133,7 @@ protected Class findClass(String name) throws ClassNotFoundException {
throw new ClassNotFoundException(name,e);
} finally {
try {
if (con != null && con instanceof JarURLConnection) {
if (con instanceof JarURLConnection) {
jars.add(((JarURLConnection) con).getJarFile());
}
} catch (IOException ioe) {
Expand All @@ -154,9 +155,7 @@ protected URL findResource(String name) {
if (u != null) {
try {
jars.add(new JarFile(new File(toJarUrl(u).toURI())));
} catch (URISyntaxException ex) {
Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex);
} catch (IOException ex) {
} catch (URISyntaxException | IOException ex) {
Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex);
} catch (ClassNotFoundException ex) {
//ignore - not a jar
Expand All @@ -171,26 +170,29 @@ protected Enumeration<URL> findResources(String name) throws IOException {
while (en.hasMoreElements()) {
try {
jars.add(new JarFile(new File(toJarUrl(en.nextElement()).toURI())));
} catch (URISyntaxException ex) {
} catch (URISyntaxException | IOException ex) {
//should not happen
Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex);
} catch (IOException ex) {
Logger.getLogger(ParallelWorldClassLoader.class.getName()).log(Level.WARNING, null, ex);
} catch (ClassNotFoundException ex) {
//ignore - not a jar
}
}
return en;
}

@Override
public synchronized void close() throws IOException {
for (JarFile jar : jars) {
jar.close();
}
}

/**
* Given the URL inside jar, returns the URL to the jar itself.
* @param res Resource in a jar
* @return URL to the conaining jar file
* @throws java.lang.ClassNotFoundException if res does not denote jar URL
* @throws java.net.MalformedURLException if computed URL is invalid
*/
public static URL toJarUrl(URL res) throws ClassNotFoundException, MalformedURLException {
String url = res.toExternalForm();
Expand Down

0 comments on commit 488c87a

Please sign in to comment.