Skip to content

Commit

Permalink
Merge pull request #65 from apache/frameworkR8
Browse files Browse the repository at this point in the history
FELIX-6369: Implement R8 core spec
  • Loading branch information
karlpauls committed Dec 15, 2020
2 parents 31fa52b + 8bccf4d commit a1ec804
Show file tree
Hide file tree
Showing 113 changed files with 4,572 additions and 2,204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@ public int hashCode()
return System.identityHashCode(this);
}

public int compareTo(Bundle o) {
// TODO Auto-generated method stub
return 0;
}

public Object adapt(Class arg0) {
// TODO Auto-generated method stub
return null;
Expand All @@ -199,9 +194,4 @@ public File getDataFile(String arg0) {
// TODO Auto-generated method stub
return null;
}

public int compareTo(Object t)
{
throw new UnsupportedOperationException("Not supported yet.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.PropertyPermission;

import org.apache.felix.framework.util.SecureAction;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.CapabilityPermission;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.PackagePermission;
import org.osgi.framework.ServicePermission;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
Expand Down Expand Up @@ -107,12 +111,15 @@ public PermissionInfo[] getImplicit(Bundle bundle)
{
return new PermissionInfo[] {
IMPLICIT[0],
new PermissionInfo(AdminPermission.class.getName(), "(id="
+ bundle.getBundleId() + ")", AdminPermission.METADATA),
new PermissionInfo(AdminPermission.class.getName(), "(id="
+ bundle.getBundleId() + ")", AdminPermission.RESOURCE),
new PermissionInfo(AdminPermission.class.getName(), "(id="
+ bundle.getBundleId() + ")", AdminPermission.CONTEXT) };
new PermissionInfo(PropertyPermission.class.getName(), "org.osgi.framework.*", "read"),
new PermissionInfo(
AdminPermission.class.getName(),
"(id=" + bundle.getBundleId() + ")",
AdminPermission.CLASS + "," + AdminPermission.METADATA + "," + AdminPermission.RESOURCE + "," + AdminPermission.CONTEXT),
new PermissionInfo(CapabilityPermission.class.getName(), "(|(capability.namespace=osgi.ee)(capability.namespace=osgi.native))", CapabilityPermission.REQUIRE),
new PermissionInfo(PackagePermission.class.getName(),"(package.name=java.*)",PackagePermission.IMPORT),
new PermissionInfo(ServicePermission.class.getName(),"org.osgi.service.condition.Condition", ServicePermission.GET)
};
}

public Permissions getPermissions(PermissionInfo[] permissionInfos)
Expand Down
42 changes: 22 additions & 20 deletions framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>org.apache.felix</groupId>
<artifactId>felix-parent</artifactId>
<version>6</version>
<relativePath>../../pom/pom.xml</relativePath>
<relativePath>../pom/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>bundle</packaging>
Expand All @@ -30,12 +30,12 @@
<version>6.1.0-SNAPSHOT</version>
<properties>
<dollar>$</dollar>
<felix.java.version>6</felix.java.version>
<felix.java.version>8</felix.java.version>
</properties>
<scm>
<connection>scm:git:https://github.com/apache/felix-dev.git</connection>
<developerConnection>scm:git:https://github.com/apache/felix-dev.git</developerConnection>
<url>https://gitbox.apache.org/repos/asf?p=felix-dev.git</url>
<connection>scm:git:https://github.com/apache/felix-dev.git</connection>
<developerConnection>scm:git:https://github.com/apache/felix-dev.git</developerConnection>
<url>https://gitbox.apache.org/repos/asf?p=felix-dev.git</url>
<tag>HEAD</tag>
</scm>

Expand All @@ -44,13 +44,13 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.1.0</version>
<version>5.1.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>org.apache.felix.framework</Bundle-SymbolicName>
<Bundle-Name>Apache Felix Framework</Bundle-Name>
<Bundle-Description>OSGi R7 framework implementation.</Bundle-Description>
<Bundle-Description>OSGi R8 framework implementation.</Bundle-Description>
<Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
<Export-Package>
org.osgi.framework.*;-split-package:=first,
Expand All @@ -61,7 +61,8 @@
org.osgi.service.url;-split-package:=first,
org.osgi.service.resolver,
org.osgi.util.tracker;-split-package:=first,
org.osgi.dto;-split-package:=first
org.osgi.dto;-split-package:=first,
org.osgi.service.condition;-split-package:=first
</Export-Package>
<Private-Package>org.apache.felix.framework.*, org.apache.felix.resolver.*</Private-Package>
<Import-Package>!*</Import-Package>
Expand Down Expand Up @@ -90,7 +91,7 @@
<excludes>
<exclude>src/main/appended-resources/**</exclude>
<exclude>src/**/packageinfo</exclude>
<exclude>src/main/resources/META-INF/services/org.osgi.framework.launch.FrameworkFactory</exclude>
<exclude>src/main/resources/META-INF/**</exclude>
<exclude>src/main/resources/org/apache/felix/framework/Felix.properties</exclude>
</excludes>
</configuration>
Expand Down Expand Up @@ -119,18 +120,19 @@
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.bytes</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.bytes</include>
</includes>
</resource>
</resources>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
Expand All @@ -153,7 +155,7 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-all</artifactId>
<version>4.2</version>
<version>5.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -164,7 +166,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
Expand Down
44 changes: 30 additions & 14 deletions framework/src/main/java/org/apache/felix/framework/BundleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class BundleImpl implements Bundle, BundleRevisions

private final BundleArchive m_archive;
private final List<BundleRevisionImpl> m_revisions = new ArrayList<BundleRevisionImpl>(0);
private volatile BundleRevisionImpl m_currentRevision = null;
private volatile int m_state;
private boolean m_useDeclaredActivationPolicy;
private BundleActivator m_activator = null;
Expand Down Expand Up @@ -188,16 +189,24 @@ synchronized void refresh() throws Exception
{
// Get current revision, since we can reuse it.
BundleRevisionImpl current = adapt(BundleRevisionImpl.class);
// Close all existing revisions.
closeRevisions();
// Clear all revisions.
m_revisions.clear();

// Purge all old archive revisions, only keeping the newest one.
m_archive.purge();
if (isRemovalPending()) {
closeRevisions();
// Purge all old archive revisions, only keeping the newest one.
m_archive.purge();

current.resetContent(m_archive.getCurrentRevision().getContent());
}
else {
// Remove the revision from the resolver state.
getFramework().getResolver().removeRevision(current);
current.resolve(null);
current.disposeContentPath();
}

m_revisions.clear();
m_currentRevision = null;

// Reset the content of the current bundle revision.
current.resetContent(m_archive.getCurrentRevision().getContent());
// Re-add the revision to the bundle.
addRevision(current);

Expand Down Expand Up @@ -1091,7 +1100,7 @@ <A> void checkAdapt(Class<A> type)
}

@Override
public synchronized <A> A adapt(Class<A> type)
public <A> A adapt(Class<A> type)
{
checkAdapt(type);
if (type == BundleContext.class)
Expand All @@ -1109,14 +1118,14 @@ else if (type == BundleRevision.class)
{
return null;
}
return (A) m_revisions.get(0);
return (A) m_currentRevision;
}
// We need some way to get the current revision even if
// the associated bundle is uninstalled, so we use the
// impl revision class for this purpose.
else if (type == BundleRevisionImpl.class)
{
return (A) m_revisions.get(0);
return (A) m_currentRevision;
}
else if (type == BundleRevisions.class)
{
Expand All @@ -1128,7 +1137,9 @@ else if (type == BundleWiring.class)
{
return null;
}
return (A) m_revisions.get(0).getWiring();
BundleRevisionImpl revision = m_currentRevision;

return (A) (revision != null ? revision.getWiring() : null);
}
else if ( type == AccessControlContext.class)
{
Expand Down Expand Up @@ -1229,6 +1240,8 @@ synchronized void revise(String location, InputStream is)
synchronized boolean rollbackRevise() throws Exception
{
BundleRevision br = m_revisions.remove(0);
m_currentRevision = !m_revisions.isEmpty() ? m_revisions.get(0) : null;

// Since revising a bundle adds a revision to the global
// state, we must remove it from the global state on rollback.
getFramework().getResolver().removeRevision(br);
Expand All @@ -1242,7 +1255,9 @@ synchronized boolean rollbackRevise() throws Exception
// which is the normal case.
synchronized void addRevision(BundleRevisionImpl revision) throws Exception
{
BundleRevisionImpl previous = m_currentRevision;
m_revisions.add(0, revision);
m_currentRevision = revision;

try
{
Expand All @@ -1251,6 +1266,7 @@ synchronized void addRevision(BundleRevisionImpl revision) throws Exception
catch (Exception ex)
{
m_revisions.remove(0);
m_currentRevision = previous;
throw ex;
}

Expand Down Expand Up @@ -1332,7 +1348,7 @@ private BundleRevisionImpl createRevision(boolean isUpdate) throws Exception
}
}
}
if (!collisionCanditates.isEmpty())
if (!collisionCanditates.isEmpty() && m_installingBundle != null)
{
throw new BundleException(
"Bundle symbolic name and version are not unique: "
Expand All @@ -1347,7 +1363,7 @@ synchronized ProtectionDomain getProtectionDomain()
{
ProtectionDomain pd = null;

for (int i = m_revisions.size() - 1; (i >= 0) && (pd == null); i--)
for (int i = 0; (i < m_revisions.size()) && (pd == null); i++)
{
pd = m_revisions.get(i).getProtectionDomain();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
Expand All @@ -45,16 +42,12 @@
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import org.apache.felix.framework.cache.Content;
import org.apache.felix.framework.cache.JarContent;
import org.apache.felix.framework.util.FelixConstants;
import org.osgi.framework.Bundle;
import org.osgi.framework.PackagePermission;

import org.osgi.framework.wiring.BundleRevision;

public class BundleProtectionDomain extends ProtectionDomain
{
private static final class BundleInputStream extends InputStream
Expand All @@ -76,7 +69,7 @@ public BundleInputStream(Content root) throws IOException

int count = 0;
String manifest = null;
for (Enumeration e = m_root.getEntries(); e.hasMoreElements();)
for (Enumeration e = m_root.getEntries(); e != null && e.hasMoreElements();)
{
String entry = (String) e.nextElement();
if (entry.endsWith("/"))
Expand Down Expand Up @@ -264,12 +257,12 @@ protected URLConnection openConnection(URL u) throws IOException
{
target = Felix.m_secureAction.createTempFile("jar", null, null);
Felix.m_secureAction.deleteFileOnExit(target);
FileOutputStream output = null;
OutputStream output = null;
InputStream input = null;
IOException rethrow = null;
try
{
output = new FileOutputStream(target);
output = Felix.m_secureAction.getOutputStream(target);
input = new BundleInputStream(content);
byte[] buffer = new byte[64 * 1024];
for (int i = input.read(buffer);i != -1; i = input.read(buffer))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ public synchronized void resolve(BundleWiringImpl wiring)
}
}

synchronized void disposeContentPath()
{
for (int i = 0; (m_contentPath != null) && (i < m_contentPath.size()); i++)
{
m_contentPath.get(i).close();
}
m_contentPath = null;
}

public void setProtectionDomain(ProtectionDomain pd)
{
m_protectionDomain = pd;
Expand Down Expand Up @@ -616,6 +625,25 @@ public InputStream getInputStream(int index, String urlPath)
return getContentPath().get(index - 1).getEntryAsStream(urlPath);
}


public long getContentTime(int index, String urlPath)
{
if (urlPath.startsWith("/"))
{
urlPath = urlPath.substring(1);
}
Content content;
if (index == 0)
{
content = getContent();
}
else {
content = getContentPath().get(index - 1);
}
long result = content.getContentTime(urlPath);
return result > 0 ? result : m_bundle.getLastModified();
}

public URL getLocalURL(int index, String urlPath)
{
if (urlPath.startsWith("/"))
Expand Down

0 comments on commit a1ec804

Please sign in to comment.