Skip to content

Commit

Permalink
FELIX-5800: calculate system package exports at runtime on jpms, opti…
Browse files Browse the repository at this point in the history
…onally with uses constraints, and cleanup the existing default definitions.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1829104 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
karlpauls committed Apr 13, 2018
1 parent 3b1e849 commit 3e970fc
Show file tree
Hide file tree
Showing 7 changed files with 3,542 additions and 1,080 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ public void serviceChanged(ServiceEvent event, Dictionary oldProps)
// Create the extension manager, which we will use as the
// revision for the system bundle.
m_extensionManager = new ExtensionManager(m_logger, m_configMap, this);

try
{
addRevision(m_extensionManager.getRevision());
Expand All @@ -445,7 +446,7 @@ public void serviceChanged(ServiceEvent event, Dictionary oldProps)
{
// This should not throw an exception, but if so, lets convert it to
// a runtime exception.
throw new RuntimeException(ex.getMessage());
throw new RuntimeException("Exception creating system bundle revision", ex);
}

// Create event dispatcher.
Expand Down Expand Up @@ -735,6 +736,25 @@ public void init(final FrameworkListener... listeners) throws BundleException
maps[IDENTIFIER_MAP_IDX].put(new Long(0), this);
m_installedBundles = maps;


try
{
getResolver().removeRevision(m_extensionManager.getRevision());
m_extensionManager.removeExtensionBundles();
m_extensionManager.updateRevision(this, m_configMap);
if (!m_configMutableMap.containsKey(Constants.FRAMEWORK_SYSTEMPACKAGES))
{
m_configMutableMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, m_extensionManager.getRevision().getHeaders().get(Constants.EXPORT_PACKAGE));
}
getResolver().addRevision(m_extensionManager.getRevision());
}
catch (Exception ex)
{
// This should not throw an exception, but if so, lets convert it to
// a runtime exception.
throw new BundleException("Exception creating system bundle revision", ex);
}

// Manually resolve the system bundle, which will cause its
// state to be set to RESOLVED.
try
Expand Down Expand Up @@ -4848,41 +4868,16 @@ private void initializeFrameworkProperties()

Properties defaultProperties = Util.loadDefaultProperties(m_logger);

Util.initializeJPMS(defaultProperties);

Util.initializeJPMSEE(_getProperty("java.specification.version"), defaultProperties, m_logger);

// Set supported execution environments to default value,
// if not explicitly configured.
loadFromDefaultIfNotDefined(defaultProperties, Constants.FRAMEWORK_EXECUTIONENVIRONMENT);

String sysprops = _getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
if(sysprops != null && "true".equalsIgnoreCase(_getProperty(FelixConstants.USE_PROPERTY_SUBSTITUTION_IN_SYSTEMPACKAGES)) )
{
defaultProperties.put(Constants.FRAMEWORK_SYSTEMPACKAGES, sysprops);
m_configMutableMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, Util.getPropertyWithSubs(defaultProperties, Constants.FRAMEWORK_SYSTEMPACKAGES));
}
else if (sysprops == null)
{
m_configMutableMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, Util.getPropertyWithSubs(defaultProperties, Constants.FRAMEWORK_SYSTEMPACKAGES));
}

String syscaps = _getProperty(Constants.FRAMEWORK_SYSTEMCAPABILITIES);
if(syscaps == null)
{
m_configMutableMap.put(Constants.FRAMEWORK_SYSTEMCAPABILITIES, Util.getPropertyWithSubs(defaultProperties, Constants.FRAMEWORK_SYSTEMCAPABILITIES));
}

loadFromDefaultIfNotDefined(defaultProperties, "ee-jpms");
loadFromDefaultIfNotDefined(defaultProperties, "eecap-jpms");
loadFromDefaultIfNotDefined(defaultProperties, "felix.detect.java.version");

// Set supported native capabilities to default value,
// if not explicitly configured.
loadPrefixFromDefaultIfNotDefined(m_configMutableMap, defaultProperties, FelixConstants.NATIVE_OS_NAME_ALIAS_PREFIX);
loadPrefixFromDefaultIfNotDefined(m_configMutableMap, defaultProperties, FelixConstants.NATIVE_PROC_NAME_ALIAS_PREFIX);
loadPrefixFromDefaultIfNotDefined(m_configMutableMap, defaultProperties, "felix.detect.jpms.");
loadPrefixFromDefaultIfNotDefined(m_configMutableMap, defaultProperties, "felix.jpms.");
}

private void loadFromDefaultIfNotDefined(Properties defaultProperties, String propertyName)
Expand Down Expand Up @@ -5226,7 +5221,6 @@ public void stop(BundleContext context)
m_securityManager = null;
}

m_extensionManager.removeExtensionBundles();
m_dependencies.removeDependents(adapt(BundleRevision.class));

// Dispose of the bundle cache.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.felix.framework.util;

import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;

import java.io.IOException;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeSet;

@IgnoreJRERequirement
public class ClassFileVisitor extends java.nio.file.SimpleFileVisitor<java.nio.file.Path>
{
private final Set<String> m_imports;
private final Set<String> m_exports;
private final ClassParser m_classParser;
private final SortedMap<String, SortedSet<String>> m_result;

public ClassFileVisitor(Set<String> imports, Set<String> exports, ClassParser classParser, SortedMap<String, SortedSet<String>> result)
{
m_imports = imports;
m_exports = exports;
m_classParser = classParser;
m_result = result;
}

@Override
public java.nio.file.FileVisitResult visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs) throws IOException
{
if (file.getNameCount() > 3)
{
String name = file.subpath(2, file.getNameCount() - 1).toString().replace("/", ".");
if (m_exports.contains(name) && file.toString().endsWith(".class"))
{
SortedSet<String> strings = m_result.get(name);

if (!name.startsWith("java."))
{
try
{
Set<String> refs = m_classParser.parseClassFileUses(file.toString(), java.nio.file.Files.newInputStream(file));
refs.retainAll(m_imports);
refs.remove(name);
if (strings == null)
{
strings = new TreeSet<String>(refs);
m_result.put(name, strings);
}
else
{
strings.addAll(refs);
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
else if (strings == null)
{
m_result.put(name, new TreeSet<String>());
}
}
}
return java.nio.file.FileVisitResult.CONTINUE;
}
}
Loading

0 comments on commit 3e970fc

Please sign in to comment.