Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.xwiki.commons</groupId>
<artifactId>xwiki-commons-observation-api</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Testing dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.classloader.internal;

import java.util.Objects;

import org.xwiki.observation.event.Event;
import org.xwiki.stability.Unstable;

/**
* Event triggered whenever a class loader has been dropped
* (see {@link org.xwiki.classloader.ClassLoaderManager#dropURLClassLoader(String)}) and reloaded. This is used for
* example when a JAR extension is uninstalled. Note that {@link org.xwiki.classloader.ClassLoaderManager} is not
* responsible for triggering this, as the trigger needs to be performed after the classloader reload.
*
* @version $Id$
* @since 17.1.0
* @since 18.0.0RC1
*/
@Unstable
public class ClassLoaderResetEvent implements Event
{
private final String namespace;

/**
* Default constructor for the root classloader.
*/
public ClassLoaderResetEvent()
{
this(null);
}

/**
* Default constructor when the event is triggered for a specific namespace.
* @param namespace the namespace of the reset classloader.
*/
public ClassLoaderResetEvent(String namespace)
{
this.namespace = namespace;
}

/**
* @return the namespace the event is triggered for.
*/
public String getNamespace()
{
return namespace;
}

@Override
public boolean matches(Object otherEvent)
{
return otherEvent instanceof ClassLoaderResetEvent classLoaderResetedEvent
&& (namespace == null
|| Objects.equals(namespace, classLoaderResetedEvent.namespace));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
<description>XWiki Commons - Extension - Handler - JAR</description>
<properties>
<xwiki.jacoco.instructionRatio>0.81</xwiki.jacoco.instructionRatio>
<!-- Too many dependencies required -->
<checkstyle.suppressions.location>${basedir}/src/checkstyle/checkstyle-suppressions.xml
</checkstyle.suppressions.location>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -79,23 +76,4 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<!-- Specify the "default" execution id so that the "blocker" one is always executed -->
<id>default</id>
<configuration>
<excludes>
org/xwiki/extension/jar/internal/handler/JarExtensionHandler.java
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static boolean isSupported(String type)
type.equals(JarExtensionHandler.JAR)
|| type.equals(JarExtensionHandler.WEBJAR)
|| type.equals(JarExtensionHandler.WEBJAR_NODE)
);
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import org.slf4j.Logger;
import org.xwiki.classloader.ClassLoaderManager;
import org.xwiki.classloader.internal.ClassLoaderResetEvent;
import org.xwiki.component.annotation.Component;
import org.xwiki.context.Execution;
import org.xwiki.context.ExecutionContext;
Expand All @@ -51,6 +52,7 @@
import org.xwiki.job.event.JobFinishingEvent;
import org.xwiki.job.event.JobStartedEvent;
import org.xwiki.observation.EventListener;
import org.xwiki.observation.ObservationManager;
import org.xwiki.observation.event.Event;

/**
Expand All @@ -62,6 +64,8 @@
@Component
@Singleton
@Named("JarExtensionJobFinishingListener")
// Fan out of 21
@SuppressWarnings("checkstyle:ClassFanOutComplexity")
public class JarExtensionJobFinishingListener implements EventListener
{
private static final class UninstalledExtensionCollection
Expand Down Expand Up @@ -120,6 +124,9 @@ private void add(String namespace)
@Inject
private Logger logger;

@Inject
private ObservationManager observationManager;

@Override
public String getName()
{
Expand Down Expand Up @@ -257,32 +264,31 @@ private void onJobFinishedEvent()
if (collection != null) {
if (collection.rootNamespace) {
// Unload extensions
unloadJARsFromNamespace(null, null);
unloadJARsFromNamespace(null);

// Drop class loaders
this.jarExtensionClassLoader.dropURLClassLoaders();

initializeExtensions(null);
this.observationManager.notify(new ClassLoaderResetEvent(), null);
} else if (collection.namespaces != null) {
for (String namespace : collection.namespaces) {
// Unload extensions
unloadJARsFromNamespace(namespace, null);
unloadJARsFromNamespace(namespace);

// Drop class loader
this.jarExtensionClassLoader.dropURLClassLoader(namespace);

initializeExtensions(namespace);
this.observationManager.notify(new ClassLoaderResetEvent(namespace), null);
}
}
}
}

private void unloadJARsFromNamespace(String namespace, Map<String, Set<InstalledExtension>> unloadedExtensions)
private void unloadJARsFromNamespace(String namespace)
{
Map<String, Set<InstalledExtension>> unloadedExtensionsMap = unloadedExtensions;
if (unloadedExtensionsMap == null) {
unloadedExtensionsMap = new HashMap<>();
}
Map<String, Set<InstalledExtension>> unloadedExtensionsMap = new HashMap<>();

// Load extensions from local repository
Collection<InstalledExtension> installedExtensions;
Expand Down